v0.13.0
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
MoFEM::BcManager Struct Reference

Simple interface for fast problem set-up. More...

#include <src/interfaces/BcManager.hpp>

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

Classes

struct  BCs
 Data structure storing bc markers and atributes. More...
 

Public Types

using BcMapByBlockName = std::map< string, boost::shared_ptr< BCs > >
 
using BcMarkerPtr = boost::shared_ptr< std::vector< char unsigned > >
 

Public Member Functions

MoFEMErrorCode query_interface (boost::typeindex::type_index type_index, UnknownInterface **iface) const
 
 BcManager (const MoFEM::Core &core)
 
virtual ~BcManager ()=default
 
MoFEMErrorCode getOptions ()
 get options More...
 
Range getAdjEnts (Range ents)
 
MoFEMErrorCode removeBlockDOFsOnEntities (const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, bool get_low_dim_ents=true)
 Remove DOFs from problem. More...
 
MoFEMErrorCode pushMarkDOFsOnEntities (const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, bool get_low_dim_ents=true)
 Mark block dofs. More...
 
boost::shared_ptr< BCspopMarkDOFsOnEntities (const std::string block_name)
 Get bc data and remove element. More...
 
auto getBcStructure (const std::string bc_id)
 Get the bc structure object. More...
 
BcMapByBlockNamegetBcMapByBlockName ()
 Get the bc map. More...
 
BcMarkerPtr getMergedBlocksMarker (std::vector< std::regex > bc_regex_vec)
 Get the Merged Boundary Marker object. More...
 
auto getMergedBlocksMarker (std::vector< string > bc_names)
 Get the Merged Boundary Marker object. More...
 
BcMarkerPtr getMergedBlocksMarker (const std::vector< BcMarkerPtr > &boundary_markers_ptr_vec)
 Get the Merged Blocks Marker object. More...
 
auto checkBlock (const std::pair< string, boost::shared_ptr< BCs >> &bc, std::regex reg)
 check if given boundary condition name is in the map bc element More...
 
auto checkBlock (const std::pair< string, boost::shared_ptr< BCs >> &bc, std::string name)
 check if given boundary condition name is in the map bc element More...
 
SmartPetscObj< IS > getBlockIS (const std::string block_prefix, const std::string block_name, const std::string field_name, const std::string problem_name, int lo, int hi, SmartPetscObj< IS > is_expand=SmartPetscObj< IS >())
 Get block is. More...
 
SmartPetscObj< IS > getBlockIS (const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, SmartPetscObj< IS > is_expand=SmartPetscObj< IS >())
 Get block is. More...
 
- Public Member Functions inherited from MoFEM::UnknownInterface
template<class IFACE >
MoFEMErrorCode registerInterface (bool error_if_registration_failed=true)
 Register interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface refernce to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface. More...
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface. More...
 
virtual ~UnknownInterface ()=default
 

Private Attributes

MoFEM::CorecOre
 
BcMapByBlockName bcMapByBlockName
 

Additional Inherited Members

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

Detailed Description

Simple interface for fast problem set-up.

Definition at line 27 of file BcManager.hpp.

Member Typedef Documentation

◆ BcMapByBlockName

using MoFEM::BcManager::BcMapByBlockName = std::map<string, boost::shared_ptr<BCs> >
Todo:
Add markers for standard BCs from cubit on Nodests and Sidesets used bu cubit for displacements, forces, etc. Also add function to add blockset by id and type.

Definition at line 113 of file BcManager.hpp.

◆ BcMarkerPtr

using MoFEM::BcManager::BcMarkerPtr = boost::shared_ptr<std::vector<char unsigned> >

Definition at line 115 of file BcManager.hpp.

Constructor & Destructor Documentation

◆ BcManager()

MoFEM::BcManager::BcManager ( const MoFEM::Core core)

Definition at line 30 of file BcManager.cpp.

