Finite Differences. More...
Finite Differences.
This class is able to discretize on a Matrix any system of equations producing a linear system of type \(Ax=b\). In order to create a consistent Matrix it is required that each processor must contain a contiguous range on grid points without holes. In order to ensure this, each processor produce a contiguous local labeling of its local points. Each processor also add an offset equal to the number of local points of the processors with id smaller than him, to produce a global and non overlapping labeling. An example is shown in the figures down, here we have a grid 8x6 divided across four processors each processor label locally its grid points
* +--------------------------+ | 1 2 3 4| 1 2 3 4| | | | | 5 6 7 8| 5 6 7 8| | | | | 9 10 11 12| 9 10 11 12| +--------------------------+ |13 14 15| 13 14 15 16 17| | | | |16 17 18| 18 19 20 21 22| | | | |19 20 21| 23 24 25 26 27| +--------------------------+ * * *
To the local relabelling is added an offset to make the local id global and non overlapping
* +--------------------------+ | 1 2 3 4|23 24 25 26| | | | | 5 6 7 8|27 28 29 30| | | | | 9 10 12 13|31 32 33 34| +--------------------------+ |14 15 16| 35 36 37 38 39| | | | |17 18 19| 40 41 42 43 44| | | | |20 21 22| 45 46 47 48 49| +--------------------------+ * * *
Sys_eqs | Definition of the system of equations |
In this case the system of equation to solve is
\( \left\{ \begin{array}{c} \eta\nabla v_x + \partial_x P = 0 \quad Eq1 \\ \eta\nabla v_y + \partial_y P = 0 \quad Eq2 \\ \partial_x v_x + \partial_y v_y = 0 \quad Eq3 \end{array} \right. \)
and boundary conditions
\( \left\{ \begin{array}{c} v_x = 0, v_y = 0 \quad x = 0 \quad B1\\ v_x = 0, v_y = 1.0 \quad x = L \quad B2\\ v_x = 0, v_y = 0 \quad y = 0 \quad B3\\ v_x = 0, v_y = 0 \quad y = L \quad B4\\ \end{array} \right. \)
with \(v_x\) and \(v_y\) the velocity in x and y and \(P\) Pressure
In order to solve such system first we define the general properties of the system
A 3D case is given in the examples
Definition at line 126 of file FDScheme.hpp.
#include <FDScheme.hpp>
Data Structures | |
struct | constant_b |
Encapsulation of the b term as constant. More... | |
struct | grid_b |
Encapsulation of the b term as grid. More... | |
struct | key_and_eq |
Equation id + space position. More... | |
Public Types | |
typedef grid_dist_id< Sys_eqs::dims, typename Sys_eqs::stype, aggregate< size_t >, typename Sys_eqs::b_grid::decomposition::extended_type > | g_map_type |
Distributed grid map. | |
typedef Sys_eqs | Sys_eqs_typ |
Type that specify the properties of the system of equations. | |
Public Member Functions | |
void | setStagPos (comb< Sys_eqs::dims >(&sp)[Sys_eqs::nvar]) |
set the staggered position for each property | |
void | computeStag () |
compute the staggered position for each property | |
const Padding< Sys_eqs::dims > & | getPadding () |
Get the specified padding. | |
const g_map_type & | getMap () |
Return the map between the grid index position and the position in the distributed vector. | |
FDScheme (const Ghost< Sys_eqs::dims, long int > &stencil, const Box< Sys_eqs::dims, typename Sys_eqs::stype > &domain, const typename Sys_eqs::b_grid &b_g) | |
Constructor. | |
FDScheme (Padding< Sys_eqs::dims > &pd, const Ghost< Sys_eqs::dims, long int > &stencil, const Box< Sys_eqs::dims, typename Sys_eqs::stype > &domain, const typename Sys_eqs::b_grid &b_g) | |
Constructor. | |
template<typename T > | |
void | impose (const T &op, typename Sys_eqs::stype num, long int id, const long int(&start)[Sys_eqs::dims], const long int(&stop)[Sys_eqs::dims], bool skip_first=false) |
Impose an operator. | |
void | new_b () |
In case we want to impose a new b re-using FDScheme we have to call This function. | |
void | new_A () |
In case we want to impose a new A re-using FDScheme we have to call This function. | |
template<unsigned int prp, typename b_term , typename iterator > | |
void | impose_dit_b (b_term &b_t, const iterator &it_d, long int id=0) |
Impose an operator. | |
template<typename T > | |
void | impose_dit (const T &op, typename Sys_eqs::stype num, long int id, grid_dist_iterator_sub< Sys_eqs::dims, typename g_map_type::d_grid > it_d) |
Impose an operator. | |
template<typename T , typename bop , typename iterator > | |
void | impose_git_gmap (const T &op, bop num, long int id, iterator &it) |
Impose an operator. | |
template<typename T , typename bop , typename iterator > | |
void | impose_git (const T &op, bop num, long int id, const iterator &it_d, bool skip_first=false) |
Impose an operator. | |
template<unsigned int prp, typename T , typename b_term , typename iterator > | |
void | impose_dit (const T &op, b_term &b_t, const iterator &it_d, long int id=0) |
Impose an operator. | |
Sys_eqs::SparseMatrix_type & | getA () |
produce the Matrix | |
Sys_eqs::Vector_type & | getB () |
produce the B vector | |
template<unsigned int ... pos, typename Vct , typename Grid_dst > | |
void | copy (Vct &v, const long int(&start)[Sys_eqs_typ::dims], const long int(&stop)[Sys_eqs_typ::dims], Grid_dst &g_dst) |
Copy the vector into the grid. | |
template<unsigned int ... pos, typename Vct , typename Grid_dst > | |
void | copy (Vct &v, Grid_dst &g_dst) |
Copy the vector into the grid. | |
Data Fields | |
Sys_eqs::SparseMatrix_type | A |
type of the sparse matrix | |
Private Types | |
typedef Sys_eqs::SparseMatrix_type::triplet_type | triplet |
Sparse matrix triplet type. | |
Private Member Functions | |
key_and_eq | from_row_to_key (size_t row) |
From the row Matrix position to the spatial position. | |
const std::vector< size_t > | padding (const size_t(&sz)[Sys_eqs::dims], Padding< Sys_eqs::dims > &pd) |
calculate the mapping grid size with padding | |
void | consistency () |
Check if the Matrix is consistent. | |
template<typename Vct , typename Grid_dst , unsigned int ... pos> | |
void | copy_staggered (Vct &v, Grid_dst &g_dst, grid_key_dx< Grid_dst::dims > &start_d, grid_key_dx< Grid_dst::dims > &stop_d) |
Copy a given solution vector in a staggered grid. | |
template<typename Vct , typename Grid_dst , unsigned int ... pos> | |
void | copy_normal (Vct &v, Grid_dst &g_dst) |
Copy a given solution vector in a normal grid. | |
template<typename bop , typename iterator > | |
void | impose_dit_b (bop num, long int id, const iterator &it_d) |
Impose an operator. | |
template<typename T , typename bop , typename iterator > | |
void | impose_dit (const T &op, bop num, long int id, const iterator &it_d) |
Impose an operator. | |
void | construct_gmap () |
Construct the gmap structure. | |
void | Initialize (const Box< Sys_eqs::dims, typename Sys_eqs::stype > &domain) |
Private Attributes | |
Padding< Sys_eqs::dims > | pd |
Padding. | |
Sys_eqs::Vector_type | b |
Vector b. | |
const grid_sm< Sys_eqs::dims, void > & | gs |
Domain Grid informations. | |
Sys_eqs::stype | spacing [Sys_eqs::dims] |
Get the grid spacing. | |
g_map_type | g_map |
mapping grid | |
size_t | row |
row of the matrix | |
size_t | row_b |
row on b | |
openfpm::vector< size_t > | pnt |
Grid points that has each processor. | |
comb< Sys_eqs::dims > | s_pos [Sys_eqs::nvar] |
Staggered position for each property. | |
size_t | s_pnt |
typedef grid_dist_id<Sys_eqs::dims,typename Sys_eqs::stype,aggregate<size_t>,typename Sys_eqs::b_grid::decomposition::extended_type> FDScheme< Sys_eqs >::g_map_type |
Distributed grid map.
Definition at line 131 of file FDScheme.hpp.
typedef Sys_eqs FDScheme< Sys_eqs >::Sys_eqs_typ |
Type that specify the properties of the system of equations.
Definition at line 134 of file FDScheme.hpp.
|
private |
Sparse matrix triplet type.
Definition at line 202 of file FDScheme.hpp.
|
inline |
Constructor.
The periodicity is given by the grid b_g
stencil | maximum extension of the stencil on each directions |
domain | the domain |
b_g | object grid that will store the solution |
Definition at line 694 of file FDScheme.hpp.
|
inline |
Constructor.
The periodicity is given by the grid b_g
pd | Padding, how many points out of boundary are present |
stencil | maximum extension of the stencil on each directions |
domain | the domain |
b_g | object grid that will store the solution |
Definition at line 712 of file FDScheme.hpp.
|
inline |
compute the staggered position for each property
This is compute from the value_type stored by Sys_eqs::b_grid::value_type the position of the staggered properties
Definition at line 652 of file FDScheme.hpp.
|
inlineprivate |
Check if the Matrix is consistent.
Definition at line 297 of file FDScheme.hpp.
|
inlineprivate |
Construct the gmap structure.
Definition at line 565 of file FDScheme.hpp.
|
inline |
Copy the vector into the grid.
scheme | Discretization scheme |
Grid_dst | type of the target grid |
pos | target properties |
v | Vector that contain the solution of the system |
start | point |
stop | point |
g_dst | Destination grid |
Definition at line 1079 of file FDScheme.hpp.
|
inline |
Copy the vector into the grid.
scheme | Discretization scheme |
Grid_dst | type of the target grid |
pos | target properties |
v | Vector that contain the solution of the system |
g_dst | Destination grid |
Definition at line 1141 of file FDScheme.hpp.
|
inlineprivate |
Copy a given solution vector in a normal grid.
Vct | Vector type |
Grid_dst | target grid |
pos | set of property |
v | Vector |
g_dst | target normal grid |
Definition at line 397 of file FDScheme.hpp.
|
inlineprivate |
Copy a given solution vector in a staggered grid.
Vct | Vector type |
Grid_dst | target grid |
pos | set of properties |
v | Vector |
g_dst | target staggered grid |
Definition at line 353 of file FDScheme.hpp.
|
inlineprivate |
From the row Matrix position to the spatial position.
row | Matrix row |
Definition at line 253 of file FDScheme.hpp.
|
inline |
|
inline |
|
inline |
Return the map between the grid index position and the position in the distributed vector.
It is the map explained in the intro of the FDScheme
Definition at line 680 of file FDScheme.hpp.
|
inline |
Get the specified padding.
Definition at line 668 of file FDScheme.hpp.
|
inline |
Impose an operator.
This function impose an operator on a box region to produce the system
Ax = b
op | Operator to impose (A term) |
num | right hand side of the term (b term) |
id | Equation id in the system that we are imposing |
start | starting point of the box |
stop | stop point of the box |
skip_first | skip the first point |
Definition at line 738 of file FDScheme.hpp.
|
inline |
Impose an operator.
This function impose an operator on a particular grid region to produce the system
Ax = b
op | Operator to impose (A term) |
num | right hand side of the term (b term) |
id | Equation id in the system that we are imposing |
it_d | iterator that define where you want to impose |
Definition at line 1018 of file FDScheme.hpp.
|
inlineprivate |
Impose an operator.
This function impose an operator on a particular grid region to produce the system
Ax = b
op | Operator to impose (A term) |
num | right hand side of the term (b term) |
id | Equation id in the system that we are imposing |
it_d | iterator that define where you want to impose |
Definition at line 495 of file FDScheme.hpp.
|
inline |
Impose an operator.
This function impose an operator on a particular grid region to produce the system
Ax = b
op | Operator to impose (A term) |
num | right hand side of the term (b term) |
id | Equation id in the system that we are imposing |
it_d | iterator that define where you want to impose |
Definition at line 828 of file FDScheme.hpp.
|
inline |
Impose an operator.
This function impose an operator on a particular grid region to produce the system
Ax = b
op | Operator to impose (A term) |
num | right hand side of the term (b term) |
id | Equation id in the system that we are imposing |
it_d | iterator that define where you want to impose |
Definition at line 804 of file FDScheme.hpp.
|
inlineprivate |
Impose an operator.
This function the RHS no matrix is imposed. This function is usefull if the Matrix has been constructed and only the right hand side b must be changed
Ax = b
num | right hand side of the term (b term) |
id | Equation id in the system that we are imposing |
it_d | iterator that define where you want to impose |
Definition at line 454 of file FDScheme.hpp.
|
inline |
Impose an operator.
This function impose an operator on a particular grid region to produce the system
Ax = b
op | Operator to impose (A term) |
num | right hand side of the term (b term) |
id | Equation id in the system that we are imposing |
it_d | iterator that define where you want to impose |
Definition at line 929 of file FDScheme.hpp.
|
inline |
Impose an operator.
This function impose an operator on a particular grid region to produce the system
Ax = b
op | Operator to impose (A term) |
num | right hand side of the term (b term) |
id | Equation id in the system that we are imposing |
it_d | iterator that define where you want to impose |
Definition at line 853 of file FDScheme.hpp.
|
inlineprivate |
\initialize the object FDScheme
domain | simulation domain |
Definition at line 611 of file FDScheme.hpp.
|
inline |
In case we want to impose a new A re-using FDScheme we have to call This function.
Definition at line 785 of file FDScheme.hpp.
|
inline |
In case we want to impose a new b re-using FDScheme we have to call This function.
Definition at line 778 of file FDScheme.hpp.
|
inlineprivate |
calculate the mapping grid size with padding
sz | original grid size |
pd | padding |
Definition at line 284 of file FDScheme.hpp.
|
inline |
set the staggered position for each property
sp | vector containing the staggered position for each property |
Definition at line 639 of file FDScheme.hpp.
Sys_eqs::SparseMatrix_type FDScheme< Sys_eqs >::A |
type of the sparse matrix
Definition at line 1029 of file FDScheme.hpp.
|
private |
Vector b.
Definition at line 205 of file FDScheme.hpp.
|
private |
mapping grid
Definition at line 214 of file FDScheme.hpp.
Domain Grid informations.
Definition at line 208 of file FDScheme.hpp.
Definition at line 199 of file FDScheme.hpp.
|
private |
Grid points that has each processor.
Definition at line 223 of file FDScheme.hpp.
|
private |
row of the matrix
Definition at line 217 of file FDScheme.hpp.
|
private |
row on b
Definition at line 220 of file FDScheme.hpp.
|
private |
Each point in the grid has a global id, to decompose correctly the Matrix each processor contain a contiguos range of global id, example processor 0 can have from 0 to 234 and processor 1 from 235 to 512 no processors can have holes in the sequence, this number indicate where the sequence start for this processor
Definition at line 232 of file FDScheme.hpp.
Staggered position for each property.
Definition at line 226 of file FDScheme.hpp.
|
private |
Get the grid spacing.
Definition at line 211 of file FDScheme.hpp.