eq_unit_test_3d.cpp 9.4 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_

incardon's avatar
incardon committed
11 12 13
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

jenkins's avatar
jenkins committed
14
#include "config.h"
15 16 17 18 19 20 21 22 23
#include "Laplacian.hpp"
#include "FiniteDifference/eq.hpp"
#include "FiniteDifference/sum.hpp"
#include "FiniteDifference/mul.hpp"
#include "Grid/grid_dist_id.hpp"
#include "Decomposition/CartDecomposition.hpp"
#include "Vector/Vector.hpp"
#include "Solvers/umfpack_solver.hpp"
#include "data_type/aggregate.hpp"
incardon's avatar
incardon committed
24 25
#include "Solvers/petsc_solver.hpp"
#include "FiniteDifference/FDScheme.hpp"
26 27 28

BOOST_AUTO_TEST_SUITE( eq_test_suite_3d )

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

incardon's avatar
incardon committed
37
	//! boundary at X and Y
38 39
	static const bool boundary[];

incardon's avatar
incardon committed
40
	//! type of space float, double, ...
41 42
	typedef float stype;

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

incardon's avatar
incardon committed
46
	//! type of SparseMatrix for the linear solver
47
	typedef SparseMatrix<double,int,EIGEN_BASE> SparseMatrix_type;
48

incardon's avatar
incardon committed
49
	//! type of Vector for the linear solver
50 51
	typedef Vector<double> Vector_type;

incardon's avatar
incardon committed
52
	//! Define the underline grid is staggered
53 54 55
	static const int grid_type = STAGGERED_GRID;
};

56
struct lid_nn_3d_petsc
57
{
incardon's avatar
incardon committed
58
	//! dimensionaly of the equation ( 3D problem ...)
59
	static const unsigned int dims = 3;
incardon's avatar
incardon committed
60
	//! number of fields in the system
61
	static const unsigned int nvar = 4;
62

incardon's avatar
incardon committed
63
	//! boundary at X and Y
64
	static const bool boundary[];
65

incardon's avatar
incardon committed
66
	//! type of space float, double, ...
67
	typedef float stype;
68

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

incardon's avatar
incardon committed
72
	//! type of SparseMatrix for the linear solver
73
	typedef SparseMatrix<double,int,PETSC_BASE> SparseMatrix_type;
74

incardon's avatar
incardon committed
75
	//! type of Vector for the linear solver
76
	typedef Vector<double,PETSC_BASE> Vector_type;
77

incardon's avatar
incardon committed
78
	//! Define the underline grid is staggered
79 80
	static const int grid_type = STAGGERED_GRID;
};
81

82
//typedef lid_nn_3d_eigen lid_nn_3d;
83

84 85
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};
86

87 88 89
// Constant Field
struct eta
{
incardon's avatar
incardon committed
90
	//! define that eta is a constant field
91
	typedef void const_field;
92

incardon's avatar
incardon committed
93
	//! therutn the value of the constant
94 95
	static float val()	{return 1.0;}
};
96

97
template<typename solver_type,typename lid_nn_3d> void lid_driven_cavity_3d()
98
{
99 100
	#include "Equations/stoke_flow_eq_3d.hpp"

incardon's avatar
incardon committed
101
	Vcluster<> & v_cl = create_vcluster();
102

103 104
	if (v_cl.getProcessingUnits() > 3)
		return;
105

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

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

112
	long int sz[] = {36,12,12};
113 114 115 116 117 118 119 120 121 122 123 124 125 126
	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);

127 128 129
	// Ghost stencil
	Ghost<3,long int> stencil_max(1);

130
	// Distributed grid
131
	FDScheme<lid_nn_3d> fd(pd,stencil_max,domain,g_dist);
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 197 198

	// 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});

199
	solver_type solver;
incardon's avatar
incardon committed
200
	auto x_ = solver.try_solve(fd.getA(),fd.getB());
201

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

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

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

jenkins's avatar
jenkins committed
210 211 212 213 214 215 216
#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

incardon's avatar
incardon committed
217 218 219 220 221 222
	#if __GNUC__ == 7

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

	#elif __GNUC__ == 5
Pietro Incardona's avatar
Pietro Incardona committed
223

224 225
        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";
226 227 228 229 230

    #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";
231

232 233 234 235
    #elif __GNUC__ == 7

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

incardon's avatar
incardon committed
237 238 239 240 241
     #elif __GNUC__ == 8

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

242 243 244 245 246 247
	#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
248 249 250

#endif

Pietro Incardona's avatar
Pietro Incardona committed
251 252 253
    std::cout << "File1: " << file1 << std::endl;
    std::cout << "File2: " << file2 << std::endl;

incardon's avatar
incardon committed
254
#if !(defined(SE_CLASS3) || defined(TEST_COVERAGE_MODE))
255

256
	// Check that match
Pietro Incardona's avatar
Pietro Incardona committed
257
	bool test = compare(file1,file2);
258
	BOOST_REQUIRE_EQUAL(test,true);
incardon's avatar
incardon committed
259 260

#endif
261 262 263 264 265 266
}

// Lid driven cavity, uncompressible fluid

BOOST_AUTO_TEST_CASE(lid_driven_cavity)
{
267
#if defined(HAVE_EIGEN) && defined(HAVE_SUITESPARSE)
incardon's avatar
incardon committed
268
	lid_driven_cavity_3d<umfpack_solver<double>,lid_nn_3d_eigen>();
269 270
#endif
#ifdef HAVE_PETSC
271
	lid_driven_cavity_3d<petsc_solver<double>,lid_nn_3d_petsc>();
272
#endif
273 274 275 276 277 278
}

BOOST_AUTO_TEST_SUITE_END()


#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_3D_HPP_ */