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.
residualbased_eulerian_convdiff_strategy.h
Go to the documentation of this file.
1 // KRATOS ___ ___ _ ___ __ ___ ___ ___ ___
2 // / __/ _ \| \| \ \ / /__| \_ _| __| __|
3 // | (_| (_) | .` |\ V /___| |) | || _|| _|
4 // \___\___/|_|\_| \_/ |___/___|_| |_| APPLICATION
5 //
6 // License: BSD License
7 // Kratos default license: kratos/license.txt
8 //
9 // Main authors: Riccardo Rossi
10 //
11 
12 #if !defined(KRATOS_RESIDUALBASED_EULERIAN_CONVECTION_DIFFUSION_STRATEGY )
13 #define KRATOS_RESIDUALBASED_EULERIAN_CONVECTION_DIFFUSION_STRATEGY
14 
15 
16 /* System includes */
17 
18 
19 /* External includes */
20 
21 /* Project includes */
22 #include "includes/define.h"
23 #include "containers/model.h"
24 #include "includes/model_part.h"
31 //#include "custom_utilities/convection_diffusion_settings.h"
32 
33 
34 
35 namespace Kratos
36 {
37 
64 
86 template<class TSparseSpace,
87  class TDenseSpace,
88  class TLinearSolver
89  >
91  : public ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>
92 {
93 public:
99 
101 
102  typedef typename BaseType::TDataType TDataType;
103 
104  //typedef typename BaseType::DofSetType DofSetType;
105 
107 
109 
111 
113 
115 
116 
117 
134  typename TLinearSolver::Pointer pNewLinearSolver,
135  bool ReformDofAtEachIteration = false,
136  int dimension = 3
137  )
138  :
139  ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>(model_part,false),
140  mrModelPart(model_part)
141  {
142  KRATOS_TRY
143 
145  mdimension = dimension;
146  mOldDt = 0.00;
147 
148  //ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
149  //ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
150  //(mpConvectionModelPart->GetProcessInfo()).GetValue(CONVECTION_DIFFUSION_SETTINGS) = my_settings;
151  Check();
152 
153 
154  //initializing fractional velocity solution step
155  typedef Scheme< TSparseSpace, TDenseSpace > SchemeType;
156  typename SchemeType::Pointer pscheme = typename SchemeType::Pointer
158 
159  bool CalculateReactions = false;
160  bool CalculateNormDxFlag = true;
161 
162  //choosing the solving strategy
163 // mstep1 = typename BaseType::Pointer(
164 // new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver >
165 // (model_part,pscheme,pNewLinearSolver,CalculateReactions,ReformDofAtEachIteration,CalculateNormDxFlag) );
166 // mstep1->SetEchoLevel(2);
167 
168 
169  typedef typename BuilderAndSolver<TSparseSpace,TDenseSpace,TLinearSolver>::Pointer BuilderSolverTypePointer;
170 
171  //const Variable<double>& rUnknownVar= my_settings->GetUnknownVariable();
172  //BuilderSolverTypePointer componentwise_build = BuilderSolverTypePointer(new ResidualBasedEliminationBuilderAndSolverComponentwise<TSparseSpace,TDenseSpace,TLinearSolver,Variable<double> > (pNewLinearSolver,rUnknownVar) );
173  //mstep1 = typename BaseType::Pointer( new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver > (*mpConvectionModelPart,pscheme,pNewLinearSolver,componentwise_build,CalculateReactions,ReformDofAtEachIteration,CalculateNormDxFlag) );
174 
175  BuilderSolverTypePointer pBuilderSolver = BuilderSolverTypePointer(new ResidualBasedBlockBuilderAndSolver<TSparseSpace,TDenseSpace,TLinearSolver>(pNewLinearSolver) );
176  mstep1 = typename BaseType::Pointer( new ResidualBasedLinearStrategy<TSparseSpace,TDenseSpace,TLinearSolver >(
177  *mpConvectionModelPart,
178  pscheme,
179  pBuilderSolver,
180  CalculateReactions,
182  CalculateNormDxFlag));
183 
184  mstep1->SetEchoLevel(2);
185 
186  KRATOS_CATCH("")
187  }
188 
189 
190 
194  {
195  Model& current_model = mrModelPart.GetModel();
196  current_model.DeleteModelPart("ConvDiffPart");
197  }
198 
202  //*********************************************************************************
203  //**********************************************************************
204  double Solve() override
205  {
206  KRATOS_TRY
207 
208  //calculate the BDF coefficients
209  //careful. Using information from the currentprocessinfo of the original model part (not the convection model part)
210  //ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
211  //double Dt = rCurrentProcessInfo[DELTA_TIME];
212  //int stationary= rCurrentProcessInfo[STATIONARY];
213 
214  //SOLVING THE PROBLEM
215  double Dp_norm = mstep1->Solve();
216 
217  return Dp_norm;
218  KRATOS_CATCH("")
219  }
220 
221 
222 
223  void SetEchoLevel(int Level) override
224  {
225  mstep1->SetEchoLevel(Level);
226  }
227 
228  void Clear() override
229  {
230  mstep1->Clear();
231  }
232 
233  int Check() override
234  {
235  KRATOS_TRY
236  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
237  if (rCurrentProcessInfo.Has(CONVECTION_DIFFUSION_SETTINGS)==false)
238  KRATOS_ERROR << "no CONVECTION_DIFFUSION_SETTINGS in model_part" << std::endl;
239  //std::cout << "ConvDiff::Check(). If crashes, check CONVECTION_DIFFUSION_SETTINGS is defined" << std::endl;
240 
241  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
242 
243  //DENSITY VARIABLE
244  if(my_settings->IsDefinedDensityVariable()==true)
245  {
246  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetDensityVariable()) == false)
247  KRATOS_ERROR << "ConvDiffSettings: Density Variable defined but not contained in the model part" << std::endl;
248  }
249  else
250  std::cout << "No density variable assigned for ConvDiff. Assuming density=1" << std::endl;
251 
252  //DIFFUSION VARIABLE
253  if(my_settings->IsDefinedDiffusionVariable()==true)
254  {
255  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetDiffusionVariable()) == false)
256  KRATOS_ERROR << "ConvDiffSettings: Diffusion Variable defined but not contained in the model part" << std::endl;
257  }
258  else
259  std::cout << "No diffusion variable assigned for ConvDiff. Assuming diffusivity=0" << std::endl;
260 
261  //UNKNOWN VARIABLE
262  if(my_settings->IsDefinedUnknownVariable()==true)
263  {
264  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetUnknownVariable()) == false)
265  KRATOS_ERROR << "ConvDiffSettings: Unknown Variable defined but not contained in the model part" << std::endl;
266  }
267  else
268  KRATOS_ERROR << "ConvDiffSettings: Unknown Variable not defined!" << std::endl;
269 
270  //VOLUME SOURCE VARIABLE
271  if(my_settings->IsDefinedVolumeSourceVariable()==true)
272  {
273  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetVolumeSourceVariable()) == false)
274  KRATOS_ERROR << "ConvDiffSettings: VolumeSource Variable defined but not contained in the model part" << std::endl;
275  }
276  else
277  std::cout << "No VolumeSource variable assigned for ConvDiff. Assuming VolumeSource=0" << std::endl;
278 
279 
280  //SURFACE SOURCE VARIABLE
281  //if(my_settings->IsDefinedSurfaceSourceVariable()==true)
282  //{
283  // if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetSurfaceSourceVariable()) == false)
284  // KRATOS_ERROR << "ConvDiffSettings: SurfaceSource Variable defined but not contained in the model part" << std::endl;
285  //}
286  //else
287  // std::cout << "No SurfaceSource variable assigned for ConvDiff. Assuming SurfaceSource=0" << std::endl;
288  if(my_settings->IsDefinedSurfaceSourceVariable()==true)
289  KRATOS_ERROR << "ConvDiffSettings: SurfaceSource not yet implemented" << std::endl;
290 
291  //PROJECTION VARIABLE
292  //if(my_settings->IsDefinedProjectionVariable()==true)
293  //{
294  // if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetProjectionVariable()) == false)
295  // KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Projection Variable defined but not contained in the model part", "");
296  //}
297  //else
298  // std::cout << "No Projection variable assigned for ConvDiff. Assuming Projection=0" << std::endl;
299  if(my_settings->IsDefinedProjectionVariable()==true)
300  KRATOS_ERROR << "ConvDiffSettings: ProjectionVariable not useed. Remove it" << std::endl;
301 
302  //CONVECTION VELOCITY VARIABLE
303  //CURRENTLY WE ARE USING (VELOCITY -MESH_VELOCITY) TO CONVECT, so the ConvectionVariable must not be used:
304  //if(my_settings->IsDefinedConvectionVariable()==true)
305  //{
306  // if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetConvectionVariable()) == false)
307  // KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Convection Variable defined but not contained in the model part", "");
308  //}
309  //else
310  // std::cout << "No Projection variable assigned for ConvDiff. Assuming Convection=0" << std::endl;
311  if(my_settings->IsDefinedConvectionVariable()==true)
312  KRATOS_ERROR << "ConvDiffSettings: ConvectionVariable not used. Use VelocityVariable instead" << std::endl;
313 
314  //MESH VELOCITY VARIABLE
315  if(my_settings->IsDefinedMeshVelocityVariable()==true)
316  {
317  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetMeshVelocityVariable()) == false)
318  KRATOS_ERROR << "ConvDiffSettings: MeshVelocity Variable defined but not contained in the model part" << std::endl;
319  }
320  else
321  std::cout << "No MeshVelocity variable assigned for ConvDiff. Assuming MeshVelocity=0" << std::endl;
322 
323  //VELOCITY VARIABLE
324  if(my_settings->IsDefinedVelocityVariable()==true)
325  {
326  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetVelocityVariable()) == false)
327  KRATOS_ERROR << "ConvDiffSettings: Velocity Variable defined but not contained in the model part" << std::endl;
328  }
329  else
330  std::cout << "No Velocity variable assigned for ConvDiff. Assuming Velocity=0" << std::endl;
331 
332  //TRANSFER COEFFICIENT VARIABLE
333  //if(my_settings->IsDefinedTransferCoefficientVariable()==true)
334  //{
335  // if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetTransferCoefficientVariable()) == false)
336  // KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: TransferCoefficient Variable defined but not contained in the model part", "");
337  //}
338  //else
339  // std::cout << "No TransferCoefficient variable assigned for ConvDiff. Assuming TransferCoefficient=0" << std::endl;
340  if(my_settings->IsDefinedTransferCoefficientVariable()==true)
341  KRATOS_ERROR << "ConvDiffSettings: TransferCoefficient not yet implemented" << std::endl;
342 
343  //SPECIFIC HEAT VARIABLE
344  if(my_settings->IsDefinedSpecificHeatVariable()==true)
345  {
346  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetSpecificHeatVariable()) == false)
347  KRATOS_ERROR << "ConvDiffSettings: SpecificHeat Variable defined but not contained in the model part" << std::endl;
348  }
349  else
350  std::cout << "No SpecificHeat variable assigned for ConvDiff. Assuming SpecificHeat=1" << std::endl;
351 
352  return 0;
353 
354  KRATOS_CATCH("")
355 
356  }
357 
385 protected:
404  virtual void GenerateMeshPart(int dimension)
405  {
406  Model& current_model = mrModelPart.GetModel();
407  if(current_model.HasModelPart("ConvDiffPart"))
408  current_model.DeleteModelPart("ConvDiffPart");
409 
410  // Generate
411  mpConvectionModelPart = &(current_model.CreateModelPart("ConvDiffPart"));
412 
413 
414  mpConvectionModelPart->SetProcessInfo( BaseType::GetModelPart().pGetProcessInfo() );
415  mpConvectionModelPart->SetBufferSize( BaseType::GetModelPart().GetBufferSize());
416 
417  //initializing mesh nodes
418  mpConvectionModelPart->Nodes() = BaseType::GetModelPart().Nodes();
419 
420  //creating mesh elements
421  ModelPart::ElementsContainerType& MeshElems = mpConvectionModelPart->Elements();
422  Element::Pointer pElem;
423 
424  if(dimension == 2)
425  {
426  for(ModelPart::ElementsContainerType::iterator it= BaseType::GetModelPart().ElementsBegin(); it != BaseType::GetModelPart().ElementsEnd(); ++it)
427  {
428  Element::GeometryType& rGeom = it->GetGeometry();
429  const unsigned int& NumNodes = rGeom.size();
430 
431  if (NumNodes == 3)
432  {
433  pElem = Element::Pointer(new EulerianConvectionDiffusionElement<2,3>(
434  (*it).Id(),
435  (*it).pGetGeometry(),
436  (*it).pGetProperties() ) );
437  MeshElems.push_back(pElem);
438  }
439  else if(NumNodes == 4)
440  {
441  pElem = Element::Pointer(new EulerianConvectionDiffusionElement<2,4>(
442  (*it).Id(),
443  (*it).pGetGeometry(),
444  (*it).pGetProperties() ) );
445  MeshElems.push_back(pElem);
446  }
447  }
448  }
449  else
450  {
451  for(ModelPart::ElementsContainerType::iterator it= BaseType::GetModelPart().ElementsBegin(); it != BaseType::GetModelPart().ElementsEnd(); ++it)
452  {
453  Element::GeometryType& rGeom = it->GetGeometry();
454  const unsigned int& NumNodes = rGeom.size();
455 
456  if (NumNodes == 4)
457  {
458  pElem = Element::Pointer(new EulerianConvectionDiffusionElement<3,4>(
459  (*it).Id(),
460  (*it).pGetGeometry(),
461  (*it).pGetProperties() ) );
462  MeshElems.push_back(pElem);
463  }
464  else if(NumNodes == 8)
465  {
466  pElem = Element::Pointer(new EulerianConvectionDiffusionElement<3,8>(
467  (*it).Id(),
468  (*it).pGetGeometry(),
469  (*it).pGetProperties() ) );
470  MeshElems.push_back(pElem);
471  }
472  }
473  }
474  }
475 
494 private:
502  ModelPart& mrModelPart;
503  ModelPart* mpConvectionModelPart;
504  typename BaseType::Pointer mstep1;
505  double mOldDt;
506  int mdimension;
507 
508 
533 
534 
537 }; /* Class ResidualBasedEulerianConvectionDiffusionStrategy */
538 
547 } /* namespace Kratos.*/
548 
549 #endif /* KRATOS_RESIDUALBASED_EULERIAN_CONVECTION_DIFFUSION_STRATEGY defined */
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
This class aims to manage different model parts across multi-physics simulations.
Definition: model.h:60
ModelPart & CreateModelPart(const std::string &ModelPartName, IndexType NewBufferSize=1)
This method creates a new model part contained in the current Model with a given name and buffer size...
Definition: model.cpp:37
void DeleteModelPart(const std::string &ModelPartName)
This method deletes a modelpart with a given name.
Definition: model.cpp:64
bool HasModelPart(const std::string &rFullModelPartName) const
This method checks if a certain a model part exists given a certain name.
Definition: model.cpp:178
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
void SetProcessInfo(ProcessInfo::Pointer pNewProcessInfo)
Definition: model_part.h:1766
ProcessInfo::Pointer pGetProcessInfo()
Definition: model_part.h:1756
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
void SetBufferSize(IndexType NewBufferSize)
This method sets the suffer size of the model part database.
Definition: model_part.cpp:2171
IndexType GetBufferSize() const
This method gets the suffer size of the model part database.
Definition: model_part.h:1876
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
Model & GetModel()
Definition: model_part.h:323
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
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
This strategy is used to solve convection-diffusion problem.
Definition: residualbased_eulerian_convdiff_strategy.h:92
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedEulerianConvectionDiffusionStrategy)
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_eulerian_convdiff_strategy.h:108
void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: residualbased_eulerian_convdiff_strategy.h:223
int Check() override
Function to perform expensive checks.
Definition: residualbased_eulerian_convdiff_strategy.h:233
virtual ~ResidualBasedEulerianConvectionDiffusionStrategy()
Definition: residualbased_eulerian_convdiff_strategy.h:193
ResidualBasedEulerianConvectionDiffusionStrategy(ModelPart &model_part, typename TLinearSolver::Pointer pNewLinearSolver, bool ReformDofAtEachIteration=false, int dimension=3)
Definition: residualbased_eulerian_convdiff_strategy.h:132
virtual void GenerateMeshPart(int dimension)
Definition: residualbased_eulerian_convdiff_strategy.h:404
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_eulerian_convdiff_strategy.h:114
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_eulerian_convdiff_strategy.h:110
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_eulerian_convdiff_strategy.h:106
double Solve() override
Definition: residualbased_eulerian_convdiff_strategy.h:204
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_eulerian_convdiff_strategy.h:100
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_eulerian_convdiff_strategy.h:112
void Clear() override
Clears the internal storage.
Definition: residualbased_eulerian_convdiff_strategy.h:228
BaseType::TDataType TDataType
Definition: residualbased_eulerian_convdiff_strategy.h:102
This class provides the implementation of a static scheme.
Definition: residualbased_incrementalupdate_static_scheme.h:57
This is a very simple strategy to solve linearly the problem.
Definition: residualbased_linear_strategy.h:64
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
TDenseSpace::MatrixType LocalSystemMatrixType
Definition: solving_strategy.h:79
TSparseSpace::DataType TDataType
Definition: solving_strategy.h:69
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
TSparseSpace::VectorType TSystemVectorType
Definition: solving_strategy.h:73
TDenseSpace::VectorType LocalSystemVectorType
Definition: solving_strategy.h:81
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
model_part
Definition: face_heat.py:14
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
ReformDofAtEachIteration
Definition: test_pureconvectionsolver_benchmarking.py:131