13 #if !defined(KRATOS_RESIDUAL_BASED_ADJOINT_BOSSAK_SCHEME_H_INCLUDED)
14 #define KRATOS_RESIDUAL_BASED_ADJOINT_BOSSAK_SCHEME_H_INCLUDED
19 #include <unordered_set>
48 template <
class TSparseSpace,
class TDenseSpace>
76 AdjointResponseFunction::Pointer pResponseFunction
80 "name" : "adjoint_bossak",
81 "scheme_type" : "bossak",
105 std::vector<const VariableData*> lambda2_vars = GatherVariables(
107 std::vector<const VariableData*>& rVec) {
108 rExtensions.GetFirstDerivativesVariables(rVec);
110 std::vector<const VariableData*> lambda3_vars = GatherVariables(
112 std::vector<const VariableData*>& rVec) {
113 return rExtensions.GetSecondDerivativesVariables(rVec);
115 std::vector<const VariableData*> auxiliary_vars = GatherVariables(
117 std::vector<const VariableData*>& rVec) {
118 return rExtensions.GetAuxiliaryVariables(rVec);
122 <<
"First derivatives variable list and second derivatives "
123 "variables list size mismatch.\n";
125 <<
"First derivatives variable list and auxiliary variables list "
128 for (
unsigned int i_var = 0; i_var < lambda2_vars.size(); ++i_var) {
129 const auto& r_lambda2_variable_name = lambda2_vars[i_var]->Name();
130 const auto& r_lambda3_variable_name = lambda3_vars[i_var]->Name();
131 const auto& r_auxiliary_variable_name = auxiliary_vars[i_var]->Name();
134 CheckVariables<array_1d<double, 3>>(rModelPart, r_lambda2_variable_name,
135 r_lambda3_variable_name,
136 r_auxiliary_variable_name);
138 CheckVariables<double>(rModelPart, r_lambda2_variable_name,
139 r_lambda3_variable_name, r_auxiliary_variable_name);
142 << r_lambda2_variable_name <<
".";
190 this->CalculateNodeNeighbourCount(rModelPart);
204 this->UpdateAuxiliaryVariable(rModelPart);
220 this->mpDofUpdater->UpdateDofs(rDofSet, rDx);
222 this->UpdateTimeSchemeAdjoints(rModelPart);
237 const auto& r_const_elem_ref = rCurrentElement;
252 rRHS_Contribution, rCurrentProcessInfo);
255 rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
258 rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
260 this->CalculatePreviousTimeStepContributions(
261 rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
264 rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
280 rEquationId, rCurrentProcessInfo);
294 const auto& r_const_cond_ref = rCurrentCondition;
308 rRHS_Contribution, rCurrentProcessInfo);
311 rCurrentCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
314 rCurrentCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
322 rCurrentCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
338 rLHS_Contribution, RHS_Contribution,
339 rEquationId, rCurrentProcessInfo);
345 this->mpDofUpdater->Clear();
353 std::string
Info()
const override
355 return "ResidualBasedAdjointBossakScheme";
419 CalculateEntityGradientContributions(
420 rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
429 CalculateEntityGradientContributions(
430 rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
439 CalculateEntityFirstDerivativeContributions(
440 rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
449 CalculateEntityFirstDerivativeContributions(
450 rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
459 CalculateEntitySecondDerivativeContributions(
460 rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
469 CalculateEntitySecondDerivativeContributions(
470 rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
491 CalculateEntityResidualLocalContributions(
492 rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
513 CalculateEntityResidualLocalContributions(
514 rCurrentCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
533 CalculateEntityTimeSchemeContributions(rElement, rAdjointTimeSchemeValues2,
534 rAdjointTimeSchemeValues3,
535 rCurrentProcessInfo);
554 CalculateEntityTimeSchemeContributions(rCondition, rAdjointTimeSchemeValues2,
555 rAdjointTimeSchemeValues3,
556 rCurrentProcessInfo);
573 CalculateEntityAuxiliaryVariableContributions(
574 rElement, rAdjointAuxiliaryValues, rCurrentProcessInfo);
591 CalculateEntityAuxiliaryVariableContributions(
592 rCondition, rAdjointAuxiliaryValues, rCurrentProcessInfo);
640 typename TSparseSpace::DofUpdaterPointerType mpDofUpdater =
641 TSparseSpace::CreateDofUpdater();
660 template<
class TEntityType>
661 void CalculateEntityResidualLocalContributions(
662 TEntityType& rCurrentEntity,
669 const auto& r_const_entity_ref = rCurrentEntity;
670 r_const_entity_ref.GetValuesVector(r_residual_adjoint);
671 noalias(rRHS_Contribution) -=
prod(rLHS_Contribution, r_residual_adjoint);
688 template<
class TEntityType>
689 void CalculateEntityGradientContributions(
690 TEntityType& rCurrentEntity,
693 const ProcessInfo& rCurrentProcessInfo)
696 rCurrentEntity.CalculateLeftHandSide(
mLeftHandSide[
k], rCurrentProcessInfo);
697 this->mpResponseFunction->CalculateGradient(
717 template<
class TEntityType>
718 void CalculateEntityFirstDerivativeContributions(
719 TEntityType& rCurrentEntity,
722 const ProcessInfo& rCurrentProcessInfo)
725 rCurrentEntity.CalculateFirstDerivativesLHS(
mFirstDerivsLHS[
k], rCurrentProcessInfo);
748 template<
class TEntityType>
749 void CalculateEntitySecondDerivativeContributions(
750 TEntityType& rCurrentEntity,
753 const ProcessInfo& rCurrentProcessInfo)
756 rCurrentEntity.CalculateSecondDerivativesLHS(
mSecondDerivsLHS[
k], rCurrentProcessInfo);
758 this->mpResponseFunction->CalculateSecondDerivativesGradient(
784 void CalculatePreviousTimeStepContributions(
785 Element& rCurrentElement,
788 const ProcessInfo& rCurrentProcessInfo)
790 const auto& r_geometry = rCurrentElement.GetGeometry();
792 auto& r_extensions = *rCurrentElement.GetValue(ADJOINT_EXTENSIONS);
794 unsigned local_index = 0;
795 for (
unsigned i_node = 0; i_node < r_geometry.PointsNumber(); ++i_node)
797 auto& r_node = r_geometry[i_node];
801 const double weight = 1.0 / r_node.GetValue(NUMBER_OF_NEIGHBOUR_ELEMENTS);
805 rRHS_Contribution[local_index] +=
835 template<
class TEntityType>
836 void CalculateEntityTimeSchemeContributions(
837 TEntityType& rCurrentEntity,
840 const ProcessInfo& rProcessInfo)
845 const auto& r_const_entity_ref = rCurrentEntity;
850 rCurrentEntity.CalculateFirstDerivativesLHS(
mFirstDerivsLHS[
k], rProcessInfo);
851 this->mpResponseFunction->CalculateFirstDerivativesGradient(
856 this->mpResponseFunction->CalculateSecondDerivativesGradient(
861 noalias(rAdjointTimeSchemeValues2) =
866 noalias(rAdjointTimeSchemeValues3) =
885 template <
class TEntityType>
886 void CalculateEntityAuxiliaryVariableContributions(
887 TEntityType& rCurrentEntity,
889 const ProcessInfo& rProcessInfo)
894 const auto& r_const_entity_ref = rCurrentEntity;
900 this->mpResponseFunction->CalculateSecondDerivativesGradient(
905 noalias(rAdjointAuxiliaryValues) =
912 void CalculateNodeNeighbourCount(ModelPart& rModelPart)
915 VariableUtils().SetNonHistoricalVariableToZero(NUMBER_OF_NEIGHBOUR_ELEMENTS, rModelPart.Nodes());
918 auto& r_geometry = rElement.GetGeometry();
919 for (unsigned j = 0; j < r_geometry.PointsNumber(); ++j) {
920 double& r_num_neighbour =
921 r_geometry[j].GetValue(NUMBER_OF_NEIGHBOUR_ELEMENTS);
922 AtomicAdd(r_num_neighbour, 1.0);
926 rModelPart.GetCommunicator().AssembleNonHistoricalData(NUMBER_OF_NEIGHBOUR_ELEMENTS);
929 void UpdateTimeSchemeAdjoints(ModelPart& rModelPart)
932 std::vector<const VariableData*> lambda2_vars = GatherVariables(
933 rModelPart.Elements(), [](
const AdjointExtensions& rExtensions,
934 std::vector<const VariableData*>& rVec) {
935 rExtensions.GetFirstDerivativesVariables(rVec);
937 std::vector<const VariableData*> lambda3_vars = GatherVariables(
938 rModelPart.Elements(), [](
const AdjointExtensions& rExtensions,
939 std::vector<const VariableData*>& rVec) {
940 return rExtensions.GetSecondDerivativesVariables(rVec);
942 std::vector<const VariableData*> auxiliary_vars = GatherVariables(
943 rModelPart.Elements(), [](
const AdjointExtensions& rExtensions,
944 std::vector<const VariableData*>& rVec) {
945 return rExtensions.GetAuxiliaryVariables(rVec);
948 SetToZero_AdjointVars(lambda2_vars, rModelPart.Nodes());
949 SetToZero_AdjointVars(lambda3_vars, rModelPart.Nodes());
951 const auto& r_process_info = rModelPart.GetProcessInfo();
952 UpdateEntityTimeSchemeContributions(rModelPart.Elements(), r_process_info);
953 UpdateEntityTimeSchemeContributions(rModelPart.Conditions(), r_process_info);
956 Assemble_AdjointVars(lambda2_vars, rModelPart.GetCommunicator());
957 Assemble_AdjointVars(lambda3_vars, rModelPart.GetCommunicator());
959 for (
unsigned int i_var = 0; i_var < lambda2_vars.size(); ++i_var) {
960 const auto& r_lambda2_variable_name = lambda2_vars[i_var]->Name();
961 const auto& r_lambda3_variable_name = lambda3_vars[i_var]->Name();
962 const auto& r_auxiliary_variable_name = auxiliary_vars[i_var]->Name();
964 if (KratosComponents<Variable<array_1d<double, 3>>>::
Has(r_lambda2_variable_name)) {
965 UpdateTimeSchemeVariablesFromOldContributions<array_1d<double, 3>>(
966 rModelPart.Nodes(), r_lambda2_variable_name,
967 r_lambda3_variable_name, r_auxiliary_variable_name);
968 }
else if (KratosComponents<Variable<double>>::
Has(r_lambda2_variable_name)) {
969 UpdateTimeSchemeVariablesFromOldContributions<double>(
970 rModelPart.Nodes(), r_lambda2_variable_name,
971 r_lambda3_variable_name, r_auxiliary_variable_name);
974 << r_lambda2_variable_name <<
".";
988 template <
class TEntityContainerType>
989 void UpdateEntityTimeSchemeContributions(
990 TEntityContainerType& rEntityContainer,
991 const ProcessInfo& rProcessInfo)
995 Vector adjoint2_aux, adjoint3_aux;
996 auto aux_TLS = std::make_pair(adjoint2_aux, adjoint3_aux);
997 using tls_type = std::tuple<Vector, Vector>;
998 block_for_each(rEntityContainer, tls_type(), [&,
this](
typename TEntityContainerType::value_type& rEntity, tls_type& rAdjointTLS){
999 auto& r_adjoint2_aux = std::get<0>(rAdjointTLS);
1000 auto& r_adjoint3_aux = std::get<1>(rAdjointTLS);
1004 this->CalculateTimeSchemeContributions(
1005 rEntity, r_adjoint2_aux, r_adjoint3_aux, *this->mpResponseFunction,
1006 mBossak, rProcessInfo);
1008 auto& r_extensions = *rEntity.GetValue(ADJOINT_EXTENSIONS);
1011 unsigned local_index = 0;
1012 auto& r_geometry = rEntity.GetGeometry();
1013 for (
unsigned i_node = 0; i_node < r_geometry.PointsNumber(); ++i_node) {
1015 r_extensions.GetFirstDerivativesVector(i_node, mAdjointIndirectVector2[
k], 0);
1016 r_extensions.GetSecondDerivativesVector(i_node, mAdjointIndirectVector3[
k], 0);
1018 auto& r_node = r_geometry[i_node];
1020 for (
unsigned d = 0;
d < mAdjointIndirectVector2[
k].size(); ++
d) {
1021 mAdjointIndirectVector2[
k][
d] += r_adjoint2_aux[local_index];
1022 mAdjointIndirectVector3[
k][
d] += r_adjoint3_aux[local_index];
1041 template<
class TDataType>
1042 void UpdateTimeSchemeVariablesFromOldContributions(
1044 const std::string& rLambda2VariableName,
1045 const std::string& rLambda3VariableName,
1046 const std::string& rAuxiliaryVariableName)
1050 const auto& r_lambda2_variable = KratosComponents<Variable<TDataType>>::Get(rLambda2VariableName);
1051 const auto& r_lambda3_variable = KratosComponents<Variable<TDataType>>::Get(rLambda3VariableName);
1052 const auto& r_auxiliary_variable = KratosComponents<Variable<TDataType>>::Get(rAuxiliaryVariableName);
1055 const TDataType& r_old_lambda2_value = rNode.FastGetSolutionStepValue(r_lambda2_variable, 1);
1056 const TDataType& r_old_lambda3_value = rNode.FastGetSolutionStepValue(r_lambda3_variable, 1);
1058 TDataType& r_lambda2_value = rNode.FastGetSolutionStepValue(r_lambda2_variable);
1059 r_lambda2_value += r_old_lambda2_value * mBossak.
C0;
1060 r_lambda2_value += r_old_lambda3_value * mBossak.
C1;
1062 TDataType& r_lambda3_value = rNode.FastGetSolutionStepValue(r_lambda3_variable);
1063 r_lambda3_value += r_old_lambda2_value * mBossak.
C2;
1064 r_lambda3_value += r_old_lambda3_value * mBossak.
C3;
1065 r_lambda3_value += rNode.FastGetSolutionStepValue(r_auxiliary_variable, 1);
1076 void UpdateAuxiliaryVariable(ModelPart& rModelPart)
1079 std::vector<const VariableData*> aux_vars = GatherVariables(
1080 rModelPart.Elements(), [](
const AdjointExtensions& rExtensions,
1081 std::vector<const VariableData*>& rOut) {
1082 return rExtensions.GetAuxiliaryVariables(rOut);
1085 SetToZero_AdjointVars(aux_vars, rModelPart.Nodes());
1087 const auto& r_process_info = rModelPart.GetProcessInfo();
1089 UpdateEntityAuxiliaryVariableContributions(rModelPart.Elements(), r_process_info);
1091 UpdateEntityAuxiliaryVariableContributions(rModelPart.Conditions(), r_process_info);
1094 Assemble_AdjointVars(aux_vars, rModelPart.GetCommunicator());
1105 template <
class TEntityContainerType>
1106 void UpdateEntityAuxiliaryVariableContributions(
1107 TEntityContainerType& rEntityContainer,
1108 const ProcessInfo& rProcessInfo)
1112 Vector aux_adjoint_vector;
1113 block_for_each(rEntityContainer, aux_adjoint_vector, [&,
this](
typename TEntityContainerType::value_type& rEntity,
Vector& rAuxAdjointVectorTLS){
1116 this->CalculateAuxiliaryVariableContributions(
1117 rEntity, rAuxAdjointVectorTLS, *this->mpResponseFunction, mBossak, rProcessInfo);
1119 auto& r_extensions = *rEntity.GetValue(ADJOINT_EXTENSIONS);
1121 unsigned local_index = 0;
1122 auto& r_geometry = rEntity.GetGeometry();
1124 for (
unsigned i_node = 0; i_node < r_geometry.PointsNumber(); ++i_node) {
1125 auto& r_node = r_geometry[i_node];
1126 r_extensions.GetAuxiliaryVector(i_node, mAuxAdjointIndirectVector1[
k], 0);
1129 for (
unsigned d = 0;
d < mAuxAdjointIndirectVector1[
k].size(); ++
d) {
1130 mAuxAdjointIndirectVector1[
k][
d] -= rAuxAdjointVectorTLS[local_index];
1149 template<
class TDataType>
1151 const ModelPart& rModelPart,
1152 const std::string& rLambda2VariableName,
1153 const std::string& rLambda3VariableName,
1154 const std::string& rAuxiliaryVariableName)
const
1159 <<
"Adjoint variable " << rLambda2VariableName
1160 <<
" is not found in variable list with required type.\n";
1163 <<
"Adjoint variable " << rLambda3VariableName
1164 <<
" is not found in variable list with required type.\n";
1167 <<
"Adjoint variable " << rAuxiliaryVariableName
1168 <<
" is not found in variable list with required type.\n";
1170 const auto& r_lambda2_variable = KratosComponents<Variable<TDataType>>::Get(rLambda2VariableName);
1171 const auto& r_lambda3_variable = KratosComponents<Variable<TDataType>>::Get(rLambda3VariableName);
1172 const auto& r_auxiliary_variable = KratosComponents<Variable<TDataType>>::Get(rAuxiliaryVariableName);
1174 KRATOS_ERROR_IF(!rModelPart.HasNodalSolutionStepVariable(r_lambda2_variable))
1175 <<
"Lambda 2 Variable " << rLambda2VariableName
1176 <<
" not found in nodal solution step variables list of "
1177 << rModelPart.Name() <<
".\n";
1178 KRATOS_ERROR_IF(!rModelPart.HasNodalSolutionStepVariable(r_lambda3_variable))
1179 <<
"Lambda 3 Variable " << rLambda3VariableName
1180 <<
" not found in nodal solution step variables list of "
1181 << rModelPart.Name() <<
".\n";
1182 KRATOS_ERROR_IF(!rModelPart.HasNodalSolutionStepVariable(r_auxiliary_variable))
1183 <<
"Auxiliary Variable " << rAuxiliaryVariableName
1184 <<
" not found in nodal solution step variables list of "
1185 << rModelPart.Name() <<
".\n";
1190 static BossakConstants CalculateBossakConstants(
double Alpha,
double DeltaTime)
1194 bc.Beta = 0.25 * (1.0 - bc.Alpha) * (1.0 - bc.Alpha);
1195 bc.Gamma = 0.5 - bc.Alpha;
1196 bc.C0 = 1.0 - bc.Gamma / bc.Beta;
1197 bc.C1 = -1.0 / (bc.Beta * DeltaTime);
1198 bc.C2 = (1.0 - 0.5 * bc.Gamma / bc.Beta) * DeltaTime;
1199 bc.C3 = (1.0 - 0.5 / bc.Beta);
1200 bc.C4 = (bc.Beta - bc.Gamma * (bc.Gamma + 0.5)) / (DeltaTime * bc.Beta * bc.Beta);
1201 bc.C5 = -1.0 * (bc.Gamma + 0.5) / (DeltaTime * DeltaTime * bc.Beta * bc.Beta);
1202 bc.C6 = bc.Gamma / (bc.Beta * DeltaTime);
1203 bc.C7 = 1.0 / (DeltaTime * DeltaTime * bc.Beta);
1207 static double GetTimeStep(
const ProcessInfo& rCurrentProcessInfo)
1210 rCurrentProcessInfo.GetPreviousSolutionStepInfo(1);
1216 r_last_process_info.GetValue(TIME) - rCurrentProcessInfo.GetValue(TIME);
1218 <<
"Backwards in time solution is not decreasing time from last "
1226 std::size_t operator()(
const VariableData*
const&
p)
const
1234 bool operator()(
const VariableData*
const l,
const VariableData*
const r)
const
1241 static std::vector<const VariableData*> GatherVariables(
1243 std::function<
void(
const AdjointExtensions&, std::vector<const VariableData*>&)> GetLocalVars)
1247 std::vector<const VariableData*> local_vars;
1248 std::vector<std::unordered_set<const VariableData*, Hash, Pred>> thread_vars(
num_threads);
1249 block_for_each(rElements, local_vars, [&](
const Element& rElement, std::vector<const VariableData*>& rLocalVarsTLS){
1250 GetLocalVars(*(rElement.GetValue(ADJOINT_EXTENSIONS)), rLocalVarsTLS);
1252 thread_vars[
k].insert(rLocalVarsTLS.begin(), rLocalVarsTLS.end());
1254 std::unordered_set<const VariableData*, Hash, Pred> all_vars;
1257 all_vars.insert(thread_vars[
i].begin(), thread_vars[
i].end());
1259 return std::vector<const VariableData*>{all_vars.begin(), all_vars.end()};
1263 static void SetToZero_AdjointVars(
const std::vector<const VariableData*>& rVariables,
1267 for (
auto p_variable_data : rVariables)
1269 if (KratosComponents<Variable<array_1d<double, 3>>>::
Has(
1270 p_variable_data->Name()))
1272 const auto& r_variable =
1273 KratosComponents<Variable<array_1d<double, 3>>>::Get(
1274 p_variable_data->Name());
1275 VariableUtils().SetHistoricalVariableToZero(r_variable, rNodes);
1277 else if (KratosComponents<Variable<double>>::
Has(p_variable_data->Name()))
1279 const auto& r_variable =
1280 KratosComponents<Variable<double>>::Get(p_variable_data->Name());
1281 VariableUtils().SetHistoricalVariableToZero(r_variable, rNodes);
1285 KRATOS_ERROR <<
"Variable \"" << p_variable_data->Name()
1286 <<
"\" not found!\n";
1292 static void Assemble_AdjointVars(
const std::vector<const VariableData*>& rVariables,
1293 Communicator& rComm)
1296 for (
auto p_variable_data : rVariables)
1298 if (KratosComponents<Variable<array_1d<double, 3>>>::
Has(
1299 p_variable_data->Name()))
1301 const auto& r_variable =
1302 KratosComponents<Variable<array_1d<double, 3>>>::Get(
1303 p_variable_data->Name());
1304 rComm.AssembleCurrentData(r_variable);
1306 else if (KratosComponents<Variable<double>>::
Has(p_variable_data->Name()))
1308 const auto& r_variable =
1309 KratosComponents<Variable<double>>::Get(p_variable_data->Name());
1310 rComm.AssembleCurrentData(r_variable);
1314 KRATOS_ERROR <<
"Variable \"" << p_variable_data->Name()
1315 <<
"\" not found!\n";
Interface extensions for adjoint elements and conditions.
Definition: adjoint_extensions.h:37
A base class for adjoint response functions.
Definition: adjoint_response_function.h:39
Base class for all Conditions.
Definition: condition.h:59
std::vector< std::size_t > EquationIdVectorType
Definition: condition.h:98
virtual void EquationIdVector(EquationIdVectorType &rResult, const ProcessInfo &rCurrentProcessInfo) const
Definition: condition.h:260
virtual void GetValuesVector(Vector &values, int Step=0) const
Definition: condition.h:303
Base class for all Elements.
Definition: element.h:60
virtual void EquationIdVector(EquationIdVectorType &rResult, const ProcessInfo &rCurrentProcessInfo) const
Definition: element.h:258
virtual void GetValuesVector(Vector &values, int Step=0) const
Definition: element.h:300
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
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
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Element ElementType
Definition: model_part.h:120
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
Node NodeType
Definition: model_part.h:117
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
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
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
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
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
BaseType::TSystemVectorType SystemVectorType
Definition: residual_based_adjoint_bossak_scheme.h:61
std::vector< LocalSystemVectorType > mResponseGradient
Definition: residual_based_adjoint_bossak_scheme.h:399
virtual void CalculateFirstDerivativeContributions(Element &rElement, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo)
Definition: residual_based_adjoint_bossak_scheme.h:433
void CalculateLHSContribution(Element &rCurrentElement, LocalSystemMatrixType &rLHS_Contribution, Element::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo) override
This function is designed to calculate just the LHS contribution.
Definition: residual_based_adjoint_bossak_scheme.h:271
BossakConstants mBossak
Definition: residual_based_adjoint_bossak_scheme.h:396
void InitializeSolutionStep(ModelPart &rModelPart, SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb) override
Function called once at the beginning of each solution step.
Definition: residual_based_adjoint_bossak_scheme.h:177
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residual_based_adjoint_bossak_scheme.h:365
virtual void CalculateSecondDerivativeContributions(Condition &rCondition, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo)
Definition: residual_based_adjoint_bossak_scheme.h:463
void CalculateSystemContributions(Element &rCurrentElement, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, Element::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo) override
This function is designed to be called in the builder and solver to introduce the selected time integ...
Definition: residual_based_adjoint_bossak_scheme.h:227
void CalculateSystemContributions(Condition &rCurrentCondition, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, Condition::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo) override
Functions totally analogous to the precedent but applied to the "condition" objects.
Definition: residual_based_adjoint_bossak_scheme.h:284
std::string Info() const override
Turn back information as a string.
Definition: residual_based_adjoint_bossak_scheme.h:353
virtual void CalculateAuxiliaryVariableContributions(Condition &rCondition, LocalSystemVectorType &rAdjointAuxiliaryValues, AdjointResponseFunction &rAdjointResponseFunction, const BossakConstants &rBossakConstants, const ProcessInfo &rCurrentProcessInfo)
Calculates auxiliary contributions from conditions.
Definition: residual_based_adjoint_bossak_scheme.h:584
virtual void CheckAndResizeThreadStorage(unsigned SystemSize)
Definition: residual_based_adjoint_bossak_scheme.h:595
std::vector< std::vector< IndirectScalar< double > > > mAuxAdjointIndirectVector1
Definition: residual_based_adjoint_bossak_scheme.h:407
virtual void CalculateFirstDerivativeContributions(Condition &rCondition, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo)
Definition: residual_based_adjoint_bossak_scheme.h:443
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residual_based_adjoint_bossak_scheme.h:65
virtual void CalculateTimeSchemeContributions(Element &rElement, LocalSystemVectorType &rAdjointTimeSchemeValues2, LocalSystemVectorType &rAdjointTimeSchemeValues3, AdjointResponseFunction &rAdjointResponseFunction, const BossakConstants &rBossakConstants, const ProcessInfo &rCurrentProcessInfo)
Calculate time scheme contributions from elements.
Definition: residual_based_adjoint_bossak_scheme.h:525
virtual void CalculateGradientContributions(Element &rElement, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo)
Definition: residual_based_adjoint_bossak_scheme.h:413
~ResidualBasedAdjointBossakScheme() override
Destructor.
Definition: residual_based_adjoint_bossak_scheme.h:89
std::vector< LocalSystemMatrixType > mSecondDerivsLHS
Definition: residual_based_adjoint_bossak_scheme.h:402
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residual_based_adjoint_bossak_scheme.h:359
std::vector< LocalSystemMatrixType > mFirstDerivsLHS
Definition: residual_based_adjoint_bossak_scheme.h:400
Scheme< TSparseSpace, TDenseSpace > BaseType
Definition: residual_based_adjoint_bossak_scheme.h:57
virtual void CalculateTimeSchemeContributions(Condition &rCondition, LocalSystemVectorType &rAdjointTimeSchemeValues2, LocalSystemVectorType &rAdjointTimeSchemeValues3, AdjointResponseFunction &rAdjointResponseFunction, const BossakConstants &rBossakConstants, const ProcessInfo &rCurrentProcessInfo)
Calculates time scheme contributions from conditions.
Definition: residual_based_adjoint_bossak_scheme.h:546
virtual void CalculateSecondDerivativeContributions(Element &rElement, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo)
Definition: residual_based_adjoint_bossak_scheme.h:453
std::vector< std::vector< IndirectScalar< double > > > mAdjointIndirectVector3
Definition: residual_based_adjoint_bossak_scheme.h:406
std::vector< LocalSystemMatrixType > mLeftHandSide
Definition: residual_based_adjoint_bossak_scheme.h:398
AdjointResponseFunction::Pointer mpResponseFunction
Definition: residual_based_adjoint_bossak_scheme.h:394
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residual_based_adjoint_bossak_scheme.h:63
std::vector< std::vector< IndirectScalar< double > > > mAdjointIndirectVector2
Definition: residual_based_adjoint_bossak_scheme.h:405
BaseType::DofsArrayType DofsArrayType
Definition: residual_based_adjoint_bossak_scheme.h:67
virtual void CalculateResidualLocalContributions(Condition &rCurrentCondition, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo)
Calculates condition residual.
Definition: residual_based_adjoint_bossak_scheme.h:507
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedAdjointBossakScheme)
std::vector< LocalSystemVectorType > mFirstDerivsResponseGradient
Definition: residual_based_adjoint_bossak_scheme.h:401
BaseType::TSystemMatrixType SystemMatrixType
Definition: residual_based_adjoint_bossak_scheme.h:59
virtual void CalculateGradientContributions(Condition &rCondition, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo)
Definition: residual_based_adjoint_bossak_scheme.h:423
void Clear() override
Liberate internal storage.
Definition: residual_based_adjoint_bossak_scheme.h:343
void Update(ModelPart &rModelPart, DofsArrayType &rDofSet, SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb) override
Performing the update of the solution.
Definition: residual_based_adjoint_bossak_scheme.h:209
void FinalizeSolutionStep(ModelPart &rModelPart, SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb) override
Function called once at the end of a solution step, after convergence is reached if an iterative proc...
Definition: residual_based_adjoint_bossak_scheme.h:195
virtual void CalculateAuxiliaryVariableContributions(Element &rElement, LocalSystemVectorType &rAdjointAuxiliaryValues, AdjointResponseFunction &rAdjointResponseFunction, const BossakConstants &rBossakConstants, const ProcessInfo &rCurrentProcessInfo)
Calculates auxiliary variable contributions from elements.
Definition: residual_based_adjoint_bossak_scheme.h:566
ResidualBasedAdjointBossakScheme(Parameters Settings, AdjointResponseFunction::Pointer pResponseFunction)
Constructor.
Definition: residual_based_adjoint_bossak_scheme.h:74
std::vector< LocalSystemVectorType > mSecondDerivsResponseGradient
Definition: residual_based_adjoint_bossak_scheme.h:403
void CalculateLHSContribution(Condition &rCurrentCondition, LocalSystemMatrixType &rLHS_Contribution, Condition::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo) override
Functions totally analogous to the precedent but applied to the "condition" objects.
Definition: residual_based_adjoint_bossak_scheme.h:329
virtual void CalculateResidualLocalContributions(Element &rCurrentElement, LocalSystemMatrixType &rLHS_Contribution, LocalSystemVectorType &rRHS_Contribution, const ProcessInfo &rCurrentProcessInfo)
Calculates elemental residual.
Definition: residual_based_adjoint_bossak_scheme.h:485
void Initialize(ModelPart &rModelPart) override
This is the place to initialize the Scheme.
Definition: residual_based_adjoint_bossak_scheme.h:151
int Check(const ModelPart &rModelPart) const override
This function is designed to be called once to perform all the checks needed on the input provided....
Definition: residual_based_adjoint_bossak_scheme.h:101
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
typename TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: scheme.h:71
typename TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: scheme.h:74
typename TDenseSpace::VectorType LocalSystemVectorType
Local system vector type definition.
Definition: scheme.h:80
virtual void FinalizeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
Function called once at the end of a solution step, after convergence is reached if an iterative proc...
Definition: scheme.h:294
virtual void InitializeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
Function called once at the beginning of each solution step.
Definition: scheme.h:272
virtual void Initialize(ModelPart &rModelPart)
This is the place to initialize the Scheme.
Definition: scheme.h:168
typename TDenseSpace::MatrixType LocalSystemMatrixType
Local system matrix type definition.
Definition: scheme.h:77
virtual int Check(const ModelPart &rModelPart) const
This function is designed to be called once to perform all the checks needed on the input provided....
Definition: scheme.h:508
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void SetNonHistoricalVariableToZero(const Variable< TType > &rVariable, TContainerType &rContainer)
Sets the nodal value of any variable to zero.
Definition: variable_utils.h:724
#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(conditional)
Definition: exception.h:162
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
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
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
ProcessInfo
Definition: edgebased_PureConvection.py:116
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
int d
Definition: ode_solve.py:397
def CheckVariables(variable_origin, variable_destination)
Definition: python_mapper.py:54
def Alpha(n, j)
Definition: quadrature.py:93
int k
Definition: quadrature.py:595
def num_threads
Definition: script.py:75
p
Definition: sensitivityMatrix.py:52
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17
Definition: residual_based_adjoint_bossak_scheme.h:380
double C5
Definition: residual_based_adjoint_bossak_scheme.h:389
double C2
Definition: residual_based_adjoint_bossak_scheme.h:386
double C6
Definition: residual_based_adjoint_bossak_scheme.h:390
double Beta
Definition: residual_based_adjoint_bossak_scheme.h:382
double C0
Definition: residual_based_adjoint_bossak_scheme.h:384
double Alpha
Definition: residual_based_adjoint_bossak_scheme.h:381
double Gamma
Definition: residual_based_adjoint_bossak_scheme.h:383
double C3
Definition: residual_based_adjoint_bossak_scheme.h:387
double C4
Definition: residual_based_adjoint_bossak_scheme.h:388
double C1
Definition: residual_based_adjoint_bossak_scheme.h:385
double C7
Definition: residual_based_adjoint_bossak_scheme.h:391