v0.15.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_NULLPTR), A(PETSC_NULLPTR),
29 B(PETSC_NULLPTR), x(PETSC_NULLPTR), dx(PETSC_NULLPTR), x_t(PETSC_NULLPTR),
30 x_tt(PETSC_NULLPTR) {}
31
33 this->data_ctx = petsc_data.data_ctx;
34 this->f = petsc_data.f;
35 this->A = petsc_data.A;
36 this->B = petsc_data.B;
37 this->x = petsc_data.x;
38 this->dx = petsc_data.dx;
39 this->x_t = petsc_data.x_t;
40 this->x_tt = petsc_data.x_tt;
41 return 0;
42}
43
44// KSP
46KspMethod::query_interface(boost::typeindex::type_index type_index,
47 UnknownInterface **iface) const {
48 *iface = const_cast<KspMethod *>(this);
49 return 0;
50};
51
53 : ksp_ctx(CTX_KSPNONE), ksp(PETSC_NULLPTR), ksp_f(PetscData::f),
54 ksp_A(PetscData::A), ksp_B(PetscData::B) {}
55
63
64// SNES
66SnesMethod::query_interface(boost::typeindex::type_index type_index,
67 UnknownInterface **iface) const {
68 *iface = const_cast<SnesMethod *>(this);
69 return 0;
70}
71
73 : snes_ctx(CTX_SNESNONE), snes_x(PetscData::x), snes_dx(PetscData::dx),
74 snes_f(PetscData::f), snes_A(PetscData::A), snes_B(PetscData::B) {}
75
83
84// TS
86TSMethod::query_interface(boost::typeindex::type_index type_index,
87 UnknownInterface **iface) const {
88 *iface = const_cast<TSMethod *>(this);
89 return 0;
90}
91
93 : ts_ctx(CTX_TSNONE), ts_step(-1), ts_a(0), ts_t(0), ts_u(PetscData::x),
94 ts_u_t(PetscData::x_t), ts_u_tt(PetscData::x_tt), ts_F(PetscData::f),
95 ts_A(PetscData::A), ts_B(PetscData::B) {}
96
100 this->ts_ctx = ts.ts_ctx;
101 this->ts = ts.ts;
102 this->ts_step = ts.ts_step;
103 this->ts_a = ts.ts_a;
104 this->ts_t = ts.ts_t;
105 this->ts_dt = ts.ts_dt;
107}
108
109// BasicMethod
111 : PetscData(), KspMethod(), SnesMethod(), TSMethod(), nInTheLoop(0),
112 loopSize(0), rAnk(-1), sIze(-1), refinedEntitiesPtr(nullptr),
113 refinedFiniteElementsPtr(nullptr), problemPtr(nullptr),
114 fieldsPtr(nullptr), entitiesPtr(nullptr), dofsPtr(nullptr),
115 finiteElementsPtr(nullptr), finiteElementsEntitiesPtr(nullptr),
116 adjacenciesPtr(nullptr) {}
117
120
121 this->nInTheLoop = basic.nInTheLoop;
122 this->loopSize = basic.loopSize;
123 this->rAnk = basic.rAnk;
124 this->sIze = basic.sIze;
127 this->problemPtr = basic.problemPtr;
128 this->fieldsPtr = basic.fieldsPtr;
129 this->entitiesPtr = basic.entitiesPtr;
130 this->dofsPtr = basic.dofsPtr;
133 this->adjacenciesPtr = basic.adjacenciesPtr;
134 this->cacheWeakPtr = basic.cacheWeakPtr;
135
137}
138
141 if (preProcessHook) {
143 CHKERRG(ierr);
144 } else {
145 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
146 "should be implemented by user in derived class (preProcess)");
147 }
149}
152 if (postProcessHook) {
154 CHKERRG(ierr);
155 } else {
156 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
157 "should be implemented by user in derived class (postProcess)");
158 }
160}
163 if (operatorHook) {
164 ierr = operatorHook();
165 CHKERRG(ierr);
166 } else {
167 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
168 "should be implemented by user in derived class (operator)");
169 }
171}
172
174 VectorDouble &data,
175 const bool reset_dofs) {
177
178 // TODO: [CORE-60] Fix implementation not to use DOFs
179
180 auto get_nodes_field_data =
181 [&](boost::shared_ptr<FEDofEntity_multiIndex> &&dofs,
182 VectorDouble &nodes_data) {
184
185 auto bit_number = getFieldBitNumber(field_name);
186 auto &dofs_by_uid = dofs->get<Unique_mi_tag>();
187 auto dit =
188 dofs_by_uid.lower_bound(FieldEntity::getLocalUniqueIdCalculate(
189 bit_number, get_id_for_min_type<MBVERTEX>()));
190 auto hi_dit =
191 dofs_by_uid.upper_bound(FieldEntity::getLocalUniqueIdCalculate(
192 bit_number, get_id_for_max_type<MBVERTEX>()));
193
194 if (dit != hi_dit) {
195 auto &first_dof = **dit;
196 const int num_nodes = getNumberOfNodes();
197 const int nb_dof_idx = first_dof.getNbOfCoeffs();
198 const int max_nb_dofs = nb_dof_idx * num_nodes;
199 nodes_data.resize(max_nb_dofs, false);
200 nodes_data.clear();
201
202 for (; dit != hi_dit;) {
203 const auto &dof_ptr = *dit;
204 const auto &dof = *dof_ptr;
205 const auto &sn = *dof.getSideNumberPtr();
206 const int side_number = sn.side_number;
207
208 int pos = side_number * nb_dof_idx;
209 auto ent_filed_data_vec = dof.getEntFieldData();
210 for (int ii = 0; ii != nb_dof_idx; ++ii) {
211 nodes_data[pos] = ent_filed_data_vec[ii];
212 ++pos;
213 ++dit;
214 }
215 }
216
217 } else if (reset_dofs) {
218 nodes_data.resize(0, false);
219 }
220
222 };
223
224 return get_nodes_field_data(getDataDofsPtr(), data);
225
227}
228
229} // namespace MoFEM
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
MoFEM::TsCtx * ts_ctx
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
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
MoFEMErrorCode copyKsp(const KspMethod &ksp)
copy data form another method
KSPContext ksp_ctx
Context.
KSP ksp
KSP solver.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
static constexpr Switches CtxSetA
static constexpr Switches CtxSetX
static constexpr Switches CtxSetX_TT
static constexpr Switches CtxSetNone
static constexpr Switches CtxSetF
std::bitset< 8 > Switches
static constexpr Switches CtxSetX_T
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
static constexpr Switches CtxSetB
static constexpr Switches CtxSetTime
MoFEMErrorCode copyPetscData(const PetscData &petsc_data)
data structure for snes (nonlinear solver) context
MoFEMErrorCode copySnes(const SnesMethod &snes)
Copy snes data.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
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
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.
base class for all interface classes