eq_unit_test.hpp 5.4 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * eq_unit_test.hpp
 *
 *  Created on: Oct 13, 2015
 *      Author: i-bird
 */

#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_HPP_
#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_HPP_

#include "Laplacian.hpp"
#include "FiniteDifference/eq.hpp"
#include "FiniteDifference/sum.hpp"
incardon's avatar
incardon committed
14
#include "FiniteDifference/mul.hpp"
incardon's avatar
incardon committed
15 16 17
#include "Grid/grid_dist_id.hpp"
#include "data_type/scalar.hpp"
#include "Decomposition/CartDecomposition.hpp"
incardon's avatar
incardon committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31

// Stokes flow

struct lid_nn
{
	// dimensionaly of the equation (2D problem 3D problem ...)
	static const unsigned int dims = 2;
	// number of fields in the system
	static const unsigned int nvar = 3;
	static const unsigned int ord = EQS_FIELD;

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

incardon's avatar
incardon committed
32 33 34
	//
	static constexpr unsigned int num_cfields = 0;

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

	// type of base grid
	typedef grid_dist_id<2,float,scalar<float>,CartDecomposition<2,float>> b_grid;
incardon's avatar
incardon committed
40 41 42 43 44 45 46
};

const bool lid_nn::boundary[] = {NON_PERIODIC,NON_PERIODIC};

// Constant Field
struct eta
{
47 48 49
	typedef void const_field;

	static float val()	{return 1.0;}
incardon's avatar
incardon committed
50 51
};

incardon's avatar
incardon committed
52
// Model the equations
incardon's avatar
incardon committed
53 54 55

constexpr unsigned int v[] = {0,1};
constexpr unsigned int P = 2;
56
constexpr unsigned int ic = 2;
incardon's avatar
incardon committed
57 58 59 60 61 62 63 64 65

typedef Field<v[x],lid_nn> v_x;
typedef Field<v[y],lid_nn> v_y;
typedef Field<P,lid_nn> Prs;

// Eq1 V_x

typedef mul<eta,Lap<v_x,lid_nn>,lid_nn> eta_lap_vx;
typedef D<x,Prs,lid_nn> p_x;
incardon's avatar
incardon committed
66
typedef sum<eta_lap_vx,p_x,lid_nn> vx_eq;
incardon's avatar
incardon committed
67 68 69 70 71 72 73 74 75 76 77

// Eq2 V_y

typedef mul<eta,Lap<v_y,lid_nn>,lid_nn> eta_lap_vy;
typedef D<x,Prs,lid_nn> p_x;
typedef sum<eta_lap_vy,p_x,lid_nn> vy_eq;

// Eq3 Incompressibility

typedef D<x,v_x,lid_nn> dx_vx;
typedef D<y,v_y,lid_nn> dy_vy;
78 79
typedef sum<dx_vx,dy_vy,lid_nn> ic_eq;

incardon's avatar
incardon committed
80

incardon's avatar
incardon committed
81 82
BOOST_AUTO_TEST_SUITE( eq_test_suite )

incardon's avatar
incardon committed
83 84 85 86
// Lid driven cavity, uncompressible fluid

