20 #include <Eigen/Dense>
80 template <
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
125 typename TLinearSolver::Pointer pNewLinearSystemSolver,
146 typename TSchemeType::Pointer pScheme,
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;
201 typename TSchemeType::Pointer pScheme,
227 double time = assembling_timer.ElapsedSeconds();
234 typename TSchemeType::Pointer pScheme,
251 typename TSchemeType::Pointer pScheme,
270 if (!mIsSelectedDofsInitialized) {
272 mIsSelectedDofsInitialized =
true;
289 auto add_selected_dofs = [&](
auto& rEntityContainer) {
290 for (
auto& rEntity : rEntityContainer) {
291 typename std::remove_reference<decltype(rEntity)>::type::DofsVectorType
dofs;
294 mSelectedDofs.insert(
dof->EquationId());
319 if (mSelectedDofs.find(
i) == mSelectedDofs.end()) {
320 row(rA, i) = zero_vector<double>(rA.size2());
345 if (mRightRomBasisInitialized==
false){
347 mRightRomBasisInitialized =
true;
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());
359 if (mSolvingTechnique !=
"normal_equations") {
360 KRATOS_ERROR <<
"LeastSquaresPetrovGalerkinHROM is only valid for 'normal_equations'. The provided solving technique is '" << mSolvingTechnique <<
"'." << std::endl;
364 const auto& eigen_rAComp = a_comp_wrapper.matrix();
368 if (mSolvingTechnique ==
"normal_equations") {
370 mEigenRomA = eigen_rAComp_times_mPhiGlobal.transpose() * eigen_rA_times_mPhiGlobal;
371 mEigenRomB = eigen_rAComp_times_mPhiGlobal.transpose() * eigen_rb;
376 if (mSolvingTechnique ==
"normal_equations"){
378 mEigenRomA = eigen_rA_times_mPhiGlobal.transpose() * eigen_rA_times_mPhiGlobal;
379 mEigenRomB = eigen_rA_times_mPhiGlobal.transpose() * eigen_rb;
381 else if (mSolvingTechnique ==
"qr_decomposition") {
382 mEigenRomA = eigen_rA_times_mPhiGlobal;
383 mEigenRomB = eigen_rb;
392 const std::stringstream& MatrixMarketVectorName
396 std::vector<const Variable<double>*> variables;
397 for (
const auto& unknown : mNodalUnknowns) {
401 std::vector<double> aux_data_array;
405 for (
const auto* var : variables) {
407 if (
node.HasDofFor(*var)) {
409 const auto&
dof =
node.pGetDof(*var);
412 aux_data_array.push_back(
dof->GetSolutionStepReactionValue());
418 Vector aux_vector(aux_data_array.size());
419 std::copy(aux_data_array.begin(), aux_data_array.end(), aux_vector.
begin());
426 typename TSchemeType::Pointer pScheme,
437 if (mTrainPetrovGalerkinFlag) {
438 std::stringstream matrix_market_vector_name;
439 matrix_market_vector_name <<
"R_" << rModelPart.
GetProcessInfo()[TIME]
442 if (mBasisStrategy ==
"residuals") {
445 else if (mBasisStrategy ==
"reactions") {
452 if (mSolvingTechnique ==
"normal_equations"){
455 else if (mSolvingTechnique ==
"qr_decomposition"){
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
478 return default_parameters;
483 return "lspg_rom_builder_and_solver";
501 virtual std::string
Info()
const override
503 return "LeastSquaresPetrovGalerkinROMBuilderAndSolver";
507 virtual void PrintInfo(std::ostream &rOStream)
const override
513 virtual void PrintData(std::ostream &rOStream)
const override
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();
564 typename TSchemeType::Pointer pScheme,
576 const int nelements = r_neighboring_and_selected_elems.size();
581 const int nconditions = r_neighboring_and_selected_conditions.size();
597 #pragma omp parallel firstprivate(nelements,nconditions, LHS_Contribution, RHS_Contribution, EquationId)
599 # pragma omp for schedule(guided, 512) nowait
600 for (
int k = 0;
k < nelements;
k++) {
601 auto it_elem = el_begin +
k;
603 if (it_elem->IsActive()) {
605 pScheme->CalculateSystemContributions(*it_elem, LHS_Contribution, RHS_Contribution, EquationId, CurrentProcessInfo);
613 #pragma omp for schedule(guided, 512)
614 for (
int k = 0;
k < nconditions;
k++) {
615 auto it_cond = cond_begin +
k;
617 if (it_cond->IsActive()) {
619 pScheme->CalculateSystemContributions(*it_cond, LHS_Contribution, RHS_Contribution, EquationId, CurrentProcessInfo);
640 std::set<int> selected_element_ids;
641 std::set<int> selected_condition_ids;
644 find_nodal_elements_neighbours_process.
Execute();
646 find_nodal_conditions_neighbours_process.
Execute();
650 selected_element_ids.insert((*it_elem)->Id());
652 const auto& r_geom = (*it_elem)->GetGeometry();
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()) {
660 selected_element_ids.insert(neighbor_elem->Id());
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()) {
669 selected_condition_ids.insert(neighbor_cond->Id());
677 selected_condition_ids.insert((*it_cond)->Id());
679 const auto& r_geom = (*it_cond)->GetGeometry();
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()) {
687 selected_condition_ids.insert(neighbor_cond->Id());
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()) {
696 selected_element_ids.insert(neighbor_elem->Id());
702 std::unordered_map<int, Element::Pointer> unique_elements_map;
704 unique_elements_map[elem.Id()] = intrusive_ptr<Element>(
const_cast<Element*
>(&elem));
707 for (
const auto& pair : unique_elements_map) {
711 std::unordered_map<int, Condition::Pointer> unique_conditions_map;
713 unique_conditions_map[cond.Id()] = intrusive_ptr<Condition>(
const_cast<Condition*
>(&cond));
716 for (
const auto& pair : unique_conditions_map) {
736 std::vector<std::string> mNodalUnknowns;
737 bool mTrainPetrovGalerkinFlag =
false;
738 std::string mBasisStrategy;
739 std::string mSolvingTechnique;
743 bool mRightRomBasisInitialized =
false;
744 std::unordered_set<std::size_t> mSelectedDofs;
745 bool mIsSelectedDofsInitialized =
false;
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
~LeastSquaresPetrovGalerkinROMBuilderAndSolver()=default
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: mesh_converter.cpp:38