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_laplacian_meshmoving_strategy.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license:
9 //kratos/license.txt
10 //
11 // Main authors: Andreas Winterstein (a.winterstein@tum.de)
12 //
13 
14 #if !defined(KRATOS_NEW_TRILINOS_LAPLACIAN_MESHMOVING_STRATEGY)
15 #define KRATOS_NEW_TRILINOS_LAPLACIAN_MESHMOVING_STRATEGY
16 
17 /* System includes */
18 
19 /* External includes */
20 
21 /* Project includes */
23 #include "includes/model_part.h"
24 #include "containers/model.h"
29 
30 /* Trilinos includes */
32 
33 namespace Kratos
34 {
56 
61 template <class TSparseSpace,
62  class TDenseSpace, //= DenseSpace<double>,
63  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
64  >
66  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
67 {
68 public:
74 
76 
78 
88  typename TLinearSolver::Pointer pNewLinearSolver,
89  int TimeOrder = 1,
90  bool ReformDofSetAtEachStep = false,
91  bool ComputeReactions = false,
92  bool CalculateMeshVelocities = true,
93  int EchoLevel = 0)
94  :
95  ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(model_part),
96  mrReferenceModelPart(model_part)
97  {
99 
100  if(mrReferenceModelPart.GetModel().HasModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart"))
101  KRATOS_ERROR << "LaplacianMeshMovingPart already existing when constructing TrilinosLaplacianMeshMovingStrategy";
102 
103  // Passed variables
104  m_reform_dof_set_at_each_step = ReformDofSetAtEachStep;
105  m_echo_level = EchoLevel;
106  m_compute_reactions = ComputeReactions;
107  m_calculate_mesh_velocities = CalculateMeshVelocities;
108  m_time_order = TimeOrder;
109  bool calculate_norm_dx_flag = false;
110 
111  // Definitions for trilinos
112  int guess_row_size;
113  guess_row_size = 15;
114 
115  // Generating Mesh Part
116  GenerateMeshPart();
117 
118  typedef Scheme<TSparseSpace, TDenseSpace> SchemeType;
119  typename SchemeType::Pointer pscheme = typename SchemeType::Pointer(
121 
122  typedef typename BuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>::Pointer BuilderSolverTypePointer;
123 
124  BuilderSolverTypePointer aux_var_build = BuilderSolverTypePointer(
126  Communicator, guess_row_size, pNewLinearSolver));
127 
128  mstrategy = typename BaseType::Pointer(new ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(
129  *mpmesh_model_part,
130  pscheme,
131  aux_var_build,
132  m_compute_reactions,
133  m_reform_dof_set_at_each_step,
134  calculate_norm_dx_flag));
135 
136  mstrategy->SetEchoLevel(m_echo_level);
137 
138  KRATOS_CATCH("");
139  }
140 
144  {
145  mrReferenceModelPart.GetModel().DeleteModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart");
146  }
147 
151  void Initialize() override
152  {}
153 
154  double Solve() override
155  {
156  KRATOS_TRY;
157 
158  // Mesh has to be regenerated in each solving step
159 
160  ProcessInfo& rCurrentProcessInfo = (mpmesh_model_part)->GetProcessInfo();
161 
162 
163  // Setting mesh to initial configuration
164  for (ModelPart::NodeIterator i = (*mpmesh_model_part).NodesBegin();
165  i != (*mpmesh_model_part).NodesEnd();
166  ++i)
167  {
168  (i)->X() = (i)->X0();
169  (i)->Y() = (i)->Y0();
170  (i)->Z() = (i)->Z0();
171  }
172 
173  unsigned int dimension =
174  BaseType::GetModelPart().GetProcessInfo()[DOMAIN_SIZE];
175 
176 
177  // X DIRECTION
178  if (dimension == 2){
179  rCurrentProcessInfo[LAPLACIAN_DIRECTION] =
180  1;
181  mstrategy->Solve();
182 
183  // Y DIRECTION
184  rCurrentProcessInfo[LAPLACIAN_DIRECTION] =
185  2;
186  mstrategy->Solve();
187  } else{
188 
189  rCurrentProcessInfo[LAPLACIAN_DIRECTION] = 1;
190  mstrategy->Solve();
191 
192  // Y DIRECTION
193  rCurrentProcessInfo[LAPLACIAN_DIRECTION] =
194  2;
195  mstrategy->Solve();
196  // Z DIRECTION
197  rCurrentProcessInfo[LAPLACIAN_DIRECTION] =
198  3;
199  mstrategy->Solve();
200 
201  }
202 
203  // clearing the system if needed
204  if (m_reform_dof_set_at_each_step == true)
205  mstrategy->Clear();
206 
207  return 0.0;
208 
209  KRATOS_CATCH("")
210  }
211 
235 protected:
265 private:
272  ModelPart& mrReferenceModelPart;
273  ModelPart* mpmesh_model_part;
274 
275  typename BaseType::Pointer mstrategy;
276 
277  bool m_reform_dof_set_at_each_step;
278  bool m_compute_reactions;
279  bool m_calculate_mesh_velocities;
280  int m_time_order;
281  int m_echo_level;
282 
291  void GenerateMeshPart()
292  {
293  if(!mrReferenceModelPart.GetModel().HasModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart"))
294  mrReferenceModelPart.GetModel().DeleteModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart");
295 
296  mpmesh_model_part = &mrReferenceModelPart.GetModel().CreateModelPart(mrReferenceModelPart.Name()+"_StructuralMeshMovingPart");
297 
298  // Initializing mesh nodes
299  mpmesh_model_part->Nodes() = BaseType::GetModelPart().Nodes();
300 
301  // Creating mesh elements
302  ModelPart::ElementsContainerType& MeshElems = mpmesh_model_part->Elements();
303  // this works for multiple geometries because we use the
304  // element's Create() member function that accepts a geometry
305  // pointer
306  const Element& rElem =
307  KratosComponents<Element>::Get("LaplacianMeshMovingElement2D3N");
308 
309  for (auto it = BaseType::GetModelPart().ElementsBegin();
311  ++it)
312  MeshElems.push_back(rElem.Create(
313  it->Id(), it->pGetGeometry(), it->pGetProperties()));
314 
315  // Optimize communicaton plan
316  ParallelFillCommunicator CommunicatorGeneration(*mpmesh_model_part, mrReferenceModelPart.GetCommunicator().GetDataCommunicator());
317  CommunicatorGeneration.Execute();
318  }
319 
335 
338 }; /* Class TrilinosLaplacianMeshMovingStrategy */
339 
347 } /* namespace Kratos.*/
348 
349 #endif /* KRATOS_NEW_TRILINOS_LAPLACIAN_MESHMOVING_STRATEGY 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 const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
Base class for all Elements.
Definition: element.h:60
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new element pointer.
Definition: element.h:202
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
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
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
std::string & Name()
Definition: model_part.h:1811
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
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
This function recomputes the communication plan for MPI.
Definition: parallel_fill_communicator.h:56
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
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
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
Current class provides an implementation for trilinos builder and solving operations.
Definition: trilinos_block_builder_and_solver.h:85
Short class definition.
Definition: trilinos_laplacian_meshmoving_strategy.h:67
Variable< double > VariableType
Definition: trilinos_laplacian_meshmoving_strategy.h:77
KRATOS_CLASS_POINTER_DEFINITION(TrilinosLaplacianMeshMovingStrategy)
virtual ~TrilinosLaplacianMeshMovingStrategy()
Definition: trilinos_laplacian_meshmoving_strategy.h:143
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: trilinos_laplacian_meshmoving_strategy.h:75
void Initialize() override
Definition: trilinos_laplacian_meshmoving_strategy.h:151
double Solve() override
The problem of interest is solved.
Definition: trilinos_laplacian_meshmoving_strategy.h:154
TrilinosLaplacianMeshMovingStrategy(Epetra_MpiComm &Communicator, ModelPart &model_part, typename TLinearSolver::Pointer pNewLinearSolver, int TimeOrder=1, bool ReformDofSetAtEachStep=false, bool ComputeReactions=false, bool CalculateMeshVelocities=true, int EchoLevel=0)
Definition: trilinos_laplacian_meshmoving_strategy.h:86
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
void CalculateMeshVelocities(ModelPart &rModelPart, const TimeDiscretization::BDF1 &rBDF)
Definition: mesh_velocity_calculation.cpp:56
ProcessInfo & GetProcessInfo(ModelPart &rModelPart)
Definition: add_model_part_to_python.cpp:54
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
integer i
Definition: TensorModule.f:17