v0.15.0
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/adjoint.cpp, and mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp.

Definition at line 23 of file VecManager.hpp.

Constructor & Destructor Documentation

◆ VecManager()

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

Definition at line 14 of file VecManager.cpp.

15 : cOre(const_cast<MoFEM::Core &>(core)), dEbug(false) {
16 if (!LogManager::checkIfChannelExist("VECWORLD")) {
17 auto core_log = logging::core::get();
18
19 core_log->add_sink(
21 core_log->add_sink(
23 core_log->add_sink(
25
26 LogManager::setLog("VECWORLD");
27 LogManager::setLog("VECSYNC");
28 LogManager::setLog("VECSELF");
29
30 MOFEM_LOG_TAG("VECWORLD", "VecMng");
31 MOFEM_LOG_TAG("VECSYNC", "VecMng");
32 MOFEM_LOG_TAG("VECSELF", "VecMng");
33 }
34
35 MOFEM_LOG("VECWORLD", Sev::noisy) << "Vector manager created";
36}
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 8 of file VecManager.cpp.

9 {
10 *iface = const_cast<VecManager *>(this);
11 return 0;
12}
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 301 of file VecManager.cpp.

303 {
305 typedef NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type
306 DofsByGlobalIdx;
307 DofsByGlobalIdx *dofs;
308 DofIdx nb_dofs;
309 switch (rc) {
310 case ROW:
311 nb_dofs = problem_ptr->getNbDofsRow();
312 dofs = const_cast<DofsByGlobalIdx *>(
313 &problem_ptr->numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>());
314 break;
315 case COL:
316 nb_dofs = problem_ptr->getNbDofsCol();
317 dofs = const_cast<DofsByGlobalIdx *>(
318 &problem_ptr->numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>());
319 break;
320 default:
321 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
322 "Function works only for ROWs and COLs");
323 }
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: {
329 VecScatter ctx;
330 Vec V_glob;
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);
334 int size;
335 CHKERR VecGetSize(V_glob, &size);
336 if (size != nb_dofs) {
337 SETERRQ(comm, MOFEM_DATA_INCONSISTENCY,
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.");
341 }
342 PetscScalar *array;
343 CHKERR VecGetArray(V_glob, &array);
344 switch (mode) {
345 case INSERT_VALUES:
346 for (; miit != hi_miit; miit++)
347 (*miit)->getFieldData() = array[(*miit)->getPetscGlobalDofIdx()];
348 break;
349 case ADD_VALUES:
350 for (; miit != hi_miit; miit++)
351 (*miit)->getFieldData() += array[(*miit)->getPetscGlobalDofIdx()];
352 break;
353 default:
354 SETERRQ(comm, MOFEM_NOT_IMPLEMENTED, "not implemented");
355 }
356 CHKERR VecRestoreArray(V_glob, &array);
357 CHKERR VecScatterDestroy(&ctx);
358 CHKERR VecDestroy(&V_glob);
359 break;
360 }
361 default:
362 SETERRQ(comm, MOFEM_NOT_IMPLEMENTED, "not implemented");
363 }
365}
@ 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 368 of file VecManager.cpp.

370 {
371 const MoFEM::Interface &m_field = cOre;
372 const Problem *problem_ptr;
374 CHKERR m_field.get_problem(name, &problem_ptr);
375 CHKERR setGlobalGhostVector(problem_ptr, rc, V, mode, scatter_mode);
377}
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 122 of file VecManager.cpp.

123 {
125 Vec vec;
126 CHKERR vecCreateGhost(name, rc, &vec);
127 v_ptr.reset(vec, false);
129}
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 177 of file VecManager.cpp.

181 {
183 VecScatter newctx;
184 CHKERR vecScatterCreate(xin, x_problem, x_field_name, x_rc, yin, y_problem,
185 y_field_name, y_rc, &newctx);
186 smart_newctx = SmartPetscObj<VecScatter>(newctx);
188}
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 191 of file VecManager.cpp.

194 {
196 VecScatter newctx;
197 CHKERR vecScatterCreate(xin, x_problem, x_rc, yin, y_problem, y_rc, &newctx);
198 smart_newctx = SmartPetscObj<VecScatter>(newctx);
200}

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: