v0.14.0
ThermalConvection.hpp
Go to the documentation of this file.
1 /**
2  * @file ThermalConvection.hpp
3  * @author Andrei Shvarts (andrei.shvarts@glasgow.ac.uk)
4  * @brief Implementation of thermal convection bc
5  * @version 0.14.0
6  * @date 2024-08-23
7  *
8  * @copyright Copyright (c) 2024
9  *
10  */
11 
12 namespace ThermoElasticOps {
13 
14 template <CubitBC BC> struct ConvectionBcType {};
15 
16 template <CubitBC BC> struct GetConvectionParameters;
17 
18 template <> struct GetConvectionParameters<BLOCKSET> {
19  GetConvectionParameters() = delete;
20 
21  static MoFEMErrorCode getParameters(double &heat_transfer_coefficient,
22  double &ambient_temperature,
23  boost::shared_ptr<Range> &ents,
24  MoFEM::Interface &m_field, int ms_id,
25  Sev sev) {
26 
28 
29  auto cubit_meshset_ptr =
30  m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(ms_id,
31  BLOCKSET);
32  std::vector<double> block_data;
33  CHKERR cubit_meshset_ptr->getAttributes(block_data);
34  if (block_data.size() < 2) {
35  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
36  "Expected that convection block has two attributes (heat "
37  "transfer coefficient and ambient temperature)");
38  }
39  heat_transfer_coefficient = block_data[0];
40  ambient_temperature = block_data[1];
41 
42  MOFEM_LOG_CHANNEL("WORLD");
43  MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "ConvectionBc")
44  << "Heat transfer coefficient " << heat_transfer_coefficient;
45  MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "ConvectionBc")
46  << "Ambient temperature " << ambient_temperature;
47 
48  ents = boost::make_shared<Range>();
49  CHKERR
50  m_field.get_moab().get_entities_by_handle(cubit_meshset_ptr->meshset,
51  *(ents), true);
52 
53  MOFEM_LOG_CHANNEL("SYNC");
54  MOFEM_TAG_AND_LOG("SYNC", Sev::noisy, "ConvectionBc") << *ents;
55  MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
56 
58  }
59 };
60 
61 } // namespace ThermoElasticOps
62 
63 template <AssemblyType A, typename EleOp>
64 struct OpFluxRhsImpl<ThermoElasticOps::ConvectionBcType<BLOCKSET>, 1, 1, A,
65  GAUSS, EleOp> : OpBaseImpl<A, EleOp> {
66 
68 
69  OpFluxRhsImpl(MoFEM::Interface &m_field, int ms_id, std::string field_name,
70  boost::shared_ptr<VectorDouble> t_ptr);
71 
72 protected:
75  boost::shared_ptr<VectorDouble> tPtr;
77 };
78 
79 template <AssemblyType A, typename EleOp>
80 struct OpFluxLhsImpl<ThermoElasticOps::ConvectionBcType<BLOCKSET>, 1, 1, A,
81  GAUSS, EleOp> : OpBaseImpl<A, EleOp> {
82 
84 
85  OpFluxLhsImpl(MoFEM::Interface &m_field, int ms_id,
86  std::string row_field_name, std::string col_field_name);
87 
88 protected:
91  MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &row_data,
92  EntitiesFieldData::EntData &col_data);
93 };
94 
95 template <AssemblyType A, typename EleOp>
96 OpFluxRhsImpl<ThermoElasticOps::ConvectionBcType<BLOCKSET>, 1, 1, A, GAUSS,
97  EleOp>::OpFluxRhsImpl(MoFEM::Interface &m_field, int ms_id,
98  std::string field_name,
99  boost::shared_ptr<VectorDouble> t_ptr)
100  : OpBase(field_name, field_name, OpBase::OPROW), tPtr(t_ptr) {
103  this->heatTransferCoefficient, this->ambientTemperature,
104  this->entsPtr, m_field, ms_id, Sev::inform),
105  "Cannot read convection data from blockset");
106 }
107 
108 template <AssemblyType A, typename EleOp>
112  &row_data) {
114 
115  // get integration weights
116  auto t_w = OpBase::getFTensor0IntegrationWeight();
117  // get base function values on rows
118  auto t_row_base = row_data.getFTensor0N();
119 
120  // get temperature
121  auto t_temp = getFTensor0FromVec(*tPtr);
122  // loop over integration points
123  for (int gg = 0; gg != OpBase::nbIntegrationPts; ++gg) {
124  const auto alpha =
125  -t_w * heatTransferCoefficient * (t_temp - ambientTemperature);
126  int rr = 0;
127  for (; rr != OpBase::nbRows; ++rr) {
128  OpBase::locF[rr] += alpha * t_row_base;
129  ++t_row_base;
130  }
131 
132  for (; rr < OpBase::nbRowBaseFunctions; ++rr)
133  ++t_row_base;
134 
135  ++t_w;
136  ++t_temp;
137  }
138 
139  // get normal vector
140  auto t_normal = OpBase::getFTensor1Normal();
141  OpBase::locF *= t_normal.l2();
142 
143  EntityType fe_type = OpBase::getNumeredEntFiniteElementPtr()->getEntType();
144  if (fe_type == MBTRI) {
145  OpBase::locF /= 2;
146  }
147 
149 }
150 
151 template <AssemblyType A, typename EleOp>
152 OpFluxLhsImpl<ThermoElasticOps::ConvectionBcType<BLOCKSET>, 1, 1, A, GAUSS,
153  EleOp>::OpFluxLhsImpl(MoFEM::Interface &m_field, int ms_id,
154  std::string row_field_name,
155  std::string col_field_name)
156  : OpBase(row_field_name, col_field_name, OpBase::OPROWCOL) {
157 
158  this->sYmm = true;
159 
162  this->heatTransferCoefficient, this->ambientTemperature,
163  this->entsPtr, m_field, ms_id, Sev::verbose),
164  "Cannot read convection data from blockset");
165 }
166 
167 template <AssemblyType A, typename EleOp>
170  GAUSS,
171  EleOp>::iNtegrate(EntitiesFieldData::EntData &row_data,
172  EntitiesFieldData::EntData &col_data) {
173 
175  // get element volume
176  const double vol = OpBase::getMeasure();
177  // get integration weights
178  auto t_w = OpBase::getFTensor0IntegrationWeight();
179  // get base function values on rows
180  auto t_row_base = row_data.getFTensor0N();
181  // loop over integration points
182  for (int gg = 0; gg != OpBase::nbIntegrationPts; ++gg) {
183  // loop over rows base functions
184  int rr = 0;
185  for (; rr != OpBase::nbRows; rr++) {
186  const auto alpha = t_w * t_row_base;
187  // get column base functions values at gauss point gg
188  auto t_col_base = col_data.getFTensor0N(gg, 0);
189  // loop over columns
190  for (int cc = 0; cc != OpBase::nbCols; cc++) {
191  OpBase::locMat(rr, cc) += alpha * t_col_base;
192  ++t_col_base;
193  }
194  ++t_row_base;
195  }
196  for (; rr < OpBase::nbRowBaseFunctions; ++rr)
197  ++t_row_base;
198  ++t_w; // move to another integration weight
199  }
200  // get normal vector
201  auto t_normal = OpBase::getFTensor1Normal();
202  // using L2 norm of normal vector for convenient area calculation for quads,
203  // tris etc.
204  OpBase::locMat *= -t_normal.l2() * heatTransferCoefficient;
205 
206  EntityType fe_type = OpBase::getNumeredEntFiniteElementPtr()->getEntType();
207  if (fe_type == MBTRI) {
208  OpBase::locMat /= 2;
209  }
210 
212 }
213 
214 template <CubitBC BCTYPE, int BASE_DIM, int FIELD_DIM, AssemblyType A,
215  IntegrationType I, typename OpBase>
216 struct AddFluxToRhsPipelineImpl<
217 
218  OpFluxRhsImpl<ThermoElasticOps::ConvectionBcType<BCTYPE>, BASE_DIM,
219  FIELD_DIM, A, I, OpBase>,
220  A, I, OpBase
221 
222  > {
223 
224  AddFluxToRhsPipelineImpl() = delete;
225 
227 
228  boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
229  MoFEM::Interface &m_field, std::string field_name,
230  boost::shared_ptr<VectorDouble> u_ptr, std::string block_name, Sev sev
231 
232  ) {
234 
235  using OP = OpFluxRhsImpl<ThermoElasticOps::ConvectionBcType<BLOCKSET>,
237 
238  auto add_op = [&](auto &&meshset_vec_ptr) {
239  for (auto m : meshset_vec_ptr) {
240  MOFEM_TAG_AND_LOG("WORLD", sev, "OpConvectionRhs") << "Add " << *m;
241  pipeline.push_back(
242  new OP(m_field, m->getMeshsetId(), field_name, u_ptr));
243  }
244  MOFEM_LOG_CHANNEL("WORLD");
245  };
246 
247  switch (BCTYPE) {
248  case BLOCKSET:
249  add_op(
250 
251  m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
252  std::regex(
253 
254  (boost::format("%s(.*)") % block_name).str()
255 
256  ))
257 
258  );
259 
260  break;
261  default:
262  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
263  "Handling of bc type not implemented");
264  break;
265  }
267  }
268 };
269 
270 template <CubitBC BCTYPE, int BASE_DIM, int FIELD_DIM, AssemblyType A,
271  IntegrationType I, typename OpBase>
272 struct AddFluxToLhsPipelineImpl<
273 
274  OpFluxLhsImpl<ThermoElasticOps::ConvectionBcType<BCTYPE>, BASE_DIM,
275  FIELD_DIM, A, I, OpBase>,
276  A, I, OpBase
277 
278  > {
279 
280  AddFluxToLhsPipelineImpl() = delete;
281 
283 
284  boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
285  MoFEM::Interface &m_field, std::string row_field_name,
286  std::string col_field_name, std::string block_name, Sev sev
287 
288  ) {
290 
291  using OP = OpFluxLhsImpl<ThermoElasticOps::ConvectionBcType<BLOCKSET>,
293 
294  auto add_op = [&](auto &&meshset_vec_ptr) {
295  for (auto m : meshset_vec_ptr) {
296  MOFEM_TAG_AND_LOG("WORLD", sev, "OpConvectionLhs") << "Add " << *m;
297  pipeline.push_back(
298  new OP(m_field, m->getMeshsetId(), row_field_name, col_field_name));
299  }
300  MOFEM_LOG_CHANNEL("WORLD");
301  };
302 
303  switch (BCTYPE) {
304  case BLOCKSET:
305  add_op(
306 
307  m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
308  std::regex(
309 
310  (boost::format("%s(.*)") % block_name).str()
311 
312  ))
313 
314  );
315 
316  break;
317  default:
318  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
319  "Handling of bc type not implemented");
320  break;
321  }
323  }
324 };
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
OpFluxRhsImpl< ThermoElasticOps::ConvectionBcType< BLOCKSET >, 1, 1, A, GAUSS, EleOp >::tPtr
boost::shared_ptr< VectorDouble > tPtr
Definition: ThermalConvection.hpp:75
MoFEM::OpBaseImpl::nbIntegrationPts
int nbIntegrationPts
number of integration points
Definition: FormsIntegrators.hpp:238
OpFluxRhsImpl< ThermoElasticOps::ConvectionBcType< BLOCKSET >, 1, 1, A, GAUSS, EleOp >::heatTransferCoefficient
double heatTransferCoefficient
Definition: ThermalConvection.hpp:73
MOFEM_LOG_SEVERITY_SYNC
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
Definition: LogManager.hpp:352
MoFEM::OpBaseImpl::locMat
MatrixDouble locMat
local entity block matrix
Definition: FormsIntegrators.hpp:249
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
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:609
AddFluxToRhsPipelineImpl< OpFluxRhsImpl< ThermoElasticOps::ConvectionBcType< 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, boost::shared_ptr< VectorDouble > u_ptr, std::string block_name, Sev sev)
Definition: ThermalConvection.hpp:226
OpFluxLhsImpl< ThermoElasticOps::ConvectionBcType< BLOCKSET >, 1, 1, A, GAUSS, EleOp >::ambientTemperature
double ambientTemperature
Definition: ThermalConvection.hpp:90
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::PETSC
@ PETSC
Definition: FormsIntegrators.hpp:105
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
MoFEM::OpFluxLhsImpl
Definition: Natural.hpp:43
I
constexpr IntegrationType I
Definition: operators_tests.cpp:31
EleOp
MoFEM::OpBaseImpl::locF
VectorDouble locF
local entity vector
Definition: FormsIntegrators.hpp:251
MoFEM::Sev
MoFEM::LogManager::SeverityLevel Sev
Definition: CoreTemplates.hpp:17
MoFEM::OpBaseImpl
Definition: FormsIntegrators.hpp:178
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
MoFEM::getFTensor0FromVec
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Definition: Templates.hpp:135
MoFEM::GAUSS
@ GAUSS
Definition: FormsIntegrators.hpp:136
ThermoElasticOps
Definition: ThermalConvection.hpp:12
OpFluxLhsImpl< ThermoElasticOps::ConvectionBcType< BLOCKSET >, 1, 1, A, GAUSS, EleOp >::heatTransferCoefficient
double heatTransferCoefficient
Definition: ThermalConvection.hpp:89
EntData
EntitiesFieldData::EntData EntData
Definition: child_and_parent.cpp:37
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
ThermoElasticOps::GetConvectionParameters< BLOCKSET >::getParameters
static MoFEMErrorCode getParameters(double &heat_transfer_coefficient, double &ambient_temperature, boost::shared_ptr< Range > &ents, MoFEM::Interface &m_field, int ms_id, Sev sev)
Definition: ThermalConvection.hpp:21
MoFEM::IntegrationType
IntegrationType
Form integrator integration types.
Definition: FormsIntegrators.hpp:136
MoFEM::OpBaseImpl::nbRowBaseFunctions
int nbRowBaseFunctions
number or row base functions
Definition: FormsIntegrators.hpp:239
ThermoElasticOps::ConvectionBcType
Definition: ThermalConvection.hpp:14
MoFEM::OpBaseImpl::nbCols
int nbCols
number if dof on column
Definition: FormsIntegrators.hpp:237
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:236
MoFEM::AssemblyType
AssemblyType
[Storage and set boundary conditions]
Definition: FormsIntegrators.hpp:104
ThermoElasticOps::GetConvectionParameters
Definition: ThermalConvection.hpp:16
BLOCKSET
@ BLOCKSET
Definition: definitions.h:161
OpBaseImpl
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
AddFluxToLhsPipelineImpl< OpFluxLhsImpl< ThermoElasticOps::ConvectionBcType< 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 row_field_name, std::string col_field_name, std::string block_name, Sev sev)
Definition: ThermalConvection.hpp:282
OpFluxRhsImpl< ThermoElasticOps::ConvectionBcType< BLOCKSET >, 1, 1, A, GAUSS, EleOp >::ambientTemperature
double ambientTemperature
Definition: ThermalConvection.hpp:74
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:429
MOFEM_NOT_IMPLEMENTED
@ MOFEM_NOT_IMPLEMENTED
Definition: definitions.h:32
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
CubitBC
CubitBC
Types of sets and boundary conditions.
Definition: definitions.h:157