v0.14.0
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
MixTransport::UnsaturatedFlowElement Struct Reference

Implementation of operators, problem and finite elements for unsaturated flow. More...

#include <users_modules/tutorials/cor-0to1/src/UnsaturatedFlow.hpp>

Inheritance diagram for MixTransport::UnsaturatedFlowElement:
[legend]
Collaboration diagram for MixTransport::UnsaturatedFlowElement:
[legend]

Classes

struct  BcData
 Class storing information about boundary condition. More...
 
struct  FaceRule
 Set integration rule to boundary elements. More...
 
struct  MonitorPostProc
 
struct  OpDivTauU_HdivL2
 
struct  OpEvaluateInitiallHead
 
struct  OpIntegrateFluxes
 
struct  OpPostProcMaterial
 
struct  OpResidualFlux
 Assemble flux residual. More...
 
struct  OpResidualMass
 
struct  OpRhsBcOnValues
 Evaluate boundary condition at the boundary. More...
 
struct  OpTauDotSigma_HdivHdiv
 
struct  OpVDivSigma_L2Hdiv
 
struct  OpVU_L2L2
 
struct  postProcessVol
 Post proces method for volume element Assemble vectors and matrices and apply essential boundary conditions. More...
 
struct  preProcessVol
 Pre-peprocessing Set head pressure rate and get inital essential boundary conditions. More...
 
struct  VolRule
 Set integration rule to volume elements. More...
 

Public Types

typedef std::map< int, boost::shared_ptr< GenericMaterial > > MaterialsDoubleMap
 
typedef map< int, boost::shared_ptr< BcData > > BcMap
 

Public Member Functions

 UnsaturatedFlowElement (MoFEM::Interface &m_field)
 
 ~UnsaturatedFlowElement ()
 
virtual MoFEMErrorCode getMaterial (const EntityHandle ent, int &block_id) const
 For given element handle get material block Id. More...
 
MoFEMErrorCode getBcOnValues (const EntityHandle ent, const int gg, const double x, const double y, const double z, double &value)
 Get value on boundary. More...
 
MoFEMErrorCode getBcOnFluxes (const EntityHandle ent, const double x, const double y, const double z, double &flux)
 essential (Neumann) boundary condition (set fluxes) More...
 
MoFEMErrorCode addFields (const std::string &values, const std::string &fluxes, const int order)
 add fields More...
 
MoFEMErrorCode addFiniteElements (const std::string &fluxes_name, const std::string &values_name)
 add finite elements More...
 
MoFEMErrorCode buildProblem (Range zero_flux_ents, BitRefLevel ref_level=BitRefLevel().set(0))
 Build problem. More...
 
MoFEMErrorCode setFiniteElements (ForcesAndSourcesCore::RuleHookFun vol_rule=VolRule(), ForcesAndSourcesCore::RuleHookFun face_rule=FaceRule())
 Create finite element instances. More...
 
MoFEMErrorCode createMatrices ()
 Create vectors and matrices. More...
 
MoFEMErrorCode destroyMatrices ()
 Delete matrices and vector when no longer needed. More...
 
MoFEMErrorCode calculateEssentialBc ()
 Calculate boundary conditions for fluxes. More...
 
MoFEMErrorCode calculateInitialPc ()
 Calculate inital pressure head distribution. More...
 
MoFEMErrorCode solveProblem (bool set_initial_pc=true)
 solve problem More...
 
- Public Member Functions inherited from MixTransport::MixTransportElement
 MixTransportElement (MoFEM::Interface &m_field)
 construction of this data structure More...
 
virtual ~MixTransportElement ()
 destructor More...
 
MoFEMErrorCode getDirichletBCIndices (IS *is)
 get dof indices where essential boundary conditions are applied More...
 
virtual MoFEMErrorCode getSource (const EntityHandle ent, const double x, const double y, const double z, double &flux)
 set source term More...
 
virtual MoFEMErrorCode getResistivity (const EntityHandle ent, const double x, const double y, const double z, MatrixDouble3by3 &inv_k)
 natural (Dirichlet) boundary conditions (set values) More...
 
virtual MoFEMErrorCode getBcOnValues (const EntityHandle ent, const int gg, const double x, const double y, const double z, double &value)
 evaluate natural (Dirichlet) boundary conditions More...
 
virtual MoFEMErrorCode getBcOnFluxes (const EntityHandle ent, const double x, const double y, const double z, double &flux)
 essential (Neumann) boundary condition (set fluxes) More...
 
MoFEMErrorCode addFields (const std::string &values, const std::string &fluxes, const int order)
 Add fields to database. More...
 
MoFEMErrorCode addFiniteElements (const std::string &fluxes_name, const std::string &values_name)
 add finite elements More...
 
MoFEMErrorCode buildProblem (BitRefLevel &ref_level)
 Build problem. More...
 
MoFEMErrorCode postProc (const string out_file)
 Post process results. More...
 
MoFEMErrorCode createMatrices ()
 create matrices More...
 
MoFEMErrorCode solveLinearProblem ()
 solve problem More...
 
MoFEMErrorCode calculateResidual ()
 calculate residual More...
 
MoFEMErrorCode evaluateError ()
 Calculate error on elements. More...
 
MoFEMErrorCode destroyMatrices ()
 destroy matrices More...
 

Public Attributes

DM dM
 Discrete manager for unsaturated flow problem. More...
 
MaterialsDoubleMap dMatMap
 materials database More...
 
BcMap bcValueMap
 Store boundary condition for head capillary pressure. More...
 
EntityHandle lastEvalBcValEnt
 
