v0.15.5
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
MoFEM::VecManager Struct Reference

Vector manager is used to create vectors \mofem_vectors. More...

#include "src/interfaces/VecManager.hpp"

Inheritance diagram for MoFEM::VecManager:
[legend]
Collaboration diagram for MoFEM::VecManager:
[legend]

Public Member Functions

MoFEMErrorCode query_interface (boost::typeindex::type_index type_index, UnknownInterface **iface) const
 
 VecManager (const MoFEM::Core &core)
 
 ~VecManager ()=default
 
MoFEMErrorCode vecCreateSeq (const std::string name, RowColData rc, Vec *V) const
 create local vector for problem
 
MoFEMErrorCode vecCreateGhost (const std::string name, RowColData rc, Vec *V) const
 create ghost vector for problem (collective)
 
MoFEMErrorCode vecCreateGhost (const std::string name, RowColData rc, SmartPetscObj< Vec > &v_ptr) const
 create ghost vector for problem (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 from one to another problem (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, SmartPetscObj< VecScatter > &smart_newctx) const
 create scatter for vectors from one to another problem (collective)
 
MoFEMErrorCode vecScatterCreate (Vec xin, const std::string x_problem, RowColData x_rc, Vec yin, const std::string y_problem, RowColData y_rc, VecScatter *newctx) const
 create scatter for vectors from one to another problem (collective)
 
MoFEMErrorCode vecScatterCreate (Vec xin, const std::string x_problem, RowColData x_rc, Vec yin, const std::string y_problem, RowColData y_rc, SmartPetscObj< VecScatter > &smart_newctx) const
 create scatter for vectors from one to another problem (collective)
 
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 setLocalGhostVector (const std::string name, RowColData rc, Vec V, InsertMode mode, ScatterMode scatter_mode) const
 set values of vector from/to mesh database
 
MoFEMErrorCode setGlobalGhostVector (const Problem *problem_ptr, RowColData rc, Vec V, InsertMode mode, ScatterMode scatter_mode) const
 
MoFEMErrorCode setGlobalGhostVector (const std::string name, RowColData rc, Vec V, InsertMode mode, ScatterMode scatter_mode) const
 
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 setOtherLocalGhostVector (const std::string name, 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 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)
 
MoFEMErrorCode setOtherGlobalGhostVector (const std::string name, 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)
 
- Public Member Functions inherited from MoFEM::UnknownInterface
template<class IFACE >
MoFEMErrorCode registerInterface (bool error_if_registration_failed=true)
 Register interface.
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface reference to pointer of interface.
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface.
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface.
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface.
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface.
 
virtual ~UnknownInterface ()=default
 

Public Attributes

const MoFEM::InterfacecOre
 
bool dEbug
 

Additional Inherited Members

- Static Public Member Functions inherited from MoFEM::UnknownInterface
static MoFEMErrorCode getLibVersion (Version &version)
 Get library version.
 
static MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version)
 Get database major version.
 
static MoFEMErrorCode setFileVersion (moab::Interface &moab, Version version=Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD))
 Get database major version.
 
static MoFEMErrorCode getInterfaceVersion (Version &version)
 Get database major version.
 

Detailed Description

Vector manager is used to create vectors \mofem_vectors.

Managing Vectors, creation, scatter, etc.

Examples
mofem/atom_tests/prism_polynomial_approximation.cpp, mofem/atom_tests/quad_polynomial_approximation.cpp, mofem/atom_tests/remove_entities_from_problem_not_partitioned.cpp, mofem/tutorials/vec-7_shape_optimisation/adjoint.cpp, mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp, and thermoplastic.cpp.

Definition at line 23 of file VecManager.hpp.

Constructor & Destructor Documentation

◆ VecManager()

MoFEM::VecManager::VecManager ( const MoFEM::Core core)

Definition at line 25 of file VecManager.cpp.

