v0.14.0
FluidLevel.hpp
Go to the documentation of this file.
1 /**
2  * @file FluidLevel.hpp
3  * @brief Natural boundary condition applying pressure from fluid.
4  * @date 2024-01-02
5  *
6  * @copyright Copyright (c) 2024
7  *
8  * Fluid level is type of linear pressure boundary condition.
9  *
10  * \todo Implement time depended fluid level.
11  *
12  */
13 
14 namespace ElasticExample {
15 
16 template <CubitBC BC> struct FluidLevelType {};
17 
18 template <CubitBC BC> struct GetFluidLevel;
19 
20 template <> struct GetFluidLevel<BLOCKSET> {
21  GetFluidLevel() = delete;
22 
23  static MoFEMErrorCode getParams(double &density,
24  std::array<double, 3> &gravity,
25  std::array<double, 3> &zero_pressure,
26  boost::shared_ptr<Range> &ents,
27  MoFEM::Interface &m_field, int ms_id) {
29 
30  auto cubit_meshset_ptr =
31  m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(ms_id,
32  BLOCKSET);
33  std::vector<double> block_data;
34  CHKERR cubit_meshset_ptr->getAttributes(block_data);
35  if (block_data.size() != 1 + 3 + 3) {
36  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
37  "Expected that block has two attribute");
38  }
39  density = block_data[0];
40  gravity = {block_data[1], block_data[2], block_data[3]};
41  zero_pressure = {block_data[4], block_data[5], block_data[6]};
42 
43  MOFEM_LOG_CHANNEL("WORLD");
44  MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "FluidPressure")
45  << "Density " << density;
46  MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "FluidPressure")
47  << "Gravity " << gravity[0] << " " << gravity[1] << " " << gravity[2];
48  MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "FluidPressure")
49  << "Zero pressure " << zero_pressure[0] << " " << zero_pressure[1]
50  << " " << zero_pressure[2];
51 
52  ents = boost::make_shared<Range>();
53  CHKERR
54  m_field.get_moab().get_entities_by_handle(cubit_meshset_ptr->meshset,
55  *(ents), true);
56 
57  MOFEM_LOG_CHANNEL("SYNC");
58  MOFEM_TAG_AND_LOG("SYNC", Sev::noisy, "FluidPressure") << *ents;
59  MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
60 
62  }
63 };
64 
65 } // namespace ElasticExample
66 
67 template <int FIELD_DIM, AssemblyType A, typename EleOp>
68 struct OpFluxRhsImpl<ElasticExample::FluidLevelType<BLOCKSET>, 1, FIELD_DIM, A,
69  GAUSS, EleOp> : OpBaseImpl<A, EleOp> {
70 
72 
73  OpFluxRhsImpl(MoFEM::Interface &m_field, int ms_id, std::string field_name,
74  std::vector<boost::shared_ptr<ScalingMethod>> smv,
75  double scale);
76 
77 protected:
78  double fluidDensity;
79  std::array<double, 3> gravityAcceleration;
80  std::array<double, 3> zeroPressure;
81  std::vector<boost::shared_ptr<ScalingMethod>> vecOfTimeScalingMethods;
82  double rhsScale;
83 
85 };
86 
87 template <int FIELD_DIM, AssemblyType A, typename EleOp>
88 OpFluxRhsImpl<
90  EleOp>::OpFluxRhsImpl(MoFEM::Interface &m_field, int ms_id,
91  std::string field_name,
92  std::vector<boost::shared_ptr<ScalingMethod>> smv,
93  double scale)
94  : OpBase(field_name, field_name, OpBase::OPROW),
95  vecOfTimeScalingMethods(smv), rhsScale(scale) {
97  this->fluidDensity, this->gravityAcceleration,
98  this->zeroPressure, this->entsPtr, m_field, ms_id),
99  "Can not read spring stiffness data from blockset");
100 }
101 
102 template <int FIELD_DIM, AssemblyType A, typename EleOp>
106  &row_data) {
110  // get element volume
111  const double vol = OpBase::getMeasure();
112  // get integration weights
113  auto t_w = OpBase::getFTensor0IntegrationWeight();
114  // get base function gradient on rows
115  auto t_row_base = row_data.getFTensor0N();
116 
117  // get coordinate at integration points
118  auto t_normal = OpBase::getFTensor1NormalsAtGaussPts();
119  // get coordinate at integration points
120  auto t_coord = OpBase::getFTensor1CoordsAtGaussPts();
121 
122  auto t_gravity = getFTensor1FromPtr<FIELD_DIM>(gravityAcceleration.data());
123  auto t_zero_pressure = getFTensor1FromPtr<FIELD_DIM>(zeroPressure.data());
124 
125  double s = 1;
126  for (auto &o : vecOfTimeScalingMethods) {
127  s *= o->getScale(OpBase::getTStime());
128  }
129 
130  // loop over integration points
131  for (int gg = 0; gg != OpBase::nbIntegrationPts; ++gg) {
132  // take into account Jacobian
133  const double alpha = t_w * rhsScale;
134 
136  t_level(i) = t_coord(i) - t_zero_pressure(i);
137  auto dot = t_gravity(i) * t_level(i);
138 
140  t_force(i) = -s * fluidDensity * dot * t_normal(i);
141 
142  // loop over rows base functions
143  auto t_nf = getFTensor1FromArray<FIELD_DIM, FIELD_DIM>(OpBase::locF);
144  int rr = 0;
145  for (; rr != OpBase::nbRows / FIELD_DIM; ++rr) {
146  t_nf(i) += (alpha * t_row_base) * t_force(i);
147  ++t_row_base;
148  ++t_nf;
149  }
150 
151  for (; rr < OpBase::nbRowBaseFunctions; ++rr)
152  ++t_row_base;
153 
154  ++t_w;
155  ++t_coord;
156  ++t_normal;
157  }
159 }
160 
161 template <CubitBC BCTYPE, int BASE_DIM, int FIELD_DIM, AssemblyType A,
162  IntegrationType I, typename OpBase>
163 struct AddFluxToRhsPipelineImpl<
164 
165  OpFluxRhsImpl<ElasticExample::FluidLevelType<BCTYPE>, BASE_DIM, FIELD_DIM,
166  A, I, OpBase>,
167  A, I, OpBase
168 
169  > {
170 
171  AddFluxToRhsPipelineImpl() = delete;
172 
174 
175  boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
176  MoFEM::Interface &m_field, std::string field_name,
177  std::vector<boost::shared_ptr<ScalingMethod>> smv, double scale,
178  std::string block_name, Sev sev
179 
180  ) {
182 
183  using OP = OpFluxRhsImpl<ElasticExample::FluidLevelType<BLOCKSET>, BASE_DIM,
185 
186  auto add_op = [&](auto &&meshset_vec_ptr) {
187  for (auto m : meshset_vec_ptr) {
188  MOFEM_TAG_AND_LOG("WORLD", sev, "OFluidLevelRhs") << "Add " << *m;
189  pipeline.push_back(
190  new OP(m_field, m->getMeshsetId(), field_name, smv, scale));
191  }
192  MOFEM_LOG_CHANNEL("WORLD");
193  };
194 
195  switch (BCTYPE) {
196  case BLOCKSET:
197  add_op(
198 
199  m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
200  std::regex(
201 
202  (boost::format("%s(.*)") % block_name).str()
203 
204  ))
205 
206  );
207 
208  break;
209  default:
210  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
211  "Handling of bc type not implemented");
212  break;
213  }
215  }
216 };
AddFluxToRhsPipelineImpl< OpFluxRhsImpl< ElasticExample::FluidLevelType< BCTYPE >, BASE_DIM, FIELD_DIM, A, I, OpBase >, A, I, OpBase >::add
static MoFEMErrorCode add(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pipeline, MoFEM::Interface &m_field, std::string field_name, std::vector< boost::shared_ptr< ScalingMethod >> smv, double scale, std::string block_name, Sev sev)
Definition: FluidLevel.hpp:173
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::OpBaseImpl::nbIntegrationPts
int nbIntegrationPts
number of integration points
Definition: FormsIntegrators.hpp:228
ElasticExample::GetFluidLevel
Definition: FluidLevel.hpp:18
MOFEM_LOG_SEVERITY_SYNC
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
Definition: LogManager.hpp:352
FTensor::Tensor1< double, FIELD_DIM >
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
MoFEM::OpFluxRhsImpl
Definition: Natural.hpp:39
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
OpFluxRhsImpl< ElasticExample::FluidLevelType< BLOCKSET >, 1, FIELD_DIM, A, GAUSS, EleOp >::gravityAcceleration
std::array< double, 3 > gravityAcceleration
Definition: FluidLevel.hpp:79
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:596
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::PETSC
@ PETSC
Definition: FormsIntegrators.hpp:104
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
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
EleOp
MoFEM::OpBaseImpl::locF
VectorDouble locF
local entity vector
Definition: FormsIntegrators.hpp:241
MoFEM::Sev
MoFEM::LogManager::SeverityLevel Sev
Definition: CoreTemplates.hpp:17
MoFEM::OpBaseImpl
Definition: FormsIntegrators.hpp:170
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
ContactOps::scale
double scale
Definition: EshelbianContact.hpp:22
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
ElasticExample::FluidLevelType
Definition: FluidLevel.hpp:16
ElasticExample
Definition: CalculateTraction.hpp:10
OpFluxRhsImpl< ElasticExample::FluidLevelType< BLOCKSET >, 1, FIELD_DIM, A, GAUSS, EleOp >::vecOfTimeScalingMethods
std::vector< boost::shared_ptr< ScalingMethod > > vecOfTimeScalingMethods
Definition: FluidLevel.hpp:81
MoFEM::GAUSS
@ GAUSS
Definition: FormsIntegrators.hpp:128
ElasticExample::GetFluidLevel< BLOCKSET >::getParams
static MoFEMErrorCode getParams(double &density, std::array< double, 3 > &gravity, std::array< double, 3 > &zero_pressure, boost::shared_ptr< Range > &ents, MoFEM::Interface &m_field, int ms_id)
Definition: FluidLevel.hpp:23
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
EntData
EntitiesFieldData::EntData EntData
Definition: child_and_parent.cpp:37
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
FTensor::Index< 'i', FIELD_DIM >
MoFEM::IntegrationType
IntegrationType
Form integrator integration types.
Definition: FormsIntegrators.hpp:128
OpFluxRhsImpl< ElasticExample::FluidLevelType< BLOCKSET >, 1, FIELD_DIM, A, GAUSS, EleOp >::fluidDensity
double fluidDensity
Definition: FluidLevel.hpp:78
MoFEM::OpBaseImpl::nbRowBaseFunctions
int nbRowBaseFunctions
number or row base functions
Definition: FormsIntegrators.hpp:229
OpFluxRhsImpl< ElasticExample::FluidLevelType< BLOCKSET >, 1, FIELD_DIM, A, GAUSS, EleOp >::rhsScale
double rhsScale
Definition: FluidLevel.hpp:82
MOFEM_TAG_AND_LOG
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
Definition: LogManager.hpp:362
MoFEM::OpBaseImpl::nbRows
int nbRows
number of dofs on rows
Definition: FormsIntegrators.hpp:226
MoFEM::AssemblyType
AssemblyType
[Storage and set boundary conditions]
Definition: FormsIntegrators.hpp:104
BLOCKSET
@ BLOCKSET
Definition: definitions.h:148
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
OpBaseImpl
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
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
OpFluxRhsImpl< ElasticExample::FluidLevelType< BLOCKSET >, 1, FIELD_DIM, A, GAUSS, EleOp >::zeroPressure
std::array< double, 3 > zeroPressure
Definition: FluidLevel.hpp:80
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
CubitBC
CubitBC
Types of sets and boundary conditions.
Definition: definitions.h:144