int lastEvalBcBlockValId
 
BcMap bcFluxMap
 
EntityHandle lastEvalBcFluxEnt
 
int lastEvalBcBlockFluxId
 
boost::shared_ptr< ForcesAndSourcesCore > feFaceBc
 Elemnet to calculate essential bc. More...
 
boost::shared_ptr< ForcesAndSourcesCore > feFaceRhs
 Face element apply natural bc. More...
 
boost::shared_ptr< ForcesAndSourcesCore > feVolInitialPc
 Calculate inital boundary conditions. More...
 
boost::shared_ptr< ForcesAndSourcesCore > feVolRhs
 Assemble residual vector. More...
 
boost::shared_ptr< ForcesAndSourcesCore > feVolLhs
 Assemble tangent matrix. More...
 
boost::shared_ptr< MethodForForceScalingscaleMethodFlux
 Method scaling fluxes. More...
 
boost::shared_ptr< MethodForForceScalingscaleMethodValue
 Method scaling values. More...
 
boost::shared_ptr< FEMethodtsMonitor
 
boost::shared_ptr< VectorDouble > headRateAtGaussPts
 Vector keeps head rate. More...
 
std::vector< int > bcVecIds
 
VectorDouble bcVecVals
 
VectorDouble vecValsOnBc
 
Vec D1
 Vector with inital head capillary pressure. More...
 
Vec ghostFlux
 Ghost Vector of integrated fluxes. More...
 
- Public Attributes inherited from MixTransport::MixTransportElement
MoFEM::InterfacemField
 
MyVolumeFE feVol
 Instance of volume element. More...
 
MyTriFE feTri
 Instance of surface element. More...
 
VectorDouble valuesAtGaussPts
 values at integration points on element More...
 
MatrixDouble valuesGradientAtGaussPts
 gradients at integration points on element More...
 
VectorDouble divergenceAtGaussPts
 divergence at integration points on element More...
 
MatrixDouble fluxesAtGaussPts
 fluxes at integration points on element More...
 
set< int > bcIndices
 
std::map< int, BlockDatasetOfBlocks
 maps block set id with appropriate BlockData More...
 
Vec D
 
Vec D0
 
Vec F
 
Mat Aij
 
map< double, EntityHandleerrorMap
 
double sumErrorFlux
 
double sumErrorDiv
 
double sumErrorJump
 

Detailed Description

Implementation of operators, problem and finite elements for unsaturated flow.

Examples
unsaturated_transport.cpp.

Definition at line 102 of file UnsaturatedFlow.hpp.

Member Typedef Documentation

◆ BcMap

typedef map<int, boost::shared_ptr<BcData> > MixTransport::UnsaturatedFlowElement::BcMap
Examples
UnsaturatedFlow.hpp.

Definition at line 152 of file UnsaturatedFlow.hpp.

◆ MaterialsDoubleMap

Examples
UnsaturatedFlow.hpp.

Definition at line 118 of file UnsaturatedFlow.hpp.

Constructor & Destructor Documentation

◆ UnsaturatedFlowElement()

MixTransport::UnsaturatedFlowElement::UnsaturatedFlowElement ( MoFEM::Interface m_field)
inline

Definition at line 106 of file UnsaturatedFlow.hpp.

107 : MixTransportElement(m_field), dM(PETSC_NULL), lastEvalBcValEnt(0),
MixTransportElement(MoFEM::Interface &m_field)
construction of this data structure
DM dM
Discrete manager for unsaturated flow problem.

◆ ~UnsaturatedFlowElement()

MixTransport::UnsaturatedFlowElement::~UnsaturatedFlowElement ( )
inline
Examples
UnsaturatedFlow.hpp.

Definition at line 111 of file UnsaturatedFlow.hpp.

111 {
112 if (dM != PETSC_NULL) {
113 CHKERR DMDestroy(&dM);
114 CHKERRABORT(PETSC_COMM_WORLD, ierr);
115 }
116 }
static PetscErrorCode ierr
#define CHKERR
Inline error check.
Definition: definitions.h:535

Member Function Documentation

◆ addFields()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::addFields ( const std::string &  values,
const std::string &  fluxes,
const int  order 
)
inline

add fields

Examples
UnsaturatedFlow.hpp.

Definition at line 1136 of file UnsaturatedFlow.hpp.

