v0.15.0
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
MoFEM::OpCalculateScalarFieldValuesFromPetscVecImpl< CTX > Struct Template Reference

Calculate scalar field values from PETSc vector at integration points. More...

#include "src/finite_elements/UserDataOperators.hpp"

Inheritance diagram for MoFEM::OpCalculateScalarFieldValuesFromPetscVecImpl< CTX >:
[legend]
Collaboration diagram for MoFEM::OpCalculateScalarFieldValuesFromPetscVecImpl< CTX >:
[legend]

Public Member Functions

 OpCalculateScalarFieldValuesFromPetscVecImpl (const std::string field_name, boost::shared_ptr< VectorDouble > data_ptr, const EntityType zero_at_type=MBVERTEX)
 Constructor for PETSc vector-based scalar field calculation.
 
MoFEMErrorCode doWork (int side, EntityType type, EntitiesFieldData::EntData &data)
 Operator for linear form, usually to calculate values on right hand side.
 
- Public Member Functions inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
 UserDataOperator (const FieldSpace space, const char type=OPSPACE, const bool symm=true)
 Constructor for operators working on finite element spaces.
 
 UserDataOperator (const std::string field_name, const char type, const bool symm=true)
 Constructor for operators working on a single field.
 
 UserDataOperator (const std::string row_field_name, const std::string col_field_name, const char type, const bool symm=true)
 Constructor for operators working on two fields (bilinear forms)
 
boost::shared_ptr< const NumeredEntFiniteElementgetNumeredEntFiniteElementPtr () const
 Return raw pointer to NumeredEntFiniteElement.
 
EntityHandle getFEEntityHandle () const
 Return finite element entity handle.
 
int getFEDim () const
 Get dimension of finite element.
 
EntityType getFEType () const
 Get dimension of finite element.
 
boost::weak_ptr< SideNumbergetSideNumberPtr (const int side_number, const EntityType type)
 Get the side number pointer.
 
EntityHandle getSideEntity (const int side_number, const EntityType type)
 Get the side entity.
 
int getNumberOfNodesOnElement () const
 Get the number of nodes on finite element.
 
MoFEMErrorCode getProblemRowIndices (const std::string filed_name, const EntityType type, const int side, VectorInt &indices) const
 Get row indices.
 
MoFEMErrorCode getProblemColIndices (const std::string filed_name, const EntityType type, const int side, VectorInt &indices) const
 Get col indices.
 
const FEMethodgetFEMethod () const
 Return raw pointer to Finite Element Method object.
 
int getOpType () const
 Get operator types.
 
void setOpType (const OpType type)
 Set operator type.
 
void addOpType (const OpType type)
 Add operator type.
 
int getNinTheLoop () const
 get number of finite element in the loop
 
int getLoopSize () const
 get size of elements in the loop
 
std::string getFEName () const
 Get name of the element.
 
ForcesAndSourcesCoregetPtrFE () const
 
ForcesAndSourcesCoregetSidePtrFE () const
 
ForcesAndSourcesCoregetRefinePtrFE () const
 
const PetscData::SwitchesgetDataCtx () const
 
const KspMethod::KSPContext getKSPCtx () const
 
const SnesMethod::SNESContext getSNESCtx () const
 
const TSMethod::TSContext getTSCtx () const
 
Vec getKSPf () const
 
Mat getKSPA () const
 
Mat getKSPB () const
 
Vec getSNESf () const
 
Vec getSNESx () const
 
Mat getSNESA () const
 
Mat getSNESB () const
 
Vec getTSu () const
 
Vec getTSu_t () const
 
Vec getTSu_tt () const
 
Vec getTSf () const
 
Mat getTSA () const
 
Mat getTSB () const
 
int getTSstep () const
 
double getTStime () const
 
double getTStimeStep () const
 
double getTSa () const
 
double getTSaa () const
 
MatrixDoublegetGaussPts ()
 matrix of integration (Gauss) points for Volume Element
 
auto getFTensor0IntegrationWeight ()
 Get integration weights.
 
MatrixDoublegetCoordsAtGaussPts ()
 Gauss points and weight, matrix (nb. of points x 3)
 
auto getFTensor1CoordsAtGaussPts ()
 Get coordinates at integration points assuming linear geometry.
 
double getMeasure () const
 get measure of element
 
doublegetMeasure ()
 get measure of element
 
MoFEMErrorCode loopSide (const string &fe_name, ForcesAndSourcesCore *side_fe, const size_t dim, const EntityHandle ent_for_side=0, boost::shared_ptr< Range > fe_range=nullptr, const int verb=QUIET, const LogManager::SeverityLevel sev=Sev::noisy, AdjCache *adj_cache=nullptr)
 User calls this function to loop over elements on the side of face. This function calls finite element with its operator to do calculations.
 
MoFEMErrorCode loopThis (const string &fe_name, ForcesAndSourcesCore *this_fe, const int verb=QUIET, const LogManager::SeverityLevel sev=Sev::noisy)
 User calls this function to loop over the same element using a different set of integration points. This function calls finite element with its operator to do calculations.
 
