OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
eq_unit_test_3d.hpp
1 /*
2  * eq_unit_test_3d.hpp
3  *
4  * Created on: Jan 4, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_3D_HPP_
9 #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_3D_HPP_
10 
11 #include "config.h"
12 #include "Laplacian.hpp"
13 #include "FiniteDifference/eq.hpp"
14 #include "FiniteDifference/sum.hpp"
15 #include "FiniteDifference/mul.hpp"
16 #include "Grid/grid_dist_id.hpp"
17 #include "Decomposition/CartDecomposition.hpp"
18 #include "Vector/Vector.hpp"
19 #include "Solvers/umfpack_solver.hpp"
20 #include "data_type/aggregate.hpp"
21 
22 BOOST_AUTO_TEST_SUITE( eq_test_suite_3d )
23 
24 struct lid_nn_3d_eigen
26 {
28  static const unsigned int dims = 3;
30  static const unsigned int nvar = 4;
31 
33  static const bool boundary[];
34 
36  typedef float stype;
37 
40 
43 
46 
48  static const int grid_type = STAGGERED_GRID;
49 };
50 
52 {
54  static const unsigned int dims = 3;
56  static const unsigned int nvar = 4;
57 
59  static const bool boundary[];
60 
62  typedef float stype;
63 
66 
69 
72 
74  static const int grid_type = STAGGERED_GRID;
75 };
76 
77 //typedef lid_nn_3d_eigen lid_nn_3d;
78 
79 const bool lid_nn_3d_eigen::boundary[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
80 const bool lid_nn_3d_petsc::boundary[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
81 
82 // Constant Field
83 struct eta
84 {
86  typedef void const_field;
87 
89  static float val() {return 1.0;}
90 };
91 
92 template<typename solver_type,typename lid_nn_3d> void lid_driven_cavity_3d()
93 {
94  #include "Equations/stoke_flow_eq_3d.hpp"
95 
96  Vcluster & v_cl = create_vcluster();
97 
98  if (v_cl.getProcessingUnits() > 3)
99  return;
100 
101  // Domain
102  Box<3,float> domain({0.0,0.0,0.0},{3.0,1.0,1.0});
103 
104  // Ghost
105  Ghost<3,float> g(0.01);
106 
107  long int sz[] = {36,12,12};
108  size_t szu[3];
109  szu[0] = (size_t)sz[0];
110  szu[1] = (size_t)sz[1];
111  szu[2] = (size_t)sz[2];
112 
113  Padding<3> pd({1,1,1},{0,0,0});
114 
115  // velocity in the grid is the property 0, pressure is the property 1
116  constexpr int velocity = 0;
117  constexpr int pressure = 1;
118 
119  // Initialize openfpm
121 
122  // Ghost stencil
123  Ghost<3,long int> stencil_max(1);
124 
125  // Distributed grid
126  FDScheme<lid_nn_3d> fd(pd,stencil_max,domain,g_dist);
127 
128  // start and end of the bulk
129 
130  fd.impose(ic_eq(),0.0, EQ_4, {0,0,0},{sz[0]-2,sz[1]-2,sz[2]-2},true);
131  fd.impose(Prs(), 0.0, EQ_4, {0,0,0},{0,0,0});
132  fd.impose(vx_eq(),0.0, EQ_1, {1,0},{sz[0]-2,sz[1]-2,sz[2]-2});
133  fd.impose(vy_eq(),0.0, EQ_2, {0,1},{sz[0]-2,sz[1]-2,sz[2]-2});
134  fd.impose(vz_eq(),0.0, EQ_3, {0,0,1},{sz[0]-2,sz[1]-2,sz[2]-2});
135 
136  // v_x
137  // R L
138  fd.impose(v_x(),0.0, EQ_1, {0,0,0}, {0,sz[1]-2,sz[2]-2});
139  fd.impose(v_x(),0.0, EQ_1, {sz[0]-1,0,0},{sz[0]-1,sz[1]-2,sz[2]-2});
140 
141  // T B
142  fd.impose(avg_y_vx_f(),0.0, EQ_1, {0,-1,0}, {sz[0]-1,-1,sz[2]-2});
143  fd.impose(avg_y_vx(),0.0, EQ_1, {0,sz[1]-1,0},{sz[0]-1,sz[1]-1,sz[2]-2});
144 
145  // A F
146  fd.impose(avg_z_vx_f(),0.0, EQ_1, {0,-1,-1}, {sz[0]-1,sz[1]-1,-1});
147  fd.impose(avg_z_vx(),0.0, EQ_1, {0,-1,sz[2]-1},{sz[0]-1,sz[1]-1,sz[2]-1});
148 
149  // v_y
150  // R L
151  fd.impose(avg_x_vy_f(),0.0, EQ_2, {-1,0,0}, {-1,sz[1]-1,sz[2]-2});
152  fd.impose(avg_x_vy(),1.0, EQ_2, {sz[0]-1,0,0},{sz[0]-1,sz[1]-1,sz[2]-2});
153 
154  // T B
155  fd.impose(v_y(), 0.0, EQ_2, {0,0,0}, {sz[0]-2,0,sz[2]-2});
156  fd.impose(v_y(), 0.0, EQ_2, {0,sz[1]-1,0},{sz[0]-2,sz[1]-1,sz[2]-2});
157 
158  // F A
159  fd.impose(avg_z_vy(),0.0, EQ_2, {-1,0,sz[2]-1}, {sz[0]-1,sz[1]-1,sz[2]-1});
160  fd.impose(avg_z_vy_f(),0.0, EQ_2, {-1,0,-1}, {sz[0]-1,sz[1]-1,-1});
161 
162  // v_z
163  // R L
164  fd.impose(avg_x_vz_f(),0.0, EQ_3, {-1,0,0}, {-1,sz[1]-2,sz[2]-1});
165  fd.impose(avg_x_vz(),1.0, EQ_3, {sz[0]-1,0,0},{sz[0]-1,sz[1]-2,sz[2]-1});
166 
167  // T B
168  fd.impose(avg_y_vz(),0.0, EQ_3, {-1,sz[1]-1,0},{sz[0]-1,sz[1]-1,sz[2]-1});
169  fd.impose(avg_y_vz_f(),0.0, EQ_3, {-1,-1,0}, {sz[0]-1,-1,sz[2]-1});
170 
171  // F A
172  fd.impose(v_z(),0.0, EQ_3, {0,0,0}, {sz[0]-2,sz[1]-2,0});
173  fd.impose(v_z(),0.0, EQ_3, {0,0,sz[2]-1},{sz[0]-2,sz[1]-2,sz[2]-1});
174 
175  // Padding pressure
176 
177  // L R
178  fd.impose(Prs(), 0.0, EQ_4, {-1,-1,-1},{-1,sz[1]-1,sz[2]-1});
179  fd.impose(Prs(), 0.0, EQ_4, {sz[0]-1,-1,-1},{sz[0]-1,sz[1]-1,sz[2]-1});
180 
181  // T B
182  fd.impose(Prs(), 0.0, EQ_4, {0,sz[1]-1,-1}, {sz[0]-2,sz[1]-1,sz[2]-1});
183  fd.impose(Prs(), 0.0, EQ_4, {0,-1 ,-1}, {sz[0]-2,-1, sz[2]-1});
184 
185  // F A
186  fd.impose(Prs(), 0.0, EQ_4, {0,0,sz[2]-1}, {sz[0]-2,sz[1]-2,sz[2]-1});
187  fd.impose(Prs(), 0.0, EQ_4, {0,0,-1}, {sz[0]-2,sz[1]-2,-1});
188 
189  // Impose v_x v_y v_z padding
190  fd.impose(v_x(), 0.0, EQ_1, {-1,-1,-1},{-1,sz[1]-1,sz[2]-1});
191  fd.impose(v_y(), 0.0, EQ_2, {-1,-1,-1},{sz[0]-1,-1,sz[2]-1});
192  fd.impose(v_z(), 0.0, EQ_3, {-1,-1,-1},{sz[0]-1,sz[1]-1,-1});
193 
194  solver_type solver;
195  auto x = solver.try_solve(fd.getA(),fd.getB());
196 
197  // Bring the solution to grid
198  fd.template copy<velocity,pressure>(x,{0,0},{sz[0]-1,sz[1]-1,sz[2]-1},g_dist);
199 
200  std::string s = std::string(demangle(typeid(solver_type).name()));
201  s += "_";
202 
203  g_dist.write(s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid");
204 
205 #ifdef HAVE_OSX
206 
207  std::string file1 = std::string("test/") + s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + "_test_osx.vtk";
208  std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";
209 
210 #else
211 
212  #if __GNUC__ == 5
213 
214  std::string file1 = std::string("test/") + s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + "_test_GCC5.vtk";
215  std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";
216 
217  #elif __GNUC__ == 6 || __GNUC__ == 7
218 
219  std::string file1 = std::string("test/") + s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + "_test_GCC6.vtk";
220  std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";
221 
222  #else
223 
224  std::string file1 = std::string("test/") + s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + "_test_GCC4.vtk";
225  std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";
226 
227  #endif
228 
229 #endif
230 
231  std::cout << "File1: " << file1 << std::endl;
232  std::cout << "File2: " << file2 << std::endl;
233 
234 #ifndef SE_CLASS3
235 
236  // Check that match
237  bool test = compare(file1,file2);
238  BOOST_REQUIRE_EQUAL(test,true);
239 
240 #endif
241 }
242 
243 // Lid driven cavity, uncompressible fluid
244 
245 BOOST_AUTO_TEST_CASE(lid_driven_cavity)
246 {
247 #if defined(HAVE_EIGEN) && defined(HAVE_SUITESPARSE)
248  lid_driven_cavity_3d<umfpack_solver<double>,lid_nn_3d_eigen>();
249 #endif
250 #ifdef HAVE_PETSC
251  lid_driven_cavity_3d<petsc_solver<double>,lid_nn_3d_petsc>();
252 #endif
253 }
254 
255 BOOST_AUTO_TEST_SUITE_END()
256 
257 
258 #endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_3D_HPP_ */
grid_dist_id< 3, float, aggregate< float[3], float >, CartDecomposition< 3, float > > b_grid
type of base grid
[Definition of the system]
SparseMatrix< double, int > SparseMatrix_type
type of SparseMatrix for the linear solver
static const bool boundary[]
boundary at X and Y
SparseMatrix< double, int, PETSC_BASE > SparseMatrix_type
type of SparseMatrix for the linear solver
size_t getProcessUnitID()
Get the process unit id.
Sparse Matrix implementation stub object when OpenFPM is compiled with no linear algebra support...
Definition: Vector.hpp:39
Definition: eq.hpp:81
Class that contain Padding information on each direction positive and Negative direction.
Definition: Ghost.hpp:117
grid_dist_id< 3, float, aggregate< float[3], float >, CartDecomposition< 3, float > > b_grid
type of base grid
Definition: Ghost.hpp:39
Implementation of VCluster class.
Definition: VCluster.hpp:36
Specify the general caratteristic of system to solve.
This class decompose a space into sub-sub-domains and distribute them across processors.
Sparse Matrix implementation.
This is a distributed grid.
Average.
Definition: Average.hpp:31
static const unsigned int nvar
number of fields in the system
void const_field
define that eta is a constant field
Vector< double > Vector_type
type of Vector for the linear solver
static const unsigned int dims
dimensionaly of the equation ( 3D problem ...)
float stype
type of space float, double, ...
It model an expression expr1 + ... exprn.
Definition: sum.hpp:92
Finite Differences.
Definition: FDScheme.hpp:124
Vector< double, PETSC_BASE > Vector_type
type of Vector for the linear solver
static float val()
therutn the value of the constant
static const bool boundary[]
boundary at X and Y
size_t getProcessingUnits()
Get the total number of processors.
float stype
type of space float, double, ...