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.
circle_bounding_box.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosContactMechanicsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: July 2016 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_CIRCLE_BOUNDING_BOX_H_INCLUDED )
11 #define KRATOS_CIRCLE_BOUNDING_BOX_H_INCLUDED
12 
13 // External includes
14 
15 // System includes
16 
17 // Project includes
19 #include "geometries/line_2d_2.h"
20 
21 namespace Kratos
22 {
23 
26 
30 
34 
38 
42 
44 
55  : public SphereBoundingBox
56 {
57 public:
60 
63 
64  //typedef BoundedVector<double, 3> PointType;
68  typedef NodesContainerType::Pointer NodesContainerTypePointer;
75 
78  {
80 
81  std::cout<< "Calling Rigid Circle Wall BBX empty constructor" <<std::endl;
82 
83  KRATOS_CATCH("")
84  }
85 
86 
87  //**************************************************************************
88  //**************************************************************************
89 
90  CircleBoundingBox(Parameters CustomParameters)
91  : SphereBoundingBox(CustomParameters)
92  {
94 
95  KRATOS_CATCH("")
96  }
97 
98  //**************************************************************************
99  //**************************************************************************
100 
101 
102  // General Wall constructor
104  double Radius,
105  PointType Velocity,
106  int Convexity)
107  : SphereBoundingBox(Center, Radius, Velocity, Convexity)
108  {
109  KRATOS_TRY
110 
111  KRATOS_CATCH("")
112  }
113 
114 
115 
116  //**************************************************************************
117  //**************************************************************************
118 
121  {
122  KRATOS_TRY
123 
125  return *this;
126 
127  KRATOS_CATCH("")
128  }
129 
130  //**************************************************************************
131  //**************************************************************************
132 
135  :SphereBoundingBox(rOther)
136  {
137  }
138 
139 
140  //**************************************************************************
141  //**************************************************************************
142 
144  virtual ~CircleBoundingBox() {};
145 
146 
150 
151 
155 
156  //************************************************************************************
157  //************************************************************************************
158 
159  //Circle
160  void CreateBoundingBoxBoundaryMesh(ModelPart& rModelPart, int linear_partitions = 4, int angular_partitions = 4 ) override
161  {
162  KRATOS_TRY
163 
164  unsigned int NodeId = 0;
165  if( rModelPart.IsSubModelPart() )
166  NodeId = this->GetMaxNodeId( rModelPart.GetParentModelPart() );
167  else
168  NodeId = this->GetMaxNodeId( rModelPart );
169 
170  unsigned int InitialNodeId = NodeId;
171 
172  //get boundary model parts ( temporary implementation )
173  std::vector<std::string> BoundaryModelPartsName;
174 
175  ModelPart* pMainModelPart = &rModelPart;
176  if( rModelPart.IsSubModelPart() )
177  pMainModelPart = &rModelPart.GetParentModelPart();
178 
179  for(ModelPart::SubModelPartIterator i_mp= pMainModelPart->SubModelPartsBegin() ; i_mp!=pMainModelPart->SubModelPartsEnd(); i_mp++)
180  {
181  if( i_mp->Is(BOUNDARY) || i_mp->Is(ACTIVE) ){
182  for(ModelPart::NodesContainerType::iterator i_node = i_mp->NodesBegin() ; i_node != i_mp->NodesEnd() ; i_node++)
183  {
184  if( i_node->Id() == rModelPart.Nodes().front().Id() ){
185  BoundaryModelPartsName.push_back(i_mp->Name());
186  break;
187  }
188  }
189  }
190  }
191  //get boundary model parts ( temporary implementation )
192 
193  PointType DirectionX(3);
194  DirectionX[0] = 0;
195  DirectionX[1] = 0;
196  DirectionX[2] = 1;
197 
198  PointType DirectionY(3);
199  noalias(DirectionY) = ZeroVector(3);
200  PointType DirectionZ(3);
201  noalias(DirectionZ) = ZeroVector(3);
202 
203  this->CalculateOrthonormalBase(DirectionX, DirectionY, DirectionZ);
204 
205  PointType BasePoint(3);
206  PointType RotationAxis(3);
207  PointType RotatedDirectionY(3);
208 
209  double alpha = 0;
211 
212  for(int k=0; k<angular_partitions; k++)
213  {
214  alpha = (2.0 * 3.14159262 * k)/(double)angular_partitions;
215 
216  //vector of rotation
217  RotationAxis = DirectionX * alpha;
219 
220  RotatedDirectionY = DirectionY;
221 
222  Quaternion.RotateVector3(RotatedDirectionY);
223 
224  //std::cout<<" Rotated "<<RotatedDirectionY<<" alpha "<<alpha<<std::endl;
225 
226  //add the angular_partitions points number along the circle
227  NodeId += 1;
228 
229  std::cout<<" node id "<<NodeId<<std::endl;
230 
231  noalias(BasePoint) = mBox.Center + mBox.Radius * RotatedDirectionY;
232 
233  NodeType::Pointer pNode = this->CreateNode(rModelPart, BasePoint, NodeId);
234 
235  pNode->Set(RIGID,true);
236 
237  rModelPart.AddNode( pNode );
238 
239  //get boundary model parts ( temporary implementation )
240  for(unsigned int j=0; j<BoundaryModelPartsName.size(); j++)
241  (pMainModelPart->GetSubModelPart(BoundaryModelPartsName[j])).AddNode( pNode );
242  //get boundary model parts ( temporary implementation )
243 
244  }
245 
246  //std::cout<<" Nodes Added "<<NodeId-InitialNodeId<<std::endl;
247 
248  this->CreateLinearBoundaryMesh(rModelPart, InitialNodeId);
249 
250  KRATOS_CATCH( "" )
251  }
252 
253 
257 
261 
262 
266 
268  std::string Info() const override
269  {
270  return "CircleBoundingBox";
271  }
272 
274  void PrintInfo(std::ostream& rOStream) const override
275  {
276  rOStream << Info();
277  }
278 
280  void PrintData(std::ostream& rOStream) const override
281  {
282  rOStream << this->mBox.UpperPoint << " , " << this->mBox.LowerPoint;
283  }
284 
288 
289 
291 
292 protected:
295 
296 
300 
301 
305 
306 
310 
311  //************************************************************************************
312  //************************************************************************************
313 
314  void CreateLinearBoundaryMesh(ModelPart& rModelPart, const unsigned int& rInitialNodeId)
315  {
316 
317  KRATOS_TRY
318 
319  //add elements to computing model part: (in order to be written)
320  ModelPart* pComputingModelPart = NULL;
321  if( rModelPart.IsSubModelPart() )
322  for(ModelPart::SubModelPartIterator i_mp= rModelPart.GetParentModelPart().SubModelPartsBegin() ; i_mp!=rModelPart.GetParentModelPart().SubModelPartsEnd(); ++i_mp)
323  {
324  if( i_mp->Is(ACTIVE) ) //computing_domain
325  pComputingModelPart = &rModelPart.GetParentModelPart().GetSubModelPart(i_mp->Name());
326  }
327  else{
328  for(ModelPart::SubModelPartIterator i_mp= rModelPart.SubModelPartsBegin() ; i_mp!=rModelPart.SubModelPartsEnd(); i_mp++)
329  {
330  if( i_mp->Is(ACTIVE) ) //computing_domain
331  pComputingModelPart = &rModelPart.GetSubModelPart(i_mp->Name());
332  }
333  }
334 
335  // Create surface of the cylinder/tube with quadrilateral shell conditions
336  unsigned int ElementId = 0;
337  if( rModelPart.IsSubModelPart() )
338  ElementId = this->GetMaxElementId( rModelPart.GetParentModelPart());
339  else
340  ElementId = this->GetMaxElementId( rModelPart );
341 
342  unsigned int NodeId = 0;
343  if( rModelPart.IsSubModelPart() )
344  NodeId = this->GetMaxNodeId( rModelPart.GetParentModelPart());
345  else
346  NodeId = this->GetMaxNodeId( rModelPart );
347 
348 
349  //GEOMETRY:
350  GeometryType::Pointer pFace;
351  ElementType::Pointer pElement;
352 
353  //PROPERTIES:
354  int number_of_properties = rModelPart.NumberOfProperties();
355  Properties::Pointer pProperties = Kratos::make_shared<Properties>(number_of_properties);
356 
357  int counter = 0;
358  unsigned int Id = rInitialNodeId;
359 
360  Vector FaceNodesIds = ZeroVector(2);
361 
362  while(Id < NodeId){
363 
364  counter += 1;
365  ElementId += 1;
366 
367  FaceNodesIds[0] = rInitialNodeId + counter ;
368  FaceNodesIds[1] = rInitialNodeId + counter + 1;
369 
370  //std::cout<<" FaceNodesIds "<<FaceNodesIds<<" element id "<<ElementId<<std::endl;
371 
373  FaceNodes.reserve(2);
374 
375  //NOTE: when creating a PointsArrayType
376  //important ask for pGetNode, if you ask for GetNode a copy is created
377  //if a copy is created a segmentation fault occurs when the node destructor is called
378 
379  for(unsigned int j=0; j<2; j++)
380  FaceNodes.push_back(rModelPart.pGetNode(FaceNodesIds[j]));
381 
382  pFace = Kratos::make_shared<Line2D2<NodeType> >(FaceNodes);
383  pElement = Kratos::make_intrusive<Element>(ElementId, pFace, pProperties);
384 
385  rModelPart.AddElement(pElement);
386  pElement->Set(ACTIVE,false);
387  pComputingModelPart->AddElement(pElement);
388 
389  Id = rInitialNodeId + counter + 1;
390 
391  }
392 
393 
394  ElementId += 1;
395 
396  //last element
397  FaceNodesIds[0] = rInitialNodeId + counter + 1;
398  FaceNodesIds[1] = rInitialNodeId + 1;
399 
401  FaceNodes.reserve(2);
402 
403  //NOTE: when creating a PointsArrayType
404  //important ask for pGetNode, if you ask for GetNode a copy is created
405  //if a copy is created a segmentation fault occurs when the node destructor is called
406 
407  for(unsigned int j=0; j<2; j++)
408  FaceNodes.push_back(rModelPart.pGetNode(FaceNodesIds[j]));
409 
410  //std::cout<<" FaceNodesIds "<<FaceNodesIds<<" element id "<<ElementId<<std::endl;
411 
412  pFace = Kratos::make_shared<Line2D2<NodeType> >(FaceNodes);
413  pElement = Kratos::make_intrusive<Element>(ElementId, pFace, pProperties);
414 
415  rModelPart.AddElement(pElement);
416  pElement->Set(ACTIVE,false);
417  pComputingModelPart->AddElement(pElement);
418 
419 
420  KRATOS_CATCH( "" )
421 
422  }
423 
427 
428 
432 
433 
437 
438 
440 
441 private:
444 
445 
449 
450 
454 
455 
459 
460 
464 
465 
469 
470 
474 
475 
477 
478 
479 }; // Class CircleBoundingBox
480 
482 
485 
486 
490 
492 
493 
494 } // namespace Kratos.
495 
496 #endif // KRATOS_CIRCLE_BOUNDING_BOX_H_INCLUDED defined
Short class definition.
Definition: circle_bounding_box.hpp:56
ModelPart::NodesContainerType NodesContainerType
Definition: circle_bounding_box.hpp:67
void CreateBoundingBoxBoundaryMesh(ModelPart &rModelPart, int linear_partitions=4, int angular_partitions=4) override
Definition: circle_bounding_box.hpp:160
CircleBoundingBox(CircleBoundingBox const &rOther)
Copy constructor.
Definition: circle_bounding_box.hpp:134
ModelPart::NodeType NodeType
Definition: circle_bounding_box.hpp:66
NodesContainerType::Pointer NodesContainerTypePointer
Definition: circle_bounding_box.hpp:68
std::string Info() const override
Turn back information as a string.
Definition: circle_bounding_box.hpp:268
CircleBoundingBox(PointType Center, double Radius, PointType Velocity, int Convexity)
Definition: circle_bounding_box.hpp:103
void CreateLinearBoundaryMesh(ModelPart &rModelPart, const unsigned int &rInitialNodeId)
Definition: circle_bounding_box.hpp:314
CircleBoundingBox(Parameters CustomParameters)
Definition: circle_bounding_box.hpp:90
CircleBoundingBox()
Default constructor.
Definition: circle_bounding_box.hpp:77
ElementType::GeometryType GeometryType
Definition: circle_bounding_box.hpp:71
Quaternion< double > QuaternionType
Definition: circle_bounding_box.hpp:69
KRATOS_CLASS_POINTER_DEFINITION(CircleBoundingBox)
Pointer definition of CircleBoundingBox.
array_1d< double, 3 > PointType
Definition: circle_bounding_box.hpp:65
CircleBoundingBox & operator=(CircleBoundingBox const &rOther)
Assignment operator.
Definition: circle_bounding_box.hpp:120
ModelPart::ElementType ElementType
Definition: circle_bounding_box.hpp:70
virtual ~CircleBoundingBox()
Destructor.
Definition: circle_bounding_box.hpp:144
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: circle_bounding_box.hpp:274
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: circle_bounding_box.hpp:280
Base class for all Elements.
Definition: element.h:60
Geometry base class.
Definition: geometry.h:71
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
SubModelPartIterator SubModelPartsEnd()
Definition: model_part.h:1708
SubModelPartIterator SubModelPartsBegin()
Definition: model_part.h:1698
void AddNode(NodeType::Pointer pNewNode, IndexType ThisIndex=0)
Definition: model_part.cpp:211
SizeType NumberOfProperties(IndexType ThisIndex=0) const
Returns the number of properties of the mesh.
Definition: model_part.cpp:575
bool IsSubModelPart() const
Definition: model_part.h:1893
SubModelPartsContainerType::iterator SubModelPartIterator
Iterator over the sub model parts of this model part.
Definition: model_part.h:258
NodeType::Pointer pGetNode(IndexType NodeId, IndexType ThisIndex=0)
Definition: model_part.h:421
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
void AddElement(ElementType::Pointer pNewElement, IndexType ThisIndex=0)
Definition: model_part.cpp:917
ModelPart & GetParentModelPart()
Definition: model_part.cpp:2124
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
void reserve(size_type dim)
Definition: pointer_vector.h:319
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
void RotateVector3(const TVector3_A &a, TVector3_B &b) const
Definition: quaternion.h:325
static Quaternion FromRotationVector(double rx, double ry, double rz)
Definition: quaternion.h:427
void CalculateOrthonormalBase(PointType &rDirectionVectorX, PointType &rDirectionVectorY, PointType &rDirectionVectorZ)
Definition: spatial_bounding_box.hpp:1408
NodeType::Pointer CreateNode(ModelPart &rModelPart, PointType &rPoint, const unsigned int &rNodeId)
Definition: spatial_bounding_box.hpp:1357
static unsigned int GetMaxNodeId(ModelPart &rModelPart)
Definition: spatial_bounding_box.hpp:1314
static unsigned int GetMaxElementId(ModelPart &rModelPart)
Definition: spatial_bounding_box.hpp:1334
BoundingBoxVariables mBox
Definition: spatial_bounding_box.hpp:1152
Short class definition.
Definition: sphere_bounding_box.hpp:57
SphereBoundingBox & operator=(SphereBoundingBox const &rOther)
Assignment operator.
Definition: sphere_bounding_box.hpp:186
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#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
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
alpha
Definition: generate_convection_diffusion_explicit_element.py:113
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int counter
Definition: script_THERMAL_CORRECT.py:218
PointType LowerPoint
Definition: spatial_bounding_box.hpp:218
double Radius
Definition: spatial_bounding_box.hpp:211
PointType Center
Definition: spatial_bounding_box.hpp:219
PointType UpperPoint
Definition: spatial_bounding_box.hpp:217