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_semi_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_SEMI_EULERIAN_CONVECTION_DIFFUSION_STRATEGY )
13 #define KRATOS_RESIDUALBASED_SEMI_EULERIAN_CONVECTION_DIFFUSION_STRATEGY
14 
15 /* System includes */
16 
17 /* External includes */
18 
19 /* Project includes */
20 #include "includes/define.h"
21 #include "containers/model.h"
22 #include "includes/model_part.h"
29 //#include "custom_utilities/convection_diffusion_settings.h"
30 
31 
32 
33 namespace Kratos
34 {
35 
62 
69 template<class TSparseSpace,
70  class TDenseSpace,
71  class TLinearSolver
72  >
74  : public ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>
75 {
76 public:
82 
84 
85  typedef typename BaseType::TDataType TDataType;
86 
87  //typedef typename BaseType::DofSetType DofSetType;
88 
90 
92 
94 
96 
98 
99 
100 
117  typename TLinearSolver::Pointer pNewLinearSolver,
118  bool ReformDofAtEachIteration = false,
119  int dimension = 3
120  )
121  :
122  ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>(model_part,false),
123  mrReferenceModelPart(model_part)
124  {
125  KRATOS_TRY
126 
127  if(mrReferenceModelPart.GetModel().HasModelPart("ConvectionDiffusionPart"))
128  KRATOS_ERROR << "ConvectionDiffusionPart already exists when constructing ResidualBasedSemiEulerianConvectionDiffusionStrategy" << std::endl;
129 
130  GenerateMeshPart(dimension);
131  mdimension = dimension;
132  mOldDt = 0.00;
133 
134  //ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
135  //ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
136  //(mpConvectionModelPart->GetProcessInfo()).GetValue(CONVECTION_DIFFUSION_SETTINGS) = my_settings;
137  Check();
138 
139 
140  //initializing fractional velocity solution step
141  typedef Scheme< TSparseSpace, TDenseSpace > SchemeType;
142  typename SchemeType::Pointer pscheme = typename SchemeType::Pointer
144 
145  bool CalculateReactions = false;
146  bool CalculateNormDxFlag = true;
147 
148  //choosing the solving strategy
149 // mstep1 = typename BaseType::Pointer(
150 // new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver >
151 // (model_part,pscheme,pNewLinearSolver,CalculateReactions,ReformDofAtEachIteration,CalculateNormDxFlag) );
152 // mstep1->SetEchoLevel(2);
153 
154 
155  typedef typename BuilderAndSolver<TSparseSpace,TDenseSpace,TLinearSolver>::Pointer BuilderSolverTypePointer;
156 
157  //const Variable<double>& rUnknownVar= my_settings->GetUnknownVariable();
158  //BuilderSolverTypePointer componentwise_build = BuilderSolverTypePointer(new ResidualBasedEliminationBuilderAndSolverComponentwise<TSparseSpace,TDenseSpace,TLinearSolver,Variable<double> > (pNewLinearSolver,rUnknownVar) );
159  //mstep1 = typename BaseType::Pointer( new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver > (*mpConvectionModelPart,pscheme,pNewLinearSolver,componentwise_build,CalculateReactions,ReformDofAtEachIteration,CalculateNormDxFlag) );
160 
161  BuilderSolverTypePointer pBuilderSolver = BuilderSolverTypePointer(new ResidualBasedBlockBuilderAndSolver<TSparseSpace,TDenseSpace,TLinearSolver>(pNewLinearSolver) );
162  mstep1 = typename BaseType::Pointer( new ResidualBasedLinearStrategy<TSparseSpace,TDenseSpace,TLinearSolver >(
163  *mpConvectionModelPart,
164  pscheme,
165  pBuilderSolver,
166  CalculateReactions,
168  CalculateNormDxFlag) );
169 
170 
171  mstep1->SetEchoLevel(2);
172 
173  KRATOS_CATCH("")
174  }
175 
176 
177 
181  {
182  mrReferenceModelPart.GetModel().DeleteModelPart("ConvectionDiffusionPart");
183  }
184 
188  //*********************************************************************************
189  //**********************************************************************
190  double Solve() override
191  {
192  KRATOS_TRY
193 
194  //calculate the BDF coefficients
195  //careful. Using information from the currentprocessinfo of the original model part (not the convection model part)
196  //ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
197  //double Dt = rCurrentProcessInfo[DELTA_TIME];
198  //int stationary= rCurrentProcessInfo[STATIONARY];
199 
200  //SOLVING THE PROBLEM
201  double Dp_norm = mstep1->Solve();
202 
203  return Dp_norm;
204  KRATOS_CATCH("")
205  }
206 
207 
208 
209  void SetEchoLevel(int Level) override
210  {
211  mstep1->SetEchoLevel(Level);
212  }
213 
214  void Clear() override
215  {
216  mstep1->Clear();
217  }
218 
219  int Check() override
220  {
221  KRATOS_TRY
222  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
223  if (rCurrentProcessInfo.Has(CONVECTION_DIFFUSION_SETTINGS)==false)
224  KRATOS_THROW_ERROR(std::logic_error, "no CONVECTION_DIFFUSION_SETTINGS in model_part", "");
225  //std::cout << "ConvDiff::Check(). If crashes, check CONVECTION_DIFFUSION_SETTINGS is defined" << std::endl;
226 
227  ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS);
228 
229  //DENSITY VARIABLE
230  if(my_settings->IsDefinedDensityVariable()==true)
231  {
232  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetDensityVariable()) == false)
233  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Density Variable defined but not contained in the model part", "");
234  }
235  else
236  std::cout << "No density variable assigned for ConvDiff. Assuming density=1" << std::endl;
237 
238  //DIFFUSION VARIABLE
239  if(my_settings->IsDefinedDiffusionVariable()==true)
240  {
241  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetDiffusionVariable()) == false)
242  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Diffusion Variable defined but not contained in the model part", "");
243  }
244  else
245  std::cout << "No diffusion variable assigned for ConvDiff. Assuming diffusivity=0" << std::endl;
246 
247  //UNKNOWN VARIABLE
248  if(my_settings->IsDefinedUnknownVariable()==true)
249  {
250  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetUnknownVariable()) == false)
251  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Unknown Variable defined but not contained in the model part", "");
252  }
253  else
254  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Unknown Variable not defined!", "");
255 
256  //VOLUME SOURCE VARIABLE
257  //if(my_settings->IsDefinedVolumeSourceVariable()==true)
258  //{
259  // if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetVolumeSourceVariable()) == false)
260  // KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: VolumeSource Variable defined but not contained in the model part", "");
261  //}
262  //else
263  // std::cout << "No VolumeSource variable assigned for ConvDiff. Assuming VolumeSource=0" << std::endl;
264  if(my_settings->IsDefinedVolumeSourceVariable()==true)
265  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: VolumeSource not yet implemented", "");
266 
267  //SURFACE SOURCE VARIABLE
268  //if(my_settings->IsDefinedSurfaceSourceVariable()==true)
269  //{
270  // if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetSurfaceSourceVariable()) == false)
271  // KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: SurfaceSource Variable defined but not contained in the model part", "");
272  //}
273  //else
274  // std::cout << "No SurfaceSource variable assigned for ConvDiff. Assuming SurfaceSource=0" << std::endl;
275  if(my_settings->IsDefinedSurfaceSourceVariable()==true)
276  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: SurfaceSource not yet implemented", "");
277 
278  //PROJECTION VARIABLE
279  //used as intermediate variable, is the variable at time n+1 but only accounting for the convective term.
280  if(my_settings->IsDefinedProjectionVariable()==true)
281  {
282  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetProjectionVariable()) == false)
283  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Projection Variable defined but not contained in the model part", "");
284  }
285  else
286  {
287  std::cout << "No Projection variable assigned for ConvDiff. Using PROJECTED_SCALAR1" << std::endl;
288  my_settings->SetProjectionVariable(PROJECTED_SCALAR1);
289 
290  }
291  //if(my_settings->IsDefinedProjectionVariable()==true)
292  // KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: ProjectionVariable not useed. Remove it", "");
293 
294  //CONVECTION VELOCITY VARIABLE
295  //CURRENTLY WE ARE USING (VELOCITY -MESH_VELOCITY) TO CONVECT, so the ConvectionVariable must not be used:
296  //if(my_settings->IsDefinedConvectionVariable()==true)
297  //{
298  // if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetConvectionVariable()) == false)
299  // KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Convection Variable defined but not contained in the model part", "");
300  //}
301  //else
302  // std::cout << "No Projection variable assigned for ConvDiff. Assuming Convection=0" << std::endl;
303  if(my_settings->IsDefinedConvectionVariable()==true)
304  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: ConvectionVariable not used. Use VelocityVariable instead", "");
305 
306  //MESH VELOCITY VARIABLE
307  if(my_settings->IsDefinedMeshVelocityVariable()==true)
308  {
309  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetMeshVelocityVariable()) == false)
310  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: MeshVelocity Variable defined but not contained in the model part", "");
311  }
312  else
313  std::cout << "No MeshVelocity variable assigned for ConvDiff. Assuming MeshVelocity=0" << std::endl;
314 
315  //VELOCITY VARIABLE
316  if(my_settings->IsDefinedVelocityVariable()==true)
317  {
318  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetVelocityVariable()) == false)
319  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: Velocity Variable defined but not contained in the model part", "");
320  }
321  else
322  std::cout << "No Velocity variable assigned for ConvDiff. Assuming Velocity=0" << std::endl;
323 
324  //TRANSFER COEFFICIENT VARIABLE
325  //if(my_settings->IsDefinedTransferCoefficientVariable()==true)
326  //{
327  // if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetTransferCoefficientVariable()) == false)
328  // KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: TransferCoefficient Variable defined but not contained in the model part", "");
329  //}
330  //else
331  // std::cout << "No TransferCoefficient variable assigned for ConvDiff. Assuming TransferCoefficient=0" << std::endl;
332  if(my_settings->IsDefinedTransferCoefficientVariable()==true)
333  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: TransferCoefficient not yet implemented", "");
334 
335  //SPECIFIC HEAT VARIABLE
336  if(my_settings->IsDefinedSpecificHeatVariable()==true)
337  {
338  if (BaseType::GetModelPart().NodesBegin()->SolutionStepsDataHas(my_settings->GetSpecificHeatVariable()) == false)
339  KRATOS_THROW_ERROR(std::logic_error, "ConvDiffSettings: SpecificHeat Variable defined but not contained in the model part", "");
340  }
341  else
342  std::cout << "No SpecificHeat variable assigned for ConvDiff. Assuming SpecificHeat=1" << std::endl;
343 
344  return 0;
345 
346  KRATOS_CATCH("")
347 
348  }
349 
377 protected:
416 private:
424  ModelPart& mrReferenceModelPart;
425  ModelPart* mpConvectionModelPart;
426  typename BaseType::Pointer mstep1;
427  double mOldDt;
428  int mdimension;
429 
430 
431 
432 
433 
442  void GenerateMeshPart(int dimension)
443  {
444  if(!mrReferenceModelPart.GetModel().HasModelPart("ConvectionDiffusionPart"))
445  mrReferenceModelPart.GetModel().DeleteModelPart("ConvectionDiffusionPart");
446 
447  mpConvectionModelPart = &(mrReferenceModelPart.GetModel().CreateModelPart("ConvectionDiffusionPart"));
448 
449  mpConvectionModelPart->SetProcessInfo( BaseType::GetModelPart().pGetProcessInfo() );
450  mpConvectionModelPart->SetBufferSize( BaseType::GetModelPart().GetBufferSize());
451 
452  //initializing mesh nodes
453  mpConvectionModelPart->Nodes() = BaseType::GetModelPart().Nodes();
454 
455  //creating mesh elements
456  ModelPart::ElementsContainerType& MeshElems = mpConvectionModelPart->Elements();
457  Element::Pointer pElem;
458 
459  if(dimension == 2)
460  for(ModelPart::ElementsContainerType::iterator it
461  = BaseType::GetModelPart().ElementsBegin();
462 
463  it != BaseType::GetModelPart().ElementsEnd(); ++it) {
464 
465  pElem = Element::Pointer(new EulerianDiffusionElement<2,3>(
466  (*it).Id(),
467  (*it).pGetGeometry(),
468  (*it).pGetProperties() ) );
469  MeshElems.push_back(pElem);
470  }
471 
472  if(dimension == 3)
473  for(ModelPart::ElementsContainerType::iterator it
474  = BaseType::GetModelPart().ElementsBegin();
475 
476  it != BaseType::GetModelPart().ElementsEnd(); ++it) {
477 
478  pElem = Element::Pointer(new EulerianDiffusionElement<3,4>(
479  (*it).Id(),
480  (*it).pGetGeometry(),
481  (*it).pGetProperties() ) );
482  MeshElems.push_back(pElem);
483  }
484  }
485 
503 
504 
507 }; /* Class ResidualBasedSemiEulerianConvectionDiffusionStrategy */
508 
517 } /* namespace Kratos.*/
518 
519 #endif /* KRATOS_RESIDUALBASED_SEMI_EULERIAN_CONVECTION_DIFFUSION_STRATEGY defined */
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
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 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 strategy is used to solve convection-diffusion problem.
Definition: residualbased_semi_eulerian_convdiff_strategy.h:75
ResidualBasedSemiEulerianConvectionDiffusionStrategy(ModelPart &model_part, typename TLinearSolver::Pointer pNewLinearSolver, bool ReformDofAtEachIteration=false, int dimension=3)
Definition: residualbased_semi_eulerian_convdiff_strategy.h:115
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_semi_eulerian_convdiff_strategy.h:91
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_semi_eulerian_convdiff_strategy.h:93
BaseType::TDataType TDataType
Definition: residualbased_semi_eulerian_convdiff_strategy.h:85
double Solve() override
Definition: residualbased_semi_eulerian_convdiff_strategy.h:190
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_semi_eulerian_convdiff_strategy.h:97
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_semi_eulerian_convdiff_strategy.h:83
virtual ~ResidualBasedSemiEulerianConvectionDiffusionStrategy()
Definition: residualbased_semi_eulerian_convdiff_strategy.h:180
void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: residualbased_semi_eulerian_convdiff_strategy.h:209
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedSemiEulerianConvectionDiffusionStrategy)
int Check() override
Function to perform expensive checks.
Definition: residualbased_semi_eulerian_convdiff_strategy.h:219
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_semi_eulerian_convdiff_strategy.h:89
void Clear() override
Clears the internal storage.
Definition: residualbased_semi_eulerian_convdiff_strategy.h:214
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_semi_eulerian_convdiff_strategy.h:95
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_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#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