26 : cOre(const_cast<MoFEM::Core &>(core)), dEbug(false) {
27 if (!LogManager::checkIfChannelExist("VECWORLD")) {
28 auto core_log = logging::core::get();
29
30 core_log->add_sink(
32 core_log->add_sink(
34 core_log->add_sink(
36
37 LogManager::setLog("VECWORLD");
38 LogManager::setLog("VECSYNC");
39 LogManager::setLog("VECSELF");
40
41 MOFEM_LOG_TAG("VECWORLD", "VecMng");
42 MOFEM_LOG_TAG("VECSYNC", "VecMng");
43 MOFEM_LOG_TAG("VECSELF", "VecMng");
44 }
45
46 MOFEM_LOG("VECWORLD", Sev::noisy) << "Vector manager created";
47}
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.
Core (interface) class.
Definition Core.hpp:82
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.
const MoFEM::Interface & cOre

◆ ~VecManager()

MoFEM::VecManager::~VecManager ( )
default

Member Function Documentation

◆ query_interface()

MoFEMErrorCode MoFEM::VecManager::query_interface ( boost::typeindex::type_index  type_index,
UnknownInterface **  iface 
) const
virtual

Implements MoFEM::UnknownInterface.

Definition at line 19 of file VecManager.cpp.

20 {
21 *iface = const_cast<VecManager *>(this);
22 return 0;
23}
VecManager(const MoFEM::Core &core)

◆ setGlobalGhostVector() [1/2]

MoFEMErrorCode MoFEM::VecManager::setGlobalGhostVector ( const Problem problem_ptr,
RowColData  rc,
Vec  V,
InsertMode  mode,
ScatterMode  scatter_mode 
) const
\brief set values of vector from/to mesh database (collective)
\ingroup mofem_vectors

collective - need to be run on all processors in communicator

Parameters
pointerto problem structure
RowColDatafor row or column (ROW or COL)
Vvector
modesee petsc manual for VecSetValue (ADD_VALUES or INSERT_VALUES)
scatter_modesee petsc manual for ScatterMode (The available modes are: SCATTER_FORWARD or SCATTER_REVERSE)

SCATTER_REVERSE set data to field entities from V vector.

Definition at line 332 of file VecManager.cpp.

334 {
336 typedef NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type
337 DofsByGlobalIdx;
338 DofsByGlobalIdx *dofs;
339 DofIdx nb_dofs;
340 switch (rc) {
341 case ROW:
342 nb_dofs = problem_ptr->getNbDofsRow();
343 dofs = const_cast<DofsByGlobalIdx *>(
344 &problem_ptr->numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>());
345 break;
346 case COL:
347 nb_dofs = problem_ptr->getNbDofsCol();
348 dofs = const_cast<DofsByGlobalIdx *>(
349 &problem_ptr->numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>());
350 break;
351 default:
352 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
353 "Function works only for ROWs and COLs");
354 }
355 DofsByGlobalIdx::iterator miit = dofs->lower_bound(0);
356 DofsByGlobalIdx::iterator hi_miit = dofs->upper_bound(nb_dofs);
357 auto comm = PetscObjectComm((PetscObject)V);
358 switch (scatter_mode) {
359 case SCATTER_REVERSE: {
360 VecScatter ctx;
361 Vec V_glob;
362 CHKERR VecScatterCreateToAll(V, &ctx, &V_glob);
363 CHKERR VecScatterBegin(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
364 CHKERR VecScatterEnd(ctx, V, V_glob, INSERT_VALUES, SCATTER_FORWARD);
365 int size;
366 CHKERR VecGetSize(V_glob, &size);
367 if (size != nb_dofs) {
368 SETERRQ(comm, MOFEM_DATA_INCONSISTENCY,
369 "Size of vector is inconsistent with size of problem. You could "
370 "use wrong vector with wrong problem, or you created vector "
371 "before you remove DOFs from problem.");
372 }
373 PetscScalar *array;
374 CHKERR VecGetArray(V_glob, &array);
375 switch (mode) {
376 case INSERT_VALUES:
377 for (; miit != hi_miit; miit++)
378 (*miit)->getFieldData() = array[(*miit)->getPetscGlobalDofIdx()];
379 break;
380 case ADD_VALUES:
381 for (; miit != hi_miit; miit++)
382 (*miit)->getFieldData() += array[(*miit)->getPetscGlobalDofIdx()];
383 break;
384 default:
385 SETERRQ(comm, MOFEM_NOT_IMPLEMENTED, "not implemented");
386 }
387 CHKERR VecRestoreArray(V_glob, &array);
388 CHKERR VecScatterDestroy(&ctx);
389 CHKERR VecDestroy(&V_glob);
390 break;
391 }
392 default:
393 SETERRQ(comm, MOFEM_NOT_IMPLEMENTED, "not implemented");
394 }
396}
@ COL
@ ROW
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
const FTensor::Tensor2< T, Dim, Dim > Vec
int DofIdx
Index of DOF.
Definition Types.hpp:18

◆ setGlobalGhostVector() [2/2]

MoFEMErrorCode MoFEM::VecManager::setGlobalGhostVector ( const std::string  name,
RowColData  rc,
Vec  V,
InsertMode  mode,
ScatterMode  scatter_mode 
) const
\brief set values of vector from/to mesh database (collective)
\ingroup mofem_vectors

collective - need to be run on all processors in communicator

\param name of the problem
Parameters
RowColDatafor row or column (ROW or COL)
Vvector
modesee petsc manual for VecSetValue (ADD_VALUES or INSERT_VALUES)
scatter_modesee petsc manual for ScatterMode (The available modes are: SCATTER_FORWARD or SCATTER_REVERSE)

SCATTER_REVERSE set data to field entities from V vector.

Definition at line 399 of file VecManager.cpp.

401 {
402 const MoFEM::Interface &m_field = cOre;
403 const Problem *problem_ptr;
405 CHKERR m_field.get_problem(name, &problem_ptr);
406 CHKERR setGlobalGhostVector(problem_ptr, rc, V, mode, scatter_mode);
408}
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
Deprecated interface functions.
MoFEMErrorCode setGlobalGhostVector(const Problem *problem_ptr, RowColData rc, Vec V, InsertMode mode, ScatterMode scatter_mode) const

◆ vecCreateGhost()

MoFEMErrorCode MoFEM::VecManager::vecCreateGhost ( const std::string  name,
RowColData  rc,
SmartPetscObj< Vec > &  v_ptr 
) const

create ghost vector for problem (collective)

collective - need to be run on all processors in communicator

Parameters
nameproblem name
RowColDataspecify what data is taken from Row, Col or Data
Vecthe vector where data is stored

Definition at line 153 of file VecManager.cpp.

154 {
156 Vec vec;
157 CHKERR vecCreateGhost(name, rc, &vec);
158 v_ptr.reset(vec, false);
160}
MoFEMErrorCode vecCreateGhost(const std::string name, RowColData rc, Vec *V) const
create ghost vector for problem (collective)

◆ vecScatterCreate() [1/2]

MoFEMErrorCode MoFEM::VecManager::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,
SmartPetscObj< VecScatter > &  smart_newctx 
) const

create scatter for vectors from one to another problem (collective)

User specify what name of field on one problem is scattered to another.

Parameters
xinvector
x_problemproblem name
x_fieldname
yinvector
y_problemproblem name
y_field_name
Return values
newctxscatter

Definition at line 208 of file VecManager.cpp.

212 {
214 VecScatter newctx;
215 CHKERR vecScatterCreate(xin, x_problem, x_field_name, x_rc, yin, y_problem,
216 y_field_name, y_rc, &newctx);
217 smart_newctx = SmartPetscObj<VecScatter>(newctx);
219}
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 from one to another problem (collective)

◆ vecScatterCreate() [2/2]

MoFEMErrorCode MoFEM::VecManager::vecScatterCreate ( Vec  xin,
const std::string  x_problem,
RowColData  x_rc,
Vec  yin,
const std::string  y_problem,
RowColData  y_rc,
SmartPetscObj< VecScatter > &  smart_newctx 
) const

create scatter for vectors from one to another problem (collective)

User specify what name of field on one problem is scattered to another.

Parameters
xinvector
x_problemproblem name
x_fieldname
yinvector
y_problemproblem name
y_field_name
Return values
newctxscatter

Definition at line 222 of file VecManager.cpp.

225 {
227 VecScatter newctx;
228 CHKERR vecScatterCreate(xin, x_problem, x_rc, yin, y_problem, y_rc, &newctx);
229 smart_newctx = SmartPetscObj<VecScatter>(newctx);
231}

Member Data Documentation

◆ cOre

const MoFEM::Interface& MoFEM::VecManager::cOre

Definition at line 28 of file VecManager.hpp.

◆ dEbug

bool MoFEM::VecManager::dEbug

Definition at line 29 of file VecManager.hpp.


The documentation for this struct was generated from the following files: