eq_unit_test_3d.hpp 8.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * eq_unit_test_3d.hpp
 *
 *  Created on: Jan 4, 2016
 *      Author: i-bird
 */

#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_3D_HPP_
#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_3D_HPP_

jenkins's avatar
jenkins committed
11
#include "config.h"
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "Laplacian.hpp"
#include "FiniteDifference/eq.hpp"
#include "FiniteDifference/sum.hpp"
#include "FiniteDifference/mul.hpp"
#include "Grid/grid_dist_id.hpp"
#include "data_type/scalar.hpp"
#include "Decomposition/CartDecomposition.hpp"
#include "Vector/Vector.hpp"
#include "Solvers/umfpack_solver.hpp"
#include "data_type/aggregate.hpp"

BOOST_AUTO_TEST_SUITE( eq_test_suite_3d )

incardon's avatar
incardon committed
25
//! Specify the general caratteristic of system to solve
Pietro Incardona's avatar
Pietro Incardona committed
26
struct lid_nn_3d_eigen
27
{
incardon's avatar
incardon committed
28
	//! dimensionaly of the equation ( 3D problem ...)
29
	static const unsigned int dims = 3;
incardon's avatar
incardon committed
30
	//! number of fields in the system
31
32
	static const unsigned int nvar = 4;

incardon's avatar
incardon committed
33
	//! boundary at X and Y
34
35
	static const bool boundary[];

incardon's avatar
incardon committed
36
	//! type of space float, double, ...
37
38
	typedef float stype;

incardon's avatar
incardon committed
39
	//! type of base grid
40
41
	typedef grid_dist_id<3,float,aggregate<float[3],float>,CartDecomposition<3,float>> b_grid;

incardon's avatar
incardon committed
42
	//! type of SparseMatrix for the linear solver
43
44
	typedef SparseMatrix<double,int> SparseMatrix_type;

incardon's avatar
incardon committed
45
	//! type of Vector for the linear solver
46
47
	typedef Vector<double> Vector_type;

incardon's avatar
incardon committed
48
	//! Define the underline grid is staggered
49
50
51
	static const int grid_type = STAGGERED_GRID;
};

Pietro Incardona's avatar
Pietro Incardona committed
52
struct lid_nn_3d_petsc
53
{
incardon's avatar
incardon committed
54
	//! dimensionaly of the equation ( 3D problem ...)
Pietro Incardona's avatar
Pietro Incardona committed
55
	static const unsigned int dims = 3;
incardon's avatar
incardon committed
56
	//! number of fields in the system
Pietro Incardona's avatar
Pietro Incardona committed
57
	static const unsigned int nvar = 4;
58

incardon's avatar
incardon committed
59
	//! boundary at X and Y
Pietro Incardona's avatar
Pietro Incardona committed
60
	static const bool boundary[];
61

incardon's avatar
incardon committed
62
	//! type of space float, double, ...
Pietro Incardona's avatar
Pietro Incardona committed
63
	typedef float stype;
64

incardon's avatar
incardon committed
65
	//! type of base grid
Pietro Incardona's avatar
Pietro Incardona committed
66
	typedef grid_dist_id<3,float,aggregate<float[3],float>,CartDecomposition<3,float>> b_grid;
67

incardon's avatar
incardon committed
68
	//! type of SparseMatrix for the linear solver
Pietro Incardona's avatar
Pietro Incardona committed
69
	typedef SparseMatrix<double,int,PETSC_BASE> SparseMatrix_type;
70

incardon's avatar
incardon committed
71
	//! type of Vector for the linear solver
Pietro Incardona's avatar
Pietro Incardona committed
72
	typedef Vector<double,PETSC_BASE> Vector_type;
73

incardon's avatar
incardon committed
74
	//! Define the underline grid is staggered
Pietro Incardona's avatar
Pietro Incardona committed
75
76
	static const int grid_type = STAGGERED_GRID;
};
77

Pietro Incardona's avatar
Pietro Incardona committed
78
//typedef lid_nn_3d_eigen lid_nn_3d;
79

