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 auto miit = dofs->lower_bound(0);
243 auto hi_miit = dofs->upper_bound(nb_local_dofs + nb_ghost_dofs);
245 switch (scatter_mode) {
246 case SCATTER_FORWARD: {
248 CHKERR VecGetArray(Vlocal, &array);
251 for (; miit != hi_miit; ++miit, ++ii)
252 array[ii] = (*miit)->getFieldData();
255 for (; miit != hi_miit; ++miit, ++ii)
256 array[ii] += (*miit)->getFieldData();
261 CHKERR VecRestoreArray(Vlocal, &array);
263 case SCATTER_REVERSE: {
264 const PetscScalar *array;
265 CHKERR VecGetArrayRead(Vlocal, &array);
268 for (; miit != hi_miit; ++miit, ++ii) {
269 (*miit)->getFieldData() = array[ii];
273 for (; miit != hi_miit; ++miit, ++ii)
274 (*miit)->getFieldData() += array[ii];
279 CHKERR VecRestoreArrayRead(Vlocal, &array);
284 CHKERR VecGhostRestoreLocalForm(V, &Vlocal);
291 ScatterMode scatter_mode)
const {
302 Vec V, InsertMode mode,
303 ScatterMode scatter_mode)
const {
305 typedef NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type
307 DofsByGlobalIdx *dofs;
312 dofs =
const_cast<DofsByGlobalIdx *
>(
317 dofs =
const_cast<DofsByGlobalIdx *
>(
322 "Function works only for ROWs and COLs");
324 DofsByGlobalIdx::iterator miit = dofs->lower_bound(0);
325 DofsByGlobalIdx::iterator hi_miit = dofs->upper_bound(nb_dofs);
326 auto comm = PetscObjectComm((PetscObject)V);
327 switch (scatter_mode) {
328 case SCATTER_REVERSE: {
331 CHKERR VecScatterCreateToAll(V, &ctx, &V_glob);
332 CHKERR VecScatterBegin(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
333 CHKERR VecScatterEnd(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
335 CHKERR VecGetSize(V_glob, &size);
336 if (size != nb_dofs) {
338 "Size of vector is inconsistent with size of problem. You could "
339 "use wrong vector with wrong problem, or you created vector "
340 "before you remove DOFs from problem.");
343 CHKERR VecGetArray(V_glob, &array);
346 for (; miit != hi_miit; miit++)
347 (*miit)->getFieldData() = array[(*miit)->getPetscGlobalDofIdx()];
350 for (; miit != hi_miit; miit++)
351 (*miit)->getFieldData() += array[(*miit)->getPetscGlobalDofIdx()];
356 CHKERR VecRestoreArray(V_glob, &array);
357 CHKERR VecScatterDestroy(&ctx);
358 CHKERR VecDestroy(&V_glob);
370 ScatterMode scatter_mode)
const {
380 template <
typename A0,
typename A1,
typename A2,
typename A3,
typename A4>
383 const std::string cpy_field_name) {
385 for (; miit != hi_miit; miit++) {
386 if (miit->get()->getHasLocalIndex()) {
389 cpy_bit_number, (*miit)->getEnt()));
390 auto diiiit = dofs_ptr->template get<Unique_mi_tag>().find(uid);
391 if (diiiit == dofs_ptr->template get<Unique_mi_tag>().end()) {
396 <<
"Problem finding DOFs in the copy field";
397 MOFEM_LOG(
"VECSELF", Sev::error) <<
"Field DOF: " << (**miit);
399 <<
"Copy field name: " << cpy_field_name;
401 "Automatic creation of entity and dof not implemented");
403 if constexpr (MODE == INSERT_VALUES)
404 (*diiiit)->getFieldData() = array[(*miit)->getPetscLocalDofIdx()];
405 else if constexpr (MODE == ADD_VALUES)
406 (*diiiit)->getFieldData() += array[(*miit)->getPetscLocalDofIdx()];
415 const std::string cpy_field_name,
RowColData rc, Vec V, InsertMode mode,
416 ScatterMode scatter_mode)
const {
421 using DofsByUId = NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type;
426 dofs =
const_cast<DofsByUId *
>(
430 dofs =
const_cast<DofsByUId *
>(
440 "cpy field < %s > not found, (top tip: check spelling)",
441 cpy_field_name.c_str());
442 const auto cpy_bit_number = (*cpy_fit)->getBitNumber();
444 auto miit = dofs->lower_bound(
446 if (miit == dofs->end()) {
448 "cpy field < %s > not found, (top tip: check spelling)",
451 auto hi_miit = dofs->upper_bound(
454 if ((*miit)->getSpace() != (*cpy_fit)->getSpace()) {
456 "fields have to have same space (%s) %s != (%s) %s",
460 if ((*miit)->getNbOfCoeffs() != (*cpy_fit)->getNbOfCoeffs()) {
462 "fields have to have same rank");
465 switch (scatter_mode) {
466 case SCATTER_REVERSE: {
469 CHKERR VecGetArray(V, &array);
470 if (mode == INSERT_VALUES)
472 dofs_ptr, array, miit, hi_miit, cpy_bit_number, cpy_field_name);
473 else if (mode == ADD_VALUES)
475 dofs_ptr, array, miit, hi_miit, cpy_bit_number, cpy_field_name);
478 "Operation mode not implemented");
479 CHKERR VecRestoreArray(V, &array);
481 case SCATTER_FORWARD: {
482 for (; miit != hi_miit; miit++) {
483 if (!miit->get()->getHasLocalIndex())
487 cpy_bit_number, (*miit)->getEnt()));
491 "no data to fill the vector (top tip: you want scatter forward "
492 "or scatter reverse?)");
494 CHKERR VecSetValue(V, (*miit)->getPetscGlobalDofIdx(),
495 (*diiiit)->getFieldData(), mode);
497 CHKERR VecAssemblyBegin(V);
507 const std::string name,
const std::string
field_name,
508 const std::string cpy_field_name,
RowColData rc, Vec V, InsertMode mode,
509 ScatterMode scatter_mode)
const {
515 V, mode, scatter_mode);
520 template <
typename A0,
typename A1,
typename A2,
typename A3,
typename A4>
522 A4 &cpy_bit_number) {
524 for (; miit != hi_miit; miit++) {
527 cpy_bit_number, (*miit)->getEnt()));
528 auto diiiit = dofs_ptr->template get<Unique_mi_tag>().find(uid);
530 if (diiiit == dofs_ptr->template get<Unique_mi_tag>().end()) {
532 "Automatic creation of entity and dof not implemented");
535 if constexpr (MODE == INSERT_VALUES)
536 (*diiiit)->getFieldData() = array[(*miit)->getPetscGlobalDofIdx()];
537 else if constexpr (MODE == ADD_VALUES)
538 (*diiiit)->getFieldData() += array[(*miit)->getPetscGlobalDofIdx()];
546 const std::string cpy_field_name,
RowColData rc, Vec V, InsertMode mode,
547 ScatterMode scatter_mode)
const {
571 "cpy field < %s > not found, (top tip: check spelling)",
572 cpy_field_name.c_str());
574 const auto cpy_bit_number = (*cpy_fit)->getBitNumber();
576 auto miit = dofs->lower_bound(
578 if (miit == dofs->end()) {
580 "problem field < %s > not found, (top tip: check spelling)",
583 auto hi_miit = dofs->upper_bound(
585 if ((*miit)->getSpace() != (*cpy_fit)->getSpace()) {
587 "fields have to have same space");
589 if ((*miit)->getNbOfCoeffs() != (*cpy_fit)->getNbOfCoeffs()) {
591 "fields have to have same rank");
593 switch (scatter_mode) {
594 case SCATTER_REVERSE: {
597 CHKERR VecScatterCreateToAll(V, &ctx, &V_glob);
598 CHKERR VecScatterBegin(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
599 CHKERR VecScatterEnd(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
601 CHKERR VecGetSize(V_glob, &size);
605 "data inconsistency: nb. of dofs and declared nb. dofs in database");
607 CHKERR VecGetArray(V_glob, &array);
609 if (mode == INSERT_VALUES)
611 dofs_ptr, array, miit, hi_miit, cpy_bit_number);
612 else if (mode == ADD_VALUES)
614 hi_miit, cpy_bit_number);
617 "Operation mode not implemented");
619 CHKERR VecRestoreArray(V_glob, &array);
620 CHKERR VecDestroy(&V_glob);
621 CHKERR VecScatterDestroy(&ctx);
623 case SCATTER_FORWARD: {
624 for (; miit != hi_miit; miit++) {
627 cpy_bit_number, (*miit)->getEnt()));
631 "No data to fill the vector (top tip: you want scatter forward "
632 "or scatter reverse?)");
634 CHKERR VecSetValue(V, (*miit)->getPetscGlobalDofIdx(),
635 (*diiiit)->getFieldData(), mode);
637 CHKERR VecAssemblyBegin(V);
647 const std::string name,
const std::string
field_name,
648 const std::string cpy_field_name,
RowColData rc, Vec V, InsertMode mode,
649 ScatterMode scatter_mode)
const {
655 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 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 mesh database
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)