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.
calculate_embedded_signed_distance_to_3d_skin_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: Pooyan Dadvand
11 // Ruben Zorrilla
12 // Daniel Baumgaertner
13 // Johannes Wolf
14 //
15 
16 #if !defined(KRATOS_CALCULATE_EMBEDDED_SIGNED_DISTANCE_TO_3D_SKIN_PROCESS_H_INCLUDED )
17 #define KRATOS_CALCULATE_EMBEDDED_SIGNED_DISTANCE_TO_3D_SKIN_PROCESS_H_INCLUDED
18 
19 
20 // System includes
21 #include <string>
22 #include <iostream>
23 #include <algorithm>
24 
25 // External includes
26 #include "includes/kratos_flags.h"
27 
28 // Project includes
29 #include "includes/define.h"
30 #include "processes/process.h"
31 #include "includes/kratos_flags.h"
32 #include "includes/element.h"
33 #include "includes/model_part.h"
35 #include "utilities/openmp_utils.h"
36 
37 namespace Kratos {
38 
41 
45 
49 
53 
57 
60 {
61 public:
62 
65 
70 
74 
75  CalculateEmbeddedSignedDistanceTo3DSkinProcess(ModelPart& rThisModelPartStruc, ModelPart& rThisModelPartFluid, bool DiscontinuousDistance = false)
76  : mrSkinModelPart(rThisModelPartStruc), mrFluidModelPart(rThisModelPartFluid), mDiscontinuousDistance(DiscontinuousDistance)
77  {
78  }
79 
82  {
83  }
84 
88 
89  void operator()()
90  {
91  Execute();
92  }
93 
97 
98  void Execute() override
99  {
100  // Create a pointer to the discontinuous or continuos distance calculation process
102  if(mDiscontinuousDistance)
103  {
105  new CalculateDiscontinuousDistanceToSkinProcess<3>(mrFluidModelPart, mrSkinModelPart));
106  }
107  else
108  {
110  new CalculateDistanceToSkinProcess<3>(mrFluidModelPart, mrSkinModelPart));
111  }
112 
113  // Call the distance calculator methods
114  pdistance_calculator->Initialize();
115  pdistance_calculator->FindIntersections();
116  pdistance_calculator->CalculateDistances(pdistance_calculator->GetIntersections());
117 
118  // TODO: Raycasting
119 
120  // Distance positive and negative peak values correction
121  this->PeakValuesCorrection(); //TODO: Check the correct behaviour of this method once the raycasting has been implemented
122 
123  // Compute the embedded velocity
124  this->CalculateEmbeddedVelocity(pdistance_calculator->GetIntersections());
125 
126  // Call the distance calculation Clear() to delete the intersection data
127  pdistance_calculator->Clear();
128  }
129 
130  void Clear() override
131  {
132  }
133 
137 
141 
145 
147  std::string Info() const override
148  {
149  return "CalculateEmbeddedSignedDistanceTo3DSkinProcess";
150  }
151 
153  void PrintInfo(std::ostream& rOStream) const override
154  {
155  rOStream << "CalculateEmbeddedSignedDistanceTo3DSkinProcess";
156  }
157 
159  void PrintData(std::ostream& rOStream) const override
160  {
161  }
162 
166 
168 
169  protected:
170 
173 
177 
181 
185 
186  void CalculateEmbeddedVelocity(std::vector<PointerVector<GeometricalObject>>& rIntersectedObjects)
187  {
188  const array_1d<double, 3> aux_zero = ZeroVector(3);
189 
190  // #pragma omp parallel for firstprivate(aux_zero)
191  for (int k = 0; k < static_cast<int>(mrFluidModelPart.NumberOfElements()); ++k)
192  {
193  ModelPart::ElementsContainerType::iterator itFluidElement = mrFluidModelPart.ElementsBegin() + k;
194  const PointerVector<GeometricalObject>& intersected_skin_elems = rIntersectedObjects[k];
195 
196  // Initialize the element EMBEDDED_VELOCITY
197  itFluidElement->SetValue(EMBEDDED_VELOCITY, aux_zero);
198 
199  // Accumulate the VELOCITY from all the structure conditions that intersect the element
200  unsigned int intersection_counter = 0;
201 
202  for(auto itSkinElement : intersected_skin_elems)
203  {
204  array_1d<double,3> emb_vel = (itSkinElement.GetGeometry()[0]).GetSolutionStepValue(VELOCITY);
205  emb_vel += (itSkinElement.GetGeometry()[1]).GetSolutionStepValue(VELOCITY);
206  emb_vel += (itSkinElement.GetGeometry()[2]).GetSolutionStepValue(VELOCITY);
207 
208  itFluidElement->GetValue(EMBEDDED_VELOCITY) += emb_vel/3;
209  intersection_counter++;
210  }
211 
212  // Set the EMBEDDED_VELOCITY as the average of the accumulated values
213  if (intersection_counter!=0)
214  {
215  itFluidElement->GetValue(EMBEDDED_VELOCITY) /= intersection_counter;
216  }
217  }
218  }
219 
221  {
222  // Obtain the maximum and minimum distance values to be set
223  double max_distance, min_distance;
224  this->SetMaximumAndMinimumDistanceValues(max_distance, min_distance);
225 
226  // Bound the distance value in the non splitted nodes
227  block_for_each(mrFluidModelPart.Nodes(), [&](Node& rNode){
228  if(rNode.IsNot(TO_SPLIT))
229  {
230  double& rnode_distance = rNode.FastGetSolutionStepValue(DISTANCE);
231  rnode_distance = (rnode_distance > 0.0) ? max_distance : min_distance;
232  }
233  });
234  }
235 
236  void SetMaximumAndMinimumDistanceValues(double& max_distance, double& min_distance)
237  {
238  // Flag the nodes belonging to the splitted elements
239  for (int k = 0; k < static_cast<int>(mrFluidModelPart.NumberOfElements()); ++k)
240  {
241  ModelPart::ElementsContainerType::iterator itFluidElement = mrFluidModelPart.ElementsBegin() + k;
242 
243  if(itFluidElement->Is(TO_SPLIT))
244  {
245  Geometry<Node>& rGeom = itFluidElement->GetGeometry();
246  for (unsigned int i=0; i<rGeom.size(); ++i)
247  {
248  rGeom[i].Set(TO_SPLIT, true);
249  }
250  }
251  }
252 
253  // Obtain the maximum and minimum nodal distance values of the nodes flagged as TO_SPLIT
254  const unsigned int num_threads = ParallelUtilities::GetNumThreads();
255  OpenMPUtils::PartitionVector nodes_partition;
256  OpenMPUtils::DivideInPartitions(mrFluidModelPart.NumberOfNodes(), num_threads, nodes_partition);
257 
258  std::vector<double> max_distance_vect(num_threads, 1.0);
259  std::vector<double> min_distance_vect(num_threads, 1.0);
260 
261  #pragma omp parallel shared(max_distance_vect, min_distance_vect)
262  {
263  const int k = OpenMPUtils::ThisThread();
264  ModelPart::NodeIterator nodes_begin = mrFluidModelPart.NodesBegin() + nodes_partition[k];
265  ModelPart::NodeIterator nodes_end = mrFluidModelPart.NodesBegin() + nodes_partition[k+1];
266 
267  double max_local_distance = 1.0;
268  double min_local_distance = 1.0;
269 
270  for( ModelPart::NodeIterator itFluidNode = nodes_begin; itFluidNode != nodes_end; ++itFluidNode)
271  {
272  if(itFluidNode->Is(TO_SPLIT))
273  {
274  const double node_distance = itFluidNode->FastGetSolutionStepValue(DISTANCE);
275  max_local_distance = (node_distance>max_local_distance) ? node_distance : max_local_distance;
276  min_local_distance = (node_distance<min_local_distance) ? node_distance : min_local_distance;
277  }
278  }
279 
280  max_distance_vect[k] = max_local_distance;
281  min_distance_vect[k] = min_local_distance;
282  }
283 
284  // Reduce to maximum and minimum the thread results
285  // Note that MSVC14 does not support max reductions, which are part of OpenMP 3.1
286  max_distance = max_distance_vect[0];
287  min_distance = min_distance_vect[0];
288  for (unsigned int k = 1; k < num_threads; k++)
289  {
290  max_distance = (max_distance > max_distance_vect[k]) ? max_distance : max_distance_vect[k];
291  min_distance = (min_distance < min_distance_vect[k]) ? min_distance : min_distance_vect[k];
292  }
293  }
294 
298 
302 
306 
308 
309  private:
310 
313 
317  ModelPart& mrSkinModelPart;
318  ModelPart& mrFluidModelPart;
319 
320  bool mDiscontinuousDistance;
321 
325 
329 
333 
337 
341 
344 
346  //CalculateEmbeddedSignedDistanceTo3DSkinProcess(CalculateEmbeddedSignedDistanceTo3DSkinProcess const& rOther);
347 
349 
350 }; // Class CalculateEmbeddedSignedDistanceTo3DSkinProcess
351 
353 
356 
360 
362 inline std::istream& operator >> (std::istream& rIStream,
364 
366 inline std::ostream& operator << (std::ostream& rOStream,
368 {
369  rThis.PrintInfo(rOStream);
370  rOStream << std::endl;
371  rThis.PrintData(rOStream);
372 
373  return rOStream;
374 }
376 
377 } // namespace Kratos.
378 
379 #endif // KRATOS_CALCULATE_EMBEDDED_SIGNED_DISTANCE_TO_3D_SKIN_PROCESS_H_INCLUDED defined
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
This only calculates the distance. Calculating the inside outside should be done by a derived class o...
Definition: calculate_discontinuous_distance_to_skin_process.h:55
virtual void FindIntersections()
Calls the FindIntersectedObjectsProcess to find the intersections This method calls the FindIntersect...
Definition: calculate_discontinuous_distance_to_skin_process.cpp:155
virtual std::vector< PointerVector< GeometricalObject > > & GetIntersections()
Get the array containing the intersecting objects This method returns an array containing pointers to...
Definition: calculate_discontinuous_distance_to_skin_process.cpp:161
virtual void CalculateDistances(std::vector< PointerVector< GeometricalObject >> &rIntersectedObjects)
Computes the elemental distance values Given an intersecting objects vector, this method computes the...
Definition: calculate_discontinuous_distance_to_skin_process.cpp:167
virtual void Initialize()
Initializes discontinuous distance computation process This method initializes the TO_SPLIT flag,...
Definition: calculate_discontinuous_distance_to_skin_process.cpp:105
void Clear() override
Calls the FindIntersectedObjects Clear() method This method calls the FindIntersectedObjects Clear() ...
Definition: calculate_discontinuous_distance_to_skin_process.cpp:189
Calculates the nodal distances using elemental discontinuous distances.
Definition: calculate_distance_to_skin_process.h:40
Short class definition.
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:60
void PeakValuesCorrection()
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:220
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:153
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:98
std::string Info() const override
Turn back information as a string.
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:147
void Clear() override
This method clears the assignation of the conditions.
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:130
KRATOS_CLASS_POINTER_DEFINITION(CalculateEmbeddedSignedDistanceTo3DSkinProcess)
CalculateEmbeddedSignedDistanceTo3DSkinProcess(ModelPart &rThisModelPartStruc, ModelPart &rThisModelPartFluid, bool DiscontinuousDistance=false)
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:75
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:159
~CalculateEmbeddedSignedDistanceTo3DSkinProcess() override
Destructor.
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:81
void CalculateEmbeddedVelocity(std::vector< PointerVector< GeometricalObject >> &rIntersectedObjects)
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:186
void operator()()
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:89
void SetMaximumAndMinimumDistanceValues(double &max_distance, double &min_distance)
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:236
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
static void DivideInPartitions(const int NumTerms, const int NumThreads, PartitionVector &Partitions)
Divide an array of length NumTerms between NumThreads threads.
Definition: openmp_utils.h:158
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
std::vector< int > PartitionVector
Vector type for the output of DivideInPartitions method.
Definition: openmp_utils.h:53
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
The base class for all processes in Kratos.
Definition: process.h:49
std::ostream & operator<<(std::ostream &rOStream, const CalculateEmbeddedSignedDistanceTo3DSkinProcess &rThis)
output stream function
Definition: calculate_embedded_signed_distance_to_3d_skin_process.h:366
std::istream & operator>>(std::istream &rIStream, CalculateEmbeddedSignedDistanceTo3DSkinProcess &rThis)
input stream function
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
def GetSolutionStepValue(entity, variable, solution_step_index)
Definition: coupling_interface_data.py:253
int k
Definition: quadrature.py:595
def num_threads
Definition: script.py:75
integer i
Definition: TensorModule.f:17