v0.14.0
EssentialMPCsData.hpp
Go to the documentation of this file.
1 /**
2  * @file EssentialMPCsData.hpp
3  * @brief Specialisation for MPCsTypes
4  * @version 0.13.2
5  * @date 2022-09-18
6  *
7  * @copyright Copyright (c) 2022
8  *
9  */
10 
11 #ifndef _ESSENTIAL_MPCS_DATA_HPP_
12 #define _ESSENTIAL_MPCS_DATA_HPP_
13 
14 namespace MoFEM {
15 
17 
18 // Base struct for all multipoint constraints data.
20 
21 
25  double mPenalty;
26 
27  std::vector<unsigned char> bcMasterMarkers;
28  std::vector<unsigned char> bcSlaveMarkers;
29 
31  MPCsType() : mpcType(MPC::TIE), isReprocitical(true), mPenalty(1e8) {}
32  // virtual ~MPCsType() {}
33  using InitConditionsMap = std::map<EntityHandle, VectorDouble>;
35 
36  enum class CouplingPairs {
40  };
41 };
42 
43 /**
44  * @brief Type generating multipoint constraints.
45  *
46  */
47 template <> struct EssentialPreProc<MPCsType> {
48  EssentialPreProc(MoFEM::Interface &m_field, boost::shared_ptr<FEMethod> fe_ptr,
49  bool is_spatial_positions = false);
50 
51  MoFEMErrorCode operator()();
52 
54 
55  static MoFEMErrorCode loadFileWithMPCs(Interface &m_field,
56  const char *file_name,
57  const char *options);
58  /* @brief add links edges to post proc mesh
59  *
60  * @param m_field
61  * @param post_proc_mesh_interface
62  * @param field_names
63  * @return MoFEMErrorCode
64  */
65  static MoFEMErrorCode addLinksToPostProcMesh(Interface &m_field,
66  moab::Interface &post_proc_mesh_interface,
67  vector<std::string> field_names);
68 
69 protected:
71  boost::weak_ptr<FEMethod> fePtr;
73 };
74 
75 /**
76  * @brief Specialization for DisplacementCubitBcData
77  *
78  * @tparam
79  */
80 template <> struct EssentialPostProcRhs<MPCsType> {
82  boost::shared_ptr<FEMethod> fe_ptr,
83  double diag = 1, SmartPetscObj<Vec> rhs = nullptr);
84 
85  MoFEMErrorCode operator()();
86 
87 protected:
89  boost::weak_ptr<FEMethod> fePtr;
90  double vDiag;
92 };
93 
94 /**
95  * @brief Specialization for MPCsType
96  *
97  * @tparam
98  */
99 template <> struct EssentialPostProcLhs<MPCsType> {
101  boost::shared_ptr<FEMethod> fe_ptr,
102  double diag = 1,
103  SmartPetscObj<Mat> lhs = nullptr,
104  SmartPetscObj<AO> ao = nullptr);
105 
106  MoFEMErrorCode operator()();
107 
108 protected:
110  boost::weak_ptr<FEMethod> fePtr;
111  double vDiag;
114 };
115 
116 
117 template <int FIELD_DIM, AssemblyType A, IntegrationType I, typename OpBase>
119  : FormsIntegrators<OpBase>::template Assembly<A>::template LinearForm<
120  I>::template OpSource<1, FIELD_DIM> {
121 
122  using OpSource = typename FormsIntegrators<OpBase>::template Assembly<
123  A>::template LinearForm<I>::template OpSource<1, FIELD_DIM>;
124 
125  OpEssentialRhsImpl(const std::string field_name,
126  boost::shared_ptr<MPCsType> bc_data, // FIXME:
127  boost::shared_ptr<Range> ents_ptr,
128  std::vector<boost::shared_ptr<ScalingMethod>> smv);
129 
131  initConstraintFunction(boost::shared_ptr<MPCsType> bc_data) {
132  // FIXME: here implement functions depending on bc_data (MPC data)
133  return [this](double x, double y, double z) { return tVal; };
134  }
135 
136 private:
139 };
140 
141 template <int FIELD_DIM, AssemblyType A, IntegrationType I, typename OpBase>
143  const std::string field_name,
144  boost::shared_ptr<MPCsType> bc_data, // FIXME:
145  boost::shared_ptr<Range> ents_ptr,
146  std::vector<boost::shared_ptr<ScalingMethod>> smv)
147  : OpSource(field_name, initConstraintFunction(bc_data), ents_ptr),
148  vecOfTimeScalingMethods(smv) {
149  // static_assert(FIELD_DIM > 1, "Is not implemented for scalar field");
150 }
151 
152 template <int BASE_DIM, int FIELD_DIM, AssemblyType A, IntegrationType I,
153  typename OpBase>
155  : FormsIntegrators<OpBase>::template Assembly<A>::template BiLinearForm<
156  I>::template OpMass<BASE_DIM, FIELD_DIM> {
157 
158  using OpMass = typename FormsIntegrators<OpBase>::template Assembly<
160 
161  OpEssentialLhsImpl(const std::string field_name,
162  boost::shared_ptr<Range> ents_ptr);
163 };
164 
165 template <int BASE_DIM, int FIELD_DIM, AssemblyType A, IntegrationType I,
166  typename OpBase>
169  boost::shared_ptr<Range>
170  ents_ptr)
171  : OpMass(
173  [](double, double, double) constexpr { return 1; }, ents_ptr) {}
174 
175 template <int BASE_DIM, int FIELD_DIM, AssemblyType A, IntegrationType I,
176  typename OpBase>
178 
180  OpBase
181 
182  > {
183 
185 
187 
188  MoFEM::Interface &m_field,
189  boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
190  const std::string problem_name, std::string field_name,
191  boost::shared_ptr<MatrixDouble> field_mat_ptr,
192  std::vector<boost::shared_ptr<ScalingMethod>> smv
193 
194  ) {
196 
197  using OP = typename EssentialBC<OpBase>::template Assembly<A>::
198  template LinearForm<I>::template OpEssentialRhs<
200  FIELD_DIM>; // TODO: we might need to implement OpEssentialRhsMaster
201  // and OpEssentialRhsSlave
202  using OpInternal = typename FormsIntegrators<OpBase>::template Assembly<
203  A>::template LinearForm<I>::template OpBaseTimesVector<BASE_DIM,
204  FIELD_DIM, 1>;
205 
206  auto add_op = [&](auto &bcs) {
208  for (auto &m : bcs) {
209  if (auto bc = m.second->mpcPtr) {
210  auto &bc_id = m.first;
211  auto regex_str =
212  (boost::format("%s_%s_(.*)") % problem_name %
213  field_name).str();
214  if (std::regex_match(bc_id, std::regex(regex_str))) {
215  MOFEM_TAG_AND_LOG("SELF", Sev::noisy, "OpMPCsRhs") << *bc;
216  pipeline.push_back(
217  new OpSetBc(field_name, false, m.second->getBcMarkersPtr()));
218  pipeline.push_back(
219  new OP(field_name, bc, m.second->getBcEntsPtr(), smv));
220  pipeline.push_back(new OpInternal(
221  field_name, field_mat_ptr,
222  [](double, double, double) constexpr { return 1.; },
223  m.second->getBcEntsPtr()));
224  pipeline.push_back(new OpUnSetBc(field_name));
225 
226  // else
227  // {
228  // // specific for master
229  // }
230  // switch (bc->mpcType) {
231  // case MPCsType::MPC::TIE:
232  // case MPCsType::MPC::RIGID_BODY:
233  // case MPCsType::MPC::COUPLING:
234  // // in case for tie, rigid body and coupling for MASTER, we dont
235  // // have to do anything
236  // break;
237  // }
238  //
239  }
240  }
241  }
242  MOFEM_LOG_CHANNEL("SELF");
244  };
245 
246  // CHKERR add_op(m_field.getInterface<BcManager>()->getBcMapByBlockName());
247  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
248  "Not implemented for MPCs");
250  }
251 };
252 
253 template <int BASE_DIM, int FIELD_DIM, AssemblyType A, IntegrationType I,
254  typename OpBase>
256 
258  OpBase
259 
260  > {
261 
263 
265 
266  MoFEM::Interface &m_field,
267  boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
268  const std::string problem_name, std::string field_name
269 
270  ) {
272 
273  // using OP = typename PCsBC<OpBase>::template Assembly<A>::
274  // template BiLinearForm<I>::template OpPCsLhs<
275  // MPCsType, BASE_DIM, FIELD_DIM>;
276 
277  // auto add_op = [&](auto &bcs) {
278  // MoFEMFunctionBeginHot;
279  // for (auto &m : bcs) {
280  // if (auto bc = m.second->dispBcPtr) {
281  // auto &bc_id = m.first;
282  // auto regex_str =
283  // (boost::format("%s_%s_(.*)") % problem_name %
284  // field_name).str();
285  // if (std::regex_match(bc_id, std::regex(regex_str))) {
286  // MOFEM_TAG_AND_LOG("SELF", Sev::noisy, "OpPCsLhs") << *bc;
287  // pipeline.push_back(
288  // new OpSetBc(field_name, false, m.second->getBcMarkersPtr()));
289  // pipeline.push_back(new OP(field_name, m.second->getBcEntsPtr()));
290  // pipeline.push_back(new OpUnSetBc(field_name));
291  // }
292  // }
293  // }
294  // MOFEM_LOG_CHANNEL("SELF");
295  // MoFEMFunctionReturnHot(0);
296  // };
297 
298  // CHKERR add_op(m_field.getInterface<BcManager>()->getBcMapByBlockName());
299 
301  }
302 };
303 
304 } // namespace MoFEM
305 
306 #endif //_ESSENTIAL_MPCS_DATA_HPP_
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEM::MPC
MPC
Definition: EssentialMPCsData.hpp:16
MoFEM::MPCsType::conditionsMap
InitConditionsMap conditionsMap
Definition: EssentialMPCsData.hpp:34
MoFEM::EssentialPreProc< MPCsType >::mField
MoFEM::Interface & mField
Definition: EssentialMPCsData.hpp:70
FTensor::Tensor1< double, FIELD_DIM >
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
MoFEM::EssentialBC
Essential boundary conditions.
Definition: Essential.hpp:111
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::OpEssentialRhsImpl< MPCsType, 1, FIELD_DIM, A, I, OpBase >::vecOfTimeScalingMethods
VecOfTimeScalingMethods vecOfTimeScalingMethods
Definition: EssentialMPCsData.hpp:138
MoFEM::OpEssentialLhsImpl< MPCsType, BASE_DIM, FIELD_DIM, A, I, OpBase >::OpMass
typename FormsIntegrators< OpBase >::template Assembly< A >::template BiLinearForm< I >::template OpMass< BASE_DIM, FIELD_DIM > OpMass
Definition: EssentialMPCsData.hpp:159
MoFEM::MPCsType::mpcType
MPC mpcType
Definition: EssentialMPCsData.hpp:30
MoFEM::MPC::EQUATION
@ EQUATION
MoFEM::MPCsType::MPCsType
MPCsType()
Definition: EssentialMPCsData.hpp:31
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
MoFEM::EssentialPostProcRhs< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:89
MoFEM::DisplacementCubitBcData
Definition of the displacement bc data structure.
Definition: BCData.hpp:76
BASE_DIM
constexpr int BASE_DIM
Definition: dg_projection.cpp:15
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
FIELD_DIM
constexpr int FIELD_DIM
Definition: child_and_parent.cpp:15
I
constexpr IntegrationType I
Definition: operators_tests.cpp:31
MoFEM::MPCsType
Definition: EssentialMPCsData.hpp:19
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MoFEM::OpEssentialRhsImpl< MPCsType, 1, FIELD_DIM, A, I, OpBase >::tVal
FTensor::Tensor1< double, FIELD_DIM > tVal
Definition: EssentialMPCsData.hpp:137
MoFEM::OpBaseImpl
Definition: FormsIntegrators.hpp:170
MoFEM::MPCsType::CouplingPairs::POINT_TO_POINT
@ POINT_TO_POINT
MoFEM::EssentialPostProcLhs< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:110
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::VectorFun
boost::function< FTensor::Tensor1< double, DIM >(const double, const double, const double)> VectorFun
Vector function type.
Definition: FormsIntegrators.hpp:168
MoFEM::AddEssentialToLhsPipelineImpl< OpEssentialLhsImpl< MPCsType, BASE_DIM, FIELD_DIM, A, I, OpBase >, A, I, OpBase >::add
static MoFEMErrorCode add(MoFEM::Interface &m_field, boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pipeline, const std::string problem_name, std::string field_name)
Definition: EssentialMPCsData.hpp:264
MoFEM::MPCsType::bcMasterMarkers
std::vector< unsigned char > bcMasterMarkers
Definition: EssentialMPCsData.hpp:27
double
MoFEM::OpEssentialLhsImpl
Enforce essential constrains on lhs.
Definition: Essential.hpp:81
MoFEM::AddEssentialToRhsPipelineImpl
Function (factory) for setting operators for rhs pipeline.
Definition: Essential.hpp:92
MoFEM::EssentialPostProcLhs
Class (Function) to enforce essential constrains on the left hand side diagonal.
Definition: Essential.hpp:33
MoFEM::AddEssentialToLhsPipelineImpl
Function (factory) for setting operators for lhs pipeline.
Definition: Essential.hpp:103
MoFEM::EssentialPostProcLhs< MPCsType >::vDiag
double vDiag
Definition: EssentialMPCsData.hpp:111
MoFEM::MPC::RIGID_BODY
@ RIGID_BODY
MoFEM::MPC::EMBEDDED_REGION
@ EMBEDDED_REGION
MoFEM::AddEssentialToRhsPipelineImpl< OpEssentialRhsImpl< MPCsType, BASE_DIM, FIELD_DIM, A, I, OpBase >, A, I, OpBase >::add
static MoFEMErrorCode add(MoFEM::Interface &m_field, boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pipeline, const std::string problem_name, std::string field_name, boost::shared_ptr< MatrixDouble > field_mat_ptr, std::vector< boost::shared_ptr< ScalingMethod >> smv)
Definition: EssentialMPCsData.hpp:186
MoFEM::EssentialPostProcRhs< MPCsType >::mField
MoFEM::Interface & mField
Definition: EssentialMPCsData.hpp:88
MoFEM::MPC::TIE
@ TIE
MoFEM::setMPCParentAdjacency
MoFEMErrorCode setMPCParentAdjacency()
Definition: EssentialMPCsData.cpp:15
MoFEM::EssentialPreProc< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:71
BiLinearForm
MoFEM::EssentialPostProcRhs
Class (Function) to enforce essential constrains on the right hand side diagonal.
Definition: Essential.hpp:41
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
MoFEM::IntegrationType
IntegrationType
Form integrator integration types.
Definition: FormsIntegrators.hpp:128
MoFEM::OpEssentialRhsImpl< MPCsType, 1, FIELD_DIM, A, I, OpBase >::initConstraintFunction
VectorFun< FIELD_DIM > initConstraintFunction(boost::shared_ptr< MPCsType > bc_data)
Definition: EssentialMPCsData.hpp:131
MoFEM::EssentialPostProcLhs< MPCsType >::vAO
SmartPetscObj< AO > vAO
Definition: EssentialMPCsData.hpp:113
MoFEM::MPCsType::CouplingPairs
CouplingPairs
Definition: EssentialMPCsData.hpp:36
MoFEM::OpUnSetBc
Definition: FormsIntegrators.hpp:49
Range
MoFEM::OpEssentialRhsImpl< MPCsType, 1, FIELD_DIM, A, I, OpBase >::OpSource
typename FormsIntegrators< OpBase >::template Assembly< A >::template LinearForm< I >::template OpSource< 1, FIELD_DIM > OpSource
Definition: EssentialMPCsData.hpp:123
MoFEM::MPCsType::bcSlaveMarkers
std::vector< unsigned char > bcSlaveMarkers
Definition: EssentialMPCsData.hpp:28
MOFEM_TAG_AND_LOG
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
Definition: LogManager.hpp:362
MoFEM::OpEssentialRhsImpl
Enforce essential constrains on rhs.
Definition: Essential.hpp:65
MoFEM::AssemblyType
AssemblyType
[Storage and set boundary conditions]
Definition: FormsIntegrators.hpp:104
MoFEM::EssentialPreProc< MPCsType >::isSpatialPositions
bool isSpatialPositions
Definition: EssentialMPCsData.hpp:72
MoFEM::MPCsType::CouplingPairs::POINT_TO_SURFACE
@ POINT_TO_SURFACE
MoFEM::MPCsType::isReprocitical
bool isReprocitical
Definition: EssentialMPCsData.hpp:24
MoFEM::EssentialPostProcRhs< MPCsType >::vRhs
SmartPetscObj< Vec > vRhs
Definition: EssentialMPCsData.hpp:91
MoFEM::VecOfTimeScalingMethods
std::vector< boost::shared_ptr< ScalingMethod > > VecOfTimeScalingMethods
Vector of time scaling methods.
Definition: Natural.hpp:20
MoFEM::OpSetBc
Set indices on entities on finite element.
Definition: FormsIntegrators.hpp:38
MoFEM::MPC::LAST
@ LAST
MoFEM::EssentialPostProcLhs< MPCsType >::vLhs
SmartPetscObj< Mat > vLhs
Definition: EssentialMPCsData.hpp:112
MoFEM::MPCsType::InitConditionsMap
std::map< EntityHandle, VectorDouble > InitConditionsMap
Definition: EssentialMPCsData.hpp:33
MoFEM::MPCsType::mPenalty
double mPenalty
Definition: EssentialMPCsData.hpp:25
MoFEM::FormsIntegrators
Integrator forms.
Definition: FormsIntegrators.hpp:291
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
MoFEM::EssentialPreProc
Class (Function) to enforce essential constrains.
Definition: Essential.hpp:25
MoFEM::SmartPetscObj< Vec >
MoFEM::EssentialPostProcRhs< MPCsType >::vDiag
double vDiag
Definition: EssentialMPCsData.hpp:90
OP
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MOFEM_NOT_IMPLEMENTED
@ MOFEM_NOT_IMPLEMENTED
Definition: definitions.h:32
MoFEM::MPCsType::mpcMasterEnts
Range mpcMasterEnts
Definition: EssentialMPCsData.hpp:22
MoFEM::MPCsType::CouplingPairs::SURFACE_TO_SURFACE
@ SURFACE_TO_SURFACE
MoFEM::MPCsType::mpcSlaveEnts
Range mpcSlaveEnts
Definition: EssentialMPCsData.hpp:23
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
MoFEM::MPC::COUPLING
@ COUPLING
MoFEM::EssentialPostProcLhs< MPCsType >::mField
MoFEM::Interface & mField
Definition: EssentialMPCsData.hpp:109