eq_unit_test_3d.hpp 6.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * 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_


#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 )

//!

Pietro Incardona's avatar
Pietro Incardona committed
27
struct lid_nn_3d_eigen
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
{
	// dimensionaly of the equation ( 3D problem ...)
	static const unsigned int dims = 3;
	// number of fields in the system
	static const unsigned int nvar = 4;

	// boundary at X and Y
	static const bool boundary[];

	// type of space float, double, ...
	typedef float stype;

	// type of base grid
	typedef grid_dist_id<3,float,aggregate<float[3],float>,CartDecomposition<3,float>> b_grid;

	// type of SparseMatrix for the linear solver
	typedef SparseMatrix<double,int> SparseMatrix_type;

	// type of Vector for the linear solver
	typedef Vector<double> Vector_type;

	// Define the underline grid is staggered
	static const int grid_type = STAGGERED_GRID;
};

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

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

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

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

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

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

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

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

Pietro Incardona's avatar
Pietro Incardona committed
81 82
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};
83

Pietro Incardona's avatar
Pietro Incardona committed
84 85 86 87
// Constant Field
struct eta
{
	typedef void const_field;
88

Pietro Incardona's avatar
Pietro Incardona committed
89 90
	static float val()	{return 1.0;}
};
91

Pietro Incardona's avatar
Pietro Incardona committed
92 93
//#define SYSEQ_TYPE lid_nn_3d_eigen;
//#include "Equations/stoke_flow_eq_3d.hpp"
94

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

99
	Vcluster & v_cl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
100

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

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

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

110
	long int sz[] = {36,12,12};
111 112 113 114 115 116 117 118 119 120 121 122 123 124
	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
125 126 127
	// Ghost stencil
	Ghost<3,long int> stencil_max(1);

128
	// Distributed grid
Pietro Incardona's avatar
Pietro Incardona committed
129
	FDScheme<lid_nn_3d> fd(pd,stencil_max,domain,g_dist.getGridInfo(),g_dist);
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 195 196

	// 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
197 198 199 200
	solver_type solver;
	solver.best_solve();
	auto x = solver.solve(fd.getA(),fd.getB());

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

204 205 206 207 208
	std::string s = std::string(demangle(typeid(solver_type).name()));
	s += "_";

	g_dist.write(s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()));

Pietro Incardona's avatar
Pietro Incardona committed
209 210 211
	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.vtk";
	std::string file2 = s + "lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()) + "_grid_" + std::to_string(v_cl.getProcessUnitID()) + ".vtk";

212
	// Check that match
Pietro Incardona's avatar
Pietro Incardona committed
213
	bool test = compare(file1,file2);
214
	BOOST_REQUIRE_EQUAL(test,true);
Pietro Incardona's avatar
Pietro Incardona committed
215 216 217 218 219 220
}

// Lid driven cavity, uncompressible fluid

BOOST_AUTO_TEST_CASE(lid_driven_cavity)
{
Pietro Incardona's avatar
Pietro Incardona committed
221
	lid_driven_cavity_3d<umfpack_solver<double>,lid_nn_3d_eigen>();
Pietro Incardona's avatar
Pietro Incardona committed
222
#ifdef HAVE_PETSC
Pietro Incardona's avatar
Pietro Incardona committed
223
	lid_driven_cavity_3d<petsc_solver<double>,lid_nn_3d_petsc>();
Pietro Incardona's avatar
Pietro Incardona committed
224
#endif
225 226 227 228 229 230
}

BOOST_AUTO_TEST_SUITE_END()


#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_3D_HPP_ */