13 #if !defined(KRATOS_SIMPLE_STEADY_ADJOINT_SCHEME_H_INCLUDED)
14 #define KRATOS_SIMPLE_STEADY_ADJOINT_SCHEME_H_INCLUDED
47 template <
class TSparseSpace,
class TDenseSpace>
48 class SimpleSteadyAdjointScheme :
public ResidualBasedAdjointStaticScheme<TSparseSpace, TDenseSpace>
56 using BaseType = ResidualBasedAdjointStaticScheme<TSparseSpace, TDenseSpace>;
58 using LocalSystemVectorType =
typename BaseType::LocalSystemVectorType;
60 using LocalSystemMatrixType =
typename BaseType::LocalSystemMatrixType;
67 explicit SimpleSteadyAdjointScheme(
68 AdjointResponseFunction::Pointer pResponseFunction,
71 : BaseType(pResponseFunction),
72 mAdjointSlipUtilities(Dimension, BlockSize)
76 mAuxMatrices.resize(number_of_threads);
78 KRATOS_INFO(this->
Info()) << this->
Info() <<
" created [ Dimensionality = " << Dimension <<
", BlockSize = " << BlockSize <<
" ].\n";
82 ~SimpleSteadyAdjointScheme()
override =
default;
88 void CalculateSystemContributions(
89 Element& rCurrentElement,
90 LocalSystemMatrixType& rLHS_Contribution,
91 LocalSystemVectorType& rRHS_Contribution,
93 const ProcessInfo& rCurrentProcessInfo)
override
95 CalculateEntitySystemContributions(rCurrentElement, rLHS_Contribution, rRHS_Contribution,
96 rEquationId, rCurrentProcessInfo);
99 void CalculateLHSContribution(
100 Element& rCurrentElement,
101 LocalSystemMatrixType& rLHS_Contribution,
103 const ProcessInfo& rCurrentProcessInfo)
override
106 Matrix& aux_matrix = mAuxMatrices[thread_id];
107 CalculateEntityLHSContribution(rCurrentElement, aux_matrix, rLHS_Contribution,
108 rEquationId, rCurrentProcessInfo);
111 void CalculateSystemContributions(
112 Condition& rCurrentCondition,
113 LocalSystemMatrixType& rLHS_Contribution,
114 LocalSystemVectorType& rRHS_Contribution,
116 const ProcessInfo& rCurrentProcessInfo)
override
118 CalculateEntitySystemContributions(rCurrentCondition, rLHS_Contribution, rRHS_Contribution,
119 rEquationId, rCurrentProcessInfo);
122 void CalculateLHSContribution(
123 Condition& rCurrentCondition,
124 LocalSystemMatrixType& rLHS_Contribution,
126 const ProcessInfo& rCurrentProcessInfo)
override
129 Matrix& aux_matrix = mAuxMatrices[thread_id];
130 CalculateEntityLHSContribution(rCurrentCondition, aux_matrix, rLHS_Contribution,
131 rEquationId, rCurrentProcessInfo);
140 std::string
Info()
const override
142 return "SimpleSteadyAdjointScheme";
151 std::vector<Matrix> mAuxMatrices;
153 const FluidAdjointSlipUtilities mAdjointSlipUtilities;
159 template<
class TEntityType>
160 void CalculateEntitySystemContributions(
161 TEntityType& rEntity,
162 LocalSystemMatrixType& rLHS_Contribution,
163 LocalSystemVectorType& rRHS_Contribution,
164 typename TEntityType::EquationIdVectorType& rEquationId,
165 const ProcessInfo& rCurrentProcessInfo)
170 Matrix& residual_derivatives = mAuxMatrices[thread_id];
172 CalculateEntityLHSContribution<TEntityType>(
173 rEntity, residual_derivatives, rLHS_Contribution, rEquationId, rCurrentProcessInfo);
175 if (rRHS_Contribution.size() != rLHS_Contribution.size1())
176 rRHS_Contribution.resize(rLHS_Contribution.size1(),
false);
178 this->mpResponseFunction->CalculateFirstDerivativesGradient(
179 rEntity, residual_derivatives, rRHS_Contribution, rCurrentProcessInfo);
181 noalias(rRHS_Contribution) = -rRHS_Contribution;
184 if (rLHS_Contribution.size1() != 0) {
185 auto& adjoint_values = this->mAdjointValues[thread_id];
186 rEntity.GetValuesVector(adjoint_values);
187 noalias(rRHS_Contribution) -=
prod(rLHS_Contribution, adjoint_values);
193 template<
class TEntityType>
194 void CalculateEntityLHSContribution(
195 TEntityType& rEntity,
196 Matrix& rEntityResidualFirstDerivatives,
197 Matrix& rEntityRotatedResidualFirstDerivatives,
199 const ProcessInfo& rCurrentProcessInfo)
203 rEntity.CalculateFirstDerivativesLHS(rEntityResidualFirstDerivatives, rCurrentProcessInfo);
204 rEntity.EquationIdVector(rEquationId, rCurrentProcessInfo);
206 mAdjointSlipUtilities.CalculateRotatedSlipConditionAppliedSlipVariableDerivatives(
207 rEntityRotatedResidualFirstDerivatives, rEntityResidualFirstDerivatives, rEntity.GetGeometry());
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
std::vector< std::size_t > EquationIdVectorType
Definition: condition.h:98
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_INFO(label)
Definition: logger.h:250
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
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
#define KRATOS_CLASS_POINTER_DEFINITION(a)
Definition: smart_pointers.h:69