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_conditions_on_free_surface_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: Josep Maria Carbonell, Massimiliano Zecchetto
10 // Collaborators:
11 //
12 //-------------------------------------------------------------
13 //
14 
15 #if !defined(KRATOS_UPDATE_CONDITIONS_ON_FREE_SURFACE_PROCESS_H_INCLUDED)
16 #define KRATOS_UPDATE_CONDITIONS_ON_FREE_SURFACE_PROCESS_H_INCLUDED
17 
18 // External includes
19 
20 // System includes
21 
22 // Project includes
25 
26 namespace Kratos {
27 
30 
40  public:
43 
45 
49 
51  UpdateConditionsOnFreeSurfaceProcess(ModelPart& rModelPart, Parameters rParameters) : mrModelPart(rModelPart) {
52 
54 
55  // Include only validation with c++11 since raw_literals do not exist in c++03
56  Parameters default_parameters(R"(
57  {
58  "update_conditions" : true,
59  "sub_model_part_list" : [],
60  "reference_condition_list" : []
61  } )");
62 
63  // Validate against defaults
64  rParameters.ValidateAndAssignDefaults(default_parameters);
65 
66  // Each sub model part to be updated must have its reference condition type
67  if (rParameters["sub_model_part_list"].size() != rParameters["reference_condition_list"].size()) {
68  KRATOS_ERROR << " sub_model_part_list and reference_condition_list must have the same dimension " << std::endl;
69  }
70 
71  for (unsigned int i = 0; i < rParameters["sub_model_part_list"].size(); i++) {
72  mListOfSubModelParts.push_back(rParameters["sub_model_part_list"][i].GetString());
73  mListOfReferenceConditions.push_back(rParameters["reference_condition_list"][i].GetString());
74  }
75 
76  // Set echo level
77  mEchoLevel = 0;
78 
79  KRATOS_CATCH("");
80  }
81 
84 
88 
90  void operator()() { Execute(); }
91 
95 
97  void Execute() override {
98 
100 
101  this->ClearAllConditions();
102  this->UpdateConditionsAfterRemesh();
103 
104  KRATOS_CATCH("")
105  }
106 
110 
114 
118 
122 
124 
125  private:
128 
132 
133  ModelPart& mrModelPart;
134  std::vector<std::string> mListOfSubModelParts;
135  std::vector<std::string> mListOfReferenceConditions;
136  std::size_t mEchoLevel;
137 
141 
145 
146  void UpdateConditionsAfterRemesh() const {
147 
148  KRATOS_TRY
149 
150  // Get computing model part
151  std::string computing_model_part_name;
152  for (ModelPart::SubModelPartIterator i_mp = mrModelPart.SubModelPartsBegin(); i_mp != mrModelPart.SubModelPartsEnd(); i_mp++) {
153  if ((i_mp->Is(ACTIVE) && i_mp->Is(SOLID)) || (i_mp->Is(ACTIVE) && i_mp->Is(FLUID))) {
154  computing_model_part_name = i_mp->Name();
155  }
156  }
157  ModelPart& r_computing_model_part = mrModelPart.GetSubModelPart(computing_model_part_name);
158 
159  // Starting free surface condition ID number
160  unsigned int condition_id = r_computing_model_part.NumberOfConditions();
161 
162  // Loop over free surface sub model parts
163  for (unsigned int i = 0; i < mListOfSubModelParts.size(); i++)
164  {
165  // Free surface sub model part to be updated
166  ModelPart& r_sub_model_part = mrModelPart.GetSubModelPart(mListOfSubModelParts[i]);
167 
168  // Remove nodes from sub model part
169  VariableUtils().SetFlag(TO_ERASE, true, r_sub_model_part.Nodes());
170  r_sub_model_part.RemoveNodes(TO_ERASE);
171  VariableUtils().SetFlag(TO_ERASE, false, mrModelPart.Nodes()); // this is suspicious
172 
173  // Condition type to be created
174  const Condition& r_reference_condition = KratosComponents<Condition>::Get(mListOfReferenceConditions[i]);
175 
176  // Property to be used in the creation of conditions (assuming r_sub_model_part has only one property)
177  Properties::Pointer p_property = mrModelPart.GetParentModelPart().pGetProperties(0);
178  for (auto i_prop(r_sub_model_part.PropertiesBegin()); i_prop != r_sub_model_part.PropertiesEnd(); ++i_prop) {
179  if (!i_prop->IsEmpty()) {
180  const int prop_id = i_prop->Id();
181  p_property = r_sub_model_part.GetParentModelPart().pGetProperties(prop_id);
182  }
183  }
184 
185  // For the first sub model part we need to find the boundaries and creating the "skin"
186  if ((i == 0))
187  {
188  BuiltinTimer time_elapsed;
189 
190  // Loop over all elements
191  for (auto i_elem(r_computing_model_part.ElementsBegin()); i_elem != r_computing_model_part.ElementsEnd(); ++i_elem)
192  {
193  Geometry<Node>& r_geometry = i_elem->GetGeometry();
194  DenseMatrix<unsigned int> lpofa; // connectivities of points defining faces
195  DenseVector<unsigned int> lnofa; // number of points defining faces
196  r_geometry.NodesInFaces(lpofa);
197  r_geometry.NumberNodesInFaces(lnofa);
198  ElementWeakPtrVectorType& number_of_neighbour_elements = i_elem->GetValue(NEIGHBOUR_ELEMENTS);
199 
200  // Loop over neighbour elements of an element
201  unsigned int iface = 0;
202  for (auto& i_nelem : number_of_neighbour_elements)
203  {
204  unsigned int number_of_nodes_in_face = lnofa[iface];
205 
206  if (i_nelem.Id() == i_elem->Id())
207  {
208  // Get face nodes
209  Condition::NodesArrayType face_nodes;
210  face_nodes.reserve(number_of_nodes_in_face);
211  unsigned int number_of_rigid_nodes = 0;
212  for (unsigned int j = 1; j <= number_of_nodes_in_face; ++j) {
213  face_nodes.push_back(r_geometry(lpofa(j, iface)));
214  if (face_nodes[j - 1].Is(RIGID)) {
215  number_of_rigid_nodes += 1;
216  }
217  }
218 
219  // Check if it is a free surface
220  if (number_of_rigid_nodes != number_of_nodes_in_face)
221  {
222  // Create new condition on free surface
223  Condition::Pointer p_condition = r_reference_condition.Create(condition_id++, face_nodes, p_property);
224  mrModelPart.Conditions().push_back(p_condition);
225  r_sub_model_part.Conditions().push_back(p_condition);
226 
227  // Add nodes to free surface
228  for (unsigned int j = 1; j <= number_of_nodes_in_face; ++j) {
229  bool add = true;
230  for (auto i_node(r_sub_model_part.NodesBegin()); i_node != r_sub_model_part.NodesEnd(); ++i_node)
231  if (i_node->Id() == r_geometry(lpofa(j, iface))->Id())
232  add = false;
233  if (add)
234  r_sub_model_part.Nodes().push_back(r_geometry(lpofa(j, iface)));
235  }
236  }
237  }
238  iface += 1;
239  }
240  }
241  KRATOS_INFO_IF("UpdateConditionsAfterRemeshProcess ", mEchoLevel > 0)
242  << " SubModelPart: " << mListOfSubModelParts[i] << " Rebuild time: " << time_elapsed.ElapsedSeconds() << std::endl;
243  }
244 
245  // For the other sub model parts we clone the nodes/conditions from the first sub model part
246  else
247  {
248  BuiltinTimer time_elapsed;
249 
250  // Get first free surface sub model part
251  ModelPart& r_origin_part = mrModelPart.GetSubModelPart(mListOfSubModelParts[0]);
252 
253  // Copy nodes from first free surface sub model part
254  r_sub_model_part.AddNodes(r_origin_part.NodesBegin(), r_origin_part.NodesEnd());
255 
256  // Initialize vector of new conditions
257  ModelPart::ConditionsContainerType temp_conditions;
258  temp_conditions.reserve(r_origin_part.NumberOfConditions());
259 
260  // Loop over conditions created for first free surface sub model part
261  for (auto i_cond = r_origin_part.ConditionsBegin(); i_cond != r_origin_part.ConditionsEnd(); ++i_cond)
262  {
263  // Create condition (reuse the geometry of the old element to save memory)
264  Condition::Pointer p_condition = r_reference_condition.Create(condition_id++, i_cond->pGetGeometry(), p_property);
265  temp_conditions.push_back(p_condition);
266  }
267 
268  // Add conditions
269  r_sub_model_part.AddConditions(temp_conditions.begin(), temp_conditions.end());
270  mrModelPart.AddConditions(temp_conditions.begin(), temp_conditions.end());
271 
272  KRATOS_INFO_IF("UpdateConditionsAfterRemeshProcess ", mEchoLevel > 0)
273  << " SubModelPart: " << mListOfSubModelParts[i] << " Rebuild time: " << time_elapsed.ElapsedSeconds() << std::endl;
274  }
275  }
276  KRATOS_CATCH("");
277  }
278 
279  void ClearAllConditions() const {
280  // Remove conditions only from free surface submodel parts
281  for (unsigned int i = 0; i < mListOfSubModelParts.size(); i++)
282  {
283  ModelPart& r_sub_model_part = mrModelPart.GetSubModelPart(mListOfSubModelParts[i]);
284  VariableUtils().SetFlag(TO_ERASE, true, r_sub_model_part.Conditions());
285  r_sub_model_part.RemoveConditionsFromAllLevels(TO_ERASE);
286  }
287  }
288 
292 
296 
300 
303 
305 
307  // Process(Process const& rOther);
308 
310 
311 }; // Class Process
312 
314 
317 
321 
323 inline std::istream& operator>>(std::istream& rIStream, UpdateConditionsOnFreeSurfaceProcess& rThis);
324 
326 inline std::ostream& operator<<(std::ostream& rOStream, const UpdateConditionsOnFreeSurfaceProcess& rThis) {
327  rThis.PrintInfo(rOStream);
328  rOStream << std::endl;
329  rThis.PrintData(rOStream);
330 
331  return rOStream;
332 }
334 
335 } // namespace Kratos.
336 
337 #endif // KRATOS_UPDATE_CONDITIONS_ON_FREE_SURFACE_PROCESS_H_INCLUDED defined
Geometry< NodeType >::PointsArrayType NodesArrayType
definition of nodes container type, redefined from GeometryType
Definition: condition.h:86
bool Is(Flags const &rOther) const
Definition: flags.h:274
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
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
SubModelPartsContainerType::iterator SubModelPartIterator
Iterator over the sub model parts of this model part.
Definition: model_part.h:258
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
SizeType size() const
This method returns the total size of the current array parameter.
Definition: kratos_parameters.cpp:993
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
This process updates the conditions applied to the free surface after the remeshing.
Definition: update_conditions_on_free_surface_process.hpp:39
KRATOS_CLASS_POINTER_DEFINITION(UpdateConditionsOnFreeSurfaceProcess)
virtual ~UpdateConditionsOnFreeSurfaceProcess()
Destructor.
Definition: update_conditions_on_free_surface_process.hpp:83
UpdateConditionsOnFreeSurfaceProcess(ModelPart &rModelPart, Parameters rParameters)
Default constructor.
Definition: update_conditions_on_free_surface_process.hpp:51
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: update_conditions_on_free_surface_process.hpp:90
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: update_conditions_on_free_surface_process.hpp:97
#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
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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 j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17