MoFEMErrorCode loopParent (const string &fe_name, ForcesAndSourcesCore *parent_fe, const int verb=QUIET, const LogManager::SeverityLevel sev=Sev::noisy)
 User calls this function to loop over parent elements. This function calls finite element with its operator to do calculations.
 
MoFEMErrorCode loopChildren (const string &fe_name, ForcesAndSourcesCore *child_fe, const int verb=QUIET, const LogManager::SeverityLevel sev=Sev::noisy)
 User calls this function to loop over parent elements. This function calls finite element with its operator to do calculations.
 
MoFEMErrorCode loopRange (const string &fe_name, ForcesAndSourcesCore *range_fe, boost::shared_ptr< Range > fe_range, const int verb=QUIET, const LogManager::SeverityLevel sev=Sev::noisy)
 Iterate over range of elements.
 
- Public Member Functions inherited from MoFEM::DataOperator
 DataOperator (const bool symm=true)
 
virtual ~DataOperator ()=default
 
virtual MoFEMErrorCode doWork (int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
 Operator for bi-linear form, usually to calculate values on left hand side.
 
virtual MoFEMErrorCode opLhs (EntitiesFieldData &row_data, EntitiesFieldData &col_data)
 
virtual MoFEMErrorCode opRhs (EntitiesFieldData &data, const bool error_if_no_base=false)
 
bool getSymm () const
 Get if operator uses symmetry of DOFs or not.
 
void setSymm ()
 set if operator is executed taking in account symmetry
 
void unSetSymm ()
 unset if operator is executed for non symmetric problem
 

Private Attributes

boost::shared_ptr< VectorDoubledataPtr
 
const EntityHandle zeroAtType
 

Additional Inherited Members

- Public Types inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
enum  OpType {
  OPROW = 1 << 0 , OPCOL = 1 << 1 , OPROWCOL = 1 << 2 , OPSPACE = 1 << 3 ,
  OPLAST = 1 << 3
}
 Controls loop over entities on element. More...
 
using AdjCache = std::map< EntityHandle, std::vector< boost::weak_ptr< NumeredEntFiniteElement > > >
 
- Public Types inherited from MoFEM::DataOperator
using DoWorkLhsHookFunType = boost::function< MoFEMErrorCode(DataOperator *op_ptr, int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)>
 
using DoWorkRhsHookFunType = boost::function< MoFEMErrorCode(DataOperator *op_ptr, int side, EntityType type, EntitiesFieldData::EntData &data)>
 
- Public Attributes inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
char opType
 
std::string rowFieldName
 
std::string colFieldName
 
FieldSpace sPace
 
- Public Attributes inherited from MoFEM::DataOperator
DoWorkLhsHookFunType doWorkLhsHook
 
DoWorkRhsHookFunType doWorkRhsHook
 
bool sYmm
 If true assume that matrix is symmetric structure.
 
std::array< bool, MBMAXTYPE > doEntities
 If true operator is executed for entity.
 
booldoVertices
 \deprectaed If false skip vertices
 
booldoEdges
 \deprectaed If false skip edges
 
booldoQuads
 \deprectaed
 
booldoTris
 \deprectaed
 
booldoTets
 \deprectaed
 
booldoPrisms
 \deprectaed
 
- Static Public Attributes inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
static const char *const OpTypeNames []
 
- Protected Member Functions inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
virtual MoFEMErrorCode setPtrFE (ForcesAndSourcesCore *ptr)
 
- Protected Attributes inherited from MoFEM::ForcesAndSourcesCore::UserDataOperator
ForcesAndSourcesCoreptrFE
 

Detailed Description

template<PetscData::DataContext CTX>
struct MoFEM::OpCalculateScalarFieldValuesFromPetscVecImpl< CTX >

Calculate scalar field values from PETSc vector at integration points.

This template structure extracts scalar field values from a PETSc vector and calculates them at integration points. It supports different data contexts through the template parameter and can handle various entity types.

Template Parameters
CTXPETSc data context type specifying how data is accessed
Examples
mofem/tutorials/cor-9/reaction_diffusion.cpp.

Definition at line 282 of file UserDataOperators.hpp.

Constructor & Destructor Documentation

◆ OpCalculateScalarFieldValuesFromPetscVecImpl()

template<PetscData::DataContext CTX>
MoFEM::OpCalculateScalarFieldValuesFromPetscVecImpl< CTX >::OpCalculateScalarFieldValuesFromPetscVecImpl ( const std::string  field_name,
boost::shared_ptr< VectorDouble data_ptr,
const EntityType  zero_at_type = MBVERTEX 
)
inline

Constructor for PETSc vector-based scalar field calculation.

Parameters
field_nameName of the scalar field to extract values from
data_ptrShared pointer to VectorDouble for storing calculated values
zero_at_typeEntity type where values should be zeroed (default: MBVERTEX)

Definition at line 292 of file UserDataOperators.hpp.

295 : ForcesAndSourcesCore::UserDataOperator(
296 field_name, ForcesAndSourcesCore::UserDataOperator::OPROW),
297 dataPtr(data_ptr), zeroAtType(zero_at_type) {
298 if (!dataPtr)
299 THROW_MESSAGE("Pointer is not set");
300 }
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
constexpr auto field_name

Member Function Documentation

◆ doWork()

template<PetscData::DataContext CTX>
MoFEMErrorCode MoFEM::OpCalculateScalarFieldValuesFromPetscVecImpl< CTX >::doWork ( int  side,
EntityType  type,
EntitiesFieldData::EntData data 
)
inlinevirtual

Operator for linear form, usually to calculate values on right hand side.

Reimplemented from MoFEM::DataOperator.

Definition at line 302 of file UserDataOperators.hpp.

303 {
305
306 const size_t nb_gauss_pts = getGaussPts().size2();
307
308 VectorDouble &vec = *dataPtr;
309 if (type == zeroAtType || vec.size() != nb_gauss_pts) {
310 vec.resize(nb_gauss_pts, false);
311 vec.clear();
312 }
313
314 auto &local_indices = data.getLocalIndices();
315 const size_t nb_dofs = local_indices.size();
316 if (nb_dofs) {
317
318 const double *array;
319
320 auto get_array = [&](const auto ctx, auto vec) {
322 #ifndef NDEBUG
323 if ((getFEMethod()->data_ctx & ctx).none()) {
324 MOFEM_LOG_CHANNEL("SELF");
325 MOFEM_LOG("SELF", Sev::error)
326 << "In this case field degrees of freedom are read from vector. "
327 "That usually happens when time solver is used, and acces to "
328 "first or second rates is needed. You probably not set ts_u, "
329 "ts_u_t, or ts_u_tt and associated data structure, i.e. "
330 "data_ctx to CTX_SET_X, CTX_SET_X_T, or CTX_SET_X_TT "
331 "respectively";
332 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vector not set!");
333 }
334 #endif
335 CHKERR VecGetArrayRead(vec, &array);
337 };
338
339 auto restore_array = [&](auto vec) {
340 return VecRestoreArrayRead(vec, &array);
341 };
342
343 switch (CTX) {
345 CHKERR get_array(PetscData::CtxSetX, getFEMethod()->ts_u);
346 break;
348 CHKERR get_array(PetscData::CtxSetX_T, getFEMethod()->ts_u_t);
349 break;
351 CHKERR get_array(PetscData::CtxSetX_TT, getFEMethod()->ts_u_tt);
352 break;
353 default:
354 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
355 "That case is not implemented");
356 }
357
358 std::array<double, MAX_DOFS_ON_ENTITY> dot_dofs_vector;
359 for (int i = 0; i != local_indices.size(); ++i)
360 if (local_indices[i] != -1)
361 dot_dofs_vector[i] = array[local_indices[i]];
362 else
363 dot_dofs_vector[i] = 0;
364
365 switch (CTX) {
367 CHKERR restore_array(getFEMethod()->ts_u);
368 break;
370 CHKERR restore_array(getFEMethod()->ts_u_t);
371 break;
373 CHKERR restore_array(getFEMethod()->ts_u_tt);
374 break;
375 default:
376 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
377 "That case is not implemented");
378 }
379
380 const size_t nb_base_functions = data.getN().size2();
381 auto base_function = data.getFTensor0N();
382 auto values_at_gauss_pts = getFTensor0FromVec(vec);
383
384 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
385 size_t bb = 0;
386 for (; bb != nb_dofs; ++bb) {
387 values_at_gauss_pts += dot_dofs_vector[bb] * base_function;
388 ++base_function;
389 }
390 // Number of dofs can be smaller than number of Tensor_Dim x base
391 // functions
392 for (; bb < nb_base_functions; ++bb)
393 ++base_function;
394 ++values_at_gauss_pts;
395 }
396 }
398 }
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
UBlasVector< double > VectorDouble
Definition Types.hpp:68
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
const FEMethod * getFEMethod() const
Return raw pointer to Finite Element Method object.
MatrixDouble & getGaussPts()
matrix of integration (Gauss) points for Volume Element
static constexpr Switches CtxSetX
Solution vector switch.
static constexpr Switches CtxSetX_TT
Second time derivative switch.
static constexpr Switches CtxSetX_T
First time derivative switch.
@ CTX_SET_X_T
Time derivative X_t is set.
@ CTX_SET_X
Solution vector X is set.
@ CTX_SET_X_TT
Second time derivative X_tt is set.

Member Data Documentation

◆ dataPtr

template<PetscData::DataContext CTX>
boost::shared_ptr<VectorDouble> MoFEM::OpCalculateScalarFieldValuesFromPetscVecImpl< CTX >::dataPtr
private

Definition at line 401 of file UserDataOperators.hpp.

◆ zeroAtType

Definition at line 402 of file UserDataOperators.hpp.


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