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.
flow_rate_slip_utility.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: Miguel Maso Sotomayor
11 //
12 
13 #ifndef KRATOS_FLOW_RATE_SLIP_UTILITY_H_INCLUDED
14 #define KRATOS_FLOW_RATE_SLIP_UTILITY_H_INCLUDED
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
23 
24 namespace Kratos
25 {
28 
31 
35 
39 
43 
47 
52 template<class TLocalMatrixType, class TLocalVectorType, class TValueType>
54  : public CoordinateTransformationUtils<TLocalMatrixType,TLocalVectorType,TValueType>
55 {
56 public:
59 
62 
64 
65  typedef std::size_t SizeType;
66 
67  typedef Node NodeType;
68 
70 
74 
76  FlowRateSlipUtility() : BaseType(2,3,SLIP) {}
77 
79  virtual ~FlowRateSlipUtility() {}
80 
84 
88 
99  virtual void ApplySlipCondition(
100  TLocalMatrixType& rLocalMatrix,
101  TLocalVectorType& rLocalVector,
102  GeometryType& rGeometry) const override
103  {
104  const SizeType LocalSize = rLocalVector.size(); // We expect this to work both with elements and conditions
105 
106  if (LocalSize > 0)
107  {
108  for (SizeType it_node = 0; it_node < rGeometry.PointsNumber(); ++it_node)
109  {
110  if (this->IsSlip(rGeometry[it_node]))
111  {
112  // We fix the first dof (normal velocity) for each rotated block
113  SizeType j = it_node * BaseType::GetBlockSize();
114 
115  array_1d<double,3> vel = rGeometry[it_node].FastGetSolutionStepValue(MOMENTUM);
116  array_1d<double,3> n = rGeometry[it_node].FastGetSolutionStepValue(NORMAL);
117  this->Normalize(n);
118 
119  for (SizeType i = 0; i < j; ++i) // Skip term (i,i)
120  {
121  rLocalMatrix(i,j) = 0.0;
122  rLocalMatrix(j,i) = 0.0;
123  }
124  for (SizeType i = j+1; i < LocalSize; ++i)
125  {
126  rLocalMatrix(i,j) = 0.0;
127  rLocalMatrix(j,i) = 0.0;
128  }
129 
130  rLocalVector(j) = - inner_prod(n, vel);
131  rLocalMatrix(j,j) = 1.0;
132  }
133  }
134  }
135  }
136 
142  virtual void ApplySlipCondition(
143  TLocalVectorType& rLocalVector,
144  GeometryType& rGeometry) const override
145  {
146  if (rLocalVector.size() > 0)
147  {
148  for (SizeType it_node = 0; it_node < rGeometry.PointsNumber(); ++it_node)
149  {
150  if (this->IsSlip(rGeometry[it_node]))
151  {
152  // We fix the first dof (normal velocity) for each rotated block
153  SizeType j = it_node * BaseType::GetBlockSize();
154 
155  array_1d<double,3> vel = rGeometry[it_node].FastGetSolutionStepValue(MOMENTUM);
156  array_1d<double,3> n = rGeometry[it_node].FastGetSolutionStepValue(NORMAL);
157  this->Normalize(n);
158 
159  rLocalVector[j] = inner_prod(n, vel);
160  }
161  }
162  }
163  }
164 
170  virtual void RotateVelocities(ModelPart& rModelPart) const override
171  {
172  struct TLS {
173  TLocalVectorType vel;
174  TLocalVectorType tmp;
175  };
176  TLS tls;
177  tls.vel.resize(BaseType::GetDomainSize());
178  tls.tmp.resize(BaseType::GetDomainSize());
179 
180  block_for_each(rModelPart.Nodes(), tls, [&](NodeType& rNode, TLS& rTLS){
181  if (this->IsSlip(rNode))
182  {
183  // For shallow water problems, domain size is always 2
184  BoundedMatrix<double,2,2> rot;
185  BaseType::LocalRotationOperatorPure(rot, rNode);
186 
187  array_1d<double,3>& r_velocity = rNode.FastGetSolutionStepValue(MOMENTUM);
188  for(SizeType i = 0; i < 2; i++) {
189  rTLS.vel[i] = r_velocity[i];
190  }
191  noalias(rTLS.tmp) = prod(rot, rTLS.vel);
192  for(SizeType i = 0; i < 2; i++) {
193  r_velocity[i] = rTLS.tmp[i];
194  }
195  }
196  });
197  }
198 
204  virtual void RecoverVelocities(ModelPart& rModelPart) const override
205  {
206  struct TLS {
207  TLocalVectorType vel;
208  TLocalVectorType tmp;
209  };
210  TLS tls;
211  tls.vel.resize(BaseType::GetDomainSize());
212  tls.tmp.resize(BaseType::GetDomainSize());
213 
214  block_for_each(rModelPart.Nodes(), tls, [&](NodeType& rNode, TLS& rTLS){
215  if( this->IsSlip(rNode) )
216  {
217  // For shallow water problems, domain size is always 2
218  BoundedMatrix<double,2,2> rot;
219  BaseType::LocalRotationOperatorPure(rot, rNode);
220 
221  array_1d<double,3>& r_velocity = rNode.FastGetSolutionStepValue(MOMENTUM);
222  for(SizeType i = 0; i < 2; i++) {
223  rTLS.vel[i] = r_velocity[i];
224  }
225  noalias(rTLS.tmp) = prod(trans(rot), rTLS.vel);
226  for(SizeType i = 0; i < 2; i++) {
227  r_velocity[i] = rTLS.tmp[i];
228  }
229  }
230  });
231  }
232 
236 
240 
244 
248  virtual std::string Info() const override
249  {
250  std::stringstream buffer;
251  buffer << "FlowRateSlipUtility";
252  return buffer.str();
253  }
254 
258  virtual void PrintInfo(std::ostream& rOStream) const override
259  {
260  rOStream << "FlowRateSlipUtility";
261  }
262 
266 
267 
269 
270 private:
273 
275  // FlowRateSlipUtility& operator=(FlowRateSlipUtility const& rOther) {}
276 
278  // FlowRateSlipUtility(FlowRateSlipUtility const& rOther) {}
279 
281 
282 }; // Class FlowRateSlipUtility
283 
285 
288 
292 
294 template<class TLocalMatrixType, class TLocalVectorType, class TValueType>
295 inline std::istream& operator >> (
296  std::istream& rIStream,
298 {
299  return rIStream;
300 }
301 
303 template<class TLocalMatrixType, class TLocalVectorType, class TValueType>
304 inline std::ostream& operator << (
305  std::ostream& rOStream,
307 {
308  rThis.PrintInfo(rOStream);
309  rOStream << std::endl;
310  rThis.PrintData(rOStream);
311 
312  return rOStream;
313 }
315 
317 
318 } // namespace Kratos.
319 
320 #endif // KRATOS_FLOW_RATE_SLIP_UTILITY_H_INCLUDED defined
Definition: coordinate_transformation_utilities.h:57
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: coordinate_transformation_utilities.h:732
double Normalize(TVectorType &rThis) const
Normalize a vector.
Definition: coordinate_transformation_utilities.h:994
bool IsSlip(const Node &rNode) const
Definition: coordinate_transformation_utilities.h:983
unsigned int GetBlockSize() const
Definition: coordinate_transformation_utilities.h:1014
unsigned int GetDomainSize() const
Definition: coordinate_transformation_utilities.h:1009
Tools to apply slip conditions @detail A utility to rotate the local contributions of certain nodes t...
Definition: flow_rate_slip_utility.h:55
FlowRateSlipUtility()
Default constructor.
Definition: flow_rate_slip_utility.h:76
virtual ~FlowRateSlipUtility()
Destructor.
Definition: flow_rate_slip_utility.h:79
virtual void RotateVelocities(ModelPart &rModelPart) const override
Transform nodal velocities to the rotated coordinates (aligned with each node's normal)
Definition: flow_rate_slip_utility.h:170
Geometry< NodeType > GeometryType
Definition: flow_rate_slip_utility.h:69
virtual std::string Info() const override
Definition: flow_rate_slip_utility.h:248
virtual void ApplySlipCondition(TLocalVectorType &rLocalVector, GeometryType &rGeometry) const override
RHS only version of ApplySlipCondition.
Definition: flow_rate_slip_utility.h:142
Node NodeType
Definition: flow_rate_slip_utility.h:67
virtual void PrintInfo(std::ostream &rOStream) const override
Definition: flow_rate_slip_utility.h:258
std::size_t SizeType
Definition: flow_rate_slip_utility.h:65
virtual void ApplySlipCondition(TLocalMatrixType &rLocalMatrix, TLocalVectorType &rLocalVector, GeometryType &rGeometry) const override
Apply slip boundary conditions to the rotated local contributions. @detail This function takes the lo...
Definition: flow_rate_slip_utility.h:99
KRATOS_CLASS_POINTER_DEFINITION(FlowRateSlipUtility)
Pointer definition of FlowRateSlipUtility.
CoordinateTransformationUtils< TLocalMatrixType, TLocalVectorType, TValueType > BaseType
Definition: flow_rate_slip_utility.h:63
virtual void RecoverVelocities(ModelPart &rModelPart) const override
Definition: flow_rate_slip_utility.h:204
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
std::istream & operator>>(std::istream &rIStream, FlowRateSlipUtility< TLocalMatrixType, TLocalVectorType, TValueType > &rThis)
input stream function
Definition: flow_rate_slip_utility.h:295
std::ostream & operator<<(std::ostream &rOStream, const FlowRateSlipUtility< TLocalMatrixType, TLocalVectorType, TValueType > &rThis)
output stream function
Definition: flow_rate_slip_utility.h:304
double GetDomainSize(const EntityPoint< TEntityType > &rPoint, Expression const *const pExpression)
Definition: explicit_filter.cpp:89
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
vel
Definition: pure_conduction.py:76
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17