v0.14.0
Loading...
Searching...
No Matches
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;
104 this->ts_dt = ts.ts_dt;
106}
107
108// BasicMethod
110 : PetscData(), KspMethod(), SnesMethod(), TSMethod(), nInTheLoop(0),
111 loopSize(0), rAnk(-1), sIze(-1), refinedEntitiesPtr(nullptr),
112 refinedFiniteElementsPtr(nullptr), problemPtr(nullptr),
113 fieldsPtr(nullptr), entitiesPtr(nullptr), dofsPtr(nullptr),
114 finiteElementsPtr(nullptr), finiteElementsEntitiesPtr(nullptr),
115 adjacenciesPtr(nullptr) {}
116
119
120 this->nInTheLoop = basic.nInTheLoop;
121 this->loopSize = basic.loopSize;
122 this->rAnk = basic.rAnk;
123 this->sIze = basic.sIze;
126 this->problemPtr = basic.problemPtr;
127 this->fieldsPtr = basic.fieldsPtr;
128 this->entitiesPtr = basic.entitiesPtr;
129 this->dofsPtr = basic.dofsPtr;
132 this->adjacenciesPtr = basic.adjacenciesPtr;
133 this->cacheWeakPtr = basic.cacheWeakPtr;
134
136}
137
140 if (preProcessHook) {
142 CHKERRG(ierr);
143 } else {
144 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
145 "should be implemented by user in derived class (preProcess)");
146 }
148}
151 if (postProcessHook) {
153 CHKERRG(ierr);
154 } else {
155 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
156 "should be implemented by user in derived class (postProcess)");
157 }
159}
162 if (operatorHook) {
163 ierr = operatorHook();
164 CHKERRG(ierr);
165 } else {
166 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
167 "should be implemented by user in derived class (operator)");
168 }
170}
171
173 VectorDouble &data,
174 const bool reset_dofs) {
176
177 // TODO: [CORE-60] Fix implementation not to use DOFs
178
179 auto get_nodes_field_data =
180 [&](boost::shared_ptr<FEDofEntity_multiIndex> &&dofs,
181 VectorDouble &nodes_data) {
183
184 auto bit_number = getFieldBitNumber(field_name);
185 auto &dofs_by_uid = dofs->get<Unique_mi_tag>();
186 auto dit =
187 dofs_by_uid.lower_bound(FieldEntity::getLocalUniqueIdCalculate(
188 bit_number, get_id_for_min_type<MBVERTEX>()));
189 auto hi_dit =
190 dofs_by_uid.upper_bound(FieldEntity::getLocalUniqueIdCalculate(
191 bit_number, get_id_for_max_type<MBVERTEX>()));
192
193 if (dit != hi_dit) {
194 auto &first_dof = **dit;
195 const int num_nodes = getNumberOfNodes();
196 const int nb_dof_idx = first_dof.getNbOfCoeffs();
197 const int max_nb_dofs = nb_dof_idx * num_nodes;
198 nodes_data.resize(max_nb_dofs, false);
199 nodes_data.clear();
200
201 for (; dit != hi_dit;) {
202 const auto &dof_ptr = *dit;
203 const auto &dof = *dof_ptr;
204 const auto &sn = *dof.getSideNumberPtr();
205 const int side_number = sn.side_number;
206
207 int pos = side_number * nb_dof_idx;
208 auto ent_filed_data_vec = dof.getEntFieldData();
209 for (int ii = 0; ii != nb_dof_idx; ++ii) {
210 nodes_data[pos] = ent_filed_data_vec[ii];
211 ++pos;
212 ++dit;
213 }
214 }
215
216 } else if (reset_dofs) {
217 nodes_data.resize(0, false);
218 }
219
221 };
222
223 return get_nodes_field_data(getDataDofsPtr(), data);
224
226}
227
228} // 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
MoFEM::TsCtx * ts_ctx
Definition: level_set.cpp:1884
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: Common.hpp:10
constexpr AssemblyType 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
PetscReal ts_dt
time step size
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 number
MoFEMErrorCode copyTs(const TSMethod &ts)
Copy TS solver data.
Definition: LoopMethods.cpp:96
base class for all interface classes