1#ifndef RAD_DIF_FD_DISCRETIZATION
2#define RAD_DIF_FD_DISCRETIZATION
4#include "AMP/IO/AsciiWriter.h"
6#include "AMP/discretization/MultiDOF_Manager.h"
7#include "AMP/discretization/boxMeshDOFManager.h"
8#include "AMP/geometry/shapes/Box.h"
9#include "AMP/matrices/MatrixBuilder.h"
10#include "AMP/mesh/structured/BoxMesh.h"
11#include "AMP/mesh/structured/structuredMeshElement.h"
12#include "AMP/operators/LinearOperator.h"
13#include "AMP/operators/Operator.h"
14#include "AMP/operators/OperatorParameters.h"
15#include "AMP/utils/AMPManager.h"
16#include "AMP/vectors/MultiVector.h"
17#include "AMP/vectors/Vector.h"
18#include "AMP/vectors/VectorBuilder.h"
62class RadDifCoefficients;
64class FDMeshGlobalIndexingOps;
69class RadDifOpPJacParameters;
70struct RadDifOpPJacData;
92 static double diffusionE(
double k11,
double T,
double zatom );
120 static constexpr size_t WEST = 0;
122 static constexpr size_t EAST = 2;
136 std::shared_ptr<AMP::Mesh::BoxMesh> &d_BoxMesh,
139 std::shared_ptr<AMP::Discretization::DOFManager> &d_scalarDOFMan,
140 std::shared_ptr<AMP::Discretization::multiDOFManager> &d_multiDOFMan,
141 std::shared_ptr<AMP::Mesh::BoxMesh::Box> &d_globalBox,
142 std::shared_ptr<AMP::Mesh::BoxMesh::Box> &d_localBox,
143 std::shared_ptr<AMP::ArraySize> &d_localArraySize,
144 std::vector<double> &d_h,
145 std::vector<double> &d_rh2 );
160 template<
bool computeE,
bool computeT>
162 std::array<double, 3> &TLoc3,
177 std::shared_ptr<AMP::Mesh::BoxMesh> &mesh,
178 std::shared_ptr<AMP::Discretization::DOFManager> &scalarDOFMan,
179 std::shared_ptr<AMP::Discretization::multiDOFManager> &multiDOFMan );
193 static constexpr size_t WEST = 0;
195 static constexpr size_t EAST = 2;
210 std::shared_ptr<AMP::Discretization::DOFManager> scalarDOFMan,
211 std::shared_ptr<AMP::Discretization::multiDOFManager> multiDOFMan );
231 static constexpr std::string_view
a_keys[] = {
"a1",
"a2",
"a3",
"a4",
"a5",
"a6" };
232 static constexpr std::string_view
b_keys[] = {
"b1",
"b2",
"b3",
"b4",
"b5",
"b6" };
233 static constexpr std::string_view
r_keys[] = {
"r1",
"r2",
"r3",
"r4",
"r5",
"r6" };
234 static constexpr std::string_view
n_keys[] = {
"n1",
"n2",
"n3",
"n4",
"n5",
"n6" };
284 const std::function<
double(
double T )> &cHandle,
321 static double ghostValueSolveE(
double a,
double b,
double r,
double c,
double h,
double Eint );
372 std::shared_ptr<AMP::Database>
d_db =
nullptr;
378 RadDifOp( std::shared_ptr<const AMP::Operator::OperatorParameters> params );
382 std::string
type()
const override {
return "RadDifOp"; };
385 void apply( std::shared_ptr<const AMP::LinearAlgebra::Vector>
ET,
386 std::shared_ptr<AMP::LinearAlgebra::Vector>
LET )
override;
439 std::shared_ptr<AMP::Mesh::BoxMesh::Box>
d_localBox =
nullptr;
452 static constexpr size_t WEST = 0;
454 static constexpr size_t EAST = 2;
463 std::shared_ptr<const AMP::LinearAlgebra::Vector>
T_vec,
464 std::shared_ptr<AMP::LinearAlgebra::Vector>
LE_vec,
465 std::shared_ptr<AMP::LinearAlgebra::Vector>
LT_vec );
469 std::shared_ptr<const AMP::LinearAlgebra::Vector>
T_vec,
470 std::shared_ptr<AMP::LinearAlgebra::Vector>
LE_vec,
471 std::shared_ptr<AMP::LinearAlgebra::Vector>
LT_vec );
506 std::shared_ptr<const AMP::LinearAlgebra::Vector>
T_vec,
507 std::array<size_t, 3> &ijk,
509 std::array<double, 3> &
ELoc3,
510 std::array<double, 3> &
TLoc3 );
538 std::shared_ptr<AMP::Operator::OperatorParameters>
555 std::shared_ptr<AMP::Database>
d_db =
nullptr;
557 std::shared_ptr<RadDifOpPJacData>
d_data =
nullptr;
571 static std::unique_ptr<AMP::Operator::Operator>
572 create( std::shared_ptr<AMP::Operator::OperatorParameters> params )
574 return std::make_unique<RadDifOpPJac>( params );
582 void reset( std::shared_ptr<const AMP::Operator::OperatorParameters> params )
override;
584 std::string
type()
const override {
return "RadDifOpPJac"; };
587 void apply( std::shared_ptr<const AMP::LinearAlgebra::Vector>
ET,
588 std::shared_ptr<AMP::LinearAlgebra::Vector>
LET )
override;
627 std::shared_ptr<AMP::Mesh::BoxMesh::Box>
d_localBox =
nullptr;
648 static constexpr size_t WEST = 0;
650 static constexpr size_t EAST = 2;
658 std::shared_ptr<AMP::LinearAlgebra::Vector>
LET_ );
673 template<
size_t Component>
690 template<
size_t Component>
692 std::shared_ptr<const AMP::LinearAlgebra::Vector>
T_vec,
696 std::vector<size_t> &cols,
697 std::vector<double> &data );
702 template<
size_t Component>
708 std::vector<double> &data );
711 template<
size_t Component>
713 std::shared_ptr<const AMP::LinearAlgebra::Vector>
T_vec,
715 std::vector<size_t> &cols,
716 std::vector<double> &data );
765 std::shared_ptr<const AMP::LinearAlgebra::Vector>
E_vec,
766 std::shared_ptr<const AMP::LinearAlgebra::Vector>
T_vec,
767 std::array<size_t, 3> &ijk,
769 std::array<double, 3> &
ELoc3,
770 std::array<double, 3> &
TLoc3,
807 std::tuple<std::shared_ptr<AMP::LinearAlgebra::Matrix>,
808 std::shared_ptr<AMP::LinearAlgebra::Matrix>,
809 std::shared_ptr<AMP::LinearAlgebra::Vector>,
810 std::shared_ptr<AMP::LinearAlgebra::Vector>,
811 std::shared_ptr<AMP::LinearAlgebra::Vector>,
812 std::shared_ptr<AMP::LinearAlgebra::Vector>>
822 std::shared_ptr<AMP::LinearAlgebra::Matrix>
d_E =
nullptr;
823 std::shared_ptr<AMP::LinearAlgebra::Matrix>
d_T =
nullptr;
824 std::shared_ptr<AMP::LinearAlgebra::Vector>
r_EE =
nullptr;
825 std::shared_ptr<AMP::LinearAlgebra::Vector>
r_ET =
nullptr;
826 std::shared_ptr<AMP::LinearAlgebra::Vector>
r_TE =
nullptr;
827 std::shared_ptr<AMP::LinearAlgebra::Vector>
r_TT =
nullptr;
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
std::shared_ptr< const Vector > const_shared_ptr
A derived class used to define a mesh element.
static size_t getBoundaryIDFromDim(size_t dim, BoundarySide side)
FDBoundaryUtils()=delete
Prevent instantiation.
static size_t getDimFromBoundaryID(size_t boundaryID)
static void ghostValuesSolve(double a, double b, const std::function< double(double T)> &cHandle, double r, double n, double h, double Eint, double Tint, double &Eg, double &Tg)
static constexpr std::string_view n_keys[]
BoundarySide
Defines a boundary in a given dimension (WEST is the first boundary, and EAST the second)
static constexpr std::string_view b_keys[]
static double ghostValueSolveT(double n, double h, double Tint)
static constexpr std::string_view a_keys[]
Keys used to access db constants.
static constexpr std::string_view r_keys[]
static double ghostValueSolveE(double a, double b, double r, double c, double h, double Eint)
static void getBCConstantsFromDB(const AMP::Database &db, size_t boundaryID, double &ak, double &bk, double &rk, double &nk)
std::shared_ptr< AMP::Discretization::DOFManager > d_scalarDOFMan
DOFManager for E and T individually.
AMP::Mesh::structuredMeshElement gridIndsToMeshElement(const std::array< size_t, 3 > &ijk) const
Map from grid index to a MeshElement.
std::shared_ptr< AMP::Discretization::multiDOFManager > d_multiDOFMan
MultiDOFManager for managing [E,T] multivectors.
static constexpr size_t EAST
static constexpr size_t ORIGIN
AMP::Mesh::GeomType d_geom
Geometry type.
static constexpr size_t WEST
Indices used for referencing WEST, ORIGIN, and EAST entries in Loc3 data structures.
std::array< size_t, 3 > scalarDOFToGridInds(size_t dof) const
Map from scalar DOF to grid indices i, j, k.
std::shared_ptr< AMP::Mesh::BoxMesh > d_BoxMesh
Mesh; keep a pointer to save having to downcast repeatedly.
size_t gridIndsToScalarDOF(const std::array< size_t, 3 > &ijk) const
Map from grid index to a the corresponding DOF.
FDMeshGlobalIndexingOps(std::shared_ptr< AMP::Mesh::BoxMesh > BoxMesh, AMP::Mesh::GeomType &geom, std::shared_ptr< AMP::Discretization::DOFManager > scalarDOFMan, std::shared_ptr< AMP::Discretization::multiDOFManager > multiDOFMan)
FDMeshOps()=delete
Prevent instantiation.
static constexpr bool IsFluxLimited
Flag indicating whether energy diffusion coefficient is limited.
static constexpr size_t EAST
static void createMeshData(std::shared_ptr< AMP::Mesh::Mesh > mesh, std::shared_ptr< AMP::Mesh::BoxMesh > &d_BoxMesh, size_t &d_dim, AMP::Mesh::GeomType &d_CellCenteredGeom, std::shared_ptr< AMP::Discretization::DOFManager > &d_scalarDOFMan, std::shared_ptr< AMP::Discretization::multiDOFManager > &d_multiDOFMan, std::shared_ptr< AMP::Mesh::BoxMesh::Box > &d_globalBox, std::shared_ptr< AMP::Mesh::BoxMesh::Box > &d_localBox, std::shared_ptr< AMP::ArraySize > &d_localArraySize, std::vector< double > &d_h, std::vector< double > &d_rh2)
Create mesh-related data given the mesh.
static constexpr size_t WEST
Indices used for referencing WEST, ORIGIN, and EAST entries in Loc3 data structures.
static void FaceDiffusionCoefficients(std::array< double, 3 > &ELoc3, std::array< double, 3 > &TLoc3, double k11, double k21, double zatom, double h, double *Dr_WO, double *Dr_OE, double *DT_WO, double *DT_OE)
static constexpr size_t ORIGIN
static void createDOFManagers(const AMP::Mesh::GeomType &Geom, std::shared_ptr< AMP::Mesh::BoxMesh > &mesh, std::shared_ptr< AMP::Discretization::DOFManager > &scalarDOFMan, std::shared_ptr< AMP::Discretization::multiDOFManager > &multiDOFMan)
Create DOFManagers given the geometry and mesh.
std::shared_ptr< AMP::Operator::Operator > shared_ptr
static constexpr bool IsNonlinear
Flag indicating whether nonlinear or linear PDE coefficients are used.
static void reaction(double k12, double k22, double T, double zatom, double &REE, double &RET, double &RTE, double &RTT)
Compute reaction coefficients REE, RET, RTE, REE.
static double diffusionE(double k11, double T, double zatom)
static double diffusionT(double k21, double T)
RadDifCoefficients()=delete
Prevent instantiation.
std::function< double(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint)> d_robinFunctionE
RadDifOpPJacParameters(std::shared_ptr< AMP::Database > db)
std::function< double(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint)> d_pseudoNeumannFunctionT
AMP::LinearAlgebra::Vector::shared_ptr d_frozenSolution
virtual ~RadDifOpPJacParameters()
std::shared_ptr< AMP::Discretization::multiDOFManager > d_multiDOFMan
Mesh-related data.
std::shared_ptr< AMP::LinearAlgebra::Vector > createInputVector() const override
Create a multiVector of E and T over the mesh.
void getCSRDataDiffusionMatrixInterior(const double *E_rawData, const double *T_rawData, size_t rowLocal, std::array< size_t, 5 > &ijkLocal, std::vector< size_t > &colsLocal, std::vector< double > &data)
std::array< double, 3 > d_TLoc3
std::vector< double > d_h
Mesh sizes, hx, hy, hz. We compute these based on the incoming mesh.
void setDataReaction(std::shared_ptr< const AMP::LinearAlgebra::Vector > T_vec)
std::shared_ptr< FDMeshGlobalIndexingOps > d_meshIndexingOps
Mesh indexing functions.
std::string type() const override
Return the name of the operator.
std::array< size_t, 3 > d_dofsLoc3
Placeholder array for dofs we connect to in 3-point stencil.
std::vector< double > d_rh2
Reciprocal squares of mesh sizes.
void fillDiffusionMatrixWithData(std::shared_ptr< AMP::LinearAlgebra::Matrix > matrix)
AMP::LinearAlgebra::Vector::shared_ptr d_frozenVec
The vector the above operator is linearized about.
std::array< double, 3 > d_ELoc3
Placeholder arrays for values used in 3-point stencils.
void reset(std::shared_ptr< const AMP::Operator::OperatorParameters > params) override
void getCSRDataDiffusionMatrix(std::shared_ptr< const AMP::LinearAlgebra::Vector > E_vec, std::shared_ptr< const AMP::LinearAlgebra::Vector > T_vec, const double *E_rawData, const double *T_rawData, size_t row, std::vector< size_t > &cols, std::vector< double > &data)
std::array< double, 6 > d_rk
void apply(std::shared_ptr< const AMP::LinearAlgebra::Vector > ET, std::shared_ptr< AMP::LinearAlgebra::Vector > LET) override
Compute LET = L(ET)
size_t d_dim
Problem dimension.
AMP::Mesh::GeomType CellCenteredGeom
Placeholder for geometry that results in cell-centered data.
std::array< double, 6 > d_ak
static constexpr size_t ORIGIN
std::shared_ptr< AMP::Database > d_db
void applyWithOverwrittenDataIsValid()
std::shared_ptr< AMP::ArraySize > d_localArraySize
Local array size.
void getNNDataBoundary(std::shared_ptr< const AMP::LinearAlgebra::Vector > E_vec, std::shared_ptr< const AMP::LinearAlgebra::Vector > T_vec, std::array< size_t, 3 > &ijk, size_t dim, std::array< double, 3 > &ELoc3, std::array< double, 3 > &TLoc3, std::array< size_t, 3 > &dofsLoc3, std::optional< FDBoundaryUtils::BoundarySide > &boundaryIntersection)
static constexpr size_t EAST
std::shared_ptr< AMP::Mesh::BoxMesh > d_BoxMesh
Mesh; keep a pointer to save having to downcast repeatedly.
virtual ~RadDifOpPJac()
Destructor.
static constexpr size_t WEST
Indices used for referencing WEST, ORIGIN, and EAST entries in Loc3 data structures.
std::array< double, 6 > d_bk
std::shared_ptr< AMP::Mesh::BoxMesh::Box > d_localBox
Local grid index box w/ zero ghosts.
std::function< double(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint)> d_pseudoNeumannFunctionT
void applyFromData(std::shared_ptr< const AMP::LinearAlgebra::Vector > ET_, std::shared_ptr< AMP::LinearAlgebra::Vector > LET_)
Apply action of the operator utilizing its representation in d_data.
std::shared_ptr< AMP::Discretization::DOFManager > d_scalarDOFMan
DOFManager for E and T individually.
double PicardCorrectionCoefficient(size_t component, size_t boundaryID, double ck) const
static std::unique_ptr< AMP::Operator::Operator > create(std::shared_ptr< AMP::Operator::OperatorParameters > params)
Used by OperatorFactory to create a RadDifOpPJac.
std::array< double, 6 > d_nk
RadDifOpPJac(std::shared_ptr< const AMP::Operator::OperatorParameters > params_)
Constructor.
void setData()
Set our d_data member.
void getCSRDataDiffusionMatrixBoundary(std::shared_ptr< const AMP::LinearAlgebra::Vector > E_vec, std::shared_ptr< const AMP::LinearAlgebra::Vector > T_vec, size_t row, std::vector< size_t > &cols, std::vector< double > &data)
Get cols and data for given row, when the row lives on a process boundary.
std::shared_ptr< AMP::Mesh::BoxMesh::Box > d_globalBox
Global grid index box w/ zero ghosts.
bool d_applyWithOverwrittenDataIsValid
void ghostValuesSolveWrapper(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint, double Eint, double Tint, double &Eg, double &Tg)
std::function< double(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint)> d_robinFunctionE
std::shared_ptr< RadDifOpPJacData > d_data
Representation of this operator as a block 2x2 matrix.
const double d_k11
Constant scaling factors in the PDE.
std::array< size_t, 5 > d_ijk
Placeholder for grid indices. Size 5 is because ArraySize deals with 5 grid indcies.
std::array< double, 6 > d_bk
virtual ~RadDifOp()
Destructor.
void ghostValuesSolveWrapper(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint, double Eint, double Tint, double &Eg, double &Tg)
static constexpr size_t EAST
std::shared_ptr< const AMP::Discretization::DOFManager > getScalarDOFManager() const
DOFManager used for each of E and T.
std::shared_ptr< AMP::LinearAlgebra::Vector > createInputVector() const override
Create a multiVector of E and T over the mesh.
std::shared_ptr< FDMeshGlobalIndexingOps > d_meshIndexingOps
Mesh-indexing functions.
void applyBoundary(std::shared_ptr< const AMP::LinearAlgebra::Vector > E_vec, std::shared_ptr< const AMP::LinearAlgebra::Vector > T_vec, std::shared_ptr< AMP::LinearAlgebra::Vector > LE_vec, std::shared_ptr< AMP::LinearAlgebra::Vector > LT_vec)
Apply operator over DOFs living on the boundary of process.
void setBoundaryFunctionT(const std::function< double(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint)> &fn_)
Set the pseudo-Neumann return function for the temperature.
static constexpr size_t WEST
Indices used for referencing WEST, ORIGIN, and EAST entries in Loc3 data structures.
void apply(std::shared_ptr< const AMP::LinearAlgebra::Vector > ET, std::shared_ptr< AMP::LinearAlgebra::Vector > LET) override
Compute LET = L(ET)
void getNNDataBoundary(std::shared_ptr< const AMP::LinearAlgebra::Vector > E_vec, std::shared_ptr< const AMP::LinearAlgebra::Vector > T_vec, std::array< size_t, 3 > &ijk, size_t dim, std::array< double, 3 > &ELoc3, std::array< double, 3 > &TLoc3)
std::shared_ptr< AMP::ArraySize > d_localArraySize
Local array size.
std::array< double, 6 > d_nk
std::array< double, 6 > d_rk
void applyInterior(std::shared_ptr< const AMP::LinearAlgebra::Vector > E_vec, std::shared_ptr< const AMP::LinearAlgebra::Vector > T_vec, std::shared_ptr< AMP::LinearAlgebra::Vector > LE_vec, std::shared_ptr< AMP::LinearAlgebra::Vector > LT_vec)
Apply operator over DOFs living on the interior of process.
std::shared_ptr< AMP::Mesh::BoxMesh::Box > d_localBox
Local grid index box w/ zero ghosts.
const std::vector< double > & getMeshSize() const
Vector of hx, hy, hz.
std::string type() const override
Return the name of the operator.
std::function< double(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint)> d_robinFunctionE
std::shared_ptr< AMP::Database > d_db
Parameters required by the discretization.
std::array< double, 6 > d_ak
size_t d_dim
Problem dimension.
AMP::Mesh::GeomType CellCenteredGeom
Placeholder for geometry that results in cell-centered data.
const double d_k11
Constant scaling factors in the PDE.
std::function< double(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint)> d_pseudoNeumannFunctionT
bool isValidVector(std::shared_ptr< const AMP::LinearAlgebra::Vector > ET) override
E and T must be positive.
void setBoundaryFunctionE(const std::function< double(size_t boundaryID, const AMP::Mesh::Point &boundaryPoint)> &fn_)
Set the Robin return function for the energy.
std::shared_ptr< AMP::Discretization::DOFManager > d_scalarDOFMan
DOFManager for E and T individually.
std::shared_ptr< AMP::Mesh::BoxMesh > d_BoxMesh
Mesh; keep a pointer to save having to downcast repeatedly.
std::vector< double > d_rh2
Reciprocal squares of mesh sizes.
RadDifOp(std::shared_ptr< const AMP::Operator::OperatorParameters > params)
Constructor.
static constexpr size_t ORIGIN
AMP::Mesh::GeomType getGeomType() const
Geometry used in the mesh.
std::vector< double > d_h
Mesh sizes, hx, hy, hz. We compute these based on the incoming mesh.
std::shared_ptr< AMP::Discretization::multiDOFManager > d_multiDOFMan
Mesh-related data.
std::shared_ptr< AMP::Operator::OperatorParameters > getJacobianParameters(AMP::LinearAlgebra::Vector::const_shared_ptr u_in) override
std::shared_ptr< AMP::Mesh::BoxMesh::Box > d_globalBox
Global grid index box w/ zero ghosts.
std::shared_ptr< ParameterBase > shared_ptr
GeomType
Enumeration for basic mesh-based quantities.
std::shared_ptr< AMP::LinearAlgebra::Matrix > d_T
std::shared_ptr< AMP::LinearAlgebra::Vector > r_EE
std::shared_ptr< AMP::LinearAlgebra::Vector > r_ET
std::shared_ptr< AMP::LinearAlgebra::Vector > r_TE
std::tuple< std::shared_ptr< AMP::LinearAlgebra::Matrix >, std::shared_ptr< AMP::LinearAlgebra::Matrix >, std::shared_ptr< AMP::LinearAlgebra::Vector >, std::shared_ptr< AMP::LinearAlgebra::Vector >, std::shared_ptr< AMP::LinearAlgebra::Vector >, std::shared_ptr< AMP::LinearAlgebra::Vector > > get()
Getter routine; any external updates to the private data members below done via this.
std::shared_ptr< AMP::LinearAlgebra::Vector > r_TT
std::shared_ptr< AMP::LinearAlgebra::Matrix > d_E
Members used to store matrix components.
bool d_dataMaybeOverwritten