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.
derivative_recovery.h
Go to the documentation of this file.
1 //
2 // Project Name: Kratos
3 // Last Modified by: $Author: gcasas $
4 // Date: $Date: 2014-03-08 08:56:42 $
5 //
6 //
7 
8 #if !defined(KRATOS_DERIVATIVE_RECOVERY)
9 #define KRATOS_DERIVATIVE_RECOVERY
10 
11 // System includes
12 #include <string>
13 #include <iostream>
14 #include <cstdlib>
15 
16 // Project includes
17 #include "includes/define.h"
18 #include "includes/model_part.h"
20 #include "includes/kratos_flags.h"
21 #include "geometries/geometry.h"
23 #include "utilities/timer.h"
24 #include "utilities/openmp_utils.h"
26 #include "custom_functions.h"
27 
28 //Database includes
31 
34 
35 // /* External includes */
36 #ifdef _OPENMP
37 #include <omp.h>
38 #endif
39 
40 namespace Kratos
41 {
42 
45 
49 
53 
57 
61 
63 
66 template <std::size_t TDim>
67 class KRATOS_API(SWIMMING_DEM_APPLICATION) DerivativeRecovery
68 {
69 public:
74 typedef std::vector<ResultElementsContainerType> VectorResultElementsContainerType;
75 
78 typedef std::vector<ResultNodesContainerType> VectorResultNodesContainerType;
79 typedef std::vector<Node::Pointer> NodalPointersContainerType;
80 typedef ModelPart::NodesContainerType::iterator NodeIteratorType;
81 
82 typedef std::size_t ListIndexType;
85 
89 
93 
95 
96 DerivativeRecovery(ModelPart& r_model_part, Parameters& r_parameters):
97  mModelPart(r_model_part),
98  mMyCustomFunctions(),
99  mFirstGradientRecovery(true),
100  mFirstLaplacianRecovery(true),
101  mSomeCloudsDontWork(false),
102  mCalculatingTheGradient(false),
103  mCalculatingTheLaplacian(false),
104  mCalculatingGradientAndLaplacian(false),
105  mFirstTimeAppending(true)
106 {
107  mStoreFullGradient = r_parameters.GetValue("store_full_gradient_option").GetBool();
108 }
109 
112 
116 
120 
121 //***************************************************************************************************************
122 //***************************************************************************************************************
123 void AddTimeDerivative(ModelPart& r_model_part, Variable<array_1d<double, 3> >& material_derivative_container);
124 
125 void AddTimeDerivativeComponent(ModelPart& r_model_part, Variable<array_1d<double, 3> >& material_derivative_container, const int i_component);
126 
127 void RecoverGradientOfAScalar(const VariableData& origin_variable, const VariableData& destination_variable);
128 
129 template <class TScalarVariable>
130 void RecoverSuperconvergentGradient(ModelPart& r_model_part, TScalarVariable& scalar_container, Variable<array_1d<double, 3> >& gradient_container);
131 
132 void RecoverSuperconvergentMatDeriv(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_container, Variable<array_1d<double, 3> >& vector_rate_container, Variable<array_1d<double, 3> >& mat_deriv_container);
133 
134 void RecoverSuperconvergentLaplacian(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_container, Variable<array_1d<double, 3> >& laplacian_container);
135 
136 void RecoverSuperconvergentVelocityLaplacianFromGradient(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_container, Variable<array_1d<double, 3> >& laplacian_container);
137 
138 void RecoverSuperconvergentMatDerivAndLaplacian(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_container, Variable<array_1d<double, 3> >& vector_rate_container, Variable<array_1d<double, 3> >& mat_deriv_container, Variable<array_1d<double, 3> >& laplacian_container);
139 
140 void CalculateVectorMaterialDerivative(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_container, Variable<array_1d<double, 3> >& vector_rate_container, Variable<array_1d<double, 3> >& material_derivative_container);
141 
142 void RecoverLagrangianAcceleration(ModelPart& r_model_part);
143 
144 void CalculateVectorMaterialDerivativeFromGradient(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_gradient_container_x, Variable<array_1d<double, 3> >& vector_gradient_container_y, Variable<array_1d<double, 3> >& vector_gradient_container_z, Variable<array_1d<double, 3> >& vector_rate_container, Variable<array_1d<double, 3> >& material_derivative_container);
145 
146 void CalculateVectorMaterialDerivativeComponent(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_component_gradient_container, Variable<array_1d<double, 3> >& vector_rate_container, Variable<array_1d<double, 3> >& material_derivative_container);
147 
148 void CalculateVorticityFromGradient(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_gradient_container_x, Variable<array_1d<double, 3> >& vector_gradient_container_y, Variable<array_1d<double, 3> >& vector_gradient_container_z, Variable<array_1d<double, 3> >& vorticity_container);
149 
150 void CalculateVorticityContributionOfTheGradientOfAComponent(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_component_gradient_container, Variable<array_1d<double, 3> >& vorticity_container);
151 
152 template <class TScalarVariable>
153 void CalculateGradient(ModelPart& r_model_part, TScalarVariable& scalar_container, Variable<array_1d<double, 3> >& gradient_container);
154 
155 void SmoothVectorField(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_field, Variable<array_1d<double, 3> >& auxiliary_veriable);
156 
157 void CalculateVectorLaplacian(ModelPart& r_model_part, Variable<array_1d<double, 3> >& vector_container, Variable<array_1d<double, 3> >& laplacian_container);
158 
159 void CalculateVelocityLaplacianRate(ModelPart& r_model_part);
160 
161 //**************************************************************************************************************************************************
162 //**************************************************************************************************************************************************
163 
164 
168 
172 
176 
178 virtual std::string Info() const
179 {
180  return "";
181 }
182 
184 virtual void PrintInfo(std::ostream& rOStream) const {}
185 
187 virtual void PrintData(std::ostream& rOStream) const {}
188 
193 {
194  return (mElementsPartition);
195 }
196 
198 {
199  return (mNodesPartition);
200 }
201 
202 ElementsArrayType::iterator GetElementPartitionBegin(ModelPart& r_model_part, unsigned int k)
203 {
204  ElementsArrayType& pElements = r_model_part.GetCommunicator().LocalMesh().Elements();
205  return (pElements.ptr_begin() + this->GetElementPartition()[k]);
206 }
207 
208 ElementsArrayType::iterator GetElementPartitionEnd(ModelPart& r_model_part, unsigned int k)
209 {
210  ElementsArrayType& pElements = r_model_part.GetCommunicator().LocalMesh().Elements();
211  return (pElements.ptr_begin() + this->GetElementPartition()[k + 1]);
212 }
213 
214 NodesArrayType::iterator GetNodePartitionBegin(ModelPart& r_model_part, unsigned int k)
215 {
216  NodesArrayType& pNodes = r_model_part.GetCommunicator().LocalMesh().Nodes();
217  return (pNodes.ptr_begin() + this->GetNodePartition()[k]);
218 }
219 
220 NodesArrayType::iterator GetNodePartitionEnd(ModelPart& r_model_part, unsigned int k)
221 {
222  NodesArrayType& pNodes = r_model_part.GetCommunicator().LocalMesh().Nodes();
223  return (pNodes.ptr_begin() + this->GetNodePartition()[k + 1]);
224 }
226 
227 protected:
228 
231 
232 private:
233 
234 ModelPart& mModelPart;
235 CustomFunctionsCalculator<TDim> mMyCustomFunctions;
236 bool mFirstGradientRecovery;
237 bool mFirstLaplacianRecovery;
238 bool mSomeCloudsDontWork;
239 bool mCalculatingTheGradient;
240 bool mCalculatingTheLaplacian;
241 bool mCalculatingGradientAndLaplacian;
242 bool mFirstTimeAppending;
243 bool mStoreFullGradient;
244 double mLastMeasurementTime;
245 double mLastPressureVariation;
246 double mTotalVolume;
247 std::vector<double> mPressures;
248 std::vector<DenseVector<double> > mFirstRowsOfB;
249 bool mMustCalculateMaxNodalArea;
250 double mMinFluidFraction;
251 double mMaxNodalAreaInv;
252 int mCouplingType;
253 int mViscosityModificationType;
254 int mParticlesPerDepthDistance;
255 VariablesList mDEMCouplingVariables;
256 VariablesList mFluidCouplingVariables;
257 PointPointSearch::Pointer mpPointPointSearch;
258 
259 
260 // neighbour lists (for mCouplingType = 3)
261 std::vector<double> mSearchRadii; // list of nodal search radii (filter radii). It is a vector since spatial search is designed for varying radius
262 VectorResultNodesContainerType mVectorsOfNeighNodes; // list of arrays of pointers to the particle's nodal neighbours
263 VectorDistanceType mVectorsOfDistances; // list of arrays of distances to the particle's neighbours
264 VectorDistanceType mVectorsOfRadii;
265 
266 struct IsCloser{
267  bool operator()(std::pair<unsigned int, double> const& first_pair, std::pair<unsigned int, double> const& second_pair)
268  {
269  return(first_pair.second < second_pair.second || (first_pair.second == second_pair.second && first_pair.first < second_pair.first));
270  }
271 };
272 
273 void SetNeighboursAndWeights(ModelPart& r_model_part);
274 void SetNeighboursAndWeightsForTheLaplacian(ModelPart& r_model_part);
275 void OrderByDistance(Node::Pointer &p_node, GlobalPointersVector<Node >& neigh_nodes);
276 bool SetInitialNeighboursAndWeights(ModelPart& r_model_part, Node::Pointer &p_node);
277 bool SetNeighboursAndWeights(ModelPart& r_model_part, Node::Pointer& p_node);
278 double SecondDegreeTestPolynomial(const array_1d <double, 3>& coordinates);
279 double SecondDegreeGenericPolynomial(DenseMatrix<double> C, const array_1d <double, 3>& coordinates);
280 inline int Factorial(const unsigned int n);
281 bool SetWeightsAndRunLeastSquaresTest(ModelPart& r_model_part, Node::Pointer& p_node);
282 unsigned int GetNumberOfUniqueNeighbours(const int my_id, const GlobalPointersVector<Element>& my_neighbour_elements);
283 double CalculateTheMaximumDistanceToNeighbours(Node::Pointer& p_node);
284 double CalculateTheMaximumEdgeLength(ModelPart& r_model_part);
285 double CalculateTheMinumumEdgeLength(ModelPart& r_model_part);
286 
287 //**************************************************************************************************************************************************
288 //**************************************************************************************************************************************************
289 
290 
291 
295 
299 
303 
307 
311 
314 
316 
317 }; // Class DerivativeRecovery
318 
320 
323 
327 
329 template<std::size_t TDim>
330 inline std::ostream& operator << (std::ostream& rOStream,
331  const DerivativeRecovery<TDim>& rThis)
332 {
333  rThis.PrintInfo(rOStream);
334  rOStream << std::endl;
335  rThis.PrintData(rOStream);
336 
337  return rOStream;
338 }
340 
341 } // namespace Kratos.
342 
343 #endif // KRATOS_DERIVATIVE_RECOVERY defined
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
Definition: custom_functions.h:41
This class constructs nodal approximations of the derivatives of a field given a Lagrangian linear FE...
Definition: derivative_recovery.h:68
ModelPart::NodesContainerType::iterator NodeIteratorType
Definition: derivative_recovery.h:80
ElementsArrayType::iterator GetElementPartitionEnd(ModelPart &r_model_part, unsigned int k)
Definition: derivative_recovery.h:208
ElementsArrayType::ContainerType ResultElementsContainerType
Definition: derivative_recovery.h:73
NodesArrayType::ContainerType ResultNodesContainerType
Definition: derivative_recovery.h:77
DenseVector< unsigned int > mNodesPartition
Definition: derivative_recovery.h:230
SpatialSearch::VectorDistanceType VectorDistanceType
Definition: derivative_recovery.h:84
KRATOS_CLASS_POINTER_DEFINITION(DerivativeRecovery_TDim)
ModelPart::ElementsContainerType ElementsArrayType
Definition: derivative_recovery.h:72
virtual std::string Info() const
Turn back information as a stemplate<class T, std::size_t dim> tring.
Definition: derivative_recovery.h:178
DenseVector< unsigned int > & GetElementPartition()
Definition: derivative_recovery.h:192
DenseVector< unsigned int > mElementsPartition
Definition: derivative_recovery.h:229
DenseVector< unsigned int > & GetNodePartition()
Definition: derivative_recovery.h:197
std::size_t ListIndexType
Definition: derivative_recovery.h:82
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: derivative_recovery.h:187
DerivativeRecovery< TDim > DerivativeRecovery_TDim
Pointer definition of DerivativeRecovery.
Definition: derivative_recovery.h:87
NodesArrayType::iterator GetNodePartitionEnd(ModelPart &r_model_part, unsigned int k)
Definition: derivative_recovery.h:220
std::vector< ResultElementsContainerType > VectorResultElementsContainerType
Definition: derivative_recovery.h:74
DerivativeRecovery(ModelPart &r_model_part, Parameters &r_parameters)
Default constructor.
Definition: derivative_recovery.h:96
virtual ~DerivativeRecovery()
Destructor.
Definition: derivative_recovery.h:111
ElementsArrayType::iterator GetElementPartitionBegin(ModelPart &r_model_part, unsigned int k)
Definition: derivative_recovery.h:202
ModelPart::NodesContainerType NodesArrayType
Definition: derivative_recovery.h:76
std::vector< ResultNodesContainerType > VectorResultNodesContainerType
Definition: derivative_recovery.h:78
NodesArrayType::iterator GetNodePartitionBegin(ModelPart &r_model_part, unsigned int k)
Definition: derivative_recovery.h:214
std::vector< Node::Pointer > NodalPointersContainerType
Definition: derivative_recovery.h:79
SpatialSearch::DistanceType DistanceType
Definition: derivative_recovery.h:83
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: derivative_recovery.h:184
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
Definition: amatrix_interface.h:41
NodesContainerType & Nodes()
Definition: mesh.h:346
ElementsContainerType & Elements()
Definition: mesh.h:568
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Communicator & GetCommunicator()
Definition: model_part.h:1821
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
Parameters GetValue(const std::string &rEntry)
This method returns the Parameter corresponding to a certain entry.
Definition: kratos_parameters.cpp:423
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
std::vector< DistanceType > VectorDistanceType
Definition: spatial_search.h:97
std::vector< double > DistanceType
Definition: spatial_search.h:96
This class is the base of variables and variable's components which contains their common data.
Definition: variable_data.h:49
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
Holds a list of variables and their position in VariablesListDataValueContainer.
Definition: variables_list.h:50
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int C
Definition: generate_hyper_elastic_simo_taylor_neo_hookean.py:27
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int k
Definition: quadrature.py:595
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247