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.
lspg_rom_builder_and_solver.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: Sebastian Ares de Parga Regalado
11 // Eduard Gomez Escandell
12 //
13 
14 #pragma once
15 
16 /* System includes */
17 
18 /* External includes */
19 #include <Eigen/Core>
20 #include <Eigen/Dense>
21 
22 /* Project includes */
23 #include "includes/define.h"
24 #include "includes/model_part.h"
29 
30 /* Application includes */
34 
35 namespace Kratos
36 {
37 
40 
41 
45 
46 
50 
51 
55 
56 
60 
80 template <class TSparseSpace, class TDenseSpace, class TLinearSolver>
81 class LeastSquaresPetrovGalerkinROMBuilderAndSolver : public GlobalROMBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>
82 {
83 public:
84 
87 
88  // Class pointer definition
90 
91  // The size_t types
92  using SizeType = std::size_t;
93  using IndexType = std::size_t;
94 
97 
108 
109  // Eigen definitions
110  using EigenDynamicMatrix = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
111  using EigenDynamicVector = Eigen::Matrix<double, Eigen::Dynamic, 1>;
112  using EigenSparseMatrix = Eigen::SparseMatrix<double, Eigen::RowMajor, int>;
113 
115  using NodeType = Node;
116 
117  // Bring the base class function into scope
118  using BaseType::ProjectROM;
119 
123 
125  typename TLinearSolver::Pointer pNewLinearSystemSolver,
126  Parameters ThisParameters) : BaseType(pNewLinearSystemSolver)
127  {
128  // Validate and assign defaults
129  Parameters this_parameters_copy = ThisParameters.Clone();
130  this_parameters_copy = BaseType::ValidateAndAssignParameters(this_parameters_copy, GetDefaultParameters());
131  AssignSettings(this_parameters_copy);
132  }
133 
135 
139 
140 
144 
146  typename TSchemeType::Pointer pScheme,
147  ModelPart &rModelPart) override
148  {
149  KRATOS_TRY;
150 
151  KRATOS_INFO_IF("GlobalLeastSquaresPetrovGalerkinROMBuilderAndSolver", (BaseType::GetEchoLevel() > 1)) << "Setting up the dofs" << std::endl;
152  KRATOS_INFO_IF("GlobalLeastSquaresPetrovGalerkinROMBuilderAndSolver", (BaseType::GetEchoLevel() > 2)) << "Number of threads" << ParallelUtilities::GetNumThreads() << "\n" << std::endl;
153  KRATOS_INFO_IF("GlobalLeastSquaresPetrovGalerkinROMBuilderAndSolver", (BaseType::GetEchoLevel() > 2)) << "Initializing element loop" << std::endl;
154 
155  // Get model part data
156  if (BaseType::mHromWeightsInitialized == false) {
158  }
159 
160  // Compute the complementary mesh for HROM
163  }
164 
165  auto dof_queue = BaseType::ExtractDofSet(pScheme, rModelPart);
166 
167  // Fill a sorted auxiliary array of with the DOFs set
168  KRATOS_INFO_IF("GlobalLeastSquaresPetrovGalerkinROMBuilderAndSolver", (BaseType::GetEchoLevel() > 2)) << "Initializing ordered array filling\n" << std::endl;
169  auto dof_array = BaseType::SortAndRemoveDuplicateDofs(dof_queue);
170 
171  // Update base builder and solver DOFs array and set corresponding flag
172  BaseType::GetDofSet().swap(dof_array);
174 
175  // Throw an exception if there are no DOFs involved in the analysis
176  KRATOS_ERROR_IF(BaseType::GetDofSet().size() == 0) << "No degrees of freedom!" << std::endl;
177  KRATOS_INFO_IF("GlobalLeastSquaresPetrovGalerkinROMBuilderAndSolver", (BaseType::GetEchoLevel() > 2)) << "Number of degrees of freedom:" << BaseType::GetDofSet().size() << std::endl;
178  KRATOS_INFO_IF("GlobalLeastSquaresPetrovGalerkinROMBuilderAndSolver", (BaseType::GetEchoLevel() > 2)) << "Finished setting up the dofs" << std::endl;
179 
180 #ifdef KRATOS_DEBUG
181  // If reactions are to be calculated, we check if all the dofs have reactions defined
183  {
184  for (const auto& r_dof: BaseType::GetDofSet())
185  {
186  KRATOS_ERROR_IF_NOT(r_dof.HasReaction())
187  << "Reaction variable not set for the following :\n"
188  << "Node : " << r_dof.Id() << '\n'
189  << "Dof : " << r_dof << '\n'
190  << "Not possible to calculate reactions." << std::endl;
191  }
192  }
193 #endif
194  KRATOS_CATCH("");
195  }
196 
200  virtual void BuildAndProjectROM(
201  typename TSchemeType::Pointer pScheme,
202  ModelPart &rModelPart,
203  TSystemMatrixType &rA,
204  TSystemVectorType &rb,
205  TSystemVectorType &rDx) override
206  {
207  KRATOS_TRY
208 
209  KRATOS_ERROR_IF(!pScheme) << "No scheme provided!" << std::endl;
210 
211  const auto assembling_timer = BuiltinTimer();
212 
213  BuildAndApplyDirichletConditions(pScheme, rModelPart, rA, rb, rDx);
214 
215  TSystemMatrixType r_a_comp = ZeroMatrix(0,0);
216  TSystemVectorType r_b_comp = ZeroVector(0);
218  BuildWithComplementaryMeshAndApplyDirichletConditions(pScheme, rModelPart, r_a_comp, r_b_comp, rDx);
219  }
220 
223  }
224 
225  ProjectROM(rModelPart, rA, rb, r_a_comp);
226 
227  double time = assembling_timer.ElapsedSeconds();
228  KRATOS_INFO_IF("LeastSquaresPetrovGalerkinROMBuilderAndSolver", (BaseType::GetEchoLevel() > 0)) << "Build and project time: " << time << std::endl;
229 
230  KRATOS_CATCH("")
231  }
232 
234  typename TSchemeType::Pointer pScheme,
235  ModelPart &rModelPart,
236  TSystemMatrixType &rA,
237  TSystemVectorType &rb,
238  TSystemVectorType &rDx
239  ){
242  BaseType::ConstructMatrixStructure(pScheme, rA, rModelPart);
243  }
244 
245  BaseType::Build(pScheme, rModelPart, rA, rb);
246 
247  BaseType::ApplyDirichletConditions(pScheme, rModelPart, rA, rDx, rb);
248  }
249 
251  typename TSchemeType::Pointer pScheme,
252  ModelPart &rModelPart,
253  TSystemMatrixType &rAComp,
254  TSystemVectorType &rBComp,
255  TSystemVectorType &rDx
256  ){
259  BaseType::ConstructMatrixStructure(pScheme, rAComp, rModelPart);
260  }
261 
263  rBComp.resize(BaseBuilderAndSolverType::mEquationSystemSize, false);
264 
265  BuildWithComplementaryMesh(pScheme, rModelPart, rAComp, rBComp);
266 
267  BaseType::ApplyDirichletConditions(pScheme, rModelPart, rAComp, rDx, rBComp);
268 
269  // Check if the selected DOFs have been initialized
270  if (!mIsSelectedDofsInitialized) {
271  InitializeSelectedDofs(rModelPart);
272  mIsSelectedDofsInitialized = true;
273  }
274 
275  // Zero out rows in 'rA' for DOFs not in selected elements/conditions and without overlap.
277  }
278 
287  ModelPart& rModelPart
288  ) {
289  auto add_selected_dofs = [&](auto& rEntityContainer) {
290  for (auto& rEntity : rEntityContainer) {
291  typename std::remove_reference<decltype(rEntity)>::type::DofsVectorType dofs;
292  rEntity.GetDofList(dofs, rModelPart.GetProcessInfo());
293  for (const auto& dof : dofs) {
294  mSelectedDofs.insert(dof->EquationId());
295  }
296  }
297  };
298 
299  // Populate the selected DOFs set.
300  add_selected_dofs(BaseType::mSelectedElements);
301  add_selected_dofs(BaseType::mSelectedConditions);
302  }
303 
315  TSystemMatrixType& rA)
316  {
317  // Use parallel utilities to zero out the rows of the system matrix that are not part of the selected DOFs.
318  IndexPartition<std::size_t>(rA.size1()).for_each([&](std::size_t i) {
319  if (mSelectedDofs.find(i) == mSelectedDofs.end()) {
320  row(rA, i) = zero_vector<double>(rA.size2());
321  }
322  });
323  }
324 
326  const ModelPart& rModelPart,
327  Matrix& rPhiGlobal
328  )
329  {
330  BaseType::BuildRightROMBasis(rModelPart, rPhiGlobal);
331  }
332 
336  virtual void ProjectROM(
337  ModelPart &rModelPart,
338  TSystemMatrixType &rA,
339  TSystemVectorType &rb,
340  TSystemMatrixType &rAComp
341  )
342  {
343  KRATOS_TRY
344 
345  if (mRightRomBasisInitialized==false){
347  mRightRomBasisInitialized = true;
348  }
349 
350  BaseType::BuildRightROMBasis(rModelPart, mPhiGlobal);
351  auto a_wrapper = UblasWrapper<double>(rA);
352  const auto& eigen_rA = a_wrapper.matrix();
353  Eigen::Map<EigenDynamicVector> eigen_rb(rb.data().begin(), rb.size());
354  Eigen::Map<EigenDynamicMatrix> eigen_mPhiGlobal(mPhiGlobal.data().begin(), mPhiGlobal.size1(), mPhiGlobal.size2());
355 
356  EigenDynamicMatrix eigen_rA_times_mPhiGlobal = eigen_rA * eigen_mPhiGlobal; //TODO: Make it in parallel.
357 
359  if (mSolvingTechnique != "normal_equations") {
360  KRATOS_ERROR << "LeastSquaresPetrovGalerkinHROM is only valid for 'normal_equations'. The provided solving technique is '" << mSolvingTechnique << "'." << std::endl;
361  }
362 
363  auto a_comp_wrapper = UblasWrapper<double>(rAComp);
364  const auto& eigen_rAComp = a_comp_wrapper.matrix();
365 
366  EigenDynamicMatrix eigen_rAComp_times_mPhiGlobal = eigen_rAComp * eigen_mPhiGlobal; //TODO: Make it in parallel.
367 
368  if (mSolvingTechnique == "normal_equations") {
369  // Compute the matrix multiplication
370  mEigenRomA = eigen_rAComp_times_mPhiGlobal.transpose() * eigen_rA_times_mPhiGlobal; //TODO: Make it in parallel.
371  mEigenRomB = eigen_rAComp_times_mPhiGlobal.transpose() * eigen_rb; //TODO: Make it in parallel.
372  }
373  }
374  else {
375 
376  if (mSolvingTechnique == "normal_equations"){
377  // Compute the matrix multiplication
378  mEigenRomA = eigen_rA_times_mPhiGlobal.transpose() * eigen_rA_times_mPhiGlobal; //TODO: Make it in parallel.
379  mEigenRomB = eigen_rA_times_mPhiGlobal.transpose() * eigen_rb; //TODO: Make it in parallel.
380  }
381  else if (mSolvingTechnique == "qr_decomposition") {
382  mEigenRomA = eigen_rA_times_mPhiGlobal;
383  mEigenRomB = eigen_rb;
384  }
385  }
386 
387  KRATOS_CATCH("")
388  }
389 
391  ModelPart& rModelPart,
392  const std::stringstream& MatrixMarketVectorName
393  )
394  {
395 
396  std::vector<const Variable<double>*> variables;
397  for (const auto& unknown : mNodalUnknowns) {
398  variables.push_back(&KratosComponents<Variable<double>>::Get(unknown));
399  }
400 
401  std::vector<double> aux_data_array;
402 
403  // Loop over all nodes
404  for (auto& node : rModelPart.Nodes()) {
405  for (const auto* var : variables) {
406  // Check if the node has the DoF
407  if (node.HasDofFor(*var)) {
408  // Get the DoF
409  const auto& dof = node.pGetDof(*var);
410 
411  // Get the reaction value and add it to the array
412  aux_data_array.push_back(dof->GetSolutionStepReactionValue());
413  }
414  }
415  }
416 
417  // Convert std::vector to Ublas Vector
418  Vector aux_vector(aux_data_array.size());
419  std::copy(aux_data_array.begin(), aux_data_array.end(), aux_vector.begin());
420 
421  // Write the vector to a MatrixMarket file
422  SparseSpaceType::WriteMatrixMarketVector(MatrixMarketVectorName.str().c_str(), aux_vector);
423  }
424 
426  typename TSchemeType::Pointer pScheme,
427  ModelPart &rModelPart,
429  TSystemVectorType &Dx,
430  TSystemVectorType &b) override
431  {
432  KRATOS_TRY
433 
434  BuildAndProjectROM(pScheme, rModelPart, A, b, Dx);
435 
436  // Obtain the assembled residuals vector (To build a basis for Petrov-Galerkin)
437  if (mTrainPetrovGalerkinFlag) {
438  std::stringstream matrix_market_vector_name;
439  matrix_market_vector_name << "R_" << rModelPart.GetProcessInfo()[TIME]
440  << "_" << rModelPart.GetProcessInfo()[NL_ITERATION_NUMBER]
441  << ".res.mm";
442  if (mBasisStrategy == "residuals") {
443  SparseSpaceType::WriteMatrixMarketVector(matrix_market_vector_name.str().c_str(), b);
444  }
445  else if (mBasisStrategy == "reactions") { // Assuming "reactions" or another suitable keyword
446  BaseType::CalculateReactions(pScheme, rModelPart, A, Dx, b);
447  WriteReactionDataToMatrixMarket(rModelPart, matrix_market_vector_name);
448  }
449  }
450 
451 
452  if (mSolvingTechnique == "normal_equations"){
453  BaseType::SolveROM(rModelPart, mEigenRomA, mEigenRomB, Dx);
454  }
455  else if (mSolvingTechnique == "qr_decomposition"){
456  BaseType::SolveROM(rModelPart, mEigenRomA, mEigenRomB, Dx);
457  }
458 
459  KRATOS_CATCH("")
460  }
461 
463  {
464  Parameters default_parameters = Parameters(R"(
465  {
466  "name" : "lspg_rom_builder_and_solver",
467  "nodal_unknowns" : [],
468  "number_of_rom_dofs" : 10,
469  "rom_bns_settings": {
470  "train_petrov_galerkin" : false,
471  "solving_technique" : "normal_equations",
472  "basis_strategy" : "residuals",
473  "monotonicity_preserving" : false
474  }
475  })");
477 
478  return default_parameters;
479  }
480 
481  static std::string Name()
482  {
483  return "lspg_rom_builder_and_solver";
484  }
485 
489 
490 
494 
495 
499 
501  virtual std::string Info() const override
502  {
503  return "LeastSquaresPetrovGalerkinROMBuilderAndSolver";
504  }
505 
507  virtual void PrintInfo(std::ostream &rOStream) const override
508  {
509  rOStream << Info();
510  }
511 
513  virtual void PrintData(std::ostream &rOStream) const override
514  {
515  rOStream << Info();
516  }
517 
521 
523 protected:
524 
528 
529 
535 
539 
540 
544 
545  void AssignSettings(const Parameters ThisParameters) override
546  {
547  BaseType::AssignSettings(ThisParameters);
548 
549  // // Set member variables
550  mNodalUnknowns = ThisParameters["nodal_unknowns"].GetStringArray();
551  mTrainPetrovGalerkinFlag = ThisParameters["rom_bns_settings"]["train_petrov_galerkin"].GetBool();
552  mBasisStrategy = ThisParameters["rom_bns_settings"]["basis_strategy"].GetString();
553  mSolvingTechnique = ThisParameters["rom_bns_settings"]["solving_technique"].GetString();
554  }
555 
564  typename TSchemeType::Pointer pScheme,
565  ModelPart& rModelPart,
568  {
569  KRATOS_TRY
570 
571  KRATOS_ERROR_IF(!pScheme) << "No scheme provided!" << std::endl;
572 
573  // // Getting the neighbouring (complementary mesh) and selected elements from the model
574  auto& r_neighboring_and_selected_elems = mNeighbouringAndSelectedElements;
575 
576  const int nelements = r_neighboring_and_selected_elems.size();
577 
578  // // Getting the neighbouring (complementary mesh) and selected conditions from the model
579  auto& r_neighboring_and_selected_conditions = mNeighbouringAndSelectedConditions;
580 
581  const int nconditions = r_neighboring_and_selected_conditions.size();
582 
583  const ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo();
584  ModelPart::ElementsContainerType::iterator el_begin = mNeighbouringAndSelectedElements.begin();
585  ModelPart::ConditionsContainerType::iterator cond_begin = mNeighbouringAndSelectedConditions.begin();
586 
587  //contributions to the system
588  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
589  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
590 
591  //vector containing the localization in the system of the different terms
593 
594  // Assemble all elements
595  const auto timer = BuiltinTimer();
596 
597  #pragma omp parallel firstprivate(nelements,nconditions, LHS_Contribution, RHS_Contribution, EquationId)
598  {
599  # pragma omp for schedule(guided, 512) nowait
600  for (int k = 0; k < nelements; k++) {
601  auto it_elem = el_begin + k;
602 
603  if (it_elem->IsActive()) {
604  // Calculate elemental contribution
605  pScheme->CalculateSystemContributions(*it_elem, LHS_Contribution, RHS_Contribution, EquationId, CurrentProcessInfo);
606 
607  // Assemble lhs the elemental contribution
608  BaseType::Assemble(A, b, LHS_Contribution, RHS_Contribution, EquationId);
609  }
610 
611  }
612 
613  #pragma omp for schedule(guided, 512)
614  for (int k = 0; k < nconditions; k++) {
615  auto it_cond = cond_begin + k;
616 
617  if (it_cond->IsActive()) {
618  // Calculate elemental contribution
619  pScheme->CalculateSystemContributions(*it_cond, LHS_Contribution, RHS_Contribution, EquationId, CurrentProcessInfo);
620 
621  // Assemble lhs the elemental contribution
622  BaseType::Assemble(A, b, LHS_Contribution, RHS_Contribution, EquationId);
623  }
624  }
625  }
626 
627  KRATOS_INFO_IF("LeastSquaresPetrovGalerkinROMResidualBasedBlockBuilderAndSolver", BaseType::GetEchoLevel() >= 1) << "Build time: " << timer.ElapsedSeconds() << std::endl;
628 
629  KRATOS_INFO_IF("LeastSquaresPetrovGalerkinROMResidualBasedBlockBuilderAndSolver", (BaseType::GetEchoLevel() > 2 && rModelPart.GetCommunicator().MyPID() == 0)) << "Finished parallel building" << std::endl;
630 
631  KRATOS_CATCH("")
632  }
633 
635  {
638 
639  // Create sets for storing Ids
640  std::set<int> selected_element_ids;
641  std::set<int> selected_condition_ids;
642 
643  FindGlobalNodalEntityNeighboursProcess<ModelPart::ElementsContainerType> find_nodal_elements_neighbours_process(rModelPart);
644  find_nodal_elements_neighbours_process.Execute();
645  FindGlobalNodalEntityNeighboursProcess<ModelPart::ConditionsContainerType> find_nodal_conditions_neighbours_process(rModelPart);
646  find_nodal_conditions_neighbours_process.Execute();
647 
648  for (auto it_elem = BaseType::mSelectedElements.ptr_begin(); it_elem != BaseType::mSelectedElements.ptr_end(); ++it_elem) {
649  mNeighbouringAndSelectedElements.push_back(*it_elem);
650  selected_element_ids.insert((*it_elem)->Id());
651 
652  const auto& r_geom = (*it_elem)->GetGeometry();
653  const SizeType n_nodes = r_geom.PointsNumber();
654  for (IndexType i_node = 0; i_node < n_nodes; ++i_node) {
655  NodeType::Pointer p_node = r_geom(i_node);
656  auto& neighbour_elements = p_node->GetValue(NEIGHBOUR_ELEMENTS);
657  for (auto& neighbor_elem : neighbour_elements.GetContainer()) {
658  if(selected_element_ids.find(neighbor_elem->Id()) == selected_element_ids.end()) {
659  mNeighbouringAndSelectedElements.push_back(&*neighbor_elem);
660  selected_element_ids.insert(neighbor_elem->Id());
661  }
662  }
663 
664  // Check and add neighbouring conditions
665  auto& neighbour_conditions = p_node->GetValue(NEIGHBOUR_CONDITIONS);
666  for (auto& neighbor_cond : neighbour_conditions.GetContainer()) {
667  if(selected_condition_ids.find(neighbor_cond->Id()) == selected_condition_ids.end()) {
668  mNeighbouringAndSelectedConditions.push_back(&*neighbor_cond);
669  selected_condition_ids.insert(neighbor_cond->Id());
670  }
671  }
672  }
673  }
674 
675  for (auto it_cond = BaseType::mSelectedConditions.ptr_begin(); it_cond != BaseType::mSelectedConditions.ptr_end(); ++it_cond) {
676  mNeighbouringAndSelectedConditions.push_back(*it_cond);
677  selected_condition_ids.insert((*it_cond)->Id());
678 
679  const auto& r_geom = (*it_cond)->GetGeometry();
680  const SizeType n_nodes = r_geom.PointsNumber();
681  for (IndexType i_node = 0; i_node < n_nodes; ++i_node) {
682  NodeType::Pointer p_node = r_geom(i_node);
683  auto& neighbour_conditions = p_node->GetValue(NEIGHBOUR_CONDITIONS);
684  for (auto& neighbor_cond : neighbour_conditions.GetContainer()) {
685  if(selected_condition_ids.find(neighbor_cond->Id()) == selected_condition_ids.end()) {
686  mNeighbouringAndSelectedConditions.push_back(&*neighbor_cond);
687  selected_condition_ids.insert(neighbor_cond->Id());
688  }
689  }
690 
691  // Check and add neighbouring elements
692  auto& neighbour_elements = p_node->GetValue(NEIGHBOUR_ELEMENTS);
693  for (auto& neighbor_elem : neighbour_elements.GetContainer()) {
694  if(selected_element_ids.find(neighbor_elem->Id()) == selected_element_ids.end()) {
695  mNeighbouringAndSelectedElements.push_back(&*neighbor_elem);
696  selected_element_ids.insert(neighbor_elem->Id());
697  }
698  }
699  }
700  }
701 
702  std::unordered_map<int, Element::Pointer> unique_elements_map;
703  for (const auto& elem : mNeighbouringAndSelectedElements) {
704  unique_elements_map[elem.Id()] = intrusive_ptr<Element>(const_cast<Element*>(&elem));
705  }
707  for (const auto& pair : unique_elements_map) {
708  mNeighbouringAndSelectedElements.push_back(pair.second);
709  }
710 
711  std::unordered_map<int, Condition::Pointer> unique_conditions_map;
712  for (const auto& cond : mNeighbouringAndSelectedConditions) {
713  unique_conditions_map[cond.Id()] = intrusive_ptr<Condition>(const_cast<Condition*>(&cond));
714  }
716  for (const auto& pair : unique_conditions_map) {
717  mNeighbouringAndSelectedConditions.push_back(pair.second);
718  }
719  }
720 
724 
725 
729 
730 
734 
735 private:
736  std::vector<std::string> mNodalUnknowns;
737  bool mTrainPetrovGalerkinFlag = false;
738  std::string mBasisStrategy;
739  std::string mSolvingTechnique;
740  EigenDynamicMatrix mEigenRomA;
741  EigenDynamicVector mEigenRomB;
742  Matrix mPhiGlobal;
743  bool mRightRomBasisInitialized = false;
744  std::unordered_set<std::size_t> mSelectedDofs;
745  bool mIsSelectedDofsInitialized = false;
746 
750 
752 }; /* Class LeastSquaresPetrovGalerkinROMBuilderAndSolver */
753 
757 
758 
760 
761 } /* namespace Kratos.*/
762 
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
std::size_t IndexType
Definition of the index type.
Definition: builder_and_solver.h:76
TSparseSpace::VectorType TSystemVectorType
Definition of the vector size.
Definition: builder_and_solver.h:85
bool GetCalculateReactionsFlag() const
This method returns the flag mCalculateReactionsFlag.
Definition: builder_and_solver.h:184
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: builder_and_solver.h:111
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: builder_and_solver.h:767
TDenseSpace::MatrixType LocalSystemMatrixType
The local matrix definition.
Definition: builder_and_solver.h:94
void SetDofSetIsInitializedFlag(bool DofSetIsInitialized)
This method sets the flag mDofSetIsInitialized.
Definition: builder_and_solver.h:211
TDenseSpace::VectorType LocalSystemVectorType
The local vector definition.
Definition: builder_and_solver.h:97
std::size_t SizeType
Definition of the size type.
Definition: builder_and_solver.h:73
int GetEchoLevel() const
It returns the echo level.
Definition: builder_and_solver.h:674
virtual DofsArrayType & GetDofSet()
It allows to get the list of Dofs from the element.
Definition: builder_and_solver.h:507
unsigned int mEquationSystemSize
Flag taking in account if it is needed or not to calculate the reactions.
Definition: builder_and_solver.h:747
ModelPart::ElementsContainerType ElementsArrayType
Definition: builder_and_solver.h:110
Definition: builtin_timer.h:26
virtual int MyPID() const
Definition: communicator.cpp:91
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: find_global_nodal_entity_neighbours_process.cpp:111
Definition: global_rom_builder_and_solver.h:64
bool GetMonotonicityPreservingFlag() const noexcept
Definition: global_rom_builder_and_solver.h:238
Eigen::SparseMatrix< double, Eigen::RowMajor, int > EigenSparseMatrix
Definition: global_rom_builder_and_solver.h:112
virtual void ProjectROM(ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb)
Definition: global_rom_builder_and_solver.h:749
Eigen::Matrix< double, Eigen::Dynamic, 1 > EigenDynamicVector
Definition: global_rom_builder_and_solver.h:111
typename BaseBuilderAndSolverType::TSystemVectorType TSystemVectorType
Definition: global_rom_builder_and_solver.h:95
bool mHromSimulation
Definition: global_rom_builder_and_solver.h:459
void BuildRightROMBasis(const ModelPart &rModelPart, Matrix &rPhiGlobal)
Definition: global_rom_builder_and_solver.h:258
virtual void SolveROM(ModelPart &rModelPart, EigenDynamicMatrix &rEigenRomA, EigenDynamicVector &rEigenRomB, TSystemVectorType &rDx)
Definition: global_rom_builder_and_solver.h:780
static DofsArrayType SortAndRemoveDuplicateDofs(DofQueue &rDofQueue)
Definition: global_rom_builder_and_solver.h:595
void Build(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &b) override
Function to perform the build of the LHS and RHS multiplied by its corresponding hrom weight.
Definition: global_rom_builder_and_solver.h:668
SizeType GetNumberOfROMModes() const noexcept
Definition: global_rom_builder_and_solver.h:233
ElementsArrayType mSelectedElements
Definition: global_rom_builder_and_solver.h:457
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: global_rom_builder_and_solver.h:390
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: global_rom_builder_and_solver.h:471
static DofQueue ExtractDofSet(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart)
Definition: global_rom_builder_and_solver.h:546
void MonotonicityPreserving(TSystemMatrixType &rA, TSystemVectorType &rB)
Definition: global_rom_builder_and_solver.h:278
typename BaseBuilderAndSolverType::TSystemMatrixType TSystemMatrixType
Definition: global_rom_builder_and_solver.h:94
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > EigenDynamicMatrix
Definition: global_rom_builder_and_solver.h:110
bool mHromWeightsInitialized
Definition: global_rom_builder_and_solver.h:460
typename BaseBuilderAndSolverType::ConditionsArrayType ConditionsArrayType
Definition: global_rom_builder_and_solver.h:101
void InitializeHROMWeights(ModelPart &rModelPart)
Definition: global_rom_builder_and_solver.h:493
typename BaseBuilderAndSolverType::TSchemeType TSchemeType
Definition: global_rom_builder_and_solver.h:92
ConditionsArrayType mSelectedConditions
Definition: global_rom_builder_and_solver.h:458
typename BaseBuilderAndSolverType::ElementsArrayType ElementsArrayType
Definition: global_rom_builder_and_solver.h:100
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
iterator begin()
Definition: amatrix_interface.h:241
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
This class provides an implementation for the LeastSquaresPetrovGalerkinROM builder and solver operat...
Definition: lspg_rom_builder_and_solver.h:82
virtual std::string Info() const override
Turn back information as a string.
Definition: lspg_rom_builder_and_solver.h:501
void GetRightROMBasis(const ModelPart &rModelPart, Matrix &rPhiGlobal)
Definition: lspg_rom_builder_and_solver.h:325
void BuildWithComplementaryMeshAndApplyDirichletConditions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rAComp, TSystemVectorType &rBComp, TSystemVectorType &rDx)
Definition: lspg_rom_builder_and_solver.h:250
virtual void BuildAndProjectROM(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb, TSystemVectorType &rDx) override
Definition: lspg_rom_builder_and_solver.h:200
ElementsArrayType mNeighbouringAndSelectedElements
Definition: lspg_rom_builder_and_solver.h:533
virtual void PrintData(std::ostream &rOStream) const override
Print object's.
Definition: lspg_rom_builder_and_solver.h:513
virtual void ProjectROM(ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb, TSystemMatrixType &rAComp)
Definition: lspg_rom_builder_and_solver.h:336
void ZeroOutUnselectedComplementaryMeshRows(TSystemMatrixType &rA)
Zeroes out the rows of the system matrix that correspond to the complementary mesh.
Definition: lspg_rom_builder_and_solver.h:314
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: lspg_rom_builder_and_solver.h:545
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: lspg_rom_builder_and_solver.h:462
void BuildWithComplementaryMesh(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &b)
Function to perform the build of the LHS and RHS on the selected elements and the corresponding compl...
Definition: lspg_rom_builder_and_solver.h:563
typename BaseBuilderAndSolverType::LocalSystemMatrixType LocalSystemMatrixType
Definition: lspg_rom_builder_and_solver.h:107
void BuildAndSolve(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Function to perform the building and solving phase at the same time.
Definition: lspg_rom_builder_and_solver.h:425
void BuildAndApplyDirichletConditions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb, TSystemVectorType &rDx)
Definition: lspg_rom_builder_and_solver.h:233
static std::string Name()
Definition: lspg_rom_builder_and_solver.h:481
void FindNeighbouringElementsAndConditions(ModelPart &rModelPart)
Definition: lspg_rom_builder_and_solver.h:634
KRATOS_CLASS_POINTER_DEFINITION(LeastSquaresPetrovGalerkinROMBuilderAndSolver)
void WriteReactionDataToMatrixMarket(ModelPart &rModelPart, const std::stringstream &MatrixMarketVectorName)
Definition: lspg_rom_builder_and_solver.h:390
LeastSquaresPetrovGalerkinROMBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Definition: lspg_rom_builder_and_solver.h:124
void SetUpDofSet(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart) override
Builds the list of the DofSets involved in the problem by "asking" to each element and condition its ...
Definition: lspg_rom_builder_and_solver.h:145
ConditionsArrayType mNeighbouringAndSelectedConditions
Definition: lspg_rom_builder_and_solver.h:534
void InitializeSelectedDofs(ModelPart &rModelPart)
Initializes the selected DOFs based on the selected elements and conditions.
Definition: lspg_rom_builder_and_solver.h:286
virtual void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: lspg_rom_builder_and_solver.h:507
typename BaseBuilderAndSolverType::LocalSystemVectorType LocalSystemVectorType
Definition: lspg_rom_builder_and_solver.h:106
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
std::vector< std::string > GetStringArray() const
This method returns the array of strings in the current Parameter.
Definition: kratos_parameters.cpp:693
Parameters Clone() const
Generates a clone of the current document.
Definition: kratos_parameters.cpp:397
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
void AddMissingParameters(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing contain at least all parameters...
Definition: kratos_parameters.cpp:1369
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
void swap(PointerVectorSet &rOther)
Swaps the contents of this PointerVectorSet with another.
Definition: pointer_vector_set.h:532
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
void ApplyDirichletConditions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Applies the dirichlet conditions. This operation may be very heavy or completely unexpensive dependin...
Definition: residualbased_block_builder_and_solver.h:940
virtual void ConstructMatrixStructure(typename TSchemeType::Pointer pScheme, TSystemMatrixType &A, ModelPart &rModelPart)
Definition: residualbased_block_builder_and_solver.h:1457
void Assemble(TSystemMatrixType &A, TSystemVectorType &b, const LocalSystemMatrixType &LHS_Contribution, const LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId)
Definition: residualbased_block_builder_and_solver.h:1566
void CalculateReactions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
It computes the reactions of the system.
Definition: residualbased_block_builder_and_solver.h:909
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
static bool WriteMatrixMarketVector(const char *pFileName, const VectorType &rV)
Definition: ublas_space.h:920
Definition: ublas_wrapper.h:32
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Eigen::Matrix< _Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > EigenDynamicMatrix
Definition: linear_solvers_define.h:32
Eigen::Matrix< _Scalar, Eigen::Dynamic, 1 > EigenDynamicVector
Definition: linear_solvers_define.h:33
time
Definition: face_heat.py:85
dofs
Enforced auxTangentSlipNonObjective = delta_time * gap_time_derivative_non_objective....
Definition: generate_frictional_mortar_condition.py:210
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int n_nodes
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:15
int dof
Definition: ode_solve.py:393
int k
Definition: quadrature.py:595
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17
Definition: timer.py:1
Definition: mesh_converter.cpp:38