13 #if !defined(KRATOS_VELOCITY_BOSSAK_ADJOINT_SCHEME_H_INCLUDED)
14 #define KRATOS_VELOCITY_BOSSAK_ADJOINT_SCHEME_H_INCLUDED
19 #include <unordered_set>
44 template <
class TSparseSpace,
class TDenseSpace>
70 AdjointResponseFunction::Pointer pResponseFunction,
73 :
BaseType(Settings, pResponseFunction),
74 mAdjointSlipUtilities(Dimension, BlockSize)
76 KRATOS_INFO(this->
Info()) << this->
Info() <<
" created [ Dimensionality = " << Dimension <<
", BlockSize = " << BlockSize <<
" ].\n";
105 std::string
Info()
const override
107 return "VelocityBossakAdjointScheme";
122 CalculateEntityGradientContributions(
123 rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
132 CalculateEntityGradientContributions(
133 rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
142 CalculateEntityFirstDerivativeContributions(
143 rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
152 CalculateEntityFirstDerivativeContributions(
153 rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
162 CalculateEntitySecondDerivativeContributions(
163 rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
172 CalculateEntitySecondDerivativeContributions(
173 rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
184 CalculateEntityTimeSchemeContributions(rElement, rAdjointTimeSchemeValues2,
185 rAdjointTimeSchemeValues3,
186 rCurrentProcessInfo);
197 CalculateEntityTimeSchemeContributions(rCondition, rAdjointTimeSchemeValues2,
198 rAdjointTimeSchemeValues3,
199 rCurrentProcessInfo);
209 CalculateEntityAuxiliaryVariableContributions(
210 rElement, rAdjointAuxiliaryValues, rCurrentProcessInfo);
220 CalculateEntityAuxiliaryVariableContributions(
221 rCondition, rAdjointAuxiliaryValues, rCurrentProcessInfo);
230 if (mAuxiliaryMatrix[
k].size1() != SystemSize ||
231 mAuxiliaryMatrix[
k].size2() != SystemSize) {
232 mAuxiliaryMatrix[
k].resize(SystemSize, SystemSize,
false);
235 if (mRotatedMatrix[
k].size1() != SystemSize || mRotatedMatrix[
k].size2() != SystemSize) {
236 mRotatedMatrix[
k].resize(SystemSize, SystemSize,
false);
246 std::vector<Matrix> mAuxiliaryMatrix;
247 std::vector<Matrix> mRotatedMatrix;
255 template<
class TEntityType>
256 void CalculateEntityGradientContributions(
257 TEntityType& rCurrentEntity,
264 auto& aux_matrix = this->mAuxiliaryMatrix[
k];
266 rCurrentEntity.CalculateLeftHandSide(aux_matrix, rCurrentProcessInfo);
268 rCurrentEntity, aux_matrix, rRHS_Contribution, rCurrentProcessInfo);
271 rLHS_Contribution, aux_matrix, rCurrentEntity.GetGeometry());
273 noalias(rRHS_Contribution) = -rRHS_Contribution;
276 template<
class TEntityType>
277 void CalculateEntityFirstDerivativeContributions(
278 TEntityType& rCurrentEntity,
281 const ProcessInfo& rCurrentProcessInfo)
284 auto& aux_matrix = this->mAuxiliaryMatrix[
k];
285 auto& rotated_matrix = this->mRotatedMatrix[
k];
288 rCurrentEntity.CalculateFirstDerivativesLHS(aux_matrix, rCurrentProcessInfo);
290 rCurrentEntity, aux_matrix, response_first_derivatives, rCurrentProcessInfo);
293 rotated_matrix, aux_matrix, rCurrentEntity.GetGeometry());
296 noalias(rRHS_Contribution) -= this->
mBossak.
C6 * response_first_derivatives;
299 template<
class TEntityType>
300 void CalculateEntitySecondDerivativeContributions(
301 TEntityType& rCurrentEntity,
304 const ProcessInfo& rCurrentProcessInfo)
307 auto& aux_matrix = this->mAuxiliaryMatrix[
k];
308 auto& rotated_matrix = this->mRotatedMatrix[
k];
311 rCurrentEntity.CalculateSecondDerivativesLHS(aux_matrix, rCurrentProcessInfo);
314 rCurrentEntity, aux_matrix, response_second_derivatives, rCurrentProcessInfo);
317 rotated_matrix, aux_matrix, rCurrentEntity.GetGeometry());
320 noalias(rRHS_Contribution) -= this->
mBossak.
C7 * response_second_derivatives;
323 template<
class TEntityType>
324 void CalculateEntityTimeSchemeContributions(
325 TEntityType& rCurrentEntity,
328 const ProcessInfo& rProcessInfo)
334 auto& aux_matrix = this->mAuxiliaryMatrix[
k];
340 const auto& r_const_entity_ref = rCurrentEntity;
341 r_const_entity_ref.GetValuesVector(adjoint_values);
345 rCurrentEntity.CalculateFirstDerivativesLHS(aux_matrix, rProcessInfo);
347 rCurrentEntity, aux_matrix, response_first_derivatives, rProcessInfo);
350 entity_first_derivatives, aux_matrix, rCurrentEntity.GetGeometry());
352 rCurrentEntity.CalculateSecondDerivativesLHS(aux_matrix, rProcessInfo);
355 rCurrentEntity, aux_matrix, response_second_derivatives, rProcessInfo);
358 entity_second_derivatives, aux_matrix, rCurrentEntity.GetGeometry());
360 if (rAdjointTimeSchemeValues2.size() != response_first_derivatives.size()) {
361 rAdjointTimeSchemeValues2.resize(response_first_derivatives.size(),
false);
364 noalias(rAdjointTimeSchemeValues2) =
365 -response_first_derivatives -
prod(entity_first_derivatives, adjoint_values);
367 if (rAdjointTimeSchemeValues3.size() != response_second_derivatives.size()) {
368 rAdjointTimeSchemeValues3.resize(response_second_derivatives.size(),
false);
371 noalias(rAdjointTimeSchemeValues3) =
372 -response_second_derivatives -
prod(entity_second_derivatives, adjoint_values);
377 template <
class TEntityType>
378 void CalculateEntityAuxiliaryVariableContributions(
379 TEntityType& rCurrentEntity,
381 const ProcessInfo& rProcessInfo)
387 auto& aux_matrix = this->mAuxiliaryMatrix[
k];
391 const auto& r_const_entity_ref = rCurrentEntity;
392 r_const_entity_ref.GetValuesVector(adjoint_values);
395 rCurrentEntity.CalculateSecondDerivativesLHS(aux_matrix, rProcessInfo);
398 rCurrentEntity, aux_matrix, response_second_derivatives, rProcessInfo);
401 entity_second_derivatives, aux_matrix, rCurrentEntity.GetGeometry());
403 if (rAdjointAuxiliaryValues.size() != entity_second_derivatives.size1()) {
404 rAdjointAuxiliaryValues.resize(entity_second_derivatives.size1(),
false);
406 noalias(rAdjointAuxiliaryValues) =
407 prod(entity_second_derivatives, adjoint_values) + response_second_derivatives;
A base class for adjoint response functions.
Definition: adjoint_response_function.h:39
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
Definition: fluid_adjoint_slip_utilities.h:39
void CalculateRotatedSlipConditionAppliedNonSlipVariableDerivatives(Matrix &rOutput, const Matrix &rResidualDerivatives, const GeometryType &rGeometry) const
Calculates rotated slip applied state derivatives.
Definition: fluid_adjoint_slip_utilities.cpp:102
void CalculateRotatedSlipConditionAppliedSlipVariableDerivatives(Matrix &rOutput, const Matrix &rResidualDerivatives, const GeometryType &rGeometry) const
Calculates rotated slip applied state derivatives.
Definition: fluid_adjoint_slip_utilities.cpp:58
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
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
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
A scheme for dynamic adjoint equations, using Bossak time integration.
Definition: residual_based_adjoint_bossak_scheme.h:50
BossakConstants mBossak
Definition: residual_based_adjoint_bossak_scheme.h:396
virtual void CheckAndResizeThreadStorage(unsigned SystemSize)
Definition: residual_based_adjoint_bossak_scheme.h:595
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residual_based_adjoint_bossak_scheme.h:65
std::vector< LocalSystemMatrixType > mSecondDerivsLHS
Definition: residual_based_adjoint_bossak_scheme.h:402
std::vector< LocalSystemMatrixType > mFirstDerivsLHS
Definition: residual_based_adjoint_bossak_scheme.h:400
AdjointResponseFunction::Pointer mpResponseFunction
Definition: residual_based_adjoint_bossak_scheme.h:394
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residual_based_adjoint_bossak_scheme.h:63
BaseType::DofsArrayType DofsArrayType
Definition: residual_based_adjoint_bossak_scheme.h:67
std::vector< LocalSystemVectorType > mFirstDerivsResponseGradient
Definition: residual_based_adjoint_bossak_scheme.h:401
std::vector< LocalSystemVectorType > mSecondDerivsResponseGradient
Definition: residual_based_adjoint_bossak_scheme.h:403
void Initialize(ModelPart &rModelPart) override
This is the place to initialize the Scheme.
Definition: residual_based_adjoint_bossak_scheme.h:151
std::vector< LocalSystemVectorType > mAdjointValuesVector
Definition: residual_based_adjoint_bossak_scheme.h:404
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
Definition: velocity_bossak_adjoint_scheme.h:46
void CalculateFirstDerivativeContributions(Element &rElement, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:136
void CalculateAuxiliaryVariableContributions(Element &rElement, LocalSystemVectorType &rAdjointAuxiliaryValues, AdjointResponseFunction &rAdjointResponseFunction, const BossakConstants &rBossakConstants, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:202
void CalculateGradientContributions(Element &rElement, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:116
typename BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: velocity_bossak_adjoint_scheme.h:57
void CalculateTimeSchemeContributions(Condition &rCondition, LocalSystemVectorType &rAdjointTimeSchemeValues2, LocalSystemVectorType &rAdjointTimeSchemeValues3, AdjointResponseFunction &rAdjointResponseFunction, const BossakConstants &rBossakConstants, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:189
VelocityBossakAdjointScheme(Parameters Settings, AdjointResponseFunction::Pointer pResponseFunction, const IndexType Dimension, const IndexType BlockSize)
Constructor.
Definition: velocity_bossak_adjoint_scheme.h:68
void Initialize(ModelPart &rModelPart) override
This is the place to initialize the Scheme.
Definition: velocity_bossak_adjoint_scheme.h:86
void CalculateAuxiliaryVariableContributions(Condition &rCondition, LocalSystemVectorType &rAdjointAuxiliaryValues, AdjointResponseFunction &rAdjointResponseFunction, const BossakConstants &rBossakConstants, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:213
void CalculateFirstDerivativeContributions(Condition &rCondition, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:146
KRATOS_CLASS_POINTER_DEFINITION(VelocityBossakAdjointScheme)
std::string Info() const override
Turn back information as a string.
Definition: velocity_bossak_adjoint_scheme.h:105
void CalculateTimeSchemeContributions(Element &rElement, LocalSystemVectorType &rAdjointTimeSchemeValues2, LocalSystemVectorType &rAdjointTimeSchemeValues3, AdjointResponseFunction &rAdjointResponseFunction, const BossakConstants &rBossakConstants, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:176
typename BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: velocity_bossak_adjoint_scheme.h:55
void CalculateSecondDerivativeContributions(Element &rElement, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:156
void CalculateSecondDerivativeContributions(Condition &rCondition, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:166
typename BaseType::BossakConstants BossakConstants
Definition: velocity_bossak_adjoint_scheme.h:61
void CalculateGradientContributions(Condition &rCondition, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo) override
Definition: velocity_bossak_adjoint_scheme.h:126
~VelocityBossakAdjointScheme() override=default
Destructor.
void CheckAndResizeThreadStorage(unsigned SystemSize) override
Definition: velocity_bossak_adjoint_scheme.h:224
#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
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
int k
Definition: quadrature.py:595
def num_threads
Definition: script.py:75
double C6
Definition: residual_based_adjoint_bossak_scheme.h:390
double Alpha
Definition: residual_based_adjoint_bossak_scheme.h:381
double C7
Definition: residual_based_adjoint_bossak_scheme.h:391