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.
inlet_management_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosPfemFluidDynamicsApplication $
3 // Created by: $Author: AFranci $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: October 2016 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_INLET_MANAGEMENT_PROCESS_H_INCLUDED)
11 #define KRATOS_INLET_MANAGEMENT_PROCESS_H_INCLUDED
12 
13 // External includes
14 
15 // System includes
16 
17 // Project includes
20 
21 #include "includes/model_part.h"
25 
27 // Data:
28 // Flags: (checked)
29 // (set)
30 // (modified)
31 // (reset)
32 //(set):=(set in this process)
33 
34 namespace Kratos
35 {
36 
39 
41 
46  : public MesherProcess
47  {
48  public:
51 
54 
59 
62 
66 
69  MesherUtilities::MeshingParameters &rRemeshingParameters,
70  int EchoLevel)
71  : mrModelPart(rModelPart),
72  mrRemesh(rRemeshingParameters)
73  {
74  KRATOS_INFO("InletManagementProcess") << " activated " << std::endl;
75 
76  mEchoLevel = EchoLevel;
77  }
78 
81 
85 
87  void operator()()
88  {
89  Execute();
90  }
91 
95 
97  void Execute() override
98  {
100 
101  if (mEchoLevel > 1)
102  std::cout << " [ INLET MANAGEMENT PROCESS: " << std::endl;
103 
104  if (mrModelPart.Name() != mrRemesh.SubModelPartName)
105  std::cout << " ModelPart Supplied do not corresponds to the Meshing Domain: (" << mrModelPart.Name() << " != " << mrRemesh.SubModelPartName << ")" << std::endl;
106 
107  const ProcessInfo &rCurrentProcessInfo = mrModelPart.GetProcessInfo();
108  double currentTime = rCurrentProcessInfo[TIME];
109  double timeInterval = rCurrentProcessInfo[DELTA_TIME];
110 
111  unsigned int numberOfLagrangianInletNodes = mrRemesh.Info->NumberOfLagrangianInletNodes;
112 
113  if (currentTime < 2 * timeInterval)
114  {
115  mrRemesh.Info->RemovedNodes = 0;
116  if (mEchoLevel > 1)
117  std::cout << " First meshes: I repare the mesh without adding new nodes" << std::endl;
118  mrRemesh.Info->InitialNumberOfNodes = mrRemesh.Info->NumberOfNodes;
119  }
120 
121  if (currentTime > 1.5 * timeInterval && numberOfLagrangianInletNodes > 0)
122  {
123  CheckAndCreateNewInletLayer();
124  }
125  else
126  {
127  CountInletNodes();
128  }
129 
130  if (mEchoLevel > 1)
131  std::cout << " INLET MANAGEMENT PROCESS ]; " << std::endl;
132 
133  KRATOS_CATCH(" ")
134  }
135 
139 
143 
147 
149  std::string Info() const override
150  {
151  return "InletManagementProcess";
152  }
153 
155  void PrintInfo(std::ostream &rOStream) const override
156  {
157  rOStream << "InletManagementProcess";
158  }
159 
161  void PrintData(std::ostream &rOStream) const override
162  {
163  }
164 
168 
170 
171  private:
174 
178  ModelPart &mrModelPart;
179 
181 
182  MesherUtilities mMesherUtilities;
183 
184  int mEchoLevel;
185 
189 
193 
194  void CheckAndCreateNewInletLayer()
195 
196  {
197  KRATOS_TRY
198 
199  if (mEchoLevel > 1)
200  std::cout << " CheckAndCreateNewInletLayer " << std::endl;
201  const unsigned int dimension = mrModelPart.ElementsBegin()->GetGeometry().WorkingSpaceDimension();
202  double maxSeparation = mrRemesh.Refine->CriticalRadius;
203 
204  std::vector<Node::Pointer> clonedNodes;
205  clonedNodes.clear();
206  clonedNodes.resize(1);
207  unsigned int numberClonedNodes = 0;
208  unsigned int sizeClonedNodes = 0;
209 
210  for (ModelPart::NodesContainerType::iterator i_node = mrModelPart.NodesBegin(); i_node != mrModelPart.NodesEnd(); i_node++)
211  {
212  if (i_node->Is(PFEMFlags::LAGRANGIAN_INLET))
213  {
214  ElementWeakPtrVectorType &neighb_elems = i_node->GetValue(NEIGHBOUR_ELEMENTS);
215  NodeWeakPtrVectorType &rN = i_node->GetValue(NEIGHBOUR_NODES);
216 
217  if ((neighb_elems.size() == 0 && rN.size() == 0) || i_node->Is(RIGID))
218  {
219 
220  const array_1d<double, 3> &inletDisplacement = i_node->FastGetSolutionStepValue(DISPLACEMENT);
221  double distanceFromOrigin = sqrt(inletDisplacement[0] * inletDisplacement[0] +
222  inletDisplacement[1] * inletDisplacement[1]);
223  if (dimension == 3)
224  {
225  distanceFromOrigin = sqrt(inletDisplacement[0] * inletDisplacement[0] +
226  inletDisplacement[1] * inletDisplacement[1] +
227  inletDisplacement[2] * inletDisplacement[2]);
228  }
229 
230  if (distanceFromOrigin > maxSeparation)
231  {
232 
233  if (i_node->Is(FLUID))
234  {
235  Node::Pointer pnode = i_node->Clone();
236  sizeClonedNodes = numberClonedNodes + 1;
237  clonedNodes.resize(sizeClonedNodes);
238  clonedNodes[numberClonedNodes] = pnode;
239  numberClonedNodes++;
240  }
241  // inlet nodes will be replaced at their initial position
242  i_node->X() = i_node->X0();
243  i_node->Y() = i_node->Y0();
244  i_node->FastGetSolutionStepValue(DISPLACEMENT_X, 0) = 0;
245  i_node->FastGetSolutionStepValue(DISPLACEMENT_X, 1) = 0;
246  i_node->FastGetSolutionStepValue(DISPLACEMENT_Y, 0) = 0;
247  i_node->FastGetSolutionStepValue(DISPLACEMENT_Y, 1) = 0;
248  if (dimension == 3)
249  {
250  i_node->Z() = i_node->Z0();
251  i_node->FastGetSolutionStepValue(DISPLACEMENT_Z, 0) = 0;
252  i_node->FastGetSolutionStepValue(DISPLACEMENT_Z, 1) = 0;
253  }
254 
255  }
256  }
257  }
258  }
259 
260  for (unsigned int i = 0; i < sizeClonedNodes; i++)
261  {
262 
263  Node::Pointer pnode = clonedNodes[i];
264  double NodeIdParent = MesherUtilities::GetMaxNodeId(mrModelPart.GetParentModelPart());
265  double NodeId = MesherUtilities::GetMaxNodeId(mrModelPart);
266  unsigned int id = NodeIdParent + 1; // total model part node size
267 
268  if (NodeId > NodeIdParent)
269  {
270  id = NodeId + 1;
271  }
272  pnode->SetId(id);
273  pnode->Free(VELOCITY_X);
274  pnode->Free(VELOCITY_Y);
275  if (dimension == 3)
276  {
277  pnode->Free(VELOCITY_Z);
278  }
279  pnode->Reset(PFEMFlags::LAGRANGIAN_INLET);
280  pnode->Reset(INLET);
281  pnode->Reset(RIGID);
282  pnode->Reset(BOUNDARY);
283  mrRemesh.NodalPreIds.push_back(pnode->Id());
284  mrModelPart.AddNode(pnode);
285  }
286 
287  KRATOS_CATCH("")
288  }
289 
290  void CountInletNodes()
291 
292  {
293  KRATOS_TRY
294 
295  unsigned int eulerianInletNodes = 0;
296  unsigned int lagrangianInletNodes = 0;
297  const unsigned int dimension = mrModelPart.ElementsBegin()->GetGeometry().WorkingSpaceDimension();
298  const double tolerance = -1e-12;
299 
300  for (ModelPart::NodesContainerType::iterator i_node = mrModelPart.NodesBegin(); i_node != mrModelPart.NodesEnd(); i_node++)
301  {
302  if (i_node->Is(PFEMFlags::EULERIAN_INLET))
303  {
304  const array_1d<double, 3> &inletVelocity = i_node->FastGetSolutionStepValue(VELOCITY);
305  const array_1d<double, 3> &inletNormal = i_node->FastGetSolutionStepValue(NORMAL);
306  const double inwardX = inletVelocity[0] * inletNormal[0];
307  const double inwardY = inletVelocity[1] * inletNormal[1];
308  if (dimension == 2)
309  {
310  if (inwardX < tolerance || inwardY < tolerance)
311  {
312  eulerianInletNodes += 1;
313  }
314  }
315  else if (dimension == 3)
316  {
317  const double inwardZ = inletVelocity[2] * inletNormal[2];
318  if (inwardX < tolerance || inwardY < tolerance || inwardZ < tolerance)
319  {
320  eulerianInletNodes += 1;
321  }
322  }
323  }
324  else if (i_node->Is(PFEMFlags::LAGRANGIAN_INLET))
325  {
326  lagrangianInletNodes += 1;
327  }
328  }
329  mrRemesh.Info->NumberOfEulerianInletNodes = eulerianInletNodes;
330  mrRemesh.Info->NumberOfLagrangianInletNodes = lagrangianInletNodes;
331 
332  KRATOS_CATCH("")
333  }
334 
338 
342 
346 
349  operator=(InletManagementProcess const &rOther);
350 
352 
354  // Process(Process const& rOther);
355 
357 
358  }; // Class Process
359 
361 
364 
368 
370  inline std::istream &operator>>(std::istream &rIStream,
371  InletManagementProcess &rThis);
372 
374  inline std::ostream &operator<<(std::ostream &rOStream,
375  const InletManagementProcess &rThis)
376  {
377  rThis.PrintInfo(rOStream);
378  rOStream << std::endl;
379  rThis.PrintData(rOStream);
380 
381  return rOStream;
382  }
384 
385 } // namespace Kratos.
386 
387 #endif // KRATOS_INLET_MANAGEMENT_PROCESS_H_INCLUDED defined
Base class for all Conditions.
Definition: condition.h:59
Geometry base class.
Definition: geometry.h:71
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
size_type size() const
Definition: global_pointers_vector.h:307
Refine Mesh Elements Process 2D and 3D.
Definition: inlet_management_process.hpp:47
ConditionType::GeometryType GeometryType
Definition: inlet_management_process.hpp:58
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: inlet_management_process.hpp:97
InletManagementProcess(ModelPart &rModelPart, MesherUtilities::MeshingParameters &rRemeshingParameters, int EchoLevel)
Default constructor.
Definition: inlet_management_process.hpp:68
virtual ~InletManagementProcess()
Destructor.
Definition: inlet_management_process.hpp:80
void PrintData(std::ostream &rOStream) const override
Print object's data.s.
Definition: inlet_management_process.hpp:161
GlobalPointersVector< Element > ElementWeakPtrVectorType
Definition: inlet_management_process.hpp:61
std::string Info() const override
Turn back information as a string.
Definition: inlet_management_process.hpp:149
ModelPart::ConditionType ConditionType
Definition: inlet_management_process.hpp:56
ModelPart::NodeType NodeType
Definition: inlet_management_process.hpp:55
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: inlet_management_process.hpp:155
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: inlet_management_process.hpp:87
GlobalPointersVector< Node > NodeWeakPtrVectorType
Definition: inlet_management_process.hpp:60
KRATOS_CLASS_POINTER_DEFINITION(InletManagementProcess)
Pointer definition of Process.
ModelPart::PropertiesType PropertiesType
Definition: inlet_management_process.hpp:57
The base class for processes passed to the solution scheme.
Definition: mesher_process.hpp:37
Short class definition.
Definition: mesher_utilities.hpp:49
static unsigned int GetMaxNodeId(ModelPart &rModelPart)
Definition: mesher_utilities.hpp:1408
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
std::string & Name()
Definition: model_part.h:1811
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
This class defines the node.
Definition: node.h:65
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO(label)
Definition: logger.h:250
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
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 dimension
Definition: isotropic_damage_automatic_differentiation.py:123
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31
Definition: mesher_utilities.hpp:631
MeshingInfoParameters::Pointer Info
Definition: mesher_utilities.hpp:681
RefiningParameters::Pointer Refine
Definition: mesher_utilities.hpp:684
std::string SubModelPartName
Definition: mesher_utilities.hpp:642
std::vector< int > NodalPreIds
Definition: mesher_utilities.hpp:668