BOOST_AUTO_TEST_CASE( lid_driven_cavity )
{
incardon's avatar
incardon committed
87 88
	// Domain
	Box<2,float> domain({0.0,0.0},{1.0,1.0});
incardon's avatar
incardon committed
89

incardon's avatar
incardon committed
90 91 92
	// Ghost
	Ghost<2,float> g(0.01);

incardon's avatar
incardon committed
93
	size_t sz[] = {256,256};
94
	Padding<2> pd({1,2},{1,2});
incardon's avatar
incardon committed
95 96 97

	// Initialize the global VCluster
	init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
incardon's avatar
incardon committed
98

incardon's avatar
incardon committed
99 100 101 102
	// Initialize openfpm
	grid_dist_id<2,float,scalar<float>,CartDecomposition<2,float>> g_dist(sz,domain,g);

	// Distributed grid
103
	FDScheme<lid_nn> fd(pd,domain,g_dist.getGridInfo(),g_dist.getDecomposition(),g_dist.getVC());
incardon's avatar
incardon committed
104 105

	// start and end of the bulk
incardon's avatar
incardon committed
106
/*	grid_key_dx<2> bulk_start(0,0);
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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
	grid_key_dx<2> bulk_end(sz[0],sz[1]);

	// Impose the vx and vy equation in the bulk
	fd.imposeA(vx_eq(), g_dist.getSubDomainIterator(bulk_start,bulk_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(bulk_start,bulk_end));
	fd.imposeA(vy_eq(), g_dist.getSubDomainIterator(bulk_start,bulk_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(bulk_start,bulk_end));
	fd.imposeA(ic_eq(), g_dist.getSubDomainIterator(bulk_start,bulk_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(bulk_start,bulk_end));

	// Boundary condition on the left
	grid_key_dx<2> bleft_start(0,-1);
	grid_key_dx<2> bleft_end(0,33);
	fd.imposeA(v_x(), g_dist.getSubDomainIterator(bleft_start,bleft_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(bleft_start,bleft_end));

	// Boundary condition on the right
	grid_key_dx<2> bright_start(32,-1);
	grid_key_dx<2> bright_end(32,33);
	fd.imposeA(v_x(), g_dist.getSubDomainIterator(bright_start,bright_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(bright_start,bright_end));

	// Padding condition Pressure Left
	grid_key_dx<2> pleft_start(-1,0);
	grid_key_dx<2> pleft_end(-1,31);
	fd.imposeA(Prs(), g_dist.getSubDomainIterator(bleft_start,bleft_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(bleft_start,bleft_end));

	// Padding condition Pressure Right
	grid_key_dx<2> pright_start(32,-1);
	grid_key_dx<2> pright_end(33,33);
	fd.imposeA(Prs(), g_dist.getSubDomainIterator(pright_start,pright_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(pright_start,pright_end));

	// Padding condition vy Right
	grid_key_dx<2> pvright_start(33,-1);
	grid_key_dx<2> pvright_end(33,33);
	fd.imposeA(v_y(), g_dist.getSubDomainIterator(pvright_start,pright_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(pvright_start,pright_end));

	// Padding Bottom pressure
	grid_key_dx<2> pbot_start(0,-1);
	grid_key_dx<2> pbot_end(31,-1);
	fd.imposeA(Prs(), g_dist.getSubDomainIterator(pbot_start,pbot_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(pbot_start,pbot_end));

	// Bottom boundary condition vy
	grid_key_dx<2> bbot_start(-1,0);
	grid_key_dx<2> bbot_end(33,0);
	fd.imposeA(v_y(), g_dist.getSubDomainIterator(bbot_start,bbot_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(bbot_start,bbot_end));

	// Padding top pressure
	grid_key_dx<2> ptop_start(0,32);
	grid_key_dx<2> ptop_end(31,33);
	fd.imposeA(Prs(), g_dist.getSubDomainIterator(ptop_start,ptop_end));
	fd.imposeB(0.0, g_dist.getSubDomainIterator(ptop_start,ptop_end));

	// Top boundary condition v_y
	grid_key_dx<2> btop_start(-1,32);
	grid_key_dx<2> btop_end(33,32);
	fd.imposeA(v_y(), g_dist.getSubDomainIterator(btop_start,btop_end));
	fd.imposeB(1.0, g_dist.getSubDomainIterator(btop_start,btop_end));

	// Padding top v_x
	grid_key_dx<2> pvtop_start(0,33);
	grid_key_dx<2> pvtop_end(31,33);
	fd.imposeA(v_x(), g_dist.getSubDomainIterator(pvtop_start,pvtop_end));
incardon's avatar
incardon committed
175
	fd.imposeB(0.0, g_dist.getSubDomainIterator(pvtop_start,pvtop_end));*/
incardon's avatar
incardon committed
176
}
incardon's avatar
incardon committed
177

incardon's avatar
incardon committed
178 179
BOOST_AUTO_TEST_SUITE_END()

incardon's avatar
incardon committed
180
#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_HPP_ */