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.
projection.h
Go to the documentation of this file.
1 // KRATOS __ __ _____ ____ _ _ ___ _ _ ____
2 // | \/ | ____/ ___|| | | |_ _| \ | |/ ___|
3 // | |\/| | _| \___ \| |_| || || \| | | _
4 // | | | | |___ ___) | _ || || |\ | |_| |
5 // |_| |_|_____|____/|_| |_|___|_| \_|\____| APPLICATION
6 //
7 // License: BSD License
8 // license: MeshingApplication/license.txt
9 //
10 // Main authors: Antonia Larese de Tetto
11 //
12 
13 #if !defined(KRATOS_PROJECTION )
14 #define KRATOS_PROJECTION
15 
16 // External includes
17 
18 // System includes
19 #include <string>
20 #include <iostream>
21 #include <cstdlib>
22 
23 // Project includes
24 #include "includes/define.h"
25 #include "includes/model_part.h"
27 #include "utilities/timer.h"
31 
32 namespace Kratos
33 {
34 
35 template< class T, std::size_t dim >
37 {
38 public:
39  double operator()( T const& p1, T const& p2 )
40  {
41  double dist = 0.0;
42  for( std::size_t i = 0 ; i < dim ; i++)
43  {
44  double tmp = p1[i] - p2[i];
45  dist += tmp*tmp;
46  }
47  return dist; //square distance because it is easier to work without the square root//
48  }
49 };
50 
51 
52 
55 
59 
63 
67 
71 
73 
85 //class MeshTransfer
86 template<std::size_t TDim >
88 {
89 public:
92 
95 
99 
101  MeshTransfer() = default; //
102 
104  virtual ~MeshTransfer() = default;
105 
106 
110 
111 
115 
116  //If you want to pass the whole model part
117  //**********************************************************************
118  //**********************************************************************
120 
125  ModelPart& rOrigin_ModelPart ,
126  ModelPart& rDestination_ModelPart
127  )
128  {
129  KRATOS_TRY
130 
131  //**********************************************************************
132 // numofpts_origin = rOrigin_ModelPart.Nodes().size();
133 // numofpts_destination = rDestination_ModelPart.Nodes().size();
134 //
135  //*******************************************************************
136  //properties to be used in the generation
137  Properties::Pointer properties = rDestination_ModelPart.GetMesh().pGetProperties(1);
138 
139  //defintions for spatial search
140  typedef Node PointType;
141  typedef Node::Pointer PointTypePointer;
142  typedef std::vector<PointType::Pointer> PointVector;
143  typedef std::vector<PointType::Pointer>::iterator PointIterator;
144  typedef std::vector<double> DistanceVector;
145  typedef std::vector<double>::iterator DistanceIterator;
146 
147 
148  //creating an auxiliary list for the new nodes
149  PointVector list_of_new_nodes;
150 
151 // KRATOS_WATCH("STARTING KDTREE CONSTRUCTION");
152  //starting calculating time of construction of the kdtree
153  auto inital_time = std::chrono::steady_clock::now();
154 
155  //*************
156  // Bucket types
158 // typedef Bins< TDim, PointType, PointVector, PointTypePointer, PointIterator, DistanceIterator > StaticBins;
159 // typedef BinsDynamic< TDim, PointType, PointVector, PointTypePointer, PointIterator, DistanceIterator > DynamicBins;
160  //*************
161  // DynamicBins;
162 
163  typedef Tree< KDTreePartition<BucketType> > tree; //Kdtree;
164 // typedef Tree< OCTreePartition<BucketType> > tree; //Octree;
165 // typedef Tree< StaticBins > tree; //Binstree;
166 // typedef Tree< KDTreePartition<StaticBins> > tree; //KdtreeBins;
167 // typedef typename KdtreeBins::Partitions SubPartitions;
168 // typedef Tree< OCTreePartition<StaticBins> > tree; //OctreeBins;
169  /*
170  typedef Bins< TDim, PointType, stdPointVector> stdBins;
171  typedef Tree< Bins<TDim,PointType,stdPointVector> > tree; //stdStaticBins;*/
172 
173 
174  for(ModelPart::NodesContainerType::iterator node_it = rDestination_ModelPart.NodesBegin();
175  node_it != rDestination_ModelPart.NodesEnd(); ++node_it)
176  {
177  //PointType::Pointer pnode(new PointType(*node_it));
178  Node::Pointer pnode = *(node_it.base());
179 
180  //putting the nodes of the destination_model part in an auxiliary list
181  list_of_new_nodes.push_back( pnode );
182  }
183 
184  std::cout << "kdt construction time " << Timer::ElapsedSeconds(inital_time) << std::endl;
185  //finishing calculating time of construction of the kdtree
186 // KRATOS_WATCH("FINISHING KDTREE CONSTRUCTION");
187 
188  //create a spatial database with the list of new nodes
189  unsigned int bucket_size = 20;
190  tree nodes_tree(list_of_new_nodes.begin(),list_of_new_nodes.end(),bucket_size);
191 
192 
193  //work arrays
194  Node work_point(0,0.0,0.0,0.0);
195  unsigned int MaximumNumberOfResults = 10000;
196  PointVector Results(MaximumNumberOfResults);
197  DistanceVector ResultsDistances(MaximumNumberOfResults);
198  array_1d<double,TDim+1> N; //Shape functions vector//
199  int step_data_size = rDestination_ModelPart.GetNodalSolutionStepDataSize();
200 
201  for(ModelPart::NodesContainerType::iterator node_it = rDestination_ModelPart.NodesBegin();
202  node_it != rDestination_ModelPart.NodesEnd(); ++node_it)
203  {
204  //Setting to zero the whole model part
205  Clear(node_it, step_data_size );
206  }
207  inital_time = std::chrono::steady_clock::now();
208  //loop over all of the elements in the "old" list to perform the interpolation
209  for( ModelPart::ElementsContainerType::iterator el_it = rOrigin_ModelPart.ElementsBegin();
210  el_it != rOrigin_ModelPart.ElementsEnd(); el_it++)
211  {
212  Geometry<Node >&geom = el_it->GetGeometry();
213 
214  //find the center and "radius" of the element
215 // double xc, yc, radius;
216 // if constexpr (TDim == 2)
217 // {
218 // CalculateCenterAndSearchRadius( geom[0].X(), geom[0].Y(),
219 // geom[1].X(), geom[1].Y(),
220 // geom[2].X(), geom[2].Y(),
221 // xc,yc,radius);
222 // work_point.X() = xc; work_point.Y() = yc;
223 //
224 // }
225 // else
226 // {
227 // double zc;
228 // CalculateCenterAndSearchRadius( geom[0].X(), geom[0].Y(),geom[0].Z(),
229 // geom[1].X(), geom[1].Y(),geom[1].Z(),
230 // geom[2].X(), geom[2].Y(),geom[2].Z(),
231 // geom[3].X(), geom[3].Y(),geom[3].Z(),
232 // xc,yc,zc, radius);
233 // work_point.X() = xc; work_point.Y() = yc; work_point.Z() = zc;
234 //
235 // }
236  double xc, yc, zc, radius;
237  CalculateCenterAndSearchRadius( geom, xc,yc,zc, radius,N);
238  work_point.X() = xc;
239  work_point.Y() = yc;
240  work_point.Z() = zc;
241 
242  //find all of the new nodes within the radius
243  int number_of_points_in_radius;
244 
245  //look between the new nodes which of them is inside the radius of the circumscribed cyrcle
246  number_of_points_in_radius = nodes_tree.SearchInRadius(work_point, radius, Results.begin(),
247  ResultsDistances.begin(), MaximumNumberOfResults);
248 
249 
250  //check if inside
251  for( auto it_found = Results.begin(); it_found != Results.begin() + number_of_points_in_radius; it_found++)
252  {
253 
254  bool is_inside = false;
255  //once we are sure the node in inside the circle we have to see if it is inside the triangle i.e. if all the Origin element shape functions are >1
256 // if constexpr (TDim == 2)
257 // {
258 // is_inside = CalculatePosition(geom[0].X(), geom[0].Y(),
259 // geom[1].X(), geom[1].Y(),
260 // geom[2].X(), geom[2].Y(),
261 // (*it_found)->X(),(*it_found)->Y(),N);
262 //
263 // }
264 // else
265 // {
266 // is_inside = CalculatePosition(geom[0].X(), geom[0].Y(), geom[0].Z(),
267 // geom[1].X(), geom[1].Y(), geom[1].Z(),
268 // geom[2].X(), geom[2].Y(), geom[2].Z(),
269 // geom[3].X(), geom[3].Y(), geom[3].Z(),
270 // (*it_found)->X(),(*it_found)->Y(),(*it_found)->Z(),N);
271 //
272 // }
273  double is_visited = (*it_found)->GetValue(IS_VISITED);
274  is_inside = CalculatePosition(geom, (*it_found)->X(),(*it_found)->Y(),(*it_found)->Z(),N);
275 
276  //if the node falls inside the element interpolate
277  if(is_inside == true && is_visited != 1.0)
278  {
279  //Interpolating all the rVariables of the rOrigin_ModelPart to get their nodal value in the rDestination_ModelPart
280  Interpolate( el_it, N, step_data_size, *it_found );
281 
282  }
283  }
284 
285  }
286  std::cout << "search and interpolation time " << Timer::ElapsedSeconds(inital_time) << std::endl;
287  KRATOS_CATCH("")
288  }
289 
290 
291  //If you want to pass only one variable
292  //**********************************************************************
293  //**********************************************************************
295 
301  template<class TDataType>
303  ModelPart& rOrigin_ModelPart ,
304  ModelPart& rDestination_ModelPart,
305  Variable<TDataType>& rOriginVariable ,
306  Variable<TDataType>& rDestinationVariable
307  )
308  {
309 
310  KRATOS_TRY
311 
312  //*******************************************************************
313  //properties to be used in the generation
314  Properties::Pointer properties = rDestination_ModelPart.GetMesh().pGetProperties(1);
315 
316  //defintions for spatial search
317  typedef Node PointType;
318  typedef Node::Pointer PointTypePointer;
319  typedef std::vector<PointType::Pointer> PointVector;
320  typedef std::vector<PointType::Pointer>::iterator PointIterator;
321  typedef std::vector<double> DistanceVector;
322  typedef std::vector<double>::iterator DistanceIterator;
323 
324 
325  //creating an auxiliary list for the new nodes
326  PointVector list_of_new_nodes;
327 
328 // KRATOS_WATCH("STARTING KDTREE CONSTRUCTION");
329  //starting calculating time of construction of the kdtree
330  auto inital_time = std::chrono::steady_clock::now();
331 
332  //*************
333  // Bucket types
335 // typedef Bins< TDim, PointType, PointVector, PointTypePointer, PointIterator, DistanceIterator > StaticBins;
336 // typedef BinsDynamic< TDim, PointType, PointVector, PointTypePointer, PointIterator, DistanceIterator > DynamicBins;
337  //*************
338  // DynamicBins;
339 
340  typedef Tree< KDTreePartition<BucketType> > tree; //Kdtree;
341 // typedef Tree< OCTreePartition<BucketType> > tree; //Octree;
342 // typedef Tree< StaticBins > tree; //Binstree;
343 // typedef Tree< KDTreePartition<StaticBins> > tree; //KdtreeBins;
344 // typedef typename KdtreeBins::Partitions SubPartitions;
345 // typedef Tree< OCTreePartition<StaticBins> > tree; //OctreeBins;
346  /*
347  typedef Bins< TDim, PointType, stdPointVector> stdBins;
348  typedef Tree< Bins<TDim,PointType,stdPointVector> > tree; //stdStaticBins;*/
349 
350  for(ModelPart::NodesContainerType::iterator node_it = rDestination_ModelPart.NodesBegin();
351  node_it != rDestination_ModelPart.NodesEnd(); ++node_it)
352  {
353  node_it->GetValue(IS_VISITED) = 0.0;
354  }
355 
356 // KRATOS_WATCH("line 328")
357  for(ModelPart::NodesContainerType::iterator node_it = rDestination_ModelPart.NodesBegin();
358  node_it != rDestination_ModelPart.NodesEnd(); ++node_it)
359  {
360 
361  ClearVariables(node_it, rDestinationVariable);
362 
363 
364  //PointType::Pointer pnode(new PointType(*node_it));
365  Node::Pointer pnode = *(node_it.base());
366 
367  //putting the nodes of the destination_model part in an auxiliary list
368  list_of_new_nodes.push_back( pnode );
369 
370 
371  }
372 
373  std::cout << "kdt construction time " << Timer::ElapsedSeconds(inital_time) << std::endl;
374  //finishing calculating time of construction of the kdtree
375 // KRATOS_WATCH("FINISHING KDTREE CONSTRUCTION");
376 
377  //create a spatial database with the list of new nodes
378  unsigned int bucket_size = 20;
379  tree nodes_tree(list_of_new_nodes.begin(),list_of_new_nodes.end(),bucket_size);
380 
381  //work arrays
382  Node work_point(0,0.0,0.0,0.0);
383  unsigned int MaximumNumberOfResults = 10000;
384  PointVector Results(MaximumNumberOfResults);
385  DistanceVector ResultsDistances(MaximumNumberOfResults);
386  array_1d<double,TDim+1> N; //Shape functions vector//
387  //int step_data_size = rDestination_ModelPart.GetNodalSolutionStepDataSize();
388  //unsigned int TDim = 3;
389 // KRATOS_WATCH("line 359")
390  inital_time = std::chrono::steady_clock::now();
391  //loop over all of the elements in the "old" list to perform the interpolation
392  for( ModelPart::ElementsContainerType::iterator el_it = rOrigin_ModelPart.ElementsBegin();
393  el_it != rOrigin_ModelPart.ElementsEnd(); el_it++)
394  {
395  Geometry<Node >&geom = el_it->GetGeometry();
396 
397  //find the center and "radius" of the element
398 // double xc, yc, radius;
399 // if constexpr (TDim == 2)
400 // {
401 // CalculateCenterAndSearchRadius( geom[0].X(), geom[0].Y(),
402 // geom[1].X(), geom[1].Y(),
403 // geom[2].X(), geom[2].Y(),
404 // xc,yc,radius);
405 // work_point.X() = xc; work_point.Y() = yc;
406 //
407 // }
408 // else
409 // {
410 // double zc;
411 // CalculateCenterAndSearchRadius( geom[0].X(), geom[0].Y(),geom[0].Z(),
412 // geom[1].X(), geom[1].Y(),geom[1].Z(),
413 // geom[2].X(), geom[2].Y(),geom[2].Z(),
414 // geom[3].X(), geom[3].Y(),geom[3].Z(),
415 // xc,yc,zc, radius);
416 // work_point.X() = xc; work_point.Y() = yc; work_point.Z() = zc;
417 //
418 // }
419  double xc, yc, zc, radius;
420  CalculateCenterAndSearchRadius( geom, xc,yc,zc, radius, N);
421  work_point.X() = xc;
422  work_point.Y() = yc;
423  work_point.Z() = zc;
424 // KRATOS_WATCH("line 391")
425  //find all of the new nodes within the radius
426  int number_of_points_in_radius;
427 
428  //look between the new nodes which of them is inside the radius of the circumscribed circle
429  number_of_points_in_radius = nodes_tree.SearchInRadius(work_point, radius, Results.begin(),
430  ResultsDistances.begin(), MaximumNumberOfResults);
431 
432 
433  //check if inside
434  for( auto it_found = Results.begin(); it_found != Results.begin() + number_of_points_in_radius; it_found++)
435  {
436 // KRATOS_WATCH("line 402")
437  bool is_inside = false;
438  //once we are sure the node in inside the circle we have to see if it is inside the triangle i.e. if all the Origin element shape functions are >1
439 // if constexpr (TDim == 2)
440 // {
441 // is_inside = CalculatePosition(geom[0].X(), geom[0].Y(),
442 // geom[1].X(), geom[1].Y(),
443 // geom[2].X(), geom[2].Y(),
444 // (*it_found)->X(),(*it_found)->Y(),N);
445 //
446 // }
447 // else
448 // {
449 // is_inside = CalculatePosition(geom[0].X(), geom[0].Y(), geom[0].Z(),
450 // geom[1].X(), geom[1].Y(), geom[1].Z(),
451 // geom[2].X(), geom[2].Y(), geom[2].Z(),
452 // geom[3].X(), geom[3].Y(), geom[3].Z(),
453 // (*it_found)->X(),(*it_found)->Y(),(*it_found)->Z(),N);
454 //
455 // }
456 
457  double is_visited = (*it_found)->GetValue(IS_VISITED);
458  is_inside = CalculatePosition(geom, (*it_found)->X(),(*it_found)->Y(),(*it_found)->Z(),N);
459 // KRATOS_WATCH("line 423")
460 // KRATOS_WATCH("IS INSIDE")
461 // KRATOS_WATCH((*it_found)->Id())
462  //if the node falls inside the element interpolate
463  if(is_inside == true && is_visited != 1.0)
464  {
465  //CANCELLA insert the variable TDim
466  //Interpolating all the rOriginVariables to get their nodal value in the rDestination_ModelPart
467  Interpolate( el_it, N, *it_found , rOriginVariable , rDestinationVariable );
468 
469  }
470  }
471 
472  }
473  std::cout << "search and interpolation time " << Timer::ElapsedSeconds(inital_time) << std::endl;
474  KRATOS_CATCH("")
475  }
476 
477 
478 
479 
480 
484 
485 
489 
490 
494 
496  virtual std::string Info() const
497  {
498  return "";
499  }
500 
502  virtual void PrintInfo(std::ostream& rOStream) const {}
503 
505  virtual void PrintData(std::ostream& rOStream) const {}
506 
507 
511 
513 
514 protected:
517 
518 
522 
523 
527 
528 
532 
533 
537 
538 
542 
543 
547 
548 
550 
551 private:
554 
555 
559 
560 
561 
562  inline void CalculateCenterAndSearchRadius(Geometry<Node >&geom,
563  double& xc, double& yc, double& zc, double& R, array_1d<double,3>& N
564  )
565  {
566  double x0 = geom[0].X();
567  double y0 = geom[0].Y();
568  double x1 = geom[1].X();
569  double y1 = geom[1].Y();
570  double x2 = geom[2].X();
571  double y2 = geom[2].Y();
572 
573 
574  xc = 0.3333333333333333333*(x0+x1+x2);
575  yc = 0.3333333333333333333*(y0+y1+y2);
576  zc = 0.0;
577 
578  double R1 = (xc-x0)*(xc-x0) + (yc-y0)*(yc-y0);
579  double R2 = (xc-x1)*(xc-x1) + (yc-y1)*(yc-y1);
580  double R3 = (xc-x2)*(xc-x2) + (yc-y2)*(yc-y2);
581 
582  R = R1;
583  if(R2 > R) R = R2;
584  if(R3 > R) R = R3;
585 
586  R = 1.01 * sqrt(R);
587  }
588  //***************************************
589  //***************************************
590  inline void CalculateCenterAndSearchRadius(Geometry<Node >&geom,
591  double& xc, double& yc, double& zc, double& R, array_1d<double,4>& N
592 
593  )
594  {
595  double x0 = geom[0].X();
596  double y0 = geom[0].Y();
597  double z0 = geom[0].Z();
598  double x1 = geom[1].X();
599  double y1 = geom[1].Y();
600  double z1 = geom[1].Z();
601  double x2 = geom[2].X();
602  double y2 = geom[2].Y();
603  double z2 = geom[2].Z();
604  double x3 = geom[3].X();
605  double y3 = geom[3].Y();
606  double z3 = geom[3].Z();
607 
608 
609  xc = 0.25*(x0+x1+x2+x3);
610  yc = 0.25*(y0+y1+y2+y3);
611  zc = 0.25*(z0+z1+z2+z3);
612 
613  double R1 = (xc-x0)*(xc-x0) + (yc-y0)*(yc-y0) + (zc-z0)*(zc-z0);
614  double R2 = (xc-x1)*(xc-x1) + (yc-y1)*(yc-y1) + (zc-z1)*(zc-z1);
615  double R3 = (xc-x2)*(xc-x2) + (yc-y2)*(yc-y2) + (zc-z2)*(zc-z2);
616  double R4 = (xc-x3)*(xc-x3) + (yc-y3)*(yc-y3) + (zc-z3)*(zc-z3);
617 
618  R = R1;
619  if(R2 > R) R = R2;
620  if(R3 > R) R = R3;
621  if(R4 > R) R = R4;
622 
623  R = sqrt(R);
624  }
625  //***************************************
626  //***************************************
627  inline double CalculateVol( const double x0, const double y0,
628  const double x1, const double y1,
629  const double x2, const double y2
630  )
631  {
632  return 0.5*( (x1-x0)*(y2-y0)- (y1-y0)*(x2-x0) );
633  }
634  //***************************************
635  //***************************************
636  inline double CalculateVol( const double x0, const double y0, const double z0,
637  const double x1, const double y1, const double z1,
638  const double x2, const double y2, const double z2,
639  const double x3, const double y3, const double z3
640  )
641  {
642  double x10 = x1 - x0;
643  double y10 = y1 - y0;
644  double z10 = z1 - z0;
645 
646  double x20 = x2 - x0;
647  double y20 = y2 - y0;
648  double z20 = z2 - z0;
649 
650  double x30 = x3 - x0;
651  double y30 = y3 - y0;
652  double z30 = z3 - z0;
653 
654  double detJ = x10 * y20 * z30 - x10 * y30 * z20 + y10 * z20 * x30 - y10 * x20 * z30 + z10 * x20 * y30 - z10 * y20 * x30;
655  return detJ*0.1666666666666666666667;
656 
657  //return 0.5*( (x1-x0)*(y2-y0)- (y1-y0)*(x2-x0) );
658  }
659  //***************************************
660  //***************************************
661  inline bool CalculatePosition( Geometry<Node >&geom,
662  const double xc, const double yc, const double zc,
663  array_1d<double,3>& N
664  )
665  {
666  double x0 = geom[0].X();
667  double y0 = geom[0].Y();
668  double x1 = geom[1].X();
669  double y1 = geom[1].Y();
670  double x2 = geom[2].X();
671  double y2 = geom[2].Y();
672 
673  double area = CalculateVol(x0,y0,x1,y1,x2,y2);
674  double inv_area = 0.0;
675  if(area == 0.0)
676  {
677 
678 // KRATOS_THROW_ERROR(std::logic_error,"element with zero area found","");
679  //The interpolated node will not be inside an elemente with zero area
680  return false;
681 
682  }
683  else
684  {
685  inv_area = 1.0 / area;
686  }
687 
688 
689  N[0] = CalculateVol(x1,y1,x2,y2,xc,yc) * inv_area;
690  N[1] = CalculateVol(x2,y2,x0,y0,xc,yc) * inv_area;
691  N[2] = CalculateVol(x0,y0,x1,y1,xc,yc) * inv_area;
692 
693 
694  if(N[0] >= 0.0 && N[1] >= 0.0 && N[2] >= 0.0 && N[0] <=1.0 && N[1]<= 1.0 && N[2] <= 1.0) //if the xc yc is inside the triangle return true
695  return true;
696 
697  return false;
698  }
699 
700  //***************************************
701  //***************************************
702 
703  inline bool CalculatePosition( Geometry<Node >&geom,
704  const double xc, const double yc, const double zc,
705  array_1d<double,4>& N
706  )
707  {
708 
709  double x0 = geom[0].X();
710  double y0 = geom[0].Y();
711  double z0 = geom[0].Z();
712  double x1 = geom[1].X();
713  double y1 = geom[1].Y();
714  double z1 = geom[1].Z();
715  double x2 = geom[2].X();
716  double y2 = geom[2].Y();
717  double z2 = geom[2].Z();
718  double x3 = geom[3].X();
719  double y3 = geom[3].Y();
720  double z3 = geom[3].Z();
721 
722  double vol = CalculateVol(x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3);
723 
724  double inv_vol = 0.0;
725  if(vol < 0.0000000000001)
726  {
727 
728 // KRATOS_THROW_ERROR(std::logic_error,"element with zero vol found","");
729  //The interpolated node will not be inside an elemente with zero volume
730  return false;
731  KRATOS_WATCH("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
732  }
733  else
734  {
735  inv_vol = 1.0 / vol;
736  }
737 
738  N[0] = CalculateVol(x1,y1,z1,x3,y3,z3,x2,y2,z2,xc,yc,zc) * inv_vol;
739  N[1] = CalculateVol(x3,y3,z3,x0,y0,z0,x2,y2,z2,xc,yc,zc) * inv_vol;
740  N[2] = CalculateVol(x3,y3,z3,x1,y1,z1,x0,y0,z0,xc,yc,zc) * inv_vol;
741  N[3] = CalculateVol(x0,y0,z0,x1,y1,z1,x2,y2,z2,xc,yc,zc) * inv_vol;
742 
743 
744  if(N[0] >= 0.0 && N[1] >= 0.0 && N[2] >= 0.0 && N[3] >=0.0 &&
745  N[0] <= 1.0 && N[1] <= 1.0 && N[2] <= 1.0 && N[3] <=1.0)
746  //if the xc yc zc is inside the tetrahedron return true
747  return true;
748 
749  return false;
750  }
751 //el_it Element iterator
752 //N Shape functions
753 //step_data_size
754 //pnode pointer to the node
755 
756  //projecting total model part 2Dversion
757  void Interpolate(
758  ModelPart::ElementsContainerType::iterator el_it,
759  const array_1d<double,3>& N,
760  int step_data_size,
761  Node::Pointer pnode)
762  {
763  //Geometry element of the rOrigin_ModelPart
764  Geometry< Node >& geom = el_it->GetGeometry();
765 
766  unsigned int buffer_size = pnode->GetBufferSize();
767 
768  for(unsigned int step = 0; step<buffer_size; step++)
769  {
770  //getting the data of the solution step
771  double* step_data = (pnode)->SolutionStepData().Data(step);
772 
773  double* node0_data = geom[0].SolutionStepData().Data(step);
774  double* node1_data = geom[1].SolutionStepData().Data(step);
775  double* node2_data = geom[2].SolutionStepData().Data(step);
776 
777  //copying this data in the position of the vector we are interested in
778  for(int j= 0; j< step_data_size; j++)
779  {
780  step_data[j] = N[0]*node0_data[j] + N[1]*node1_data[j] + N[2]*node2_data[j];
781  }
782  }
783  pnode->GetValue(IS_VISITED) = 1.0;
784 
785  }
786  //projecting total model part 3Dversion
787  void Interpolate(
788  ModelPart::ElementsContainerType::iterator el_it,
789  const array_1d<double,4>& N,
790  int step_data_size,
791  Node::Pointer pnode)//dimension or number of nodes???
792  {
793  //Geometry element of the rOrigin_ModelPart
794  Geometry< Node >& geom = el_it->GetGeometry();
795 
796  unsigned int buffer_size = pnode->GetBufferSize();
797 
798  for(unsigned int step = 0; step<buffer_size; step++)
799  {
800  //getting the data of the solution step
801  double* step_data = (pnode)->SolutionStepData().Data(step);
802 
803  double* node0_data = geom[0].SolutionStepData().Data(step);
804  double* node1_data = geom[1].SolutionStepData().Data(step);
805  double* node2_data = geom[2].SolutionStepData().Data(step);
806  double* node3_data = geom[3].SolutionStepData().Data(step);
807 
808  //copying this data in the position of the vector we are interested in
809  for(int j= 0; j< step_data_size; j++)
810  {
811  step_data[j] = N[0]*node0_data[j] + N[1]*node1_data[j] + N[2]*node2_data[j] + N[3]*node3_data[j];
812  }
813  }
814  pnode->GetValue(IS_VISITED) = 1.0;
815 
816  }
817 
818 
819  //projecting an array1D 2Dversion
820  void Interpolate(
821  ModelPart::ElementsContainerType::iterator el_it,
822  const array_1d<double,3>& N,
823  Node::Pointer pnode,
824  Variable<array_1d<double,3> >& rOriginVariable,
825  Variable<array_1d<double,3> >& rDestinationVariable)
826  {
827  //Geometry element of the rOrigin_ModelPart
828  Geometry< Node >& geom = el_it->GetGeometry();
829 
830  unsigned int buffer_size = pnode->GetBufferSize();
831 
832  for(unsigned int step = 0; step<buffer_size; step++)
833  {
834  //getting the data of the solution step
835  array_1d<double,3>& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable , step);
836  //Reference or no reference???//CANCELLA
837  const array_1d<double,3>& node0_data = geom[0].FastGetSolutionStepValue(rOriginVariable , step);
838  const array_1d<double,3>& node1_data = geom[1].FastGetSolutionStepValue(rOriginVariable , step);
839  const array_1d<double,3>& node2_data = geom[2].FastGetSolutionStepValue(rOriginVariable , step);
840 
841  //copying this data in the position of the vector we are interested in
842  for(unsigned int j= 0; j< TDim; j++)
843  {
844  step_data[j] = N[0]*node0_data[j] + N[1]*node1_data[j] + N[2]*node2_data[j];
845  }
846  }
847  pnode->GetValue(IS_VISITED) = 1.0;
848 
849  }
850 
851  //projecting an array1D 3Dversion
852  void Interpolate(
853  ModelPart::ElementsContainerType::iterator el_it,
854  const array_1d<double,4>& N,
855  Node::Pointer pnode,
856  Variable<array_1d<double,3> >& rOriginVariable,
857  Variable<array_1d<double,3> >& rDestinationVariable)
858 
859  {
860  //Geometry element of the rOrigin_ModelPart
861  Geometry< Node >& geom = el_it->GetGeometry();
862 
863  unsigned int buffer_size = pnode->GetBufferSize();
864 
865  for(unsigned int step = 0; step<buffer_size; step++)
866  {
867  //getting the data of the solution step
868  array_1d<double,3>& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable , step);
869  //Reference or no reference???//CANCELLA
870  const array_1d<double,3>& node0_data = geom[0].FastGetSolutionStepValue(rOriginVariable , step);
871  const array_1d<double,3>& node1_data = geom[1].FastGetSolutionStepValue(rOriginVariable , step);
872  const array_1d<double,3>& node2_data = geom[2].FastGetSolutionStepValue(rOriginVariable , step);
873  const array_1d<double,3>& node3_data = geom[3].FastGetSolutionStepValue(rOriginVariable , step);
874 
875  //copying this data in the position of the vector we are interested in
876  for(unsigned int j= 0; j< TDim; j++)
877  {
878  step_data[j] = N[0]*node0_data[j] + N[1]*node1_data[j] + N[2]*node2_data[j] + N[3]*node3_data[j];
879  }
880  }
881  pnode->GetValue(IS_VISITED) = 1.0;
882 
883  }
884  //projecting a scalar 2Dversion
885  void Interpolate(
886  ModelPart::ElementsContainerType::iterator el_it,
887  const array_1d<double,3>& N,
888  Node::Pointer pnode,
889  Variable<double>& rOriginVariable,
890  Variable<double>& rDestinationVariable)
891  {
892  //Geometry element of the rOrigin_ModelPart
893  Geometry< Node >& geom = el_it->GetGeometry();
894 
895  unsigned int buffer_size = pnode->GetBufferSize();
896  //facendo un loop sugli step temporali step_data come salva i dati al passo anteriore? Cioś dove passiamo l'informazione ai nodi???
897  for(unsigned int step = 0; step<buffer_size; step++)
898  {
899  //getting the data of the solution step
900  double& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable , step);
901  //Reference or no reference???//CANCELLA
902  const double node0_data = geom[0].FastGetSolutionStepValue(rOriginVariable , step);
903  const double node1_data = geom[1].FastGetSolutionStepValue(rOriginVariable , step);
904  const double node2_data = geom[2].FastGetSolutionStepValue(rOriginVariable , step);
905 
906  //copying this data in the position of the vector we are interested in
907 
908  step_data = N[0]*node0_data + N[1]*node1_data + N[2]*node2_data;
909 
910  }
911  pnode->GetValue(IS_VISITED) = 1.0;
912 
913  }
914  //projecting a scalar 3Dversion
915  void Interpolate(
916  ModelPart::ElementsContainerType::iterator el_it,
917  const array_1d<double,4>& N,
918  Node::Pointer pnode,
919  Variable<double>& rOriginVariable,
920  Variable<double>& rDestinationVariable)
921  {
922  //Geometry element of the rOrigin_ModelPart
923  Geometry< Node >& geom = el_it->GetGeometry();
924 
925  unsigned int buffer_size = pnode->GetBufferSize();
926  //facendo un loop sugli step temporali step_data come salva i dati al passo anteriore? Cioś dove passiamo l'informazione ai nodi???
927  for(unsigned int step = 0; step<buffer_size; step++)
928  {
929  //getting the data of the solution step
930  double& step_data = (pnode)->FastGetSolutionStepValue(rDestinationVariable , step);
931  //Reference or no reference???//CANCELLA
932  const double node0_data = geom[0].FastGetSolutionStepValue(rOriginVariable , step);
933  const double node1_data = geom[1].FastGetSolutionStepValue(rOriginVariable , step);
934  const double node2_data = geom[2].FastGetSolutionStepValue(rOriginVariable , step);
935  const double node3_data = geom[3].FastGetSolutionStepValue(rOriginVariable , step);
936 
937  //copying this data in the position of the vector we are interested in
938 
939  step_data = N[0]*node0_data + N[1]*node1_data + N[2]*node2_data + N[3]*node3_data;
940 
941  }
942  pnode->GetValue(IS_VISITED) = 1.0;
943 
944  }
945  inline void Clear(ModelPart::NodesContainerType::iterator node_it, int step_data_size )
946  {
947  unsigned int buffer_size = node_it->GetBufferSize();
948 
949  for(unsigned int step = 0; step<buffer_size; step++)
950  {
951  //getting the data of the solution step
952  double* step_data = (node_it)->SolutionStepData().Data(step);
953 
954  //copying this data in the position of the vector we are interested in
955  for(int j= 0; j< step_data_size; j++)
956  {
957  step_data[j] = 0.0;
958  }
959  }
960 
961  }
962 
963  inline void ClearVariables(ModelPart::NodesContainerType::iterator node_it , Variable<array_1d<double,3> >& rVariable)
964  {
965  array_1d<double, 3>& Aux_var = node_it->FastGetSolutionStepValue(rVariable, 0);
966 
967  noalias(Aux_var) = ZeroVector(3);
968 
969  }
970 
971 
972  inline void ClearVariables(ModelPart::NodesContainerType::iterator node_it, Variable<double>& rVariable)
973  {
974  double& Aux_var = node_it->FastGetSolutionStepValue(rVariable, 0);
975 
976  Aux_var = 0.0;
977 
978  }
979 
980 
981 
982 
986 
990 
991 
995 
996 
1000 
1001 
1005 
1007  MeshTransfer& operator=(MeshTransfer const& rOther);
1008 
1009 
1011 
1012 }; // Class MeshTransfer
1013 
1015 
1018 
1019 
1023 
1024 
1025 
1026 
1028 template<std::size_t TDim>
1029 inline std::ostream& operator << (std::ostream& rOStream,
1030  const MeshTransfer<TDim>& rThis)
1031 {
1032  rThis.PrintInfo(rOStream);
1033  rOStream << std::endl;
1034  rThis.PrintData(rOStream);
1035 
1036  return rOStream;
1037 }
1039 
1040 
1041 } // namespace Kratos.
1042 
1043 #endif // KRATOS_PROJECTION defined
Short class definition.
Definition: bucket.h:57
Definition: projection.h:37
double operator()(T const &p1, T const &p2)
Definition: projection.h:39
Geometry base class.
Definition: geometry.h:71
PropertiesType::Pointer pGetProperties(IndexType PropertiesId)
Definition: mesh.h:394
This class allows the interpolation between non-matching meshes in 2D and 3D.
Definition: projection.h:88
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: projection.h:502
void DirectVariableInterpolation(ModelPart &rOrigin_ModelPart, ModelPart &rDestination_ModelPart, Variable< TDataType > &rOriginVariable, Variable< TDataType > &rDestinationVariable)
Interpolate one variable.
Definition: projection.h:302
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: projection.h:505
virtual std::string Info() const
Turn back information as a stemplate<class T, std::size_t dim> tring.
Definition: projection.h:496
void DirectInterpolation(ModelPart &rOrigin_ModelPart, ModelPart &rDestination_ModelPart)
Interpolate the whole problem type.
Definition: projection.h:124
KRATOS_CLASS_POINTER_DEFINITION(MeshTransfer< TDim >)
Pointer definition of MeshTransfer.
MeshTransfer()=default
Default constructor.
virtual ~MeshTransfer()=default
Destructor.
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 GetNodalSolutionStepDataSize()
Definition: model_part.h:571
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
MeshType & GetMesh(IndexType ThisIndex=0)
Definition: model_part.h:1791
This class defines the node.
Definition: node.h:65
double Y() const
Definition: point.h:187
double Z() const
Definition: point.h:193
double X() const
Definition: point.h:181
static double ElapsedSeconds(const std::chrono::steady_clock::time_point StartTime)
This method returns the resulting time.
Definition: timer.h:179
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
DistanceVector::iterator DistanceIterator
Definition: internal_variables_interpolation_process.h:56
std::vector< PointTypePointer > PointVector
Definition: internal_variables_interpolation_process.h:53
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
PointType::Pointer PointTypePointer
Definition: internal_variables_interpolation_process.h:52
PointVector::iterator PointIterator
Definition: internal_variables_interpolation_process.h:54
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
std::vector< double > DistanceVector
Definition: internal_variables_interpolation_process.h:55
Point PointType
Geometric definitions.
Definition: mortar_classes.h:36
float dist
Definition: edgebased_PureConvection.py:89
int step
Definition: face_heat.py:88
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
R
Definition: isotropic_damage_automatic_differentiation.py:172
float radius
Definition: mesh_to_mdpa_converter.py:18
int j
Definition: quadrature.py:648
float xc
Definition: rotating_cone.py:77
float yc
Definition: rotating_cone.py:78
N
Definition: sensitivityMatrix.py:29
int dim
Definition: sensitivityMatrix.py:25
integer i
Definition: TensorModule.f:17