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.
shallow_water_utilities.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_SHALLOW_WATER_UTILITIES_H_INCLUDED
14 #define KRATOS_SHALLOW_WATER_UTILITIES_H_INCLUDED
15 
16 
17 // System includes
18 
19 
20 // External includes
21 
22 
23 // Project includes
24 #include "includes/model_part.h"
28 
29 
30 namespace Kratos
31 {
34 
37 
41 
45 
49 
53 
59 class KRATOS_API(SHALLOW_WATER_APPLICATION) ShallowWaterUtilities
60 {
61 public:
64 
65  typedef Node NodeType;
66 
68 
70 
74 
76 
80 
84 
85  void ComputeFreeSurfaceElevation(ModelPart& rModelPart);
86 
87  void ComputeHeightFromFreeSurface(ModelPart& rModelPart);
88 
89  void ComputeVelocity(ModelPart& rModelPart, bool PerformProjection = false);
90 
91  void ComputeSmoothVelocity(ModelPart& rModelPart);
92 
93  void ComputeMomentum(ModelPart& rModelPart);
94 
95  void ComputeLinearizedMomentum(ModelPart& rModelPart);
96 
97  template<bool THistorical>
98  void ComputeFroude(ModelPart& rModelPart, const double Epsilon);
99 
100  template<bool THistorical>
101  void ComputeEnergy(ModelPart& rModelPart);
102 
103  void FlipScalarVariable(Variable<double>& rOriginVariable, Variable<double>& rDestinationVariable, ModelPart& rModelPart);
104 
105  void IdentifySolidBoundary(ModelPart& rModelPart, double SeaWaterLevel, Flags SolidBoundaryFlag);
106 
107  void FlagWetElements(ModelPart& rModelPart, Flags WetFlag, double RelativeDryHeight = -1.0);
108 
109  void ExtrapolateElementalFlagToNodes(ModelPart& rModelPart, Flags Flag);
110 
111  void NormalizeVector(ModelPart& rModelPart, const Variable<array_1d<double,3>>& rVariable);
112 
113  template<class TDataType, class TVarType = Variable<TDataType>>
115  const TVarType& rVariable,
116  NodesContainerType& rNodes,
117  const double ElapsedTime,
118  const double SemiPeriod)
119  {
120  const double smooth = -std::expm1(-ElapsedTime / SemiPeriod);
121  block_for_each(rNodes, [&](NodeType& rNode){
122  TDataType& initial = rNode.FastGetSolutionStepValue(rVariable, 1);
123  TDataType& current = rNode.FastGetSolutionStepValue(rVariable);
124  TDataType increment = current - initial;
125  current = initial + smooth * increment;
126  });
127  }
128 
129  template<class TVarType>
130  void CopyVariableToPreviousTimeStep(ModelPart& rModelPart, const TVarType& rVariable)
131  {
132  block_for_each(rModelPart.Nodes(), [&](NodeType& rNode){
133  rNode.FastGetSolutionStepValue(rVariable, 1) = rNode.FastGetSolutionStepValue(rVariable);
134  });
135  }
136 
137  void SetMinimumValue(ModelPart& rModelPart, const Variable<double>& rVariable, double MinValue);
138 
142  void SetMeshZCoordinateToZero(ModelPart& rModelPart);
143 
147  void SetMeshZ0CoordinateToZero(ModelPart& rModelPart);
148 
152  void SetMeshZCoordinate(ModelPart& rModelPart, const Variable<double>& rVariable);
153 
157  void OffsetMeshZCoordinate(ModelPart& rModelPart, const double Increment);
158 
162  void SwapYZCoordinates(ModelPart& rModelPart);
163 
167  void SwapY0Z0Coordinates(ModelPart& rModelPart);
168 
172  void StoreNonHistoricalGiDNoDataIfDry(ModelPart& rModelPart, const Variable<double>& rVariable);
173 
178  {
179  block_for_each(rNodes, [&](NodeType& rNode){
180  array_1d<double,3>& r_value = rNode.FastGetSolutionStepValue(rVariable);
181  std::swap(r_value[1], r_value[2]);
182  });
183  }
184 
188  template<class TContainerType>
189  void SwapYZComponentsNonHistorical(const Variable<array_1d<double,3>>& rVariable, TContainerType& rContainer)
190  {
191  block_for_each(rContainer, [&](typename TContainerType::value_type& rEntity){
192  array_1d<double,3>& r_value = rEntity.GetValue(rVariable);
193  std::swap(r_value[1], r_value[2]);
194  });
195  }
196 
200  template<class TContainerType>
201  void OffsetIds(TContainerType& rContainer, const double Offset)
202  {
203  block_for_each(rContainer, [&](typename TContainerType::value_type& rEntity){
204  rEntity.SetId(rEntity.Id() + Offset);
205  });
206  }
207 
211  template<class TContainerType>
212  void OffsetIds(TContainerType& rContainer)
213  {
214  const std::size_t offset = rContainer.size();
215  OffsetIds(rContainer, offset);
216  }
217 
221  template<bool THistorical>
222  double ComputeL2Norm(ModelPart& rModelPart, const Variable<double>& rVariable);
223 
227  template<bool THistorical>
228  double ComputeL2NormAABB(
229  ModelPart& rModelPart,
230  const Variable<double>& rVariable,
231  Point& rLow,
232  Point& rHigh);
233 
237  template<class TContainerType>
239  TContainerType& rContainer,
240  const ProcessInfo& rProcessInfo,
241  const double RelativeDryHeight = -1.0)
242  {
243  KRATOS_ERROR_IF_NOT(rProcessInfo.Has(GRAVITY)) << "ShallowWaterUtilities::ComputeHydrostaticForces : GRAVITY is not defined in the ProcessInfo" << std::endl;
244  if (rContainer.size() > 0) {
245  const auto& r_prop = rContainer.begin()->GetProperties();
246  KRATOS_ERROR_IF_NOT(r_prop.Has(DENSITY)) << "ShallowWaterUtilities::ComputeHydrostaticForces : DENSITY is not defined in the Properties" << std::endl;
247  }
248 
249  array_1d<double,3> forces = ZeroVector(3);
250  forces = block_for_each<SumReduction<array_1d<double,3>>>(
251  rContainer, [&](typename TContainerType::value_type& rEntity){
252  array_1d<double,3> local_force = ZeroVector(3);
253  if (RelativeDryHeight >= 0.0) {
254  if (IsWet(rEntity.GetGeometry(), RelativeDryHeight)) {
255  rEntity.Calculate(FORCE, local_force, rProcessInfo);
256  }
257  } else {
258  rEntity.Calculate(FORCE, local_force, rProcessInfo);
259  }
260  return local_force;
261  }
262  );
263  return forces;
264  }
265 
267 
268 private:
269 
272 
273  void CalculateMassMatrix(Matrix& rMassMatrix, const GeometryType& rGeometry);
274 
275  template<bool THistorical>
276  double& GetValue(NodeType& rNode, const Variable<double>& rVariable);
277 
278  bool IsWet(const GeometryType& rGeometry, const double RelativeDryHeight);
279 
280  bool IsWet(const GeometryType& rGeometry, const double Height, const double RelativeDryHeight);
281 
282  bool IsWet(const double Height, const double DryHeight);
283 
285 
286 }; // Class ShallowWaterUtilities
287 
289 
292 
293 
297 
298 
300 
302 
303 } // namespace Kratos.
304 
305 #endif // KRATOS_SHALLOW_WATER_UTILITIES_H_INCLUDED defined
bool Has(const Variable< TDataType > &rThisVariable) const
Checks if the data container has a value associated with a given variable.
Definition: data_value_container.h:382
Definition: flags.h:58
Geometry base class.
Definition: geometry.h:71
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
Point class.
Definition: point.h:59
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
This class is a wrapper of useful utilities for shallow water computations.
Definition: shallow_water_utilities.h:60
void OffsetIds(TContainerType &rContainer)
Offset the ids of the given container for visualization purpose in GiD.
Definition: shallow_water_utilities.h:212
void SwapYZComponents(const Variable< array_1d< double, 3 >> &rVariable, NodesContainerType &rNodes)
Swap the Y and Z components of a vector variable.
Definition: shallow_water_utilities.h:177
ModelPart::NodesContainerType NodesContainerType
Definition: shallow_water_utilities.h:69
Geometry< NodeType > GeometryType
Definition: shallow_water_utilities.h:67
void OffsetIds(TContainerType &rContainer, const double Offset)
Offset the ids of the given container for visualization purpose in GiD.
Definition: shallow_water_utilities.h:201
KRATOS_CLASS_POINTER_DEFINITION(ShallowWaterUtilities)
array_1d< double, 3 > ComputeHydrostaticForces(TContainerType &rContainer, const ProcessInfo &rProcessInfo, const double RelativeDryHeight=-1.0)
Compute the horizontal hydrostatic pressures.
Definition: shallow_water_utilities.h:238
void SmoothHistoricalVariable(const TVarType &rVariable, NodesContainerType &rNodes, const double ElapsedTime, const double SemiPeriod)
Definition: shallow_water_utilities.h:114
Node NodeType
Definition: shallow_water_utilities.h:65
void SwapYZComponentsNonHistorical(const Variable< array_1d< double, 3 >> &rVariable, TContainerType &rContainer)
Swap the Y and Z components of a vector variable.
Definition: shallow_water_utilities.h:189
void CopyVariableToPreviousTimeStep(ModelPart &rModelPart, const TVarType &rVariable)
Definition: shallow_water_utilities.h:130
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
array_1d< double, Dim > ComputeVelocity(const Element &rElement)
Definition: potential_flow_utilities.cpp:112
Parameters GetValue(Parameters &rParameters, const std::string &rEntry)
Definition: add_kratos_parameters_to_python.cpp:53
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
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
subroutine initial(STRESS, T, DSTRAN, DEPS, NTENS, NDI, NSHR)
Definition: TensorModule.f:377