GradientStencil
The GradientStencil is the storage container for storing the gradient stencil components. It stores only non-zero stencil components for 1D, 2D and 3D stencils and offers iterators allowing convenient evaluation of the gradient operators which is beneficial for compact stencils.
The GradientStencil can be initialized to use the following stencils:
Simple- simple stencils in 1D, 2D and 3D.Isotropic- isotropic stencils in 1D, 2D and 3D.LB- isotropic stencils based on lattice Boltzmann stencils.
The available stencils for 1D, 2D and 3D cases are given below. Note that 1D and 2D stencils for convenience defined in 3D arrays but should only be used with inactive dimensions suppressed. Also, the gradient stencils have no negative coefficients and their respective components should be multiplied by -1 manually at the point of use.
Simple gradient stencil
cppconst double GradientStencil1D[3][3][3] = {{{ 0.0, 0.0, 0.0}, { 0.0, 0.5, 0.0}, { 0.0, 0.0, 0.0}}, {{ 0.0, 0.5, 0.0}, { 0.5, 0.0, 0.5}, { 0.0, 0.5, 0.0}}, {{ 0.0, 0.0, 0.0}, { 0.0, 0.5, 0.0}, { 0.0, 0.0, 0.0}}};2-point simple 1D/2D/3D Gradient stencil (standard finite differences stencil)
Isotropic gradient stencils
cppconst double GradientStencil2D[3][3][3] = {{{ 0.0, 1.0/12.0, 0.0}, { 1.0/12.0, 1.0/3.0, 1.0/12.0}, { 0.0, 1.0/12.0, 0.0}}, {{ 1.0/12.0, 1.0/3.0, 1.0/12.0}, { 1.0/3.0, 0.0, 1.0/3.0}, { 1.0/12.0, 1.0/3.0, 1.0/12.0}}, {{ 0.0, 1.0/12.0, 0.0}, { 1.0/12.0, 1.0/3.0, 1.0/12.0}, { 0.0, 1.0/12.0, 0.0}}};8-point 2D gradient stencil from "M.Alfaraj, Y. Wang and Y. Luo, Geophysical prospecting 62 (2014) 507-517"
cppconst double GradientStencil2D_2[3][3][3] = {{{ 0.0, 0.125, 0.0}, { 0.125, 0.25, 0.125}, { 0.0, 0.125, 0.0}}, {{ 0.125, 0.25, 0.125}, { 0.25, 0.0, 0.25}, { 0.125, 0.25, 0.125}}, {{ 0.0, 0.125, 0.0}, { 0.125, 0.25, 0.125}, { 0.0, 0.125, 0.0}}};8 point 2D gradient stencil by Sobel
cppconst double GradientStencil3D[3][3][3] = {{{ 0.085/4.64, 0.245/4.64, 0.085/4.64}, { 0.245/4.64, 1.0/4.64, 0.245/4.64}, { 0.085/4.64, 0.245/4.64, 0.085/4.64}}, {{ 0.245/4.64, 1.0/4.64, 0.245/4.64}, { 1.0/4.64, 0.0, 1.0/4.64}, { 0.245/4.64, 1.0/4.64, 0.245/4.64}}, {{ 0.085/4.64, 0.245/4.64, 0.085/4.64}, { 0.245/4.64, 1.0/4.64, 0.245/4.64}, { 0.085/4.64, 0.245/4.64, 0.085/4.64}}};26 point 3D Gradient stencil from "M.Alfaraj, Y. Wang and Y. Luo, Geophysical prospecting 62 (2014) 507-517".
Gradient stencils based on lattice Boltzmann stencils
cppconst double GradientStencil2D_LB[3][3][3] = {{{ 0.0, 1.0/12.0, 0.0}, {1.0/12.0, 1.0/3.0, 1.0/12.0}, { 0.0, 1.0/12.0, 0.0}}, {{1.0/12.0, 1.0/3.0, 1.0/12.0}, {1.0/3.0, 0.0, 1.0/3.0}, {1.0/12.0, 1.0/3.0, 1.0/12.0}}, {{ 0.0, 1.0/12.0, 0.0}, {1.0/12.0, 1.0/3.0, 1.0/12.0}, { 0.0, 1.0/12.0, 0.0}}};Isotropic gradient stencil based on the
D2Q9lattice Boltzmann stencil. It is the same as the 8 point 2D gradient stencil from "M.Alfaraj, Y. Wang and Y. Luo, Geophysical prospecting 62 (2014) 507-517".
cppconst double GradientStencil3D_LB[3][3][3] = {{{1.0/72.0, 1.0/18.0, 1.0/72.0}, {1.0/18.0, 2.0/9.0, 1.0/18.0}, {1.0/72.0, 1.0/18.0, 1.0/72.0}}, {{1.0/18.0, 2.0/9.0, 1.0/18.0}, {2.0/9.0, 0.0, 2.0/9.0}, {1.0/18.0, 2.0/9.0, 1.0/18.0}}, {{1.0/72.0, 1.0/18.0, 1.0/72.0}, {1.0/18.0, 2.0/9.0, 1.0/18.0}, {1.0/72.0, 1.0/18.0, 1.0/72.0}}};Isotropic gradient stencil based on the
D3Q27lattice Boltzmann stencil. It is very close to the 27 point 2D gradient stencil from "M.Alfaraj, Y. Wang and Y. Luo, Geophysical prospecting 62 (2014) 507-517".
GradientStencilEntry
The stencil components inside of the GradientStencil are stored using the corresponding GradientStencilEntry structure which contains three stencil direction coordinates and their weights:
cppint di;X coordinate of the stencil element.
cppint dj;Y coordinate of the stencil element.
cppint dk;Z coordinate of the stencil element.
cppdouble weightX;Weight associated with the X component of the stencil element.
cppdouble weightY;Weight associated with the Y component of the stencil element.
cppdouble weightZ;Weight associated with the Z component of the stencil element.
GradientStencil construction methods
cppvoid Set(const double UserStencil[3][3][3], double dx, int dNx = 1, int dNy = 1, int dNz = 1);Sets nonzero stencil entries for gradient components using user specified stencil.
dNx,dNyanddNzare used to enable or suppress the stencil components for correpsonding dimensionX,Yand/orZ. The value0suppresses the corresponding stencil components, value1enables them.
cppvoid Set(const double UserStencil[3][3][3], GridParameters& Dimensions)Sets nonzero stencil entries for gradient components using user specified stencil.
Container properties
cppsize_t size() const;Returns the size of the stencil storage (considers only non-zero entries).
Iterators
cppiterator begin();Iterator to the begin of the stencil.
cppiterator end();Iterator to the end of the stencil.
cppciterator cbegin() const;Constant iterator to the begin of the stencil.
cppciterator cend() const;Constant iterator to the end of the stencil.
Data manipulation methods
cppiterator erase(iterator it);Erases the entry pointed to by the given iterator
it.