30  : cOre(const_cast<Core &>(core)) {
31 
32  if (!LogManager::checkIfChannelExist("BcMngWorld")) {
33  auto core_log = logging::core::get();
34 
35  core_log->add_sink(
37  core_log->add_sink(
39  core_log->add_sink(
41 
42  LogManager::setLog("BcMngWorld");
43  LogManager::setLog("BcMngSync");
44  LogManager::setLog("BcMngSelf");
45 
46  MOFEM_LOG_TAG("BcMngWorld", "BcMng");
47  MOFEM_LOG_TAG("BcMngSync", "BcMng");
48  MOFEM_LOG_TAG("BcMngSelf", "BcMng");
49  }
50 
51  MOFEM_LOG("BcMngWorld", Sev::noisy) << "BC manager created";
52 }
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
Definition: LogManager.cpp:364
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:311
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Definition: LogManager.hpp:342
CoreTmp< 0 > Core
Definition: Core.hpp:1096
MoFEM::Core & cOre
Definition: BcManager.hpp:220
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
Definition: LogManager.cpp:279
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
Definition: LogManager.cpp:323
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
Definition: LogManager.cpp:327
static bool checkIfChannelExist(const std::string channel)
Check if channel exist.
Definition: LogManager.cpp:374
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
Definition: LogManager.cpp:319

◆ ~BcManager()

virtual MoFEM::BcManager::~BcManager ( )
virtualdefault

Member Function Documentation

◆ checkBlock() [1/2]

auto MoFEM::BcManager::checkBlock ( const std::pair< string, boost::shared_ptr< BCs >> &  bc,
std::regex  reg 
)

check if given boundary condition name is in the map bc element

Parameters
bcelement of the map
regbc regex
Returns
auto

Definition at line 169 of file BcManager.hpp.

170  {
171  return std::regex_match(bc.first, reg);
172  }

◆ checkBlock() [2/2]

auto MoFEM::BcManager::checkBlock ( const std::pair< string, boost::shared_ptr< BCs >> &  bc,
std::string  name 
)

check if given boundary condition name is in the map bc element

Parameters
bcelement of the map
namebc name
Returns
auto

Definition at line 180 of file BcManager.hpp.

181  {
182  string full_name = string("(.*)_") + name + string("(.*)");
183  return checkBlock(bc, std::regex(full_name));
184  }
auto checkBlock(const std::pair< string, boost::shared_ptr< BCs >> &bc, std::regex reg)
check if given boundary condition name is in the map bc element
Definition: BcManager.hpp:169

◆ getAdjEnts()

Range MoFEM::BcManager::getAdjEnts ( Range  ents)

◆ getBcMapByBlockName()

BcMapByBlockName& MoFEM::BcManager::getBcMapByBlockName ( )

Get the bc map.

Returns
auto

Definition at line 131 of file BcManager.hpp.

131 { return bcMapByBlockName; }
BcMapByBlockName bcMapByBlockName
Definition: BcManager.hpp:222

◆ getBcStructure()

auto MoFEM::BcManager::getBcStructure ( const std::string  bc_id)

Get the bc structure object.

Parameters
block_name
Returns
auto

Definition at line 122 of file BcManager.hpp.

122  {
123  return bcMapByBlockName.at(bc_id);
124  }

◆ getBlockIS() [1/2]

SmartPetscObj< IS > MoFEM::BcManager::getBlockIS ( const std::string  block_prefix,
const std::string  block_name,
const std::string  field_name,
const std::string  problem_name,
int  lo,
int  hi,
SmartPetscObj< IS >  is_expand = SmartPetscObj<IS>() 
)

Get block is.

Parameters
block_prefixfor hashmap
block_namefor hash map
field_namefor hash map and IS
problem_namefor IS
lo
hi
is_expandis to extend
Returns
SmartPetscObj<IS>

Definition at line 238 of file BcManager.cpp.

242  {
243  Interface &m_field = cOre;
244 
245  const std::string bc_id =
246  block_prefix + "_" + field_name + "_" + block_name + "(.*)";
247 
248  Range bc_ents;
249  for (auto bc : getBcMapByBlockName()) {
250  if (std::regex_match(bc.first, std::regex(bc_id))) {
251  bc_ents.merge(*(bc.second->getBcEntsPtr()));
252  MOFEM_LOG("BcMngSelf", Sev::noisy)
253  << "Get entities from block and add to IS. Block name " << bc.first;
254  }
255  }
256 
257  SmartPetscObj<IS> is_bc;
258  auto get_is = [&]() {
260  CHKERR m_field.getInterface<CommInterface>()->synchroniseEntities(bc_ents);
261  CHKERR m_field.getInterface<ISManager>()->isCreateProblemFieldAndRank(
262  problem_name, ROW, field_name, lo, hi, is_bc, &bc_ents);
263  if (is_expand) {
264  IS is_tmp;
265  CHKERR ISExpand(is_bc, is_expand, &is_tmp);
266  is_bc = SmartPetscObj<IS>(is_tmp);
267  }
268  CHKERR ISSort(is_bc);
270  };
271 
272  if (get_is())
273  CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "IS is not created");
274 
275  return is_bc;
276 }
@ ROW
Definition: definitions.h:136
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:608
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:44
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
BcMapByBlockName & getBcMapByBlockName()
Get the bc map.
Definition: BcManager.hpp:131

◆ getBlockIS() [2/2]

SmartPetscObj< IS > MoFEM::BcManager::getBlockIS ( const std::string  problem_name,
const std::string  block_name,
const std::string  field_name,
int  lo,
int  hi,
SmartPetscObj< IS >  is_expand = SmartPetscObj<IS>() 
)

Get block is.

Parameters
problem_name
block_name
field_name
lo
hi
is_expandis to extend
Returns
SmartPetscObj<IS>

Definition at line 278 of file BcManager.cpp.

281  {
282  return getBlockIS(problem_name, block_name, field_name, problem_name, lo, hi,
283  is_expand);
284 }
SmartPetscObj< IS > getBlockIS(const std::string block_prefix, const std::string block_name, const std::string field_name, const std::string problem_name, int lo, int hi, SmartPetscObj< IS > is_expand=SmartPetscObj< IS >())
Get block is.
Definition: BcManager.cpp:238

◆ getMergedBlocksMarker() [1/3]

BcManager::BcMarkerPtr MoFEM::BcManager::getMergedBlocksMarker ( const std::vector< BcMarkerPtr > &  boundary_markers_ptr_vec)

Get the Merged Blocks Marker object.

Parameters
boundary_markers_ptr_vecvector of boundary markers to merge
Returns
BcMarkerPtr

Definition at line 227 of file BcManager.cpp.

228  {
229  auto boundary_marker_ptr = boost::make_shared<std::vector<char unsigned>>();
230  for (auto &bcm : boundary_markers_ptr_vec) {
231  boundary_marker_ptr->resize(bcm->size(), 0);
232  for (int i = 0; i != bcm->size(); ++i)
233  (*boundary_marker_ptr)[i] |= (*bcm)[i];
234  }
235  return boundary_marker_ptr;
236 }
FTensor::Index< 'i', SPACE_DIM > i

◆ getMergedBlocksMarker() [2/3]

BcManager::BcMarkerPtr MoFEM::BcManager::getMergedBlocksMarker ( std::vector< std::regex >  bc_regex_vec)

Get the Merged Boundary Marker object.

Parameters
bc_regex_vecboundary name regex vector
Returns
boundaryMarker

Definition at line 209 of file BcManager.cpp.

209  {
210  BcManager::BcMarkerPtr boundary_marker_ptr;
211  if (bcMapByBlockName.size()) {
212  boundary_marker_ptr = boost::make_shared<std::vector<char unsigned>>();
213  for (auto b : bcMapByBlockName) {
214  for (auto &reg_name : bc_regex_vec) {
215  if (std::regex_match(b.first, reg_name)) {
216  boundary_marker_ptr->resize(b.second->bcMarkers.size(), 0);
217  for (int i = 0; i != b.second->bcMarkers.size(); ++i) {
218  (*boundary_marker_ptr)[i] |= b.second->bcMarkers[i];
219  }
220  }
221  }
222  }
223  }
224  return boundary_marker_ptr;
225 }
boost::shared_ptr< std::vector< char unsigned > > BcMarkerPtr
Definition: BcManager.hpp:115

◆ getMergedBlocksMarker() [3/3]

auto MoFEM::BcManager::getMergedBlocksMarker ( std::vector< string >  bc_names)

Get the Merged Boundary Marker object.

Parameters
bc_namesvector of boundary names
Returns
boundaryMarker

Definition at line 146 of file BcManager.hpp.

146  {
147  std::vector<std::regex> reg_vec(bc_names.size());
148  for (int i = 0; i != bc_names.size(); ++i) {
149  string full_name = string("(.*)_") + bc_names[i] + string("(.*)");
150  reg_vec[i] = std::regex(full_name);
151  }
152  return getMergedBlocksMarker(reg_vec);
153  }
BcMarkerPtr getMergedBlocksMarker(std::vector< std::regex > bc_regex_vec)
Get the Merged Boundary Marker object.
Definition: BcManager.cpp:209

◆ getOptions()

MoFEMErrorCode MoFEM::BcManager::getOptions ( )

get options

Returns
error code

Definition at line 54 of file BcManager.cpp.

54  {
55  PetscBool flg = PETSC_TRUE;
57  ierr = PetscOptionsBegin(PETSC_COMM_WORLD, "", "BcManager options", "none");
58  ierr = PetscOptionsEnd();
59  CHKERRG(ierr);
61 }
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:496
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:87

◆ popMarkDOFsOnEntities()

boost::shared_ptr< BcManager::BCs > MoFEM::BcManager::popMarkDOFsOnEntities ( const std::string  block_name)

Get bc data and remove element.

Parameters
block_name
Returns
boost::shared_ptr<BCs>

Definition at line 198 of file BcManager.cpp.

198  {
199  auto bc_it = bcMapByBlockName.find(block_name);
200  if (bc_it != bcMapByBlockName.end()) {
201  auto bc = bc_it->second;
202  bcMapByBlockName.erase(bc_it);
203  return bc;
204  }
205  return boost::shared_ptr<BCs>();
206 }

◆ pushMarkDOFsOnEntities()

MoFEMErrorCode MoFEM::BcManager::pushMarkDOFsOnEntities ( const std::string  problem_name,
const std::string  block_name,
const std::string  field_name,
int  lo,
int  hi,
bool  get_low_dim_ents = true 
)

Mark block dofs.

Parameters
problem_name
block_name
field_name
lolowest coefficient
hihighest coefficient
get_low_dim_entsget lower dimension entities
Returns
MoFEMErrorCode

Definition at line 121 of file BcManager.cpp.

125  {
126  Interface &m_field = cOre;
127  auto prb_mng = m_field.getInterface<ProblemsManager>();
129 
130  auto get_dim = [&](const Range &ents) {
131  for (auto d : {3, 2, 1})
132  if (ents.num_of_dimension(d))
133  return d;
134  return 0;
135  };
136 
137  auto get_adj_ents = [&](const Range &ents) {
138  Range verts;
139  CHKERR m_field.get_moab().get_connectivity(ents, verts, true);
140  const auto dim = get_dim(ents);
141  for (size_t d = 1; d < dim; ++d)
142  CHKERR m_field.get_moab().get_adjacencies(ents, d, false, verts,
143  moab::Interface::UNION);
144  verts.merge(ents);
145  CHKERR m_field.getInterface<CommInterface>()->synchroniseEntities(verts);
146  return verts;
147  };
148 
149  auto fix_disp = [&]() {
151 
152  auto mark_fix_dofs = [&](std::vector<unsigned char> &marked_field_dofs,
153  const auto lo, const auto hi) {
154  return prb_mng->modifyMarkDofs(problem_name, ROW, field_name, lo, hi,
155  ProblemsManager::MarkOP::OR, 1,
156  marked_field_dofs);
157  };
158 
160  if (it->getName().compare(0, block_name.length(), block_name) == 0) {
161 
162  const std::string bc_id =
163  problem_name + "_" + field_name + "_" + it->getName();
164 
165  auto bc = boost::make_shared<BCs>();
166  CHKERR m_field.get_moab().get_entities_by_handle(it->meshset,
167  bc->bcEnts, true);
168  CHKERR it->getAttributes(bc->bcAttributes);
169 
170  MOFEM_LOG("BcMngWorld", Sev::verbose)
171  << "Found block " << block_name << " number of entities "
172  << bc->bcEnts.size() << " number of attributes "
173  << bc->bcAttributes.size() << " highest dim of entities "
174  << get_dim(bc->bcEnts);
175 
176  CHKERR mark_fix_dofs(bc->bcMarkers, lo, hi);
177  if (get_low_dim_ents) {
178  auto low_dim_ents = get_adj_ents(bc->bcEnts);
179  CHKERR prb_mng->markDofs(problem_name, ROW, ProblemsManager::AND,
180  low_dim_ents, bc->bcMarkers);
181  bc->bcEnts.swap(low_dim_ents);
182  } else
183  CHKERR prb_mng->markDofs(problem_name, ROW, ProblemsManager::AND,
184  bc->bcEnts, bc->bcMarkers);
185 
186  bcMapByBlockName[bc_id] = bc;
187  }
188  }
190  };
191 
192  CHKERR fix_disp();
193 
195 }
@ BLOCKSET
Definition: definitions.h:161
const int dim
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
const Tensor1_Expr< const dTensor0< T, Dim, i >, typename promote< T, double >::V, Dim, i > d(const Tensor0< T * > &a, const Index< i, Dim > index, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: dTensor0.hpp:27
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.

◆ query_interface()

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

Implements MoFEM::UnknownInterface.

Definition at line 23 of file BcManager.cpp.

24  {
26  *iface = const_cast<BcManager *>(this);
28 }
BcManager(const MoFEM::Core &core)
Definition: BcManager.cpp:30

◆ removeBlockDOFsOnEntities()

MoFEMErrorCode MoFEM::BcManager::removeBlockDOFsOnEntities ( const std::string  problem_name,
const std::string  block_name,
const std::string  field_name,
int  lo,
int  hi,
bool  get_low_dim_ents = true 
)

Remove DOFs from problem.

Parameters
problem_name
block_name
field_name
lolowest coefficient
hihighest coefficient
get_low_dim_entsget lower dimension entities
Returns
MoFEMErrorCode

Definition at line 63 of file BcManager.cpp.

65  {
66  Interface &m_field = cOre;
67  auto prb_mng = m_field.getInterface<ProblemsManager>();
69 
70  auto get_dim = [&](const Range &ents) {
71  for (auto d : {3, 2, 1})
72  if (ents.num_of_dimension(d))
73  return d;
74  return 0;
75  };
76 
77  auto get_adj_ents = [&](const Range &ents) {
78  Range verts;
79  CHKERR m_field.get_moab().get_connectivity(ents, verts, true);
80  const auto dim = get_dim(ents);
81  for (size_t d = 1; d < dim; ++d)
82  CHKERR m_field.get_moab().get_adjacencies(ents, d, false, verts,
83  moab::Interface::UNION);
84  verts.merge(ents);
85  CHKERR m_field.getInterface<CommInterface>()->synchroniseEntities(verts);
86  return verts;
87  };
88 
89  auto remove_dofs_on_ents = [&](const Range &&ents, const int lo,
90  const int hi) {
92  CHKERR prb_mng->removeDofsOnEntities(problem_name, field_name, ents, lo,
93  hi);
95  };
96 
97  auto get_block_ents = [&](const std::string block_name) {
98  Range remove_ents;
100  if (it->getName().compare(0, block_name.length(), block_name) == 0) {
101  CHKERR m_field.get_moab().get_entities_by_handle(it->meshset,
102  remove_ents, true);
103  MOFEM_LOG("BcMngWorld", Sev::verbose)
104  << "Found block to remove " << block_name << " number of entities "
105  << remove_ents.size() << " highest dim of entities "
106  << get_dim(remove_ents);
107  }
108  }
109  return remove_ents;
110  };
111 
112  if (get_lod_dim_ents)
113  CHKERR remove_dofs_on_ents(get_adj_ents(get_block_ents(block_name)), lo,
114  hi);
115  else
116  CHKERR remove_dofs_on_ents(get_block_ents(block_name), lo, hi);
117 
119 }

Member Data Documentation

◆ bcMapByBlockName

BcMapByBlockName MoFEM::BcManager::bcMapByBlockName
private

Definition at line 222 of file BcManager.hpp.

◆ cOre

MoFEM::Core& MoFEM::BcManager::cOre
private

Definition at line 220 of file BcManager.hpp.


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