1137 {
1139 // Fields
1142 CHKERR mField.add_field(values + "_t", L2, AINSWORTH_LEGENDRE_BASE, 1);
1143 // CHKERR mField.add_field(fluxes+"_residual",L2,AINSWORTH_LEGENDRE_BASE,1);
1144
1145 // meshset consisting all entities in mesh
1146 EntityHandle root_set = mField.get_moab().get_root_set();
1147 // add entities to field
1148
1150 if (it->getName().compare(0, 4, "SOIL") != 0)
1151 continue;
1152 CHKERR mField.add_ents_to_field_by_type(dMatMap[it->getMeshsetId()]->tEts,
1153 MBTET, fluxes);
1154 CHKERR mField.add_ents_to_field_by_type(dMatMap[it->getMeshsetId()]->tEts,
1155 MBTET, values);
1156 CHKERR mField.add_ents_to_field_by_type(dMatMap[it->getMeshsetId()]->tEts,
1157 MBTET, values + "_t");
1158 // CHKERR mField.add_ents_to_field_by_type(
1159 // dMatMap[it->getMeshsetId()]->tEts,MBTET,fluxes+"_residual"
1160 // );
1161 }
1162
1163 CHKERR mField.set_field_order(root_set, MBTET, fluxes, order + 1);
1164 CHKERR mField.set_field_order(root_set, MBTRI, fluxes, order + 1);
1165 CHKERR mField.set_field_order(root_set, MBTET, values, order);
1166 CHKERR mField.set_field_order(root_set, MBTET, values + "_t", order);
1167 // CHKERR mField.set_field_order(root_set,MBTET,fluxes+"_residual",order);
1169 }
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
@ DEMKOWICZ_JACOBI_BASE
Definition: definitions.h:66
@ L2
field with C-1 continuity
Definition: definitions.h:88
@ HDIV
field with continuous normal traction
Definition: definitions.h:87
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ BLOCKSET
Definition: definitions.h:148
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
constexpr int order
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
MaterialsDoubleMap dMatMap
materials database
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode add_field(const std::string &name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.

◆ addFiniteElements()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::addFiniteElements ( const std::string &  fluxes_name,
const std::string &  values_name 
)
inline

add finite elements

Examples
UnsaturatedFlow.hpp.

Definition at line 1172 of file UnsaturatedFlow.hpp.

1173 {
1175
1176 // Define element "MIX". Note that this element will work with fluxes_name
1177 // and values_name. This reflect bilinear form for the problem
1186 values_name + "_t");
1187 // CHKERR
1188 // mField.modify_finite_element_add_field_data("MIX",fluxes_name+"_residual");
1189
1191 if (it->getName().compare(0, 4, "SOIL") != 0)
1192 continue;
1194 dMatMap[it->getMeshsetId()]->tEts, MBTET, "MIX");
1195 }
1196
1197 // Define element to integrate natural boundary conditions, i.e. set values.
1198 CHKERR mField.add_finite_element("MIX_BCVALUE", MF_ZERO);
1200 fluxes_name);
1202 fluxes_name);
1204 fluxes_name);
1206 values_name);
1207
1209 if (it->getName().compare(0, 4, "HEAD") != 0)
1210 continue;
1212 bcValueMap[it->getMeshsetId()]->eNts, MBTRI, "MIX_BCVALUE");
1213 }
1214
1215 // Define element to apply essential boundary conditions.
1216 CHKERR mField.add_finite_element("MIX_BCFLUX", MF_ZERO);
1218 fluxes_name);
1220 fluxes_name);
1222 fluxes_name);
1224 values_name);
1225
1227 if (it->getName().compare(0, 4, "FLUX") != 0)
1228 continue;
1230 bcFluxMap[it->getMeshsetId()]->eNts, MBTRI, "MIX_BCFLUX");
1231 }
1232
1234 }
@ MF_ZERO
Definition: definitions.h:98
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string &name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_filed)=0
set finite element field data
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
BcMap bcValueMap
Store boundary condition for head capillary pressure.

◆ buildProblem()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::buildProblem ( Range  zero_flux_ents,
BitRefLevel  ref_level = BitRefLevel().set(0) 
)
inline

Build problem.

Parameters
ref_levelmesh refinement on which mesh problem you like to built.
Returns
error code
Examples
UnsaturatedFlow.hpp.

Definition at line 1241 of file UnsaturatedFlow.hpp.

1242 {
1244
1245 // Build fields
1247 // Build finite elements
1249 CHKERR mField.build_finite_elements("MIX_BCFLUX");
1250 CHKERR mField.build_finite_elements("MIX_BCVALUE");
1251 // Build adjacencies of degrees of freedom and elements
1252 CHKERR mField.build_adjacencies(ref_level);
1253
1254 // create DM instance
1255 CHKERR DMCreate(PETSC_COMM_WORLD, &dM);
1256 // setting that DM is type of DMMOFEM, i.e. MOFEM implementation manages DM
1257 CHKERR DMSetType(dM, "DMMOFEM");
1258 // mesh is portioned, each process keeps only part of problem
1259 CHKERR DMMoFEMSetIsPartitioned(dM, PETSC_TRUE);
1260 // creates problem in DM
1261 CHKERR DMMoFEMCreateMoFEM(dM, &mField, "MIX", ref_level);
1262 // discretised problem creates square matrix (that makes some optimizations)
1263 CHKERR DMMoFEMSetIsPartitioned(dM, PETSC_TRUE);
1264 // set DM options from command line
1265 CHKERR DMSetFromOptions(dM);
1266 // add finite elements
1267 CHKERR DMMoFEMAddElement(dM, "MIX");
1268 CHKERR DMMoFEMAddElement(dM, "MIX_BCFLUX");
1269 CHKERR DMMoFEMAddElement(dM, "MIX_BCVALUE");
1270 // constructor data structures
1271 CHKERR DMSetUp(dM);
1272
1273 // remove zero flux dofs
1274 CHKERR mField.getInterface<ProblemsManager>()->removeDofsOnEntities(
1275 "MIX", "FLUXES", zero_flux_ents);
1276
1277 PetscSection section;
1278 CHKERR mField.getInterface<ISManager>()->sectionCreate("MIX", &section);
1279 CHKERR DMSetSection(dM, section);
1280 // CHKERR PetscSectionView(section,PETSC_VIEWER_STDOUT_WORLD);
1281 CHKERR PetscSectionDestroy(&section);
1282
1284 }
PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned)
Definition: DMMoFEM.cpp:1109
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition: DMMoFEM.cpp:483
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
Definition: DMMoFEM.cpp:118
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.

◆ calculateEssentialBc()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::calculateEssentialBc ( )
inline

Calculate boundary conditions for fluxes.

Returns
Error code

Definition at line 1650 of file UnsaturatedFlow.hpp.

