v0.13.1
LoopMethods.cpp
Go to the documentation of this file.
1/** \file LoopMethods.cpp
2\brief methods for managing loops
3*/
4
5
6#include <MoFEM.hpp>
7
8namespace MoFEM {
9
18
19// PetscData
21PetscData::query_interface(boost::typeindex::type_index type_index,
22 UnknownInterface **iface) const {
23 *iface = const_cast<PetscData *>(this);
24 return 0;
25}
26
28 : data_ctx(PetscData::CtxSetNone), f(PETSC_NULL), A(PETSC_NULL),
29 B(PETSC_NULL), x(PETSC_NULL), x_t(PETSC_NULL), x_tt(PETSC_NULL) {}
30
32 this->data_ctx = petsc_data.data_ctx;
33 this->f = petsc_data.f;
34 this->A = petsc_data.A;
35 this->B = petsc_data.B;
36 this->x = petsc_data.x;
37 this->x = petsc_data.x;
38 this->x_t = petsc_data.x_t;
39 this->x_tt = petsc_data.x_tt;
40 return 0;
41}
42
43// KSP
45KspMethod::query_interface(boost::typeindex::type_index type_index,
46 UnknownInterface **iface) const {
47 *iface = const_cast<KspMethod *>(this);
48 return 0;
49};
50
52 : ksp_ctx(CTX_KSPNONE), ksp(PETSC_NULL), ksp_f(PetscData::f),
53 ksp_A(PetscData::A), ksp_B(PetscData::B) {}
54
58 this->ksp_ctx = ksp.ksp_ctx;
59 this->ksp = ksp.ksp;
61}
62
63// SNES
65SnesMethod::query_interface(boost::typeindex::type_index type_index,
66 UnknownInterface **iface) const {
67 *iface = const_cast<SnesMethod *>(this);
68 return 0;
69}
70
72 : snes_ctx(CTX_SNESNONE), snes_x(PetscData::x), snes_f(PetscData::f),
73 snes_A(PetscData::A), snes_B(PetscData::B) {}
74
78 this->snes_ctx = snes.snes_ctx;
79 this->snes = snes.snes;
81}
82
83// TS
85TSMethod::query_interface(boost::typeindex::type_index type_index,
86 UnknownInterface **iface) const {
87 *iface = const_cast<TSMethod *>(this);
88 return 0;
89}
90
92 : ts_ctx(CTX_TSNONE), ts_step(-1), ts_a(0), ts_t(0), ts_u(PetscData::x),
93 ts_u_t(PetscData::x_t), ts_u_tt(PetscData::x_tt), ts_F(PetscData::f),
94 ts_A(PetscData::A), ts_B(PetscData::B) {}
95
99 this->ts_ctx = ts.ts_ctx;
100 this->ts = ts.ts;
101 this->ts_step = ts.ts_step;
102 this->ts_a = ts.ts_a;
103 this->ts_t = ts.ts_t;
105}
106
107// BasicMethod
109 : PetscData(), KspMethod(), SnesMethod(), TSMethod(), nInTheLoop(0),
110 loopSize(0), rAnk(-1), sIze(-1), refinedEntitiesPtr(nullptr),
111 refinedFiniteElementsPtr(nullptr), problemPtr(nullptr),
112 fieldsPtr(nullptr), entitiesPtr(nullptr), dofsPtr(nullptr),
113 finiteElementsPtr(nullptr), finiteElementsEntitiesPtr(nullptr),
114 adjacenciesPtr(nullptr) {}
115
118
119 this->nInTheLoop = basic.nInTheLoop;
120 this->loopSize = basic.loopSize;
121 this->rAnk = basic.rAnk;
122 this->sIze = basic.sIze;
125 this->problemPtr = basic.problemPtr;
126 this->fieldsPtr = basic.fieldsPtr;
127 this->entitiesPtr = basic.entitiesPtr;
128 this->dofsPtr = basic.dofsPtr;
131 this->adjacenciesPtr = basic.adjacenciesPtr;
132 this->cacheWeakPtr = basic.cacheWeakPtr;
133
135}
136
139 if (preProcessHook) {
141 CHKERRG(ierr);
142 } else {
143 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
144 "should be implemented by user in derived class (preProcess)");
145 }
147}
150 if (postProcessHook) {
152 CHKERRG(ierr);
153 } else {
154 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
155 "should be implemented by user in derived class (postProcess)");
156 }
158}
161 if (operatorHook) {
162 ierr = operatorHook();
163 CHKERRG(ierr);
164 } else {
165 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
166 "should be implemented by user in derived class (operator)");
167 }
169}
170
172 VectorDouble &data,
173 const bool reset_dofs) {
175
176 // TODO: [CORE-60] Fix implementation not to use DOFs
177
178 auto get_nodes_field_data =
179 [&](boost::shared_ptr<FEDofEntity_multiIndex> &&dofs,
180 VectorDouble &nodes_data) {
182
183 auto bit_number = getFieldBitNumber(field_name);
184 auto &dofs_by_uid = dofs->get<Unique_mi_tag>();
185 auto dit =
186 dofs_by_uid.lower_bound(FieldEntity::getLocalUniqueIdCalculate(
187 bit_number, get_id_for_min_type<MBVERTEX>()));
188 auto hi_dit =
189 dofs_by_uid.upper_bound(FieldEntity::getLocalUniqueIdCalculate(
190 bit_number, get_id_for_max_type<MBVERTEX>()));
191
192 if (dit != hi_dit) {
193 auto &first_dof = **dit;
194 const int num_nodes = getNumberOfNodes();
195 const int nb_dof_idx = first_dof.getNbOfCoeffs();
196 const int max_nb_dofs = nb_dof_idx * num_nodes;
197 nodes_data.resize(max_nb_dofs, false);
198 nodes_data.clear();
199
200 for (; dit != hi_dit;) {
201 const auto &dof_ptr = *dit;
202 const auto &dof = *dof_ptr;
203 const auto &sn = *dof.getSideNumberPtr();
204 const int side_number = sn.side_number;
205
206 int pos = side_number * nb_dof_idx;
207 auto ent_filed_data_vec = dof.getEntFieldData();
208 for (int ii = 0; ii != nb_dof_idx; ++ii) {
209 nodes_data[pos] = ent_filed_data_vec[ii];
210 ++pos;
211 ++dit;
212 }
213 }
214
215 } else if (reset_dofs) {
216 nodes_data.resize(0, false);
217 }
218
220 };
221
222 return get_nodes_field_data(getDataDofsPtr(), data);
223
225}
226
227} // namespace MoFEM
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:483
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition: definitions.h:34
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
auto f
Definition: HenckyOps.hpp:5
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
implementation of Data Operators for Forces and Sources
Definition: MoFEM.hpp:24
double A
constexpr auto field_name
Data structure to exchange data between mofem and User Loop Methods.
int loopSize
local number oe methods to process
const FieldEntity_multiIndex * entitiesPtr
raw pointer to container of field entities
unsigned int getFieldBitNumber(std::string field_name) const
MoFEMErrorCode copyBasicMethod(const BasicMethod &basic)
Copy data from other base method to this base method.
const FiniteElement_multiIndex * finiteElementsPtr
raw pointer to container finite elements
const RefElement_multiIndex * refinedFiniteElementsPtr
container of mofem finite element entities
boost::function< MoFEMErrorCode()> preProcessHook
Hook function for pre-processing.
const DofEntity_multiIndex * dofsPtr
raw pointer container of dofs
int rAnk
processor rank
const Field_multiIndex * fieldsPtr
raw pointer to fields container
int nInTheLoop
number currently of processed method
const RefEntity_multiIndex * refinedEntitiesPtr
container of mofem dof entities
virtual MoFEMErrorCode postProcess()
function is run at the end of loop
const FieldEntityEntFiniteElementAdjacencyMap_multiIndex * adjacenciesPtr
virtual MoFEMErrorCode operator()()
function is run for every finite element
virtual MoFEMErrorCode preProcess()
function is run at the beginning of loop
const EntFiniteElement_multiIndex * finiteElementsEntitiesPtr
const Problem * problemPtr
raw pointer to problem
boost::function< MoFEMErrorCode()> operatorHook
Hook function for operator.
int sIze
number of processors in communicator
boost::weak_ptr< CacheTuple > cacheWeakPtr
boost::function< MoFEMErrorCode()> postProcessHook
Hook function for post-processing.
MoFEMErrorCode getNodeData(const std::string field_name, VectorDouble &data, const bool reset_dofs=true)
auto getDataDofsPtr() const
auto getNumberOfNodes() const
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
data structure for ksp (linear solver) context
Definition: LoopMethods.hpp:64
MoFEMErrorCode copyKsp(const KspMethod &ksp)
copy data form another method
Definition: LoopMethods.cpp:55
KSPContext ksp_ctx
Context.
Definition: LoopMethods.hpp:86
KSP ksp
KSP solver.
Definition: LoopMethods.hpp:87
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition: LoopMethods.cpp:45
static constexpr Switches CtxSetA
Definition: LoopMethods.hpp:37
static constexpr Switches CtxSetX
Definition: LoopMethods.hpp:39
static constexpr Switches CtxSetX_TT
Definition: LoopMethods.hpp:41
static constexpr Switches CtxSetNone
Definition: LoopMethods.hpp:35
static constexpr Switches CtxSetF
Definition: LoopMethods.hpp:36
std::bitset< 8 > Switches
Definition: LoopMethods.hpp:33
static constexpr Switches CtxSetX_T
Definition: LoopMethods.hpp:40
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition: LoopMethods.cpp:21
static constexpr Switches CtxSetB
Definition: LoopMethods.hpp:38
static constexpr Switches CtxSetTime
Definition: LoopMethods.hpp:42
MoFEMErrorCode copyPetscData(const PetscData &petsc_data)
Definition: LoopMethods.cpp:31
data structure for snes (nonlinear solver) context
MoFEMErrorCode copySnes(const SnesMethod &snes)
Copy snes data.
Definition: LoopMethods.cpp:75
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition: LoopMethods.cpp:65
SNESContext snes_ctx
SNES snes
snes solver
data structure for TS (time stepping) context
TS ts
time solver
PetscReal ts_t
time
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition: LoopMethods.cpp:85
TSContext ts_ctx
PetscReal ts_a
shift for U_t (see PETSc Time Solver)
PetscInt ts_step
time step
MoFEMErrorCode copyTs(const TSMethod &ts)
Copy TS solver data.
Definition: LoopMethods.cpp:96
base class for all interface classes