Pietro Incardona's avatar
Pietro Incardona committed
80
81
const bool lid_nn_3d_eigen::boundary[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
const bool lid_nn_3d_petsc::boundary[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
82

Pietro Incardona's avatar
Pietro Incardona committed
83
84
85
// Constant Field
struct eta
{
incardon's avatar
incardon committed
86
	//! define that eta is a constant field
Pietro Incardona's avatar
Pietro Incardona committed
87
	typedef void const_field;
88

incardon's avatar
incardon committed
89
	//! therutn the value of the constant
Pietro Incardona's avatar
Pietro Incardona committed
90
91
	static float val()	{return 1.0;}
};
92

Pietro Incardona's avatar
Pietro Incardona committed
93
template<typename solver_type,typename lid_nn_3d> void lid_driven_cavity_3d()
94
{
Pietro Incardona's avatar
Pietro Incardona committed
95
96
	#include "Equations/stoke_flow_eq_3d.hpp"

97
	Vcluster & v_cl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
98

99
100
	if (v_cl.getProcessingUnits() > 3)
		return;
Pietro Incardona's avatar
Pietro Incardona committed
101

102
103
104
105
106
107
	// Domain
	Box<3,float> domain({0.0,0.0,0.0},{3.0,1.0,1.0});

	// Ghost
	Ghost<3,float> g(0.01);

108
	long int sz[] = {36,12,12};
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	size_t szu[3];
	szu[0] = (size_t)sz[0];
	szu[1] = (size_t)sz[1];
	szu[2] = (size_t)sz[2];

	Padding<3> pd({1,1,1},{0,0,0});

	// velocity in the grid is the property 0, pressure is the property 1
	constexpr int velocity = 0;
	constexpr int pressure = 1;

	// Initialize openfpm
	grid_dist_id<3,float,aggregate<float[3],float>,CartDecomposition<3,float>> g_dist(szu,domain,g);

Pietro Incardona's avatar
Pietro Incardona committed
123
124
125
	// Ghost stencil
	Ghost<3,long int> stencil_max(1);

126
	// Distributed grid
incardon's avatar
incardon committed
127
	FDScheme<lid_nn_3d> fd(pd,stencil_max,domain,g_dist);
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

	// start and end of the bulk

	fd.impose(ic_eq(),0.0, EQ_4, {0,0,0},{sz[0]-2,sz[1]-2,sz[2]-2},true);
	fd.impose(Prs(),  0.0, EQ_4, {0,0,0},{0,0,0});
	fd.impose(vx_eq(),0.0, EQ_1, {1,0},{sz[0]-2,sz[1]-2,sz[2]-2});
	fd.impose(vy_eq(),0.0, EQ_2, {0,1},{sz[0]-2,sz[1]-2,sz[2]-2});
	fd.impose(vz_eq(),0.0, EQ_3, {0,0,1},{sz[0]-2,sz[1]-2,sz[2]-2});

	// v_x
	// R L
	fd.impose(v_x(),0.0, EQ_1, {0,0,0},      {0,sz[1]-2,sz[2]-2});
	fd.impose(v_x(),0.0, EQ_1, {sz[0]-1,0,0},{sz[0]-1,sz[1]-2,sz[2]-2});

	// T B
	fd.impose(avg_y_vx_f(),0.0, EQ_1, {0,-1,0},     {sz[0]-1,-1,sz[2]-2});
	fd.impose(avg_y_vx(),0.0, EQ_1,   {0,sz[1]-1,0},{sz[0]-1,sz[1]-1,sz[2]-2});

	// A F
	fd.impose(avg_z_vx_f(),0.0, EQ_1, {0,-1,-1},     {sz[0]-1,sz[1]-1,-1});
	fd.impose(avg_z_vx(),0.0, EQ_1, {0,-1,sz[2]-1},{sz[0]-1,sz[1]-1,sz[2]-1});

	// v_y
	// R L
	fd.impose(avg_x_vy_f(),0.0, EQ_2,  {-1,0,0},     {-1,sz[1]-1,sz[2]-2});
	fd.impose(avg_x_vy(),1.0, EQ_2,    {sz[0]-1,0,0},{sz[0]-1,sz[1]-1,sz[2]-2});

	// T B
	fd.impose(v_y(), 0.0, EQ_2, {0,0,0},      {sz[0]-2,0,sz[2]-2});
	fd.impose(v_y(), 0.0, EQ_2, {0,sz[1]-1,0},{sz[0]-2,sz[1]-1,sz[2]-2});

	// F A
	fd.impose(avg_z_vy(),0.0, EQ_2,   {-1,0,sz[2]-1}, {sz[0]-1,sz[1]-1,sz[2]-1});
	fd.impose(avg_z_vy_f(),0.0, EQ_2, {-1,0,-1},      {sz[0]-1,sz[1]-1,-1});

	// v_z
	// R L
	fd.impose(avg_x_vz_f(),0.0, EQ_3, {-1,0,0},     {-1,sz[1]-2,sz[2]-1});
	fd.impose(avg_x_vz(),1.0, EQ_3,   {sz[0]-1,0,0},{sz[0]-1,sz[1]-2,sz[2]-1});

	// T B
	fd.impose(avg_y_vz(),0.0, EQ_3, {-1,sz[1]-1,0},{sz[0]-1,sz[1]-1,sz[2]-1});
	fd.impose(avg_y_vz_f(),0.0, EQ_3, {-1,-1,0},   {sz[0]-1,-1,sz[2]-1});

	// F A
	fd.impose(v_z(),0.0, EQ_3, {0,0,0},      {sz[0]-2,sz[1]-2,0});
	fd.impose(v_z(),0.0, EQ_3, {0,0,sz[2]-1},{sz[0]-2,sz[1]-2,sz[2]-1});

	// Padding pressure

	// L R
	fd.impose(Prs(), 0.0, EQ_4, {-1,-1,-1},{-1,sz[1]-1,sz[2]-1});
	fd.impose(Prs(), 0.0, EQ_4, {sz[0]-1,-1,-1},{sz[0]-1,sz[1]-1,sz[2]-1});

	// T B
	fd.impose(Prs(), 0.0, EQ_4, {0,sz[1]-1,-1}, {sz[0]-2,sz[1]-1,sz[2]-1});
	fd.impose(Prs(), 0.0, EQ_4, {0,-1     ,-1}, {sz[0]-2,-1,     sz[2]-1});

	// F A
	fd.impose(Prs(), 0.0, EQ_4, {0,0,sz[2]-1}, {sz[0]-2,sz[1]-2,sz[2]-1});
	fd.impose(Prs(), 0.0, EQ_4, {0,0,-1},      {sz[0]-2,sz[1]-2,-1});

	// Impose v_x  v_y v_z padding
	fd.impose(v_x(), 0.0, EQ_1, {-1,-1,-1},{-1,sz[1]-1,sz[2]-1});
	fd.impose(v_y(), 0.0, EQ_2, {-1,-1,-1},{sz[0]-1,-1,sz[2]-1});
	fd.impose(v_z(), 0.0, EQ_3, {-1,-1,-1},{sz[0]-1,sz[1]-1,-1});

Pietro Incardona's avatar
Pietro Incardona committed
195
	solver_type solver;
196
	auto x = solver.try_solve(fd.getA(),fd.getB());
Pietro Incardona's avatar
Pietro Incardona committed
197

198
	// Bring the solution to grid
Pietro Incardona's avatar
Pietro Incardona committed
199
	fd.template copy<velocity,pressure>(x,{0,0},{sz[0]-1,sz[1]-1,sz[2]-1},g_dist);
200

201
202
203
	std::string s = std::string(demangle(typeid(solver_type).name()));
	s += "_";

Pietro Incardona's avatar
Pietro Incardona committed
204
	g_dist.write(s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid");
205

jenkins's avatar
jenkins committed
206
207
208
209
210
211
212
#ifdef HAVE_OSX

        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";
        std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";

#else

213
	#if __GNUC__ == 5
Pietro Incardona's avatar
Pietro Incardona committed
214

215
216
        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";
        std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";
217
218
219
220
221

    #elif __GNUC__ == 6

        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";
        std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";
222
223
224
225
226
227
228

	#else

        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";
        std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";

	#endif
jenkins's avatar
jenkins committed
229
230
231

#endif

Pietro Incardona's avatar
Pietro Incardona committed
232
233
234
    std::cout << "File1: " << file1 << std::endl;
    std::cout << "File2: " << file2 << std::endl;

incardon's avatar
incardon committed
235
#ifndef SE_CLASS3
jenkins's avatar
jenkins committed
236

237
	// Check that match
Pietro Incardona's avatar
Pietro Incardona committed
238
	bool test = compare(file1,file2);
239
	BOOST_REQUIRE_EQUAL(test,true);
incardon's avatar
incardon committed
240
241

#endif
Pietro Incardona's avatar
Pietro Incardona committed
242
243
244
245
246
247
}

// Lid driven cavity, uncompressible fluid

BOOST_AUTO_TEST_CASE(lid_driven_cavity)
{
Pietro Incardona's avatar
Pietro Incardona committed
248
	lid_driven_cavity_3d<umfpack_solver<double>,lid_nn_3d_eigen>();
Pietro Incardona's avatar
Pietro Incardona committed
249
#ifdef HAVE_PETSC
Pietro Incardona's avatar
Pietro Incardona committed
250
	lid_driven_cavity_3d<petsc_solver<double>,lid_nn_3d_petsc>();
Pietro Incardona's avatar
Pietro Incardona committed
251
#endif
252
253
254
255
256
257
}

BOOST_AUTO_TEST_SUITE_END()


#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_3D_HPP_ */