1650 {
1652 // clear vectors
1653 CHKERR VecZeroEntries(D0);
1654 CHKERR VecGhostUpdateBegin(D0, INSERT_VALUES, SCATTER_FORWARD);
1655 CHKERR VecGhostUpdateEnd(D0, INSERT_VALUES, SCATTER_FORWARD);
1656 // clear essential bc indices, it could have dofs from other mesh refinement
1657 bcIndices.clear();
1658 // set operator to calculate essential boundary conditions
1660 CHKERR VecAssemblyBegin(D0);
1661 CHKERR VecAssemblyEnd(D0);
1662 CHKERR VecGhostUpdateBegin(D0, INSERT_VALUES, SCATTER_FORWARD);
1663 CHKERR VecGhostUpdateEnd(D0, INSERT_VALUES, SCATTER_FORWARD);
1664 double norm2D0;
1665 CHKERR VecNorm(D0, NORM_2, &norm2D0);
1666 // CHKERR VecView(D0,PETSC_VIEWER_STDOUT_WORLD);
1667 PetscPrintf(PETSC_COMM_WORLD, "norm2D0 = %6.4e\n", norm2D0);
1669 }
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMoFEM.cpp:572
boost::shared_ptr< ForcesAndSourcesCore > feFaceBc
Elemnet to calculate essential bc.

◆ calculateInitialPc()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::calculateInitialPc ( )
inline

Calculate inital pressure head distribution.

Returns
Error code

Definition at line 1675 of file UnsaturatedFlow.hpp.

1675 {
1677 // clear vectors
1678 CHKERR VecZeroEntries(D1);
1679 CHKERR VecGhostUpdateBegin(D1, INSERT_VALUES, SCATTER_FORWARD);
1680 CHKERR VecGhostUpdateEnd(D1, INSERT_VALUES, SCATTER_FORWARD);
1681 // Calculate initial pressure head on each element
1683 // Assemble vector
1684 CHKERR VecAssemblyBegin(D1);
1685 CHKERR VecAssemblyEnd(D1);
1686 CHKERR VecGhostUpdateBegin(D1, INSERT_VALUES, SCATTER_FORWARD);
1687 CHKERR VecGhostUpdateEnd(D1, INSERT_VALUES, SCATTER_FORWARD);
1688 // Calculate norm
1689 double norm2D1;
1690 CHKERR VecNorm(D1, NORM_2, &norm2D1);
1691 // CHKERR VecView(D0,PETSC_VIEWER_STDOUT_WORLD);
1692 PetscPrintf(PETSC_COMM_WORLD, "norm2D1 = %6.4e\n", norm2D1);
1694 }
Vec D1
Vector with inital head capillary pressure.
boost::shared_ptr< ForcesAndSourcesCore > feVolInitialPc
Calculate inital boundary conditions.

◆ createMatrices()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::createMatrices ( )
inline

Create vectors and matrices.

Returns
Error code

Definition at line 1616 of file UnsaturatedFlow.hpp.

1616 {
1618 CHKERR DMCreateMatrix(dM, &Aij);
1619 CHKERR DMCreateGlobalVector(dM, &D0);
1620 CHKERR VecDuplicate(D0, &D1);
1621 CHKERR VecDuplicate(D0, &D);
1622 CHKERR VecDuplicate(D0, &F);
1623 int ghosts[] = {0};
1624 int nb_locals = mField.get_comm_rank() == 0 ? 1 : 0;
1625 int nb_ghosts = mField.get_comm_rank() > 0 ? 1 : 0;
1626 CHKERR VecCreateGhost(PETSC_COMM_WORLD, nb_locals, 1, nb_ghosts, ghosts,
1627 &ghostFlux);
1629 }
Vec ghostFlux
Ghost Vector of integrated fluxes.
virtual int get_comm_rank() const =0

◆ destroyMatrices()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::destroyMatrices ( )
inline

Delete matrices and vector when no longer needed.

Returns
error code

Definition at line 1635 of file UnsaturatedFlow.hpp.

1635 {
1637 CHKERR MatDestroy(&Aij);
1638 CHKERR VecDestroy(&D);
1639 CHKERR VecDestroy(&D0);
1640 CHKERR VecDestroy(&D1);
1641 CHKERR VecDestroy(&F);
1642 CHKERR VecDestroy(&ghostFlux);
1644 }

◆ getBcOnFluxes()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::getBcOnFluxes ( const EntityHandle  ent,
const double  x,
const double  y,
const double  z,
double flux 
)
inlinevirtual

essential (Neumann) boundary condition (set fluxes)

Parameters
enthandle to finite element entity
xcoord
ycoord
zcoord
fluxreference to flux which is set by function
Returns
[description]

Reimplemented from MixTransport::MixTransportElement.

Examples
UnsaturatedFlow.hpp.

Definition at line 210 of file UnsaturatedFlow.hpp.

211 {
213 int block_id = -1;
214 if (lastEvalBcFluxEnt == ent) {
215 block_id = lastEvalBcBlockFluxId;
216 } else {
217 for (BcMap::iterator it = bcFluxMap.begin(); it != bcFluxMap.end();
218 it++) {
219 if (it->second->eNts.find(ent) != it->second->eNts.end()) {
220 block_id = it->first;
221 }
222 }
223 lastEvalBcFluxEnt = ent;
224 lastEvalBcBlockFluxId = block_id;
225 }
226 if (block_id >= 0) {
227 if (bcFluxMap.at(block_id)->hookFun) {
228 flux = bcFluxMap.at(block_id)->hookFun(x, y, z);
229 } else {
230 flux = bcFluxMap.at(block_id)->fixValue;
231 }
232 } else {
233 flux = 0;
234 }
236 }

