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.
embedded_nodes_initialization_process.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Ruben Zorrilla
11 //
12 //
13 
14 #ifndef KRATOS_EMBEDDED_NODES_INITIALIZATION_PROCESS_H
15 #define KRATOS_EMBEDDED_NODES_INITIALIZATION_PROCESS_H
16 
17 // System includes
18 #include <string>
19 #include <iostream>
20 
21 // External includes
22 
23 // Project includes
24 #include "includes/define.h"
25 #include "processes/process.h"
26 #include "includes/model_part.h"
27 #include "includes/cfd_variables.h"
28 
29 // Application includes
30 
31 
32 namespace Kratos
33 {
36 
39 
43 
47 
51 
55 
59 {
60 public:
63 
66 
67  typedef Node NodeType;
68  typedef NodeType::Pointer NodePointerType;
70 
74 
76  EmbeddedNodesInitializationProcess(ModelPart& rModelPart, unsigned int MaxIterations = 10) : mrModelPart(rModelPart)
77  {
78  mMaxIterations = MaxIterations;
79  }
80 
83 
87 
91 
95 
97  {
98  const unsigned int BufferSize = mrModelPart.GetBufferSize();
101 
102  // Simple check
103  if( mrModelPart.NodesBegin()->SolutionStepsDataHas( DISTANCE ) == false )
104  KRATOS_ERROR << "Nodes do not have DISTANCE variable!";
105  if( mrModelPart.NodesBegin()->SolutionStepsDataHas( PRESSURE ) == false )
106  KRATOS_ERROR << "Nodes do not have PRESSURE variable!";
107  if( mrModelPart.NodesBegin()->SolutionStepsDataHas( VELOCITY ) == false )
108  KRATOS_ERROR << "Nodes do not have VELOCITY variable!";
109 
110  // Mark the nodes that have switched from structure to fluid during the last step
111  #pragma omp parallel for
112  for (int k = 0; k < static_cast<int>(rNodes.size()); ++k)
113  {
114  ModelPart::NodesContainerType::iterator itNode = rNodes.begin() + k;
115  const double& d = itNode->FastGetSolutionStepValue(DISTANCE); // Current step distance value
116  const double& dn = itNode->FastGetSolutionStepValue(DISTANCE,1); // Previous step distance value
117 
118  if ((d>0) && (dn<=0))
119  itNode->Set(SELECTED, true);
120  }
121 
122  for (unsigned int it=0; it<mMaxIterations; ++it)
123  {
124  // Loop along the elements to find which ones have a unique selected node
125  for (int k = 0; k < static_cast<int>(rElements.size()); ++k)
126  {
127  unsigned int NewNodes = 0;
128  ModelPart::ElementsContainerType::iterator itElement = rElements.begin() + k;
129  const GeometryType& rGeometry = itElement->GetGeometry();
130  const unsigned int ElemNumNodes = rGeometry.PointsNumber();
131 
132  // Get the number of nodes that have switched from structure to fluid in the current element
133  for (unsigned int j=0; j<ElemNumNodes; ++j)
134  {
135  if (rGeometry[j].Is(SELECTED))
136  NewNodes++;
137  }
138 
139  // If there is only one unique "new" node in the element, initialize it.
140  // Otherwise it remains to be initialized in a further iteration.
141  if (NewNodes == 1)
142  {
143  NodeType::Pointer pNode;
144  double p_avg = 0.0;
145  array_1d<double, 3> v_avg = ZeroVector(3);
146 
147  for (unsigned int j=0; j<ElemNumNodes; ++j)
148  {
149  if (rGeometry[j].IsNot(SELECTED))
150  {
151  // Compute the average velocity in the non selected nodes
152  p_avg += rGeometry[j].FastGetSolutionStepValue(PRESSURE);
153  v_avg += rGeometry[j].FastGetSolutionStepValue(VELOCITY);
154  }
155  else
156  {
157  // Get a pointer to the unique SELECTED node
158  pNode = rGeometry(j);
159  }
160  }
161 
162  // Compute the non-SELECTED nodes average values
163  p_avg /= (ElemNumNodes-1);
164  v_avg /= (ElemNumNodes-1);
165 
166  // Historical values initialization
167  pNode->Set(SELECTED, false); // Once a node has been initialized it is marked as non SELECTED
168  for (unsigned int step=0; step<BufferSize; ++step) // Fill the velocity and pressure buffer
169  {
170  pNode->FastGetSolutionStepValue(PRESSURE, step) = p_avg;
171  pNode->FastGetSolutionStepValue(VELOCITY, step) = v_avg;
172  }
173  }
174  }
175  }
176 
177  // If there still exist some remaining nodes, initialize their values to zero
178  #pragma omp parallel for
179  for (int k = 0; k < static_cast<int>(rNodes.size()); ++k)
180  {
181  ModelPart::NodesContainerType::iterator itNode = rNodes.begin() + k;
182 
183  if (itNode->Is(SELECTED))
184  {
185  itNode->Set(SELECTED, false); // Once a node has been initialized it is marked as non SELECTED
186  for (unsigned int step=0; step<BufferSize; ++step) // Fill the velocity and pressure buffer
187  {
188  itNode->FastGetSolutionStepValue(PRESSURE, step) = 0.0;
189  itNode->FastGetSolutionStepValue(VELOCITY, step) = ZeroVector(3);
190  }
191  }
192  }
193  }
194 
198 
202 
204  std::string Info() const override
205  {
206  std::stringstream buffer;
207  buffer << "EmbeddedNodesInitializationProcess" ;
208  return buffer.str();
209  }
210 
212  void PrintInfo(std::ostream& rOStream) const override {rOStream << "EmbeddedNodesInitializationProcess";}
213 
215  void PrintData(std::ostream& rOStream) const override {}
216 
217 
221 
222 
224 
225 protected:
228 
232 
234  unsigned int mMaxIterations;
235 
239 
240 
244 
245 
249 
250 
254 
255 
257 
258 private:
261 
262 
266 
267 
271 
272 
276 
277 
281 
282 
286 
287 
291 
294 
297 
300 
301 
303 
304 }; // Class EmbeddedNodesInitializationProcess
305 
309 
313 
315 
317 
318 }; // namespace Kratos.
319 
320 #endif // KRATOS_EMBEDDED_NODES_INITIALIZATION_PROCESS_H
Definition: embedded_nodes_initialization_process.h:59
EmbeddedNodesInitializationProcess(ModelPart &rModelPart, unsigned int MaxIterations=10)
Constructor.
Definition: embedded_nodes_initialization_process.h:76
Node NodeType
Definition: embedded_nodes_initialization_process.h:67
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: embedded_nodes_initialization_process.h:212
KRATOS_CLASS_POINTER_DEFINITION(EmbeddedNodesInitializationProcess)
Pointer definition of EmbeddedNodesInitializationProcess.
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: embedded_nodes_initialization_process.h:215
Geometry< NodeType > GeometryType
Definition: embedded_nodes_initialization_process.h:69
~EmbeddedNodesInitializationProcess() override
Destructor.
Definition: embedded_nodes_initialization_process.h:82
unsigned int mMaxIterations
Definition: embedded_nodes_initialization_process.h:234
ModelPart & mrModelPart
Definition: embedded_nodes_initialization_process.h:233
std::string Info() const override
Turn back information as a string.
Definition: embedded_nodes_initialization_process.h:204
void ExecuteInitializeSolutionStep() override
This function will be executed at every time step BEFORE performing the solve phase.
Definition: embedded_nodes_initialization_process.h:96
NodeType::Pointer NodePointerType
Definition: embedded_nodes_initialization_process.h:68
bool Is(Flags const &rOther) const
Definition: flags.h:274
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
IndexType GetBufferSize() const
This method gets the suffer size of the model part database.
Definition: model_part.h:1876
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
The base class for all processes in Kratos.
Definition: process.h:49
BOOST_UBLAS_INLINE const_iterator begin() const
Definition: array_1d.h:606
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
int step
Definition: face_heat.py:88
int d
Definition: ode_solve.py:397
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648