18 #include "concurrentqueue/concurrentqueue.h"
77 template <
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
127 typedef moodycamel::ConcurrentQueue<DofType::Pointer>
DofQueue;
134 typename TLinearSolver::Pointer pNewLinearSystemSolver,
156 typename TSchemeType::Pointer pScheme,
173 KRATOS_INFO_IF(
"PetrovGalerkinROMBuilderAndSolver", (this->
GetEchoLevel() > 2)) <<
"Initializing ordered array filling\n" << std::endl;
183 KRATOS_INFO_IF(
"PetrovGalerkinROMBuilderAndSolver", (this->
GetEchoLevel() > 2)) <<
"Finished setting up the dofs" << std::endl;
192 <<
"Reaction variable not set for the following :\n"
193 <<
"Node : " << r_dof.Id() <<
'\n'
194 <<
"Dof : " << r_dof <<
'\n'
195 <<
"Not possible to calculate reactions." << std::endl;
203 typename TSchemeType::Pointer pScheme,
212 BuildROM(pScheme, rModelPart, Arom, brom);
213 SolveROM(rModelPart, Arom, brom, Dx);
223 "name" : "petrov_galerkin_rom_builder_and_solver",
224 "nodal_unknowns" : [],
225 "number_of_rom_dofs" : 10,
226 "petrov_galerkin_number_of_rom_dofs" : 10
230 return default_parameters;
235 return "petrov_galerkin_rom_builder_and_solver";
253 virtual std::string
Info()
const override
255 return "PetrovGalerkinROMBuilderAndSolver";
259 virtual void PrintInfo(std::ostream &rOStream)
const override
265 virtual void PrintData(std::ostream &rOStream)
const override
372 template<
typename TMatrix>
375 if(
mat.size1() != rows ||
mat.size2() != cols) {
376 mat.resize(rows, cols,
false);
384 typename TSchemeType::Pointer pScheme,
409 if(!r_elements.empty())
412 block_for_each<SystemSumReducer>(r_elements, assembly_tls_container,
415 return CalculateLocalContributionPetrovGalerkin(r_element, rA, rb, r_thread_prealloc, *pScheme, r_current_process_info);
422 if(!r_conditions.empty())
427 std::tie(aconditions, bconditions) =
428 block_for_each<SystemSumReducer>(r_conditions, assembly_tls_container,
431 return CalculateLocalContributionPetrovGalerkin(r_condition, rA, rb, r_thread_prealloc, *pScheme, r_current_process_info);
438 KRATOS_INFO_IF(
"PetrovGalerkinROMBuilderAndSolver", (this->
GetEchoLevel() > 0)) <<
"Build time: " << assembling_timer.ElapsedSeconds() << std::endl;
462 qr_decomposition.
Solve(rb, dxrom);
463 KRATOS_INFO_IF(
"PetrovGalerkinROMBuilderAndSolver", (this->
GetEchoLevel() > 0)) <<
"Solve reduced system time: " << solving_timer.ElapsedSeconds() << std::endl;
467 noalias(r_root_mp.GetValue(ROM_SOLUTION_INCREMENT)) += dxrom;
472 KRATOS_INFO_IF(
"PetrovGalerkinROMBuilderAndSolver", (this->
GetEchoLevel() > 0)) <<
"Project to fine basis time: " << backward_projection_timer.ElapsedSeconds() << std::endl;
499 template<
typename TEntity>
500 std::tuple<LocalSystemMatrixType, LocalSystemVectorType> CalculateLocalContributionPetrovGalerkin(
504 AssemblyTLS& rPreAlloc,
508 if (rEntity.IsDefined(ACTIVE) && rEntity.IsNot(ACTIVE))
512 return std::tie(rPreAlloc.romA, rPreAlloc.romB);
516 rScheme.CalculateSystemContributions(rEntity, rPreAlloc.lhs, rPreAlloc.rhs, rPreAlloc.eq_id, rCurrentProcessInfo);
517 rEntity.GetDofList(rPreAlloc.dofs, rCurrentProcessInfo);
519 const SizeType ndofs = rPreAlloc.dofs.size();
520 ResizeIfNeeded(rPreAlloc.phiE, ndofs, this->GetNumberOfROMModes());
522 ResizeIfNeeded(rPreAlloc.aux, ndofs, this->GetNumberOfROMModes());
524 const auto &r_geom = rEntity.GetGeometry();
528 const double h_rom_weight = this->
mHromSimulation ? rEntity.GetValue(HROM_WEIGHT) : 1.0;
530 noalias(rPreAlloc.aux) =
prod(rPreAlloc.lhs, rPreAlloc.phiE);
531 noalias(rPreAlloc.romA) =
prod(
trans(rPreAlloc.psiE), rPreAlloc.aux) * h_rom_weight;
532 noalias(rPreAlloc.romB) =
prod(
trans(rPreAlloc.psiE), rPreAlloc.rhs) * h_rom_weight;
534 return std::tie(rPreAlloc.romA, rPreAlloc.romB);
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
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
Definition: builtin_timer.h:26
Base class for all Conditions.
Definition: condition.h:59
Definition: dense_householder_qr_decomposition.h:45
void Compute(MatrixType &rInputMatrix) override
Compute the QR Computes the QR Decomposition (QR) of the given imput matrix Note that the input matri...
Definition: dense_householder_qr_decomposition.h:92
void Solve(MatrixType &rB, MatrixType &rX) const override
Solves the problem Ax=b Being A the input matrix, this method solves the problem Ax = b.
Definition: dense_householder_qr_decomposition.h:148
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
Base class for all Elements.
Definition: element.h:60
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
Definition: amatrix_interface.h:497
Definition: amatrix_interface.h:530
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ModelPart & GetRootModelPart()
Definition: model_part.cpp:510
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
This class defines the node.
Definition: node.h:65
static LockObject & GetGlobalLock()
Returns the global lock Global lock that can be used for critical sections.
Definition: parallel_utilities.cpp:125
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
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
Parameters Clone() const
Generates a clone of the current document.
Definition: kratos_parameters.cpp:397
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
Current class provides an implementation for PetrovGalerkinROM builder and solving operations.
Definition: petrov_galerkin_rom_builder_and_solver.h:79
NodeType::DofType DofType
Definition: petrov_galerkin_rom_builder_and_solver.h:125
void SolveROM(ModelPart &rModelPart, PetrovGalerkinSystemMatrixType &rA, PetrovGalerkinSystemVectorType &rb, TSystemVectorType &rDx) override
Definition: petrov_galerkin_rom_builder_and_solver.h:447
static std::string Name()
Definition: petrov_galerkin_rom_builder_and_solver.h:233
SizeType mNumberOfPetrovGalerkinRomModes
Definition: petrov_galerkin_rom_builder_and_solver.h:286
ModelPart::MasterSlaveConstraintContainerType MasterSlaveConstraintContainerType
Additional definitions.
Definition: petrov_galerkin_rom_builder_and_solver.h:110
std::size_t SizeType
Definition: petrov_galerkin_rom_builder_and_solver.h:90
virtual std::string Info() const override
Turn back information as a string.
Definition: petrov_galerkin_rom_builder_and_solver.h:253
BaseType::ConditionsArrayType ConditionsArrayType
Definition: petrov_galerkin_rom_builder_and_solver.h:107
BaseType::TSystemVectorType TSystemVectorType
Definition: petrov_galerkin_rom_builder_and_solver.h:101
DofType::Pointer DofPointerType
Definition: petrov_galerkin_rom_builder_and_solver.h:126
BaseType::ElementsArrayType ElementsArrayType
Definition: petrov_galerkin_rom_builder_and_solver.h:106
void BuildROM(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, PetrovGalerkinSystemMatrixType &rA, PetrovGalerkinSystemVectorType &rb) override
Definition: petrov_galerkin_rom_builder_and_solver.h:383
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: petrov_galerkin_rom_builder_and_solver.h:105
LocalSystemMatrixType RomSystemMatrixType
Definition: petrov_galerkin_rom_builder_and_solver.h:115
virtual void PrintData(std::ostream &rOStream) const override
Print object's data.GetNumberOfROMModes()
Definition: petrov_galerkin_rom_builder_and_solver.h:265
std::size_t IndexType
Definition: petrov_galerkin_rom_builder_and_solver.h:91
ROMBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition of the classes from the base class.
Definition: petrov_galerkin_rom_builder_and_solver.h:97
PetrovGalerkinROMBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Definition: petrov_galerkin_rom_builder_and_solver.h:133
BaseType::TSchemeType TSchemeType
Definition: petrov_galerkin_rom_builder_and_solver.h:98
PetrovGalerkinROMBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
The definition of the current class.
Definition: petrov_galerkin_rom_builder_and_solver.h:94
BaseType::TSystemMatrixType TSystemMatrixType
Definition: petrov_galerkin_rom_builder_and_solver.h:100
Element::EquationIdVectorType EquationIdVectorType
Definition: petrov_galerkin_rom_builder_and_solver.h:111
RomSystemVectorType PetrovGalerkinSystemVectorType
Definition: petrov_galerkin_rom_builder_and_solver.h:120
moodycamel::ConcurrentQueue< DofType::Pointer > DofQueue
Definition: petrov_galerkin_rom_builder_and_solver.h:127
RomSystemMatrixType PetrovGalerkinSystemMatrixType
Definition: petrov_galerkin_rom_builder_and_solver.h:119
BaseType::DofsArrayType DofsArrayType
Definition: petrov_galerkin_rom_builder_and_solver.h:99
Node NodeType
DoF types definition.
Definition: petrov_galerkin_rom_builder_and_solver.h:124
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: petrov_galerkin_rom_builder_and_solver.h:104
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: petrov_galerkin_rom_builder_and_solver.h:155
virtual void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: petrov_galerkin_rom_builder_and_solver.h:259
KRATOS_CLASS_POINTER_DEFINITION(PetrovGalerkinROMBuilderAndSolver)
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: petrov_galerkin_rom_builder_and_solver.h:103
LocalSystemVectorType RomSystemVectorType
Definition: petrov_galerkin_rom_builder_and_solver.h:116
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: petrov_galerkin_rom_builder_and_solver.h:219
static void ResizeIfNeeded(TMatrix &mat, const SizeType rows, const SizeType cols)
Definition: petrov_galerkin_rom_builder_and_solver.h:373
Element::DofsVectorType DofsVectorType
Definition: petrov_galerkin_rom_builder_and_solver.h:112
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: petrov_galerkin_rom_builder_and_solver.h:102
~PetrovGalerkinROMBuilderAndSolver()=default
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: petrov_galerkin_rom_builder_and_solver.h:202
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: petrov_galerkin_rom_builder_and_solver.h:297
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
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
Definition: rom_builder_and_solver.h:62
BaseType::TSystemMatrixType TSystemMatrixType
Definition: rom_builder_and_solver.h:91
void InitializeHROMWeights(ModelPart &rModelPart)
Definition: rom_builder_and_solver.h:487
void ProjectToFineBasis(const TSystemVectorType &rRomUnkowns, const ModelPart &rModelPart, TSystemVectorType &rDx) const
Definition: rom_builder_and_solver.h:254
ElementsArrayType mSelectedElements
Definition: rom_builder_and_solver.h:408
BaseType::TSystemVectorType TSystemVectorType
Definition: rom_builder_and_solver.h:92
ConditionsArrayType mSelectedConditions
Definition: rom_builder_and_solver.h:409
static DofsArrayType SortAndRemoveDuplicateDofs(DofQueue &rDofQueue)
Definition: rom_builder_and_solver.h:589
SizeType GetNumberOfROMModes() const noexcept
Definition: rom_builder_and_solver.h:249
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: rom_builder_and_solver.h:338
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: rom_builder_and_solver.h:93
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: rom_builder_and_solver.h:466
bool mHromSimulation
Definition: rom_builder_and_solver.h:411
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: rom_builder_and_solver.h:95
BaseType::ConditionsArrayType ConditionsArrayType
Definition: rom_builder_and_solver.h:98
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: rom_builder_and_solver.h:96
bool mHromWeightsInitialized
Definition: rom_builder_and_solver.h:412
BaseType::ElementsArrayType ElementsArrayType
Definition: rom_builder_and_solver.h:97
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: rom_builder_and_solver.h:94
static DofQueue ExtractDofSet(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart)
Definition: rom_builder_and_solver.h:540
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static void GetPsiElemental(Matrix &rPsiElemental, const Element::DofsVectorType &rDofs, const Element::GeometryType &rGeom, const std::unordered_map< Kratos::VariableData::KeyType, Matrix::size_type > &rVarToRowMapping)
Obtain the left elemental basis (Psi) matrix for a particular element.
Definition: rom_auxiliary_utilities.cpp:750
static void GetPhiElemental(Matrix &rPhiElemental, const Element::DofsVectorType &rDofs, const Element::GeometryType &rGeom, const std::unordered_map< Kratos::VariableData::KeyType, Matrix::size_type > &rVarToRowMapping)
Obtain the elemental basis matrix for a particular element.
Definition: rom_auxiliary_utilities.cpp:718
#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
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
mat
Definition: script_ELASTIC.py:155
A
Definition: sensitivityMatrix.py:70
Definition: reduction_utilities.h:310
Definition: petrov_galerkin_rom_builder_and_solver.h:309
PetrovGalerkinSystemVectorType romB
Definition: petrov_galerkin_rom_builder_and_solver.h:323
EquationIdVectorType eq_id
Definition: petrov_galerkin_rom_builder_and_solver.h:320
DofsVectorType dofs
Definition: petrov_galerkin_rom_builder_and_solver.h:321
PetrovGalerkinSystemMatrixType romA
Definition: petrov_galerkin_rom_builder_and_solver.h:322
Matrix psiE
Definition: petrov_galerkin_rom_builder_and_solver.h:317
LocalSystemVectorType rhs
Definition: petrov_galerkin_rom_builder_and_solver.h:319
LocalSystemMatrixType lhs
Definition: petrov_galerkin_rom_builder_and_solver.h:318
AssemblyTLS(SizeType NRomModes, SizeType NPetrovGalerkinRomModes)
Definition: petrov_galerkin_rom_builder_and_solver.h:310
RomSystemMatrixType aux
Definition: petrov_galerkin_rom_builder_and_solver.h:324
Matrix phiE
Definition: petrov_galerkin_rom_builder_and_solver.h:316
Definition: petrov_galerkin_rom_builder_and_solver.h:332
void ThreadSafeReduce(const NonTrivialSumReduction &rOther)
Definition: petrov_galerkin_rom_builder_and_solver.h:360
bool mInitialized
Definition: petrov_galerkin_rom_builder_and_solver.h:337
void LocalReduce(const value_type &value)
Definition: petrov_galerkin_rom_builder_and_solver.h:351
T value_type
Definition: petrov_galerkin_rom_builder_and_solver.h:333
void Init(const value_type &first_value)
Definition: petrov_galerkin_rom_builder_and_solver.h:339
T mValue
Definition: petrov_galerkin_rom_builder_and_solver.h:336
return_type GetValue() const
access to reduced value
Definition: petrov_galerkin_rom_builder_and_solver.h:346
T return_type
Definition: petrov_galerkin_rom_builder_and_solver.h:334