◆ getBcOnValues()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::getBcOnValues ( const EntityHandle  ent,
const int  gg,
const double  x,
const double  y,
const double  z,
double value 
)
inlinevirtual

Get value on boundary.

Parameters
ententity handle
ggnumber of integration point
xx-coordinate
yy-coordinate
zz-coordinate
valuereturned value
Returns
error code

Reimplemented from MixTransport::MixTransportElement.

Examples
UnsaturatedFlow.hpp.

Definition at line 168 of file UnsaturatedFlow.hpp.

170 {
172 int block_id = -1;
173 if (lastEvalBcValEnt == ent) {
174 block_id = lastEvalBcBlockValId;
175 } else {
176 for (BcMap::iterator it = bcValueMap.begin(); it != bcValueMap.end();
177 it++) {
178 if (it->second->eNts.find(ent) != it->second->eNts.end()) {
179 block_id = it->first;
180 }
181 }
182 lastEvalBcValEnt = ent;
183 lastEvalBcBlockValId = block_id;
184 }
185 if (block_id >= 0) {
186 if (bcValueMap.at(block_id)->hookFun) {
187 value = bcValueMap.at(block_id)->hookFun(x, y, z);
188 } else {
189 value = bcValueMap.at(block_id)->fixValue;
190 }
191 } else {
192 value = 0;
193 }
195 }

◆ getMaterial()

virtual MoFEMErrorCode MixTransport::UnsaturatedFlowElement::getMaterial ( const EntityHandle  ent,
int &  block_id 
) const
inlinevirtual

For given element handle get material block Id.

Parameters
entfinite element entity handle
block_idreference to returned block id
Returns
error code
Examples
UnsaturatedFlow.hpp.

Definition at line 127 of file UnsaturatedFlow.hpp.

128 {
130 for (MaterialsDoubleMap::const_iterator mit = dMatMap.begin();
131 mit != dMatMap.end(); mit++) {
132 if (mit->second->tEts.find(ent) != mit->second->tEts.end()) {
133 block_id = mit->first;
135 }
136 }
138 "Element not found, no material data");
140 }
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
virtual MPI_Comm & get_comm() const =0

◆ setFiniteElements()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::setFiniteElements ( ForcesAndSourcesCore::RuleHookFun  vol_rule = VolRule(),
ForcesAndSourcesCore::RuleHookFun  face_rule = FaceRule() 
)
inline

Create finite element instances.

Parameters
vol_ruleintegration rule for volume element
face_ruleintegration rule for boundary element
Returns
error code
Examples
UnsaturatedFlow.hpp.

Definition at line 1446 of file UnsaturatedFlow.hpp.

