15 : cOre(const_cast<
MoFEM::
Core &>(core)), dEbug(false) {
17 auto core_log = logging::core::get();
35 MOFEM_LOG(
"VECWORLD", Sev::noisy) <<
"Vector manager created";
44 DofIdx nb_local_dofs, nb_ghost_dofs;
57 CHKERR ::VecCreateSeq(PETSC_COMM_SELF, nb_local_dofs + nb_ghost_dofs, V);
58 CHKERR ::VecSetOption(
59 *V, VEC_IGNORE_NEGATIVE_INDICES,
70 DofIdx nb_dofs, nb_local_dofs, nb_ghost_dofs;
91 auto miit = dofs->lower_bound(nb_local_dofs);
92 auto hi_miit = dofs->upper_bound(nb_local_dofs + nb_ghost_dofs);
93 int count = std::distance(miit, hi_miit);
94 if (count != nb_ghost_dofs) {
97 std::vector<DofIdx> ghost_idx;
98 ghost_idx.reserve(count);
99 for (; miit != hi_miit; ++miit) {
100 if ((*miit)->getActive()) {
101 ghost_idx.emplace_back((*miit)->petscGloablDofIdx);
104 if (PetscUnlikely(ghost_idx.back() > nb_dofs || ghost_idx.back() < 0)) {
108 MOFEM_LOG(
"VECSELF", Sev::error) <<
"Problem with DOF " << **miit;
114 CHKERR ::VecCreateGhost(m_field.
get_comm(), nb_local_dofs, nb_dofs,
115 ghost_idx.size(), &*ghost_idx.begin(), V);
116 CHKERR ::VecSetOption(
117 *V, VEC_IGNORE_NEGATIVE_INDICES,
127 v_ptr.reset(vec,
false);
132 Vec xin,
const std::string x_problem,
const std::string x_field_name,
133 RowColData x_rc, Vec yin,
const std::string y_problem,
134 const std::string y_field_name,
RowColData y_rc, VecScatter *newctx)
const {
137 std::vector<int> idx(0), idy(0);
139 ->isCreateFromProblemFieldToOtherProblemField(
140 x_problem, x_field_name, x_rc, y_problem, y_field_name, y_rc, idx,
143 CHKERR ISCreateGeneral(PETSC_COMM_WORLD, idx.size(), &idx[0],
144 PETSC_USE_POINTER, &ix);
145 CHKERR ISCreateGeneral(PETSC_COMM_WORLD, idy.size(), &idy[0],
146 PETSC_USE_POINTER, &iy);
147 CHKERR ::VecScatterCreate(xin, ix, yin, iy, newctx);
154 Vec xin,
const std::string x_problem,
RowColData x_rc, Vec yin,
155 const std::string y_problem,
RowColData y_rc, VecScatter *newctx)
const {
158 std::vector<int> idx(0), idy(0);
160 x_problem, x_rc, y_problem, y_rc, idx, idy);
162 CHKERR ISCreateGeneral(PETSC_COMM_WORLD, idx.size(), &idx[0],
163 PETSC_USE_POINTER, &ix);
164 CHKERR ISCreateGeneral(PETSC_COMM_WORLD, idy.size(), &idy[0],
165 PETSC_USE_POINTER, &iy);
167 ISView(ix, PETSC_VIEWER_STDOUT_WORLD);
168 ISView(iy, PETSC_VIEWER_STDOUT_WORLD);
170 CHKERR ::VecScatterCreate(xin, ix, yin, iy, newctx);
178 const std::string x_field_name,
RowColData x_rc,
179 Vec yin,
const std::string y_problem,
180 const std::string y_field_name,
RowColData y_rc,
185 y_field_name, y_rc, &newctx);
205 ScatterMode scatter_mode)
const {
208 DofIdx nb_local_dofs, nb_ghost_dofs;
226 CHKERR VecGhostGetLocalForm(V, &Vlocal);
228 CHKERR VecGetLocalSize(V, &size);
229 if (size != nb_local_dofs) {
231 "data inconsistency: check ghost vector, problem <%s> with nb. of "
232 "local nodes %d != %d",
233 problem_ptr->
getName().c_str(), size, nb_local_dofs);
235 CHKERR VecGetLocalSize(Vlocal, &size);
236 if (size != nb_local_dofs + nb_ghost_dofs) {
238 "data inconsistency: check ghost vector, problem with nb. of "
239 "ghost nodes %d != ",
240 size, nb_local_dofs + nb_ghost_dofs);
242 NumeredDofEntityByLocalIdx::iterator miit = dofs->lower_bound(0);
243 NumeredDofEntityByLocalIdx::iterator hi_miit =
244 dofs->upper_bound(nb_local_dofs + nb_ghost_dofs);
246 switch (scatter_mode) {
247 case SCATTER_FORWARD: {
249 CHKERR VecGetArray(Vlocal, &array);
252 for (; miit != hi_miit; ++miit, ++ii)
253 array[ii] = (*miit)->getFieldData();
256 for (; miit != hi_miit; ++miit, ++ii)
257 array[ii] += (*miit)->getFieldData();
262 CHKERR VecRestoreArray(Vlocal, &array);
264 case SCATTER_REVERSE: {
265 const PetscScalar *array;
266 CHKERR VecGetArrayRead(Vlocal, &array);
269 for (; miit != hi_miit; ++miit, ++ii) {
272 (*miit)->getFieldData() = array[ii];
276 for (; miit != hi_miit; ++miit, ++ii)
277 (*miit)->getFieldData() += array[ii];
282 CHKERR VecRestoreArrayRead(Vlocal, &array);
287 CHKERR VecGhostRestoreLocalForm(V, &Vlocal);
294 ScatterMode scatter_mode)
const {
305 Vec V, InsertMode mode,
306 ScatterMode scatter_mode)
const {
308 typedef NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type
310 DofsByGlobalIdx *dofs;
315 dofs =
const_cast<DofsByGlobalIdx *
>(
320 dofs =
const_cast<DofsByGlobalIdx *
>(
325 "Function works only for ROWs and COLs");
327 DofsByGlobalIdx::iterator miit = dofs->lower_bound(0);
328 DofsByGlobalIdx::iterator hi_miit = dofs->upper_bound(nb_dofs);
329 auto comm = PetscObjectComm((PetscObject)V);
330 switch (scatter_mode) {
331 case SCATTER_REVERSE: {
334 CHKERR VecScatterCreateToAll(V, &ctx, &V_glob);
335 CHKERR VecScatterBegin(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
336 CHKERR VecScatterEnd(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
338 CHKERR VecGetSize(V_glob, &size);
339 if (size != nb_dofs) {
341 "Size of vector is inconsistent with size of problem. You could "
342 "use wrong vector with wrong problem, or you created vector "
343 "before you remove DOFs from problem.");
346 CHKERR VecGetArray(V_glob, &array);
349 for (; miit != hi_miit; miit++)
350 (*miit)->getFieldData() = array[(*miit)->getPetscGlobalDofIdx()];
353 for (; miit != hi_miit; miit++)
354 (*miit)->getFieldData() += array[(*miit)->getPetscGlobalDofIdx()];
359 CHKERR VecRestoreArray(V_glob, &array);
360 CHKERR VecScatterDestroy(&ctx);
361 CHKERR VecDestroy(&V_glob);
373 ScatterMode scatter_mode)
const {
383 template <
typename A0,
typename A1,
typename A2,
typename A3,
typename A4>
386 const std::string cpy_field_name) {
388 for (; miit != hi_miit; miit++) {
389 if (miit->get()->getHasLocalIndex()) {
392 cpy_bit_number, (*miit)->getEnt()));
393 auto diiiit = dofs_ptr->template get<Unique_mi_tag>().find(uid);
394 if (diiiit == dofs_ptr->template get<Unique_mi_tag>().end()) {
399 <<
"Problem finding DOFs in the copy field";
400 MOFEM_LOG(
"VECSELF", Sev::error) <<
"Field DOF: " << (**miit);
402 <<
"Copy field name: " << cpy_field_name;
404 "Automatic creation of entity and dof not implemented");
406 if constexpr (MODE == INSERT_VALUES)
407 (*diiiit)->getFieldData() = array[(*miit)->getPetscLocalDofIdx()];
408 else if constexpr (MODE == ADD_VALUES)
409 (*diiiit)->getFieldData() += array[(*miit)->getPetscLocalDofIdx()];
418 const std::string cpy_field_name,
RowColData rc, Vec V, InsertMode mode,
419 ScatterMode scatter_mode)
const {
424 using DofsByUId = NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type;
429 dofs =
const_cast<DofsByUId *
>(
433 dofs =
const_cast<DofsByUId *
>(
443 "cpy field < %s > not found, (top tip: check spelling)",
444 cpy_field_name.c_str());
445 const auto cpy_bit_number = (*cpy_fit)->getBitNumber();
447 auto miit = dofs->lower_bound(
449 if (miit == dofs->end()) {
451 "cpy field < %s > not found, (top tip: check spelling)",
454 auto hi_miit = dofs->upper_bound(
457 if ((*miit)->getSpace() != (*cpy_fit)->getSpace()) {
459 "fields have to have same space (%s) %s != (%s) %s",
463 if ((*miit)->getNbOfCoeffs() != (*cpy_fit)->getNbOfCoeffs()) {
465 "fields have to have same rank");
468 switch (scatter_mode) {
469 case SCATTER_REVERSE: {
472 CHKERR VecGetArray(V, &array);
473 if (mode == INSERT_VALUES)
475 dofs_ptr, array, miit, hi_miit, cpy_bit_number, cpy_field_name);
476 else if (mode == ADD_VALUES)
478 dofs_ptr, array, miit, hi_miit, cpy_bit_number, cpy_field_name);
481 "Operation mode not implemented");
482 CHKERR VecRestoreArray(V, &array);
484 case SCATTER_FORWARD: {
485 for (; miit != hi_miit; miit++) {
486 if (!miit->get()->getHasLocalIndex())
490 cpy_bit_number, (*miit)->getEnt()));
494 "no data to fill the vector (top tip: you want scatter forward "
495 "or scatter reverse?)");
497 CHKERR VecSetValue(V, (*miit)->getPetscGlobalDofIdx(),
498 (*diiiit)->getFieldData(), mode);
500 CHKERR VecAssemblyBegin(V);
510 const std::string name,
const std::string
field_name,
511 const std::string cpy_field_name,
RowColData rc, Vec V, InsertMode mode,
512 ScatterMode scatter_mode)
const {
518 V, mode, scatter_mode);
523 template <
typename A0,
typename A1,
typename A2,
typename A3,
typename A4>
525 A4 &cpy_bit_number) {
527 for (; miit != hi_miit; miit++) {
530 cpy_bit_number, (*miit)->getEnt()));
531 auto diiiit = dofs_ptr->template get<Unique_mi_tag>().find(uid);
533 if (diiiit == dofs_ptr->template get<Unique_mi_tag>().end()) {
535 "Automatic creation of entity and dof not implemented");
538 if constexpr (MODE == INSERT_VALUES)
539 (*diiiit)->getFieldData() = array[(*miit)->getPetscGlobalDofIdx()];
540 else if constexpr (MODE == ADD_VALUES)
541 (*diiiit)->getFieldData() += array[(*miit)->getPetscGlobalDofIdx()];
549 const std::string cpy_field_name,
RowColData rc, Vec V, InsertMode mode,
550 ScatterMode scatter_mode)
const {
575 "cpy field < %s > not found, (top tip: check spelling)",
576 cpy_field_name.c_str());
578 const auto cpy_bit_number = (*cpy_fit)->getBitNumber();
580 auto miit = dofs->lower_bound(
582 if (miit == dofs->end()) {
584 "problem field < %s > not found, (top tip: check spelling)",
587 auto hi_miit = dofs->upper_bound(
589 if ((*miit)->getSpace() != (*cpy_fit)->getSpace()) {
591 "fields have to have same space");
593 if ((*miit)->getNbOfCoeffs() != (*cpy_fit)->getNbOfCoeffs()) {
595 "fields have to have same rank");
597 switch (scatter_mode) {
598 case SCATTER_REVERSE: {
601 CHKERR VecScatterCreateToAll(V, &ctx, &V_glob);
602 CHKERR VecScatterBegin(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
603 CHKERR VecScatterEnd(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
605 CHKERR VecGetSize(V_glob, &size);
609 "data inconsistency: nb. of dofs and declared nb. dofs in database");
611 CHKERR VecGetArray(V_glob, &array);
613 if (mode == INSERT_VALUES)
615 dofs_ptr, array, miit, hi_miit, cpy_bit_number);
616 else if (mode == ADD_VALUES)
618 hi_miit, cpy_bit_number);
621 "Operation mode not implemented");
623 CHKERR VecRestoreArray(V_glob, &array);
624 CHKERR VecDestroy(&V_glob);
625 CHKERR VecScatterDestroy(&ctx);
627 case SCATTER_FORWARD: {
628 for (; miit != hi_miit; miit++) {
631 cpy_bit_number, (*miit)->getEnt()));
635 "No data to fill the vector (top tip: you want scatter forward "
636 "or scatter reverse?)");
638 CHKERR VecSetValue(V, (*miit)->getPetscGlobalDofIdx(),
639 (*diiiit)->getFieldData(), mode);
641 CHKERR VecAssemblyBegin(V);
651 const std::string name,
const std::string
field_name,
652 const std::string cpy_field_name,
RowColData rc, Vec V, InsertMode mode,
653 ScatterMode scatter_mode)
const {
659 V, mode, scatter_mode);
static const char *const FieldSpaceNames[]
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
NumeredDofEntity_multiIndex::index< Unique_mi_tag >::type NumeredDofEntityByUId
Numbered DoF multi-index by UId.
NumeredDofEntity_multiIndex::index< PetscLocalIdx_mi_tag >::type NumeredDofEntityByLocalIdx
Numbered DoF multi-index by local index.
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
virtual const FieldEntity_multiIndex * get_field_ents() const =0
Get the field ents object.
virtual const DofEntity_multiIndex * get_dofs() const =0
Get the dofs object.
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_ATTRIBUTES(channel, bit)
Add attributes to channel.
#define MOFEM_LOG_FUNCTION()
Set scope.
MoFEMErrorCode vecCreateGhost(const std::string name, RowColData rc, Vec *V) const
create ghost vector for problem (collective)
MoFEMErrorCode setOtherLocalGhostVector(const Problem *problem_ptr, const std::string field_name, const std::string cpy_field_name, RowColData rc, Vec V, InsertMode mode, ScatterMode scatter_mode) const
Copy vector to field which is not part of the problem.
MoFEMErrorCode setGlobalGhostVector(const Problem *problem_ptr, RowColData rc, Vec V, InsertMode mode, ScatterMode scatter_mode) const
set values of vector from/to mesh database (collective)
MoFEMErrorCode vecScatterCreate(Vec xin, const std::string x_problem, const std::string x_field_name, RowColData x_rc, Vec yin, const std::string y_problem, const std::string y_field_name, RowColData y_rc, VecScatter *newctx) const
create scatter for vectors form one to another problem (collective)
MoFEMErrorCode vecCreateSeq(const std::string name, RowColData rc, Vec *V) const
create local vector for problem
MoFEMErrorCode setLocalGhostVector(const Problem *problem_ptr, RowColData rc, Vec V, InsertMode mode, ScatterMode scatter_mode) const
set values of vector from/to meshdatabase
MoFEMErrorCode setOtherGlobalGhostVector(const Problem *problem_ptr, const std::string field_name, const std::string cpy_field_name, RowColData rc, Vec V, InsertMode mode, ScatterMode scatter_mode) const
Copy vector to field which is not part of the problem (collective)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
constexpr auto field_name
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
virtual MPI_Comm & get_comm() const =0
Deprecated interface functions.
static UId getUniqueIdCalculate(const DofIdx dof, UId ent_uid)
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
MultiIndex Tag for field name.
Section manager is used to create indexes and sections.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
static bool checkIfChannelExist(const std::string channel)
Check if channel exist.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
keeps basic data about problem
DofIdx getNbLocalDofsRow() const
DofIdx getNbDofsRow() const
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem
DofIdx getNbGhostDofsCol() const
DofIdx getNbDofsCol() const
DofIdx getNbLocalDofsCol() const
DofIdx getNbGhostDofsRow() const
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredColDofsPtr
store DOFs on columns for this problem
MoFEMErrorCode operator()(A0 dofs_ptr, A1 array, A2 miit, A3 hi_miit, A4 &cpy_bit_number)
MoFEMErrorCode operator()(A0 dofs_ptr, A1 array, A2 miit, A3 hi_miit, A4 &cpy_bit_number, const std::string cpy_field_name)
intrusive_ptr for managing petsc objects
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
const MoFEM::Interface & cOre
VecManager(const MoFEM::Core &core)