v0.14.0
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
Reactions Struct Reference

calculate reactions from vector of internal forces on meshsets More...

#include <users_modules/basic_finite_elements/src/DirichletBC.hpp>

Collaboration diagram for Reactions:
[legend]

Public Types

typedef std::map< int, VectorDouble > ReactionsMap
 

Public Member Functions

 Reactions (MoFEM::Interface &m_field, string problem_name, string field_name)
 
const ReactionsMapgetReactionsMap () const
 Get the Reactions Map. More...
 
const VectorDouble & getReactionsFromSet (const int &id) const
 Get the Reactions at specified meshset id. More...
 
MoFEMErrorCode calculateReactions (Vec &internal)
 calculate reactions from a given vector More...
 

Public Attributes

MoFEM::InterfacemField
 

Private Attributes

std::string problemName
 
std::string fieldName
 
ReactionsMap reactionsMap
 

Detailed Description

calculate reactions from vector of internal forces on meshsets

example usage

Vec F_int;
feRhs->snes_ctx = FEMethod::CTX_SNESSETFUNCTION;
feRhs->snes_f = F_int;
DMoFEMLoopFiniteElements(dm, "ELASTIC", feRhs);
VecAssemblyBegin(F_int);
VecAssemblyEnd(F_int);
VecGhostUpdateBegin(F_int, INSERT_VALUES, SCATTER_FORWARD);
VecGhostUpdateEnd(F_int, INSERT_VALUES, SCATTER_FORWARD);
Reactions my_react(m_field, "DM_ELASTIC", "U");
my_react.calculateReactions(F_int);
int fix_nodes_meshset_id = 1;
cout << my_react.getReactionsFromSet(fix_nodes_meshset_id) << endl;

Definition at line 407 of file DirichletBC.hpp.

Member Typedef Documentation

◆ ReactionsMap

typedef std::map<int, VectorDouble> Reactions::ReactionsMap

Definition at line 412 of file DirichletBC.hpp.

Constructor & Destructor Documentation

◆ Reactions()

Reactions::Reactions ( MoFEM::Interface m_field,
string  problem_name,
string  field_name 
)
inline

Definition at line 409 of file DirichletBC.hpp.

410  : mField(m_field), problemName(problem_name), fieldName(field_name) {}

Member Function Documentation

◆ calculateReactions()

MoFEMErrorCode Reactions::calculateReactions ( Vec &  internal)

calculate reactions from a given vector

Parameters
internalforces vector
Returns
MoFEMErrorCode

Definition at line 782 of file DirichletBC.cpp.

782  {
783 
785 
786  const Problem *problem_ptr;
787  CHKERR mField.get_problem(problemName.c_str(), &problem_ptr);
788  const double *array;
789  CHKERR VecGetArrayRead(internal, &array);
790 
791  auto field_ptr = mField.get_field_structure(fieldName);
792  const int nb_coefficients = field_ptr->getNbOfCoeffs();
793 
794  std::vector<int> ghosts(nb_coefficients);
795  for (int g = 0; g != nb_coefficients; ++g)
796  ghosts[g] = g;
797 
798  Vec v;
799  CHKERR VecCreateGhost(
800  mField.get_comm(), (mField.get_comm_rank() ? 0 : nb_coefficients),
801  nb_coefficients, (mField.get_comm_rank() ? nb_coefficients : 0),
802  &*ghosts.begin(), &v);
803 
805  mField, NODESET | DISPLACEMENTSET, it)) {
806 
807  const int id = it->getMeshsetId();
808  VectorDouble &reaction_vec = reactionsMap[id];
809  reaction_vec.resize(nb_coefficients);
810  reaction_vec.clear();
811 
812  Range verts;
813  for (int dim = 0; dim != 3; ++dim) {
814  Range ents;
815  CHKERR it->getMeshsetIdEntitiesByDimension(mField.get_moab(), dim, ents,
816  true);
817  Range nodes;
818  CHKERR mField.get_moab().get_connectivity(ents, nodes, true);
819  verts.insert(nodes.begin(), nodes.end());
820  }
821 
822  auto for_each_dof = [&](auto &dof) {
824  reaction_vec[dof->getDofCoeffIdx()] += array[dof->getPetscLocalDofIdx()];
826  };
827 
828  CHKERR set_numered_dofs_on_ents(problem_ptr,
830  verts, for_each_dof);
831 
832  double *res_array;
833 
834  CHKERR VecGetArray(v, &res_array);
835  for (int dd = 0; dd != reaction_vec.size(); ++dd)
836  res_array[dd] = reaction_vec[dd];
837  CHKERR VecRestoreArray(v, &res_array);
838 
839  CHKERR VecGetArray(v, &res_array);
840  for (int dd = 0; dd != reaction_vec.size(); ++dd)
841  reaction_vec[dd] = res_array[dd];
842  CHKERR VecRestoreArray(v, &res_array);
843  }
844 
845  CHKERR VecGhostUpdateBegin(v, ADD_VALUES, SCATTER_REVERSE);
846  CHKERR VecGhostUpdateEnd(v, ADD_VALUES, SCATTER_REVERSE);
847  CHKERR VecGhostUpdateBegin(v, INSERT_VALUES, SCATTER_FORWARD);
848  CHKERR VecGhostUpdateEnd(v, INSERT_VALUES, SCATTER_FORWARD);
849 
850  CHKERR VecDestroy(&v);
851  CHKERR VecRestoreArrayRead(internal, &array);
853 }

