Advanced Multi-Physics (AMP)
On-Line Documentation
DiffusionFD.h
Go to the documentation of this file.
1#ifndef included_AMP_DiffusionFD
2#define included_AMP_DiffusionFD
3
4#include "AMP/IO/PIO.h"
5#include "AMP/discretization/boxMeshDOFManager.h"
6#include "AMP/geometry/Geometry.h"
7#include "AMP/geometry/shapes/Box.h"
8#include "AMP/matrices/MatrixBuilder.h"
9#include "AMP/mesh/Mesh.h"
10#include "AMP/mesh/MeshID.h"
11#include "AMP/mesh/structured/BoxMesh.h"
12#include "AMP/operators/LinearOperator.h"
13#include "AMP/operators/Operator.h"
14#include "AMP/utils/ArraySize.h"
15#include "AMP/vectors/Vector.h"
16#include "AMP/vectors/VectorBuilder.h"
17#include "ProfilerApp.h"
18
19
20namespace AMP::Operator {
21
22
23/* ------------------------------------------------------------------------------------------
24 Implementation of a finite-difference discretization of a constant-coefficient diffusion
25operator
26------------------------------------------------------------------------------------------- */
27
28/* Specifically, given a set of coefficients {cij}, the discretized operators are:
29 - In 1D:
30 -cxx*u_xx (3-point stencil)
31 - In 2D:
32 -(cxx*u_xx + cyy*u_yy + cyx*u_yx) (9-point stencil)
33 - In 3D:
34 -(cxx*u_xx + cyy*u_yy + czz*u_zz + cyx*u_yx + czx*u_zx + czy*u_yz) (19-point stencil)
35
36 - Mixed derivatives are discretized with central finite differences (as opposed to upwind)
37 - The incoming database must specify the constants cij
38 - The mesh in the incoming OperatorParamaters must be a BoxMesh build from a cube generator
39 - This class provides the functionality to construct a RHS vector, given the source term on the
40 RHS of the PDE and Dirichlet boundary function
41 - Dirichlet boundary conditions are not eliminated; instead, boundary rows in the matrix are
42 some scaled identity (with the constant equal to the diagonal entry in the discretization
43 stencil)
44 - Note that, technically, any second-order, constant-coefficient PDEs of the form specific above
45 can be discretized with this class. I.e., this class does not enforce any requirement that the
46 PDE be elliptic (determinant[PDE operator] < 0).
47*/
48
50{
51
52 //
53private:
55 size_t d_dim = static_cast<size_t>( -1 );
56
58 std::shared_ptr<AMP::Mesh::BoxMesh> d_BoxMesh = nullptr;
59
61 static constexpr auto VertexGeom = AMP::Mesh::GeomType::Vertex;
62
64 std::vector<double> d_h;
65
66 //
67public:
68 std::shared_ptr<AMP::Database> d_db;
69 std::shared_ptr<AMP::Discretization::boxMeshDOFManager> d_DOFMan;
70
71 // Constructor
72 DiffusionFDOperator( std::shared_ptr<const AMP::Operator::OperatorParameters> params_ );
73
74 // Destructor
76
77 // Used by OperatorFactory to create a DiffusionFDOperator
78 static std::unique_ptr<AMP::Operator::Operator>
79 create( std::shared_ptr<AMP::Operator::OperatorParameters> params )
80 {
81 return std::make_unique<DiffusionFDOperator>( params );
82 };
83
84 // Used to register this operator in a factory
85 std::string type() const override { return "DiffusionFDOperator"; }
86
87 /* Create RHS vector consistent with the linear operator. Here:
88 1. PDESourceFun is a function returning the PDE source term
89 2. boundaryFun is a function returning the Dirichlet boundary value at the given location on
90 the given boundary */
91 std::shared_ptr<AMP::LinearAlgebra::Vector> createRHSVector(
92 std::function<double( const AMP::Mesh::Point & )> PDESourceFun,
93 std::function<double( const AMP::Mesh::Point &, int boundary_id )> boundaryFun );
94
95 // Populate a vector with the given function
96 void fillVectorWithFunction( std::shared_ptr<AMP::LinearAlgebra::Vector> u,
97 std::function<double( const AMP::Mesh::Point & )> fun ) const;
98
99 // Vector of hx, hy, hz
100 const std::vector<double> &getMeshSize() const;
101
102
103 // Data
104private:
106 std::shared_ptr<std::vector<double>> d_stencil = nullptr;
107
109 std::shared_ptr<AMP::Mesh::BoxMesh::Box> d_localBox = nullptr;
110
112 std::shared_ptr<AMP::Mesh::BoxMesh::Box> d_globalBox = nullptr;
113
115 std::shared_ptr<AMP::ArraySize> d_localArraySize = nullptr;
116
118 std::array<size_t, 5> d_ijk;
119
120 //
121private:
122 // Build and set d_DOFMan
124
125 // FD stencil
126 std::vector<double> createStencil() const;
127
129 void getCSRData( size_t row, std::vector<size_t> &cols, std::vector<double> &data );
130
135 void getCSRDataInterior( std::array<size_t, 5> &ijkLocal,
136 size_t rowLocal,
137 std::vector<size_t> &cols,
138 std::vector<double> &data ) const;
139
144 void
145 getCSRDataBoundary( size_t row, std::vector<size_t> &cols, std::vector<double> &data ) const;
146
147
148 // Fill CSR matrix with data
149 void fillMatrixWithCSRData( std::shared_ptr<AMP::LinearAlgebra::Matrix> matrix );
150
151 // Assemble matrix
152 std::shared_ptr<AMP::LinearAlgebra::Matrix> createDiscretizationMatrix();
153
155 size_t gridIndsToDOF( std::array<int, 3> ijk ) const;
156
158 std::array<int, 3> DOFToGridInds( size_t dof ) const;
159
165
168};
169} // namespace AMP::Operator
170
171
172#endif
Structure to identify a logical box.
Definition BoxMesh.h:79
std::shared_ptr< AMP::ArraySize > d_localArraySize
ArraySize of the local box.
size_t d_dim
Problem dimension.
Definition DiffusionFD.h:55
DiffusionFDOperator(std::shared_ptr< const AMP::Operator::OperatorParameters > params_)
std::shared_ptr< std::vector< double > > d_stencil
FD coefficients.
std::shared_ptr< AMP::Database > d_db
Definition DiffusionFD.h:68
const std::vector< double > & getMeshSize() const
void fillMatrixWithCSRData(std::shared_ptr< AMP::LinearAlgebra::Matrix > matrix)
std::vector< double > createStencil() const
void getCSRDataBoundary(size_t row, std::vector< size_t > &cols, std::vector< double > &data) const
std::shared_ptr< AMP::Discretization::boxMeshDOFManager > d_DOFMan
Definition DiffusionFD.h:69
void fillVectorWithFunction(std::shared_ptr< AMP::LinearAlgebra::Vector > u, std::function< double(const AMP::Mesh::Point &)> fun) const
std::shared_ptr< AMP::LinearAlgebra::Matrix > createDiscretizationMatrix()
std::array< int, 3 > DOFToGridInds(size_t dof) const
Get grid indices corresponding to the DOF.
std::shared_ptr< AMP::Mesh::BoxMesh::Box > d_localBox
Local grid index box w/ zero ghosts.
size_t gridIndsToDOF(std::array< int, 3 > ijk) const
Map from grid index ijk to the corresponding DOF.
std::array< size_t, 5 > d_ijk
Placeholder array of grid indices.
void getCSRData(size_t row, std::vector< size_t > &cols, std::vector< double > &data)
Pack cols+data vectors in given row.
AMP::Mesh::BoxMesh::Box getLocalNodeBox() const
Convert a local element box to a local node box.
std::string type() const override
Return the name of the operator.
Definition DiffusionFD.h:85
AMP::Mesh::BoxMesh::Box getGlobalNodeBox() const
std::shared_ptr< AMP::Mesh::BoxMesh > d_BoxMesh
Mesh.
Definition DiffusionFD.h:58
static constexpr auto VertexGeom
Convenience member.
Definition DiffusionFD.h:61
std::vector< double > d_h
Mesh sizes, hx, hy, hz. We compute these based on the incoming mesh.
Definition DiffusionFD.h:64
void getCSRDataInterior(std::array< size_t, 5 > &ijkLocal, size_t rowLocal, std::vector< size_t > &cols, std::vector< double > &data) const
std::shared_ptr< AMP::Mesh::BoxMesh::Box > d_globalBox
Global grid index box w/ zero ghosts.
static std::unique_ptr< AMP::Operator::Operator > create(std::shared_ptr< AMP::Operator::OperatorParameters > params)
Definition DiffusionFD.h:79
std::shared_ptr< AMP::LinearAlgebra::Vector > createRHSVector(std::function< double(const AMP::Mesh::Point &)> PDESourceFun, std::function< double(const AMP::Mesh::Point &, int boundary_id)> boundaryFun)
std::shared_ptr< AMP::Operator::Operator > shared_ptr
Definition Operator.h:29



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page