1447 {
1449
1450 // create finite element instances
1451 feFaceBc = boost::shared_ptr<ForcesAndSourcesCore>(
1453 feFaceRhs = boost::shared_ptr<ForcesAndSourcesCore>(
1455 feVolInitialPc = boost::shared_ptr<ForcesAndSourcesCore>(
1456 new VolumeElementForcesAndSourcesCore(mField));
1457 feVolLhs = boost::shared_ptr<ForcesAndSourcesCore>(
1458 new VolumeElementForcesAndSourcesCore(mField));
1459 feVolRhs = boost::shared_ptr<ForcesAndSourcesCore>(
1460 new VolumeElementForcesAndSourcesCore(mField));
1461 // set integration rule to elements
1462 feFaceBc->getRuleHook = face_rule;
1463 feFaceRhs->getRuleHook = face_rule;
1464 feVolInitialPc->getRuleHook = vol_rule;
1465 feVolLhs->getRuleHook = vol_rule;
1466 feVolRhs->getRuleHook = vol_rule;
1467 // set function hook for finite element postprocessing stage
1468 feVolRhs->preProcessHook = preProcessVol(*this, feVolRhs);
1469 feVolLhs->preProcessHook = preProcessVol(*this, feVolLhs);
1470 feVolRhs->postProcessHook = postProcessVol(*this, feVolRhs);
1471 feVolLhs->postProcessHook = postProcessVol(*this, feVolLhs);
1472
1473 // Set Piola transform
1474 CHKERR AddHOOps<2, 3, 3>::add(feFaceBc->getOpPtrVector(), {HDIV});
1475 CHKERR AddHOOps<2, 3, 3>::add(feFaceRhs->getOpPtrVector(), {HDIV});
1476
1477 // create method for setting history for fluxes on boundary
1478 scaleMethodFlux = boost::shared_ptr<MethodForForceScaling>(
1479 new TimeForceScale("-flux_history", false));
1480
1481 // create method for setting history for presure heads on boundary
1482 scaleMethodValue = boost::shared_ptr<MethodForForceScaling>(
1483 new TimeForceScale("-head_history", false));
1484
1485 // Set operator to calculate essential boundary conditions
1486 feFaceBc->getOpPtrVector().push_back(
1487 new OpEvaluateBcOnFluxes(*this, "FLUXES"));
1488
1489 // Set operator to calculate initial capillary pressure
1490 CHKERR AddHOOps<3, 3, 3>::add(feVolInitialPc->getOpPtrVector(), {HDIV, L2});
1491 feVolInitialPc->getOpPtrVector().push_back(
1492 new OpEvaluateInitiallHead(*this, "VALUES"));
1493
1494 // set residual face from Neumann terms, i.e. applied pressure
1495 feFaceRhs->getOpPtrVector().push_back(
1496 new OpRhsBcOnValues(*this, "FLUXES", scaleMethodValue));
1497 // set residual finite element operators
1498 headRateAtGaussPts = boost::make_shared<VectorDouble>();
1499
1500
1501 // resAtGaussPts = boost::make_shared<VectorDouble>();
1502 CHKERR AddHOOps<3, 3, 3>::add(feVolRhs->getOpPtrVector(), {HDIV, L2});
1503 feVolRhs->getOpPtrVector().push_back(new OpCalculateScalarFieldValues(
1504 string("VALUES") + "_t", headRateAtGaussPts, MBTET));
1505 feVolRhs->getOpPtrVector().push_back(
1506 new OpValuesAtGaussPts(*this, "VALUES"));
1507 feVolRhs->getOpPtrVector().push_back(
1508 new OpFluxDivergenceAtGaussPts(*this, "FLUXES"));
1509 feVolRhs->getOpPtrVector().push_back(new OpResidualFlux(*this, "FLUXES"));
1510 feVolRhs->getOpPtrVector().push_back(new OpResidualMass(*this, "VALUES"));
1511 feVolRhs->getOpPtrVector().back().opType =
1512 ForcesAndSourcesCore::UserDataOperator::OPROW;
1513 // set tangent matrix finite element operators
1514 CHKERR AddHOOps<3, 3, 3>::add(feVolLhs->getOpPtrVector(), {HDIV, L2});
1515 feVolLhs->getOpPtrVector().push_back(new OpCalculateScalarFieldValues(
1516 string("VALUES") + "_t", headRateAtGaussPts, MBTET));
1517 // feVolLhs->getOpPtrVector().push_back(
1518 // new
1519 // OpCalculateScalarFieldValues(string("FLUXES")+"_residual",resAtGaussPts,MBTET)
1520 // );
1521 feVolLhs->getOpPtrVector().push_back(
1522 new OpValuesAtGaussPts(*this, "VALUES"));
1523 feVolLhs->getOpPtrVector().push_back(
1524 new OpFluxDivergenceAtGaussPts(*this, "FLUXES"));
1525 feVolLhs->getOpPtrVector().push_back(
1526 new OpTauDotSigma_HdivHdiv(*this, "FLUXES"));
1527 feVolLhs->getOpPtrVector().push_back(new OpVU_L2L2(*this, "VALUES"));
1528 feVolLhs->getOpPtrVector().push_back(
1529 new OpVDivSigma_L2Hdiv(*this, "VALUES", "FLUXES"));
1530 feVolLhs->getOpPtrVector().push_back(
1531 new OpDivTauU_HdivL2(*this, "FLUXES", "VALUES"));
1532
1533 // Adding finite elements to DM, time solver will ask for it to assemble
1534 // tangent matrices and residuals
1535 boost::shared_ptr<FEMethod> null;
1536 CHKERR DMMoFEMTSSetIFunction(dM, "MIX_BCVALUE", feFaceRhs, null, null);
1537 CHKERR DMMoFEMTSSetIFunction(dM, "MIX", feVolRhs, null, null);
1538 CHKERR DMMoFEMTSSetIJacobian(dM, "MIX", feVolLhs, null, null);
1539
1540 // setting up post-processing
1541
1542
1543 auto get_post_process_ele = [&]() {
1544 auto post_process = boost::make_shared<PostProcEle>(mField);
1545
1546 CHKERR AddHOOps<3, 3, 3>::add(post_process->getOpPtrVector(), {HDIV, L2});
1547
1548 auto values_ptr = boost::make_shared<VectorDouble>();
1549 auto grad_ptr = boost::make_shared<MatrixDouble>();
1550 auto flux_ptr = boost::make_shared<MatrixDouble>();
1551
1552 post_process->getOpPtrVector().push_back(
1553 new OpCalculateScalarFieldValues("VALUES", values_ptr));
1554 post_process->getOpPtrVector().push_back(
1555 new OpCalculateScalarFieldGradient<3>("VALUES", grad_ptr));
1556 post_process->getOpPtrVector().push_back(
1557 new OpCalculateHVecVectorField<3>("FLUXES", flux_ptr));
1558
1559 using OpPPMap = OpPostProcMapInMoab<3, 3>;
1560
1561 post_process->getOpPtrVector().push_back(
1562
1563 new OpPPMap(post_process->getPostProcMesh(),
1564 post_process->getMapGaussPts(),
1565
1566 {{"VALUES", values_ptr}},
1567
1568 {{"GRAD", grad_ptr}, {"FLUXES", flux_ptr}},
1569
1570 {}, {}
1571
1572 ));
1573
1574 return post_process;
1575 };
1576
1577 auto post_process = get_post_process_ele();
1578
1579 post_process->getOpPtrVector().push_back(
1580 new OpValuesAtGaussPts(*this, "VALUES"));
1581 post_process->getOpPtrVector().push_back(
1582 new OpPostProcMaterial(*this, post_process->getPostProcMesh(),
1583 post_process->getMapGaussPts(), "VALUES"));
1584
1585 // Integrate fluxes on boundary
1586 boost::shared_ptr<ForcesAndSourcesCore> flux_integrate;
1587 flux_integrate = boost::shared_ptr<ForcesAndSourcesCore>(
1589 CHKERR AddHOOps<2, 3, 3>::add(flux_integrate->getOpPtrVector(), {HDIV});
1590 flux_integrate->getOpPtrVector().push_back(
1591 new OpIntegrateFluxes(*this, "FLUXES"));
1592 int frequency = 1;
1593 CHKERR PetscOptionsBegin(PETSC_COMM_WORLD, "", "Monitor post proc", "none");
1594 CHKERR PetscOptionsInt(
1595 "-how_often_output",
1596 "frequency how often results are dumped on hard disk", "", frequency,
1597 &frequency, NULL);
1598 ierr = PetscOptionsEnd();
1599 CHKERRG(ierr);
1600
1601 tsMonitor = boost::shared_ptr<FEMethod>(
1602 new MonitorPostProc(*this, post_process, flux_integrate, frequency));
1603 TsCtx *ts_ctx;
1607 }
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:483
PetscErrorCode DMMoFEMTSSetIFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set TS implicit function evaluation function
Definition: DMMoFEM.cpp:786
PetscErrorCode DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx)
get MoFEM::TsCtx data structure
Definition: DMMoFEM.cpp:1128
PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
Definition: DMMoFEM.cpp:839
MoFEM::TsCtx * ts_ctx
Definition: level_set.cpp:1884
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
boost::shared_ptr< ForcesAndSourcesCore > feVolLhs
Assemble tangent matrix.
boost::shared_ptr< VectorDouble > headRateAtGaussPts
Vector keeps head rate.
boost::shared_ptr< MethodForForceScaling > scaleMethodFlux
Method scaling fluxes.
boost::shared_ptr< ForcesAndSourcesCore > feFaceRhs
Face element apply natural bc.
boost::shared_ptr< ForcesAndSourcesCore > feVolRhs
Assemble residual vector.
boost::shared_ptr< FEMethod > tsMonitor
boost::shared_ptr< MethodForForceScaling > scaleMethodValue
Method scaling values.
Post post-proc data at points from hash maps.
BasicMethodsSequence & getPostProcessMonitor()
Get the postProcess to do Monitor object.
Definition: TsCtx.hpp:154
Force scale operator for reading two columns.

◆ solveProblem()

MoFEMErrorCode MixTransport::UnsaturatedFlowElement::solveProblem ( bool  set_initial_pc = true)
inline

solve problem

Returns
error code

Definition at line 1700 of file UnsaturatedFlow.hpp.

1700 {
1702 if (set_initial_pc) {
1703 // Set initial head
1704 CHKERR DMoFEMMeshToLocalVector(dM, D1, INSERT_VALUES, SCATTER_REVERSE);
1705 }
1706
1707 // Initiate vector from data on the mesh
1708 CHKERR DMoFEMMeshToLocalVector(dM, D, INSERT_VALUES, SCATTER_FORWARD);
1709
1710 // Create time solver
1711 TS ts;
1712 CHKERR TSCreate(PETSC_COMM_WORLD, &ts);
1713 // Use backward Euler method
1714 CHKERR TSSetType(ts, TSBEULER);
1715 // Set final time
1716 double ftime = 1;
1717 CHKERR TSSetDuration(ts, PETSC_DEFAULT, ftime);
1718 // Setup solver from commabd line
1719 CHKERR TSSetFromOptions(ts);
1720 // Set DM to TS
1721 CHKERR TSSetDM(ts, dM);
1722#if PETSC_VERSION_GE(3, 7, 0)
1723 CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_STEPOVER);
1724#endif
1725 // Set-up monitor
1726 TsCtx *ts_ctx;
1728 CHKERR TSMonitorSet(ts, TsMonitorSet, ts_ctx, PETSC_NULL);
1729
1730 // This add SNES monitor, to show error by fields. It is dirty trick
1731 // to add monitor, so code is hidden from doxygen
1732 CHKERR TSSetSolution(ts, D);
1733 CHKERR TSSetUp(ts);
1734 SNES snes;
1735 CHKERR TSGetSNES(ts, &snes);
1736
1737#if PETSC_VERSION_GE(3, 7, 0)
1738 {
1739 PetscViewerAndFormat *vf;
1740 CHKERR PetscViewerAndFormatCreate(PETSC_VIEWER_STDOUT_WORLD,
1741 PETSC_VIEWER_DEFAULT, &vf);
1742 CHKERR SNESMonitorSet(
1743 snes,
1744 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
1745 void *))SNESMonitorFields,
1746 vf, (MoFEMErrorCode(*)(void **))PetscViewerAndFormatDestroy);
1747 }
1748#else
1749 {
1750 CHKERR SNESMonitorSet(snes,
1751 (MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
1752 void *))SNESMonitorFields,
1753 0, 0);
1754 }
1755#endif
1756
1757 CHKERR TSSolve(ts, D);
1758
1759 // Get statistic form TS and print it
1760 CHKERR TSGetTime(ts, &ftime);
1761 PetscInt steps, snesfails, rejects, nonlinits, linits;
1762 CHKERR TSGetTimeStepNumber(ts, &steps);
1763 CHKERR TSGetSNESFailures(ts, &snesfails);
1764 CHKERR TSGetStepRejections(ts, &rejects);
1765 CHKERR TSGetSNESIterations(ts, &nonlinits);
1766 CHKERR TSGetKSPIterations(ts, &linits);
1767 PetscPrintf(PETSC_COMM_WORLD,
1768 "steps %D (%D rejected, %D SNES fails), ftime %g, nonlinits "
1769 "%D, linits %D\n",
1770 steps, rejects, snesfails, ftime, nonlinits, linits);
1771
1773 }
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition: DMMoFEM.cpp:509
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56

