1 #ifndef ABLATELIBRARY_BOUNDARYSOLVER_HPP
2 #define ABLATELIBRARY_BOUNDARYSOLVER_HPP
5 #include "solver/cellSolver.hpp"
6 #include "solver/timeStepper.hpp"
8 namespace ablate::boundarySolver {
11 class BoundaryProcess;
22 PetscReal centroid[3];
25 using BoundarySourceFunction = PetscErrorCode (*)(PetscInt dim,
const BoundaryFVFaceGeom* fg,
const PetscFVCellGeom* boundaryCell,
const PetscInt uOff[],
const PetscScalar* boundaryValues,
26 const PetscScalar* stencilValues[],
const PetscInt aOff[],
const PetscScalar* auxValues,
const PetscScalar* stencilAuxValues[],
27 PetscInt stencilSize,
const PetscInt stencil[],
const PetscScalar stencilWeights[],
const PetscInt sOff[], PetscScalar source[],
void* ctx);
33 const PetscScalar* stencilValues,
const PetscInt aOff[], PetscScalar* auxValues,
const PetscScalar* stencilAuxValues,
void* ctx);
58 static void ComputeGradient(PetscInt dim, PetscScalar boundaryValue, PetscInt stencilSize,
const PetscScalar* stencilValues,
const PetscScalar* stencilWeights, PetscScalar* grad);
68 static void ComputeGradientAlongNormal(PetscInt dim,
const BoundaryFVFaceGeom* fg, PetscScalar boundaryValue, PetscInt stencilSize,
const PetscScalar* stencilValues,
69 const PetscScalar* stencilWeights, PetscScalar& dPhiDNorm);
75 PetscScalar* boundaryValues,
const PetscScalar* stencilValues[],
const PetscInt aOff[], PetscScalar* auxValues,
76 const PetscScalar* stencilAuxValues[], PetscInt stencilSize,
const PetscInt stencil[],
const PetscScalar stencilWeights[],
void* ctx);
85 std::vector<PetscInt> inputFieldsOffset;
86 std::vector<PetscInt> auxFieldsOffset;
103 struct GradientStencil {
109 std::vector<PetscInt> stencil;
111 PetscInt stencilSize;
113 std::vector<PetscScalar> gradientWeights;
115 std::vector<PetscScalar> distributionWeights;
117 std::vector<PetscScalar> volumes;
123 struct BoundarySourceFunctionDescription {
124 BoundarySourceFunction
function;
128 std::vector<PetscInt> sourceFieldsOffset;
129 std::vector<PetscInt> inputFieldsOffset;
130 std::vector<PetscInt> auxFieldsOffset;
136 struct BoundaryUpdateFunctionDescription {
140 std::vector<PetscInt> inputFields;
141 std::vector<PetscInt> auxFields;
145 const std::shared_ptr<domain::Region> fieldBoundary;
148 std::vector<BoundarySourceFunctionDescription> boundarySourceFunctions;
151 std::vector<BoundarySourceFunctionDescription> boundaryOutputFunctions;
154 std::vector<std::string> outputComponents;
157 std::vector<BoundaryUpdateFunctionDescription> boundaryUpdateFunctions;
160 std::vector<std::shared_ptr<BoundaryProcess>> boundaryProcesses;
163 std::vector<std::pair<BoundaryPreRHSFunctionDefinition, void*>> preRhsFunctions;
167 std::vector<GradientStencil> gradientStencils;
171 PetscInt maximumStencilSize = 0;
174 PetscFV gradientCalculator =
nullptr;
177 const bool mergeFaces;
187 void CreateGradientStencil(PetscInt cellId,
const BoundaryFVFaceGeom& geometry,
const std::vector<PetscInt>& stencil, DM cellDM,
const PetscScalar* cellGeomArray);
203 BoundarySolver(std::string solverId, std::shared_ptr<domain::Region> region, std::shared_ptr<domain::Region> fieldBoundary, std::vector<std::shared_ptr<BoundaryProcess>> boundaryProcesses,
204 std::shared_ptr<parameters::Parameters> options,
bool mergeFaces =
false);
208 void Setup()
override;
209 void Initialize()
override;
216 void RegisterFunction(BoundarySourceFunction
function,
void* context,
const std::vector<std::string>& sourceFields,
const std::vector<std::string>& inputFields,
217 const std::vector<std::string>& auxFields,
BoundarySourceType type = BoundarySourceType::Point);
250 PetscErrorCode
ComputeRHSFunction(PetscReal time, Vec locXVec, Vec locFVec,
const std::vector<BoundarySourceFunctionDescription>& boundarySourceFunctions);
255 void InsertFieldFunctions(
const std::vector<std::shared_ptr<mathFunctions::FieldFunction>>& initialization, PetscReal time = 0.0);
275 inline const std::vector<BoundarySourceFunctionDescription>&
GetOutputFunctions() {
return boundaryOutputFunctions; }
283 PetscErrorCode
PreRHSFunction(TS ts, PetscReal time,
bool initialStage, Vec locX)
override;
303 PetscErrorCode
Save(PetscViewer viewer, PetscInt sequenceNumber, PetscReal time)
override;
311 PetscErrorCode
Restore(PetscViewer viewer, PetscInt sequenceNumber, PetscReal time)
override;
Definition: boundarySolver.hpp:13
static void ComputeGradientAlongNormal(PetscInt dim, const BoundaryFVFaceGeom *fg, PetscScalar boundaryValue, PetscInt stencilSize, const PetscScalar *stencilValues, const PetscScalar *stencilWeights, PetscScalar &dPhiDNorm)
Definition: boundarySolver.cpp:665
PetscErrorCode Save(PetscViewer viewer, PetscInt sequenceNumber, PetscReal time) override
Definition: boundarySolver.cpp:953
const std::vector< BoundarySourceFunctionDescription > & GetOutputFunctions()
Definition: boundarySolver.hpp:275
void RegisterPreRHSFunction(BoundaryPreRHSFunctionDefinition function, void *context)
Definition: boundarySolver.cpp:381
SerializerType Serialize() const override
Definition: boundarySolver.cpp:951
PetscErrorCode(*)(BoundarySolver &, TS ts, PetscReal time, bool initialStage, Vec locX, void *ctx) BoundaryPreRHSFunctionDefinition
Definition: boundarySolver.hpp:38
void RegisterFunction(BoundarySourceFunction function, void *context, const std::vector< std::string > &sourceFields, const std::vector< std::string > &inputFields, const std::vector< std::string > &auxFields, BoundarySourceType type=BoundarySourceType::Point)
Definition: boundarySolver.cpp:318
const std::string & GetId() const override
Definition: boundarySolver.hpp:295
void Setup() override
Definition: boundarySolver.cpp:63
BoundarySourceType
Definition: boundarySolver.hpp:43
BoundarySolver(std::string solverId, std::shared_ptr< domain::Region > region, std::shared_ptr< domain::Region > fieldBoundary, std::vector< std::shared_ptr< BoundaryProcess >> boundaryProcesses, std::shared_ptr< parameters::Parameters > options, bool mergeFaces=false)
Definition: boundarySolver.cpp:8
void InsertFieldFunctions(const std::vector< std::shared_ptr< mathFunctions::FieldFunction >> &initialization, PetscReal time=0.0)
Definition: boundarySolver.cpp:604
const std::vector< std::string > & GetOutputComponents()
Definition: boundarySolver.hpp:270
PetscErrorCode Restore(PetscViewer viewer, PetscInt sequenceNumber, PetscReal time) override
Definition: boundarySolver.cpp:965
PetscErrorCode(*)(PetscInt dim, const BoundaryFVFaceGeom *fg, const PetscFVCellGeom *boundaryCell, const PetscInt uOff[], PetscScalar *boundaryValues, const PetscScalar *stencilValues, const PetscInt aOff[], PetscScalar *auxValues, const PetscScalar *stencilAuxValues, void *ctx) BoundaryUpdateFunction
Definition: boundarySolver.hpp:33
PetscErrorCode ComputeRHSFunction(PetscReal time, Vec locXVec, Vec locFVec) override
Definition: boundarySolver.cpp:383
PetscErrorCode(*)(PetscReal time, PetscReal dt, PetscInt dim, const BoundaryFVFaceGeom *fg, const PetscFVCellGeom *boundaryCell, const PetscInt uOff[], PetscScalar *boundaryValues, const PetscScalar *stencilValues[], const PetscInt aOff[], PetscScalar *auxValues, const PetscScalar *stencilAuxValues[], PetscInt stencilSize, const PetscInt stencil[], const PetscScalar stencilWeights[], void *ctx) BoundaryPreRHSPointFunction
Definition: boundarySolver.hpp:76
const std::vector< GradientStencil > & GetBoundaryGeometry() const
Definition: boundarySolver.hpp:265
PetscErrorCode PreRHSFunction(TS ts, PetscReal time, bool initialStage, Vec locX) override
Definition: boundarySolver.cpp:835
PetscErrorCode ComputeBoundaryPreRHSPointFunction(PetscReal time, PetscReal dt, Vec locXVec, const BoundaryPreRHSPointFunctionDefinition &boundaryPreRhsPointFunction)
Definition: boundarySolver.cpp:853
static void ComputeGradient(PetscInt dim, PetscScalar boundaryValue, PetscInt stencilSize, const PetscScalar *stencilValues, const PetscScalar *stencilWeights, PetscScalar *grad)
Definition: boundarySolver.cpp:652
Definition: serializable.hpp:13
SerializerType
Definition: serializable.hpp:18
Definition: cellSolver.hpp:11
Definition: rhsFunction.hpp:7
Definition: solver.hpp:17
const std::string & GetSolverId() const
Definition: solver.hpp:58
Definition: loggable.hpp:9
Definition: boundarySolver.hpp:18
Definition: boundarySolver.hpp:81