◆ getReactionsFromSet()

const VectorDouble& Reactions::getReactionsFromSet ( const int &  id) const
inline

Get the Reactions at specified meshset id.

Parameters
idmeshset id (from Cubit)
Returns
const VectorDouble&

Definition at line 426 of file DirichletBC.hpp.

426  {
427  return reactionsMap.at(id);
428  }

◆ getReactionsMap()

const ReactionsMap& Reactions::getReactionsMap ( ) const
inline

Get the Reactions Map.

Returns
const ReactionsMap&

Definition at line 419 of file DirichletBC.hpp.

419 { return reactionsMap; }

Member Data Documentation

◆ fieldName

std::string Reactions::fieldName
private

Definition at line 439 of file DirichletBC.hpp.

◆ mField

MoFEM::Interface& Reactions::mField

Definition at line 413 of file DirichletBC.hpp.

◆ problemName

std::string Reactions::problemName
private

Definition at line 438 of file DirichletBC.hpp.

◆ reactionsMap

ReactionsMap Reactions::reactionsMap
private

Definition at line 440 of file DirichletBC.hpp.


The documentation for this struct was generated from the following files:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
g
constexpr double g
Definition: shallow_wave.cpp:63
MoFEM::Field::getNbOfCoeffs
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients.
Definition: FieldMultiIndices.hpp:188
Reactions::fieldName
std::string fieldName
Definition: DirichletBC.hpp:439
Reactions::problemName
std::string problemName
Definition: DirichletBC.hpp:438
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MoFEM::CoreInterface::get_field_structure
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
_IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
Definition: MeshsetsManager.hpp:49
MoFEM::CoreInterface::get_field_bit_number
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
MoFEM::CoreInterface::get_comm_rank
virtual int get_comm_rank() const =0
MoFEM::CoreInterface::get_problem
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
Reactions
calculate reactions from vector of internal forces on meshsets
Definition: DirichletBC.hpp:407
MoFEM::DMCreateGlobalVector_MoFEM
PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
Definition: DMMoFEM.cpp:1171
NODESET
@ NODESET
Definition: definitions.h:146
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
DISPLACEMENTSET
@ DISPLACEMENTSET
Definition: definitions.h:150
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
Reactions::reactionsMap
ReactionsMap reactionsMap
Definition: DirichletBC.hpp:440
set_numered_dofs_on_ents
static MoFEMErrorCode set_numered_dofs_on_ents(const Problem *problem_ptr, const FieldBitNumber bit_number, Range &ents, boost::function< MoFEMErrorCode(const boost::shared_ptr< MoFEM::NumeredDofEntity > &dof)> for_each_dof)
Definition: DirichletBC.cpp:11
v
const double v
phase velocity of light in medium (cm/ns)
Definition: initial_diffusion.cpp:40
Range
FTensor::dd
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
Reactions::mField
MoFEM::Interface & mField
Definition: DirichletBC.hpp:413
EigenMatrix::Vec
const FTensor::Tensor2< T, Dim, Dim > Vec
Definition: MatrixFunction.hpp:66
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
MoFEM::Problem
keeps basic data about problem
Definition: ProblemsMultiIndices.hpp:54
MoFEM::DMoFEMLoopFiniteElements
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMoFEM.cpp:590
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346