Langevin C++ source

Loading...
Searching...
No Matches
langevin_bc.cpp
Go to the documentation of this file.
1
5
6#include "langevin_types.hpp"
7#include "langevin_base.hpp"
8
10 bool BaseLangevin::check_boundary_conditions(const Parameters p)
11{
12 switch (p.grid_dimension)
13 {
14 case (GridDimension::D1):
15 return (p.bc_values.size()==2);
16 case (GridDimension::D2):
17 return (p.bc_values.size()==4);
18 case (GridDimension::D3):
19 return (p.bc_values.size()==6);
20 default:
21 return false;
22 }
23}
24
26 void BaseLangevin::apply_boundary_conditions(const Parameters p, int i_epoch)
27{
28 auto i_from_xy = [&](int x, int y) -> int { return x + y*p.n_x; };
29 auto add_to_density = [&](int x, int y, double value)
30 {
31 density_grid[i_from_xy(x, y)]
32 = fmax(density_grid[i_from_xy(x, y)] + value*p.dt, 0.0);
33
34 };
35 auto apply_bc_to_edge_2d = [&] (
36 GridEdge grid_edge, BoundaryCondition bc, double value
37 )
38 {
39 if (bc==BoundaryCondition::FIXED_VALUE)
40 {
41 switch (grid_edge)
42 {
43 case (GridEdge::lx):
44 for (auto x=0; x<p.n_x; x++){
45 density_grid[i_from_xy(x,0)] = value;
46 }
47 break;
48 case (GridEdge::ux):
49 for (auto x=0; x<p.n_x; x++){
50 density_grid[i_from_xy(x, p.n_y-1)] = value;
51 }
52 break;
53 case (GridEdge::ly):
54 for (auto y=0; y<p.n_y; y++){
55 density_grid[i_from_xy(0, y)] = value;
56 }
57 break;
58 case (GridEdge::uy):
59 for (auto y=0; y<p.n_y; y++){
60 density_grid[i_from_xy(p.n_x-1, y)] = value;
61 }
62 break;
63 }
64 }
65 // Don't "add flux" if we're at epoch#0
66 else if (bc==BoundaryCondition::FIXED_FLUX and i_epoch>0)
67 {
68 switch (grid_edge)
69 {
70 case (GridEdge::lx):
71 for (auto x=0; x<p.n_x; x++){
72 auto y = 0;
73 add_to_density(x, y, value);
74 }
75 break;
76 case (GridEdge::ux):
77 for (auto x=0; x<p.n_x; x++){
78 auto y = p.n_y-1;
79 add_to_density(x, y, value);
80 }
81 break;
82 case (GridEdge::ly):
83 for (auto y=0; y<p.n_y; y++){
84 auto x = 0;
85 add_to_density(x, y, value);
86 }
87 break;
88 case (GridEdge::uy):
89 for (auto y=0; y<p.n_y; y++){
90 auto x = p.n_x-1;
91 add_to_density(x, y, value);
92 }
93 break;
94 }
95 }
96 };
97 auto apply_boundary_conditions_1d = [&]()
98 {
99 // apply_bc_to_edge_1d(GridEdge::lx, p.boundary_conditions.at(0), p.bc_values.at(0));
100 // apply_bc_to_edge_1d(GridEdge::ux, p.boundary_conditions.at(1), p.bc_values.at(1));
101 };
102 auto apply_boundary_conditions_2d = [&]()
103 {
104 apply_bc_to_edge_2d(
105 GridEdge::lx, p.boundary_conditions.at(0), p.bc_values.at(0)
106 );
107 apply_bc_to_edge_2d(
108 GridEdge::ux, p.boundary_conditions.at(1), p.bc_values.at(1)
109 );
110 apply_bc_to_edge_2d(
111 GridEdge::ly, p.boundary_conditions.at(2), p.bc_values.at(2)
112 );
113 apply_bc_to_edge_2d(
114 GridEdge::uy, p.boundary_conditions.at(3), p.bc_values.at(3)
115 );
116 };
117 auto apply_boundary_conditions_3d = [&]()
118 {
119 // apply_bc_to_edge(GridEdge::lx, p.boundary_conditions.at(0), p.bc_values.at(0));
120 // apply_bc_to_edge(GridEdge::ux, p.boundary_conditions.at(1), p.bc_values.at(1));
121 // apply_bc_to_edge(GridEdge::ly, p.boundary_conditions.at(2), p.bc_values.at(2));
122 // apply_bc_to_edge(GridEdge::uy, p.boundary_conditions.at(3), p.bc_values.at(3));
123 };
124
125 switch (p.grid_dimension)
126 {
127 case (GridDimension::D1):
128 apply_boundary_conditions_1d();
129 break;
130 case (GridDimension::D2):
131 apply_boundary_conditions_2d();
132 break;
133 case (GridDimension::D3):
134 apply_boundary_conditions_3d();
135 break;
136 }
137}
BaseLangevin::density_grid
grid_t density_grid
Density field grid.
Definition langevin_base.hpp:21
BaseLangevin::check_boundary_conditions
bool check_boundary_conditions(const Parameters parameters)
Check we have 2N boundary conditions for an N-dimensional grid.
Definition langevin_bc.cpp:10
BaseLangevin::apply_boundary_conditions
void apply_boundary_conditions(const Parameters parameters, int i_epoch)
Set density field values only the grid edges per bc specs.
Definition langevin_bc.cpp:26
langevin_base.hpp
Base class for Langevin equation integrator.
GridEdge
GridEdge
Classifier for grid edges used in boundary condition handling.
Definition langevin_enums.hpp:23
BoundaryCondition
BoundaryCondition
Grid boundary condition: floating/fixed value/fixed flux; application equally to all edges only for n...
Definition langevin_enums.hpp:41
langevin_types.hpp
Type definitions for BaseLangevin integrator.
Parameters
Container for BaseLangevin integrator parameters.
Definition langevin_parameters.hpp:21