Member Data Documentation

◆ bcFluxMap

BcMap MixTransport::UnsaturatedFlowElement::bcFluxMap
Examples
UnsaturatedFlow.hpp.

Definition at line 197 of file UnsaturatedFlow.hpp.

◆ bcValueMap

BcMap MixTransport::UnsaturatedFlowElement::bcValueMap

Store boundary condition for head capillary pressure.

Examples
UnsaturatedFlow.hpp.

Definition at line 153 of file UnsaturatedFlow.hpp.

◆ bcVecIds

std::vector<int> MixTransport::UnsaturatedFlowElement::bcVecIds
Examples
UnsaturatedFlow.hpp.

Definition at line 1323 of file UnsaturatedFlow.hpp.

◆ bcVecVals

VectorDouble MixTransport::UnsaturatedFlowElement::bcVecVals
Examples
UnsaturatedFlow.hpp.

Definition at line 1324 of file UnsaturatedFlow.hpp.

◆ D1

Vec MixTransport::UnsaturatedFlowElement::D1

Vector with inital head capillary pressure.

Examples
UnsaturatedFlow.hpp.

Definition at line 1609 of file UnsaturatedFlow.hpp.

◆ dM

DM MixTransport::UnsaturatedFlowElement::dM

Discrete manager for unsaturated flow problem.

