KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
update_thermal_model_part_process.hpp
Go to the documentation of this file.
1 //-------------------------------------------------------------
2 // ___ __ ___ _ _ _
3 // KRATOS| _ \/ _|___ _ __ | __| |_ _(_)__| |
4 // | _/ _/ -_) ' \| _|| | || | / _` |
5 // |_| |_| \___|_|_|_|_| |_|\_,_|_\__,_|DYNAMICS
6 //
7 // BSD License: PfemFluidDynamicsApplication/license.txt
8 //
9 // Main authors: Massimiliano Zecchetto
10 // Collaborators:
11 //
12 //-------------------------------------------------------------
13 //
14 
15 #if !defined(UPDATE_THERMAL_MODEL_PART_PROCESS)
16 #define UPDATE_THERMAL_MODEL_PART_PROCESS
17 
18 #include <algorithm>
19 #include <iostream>
20 #include <string>
21 #include "includes/define.h"
22 #include "includes/model_part.h"
23 #include "processes/process.h"
25 
26 namespace Kratos {
27 
38  public:
39  typedef Element BaseType;
40 
42 
44  UpdateThermalModelPartProcess(ModelPart& origin_model_part, ModelPart& destination_model_part,
45  ModelPart& computing_model_part, unsigned int DomainSize)
46  : rOriginModelPart(origin_model_part),
47  rDestinationModelPart(destination_model_part),
49  rDomainSize = DomainSize;
50  if (rDomainSize == 2) {
51  ReferenceElement = "EulerianConvDiff2D";
52  } else {
53  ReferenceElement = "EulerianConvDiff3D";
54  }
55  }
56 
59 
60  void operator()() { Execute(); }
61 
62  void Execute() override {
63  KRATOS_TRY;
64 
65  this->ResetDestinationModelPart();
66  this->CopyNodes();
67  this->DuplicateElements();
68  this->BuildThermalComputingDomain();
69  this->UpdateConditions();
70 
71  // It was verified that the residue of the thermal problem has large terms associated to DOFs
72  // of flux BC in free surface problems, when the node is not connected to fluid.
73  // If these DOFs are not considered in the residue, which is done by fixing them, the remaining terms satisfy the tolerance.
74  // This next function is to fix the flux DOFs that are not connected to fluid,
75  // to avoid the unessesary iteration in nonlinear thermal analysis, but it is also changing the results.
76  // this->FixDOFs();
77 
78  KRATOS_CATCH("");
79  }
80 
81  void ExecuteInitialize() override {}
82 
83  void ExecuteInitializeSolutionStep() override {}
84 
85  protected:
89  std::string ReferenceElement;
90  unsigned int rDomainSize;
91 
92  private:
93  void ResetDestinationModelPart() const {
95  VariableUtils().SetFlag(TO_ERASE, true, rDestinationModelPart.Nodes());
99  VariableUtils().SetFlag(TO_ERASE, false, rOriginModelPart.Nodes());
100  }
101 
102  void CopyNodes() const {
103  // Copy nodes to the rDestinationModelPart
105 
106  // Copy nodes to the rDestinationModelPart's sub model parts
107  for (auto i_part = rOriginModelPart.SubModelPartsBegin(); i_part != rOriginModelPart.SubModelPartsEnd(); ++i_part) {
108  if (!rDestinationModelPart.HasSubModelPart(i_part->Name())) {
110  }
111  ModelPart& destination_part = rDestinationModelPart.GetSubModelPart(i_part->Name());
112  destination_part.AddNodes(i_part->NodesBegin(), i_part->NodesEnd());
113  }
114  }
115 
116  void DuplicateElements() const {
117  const Element& mReferenceElement = KratosComponents<Element>::Get(ReferenceElement);
119  i_mp != rOriginModelPart.SubModelPartsEnd(); i_mp++) {
120  if (i_mp->NumberOfElements()) {
121  ModelPart& destination_part = rDestinationModelPart.GetSubModelPart(i_mp->Name());
122  ModelPart::ElementsContainerType temp_elements;
123  temp_elements.reserve(i_mp->NumberOfElements());
124 
125  // Skip the ComputingModelPart of the PfemFluidModelPart
126  if ((i_mp->Is(SOLID) && i_mp->IsNot(ACTIVE)) || (i_mp->Is(FLUID) && i_mp->IsNot(ACTIVE)) ||
127  (i_mp->Is(BOUNDARY) && i_mp->Is(RIGID))) {
128  for (auto it_elem = i_mp->ElementsBegin(); it_elem != i_mp->ElementsEnd(); ++it_elem) {
129  Properties::Pointer properties = it_elem->pGetProperties();
130 
131  Element::Pointer p_element =
132  mReferenceElement.Create(it_elem->Id(), it_elem->GetGeometry(), properties);
133  temp_elements.push_back(p_element);
134  }
135  rDestinationModelPart.AddElements(temp_elements.begin(), temp_elements.end());
136  destination_part.AddElements(temp_elements.begin(), temp_elements.end());
137  }
138  }
139  }
140  }
141 
142  void BuildThermalComputingDomain() const {
143  // Copy nodes
145 
146  // Copy elements
147  std::vector<ModelPart::IndexType> ids;
148  ids.reserve(rDestinationModelPart.Elements().size());
149  const auto& it_elem_begin = rDestinationModelPart.ElementsBegin();
150 
151  #pragma omp parallel for
152  for (int i = 0; i < static_cast<int>(rDestinationModelPart.Elements().size()); i++) {
153  auto it_elem = it_elem_begin + i;
154  #pragma omp critical
155  { ids.push_back(it_elem->Id()); }
156  }
157 
159  }
160 
161  void UpdateConditions() const
162  {
163  // Remove conditions from thermal submodel parts
165  if (i_mp->NumberOfConditions() && rDestinationModelPart.HasSubModelPart(i_mp->Name())) {
166  ModelPart& destination_part = rDestinationModelPart.GetSubModelPart(i_mp->Name());
167  VariableUtils().SetFlag(TO_ERASE, true, destination_part.Conditions());
168  destination_part.RemoveConditionsFromAllLevels(TO_ERASE);
169  }
170  }
171  unsigned int condition_id = 0;
172 
173  // Re-create conditions based on updated conditions of fluid model part (free surface or not)
175  {
176  if (i_mp->NumberOfConditions() && rDestinationModelPart.HasSubModelPart(i_mp->Name())) {
177  ModelPart& destination_part = rDestinationModelPart.GetSubModelPart(i_mp->Name());
178 
179  // Loop over each condition of fluid submodel part
180  for (auto i_cond(i_mp->ConditionsBegin()); i_cond != i_mp->ConditionsEnd(); ++i_cond)
181  {
182  // Get condition nodes
183  Geometry<Node>& r_geometry = i_cond->GetGeometry();
184  Condition::NodesArrayType cond_nodes;
185  cond_nodes.reserve(r_geometry.size());
186  for (unsigned int i = 0; i < r_geometry.size(); i++)
187  cond_nodes.push_back(r_geometry(i));
188 
189  // Property to be used in the creation of condition
190  Properties::Pointer p_property = i_cond->pGetProperties();
191 
192  // Condition type according to domain size
193  std::string condition_type;
194  if (rDomainSize == 2) condition_type = "ThermalFace2D2N";
195  else if (rDomainSize == 3) condition_type = "ThermalFace3D3N";
196  const Condition& r_reference_condition = KratosComponents<Condition>::Get(condition_type);
197 
198  // Create and store thermal face condition
199  Condition::Pointer p_condition = r_reference_condition.Create(++condition_id, cond_nodes, p_property);
200  destination_part.Conditions().push_back(p_condition);
201  rDestinationModelPart.Conditions().push_back(p_condition);
202  rComputingModelPart.Conditions().push_back(p_condition);
203  }
204  }
205  }
206  }
207 
208  void FixDOFs() const {
209  // Loop over all conditions (currently, only flux on walls or free surface)
210  for (auto i_cond(rComputingModelPart.ConditionsBegin()); i_cond != rComputingModelPart.ConditionsEnd(); ++i_cond)
211  {
212  // Loop over each condition node
213  Geometry<Node>& cond_geometry = i_cond->GetGeometry();
214  for (unsigned int i = 0; i < cond_geometry.size(); i++)
215  {
216  // Loop over neighbour elements
217  bool fix = true;
218  ElementWeakPtrVectorType& neighbour_elements = cond_geometry(i)->GetValue(NEIGHBOUR_ELEMENTS);
219  for (unsigned int j = 0; j < neighbour_elements.size(); j++)
220  {
221  // Check if neighbour element is fluid
222  GeometryType neighbour_elements_geom = neighbour_elements(j)->GetGeometry();
223  if (neighbour_elements_geom.size() != 2) {
224  fix = false;
225  break;
226  }
227  }
228  // Fix DOF if it is not connected to fluid elements
229  if (fix) {
230  const Node::DofType::Pointer dof = cond_geometry(i)->pGetDof(TEMPERATURE);
231  if (!dof->IsFixed())
232  dof->FixDof();
233  }
234  }
235  }
236  }
237 
238 }; // Class UpdateThermalModelPartProcess
239 
241 inline std::istream& operator>>(std::istream& rIStream, UpdateThermalModelPartProcess& rThis);
242 
244 inline std::ostream& operator<<(std::ostream& rOStream, const UpdateThermalModelPartProcess& rThis) {
245  rThis.PrintInfo(rOStream);
246  rOStream << std::endl;
247  rThis.PrintData(rOStream);
248 
249  return rOStream;
250 }
251 
252 } // namespace Kratos.
253 
254 #endif /* UPDATE_THERMAL_MODEL_PART_PROCESS defined */
Geometry< NodeType >::PointsArrayType NodesArrayType
definition of nodes container type, redefined from GeometryType
Definition: condition.h:86
Dof * Pointer
Pointer definition of Dof.
Definition: dof.h:93
Base class for all Elements.
Definition: element.h:60
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
void RemoveElementsFromAllLevels(Flags IdentifierFlag=TO_ERASE)
Definition: model_part.cpp:1163
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
SubModelPartIterator SubModelPartsEnd()
Definition: model_part.h:1708
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
SubModelPartIterator SubModelPartsBegin()
Definition: model_part.h:1698
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
void RemoveNodesFromAllLevels(Flags IdentifierFlag=TO_ERASE)
Definition: model_part.cpp:504
bool HasSubModelPart(std::string const &ThisSubModelPartName) const
Definition: model_part.cpp:2142
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
SubModelPartsContainerType::iterator SubModelPartIterator
Iterator over the sub model parts of this model part.
Definition: model_part.h:258
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
void RemoveConditionsFromAllLevels(Flags IdentifierFlag=TO_ERASE)
Definition: model_part.cpp:1673
GeometryType & GetGeometry(IndexType GeometryId)
Returns a reference geometry corresponding to the id.
Definition: model_part.h:1584
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
ModelPart & CreateSubModelPart(std::string const &NewSubModelPartName)
Definition: model_part.cpp:2000
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
void AddElements(std::vector< IndexType > const &ElementIds, IndexType ThisIndex=0)
Definition: model_part.cpp:941
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
void AddNodes(std::vector< IndexType > const &NodeIds, IndexType ThisIndex=0)
Definition: model_part.cpp:235
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
void reserve(size_type dim)
Definition: pointer_vector.h:319
void reserve(int reservedsize)
Reserves memory for a specified number of elements.
Definition: pointer_vector_set.h:733
The base class for all processes in Kratos.
Definition: process.h:49
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: process.h:204
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: process.h:210
Definition: update_thermal_model_part_process.hpp:37
std::string ReferenceElement
Definition: update_thermal_model_part_process.hpp:89
KRATOS_CLASS_POINTER_DEFINITION(UpdateThermalModelPartProcess)
UpdateThermalModelPartProcess(ModelPart &origin_model_part, ModelPart &destination_model_part, ModelPart &computing_model_part, unsigned int DomainSize)
Constructor.
Definition: update_thermal_model_part_process.hpp:44
ModelPart & rDestinationModelPart
Definition: update_thermal_model_part_process.hpp:87
void ExecuteInitializeSolutionStep() override
This function will be executed at every time step BEFORE performing the solve phase.
Definition: update_thermal_model_part_process.hpp:83
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: update_thermal_model_part_process.hpp:62
void ExecuteInitialize() override
This function is designed for being called at the beginning of the computations right after reading t...
Definition: update_thermal_model_part_process.hpp:81
void operator()()
Definition: update_thermal_model_part_process.hpp:60
unsigned int rDomainSize
Definition: update_thermal_model_part_process.hpp:90
~UpdateThermalModelPartProcess() override
Destructor.
Definition: update_thermal_model_part_process.hpp:58
ModelPart & rComputingModelPart
Definition: update_thermal_model_part_process.hpp:88
ModelPart & rOriginModelPart
Definition: update_thermal_model_part_process.hpp:86
Element BaseType
Definition: update_thermal_model_part_process.hpp:39
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void SetFlag(const Flags &rFlag, const bool FlagValue, TContainerType &rContainer)
Sets a flag according to a given status over a given container.
Definition: variable_utils.h:900
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
GlobalPointersVector< Element > ElementWeakPtrVectorType
Definition: build_model_part_boundary_process.hpp:60
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Geometry< Node > GeometryType
The definition of the geometry.
Definition: mortar_classes.h:37
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int dof
Definition: ode_solve.py:393
int j
Definition: quadrature.py:648
computing_model_part
processes settings end ####
Definition: script.py:170
integer i
Definition: TensorModule.f:17