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.
contact_domain_utilities.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_CONTACT_DOMAIN_UTILITIES_H_INCLUDED )
11 #define KRATOS_CONTACT_DOMAIN_UTILITIES_H_INCLUDED
12 
13 // External includes
14 
15 // System includes
16 
17 // Project includes
18 #include "utilities/math_utils.h"
19 
20 namespace Kratos
21 {
24 
28 
32 
36 
40 
42 
44 class KRATOS_API(CONTACT_MECHANICS_APPLICATION) ContactDomainUtilities
45 {
46 public:
47 
50 
53 
57  KRATOS_DEFINE_LOCAL_FLAG( COMPUTE_RHS_VECTOR );
58  KRATOS_DEFINE_LOCAL_FLAG( COMPUTE_LHS_MATRIX );
59 
60  KRATOS_DEFINE_LOCAL_FLAG( COMPUTE_RHS_VECTOR_WITH_COMPONENTS );
61  KRATOS_DEFINE_LOCAL_FLAG( COMPUTE_LHS_MATRIX_WITH_COMPONENTS );
62 
63  KRATOS_DEFINE_LOCAL_FLAG( COMPUTE_FRICTION_FORCES );
64  KRATOS_DEFINE_LOCAL_FLAG( COMPUTE_FRICTION_STIFFNESS );
65 
66  KRATOS_DEFINE_LOCAL_FLAG( COMPUTE_NODAL_CONTACT_FORCES );
67 
69  //typedef BoundedVector<double, 3> PointType;
71 
72 
73  typedef struct
74  {
75  double L; //base side lentgh
76  double A; //distance 2-3
77  double B; //distance 1-2
78 
79  } BaseLengths;
80 
81 
82  typedef struct
83  {
84  PointType Normal; //normal direction
85  PointType Tangent; //tangent direction
86 
87  } SurfaceVector;
88 
89 
90  typedef struct
91  {
92  double Normal; //normal component
93  double Tangent; //tangent component
94 
95  } SurfaceScalar;
96 
97 
98  typedef struct
99  {
100  double Covariant; //covariant component
101  double Contravariant; //contravariant component
102 
103  } ScalarBaseType;
104 
105 
106  typedef struct
107  {
108  Matrix Metric; //metric of the base
109  PointType DirectionA; //reference base direction a
110  PointType DirectionB; //reference base direction b
111 
112  } SurfaceBase;
113 
114 
118 
121 
124 
125 
129 
130 
134 
135  inline double CalculateVolume(const double x0, const double y0,
136  const double x1, const double y1,
137  const double x2, const double y2)
138  {
139  return 0.5*( (x1-x0)*(y2-y0)- (y1-y0)*(x2-x0) );
140  }
141 
142 
143  //************************************************************************************
144  //************************************************************************************
145 
146  inline bool CalculatePosition(const double x0, const double y0,
147  const double x1, const double y1,
148  const double x2, const double y2,
149  const double xc, const double yc)
150  {
151  double area = CalculateVolume(x0,y0,x1,y1,x2,y2);
152 
153  //std::cout<<" Area "<<area<<std::endl;
154 
155  if(area < 1e-15)
156  {
157  //KRATOS_THROW_ERROR( std::logic_error,"element with zero area found", "" )
158  std::cout<<"element with zero area found: "<<area<<" position ("<<x0<<", "<<y0<<") ("<<x1<<", "<<y1<<") ("<<x2<<", "<<y2<<") "<<std::endl;
159  }
160 
161  PointType N;
162 
163  N[0] = CalculateVolume(x1,y1,x2,y2,xc,yc) / area;
164  N[1] = CalculateVolume(x2,y2,x0,y0,xc,yc) / area;
165  N[2] = CalculateVolume(x0,y0,x1,y1,xc,yc) / area;
166 
167  double tol = 1e-3;
168  double upper_limit = 1.0+tol;
169  double lower_limit = -tol;
170 
171  if(N[0] >= lower_limit && N[1] >= lower_limit && N[2] >= lower_limit && N[0] <= upper_limit && N[1] <= upper_limit && N[2] <= upper_limit) //if the xc yc is inside the triangle
172  return true;
173 
174  return false;
175  }
176 
177  //************************************************************************************
178  //************************************************************************************
179 
180  inline bool CalculateObtuseAngle(const double x0, const double y0,
181  const double x1, const double y1,
182  const double xc, const double yc)
183  {
184 
185  double side0 = sqrt( (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1) ); //master side
186  double side1 = sqrt( (x0-xc)*(x0-xc) + (y0-yc)*(y0-yc) );
187  double side2 = sqrt( (xc-x1)*(xc-x1) + (yc-y1)*(yc-y1) );
188 
189  double cos_angle = 0;
190  double aux = (2*side1*side0);
191  if(aux!=0)
192  cos_angle = ((side1*side1) + (side0*side0) - (side2*side2)) / aux;
193 
194  if(cos_angle<(-0.1))
195  return true;
196 
197  aux = (2*side2*side0);
198  if(aux!=0)
199  cos_angle = ((side2*side2) + (side0*side0) - (side1*side1)) / aux;
200 
201  if(cos_angle<(-0.1))
202  return true;
203 
204  return false;
205  }
206 
207 
208  void CalculateBaseArea (double& area,
209  double& a,
210  double& b,
211  double& c);
212 
213  void CalculateLineIntersection (double& a,
214  const PointType& P1,
215  const PointType& P2,
216  const PointType& V1,
217  const PointType& V2);
218 
219 
220  void CalculateEdgeDistances (std::vector<BaseLengths>& BaseVector,
221  const PointType& P1,
222  const PointType& P2,
223  const PointType& PS1,
224  const PointType& PS2,
225  const PointType& Normal);
226 
227  void CalculateBaseDistances (std::vector<BaseLengths>& BaseVector,
228  const PointType& P1,
229  const PointType& P2,
230  const PointType& P3,
231  const PointType& PS,
232  const PointType& Normal);
233 
234 
235  void CalculateBaseDistances (BaseLengths& Base,
236  const PointType& P1,
237  const PointType& P2,
238  const PointType& PS,
239  const PointType& Normal);
240 
241  PointType & CalculateSurfaceNormal(PointType& Normal,
242  const PointType& P1,
243  const PointType& P2);
244 
245 
246  PointType & CalculateFaceNormal(PointType& Normal,
247  const PointType& P1,
248  const PointType& P2);
249 
250 
251  PointType & CalculateFaceTangent(PointType& Tangent,
252  const PointType& P1,
253  const PointType& P2);
254 
255 
256 
257  PointType & CalculateFaceTangent(PointType& Tangent,
258  PointType& Normal);
259 
260 
261  void GetOppositeEdge(unsigned int& i, unsigned int& j, unsigned int& k, unsigned int& l);
262 
263 
264  void BuildEdgeVector(std::vector<std::vector<std::vector<unsigned int> > >& rEdges);
268 
269 
273 
274 
278 
280  virtual std::string Info() const
281  {
282  return "";
283  }
284 
286  virtual void PrintInfo(std::ostream& rOStream) const {}
287 
289  virtual void PrintData(std::ostream& rOStream) const {}
290 
291 
295 
296 
298 
299 protected:
302 
303 
307 
308 
312 
313 
317 
318 
322 
323 
327 
328 
332 
333 
335 
336 private:
339 
340 
344 
345 
349 
352 
356 
357 
361 
362 
366 
367 
371 
373 
374 }; // Class ContactDomainUtilities
375 
377 
380 
381 
385 
386 
388  inline std::istream& operator >> (std::istream& rIStream,
389  ContactDomainUtilities& rThis);
390 
392  inline std::ostream& operator << (std::ostream& rOStream,
393  const ContactDomainUtilities& rThis)
394  {
395  rThis.PrintInfo(rOStream);
396  rOStream << std::endl;
397  rThis.PrintData(rOStream);
398 
399  return rOStream;
400  }
402 
403 
404 } // namespace Kratos.
405 
406 #endif // KRATOS_CONTACT_DOMAIN_UTILITIES_H_INCLUDED defined
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Short class definition.
Definition: contact_domain_utilities.hpp:45
ContactDomainUtilities()
Default constructor.
Definition: contact_domain_utilities.hpp:120
KRATOS_DEFINE_LOCAL_FLAG(COMPUTE_FRICTION_STIFFNESS)
KRATOS_CLASS_POINTER_DEFINITION(ContactDomainUtilities)
Pointer definition of ContactDomainUtilities.
KRATOS_DEFINE_LOCAL_FLAG(COMPUTE_LHS_MATRIX)
bool CalculatePosition(const double x0, const double y0, const double x1, const double y1, const double x2, const double y2, const double xc, const double yc)
Definition: contact_domain_utilities.hpp:146
KRATOS_DEFINE_LOCAL_FLAG(COMPUTE_LHS_MATRIX_WITH_COMPONENTS)
KRATOS_DEFINE_LOCAL_FLAG(COMPUTE_RHS_VECTOR)
KRATOS_DEFINE_LOCAL_FLAG(COMPUTE_NODAL_CONTACT_FORCES)
virtual std::string Info() const
Turn back information as a string.
Definition: contact_domain_utilities.hpp:280
array_1d< double, 3 > PointType
Tensor order 1 definition.
Definition: contact_domain_utilities.hpp:70
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: contact_domain_utilities.hpp:289
KRATOS_DEFINE_LOCAL_FLAG(COMPUTE_FRICTION_FORCES)
double CalculateVolume(const double x0, const double y0, const double x1, const double y1, const double x2, const double y2)
Definition: contact_domain_utilities.hpp:135
KRATOS_DEFINE_LOCAL_FLAG(COMPUTE_RHS_VECTOR_WITH_COMPONENTS)
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: contact_domain_utilities.hpp:286
virtual ~ContactDomainUtilities()
Destructor.
Definition: contact_domain_utilities.hpp:123
bool CalculateObtuseAngle(const double x0, const double y0, const double x1, const double y1, const double xc, const double yc)
Definition: contact_domain_utilities.hpp:180
Point class.
Definition: point.h:59
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
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
a
Definition: generate_stokes_twofluid_element.py:77
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
int tol
Definition: hinsberg_optimization.py:138
int k
Definition: quadrature.py:595
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
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31
Definition: contact_domain_utilities.hpp:74
double A
Definition: contact_domain_utilities.hpp:76
double L
Definition: contact_domain_utilities.hpp:75
double B
Definition: contact_domain_utilities.hpp:77
Definition: contact_domain_utilities.hpp:99
double Covariant
Definition: contact_domain_utilities.hpp:100
double Contravariant
Definition: contact_domain_utilities.hpp:101
Definition: contact_domain_utilities.hpp:107
PointType DirectionB
Definition: contact_domain_utilities.hpp:110
PointType DirectionA
Definition: contact_domain_utilities.hpp:109
Matrix Metric
Definition: contact_domain_utilities.hpp:108
Definition: contact_domain_utilities.hpp:91
double Tangent
Definition: contact_domain_utilities.hpp:93
double Normal
Definition: contact_domain_utilities.hpp:92
Definition: contact_domain_utilities.hpp:83
PointType Tangent
Definition: contact_domain_utilities.hpp:85
PointType Normal
Definition: contact_domain_utilities.hpp:84