Examples
UnsaturatedFlow.hpp.

Definition at line 104 of file UnsaturatedFlow.hpp.

◆ dMatMap

MaterialsDoubleMap MixTransport::UnsaturatedFlowElement::dMatMap

materials database

Examples
UnsaturatedFlow.hpp.

Definition at line 119 of file UnsaturatedFlow.hpp.

◆ feFaceBc

boost::shared_ptr<ForcesAndSourcesCore> MixTransport::UnsaturatedFlowElement::feFaceBc

Elemnet to calculate essential bc.

Examples
UnsaturatedFlow.hpp.

Definition at line 1287 of file UnsaturatedFlow.hpp.

◆ feFaceRhs

boost::shared_ptr<ForcesAndSourcesCore> MixTransport::UnsaturatedFlowElement::feFaceRhs

Face element apply natural bc.

Examples
UnsaturatedFlow.hpp.

Definition at line 1289 of file UnsaturatedFlow.hpp.

◆ feVolInitialPc

boost::shared_ptr<ForcesAndSourcesCore> MixTransport::UnsaturatedFlowElement::feVolInitialPc

Calculate inital boundary conditions.

Examples
UnsaturatedFlow.hpp.

Definition at line 1291 of file UnsaturatedFlow.hpp.

◆ feVolLhs

boost::shared_ptr<ForcesAndSourcesCore> MixTransport::UnsaturatedFlowElement::feVolLhs

Assemble tangent matrix.

Examples
UnsaturatedFlow.hpp.

Definition at line 1294 of file UnsaturatedFlow.hpp.

◆ feVolRhs

boost::shared_ptr<ForcesAndSourcesCore> MixTransport::UnsaturatedFlowElement::feVolRhs

Assemble residual vector.

Examples
UnsaturatedFlow.hpp.

Definition at line 1293 of file UnsaturatedFlow.hpp.

◆ ghostFlux

Vec MixTransport::UnsaturatedFlowElement::ghostFlux

Ghost Vector of integrated fluxes.

Examples
UnsaturatedFlow.hpp.

Definition at line 1610 of file UnsaturatedFlow.hpp.

◆ headRateAtGaussPts

boost::shared_ptr<VectorDouble> MixTransport::UnsaturatedFlowElement::headRateAtGaussPts

Vector keeps head rate.

Examples
UnsaturatedFlow.hpp.

Definition at line 1303 of file UnsaturatedFlow.hpp.

◆ lastEvalBcBlockFluxId

int MixTransport::UnsaturatedFlowElement::lastEvalBcBlockFluxId
Examples
UnsaturatedFlow.hpp.

Definition at line 199 of file UnsaturatedFlow.hpp.

◆ lastEvalBcBlockValId

int MixTransport::UnsaturatedFlowElement::lastEvalBcBlockValId
Examples
UnsaturatedFlow.hpp.

Definition at line 156 of file UnsaturatedFlow.hpp.

◆ lastEvalBcFluxEnt

EntityHandle MixTransport::UnsaturatedFlowElement::lastEvalBcFluxEnt
Examples
UnsaturatedFlow.hpp.

Definition at line 198 of file UnsaturatedFlow.hpp.

◆ lastEvalBcValEnt

EntityHandle MixTransport::UnsaturatedFlowElement::lastEvalBcValEnt
Examples
UnsaturatedFlow.hpp.

Definition at line 155 of file UnsaturatedFlow.hpp.

◆ scaleMethodFlux

boost::shared_ptr<MethodForForceScaling> MixTransport::UnsaturatedFlowElement::scaleMethodFlux

Method scaling fluxes.

Examples
UnsaturatedFlow.hpp.

Definition at line 1296 of file UnsaturatedFlow.hpp.

◆ scaleMethodValue

boost::shared_ptr<MethodForForceScaling> MixTransport::UnsaturatedFlowElement::scaleMethodValue

Method scaling values.

Examples
UnsaturatedFlow.hpp.

Definition at line 1298 of file UnsaturatedFlow.hpp.

◆ tsMonitor

boost::shared_ptr<FEMethod> MixTransport::UnsaturatedFlowElement::tsMonitor

Element used by TS monitor to postprocess results at time step

Examples
UnsaturatedFlow.hpp.

Definition at line 1299 of file UnsaturatedFlow.hpp.

◆ vecValsOnBc

VectorDouble MixTransport::UnsaturatedFlowElement::vecValsOnBc
Examples
UnsaturatedFlow.hpp.

Definition at line 1324 of file UnsaturatedFlow.hpp.


The documentation for this struct was generated from the following file: