eq_unit_test.hpp 2.66 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
{
incardon's avatar
incardon committed
47
	float val()	{return 1.0;}
incardon's avatar
incardon committed
48 49
};

incardon's avatar
incardon committed
50
// Model the equations
incardon's avatar
incardon committed
51 52 53 54 55 56 57 58 59 60 61 62

constexpr unsigned int v[] = {0,1};
constexpr unsigned int P = 2;

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
63
typedef sum<eta_lap_vx,p_x,lid_nn> vx_eq;
incardon's avatar
incardon committed
64 65 66 67 68 69 70 71 72 73 74 75 76

// 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;
typedef sum<dx_vx,dy_vy> incompressibility;

incardon's avatar
incardon committed
77 78
BOOST_AUTO_TEST_SUITE( eq_test_suite )

incardon's avatar
incardon committed
79 80 81 82
// Lid driven cavity, uncompressible fluid

BOOST_AUTO_TEST_CASE( lid_driven_cavity )
{
incardon's avatar
incardon committed
83 84
	// Domain
	Box<2,float> domain({0.0,0.0},{1.0,1.0});
incardon's avatar
incardon committed
85

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

	size_t sz[] = {32,32};

	// 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
93

incardon's avatar
incardon committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	// Initialize openfpm
	grid_dist_id<2,float,scalar<float>,CartDecomposition<2,float>> g_dist(sz,domain,g);

	// Distributed grid
	FDScheme<lid_nn> fd;

	// start and end of the bulk
	grid_key_dx<2> bulk_start(1,1);
	grid_key_dx<2> bulk_end(sz[0]-1,sz[1]-1);

	// Impose the vx equation
	vx_eq vx;
	fd.impose(vx, g_dist.getGridInfo() , g_dist.getSubDomainIterator(bulk_start,bulk_end));

	// Impose the vy equation
	vy_eq vy;
	fd.impose(vy, g_dist.getGridInfo(), g_dist.getSubDomainIterator(bulk_start,bulk_end));
}
incardon's avatar
incardon committed
112

incardon's avatar
incardon committed
113 114
BOOST_AUTO_TEST_SUITE_END()

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