v0.15.0
Loading...
Searching...
No Matches
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.
 
const VectorDouble & getReactionsFromSet (const int &id) const
 Get the Reactions at specified meshset id.
 
MoFEMErrorCode calculateReactions (Vec &internal)
 calculate reactions from a given vector
 

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;
DMCreateGlobalVector_MoFEM(dm, &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;
calculate reactions from vector of internal forces on meshsets

Definition at line 407 of file DirichletBC.hpp.

Member Typedef Documentation

◆ ReactionsMap

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) {}
constexpr auto field_name
std::string problemName
MoFEM::Interface & mField
std::string fieldName

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
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
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}
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)
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ NODESET
@ DISPLACEMENTSET
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
const double v
phase velocity of light in medium (cm/ns)
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
constexpr double g
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients.
keeps basic data about problem
ReactionsMap reactionsMap

◆ 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: