v0.16.3
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
30 this->data_ctx = petsc_data.data_ctx;
31 this->f = petsc_data.f;
32 this->A = petsc_data.A;
33 this->B = petsc_data.B;
34 this->x = petsc_data.x;
35 this->dx = petsc_data.dx;
36 this->x_t = petsc_data.x_t;
37 this->x_tt = petsc_data.x_tt;
38 return 0;
39}
40
41// KSP
43KspMethod::query_interface(boost::typeindex::type_index type_index,
44 UnknownInterface **iface) const {
45 *iface = const_cast<KspMethod *>(this);
46 return 0;
47};
48
50 : ksp_f(PetscData::f), ksp_A(PetscData::A), ksp_B(PetscData::B) {}
51
59
60// SNES
62SnesMethod::query_interface(boost::typeindex::type_index type_index,
63 UnknownInterface **iface) const {
64 *iface = const_cast<SnesMethod *>(this);
65 return 0;
66}
67
69 : snes_x(PetscData::x), snes_dx(PetscData::dx), snes_f(PetscData::f),
70 snes_A(PetscData::A), snes_B(PetscData::B) {}
71
79
80// TAO
82TaoMethod::query_interface(boost::typeindex::type_index type_index,
83 UnknownInterface **iface) const {
84 *iface = const_cast<TaoMethod *>(this);
85 return 0;
86}
87
89 : tao_x(PetscData::x), tao_f(PetscData::f), tao_A(PetscData::A),
90 tao_B(PetscData::B), tao_c(PetscData::f), tao_J(PetscData::A),
91 tao_Jpre(PetscData::B) {}
92
100
101// TS
103TSMethod::query_interface(boost::typeindex::type_index type_index,
104 UnknownInterface **iface) const {
105 *iface = const_cast<TSMethod *>(this);
106 return 0;
107}
108
110 : ts_step(-1), ts_a(0), ts_t(0), ts_u(PetscData::x),
111 ts_u_t(PetscData::x_t), ts_u_tt(PetscData::x_tt),
112 ts_F(PetscData::f), ts_A(PetscData::A), ts_B(PetscData::B) {}
113
117 this->ts_ctx = ts.ts_ctx;
118 this->ts = ts.ts;
119 this->ts_step = ts.ts_step;
120 this->ts_a = ts.ts_a;
121 this->ts_t = ts.ts_t;
122 this->ts_dt = ts.ts_dt;
124}
125
126// BasicMethod
129 nInTheLoop(0), loopSize(0), rAnk(-1), sIze(-1) {}
130
133
134 this->nInTheLoop = basic.nInTheLoop;
135 this->loopSize = basic.loopSize;
136 this->rAnk = basic.rAnk;
137 this->sIze = basic.sIze;
140 this->problemPtr = basic.problemPtr;
141 this->fieldsPtr = basic.fieldsPtr;
142 this->entitiesPtr = basic.entitiesPtr;
143 this->dofsPtr = basic.dofsPtr;
146 this->adjacenciesPtr = basic.adjacenciesPtr;
147 this->cacheWeakPtr = basic.cacheWeakPtr;
148
150}
151
154 if (preProcessHook) {
156 CHKERRG(ierr);
157 } else {
158 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
159 "should be implemented by user in derived class (preProcess)");
160 }
162}
165 if (postProcessHook) {
167 CHKERRG(ierr);
168 } else {
169 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
170 "should be implemented by user in derived class (postProcess)");
171 }
173}
176 if (operatorHook) {
177 ierr = operatorHook();
178 CHKERRG(ierr);
179 } else {
180 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
181 "should be implemented by user in derived class (operator)");
182 }
184}
185
187 VectorDouble &data,
188 const bool reset_dofs) {
190
191 // TODO: [CORE-60] Fix implementation not to use DOFs
192
193 auto get_nodes_field_data =
194 [&](boost::shared_ptr<FEDofEntity_multiIndex> &&dofs,
195 VectorDouble &nodes_data) {
197
198 auto bit_number = getFieldBitNumber(field_name);
199 auto &dofs_by_uid = dofs->get<Unique_mi_tag>();
200 auto dit =
201 dofs_by_uid.lower_bound(FieldEntity::getLocalUniqueIdCalculate(
202 bit_number, get_id_for_min_type<MBVERTEX>()));
203 auto hi_dit =
204 dofs_by_uid.upper_bound(FieldEntity::getLocalUniqueIdCalculate(
205 bit_number, get_id_for_max_type<MBVERTEX>()));
206
207 if (dit != hi_dit) {
208 auto &first_dof = **dit;
209 const int num_nodes = getNumberOfNodes();
210 const int nb_dof_idx = first_dof.getNbOfCoeffs();
211 const int max_nb_dofs = nb_dof_idx * num_nodes;
212 nodes_data.resize(max_nb_dofs, false);
213 nodes_data.clear();
214
215 for (; dit != hi_dit;) {
216 const auto &dof_ptr = *dit;
217 const auto &dof = *dof_ptr;
218 const auto &sn = *dof.getSideNumberPtr();
219 const int side_number = sn.side_number;
220
221 int pos = side_number * nb_dof_idx;
222 auto ent_filed_data_vec = dof.getEntFieldData();
223 for (int ii = 0; ii != nb_dof_idx; ++ii) {
224 nodes_data[pos] = ent_filed_data_vec[ii];
225 ++pos;
226 ++dit;
227 }
228 }
229
230 } else if (reset_dofs) {
231 nodes_data.resize(0, false);
232 }
233
235 };
236
237 return get_nodes_field_data(getDataDofsPtr(), data);
238
240}
241
242} // namespace MoFEM
SmartPetscObj< KSP > ksp
#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 ...
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
Total number of methods to process in the loop.
const FieldEntity_multiIndex * entitiesPtr
Raw pointer to container of field entities.
BasicMethod()
Default constructor.
unsigned int getFieldBitNumber(std::string field_name) const
Get bit number for a specific field by name.
MoFEMErrorCode copyBasicMethod(const BasicMethod &basic)
Copy data from another BasicMethod instance.
const FiniteElement_multiIndex * finiteElementsPtr
Raw pointer to container of finite elements.
const RefElement_multiIndex * refinedFiniteElementsPtr
Pointer to container of refined finite element entities.
boost::function< MoFEMErrorCode()> preProcessHook
Hook function for pre-processing operations.
const DofEntity_multiIndex * dofsPtr
Raw pointer to container of degree of freedom entities.
int rAnk
Current processor rank in MPI communicator.
const Field_multiIndex * fieldsPtr
Raw pointer to fields multi-index container.
int nInTheLoop
Current index of processed method in the loop.
const RefEntity_multiIndex * refinedEntitiesPtr
Pointer to container of refined MoFEM DOF entities.
virtual MoFEMErrorCode postProcess()
Post-processing function executed at loop completion.
const FieldEntityEntFiniteElementAdjacencyMap_multiIndex * adjacenciesPtr
Raw pointer to container of adjacencies between DOFs and finite elements.
virtual MoFEMErrorCode operator()()
Main operator function executed for each loop iteration.
virtual MoFEMErrorCode preProcess()
Pre-processing function executed at loop initialization.
const EntFiniteElement_multiIndex * finiteElementsEntitiesPtr
Raw pointer to container of finite element entities.
const Problem * problemPtr
Raw pointer to current MoFEM problem instance.
boost::function< MoFEMErrorCode()> operatorHook
Hook function for main operator execution.
int sIze
Total number of processors in MPI communicator.
boost::weak_ptr< CacheTuple > cacheWeakPtr
Weak pointer to cached entity data.
boost::function< MoFEMErrorCode()> postProcessHook
Hook function for post-processing operations.
MoFEMErrorCode getNodeData(const std::string field_name, VectorDouble &data, const bool reset_dofs=true)
Get nodal data for a specific field.
auto getDataDofsPtr() const
Get pointer to DOF data for the current finite element.
auto getNumberOfNodes() const
Get the number of nodes in the current finite element.
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
Data structure for KSP (linear solver) context.
MoFEMErrorCode copyKsp(const KspMethod &ksp)
Copy data from another KSP method.
KSPContext ksp_ctx
Current KSP computation context.
KspMethod()
Default constructor.
KSP ksp
PETSc KSP linear solver object.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Query interface for type casting.
Base data structure for PETSc-related contexts.
static constexpr Switches CtxSetA
Jacobian matrix switch.
static constexpr Switches CtxSetX
Solution vector switch.
Vec f
PETSc residual vector.
static constexpr Switches CtxSetX_TT
Second time derivative switch.
static constexpr Switches CtxSetNone
No data switch.
static constexpr Switches CtxSetF
Residual vector switch.
Vec x_t
PETSc first time derivative vector.
std::bitset< 8 > Switches
Bitset type for context switches.
Vec x_tt
PETSc second time derivative vector.
Vec dx
PETSc solution increment vector.
Switches data_ctx
Current data context switches.
static constexpr Switches CtxSetX_T
First time derivative switch.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Query interface for type casting.
Vec x
PETSc solution vector.
Mat B
PETSc preconditioner matrix.
static constexpr Switches CtxSetB
Preconditioner matrix switch.
PetscData()
Default constructor.
static constexpr Switches CtxSetTime
Time value switch.
MoFEMErrorCode copyPetscData(const PetscData &petsc_data)
Copy PETSc data from another instance.
Mat A
PETSc Jacobian matrix.
Data structure for SNES (nonlinear solver) context.
MoFEMErrorCode copySnes(const SnesMethod &snes)
Copy SNES data from another instance.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Query interface for type casting.
SnesMethod()
Default constructor.
SNESContext snes_ctx
Current SNES computation context.
SNES snes
PETSc SNES nonlinear solver object.
Data structure for TS (time stepping) context.
TS ts
PETSc time stepping solver object.
TSMethod()
Default constructor.
PetscReal ts_t
Current time value.
PetscReal ts_dt
Current time step size.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Query interface for type casting.
TSContext ts_ctx
Current TS computation context.
PetscReal ts_a
Shift parameter for U_t (see PETSc Time Solver documentation)
PetscInt ts_step
Current time step number.
MoFEMErrorCode copyTs(const TSMethod &ts)
Copy TS solver data from another instance.
Data structure for TAO (optimization) context.
TAOContext tao_ctx
Current TAO computation context.
Tao tao
PETSc TAO optimization solver object.
TaoMethod()
Default constructor.
MoFEMErrorCode copyTao(const TaoMethod &tao)
Copy TAO data from another instance.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Query interface for type casting.
base class for all interface classes