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 
24  double mPenalty;
25 
26  std::vector<unsigned char> bcMasterMarkers;
27  std::vector<unsigned char> bcSlaveMarkers;
28 
30  MPCsType() : mpcType(MPC::TIE), isReprocitical(true), mPenalty(1e8) {}
31  // virtual ~MPCsType() {}
32  using InitConditionsMap = std::map<EntityHandle, VectorDouble>;
34 
35  enum class CouplingPairs {
39  };
40 };
41 
42 /**
43  * @brief Type generating multipoint constraints.
44  *
45  */
46 template <> struct EssentialPreProc<MPCsType> {
47  EssentialPreProc(MoFEM::Interface &m_field, boost::shared_ptr<FEMethod> fe_ptr,
48  bool is_spatial_positions = false);
49 
50  virtual ~EssentialPreProc() = default;
51 
52  MoFEMErrorCode operator()();
53 
55 
56  static MoFEMErrorCode loadFileWithMPCs(Interface &m_field,
57  const char *file_name,
58  const char *options);
59  /* @brief add links edges to post proc mesh
60  *
61  * @param m_field
62  * @param post_proc_mesh_interface
63  * @param field_names
64  * @return MoFEMErrorCode
65  */
66  static MoFEMErrorCode addLinksToPostProcMesh(Interface &m_field,
67  moab::Interface &post_proc_mesh_interface,
68  vector<std::string> field_names);
69 
70 protected:
72  boost::weak_ptr<FEMethod> fePtr;
74 };
75 
76 /**
77  * @brief Specialization for DisplacementCubitBcData
78  *
79  * @tparam
80  */
81 template <> struct EssentialPostProcRhs<MPCsType> {
83  boost::shared_ptr<FEMethod> fe_ptr,
84  double diag = 1, SmartPetscObj<Vec> rhs = nullptr);
85 
86  virtual ~EssentialPostProcRhs() = default;
87 
88  MoFEMErrorCode operator()();
89 
90 protected:
92  boost::weak_ptr<FEMethod> fePtr;
93  double vDiag;
95 };
96 
97 /**
98  * @brief Specialization for MPCsType
99  *
100  * @tparam
101  */
102 template <> struct EssentialPostProcLhs<MPCsType> {
104  boost::shared_ptr<FEMethod> fe_ptr,
105  double diag = 1,
106  SmartPetscObj<Mat> lhs = nullptr,
107  SmartPetscObj<AO> ao = nullptr);
108 
109  virtual ~EssentialPostProcLhs() = default;
110 
111  MoFEMErrorCode operator()();
112 
113 protected:
115  boost::weak_ptr<FEMethod> fePtr;
116  double vDiag;
119 };
120 
121 
122 template <int FIELD_DIM, AssemblyType A, IntegrationType I, typename OpBase>
124  : FormsIntegrators<OpBase>::template Assembly<A>::template LinearForm<
125  I>::template OpSource<1, FIELD_DIM> {
126 
127  using OpSource = typename FormsIntegrators<OpBase>::template Assembly<
128  A>::template LinearForm<I>::template OpSource<1, FIELD_DIM>;
129 
130  OpEssentialRhsImpl(const std::string field_name,
131  boost::shared_ptr<MPCsType> bc_data, // FIXME:
132  boost::shared_ptr<Range> ents_ptr,
133  std::vector<boost::shared_ptr<ScalingMethod>> smv);
134 
136  initConstraintFunction(boost::shared_ptr<MPCsType> bc_data) {
137  // FIXME: here implement functions depending on bc_data (MPC data)
138  return [this](double x, double y, double z) { return tVal; };
139  }
140 
141 private:
144 };
145 
146 template <int FIELD_DIM, AssemblyType A, IntegrationType I, typename OpBase>
148  const std::string field_name,
149  boost::shared_ptr<MPCsType> bc_data, // FIXME:
150  boost::shared_ptr<Range> ents_ptr,
151  std::vector<boost::shared_ptr<ScalingMethod>> smv)
152  : OpSource(field_name, initConstraintFunction(bc_data), ents_ptr),
153  vecOfTimeScalingMethods(smv) {
154  // static_assert(FIELD_DIM > 1, "Is not implemented for scalar field");
155 }
156 
157 template <int BASE_DIM, int FIELD_DIM, AssemblyType A, IntegrationType I,
158  typename OpBase>
160  : FormsIntegrators<OpBase>::template Assembly<A>::template BiLinearForm<
161  I>::template OpMass<BASE_DIM, FIELD_DIM> {
162 
163  using OpMass = typename FormsIntegrators<OpBase>::template Assembly<
165 
166  OpEssentialLhsImpl(const std::string field_name,
167  boost::shared_ptr<Range> ents_ptr);
168 };
169 
170 template <int BASE_DIM, int FIELD_DIM, AssemblyType A, IntegrationType I,
171  typename OpBase>
174  boost::shared_ptr<Range>
175  ents_ptr)
176  : OpMass(
178  [](double, double, double) constexpr { return 1; }, ents_ptr) {}
179 
180 template <int BASE_DIM, int FIELD_DIM, AssemblyType A, IntegrationType I,
181  typename OpBase>
183 
185  OpBase
186 
187  > {
188 
190 
192 
193  MoFEM::Interface &m_field,
194  boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
195  const std::string problem_name, std::string field_name,
196  boost::shared_ptr<MatrixDouble> field_mat_ptr,
197  std::vector<boost::shared_ptr<ScalingMethod>> smv
198 
199  ) {
201 
202  using OP = typename EssentialBC<OpBase>::template Assembly<A>::
203  template LinearForm<I>::template OpEssentialRhs<
205  FIELD_DIM>; // TODO: we might need to implement OpEssentialRhsMaster
206  // and OpEssentialRhsSlave
207  using OpInternal = typename FormsIntegrators<OpBase>::template Assembly<
208  A>::template LinearForm<I>::template OpBaseTimesVector<BASE_DIM,
209  FIELD_DIM, 1>;
210 
211  auto add_op = [&](auto &bcs) {
213  for (auto &m : bcs) {
214  if (auto bc = m.second->mpcPtr) {
215  auto &bc_id = m.first;
216  auto regex_str =
217  (boost::format("%s_%s_(.*)") % problem_name %
218  field_name).str();
219  if (std::regex_match(bc_id, std::regex(regex_str))) {
220  MOFEM_TAG_AND_LOG("SELF", Sev::noisy, "OpMPCsRhs") << *bc;
221  pipeline.push_back(
222  new OpSetBc(field_name, false, m.second->getBcMarkersPtr()));
223  pipeline.push_back(
224  new OP(field_name, bc, m.second->getBcEntsPtr(), smv));
225  pipeline.push_back(new OpInternal(
226  field_name, field_mat_ptr,
227  [](double, double, double) constexpr { return 1.; },
228  m.second->getBcEntsPtr()));
229  pipeline.push_back(new OpUnSetBc(field_name));
230 
231  // else
232  // {
233  // // specific for master
234  // }
235  // switch (bc->mpcType) {
236  // case MPCsType::MPC::TIE:
237  // case MPCsType::MPC::RIGID_BODY:
238  // case MPCsType::MPC::COUPLING:
239  // // in case for tie, rigid body and coupling for MASTER, we dont
240  // // have to do anything
241  // break;
242  // }
243  //
244  }
245  }
246  }
247  MOFEM_LOG_CHANNEL("SELF");
249  };
250 
251  // CHKERR add_op(m_field.getInterface<BcManager>()->getBcMapByBlockName());
252  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
253  "Not implemented for MPCs");
255  }
256 };
257 
258 template <int BASE_DIM, int FIELD_DIM, AssemblyType A, IntegrationType I,
259  typename OpBase>
261 
263  OpBase
264 
265  > {
266 
268 
270 
271  MoFEM::Interface &m_field,
272  boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
273  const std::string problem_name, std::string field_name
274 
275  ) {
277 
278  // using OP = typename PCsBC<OpBase>::template Assembly<A>::
279  // template BiLinearForm<I>::template OpPCsLhs<
280  // MPCsType, BASE_DIM, FIELD_DIM>;
281 
282  // auto add_op = [&](auto &bcs) {
283  // MoFEMFunctionBeginHot;
284  // for (auto &m : bcs) {
285  // if (auto bc = m.second->dispBcPtr) {
286  // auto &bc_id = m.first;
287  // auto regex_str =
288  // (boost::format("%s_%s_(.*)") % problem_name %
289  // field_name).str();
290  // if (std::regex_match(bc_id, std::regex(regex_str))) {
291  // MOFEM_TAG_AND_LOG("SELF", Sev::noisy, "OpPCsLhs") << *bc;
292  // pipeline.push_back(
293  // new OpSetBc(field_name, false, m.second->getBcMarkersPtr()));
294  // pipeline.push_back(new OP(field_name, m.second->getBcEntsPtr()));
295  // pipeline.push_back(new OpUnSetBc(field_name));
296  // }
297  // }
298  // }
299  // MOFEM_LOG_CHANNEL("SELF");
300  // MoFEMFunctionReturnHot(0);
301  // };
302 
303  // CHKERR add_op(m_field.getInterface<BcManager>()->getBcMapByBlockName());
304 
306  }
307 };
308 
309 } // namespace MoFEM
310 
311 #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:33
MoFEM::EssentialPreProc< MPCsType >::mField
MoFEM::Interface & mField
Definition: EssentialMPCsData.hpp:71
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:143
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:164
MoFEM::MPCsType::mpcType
MPC mpcType
Definition: EssentialMPCsData.hpp:29
MoFEM::MPC::EQUATION
@ EQUATION
MoFEM::MPCsType::MPCsType
MPCsType()
Definition: EssentialMPCsData.hpp:30
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
MoFEM::EssentialPostProcRhs< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:92
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:142
MoFEM::OpBaseImpl
Definition: FormsIntegrators.hpp:178
MoFEM::MPCsType::CouplingPairs::POINT_TO_POINT
@ POINT_TO_POINT
MoFEM::EssentialPostProcLhs< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:115
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:176
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:269
MoFEM::MPCsType::bcMasterMarkers
std::vector< unsigned char > bcMasterMarkers
Definition: EssentialMPCsData.hpp:26
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:116
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:191
MoFEM::EssentialPostProcRhs< MPCsType >::mField
MoFEM::Interface & mField
Definition: EssentialMPCsData.hpp:91
MoFEM::MPC::TIE
@ TIE
MoFEM::setMPCParentAdjacency
MoFEMErrorCode setMPCParentAdjacency()
Definition: EssentialMPCsData.cpp:15
MoFEM::EssentialPreProc< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:72
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:136
MoFEM::OpEssentialRhsImpl< MPCsType, 1, FIELD_DIM, A, I, OpBase >::initConstraintFunction
VectorFun< FIELD_DIM > initConstraintFunction(boost::shared_ptr< MPCsType > bc_data)
Definition: EssentialMPCsData.hpp:136
MoFEM::EssentialPostProcLhs< MPCsType >::vAO
SmartPetscObj< AO > vAO
Definition: EssentialMPCsData.hpp:118
MoFEM::MPCsType::CouplingPairs
CouplingPairs
Definition: EssentialMPCsData.hpp:35
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:128
MoFEM::MPCsType::bcSlaveMarkers
std::vector< unsigned char > bcSlaveMarkers
Definition: EssentialMPCsData.hpp:27
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:73
MoFEM::MPCsType::CouplingPairs::POINT_TO_SURFACE
@ POINT_TO_SURFACE
MoFEM::MPCsType::isReprocitical
bool isReprocitical
Definition: EssentialMPCsData.hpp:23
MoFEM::EssentialPostProcRhs< MPCsType >::vRhs
SmartPetscObj< Vec > vRhs
Definition: EssentialMPCsData.hpp:94
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:117
MoFEM::MPCsType::InitConditionsMap
std::map< EntityHandle, VectorDouble > InitConditionsMap
Definition: EssentialMPCsData.hpp:32
MoFEM::MPCsType::mPenalty
double mPenalty
Definition: EssentialMPCsData.hpp:24
MoFEM::FormsIntegrators
Integrator forms.
Definition: FormsIntegrators.hpp:299
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:93
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:21
MoFEM::MPCsType::CouplingPairs::SURFACE_TO_SURFACE
@ SURFACE_TO_SURFACE
MoFEM::MPCsType::mpcSlaveEnts
Range mpcSlaveEnts
Definition: EssentialMPCsData.hpp:22
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:114