13 #if !defined( ROM_RESIDUALS_UTILITY_H_INCLUDED )
14 #define ROM_RESIDUALS_UTILITY_H_INCLUDED
28 typedef UblasSpace<double, CompressedMatrix, boost::numeric::ublas::vector<double>>
SparseSpaceType;
42 BaseSchemeType::Pointer pScheme
47 "nodal_unknowns" : [],
48 "number_of_rom_dofs" : 10,
49 "petrov_galerkin_number_of_rom_dofs" : 10
78 template<
typename TMatrix>
79 static void ResizeIfNeeded(TMatrix& rMat,
const std::size_t Rows,
const std::size_t Cols)
82 if(rMat.size1() != Rows || rMat.size2() != Cols) {
83 rMat.resize(Rows, Cols,
false);
109 #pragma omp parallel firstprivate(n_elements, n_conditions, lhs_contribution, rhs_contribution, equation_id, phi_elemental, el_begin, cond_begin, elem_dofs, cond_dofs)
111 #pragma omp for nowait
112 for (
int k = 0;
k < n_elements;
k++){
113 const auto it_el = el_begin +
k;
115 bool element_is_active =
true;
116 if ((it_el)->IsDefined(ACTIVE))
117 element_is_active = (it_el)->Is(ACTIVE);
118 if (element_is_active){
120 mpScheme->CalculateSystemContributions(*it_el, lhs_contribution, rhs_contribution, equation_id, r_current_process_info);
121 it_el->GetDofList(elem_dofs, r_current_process_info);
124 const auto& r_geom = it_el->GetGeometry();
125 if(phi_elemental.size1() != elem_dofs.size() || phi_elemental.size2() !=
mRomDofs)
133 #pragma omp for nowait
134 for (
int k = 0;
k < n_conditions;
k++){
135 ModelPart::ConditionsContainerType::iterator it = cond_begin +
k;
137 bool condition_is_active =
true;
138 if ((it)->IsDefined(ACTIVE))
139 condition_is_active = (it)->Is(ACTIVE);
140 if (condition_is_active){
141 it->GetDofList(cond_dofs, r_current_process_info);
143 mpScheme->CalculateSystemContributions(*it, lhs_contribution, rhs_contribution, equation_id, r_current_process_info);
146 const auto& r_geom = it->GetGeometry();
147 if(phi_elemental.size1() != cond_dofs.size() || phi_elemental.size2() !=
mRomDofs)
154 return matrix_residuals;
179 #pragma omp parallel firstprivate(n_elements, n_conditions, lhs_contribution, rhs_contribution, equation_id, psi_elemental, el_begin, cond_begin, elem_dofs, cond_dofs)
181 #pragma omp for nowait
182 for (
int k = 0;
k < n_elements;
k++){
183 const auto it_el = el_begin +
k;
185 const bool element_is_active = it_el->IsDefined(ACTIVE) ? it_el->Is(ACTIVE) :
true;
186 if (element_is_active){
188 mpScheme->CalculateSystemContributions(*it_el, lhs_contribution, rhs_contribution, equation_id, r_current_process_info);
189 it_el->GetDofList(elem_dofs, r_current_process_info);
192 const auto& r_geom = it_el->GetGeometry();
201 #pragma omp for nowait
202 for (
int k = 0;
k < n_conditions;
k++){
203 const auto it = cond_begin +
k;
205 const bool condition_is_active = it->IsDefined(ACTIVE) ? it->Is(ACTIVE) :
true;
206 if (condition_is_active){
207 it->GetDofList(cond_dofs, r_current_process_info);
209 mpScheme->CalculateSystemContributions(*it, lhs_contribution, rhs_contribution, equation_id, r_current_process_info);
212 const auto& r_geom = it->GetGeometry();
220 return matrix_residuals;
246 #pragma omp parallel firstprivate(n_elements, n_conditions, rhs_contribution, equation_id, phi_j_elemental, el_begin, cond_begin, elem_dofs, cond_dofs)
249 for (
int k = 0;
k < n_elements;
k++){
250 auto r_element = el_begin +
k;
251 if (r_element->IsDefined(ACTIVE) && r_element->IsNot(ACTIVE))
continue;
253 mpScheme->CalculateRHSContribution(*r_element, rhs_contribution, equation_id, r_current_process_info);
254 r_element->GetDofList(elem_dofs, r_current_process_info);
256 const std::size_t ndofs = elem_dofs.size();
267 for (
int k = 0;
k < n_conditions;
k++){
268 auto r_condition = cond_begin +
k;
269 if (r_condition->IsDefined(ACTIVE) && r_condition->IsNot(ACTIVE))
continue;
271 mpScheme->CalculateRHSContribution(*r_condition, rhs_contribution, equation_id, r_current_process_info);
272 r_condition->GetDofList(cond_dofs, r_current_process_info);
274 const std::size_t ndofs = cond_dofs.size();
280 noalias(
row(matrix_residuals, n_elements +
k)) =
prod(
trans(phi_j_elemental), rhs_contribution);
284 return matrix_residuals;
294 std::unordered_map<Kratos::VariableData::KeyType, Matrix::size_type>
mMapPhi;
std::vector< DofType::Pointer > DofsVectorType
Definition: condition.h:100
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
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
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
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
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
Definition: rom_residuals_utility.h:34
static void ResizeIfNeeded(TMatrix &rMat, const std::size_t Rows, const std::size_t Cols)
Definition: rom_residuals_utility.h:79
Matrix GetProjectedResidualsOntoJPhi(Matrix &rJPhi)
Definition: rom_residuals_utility.h:223
ModelPart & mrModelPart
Definition: rom_residuals_utility.h:292
unsigned int mPetrovGalerkinRomDofs
Definition: rom_residuals_utility.h:291
Matrix GetProjectedResidualsOntoPsi()
Definition: rom_residuals_utility.h:157
int mNodalDofs
Definition: rom_residuals_utility.h:289
Matrix GetProjectedResidualsOntoPhi()
Definition: rom_residuals_utility.h:87
RomResidualsUtility(ModelPart &rModelPart, Parameters ThisParameters, BaseSchemeType::Pointer pScheme)
Definition: rom_residuals_utility.h:39
KRATOS_CLASS_POINTER_DEFINITION(RomResidualsUtility)
~RomResidualsUtility()=default
std::unordered_map< Kratos::VariableData::KeyType, Matrix::size_type > mMapPhi
Definition: rom_residuals_utility.h:294
BaseSchemeType::Pointer mpScheme
Definition: rom_residuals_utility.h:293
unsigned int mRomDofs
Definition: rom_residuals_utility.h:290
std::vector< std::string > mNodalVariablesNames
Definition: rom_residuals_utility.h:288
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
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
static void GetJPhiElemental(Matrix &rJPhiElemental, const Element::DofsVectorType &rDofs, const Matrix &rJPhi)
Obtain the JPhi elemental matrix for a particular element. JPhi represents the projection of the Jaco...
Definition: rom_auxiliary_utilities.cpp:782
#define KRATOS_ERROR
Definition: exception.h:161
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
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
Scheme< SparseSpaceType, LocalSpaceType > BaseSchemeType
Definition: rom_residuals_utility.h:30
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
TUblasSparseSpace< double > SparseSpaceType
Definition: linear_solver_factory.h:154
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
TUblasDenseSpace< double > LocalSpaceType
Definition: register_factories.h:33
int k
Definition: quadrature.py:595