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.
trilinos_levelset_convection_process.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: Ruben Zorrilla
11 //
12 
13 #if !defined(KRATOS_TRILINOS_LEVELSET_CONVECTION_PROCESS_INCLUDED )
14 #define KRATOS_TRILINOS_LEVELSET_CONVECTION_PROCESS_INCLUDED
15 
16 // System includes
17 
18 // External includes
19 #include "Epetra_MpiComm.h"
20 
21 // Project includes
22 #include "containers/model.h"
24 
25 // Application includes
27 
28 namespace Kratos
29 {
32 
36 
40 
44 
48 
50 
53 template< unsigned int TDim, class TSparseSpace, class TDenseSpace, class TLinearSolver >
55  : public LevelSetConvectionProcess<TDim, TSparseSpace, TDenseSpace, TLinearSolver>
56 {
57 public:
58 
59  KRATOS_DEFINE_LOCAL_FLAG(PERFORM_STEP1);
60  KRATOS_DEFINE_LOCAL_FLAG(DO_EXPENSIVE_CHECKS);
61 
64 
66  typedef typename TLinearSolver::Pointer LinearSolverPointerType;
68 
72 
75 
79 
81  Epetra_MpiComm& rEpetraCommunicator,
82  Model& rModel,
83  typename TLinearSolver::Pointer pLinearSolver,
84  Parameters ThisParameters)
86  rEpetraCommunicator,
87  rModel.GetModelPart(ThisParameters["model_part_name"].GetString()),
88  pLinearSolver,
89  ThisParameters)
90  {
91  }
92 
94  Epetra_MpiComm& rEpetraCommunicator,
95  ModelPart& rBaseModelPart,
96  typename TLinearSolver::Pointer pLinearSolver,
97  Parameters ThisParameters)
98  : BaseType(
99  rBaseModelPart,
100  ThisParameters)
101  , mrEpetraCommunicator(rEpetraCommunicator)
102  {
103  KRATOS_TRY
104 
105  const int row_size_guess = (TDim == 2 ? 15 : 40);
106  auto p_builder_and_solver = Kratos::make_shared< TrilinosBlockBuilderAndSolver<TSparseSpace,TDenseSpace,TLinearSolver>>(
108  row_size_guess,
109  pLinearSolver);
110  InitializeConvectionStrategy(p_builder_and_solver);
111 
112  KRATOS_CATCH("")
113  }
114 
117 
120 
124 
128 
132 
136 
140 
142  std::string Info() const override {
143  return "TrilinosLevelSetConvectionProcess";
144  }
145 
147  void PrintInfo(std::ostream& rOStream) const override {
148  rOStream << "TrilinosLevelSetConvectionProcess";
149  }
150 
151  // /// Print object's data.
152  // void PrintData(std::ostream& rOStream) const override {
153  // }
154 
158 
160 protected:
163 
167 
168  Epetra_MpiComm& mrEpetraCommunicator;
169 
173 
177 
178  void ReGenerateConvectionModelPart(ModelPart& rBaseModelPart) override {
179 
180  KRATOS_TRY
181 
182  // Check buffer size
183  const auto base_buffer_size = rBaseModelPart.GetBufferSize();
184  KRATOS_ERROR_IF(base_buffer_size < 2) <<
185  "Base model part buffer size is " << base_buffer_size << ". Set it to a minimum value of 2." << std::endl;
186 
187  if(rBaseModelPart.GetModel().HasModelPart("DistanceConvectionPart"))
188  rBaseModelPart.GetModel().DeleteModelPart("DistanceConvectionPart");
189 
190  BaseType::mpDistanceModelPart= &(rBaseModelPart.GetModel().CreateModelPart("DistanceConvectionPart"));
191 
192  // Generate
196 
198  BaseType::mpDistanceModelPart->SetBufferSize(base_buffer_size);
200  BaseType::mpDistanceModelPart->Tables() = rBaseModelPart.Tables();
201 
202  // Assigning the nodes to the new model part
203  BaseType::mpDistanceModelPart->Nodes() = rBaseModelPart.Nodes();
204 
205  // Ensure that the nodes have distance as a DOF
207 
208  // Copy communicator data
209  Communicator& r_base_comm = rBaseModelPart.GetCommunicator();
210  Communicator::Pointer p_new_comm = r_base_comm.Create();
211 
212  p_new_comm->SetNumberOfColors(r_base_comm.GetNumberOfColors());
213  p_new_comm->NeighbourIndices() = r_base_comm.NeighbourIndices();
214  p_new_comm->LocalMesh().SetNodes(r_base_comm.LocalMesh().pNodes());
215  p_new_comm->InterfaceMesh().SetNodes(r_base_comm.InterfaceMesh().pNodes());
216  p_new_comm->GhostMesh().SetNodes(r_base_comm.GhostMesh().pNodes());
217  for (unsigned int i = 0; i < r_base_comm.GetNumberOfColors(); ++i){
218  p_new_comm->pInterfaceMesh(i)->SetNodes(r_base_comm.pInterfaceMesh(i)->pNodes());
219  p_new_comm->pLocalMesh(i)->SetNodes(r_base_comm.pLocalMesh(i)->pNodes());
220  p_new_comm->pGhostMesh(i)->SetNodes(r_base_comm.pGhostMesh(i)->pNodes());
221  }
222 
224 
225  // Generating the elements
226  (BaseType::mpDistanceModelPart->Elements()).reserve(rBaseModelPart.NumberOfElements());
227  KRATOS_ERROR_IF(BaseType::mpConvectionFactoryElement == nullptr) << "Convection factory element has not been set yet." << std::endl;
228  for (auto it_elem = rBaseModelPart.ElementsBegin(); it_elem != rBaseModelPart.ElementsEnd(); ++it_elem){
229  // Create the new element from the factory registered one
231  it_elem->Id(),
232  it_elem->pGetGeometry(),
233  it_elem->pGetProperties());
234 
235  (BaseType::mpDistanceModelPart->Elements()).push_back(p_element);
236  (BaseType::mpDistanceModelPart->GetCommunicator()).LocalMesh().Elements().push_back(p_element);
237  }
238 
239  // Initialize the nodal and elemental databases
241 
242  // Resize the arrays
244  (this->mVelocity).resize(n_nodes);
245  (this->mVelocityOld).resize(n_nodes);
246  (this->mOldDistance).resize(n_nodes);
247 
248  if (this->mIsBfecc){
249  (this->mError).resize(n_nodes);
250  (this->mSigmaPlus).resize(n_nodes);
251  (this->mSigmaMinus).resize(n_nodes);
252  (this->mLimiter).resize(n_nodes);
253  }
254 
255  (this->mDistancePartIsInitialized) = true;
256 
257  KRATOS_CATCH("")
258  }
259 
263 
267 
271 
273 private:
276 
280 
284 
288 
289  void InitializeConvectionStrategy(BuilderSolverPointerType pBuilderAndSolver)
290  {
291  KRATOS_TRY
292 
293  // Get auxiliary member variables from base class
294  auto& r_base_model_part = BaseType::mrBaseModelPart;
295  const auto& r_level_set_var = *BaseType::mpLevelSetVar;
296  const auto& r_convect_var = *BaseType::mpConvectVar;
297 
298  // Check the nodal database of the current partition
299  VariableUtils().CheckVariableExists<Variable<double>>(r_level_set_var, r_base_model_part.Nodes());
300  VariableUtils().CheckVariableExists<Variable<array_1d<double,3>>>(r_convect_var, r_base_model_part.Nodes());
301 
302  // Check if the modelpart is globally empty
303  KRATOS_ERROR_IF(r_base_model_part.GetCommunicator().GlobalNumberOfNodes() == 0) << "The model has no nodes." << std::endl;
304  KRATOS_ERROR_IF(r_base_model_part.GetCommunicator().GlobalNumberOfElements() == 0) << "The model has no elements." << std::endl;
305 
306  // Check if any partition has incorrect elements
307  if constexpr (TDim == 2){
308  bool has_incorrect_elems = r_base_model_part.NumberOfElements() ? r_base_model_part.ElementsBegin()->GetGeometry().GetGeometryFamily() != GeometryData::KratosGeometryFamily::Kratos_Triangle : false;
309  KRATOS_ERROR_IF(has_incorrect_elems) << "In 2D the element type is expected to be a triangle" << std::endl;
310  } else if constexpr (TDim == 3) {
311  bool has_incorrect_elems = r_base_model_part.NumberOfElements() ? r_base_model_part.ElementsBegin()->GetGeometry().GetGeometryFamily() != GeometryData::KratosGeometryFamily::Kratos_Tetrahedra : false;
312  KRATOS_ERROR_IF(has_incorrect_elems) << "In 3D the element type is expected to be a tetrahedra" << std::endl;
313  }
314 
315  // Generate an auxilary model part and populate it by elements of type DistanceCalculationElementSimplex
316  ReGenerateConvectionModelPart(r_base_model_part);
317 
318  // Generate a linear strategy
319  const bool calculate_reactions = false;
320  const bool reform_dof_at_each_iteration = false;
321  const bool calculate_norm_Dx_flag = false;
322  auto p_scheme = Kratos::make_shared< ResidualBasedIncrementalUpdateStaticScheme< TSparseSpace,TDenseSpace > >();
323  (this->mpSolvingStrategy) = Kratos::make_unique< ResidualBasedLinearStrategy<TSparseSpace,TDenseSpace,TLinearSolver > >(
325  p_scheme,
326  pBuilderAndSolver,
327  calculate_reactions,
328  reform_dof_at_each_iteration,
329  calculate_norm_Dx_flag);
330 
331  //TODO: check flag DO_EXPENSIVE_CHECKS
332  this->mpSolvingStrategy->SetEchoLevel(0);
333  this->mpSolvingStrategy->Check();
334  this->mpSolvingStrategy->Initialize();
335 
336  KRATOS_CATCH("")
337  }
338 
342 
346 
350 
353 
355 }; // Class TrilinosLevelSetConvectionProcess
356 
360 
364 
366 } // namespace Kratos.
367 
368 #endif // KRATOS_TRILINOS_LEVELSET_CONVECTION_PROCESS_INCLUDED defined
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
The Commmunicator class manages communication for distributed ModelPart instances.
Definition: communicator.h:67
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new element pointer.
Definition: element.h:202
Short class definition.
Definition: levelset_convection_process.h:71
Vector mError
Definition: levelset_convection_process.h:422
std::vector< array_1d< double, 3 > > mVelocityOld
Definition: levelset_convection_process.h:434
Vector mOldDistance
Definition: levelset_convection_process.h:424
bool mDistancePartIsInitialized
Definition: levelset_convection_process.h:436
Vector mSigmaPlus
Definition: levelset_convection_process.h:426
SolvingStrategyType::UniquePointer mpSolvingStrategy
Definition: levelset_convection_process.h:438
std::vector< array_1d< double, 3 > > mVelocity
Definition: levelset_convection_process.h:432
Vector mSigmaMinus
Definition: levelset_convection_process.h:428
const Element * mpConvectionFactoryElement
Definition: levelset_convection_process.h:444
const Variable< array_1d< double, 3 > > * mpConvectVar
Definition: levelset_convection_process.h:398
Vector mLimiter
Definition: levelset_convection_process.h:430
void InitializeDistanceModelPartDatabases()
Initializes the databases values This function initializes is intended to collect all the database in...
Definition: levelset_convection_process.h:586
const Variable< double > * mpLevelSetVar
Definition: levelset_convection_process.h:396
bool mIsBfecc
Definition: levelset_convection_process.h:406
ModelPart * mpDistanceModelPart
Definition: levelset_convection_process.h:394
ModelPart & mrBaseModelPart
Definition: levelset_convection_process.h:390
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
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
void SetCommunicator(Communicator::Pointer pNewCommunicator)
Definition: model_part.h:1836
void SetProcessInfo(ProcessInfo::Pointer pNewProcessInfo)
Definition: model_part.h:1766
void SetProperties(PropertiesContainerType::Pointer pOtherProperties, IndexType ThisIndex=0)
Definition: model_part.h:1013
ProcessInfo::Pointer pGetProcessInfo()
Definition: model_part.h:1756
Communicator & GetCommunicator()
Definition: model_part.h:1821
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
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
PropertiesContainerType::Pointer pProperties(IndexType ThisIndex=0)
Definition: model_part.h:1008
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
TablesContainerType & Tables()
Definition: model_part.h:635
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
Model & GetModel()
Definition: model_part.h:323
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
Short class definition.
Definition: trilinos_levelset_convection_process.h:56
TrilinosLevelSetConvectionProcess(Epetra_MpiComm &rEpetraCommunicator, ModelPart &rBaseModelPart, typename TLinearSolver::Pointer pLinearSolver, Parameters ThisParameters)
Definition: trilinos_levelset_convection_process.h:93
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: trilinos_levelset_convection_process.h:147
TrilinosLevelSetConvectionProcess(TrilinosLevelSetConvectionProcess const &rOther)=delete
Copy constructor.
KRATOS_CLASS_POINTER_DEFINITION(TrilinosLevelSetConvectionProcess)
Pointer definition of TrilinosLevelSetConvectionProcess.
KRATOS_DEFINE_LOCAL_FLAG(DO_EXPENSIVE_CHECKS)
LevelSetConvectionProcess< TDim, TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: trilinos_levelset_convection_process.h:65
void ReGenerateConvectionModelPart(ModelPart &rBaseModelPart) override
Definition: trilinos_levelset_convection_process.h:178
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer BuilderSolverPointerType
Definition: trilinos_levelset_convection_process.h:67
Epetra_MpiComm & mrEpetraCommunicator
Definition: trilinos_levelset_convection_process.h:168
std::string Info() const override
Turn back information as a string.
Definition: trilinos_levelset_convection_process.h:142
TrilinosLevelSetConvectionProcess(Epetra_MpiComm &rEpetraCommunicator, Model &rModel, typename TLinearSolver::Pointer pLinearSolver, Parameters ThisParameters)
Definition: trilinos_levelset_convection_process.h:80
TLinearSolver::Pointer LinearSolverPointerType
Definition: trilinos_levelset_convection_process.h:66
~TrilinosLevelSetConvectionProcess() override
Destructor.
Definition: trilinos_levelset_convection_process.h:119
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
int CheckVariableExists(const TVarType &rVariable, const NodesContainerType &rNodes)
Checks if all the nodes of a node set has the specified variable.
Definition: variable_utils.h:1051
void AddDof(const TVarType &rVar, ModelPart &rModelPart)
This function add dofs to the nodes in a model part. It is useful since addition is done in parallel.
Definition: variable_utils.h:1361
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
unique_ptr< C > make_unique(Args &&...args)
Definition: smart_pointers.h:45
int n_nodes
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:15
integer i
Definition: TensorModule.f:17