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.
wall_condition_discontinuous.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3 Kratos Fluid Dynamics Application
4 Kratos
5 A General Purpose Software for Multi-Physics Finite Element Analysis
6 Version 1.0 (Released on march 05, 2007).
7 
8 Copyright 2007
9 Pooyan Dadvand, Riccardo Rossi
10 pooyan@cimne.upc.edu
11 rrossi@cimne.upc.edu
12 CIMNE (International Center for Numerical Methods in Engineering),
13 Gran Capita' s/n, 08034 Barcelona, Spain
14 
15 Permission is hereby granted, free of charge, to any person obtaining
16 a copy of this software and associated documentation files (the
17 "Software"), to deal in the Software without restriction, including
18 without limitation the rights to use, copy, modify, merge, publish,
19 distribute, sublicense and/or sell copies of the Software, and to
20 permit persons to whom the Software is furnished to do so, subject to
21 the following condition:
22 
23 Distribution of this code for any commercial purpose is permissible
24 ONLY BY DIRECT ARRANGEMENT WITH THE COPYRIGHT OWNER.
25 
26 The above copyright notice and this permission notice shall be
27 included in all copies or substantial portions of the Software.
28 
29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
33 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
34 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 
37 ==============================================================================
38  */
39 
40 #ifndef KRATOS_WALL_CONDITION_DISCONTINUOUS_H
41 #define KRATOS_WALL_CONDITION_DISCONTINUOUS_H
42 
43 // System includes
44 #include <string>
45 #include <iostream>
46 
47 
48 // External includes
49 
50 
51 // Project includes
52 #include "includes/define.h"
53 #include "includes/serializer.h"
54 #include "wall_condition.h"
55 #include "includes/process_info.h"
57 
58 // Application includes
60 
61 namespace Kratos
62 {
65 
68 
72 
76 
80 
84 
86 
94 template< unsigned int TDim, unsigned int TNumNodes = TDim >
95 class WallConditionDiscontinuous : public WallCondition<TDim,TNumNodes>
96 {
97 public:
100 
103 
104  typedef Node NodeType;
105 
107 
109 
111 
113 
115 
116  typedef std::size_t IndexType;
117 
118  typedef std::size_t SizeType;
119 
120  typedef std::vector<std::size_t> EquationIdVectorType;
121 
122  typedef std::vector< Dof<double>::Pointer > DofsVectorType;
123 
125 
129 
131 
135  WallCondition<TDim,TNumNodes>(NewId)
136  {
137  }
138 
140 
145  const NodesArrayType& ThisNodes):
146  WallCondition<TDim,TNumNodes>(NewId,ThisNodes)
147  {
148  }
149 
151 
156  GeometryType::Pointer pGeometry):
157  WallCondition<TDim,TNumNodes>(NewId,pGeometry)
158  {
159  }
160 
162 
168  GeometryType::Pointer pGeometry,
169  PropertiesType::Pointer pProperties):
170  WallCondition<TDim,TNumNodes>(NewId,pGeometry,pProperties)
171  {
172  }
173 
176  WallCondition<TDim,TNumNodes>(rOther)
177  {
178  }
179 
182 
183 
187 
190  {
191  Condition::operator=(rOther);
192 
193  return *this;
194  }
195 
199 
201 
206  Condition::Pointer Create(IndexType NewId, NodesArrayType const& ThisNodes, PropertiesType::Pointer pProperties) const override
207  {
208  return Kratos::make_intrusive<WallConditionDiscontinuous>(NewId, this->GetGeometry().Create(ThisNodes), pProperties);
209  }
210 
211 
212 
213  Condition::Pointer Create(IndexType NewId, Condition::GeometryType::Pointer pGeom, PropertiesType::Pointer pProperties) const override
214  {
215  return Kratos::make_intrusive<WallConditionDiscontinuous>(NewId, pGeom, pProperties);
216  }
217 
218 
220 
225  void CalculateLocalSystem(MatrixType& rLeftHandSideMatrix,
226  VectorType& rRightHandSideVector,
227  const ProcessInfo& rCurrentProcessInfo) override
228  {
229  const ProcessInfo& r_process_info = rCurrentProcessInfo;
230  unsigned int step = r_process_info[FRACTIONAL_STEP];
231  if ( step == 1)
232  {
233  // Initialize local contributions
234  const SizeType LocalSize = TDim * TNumNodes;
235 
236  if (rLeftHandSideMatrix.size1() != LocalSize)
237  rLeftHandSideMatrix.resize(LocalSize,LocalSize);
238  if (rRightHandSideVector.size() != LocalSize)
239  rRightHandSideVector.resize(LocalSize);
240 
241  noalias(rLeftHandSideMatrix) = ZeroMatrix(LocalSize,LocalSize);
242  noalias(rRightHandSideVector) = ZeroVector(LocalSize);
243 
244  this->ApplyInflowCondition(rLeftHandSideMatrix,rRightHandSideVector);
245 
246  this->ApplyWallLaw(rLeftHandSideMatrix,rRightHandSideVector);
247  }
248  else if(step == 5)
249  {
250  // Initialize local contributions
251  const SizeType LocalSize = TNumNodes;
252 
253  if (rLeftHandSideMatrix.size1() != LocalSize)
254  rLeftHandSideMatrix.resize(LocalSize,LocalSize);
255  if (rRightHandSideVector.size() != LocalSize)
256  rRightHandSideVector.resize(LocalSize);
257 
258  noalias(rLeftHandSideMatrix) = ZeroMatrix(LocalSize,LocalSize);
259  noalias(rRightHandSideVector) = ZeroVector(LocalSize);
260 
261  if(!this->Is(SLIP) )
262  {
263  const GeometryType& rGeom = this->GetGeometry();
265  const unsigned int NumGauss = IntegrationPoints.size();
266  Vector GaussWeights = ZeroVector(NumGauss);
267 
269 
270  array_1d<double,3> Normal;
271  this->CalculateNormal(Normal); //this already contains the area
272  double A = norm_2(Normal);
273  Normal /= A;
274 
275  for (unsigned int g = 0; g < NumGauss; g++)
276  GaussWeights[g] = 2.0*A * IntegrationPoints[g].Weight();
277 
278  for (unsigned int g = 0; g < NumGauss; g++)
279  {
280  double Weight = GaussWeights[g];
281 
282  array_1d<double,3> vgauss = N(0,g)*rGeom[0].FastGetSolutionStepValue(VELOCITY);
283  for (unsigned int iNode = 1; iNode < TNumNodes; ++iNode)
284  {
285  vgauss += N(iNode,g)*rGeom[iNode].FastGetSolutionStepValue(VELOCITY);
286  }
287 
288  double aux =inner_prod(Normal,vgauss);
289 
290  for (unsigned int iNode = 0; iNode < TNumNodes; ++iNode)
291  {
292  rRightHandSideVector[iNode] -= N(iNode,g)*Weight*aux;
293  }
294  }
295  }
296 
297 
298 
299  // Initialize local contributions
300 // const SizeType LocalSize = TNumNodes;
301 //
302 // if (rLeftHandSideMatrix.size1() != LocalSize)
303 // rLeftHandSideMatrix.resize(LocalSize,LocalSize);
304 // if (rRightHandSideVector.size() != LocalSize)
305 // rRightHandSideVector.resize(LocalSize);
306 //
307 // noalias(rLeftHandSideMatrix) = ZeroMatrix(LocalSize,LocalSize);
308 // noalias(rRightHandSideVector) = ZeroVector(LocalSize);
309 //
310 // if (!this->Is(SLIP))
311 // {
312 // const double N = 1.0 / static_cast<double>(TNumNodes);
313 // array_1d<double,3> rNormal;
314 // this->CalculateNormal(rNormal); //this already contains the area
315 //
316 // for (unsigned int iNode = 0; iNode < TNumNodes; ++iNode)
317 // {
318 // const array_1d<double,3>& rVelocity = this->GetGeometry()[iNode].FastGetSolutionStepValue(VELOCITY);
319 // for (unsigned int d = 0; d < TDim; ++d)
320 // rRightHandSideVector[iNode] -= N*rVelocity[d]*rNormal[d];
321 // }
322 // }
323  }
324  else
325  {
326  if (rLeftHandSideMatrix.size1() != 0)
327  rLeftHandSideMatrix.resize(0,0,false);
328 
329  if (rRightHandSideVector.size() != 0)
330  rRightHandSideVector.resize(0,false);
331  }
332  }
333 
334 
336  int Check(const ProcessInfo& rCurrentProcessInfo) const override
337  {
338  KRATOS_TRY;
339 
340  int Check = Condition::Check(rCurrentProcessInfo); // Checks id > 0 and area > 0
341 
342  if (Check != 0)
343  {
344  return Check;
345  }
346  else
347  {
348  // Checks on nodes
349  // Check that the element's nodes contain all required SolutionStepData and Degrees of freedom
350  for(unsigned int i=0; i<this->GetGeometry().size(); ++i)
351  {
352 
353  if(this->GetGeometry()[i].SolutionStepsDataHas(VELOCITY) == false)
354  KRATOS_THROW_ERROR(std::invalid_argument,"missing VELOCITY variable on solution step data for node ",this->GetGeometry()[i].Id());
355  if(this->GetGeometry()[i].SolutionStepsDataHas(MESH_VELOCITY) == false)
356  KRATOS_THROW_ERROR(std::invalid_argument,"missing MESH_VELOCITY variable on solution step data for node ",this->GetGeometry()[i].Id());
357  if(this->GetGeometry()[i].SolutionStepsDataHas(NORMAL) == false)
358  KRATOS_THROW_ERROR(std::invalid_argument,"missing NORMAL variable on solution step data for node ",this->GetGeometry()[i].Id());
359  if(this->GetGeometry()[i].HasDofFor(VELOCITY_X) == false ||
360  this->GetGeometry()[i].HasDofFor(VELOCITY_Y) == false ||
361  this->GetGeometry()[i].HasDofFor(VELOCITY_Z) == false)
362  KRATOS_THROW_ERROR(std::invalid_argument,"missing VELOCITY component degree of freedom on node ",this->GetGeometry()[i].Id());
363  }
364 
365  return Check;
366  }
367 
368  KRATOS_CATCH("");
369  }
370 
372 
377  void ApplyInflowCondition(MatrixType& rLocalMatrix,
378  VectorType& rLocalVector)
379  {
380  if (!this->Is(SLIP))
381  {
382  const unsigned int LocalSize = TNumNodes;
383  const GeometryType& rGeom = this->GetGeometry();
385  const unsigned int NumGauss = IntegrationPoints.size();
386  Vector GaussWeights = ZeroVector(NumGauss);
387 
389 
390  array_1d<double,3> Normal;
391  this->CalculateNormal(Normal); //this already contains the area
392  double A = std::sqrt(Normal[0]*Normal[0]+Normal[1]*Normal[1]+Normal[2]*Normal[2]);
393  Normal /= A;
394 
395  for (unsigned int g = 0; g < NumGauss; g++)
396  GaussWeights[g] = 2.0*A * IntegrationPoints[g].Weight();
397 
398  for (unsigned int g = 0; g < NumGauss; g++)
399  {
400  Vector N = row(NContainer,g);
401  double Weight = GaussWeights[g];
402 
403  // Neumann boundary condition
404  // for (unsigned int i = 0; i < TNumNodes; i++)
405  // {
406  // //unsigned int row = i*LocalSize;
407  // const NodeType& rConstNode = this->GetGeometry()[i];
408  // if ( rConstNode.IsFixed(PRESSURE)==true)
409  // {
410  // const double pext = rConstNode.FastGetSolutionStepValue(PRESSURE);
411  // for (unsigned int j = 0; j < TNumNodes; j++)
412  // {
413  // unsigned int row = j*LocalSize;
414  // for (unsigned int d = 0; d < TDim;d++)
415  // rLocalVector[row+d] -= Weight*N[j]*N[i]*pext*Normal[d];
416  // }
417  // }
418  // }
419 
420  // Velocity inflow correction
422  double Density = 0.0;
423 
424  for (unsigned int i = 0; i < TNumNodes; i++)
425  {
426  const NodeType& rConstNode = this->GetGeometry()[i];
427  Vel += N[i]*rConstNode.FastGetSolutionStepValue(VELOCITY);
428  Density += N[i]*rConstNode.FastGetSolutionStepValue(DENSITY);
429  }
430 
431  double Proj = Vel[0]*Normal[0] + Vel[1]*Normal[1] + Vel[2]*Normal[2];
432 
433  if (Proj < 0)
434  {
435  const double W = Weight*Density*Proj;
436  for (unsigned int i = 0; i < TNumNodes; i++)
437  {
438  double row = i*LocalSize;
439  for (unsigned int j = 0; j < TNumNodes; j++)
440  {
441  double col = j*LocalSize;
442  const array_1d<double,3>& rVel = this->GetGeometry()[j].FastGetSolutionStepValue(VELOCITY);
443  for (unsigned int d = 0; d < TDim; d++)
444  {
445  double Tij = W*N[i]*N[j];
446  rLocalMatrix(row+d,col+d) -= Tij;
447  rLocalVector[row+d] += Tij*rVel[d];
448  }
449  }
450  }
451  }
452  }
453  }
454  }
455 
456 
458 
463  const ProcessInfo& rCurrentProcessInfo) const override;
464 
465 
467 
471  void GetDofList(DofsVectorType& ConditionDofList,
472  const ProcessInfo& CurrentProcessInfo) const override;
473 
474 
478 
479 
483 
484 
488 
490  std::string Info() const override
491  {
492  std::stringstream buffer;
493  this->PrintInfo(buffer);
494  return buffer.str();
495  }
496 
498  void PrintInfo(std::ostream& rOStream) const override
499  {
500  rOStream << "WallConditionDiscontinuous" << TDim << "D #" << this->Id();
501  }
502 
504  void PrintData(std::ostream& rOStream) const override
505  {
506  this->pGetGeometry()->PrintData(rOStream);
507  }
508 
509 
513 
514 
516 
517 protected:
520 
521 
525 
526 
530 
531 
535 
536 
537 
538 
539 
543 
544 
548 
549 
553 
554 
556 
557 private:
560 
561 
565 
566 
570 
571  friend class Serializer;
572 
573  void save(Serializer& rSerializer) const override
574  {
577  }
578 
579  void load(Serializer& rSerializer) override
580  {
583  }
584 
588 
589 
593 
594 
598 
599 
603 
604 
608 
609 
611 
612 }; // Class WallConditionDiscontinuous
613 
614 
616 
619 
620 
624 
625 
627 template< unsigned int TDim, unsigned int TNumNodes >
628 inline std::istream& operator >> (std::istream& rIStream,
630 {
631  return rIStream;
632 }
633 
635 template< unsigned int TDim, unsigned int TNumNodes >
636 inline std::ostream& operator << (std::ostream& rOStream,
638 {
639  rThis.PrintInfo(rOStream);
640  rOStream << std::endl;
641  rThis.PrintData(rOStream);
642 
643  return rOStream;
644 }
645 
647 
649 
650 
651 } // namespace Kratos.
652 
653 #endif // KRATOS_WALL_CONDITION_DISCONTINUOUS_H
std::size_t SizeType
Definition: condition.h:94
GeometricalObject BaseType
base type: an GeometricalObject that automatically has a unique number
Definition: condition.h:71
std::vector< std::size_t > EquationIdVectorType
Definition: condition.h:98
std::vector< DofType::Pointer > DofsVectorType
Definition: condition.h:100
virtual int Check(const ProcessInfo &rCurrentProcessInfo) const
Definition: condition.h:854
Condition & operator=(Condition const &rOther)
Assignment operator.
Definition: condition.h:181
std::size_t IndexType
Definition: flags.h:74
bool Is(Flags const &rOther) const
Definition: flags.h:274
This defines the geometrical object, base definition of the element and condition entities.
Definition: geometrical_object.h:58
GeometryType::Pointer pGetGeometry()
Returns the pointer to the geometry.
Definition: geometrical_object.h:140
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
std::vector< IntegrationPointType > IntegrationPointsArrayType
Definition: geometry.h:161
const Matrix & ShapeFunctionsValues() const
Definition: geometry.h:3393
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
const IntegrationPointsArrayType & IntegrationPoints() const
Definition: geometry.h:2284
This object defines an indexed object.
Definition: indexed_object.h:54
IndexType Id() const
Definition: indexed_object.h:107
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
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
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
Implements a wall condition for the monolithic formulation.
Definition: wall_condition_discontinuous.h:96
Geometry< NodeType > GeometryType
Definition: wall_condition_discontinuous.h:108
Vector VectorType
Definition: wall_condition_discontinuous.h:112
~WallConditionDiscontinuous() override
Destructor.
Definition: wall_condition_discontinuous.h:181
WallConditionDiscontinuous(WallConditionDiscontinuous const &rOther)
Copy constructor.
Definition: wall_condition_discontinuous.h:175
PointerVectorSet< Dof< double >, IndexedObject > DofsArrayType
Definition: wall_condition_discontinuous.h:124
Condition::Pointer Create(IndexType NewId, Condition::GeometryType::Pointer pGeom, PropertiesType::Pointer pProperties) const override
Definition: wall_condition_discontinuous.h:213
Node NodeType
Definition: wall_condition_discontinuous.h:104
Properties PropertiesType
Definition: wall_condition_discontinuous.h:106
void GetDofList(DofsVectorType &ConditionDofList, const ProcessInfo &CurrentProcessInfo) const override
Returns a list of the element's Dofs.
std::vector< Dof< double >::Pointer > DofsVectorType
Definition: wall_condition_discontinuous.h:122
Geometry< NodeType >::PointsArrayType NodesArrayType
Definition: wall_condition_discontinuous.h:110
Matrix MatrixType
Definition: wall_condition_discontinuous.h:114
void CalculateLocalSystem(MatrixType &rLeftHandSideMatrix, VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo) override
Calculate wall stress term for all nodes with SLIP set.
Definition: wall_condition_discontinuous.h:225
int Check(const ProcessInfo &rCurrentProcessInfo) const override
Check that all data required by this condition is available and reasonable.
Definition: wall_condition_discontinuous.h:336
std::size_t IndexType
Definition: wall_condition_discontinuous.h:116
WallConditionDiscontinuous(IndexType NewId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties)
Constructor using Properties.
Definition: wall_condition_discontinuous.h:167
Condition::Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const override
Create a new WallConditionDiscontinuous object.
Definition: wall_condition_discontinuous.h:206
std::string Info() const override
Turn back information as a string.
Definition: wall_condition_discontinuous.h:490
void ApplyInflowCondition(MatrixType &rLocalMatrix, VectorType &rLocalVector)
Apply condition to prevent numerical problems due to flow into the domain in unexpected places.
Definition: wall_condition_discontinuous.h:377
WallConditionDiscontinuous(IndexType NewId, const NodesArrayType &ThisNodes)
Constructor using an array of nodes.
Definition: wall_condition_discontinuous.h:144
WallConditionDiscontinuous(IndexType NewId=0)
Default constructor.
Definition: wall_condition_discontinuous.h:134
std::vector< std::size_t > EquationIdVectorType
Definition: wall_condition_discontinuous.h:120
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: wall_condition_discontinuous.h:504
void EquationIdVector(EquationIdVectorType &rResult, const ProcessInfo &rCurrentProcessInfo) const override
Provides the global indices for each one of this element's local rows.
WallConditionDiscontinuous(IndexType NewId, GeometryType::Pointer pGeometry)
Constructor using Geometry.
Definition: wall_condition_discontinuous.h:155
WallConditionDiscontinuous & operator=(WallConditionDiscontinuous const &rOther)
Copy constructor.
Definition: wall_condition_discontinuous.h:189
std::size_t SizeType
Definition: wall_condition_discontinuous.h:118
KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(WallConditionDiscontinuous)
Pointer definition of WallConditionDiscontinuous.
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: wall_condition_discontinuous.h:498
Implements a wall condition for the monolithic formulation.
Definition: wall_condition.h:98
void ApplyWallLaw(MatrixType &rLocalMatrix, VectorType &rLocalVector)
Commpute the wall stress and add corresponding terms to the system contributions.
Definition: wall_condition.h:561
void CalculateNormal(array_1d< double, 3 > &An)
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_SERIALIZE_SAVE_BASE_CLASS(Serializer, BaseType)
Definition: define.h:812
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_SERIALIZE_LOAD_BASE_CLASS(Serializer, BaseType)
Definition: define.h:815
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int step
Definition: face_heat.py:88
vgauss
Definition: generate_stokes_twofluid_element.py:52
def load(f)
Definition: ode_solve.py:307
int d
Definition: ode_solve.py:397
int j
Definition: quadrature.py:648
A
Definition: sensitivityMatrix.py:70
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17