KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
residual_based_adjoint_bossak_scheme.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors:
11 //
12 
13 #if !defined(KRATOS_RESIDUAL_BASED_ADJOINT_BOSSAK_SCHEME_H_INCLUDED)
14 #define KRATOS_RESIDUAL_BASED_ADJOINT_BOSSAK_SCHEME_H_INCLUDED
15 
16 // System includes
17 #include <vector>
18 #include <string>
19 #include <unordered_set>
20 #include <functional>
21 
22 // External includes
23 
24 // Project includes
25 #include "includes/define.h"
26 #include "includes/checks.h"
35 
36 namespace Kratos
37 {
40 
42 
48 template <class TSparseSpace, class TDenseSpace>
49 class ResidualBasedAdjointBossakScheme : public Scheme<TSparseSpace, TDenseSpace>
50 {
51 public:
54 
56 
58 
60 
62 
64 
66 
68 
72 
75  Parameters Settings,
76  AdjointResponseFunction::Pointer pResponseFunction
77  ) : mpResponseFunction(pResponseFunction)
78  {
79  Parameters default_parameters(R"({
80  "name" : "adjoint_bossak",
81  "scheme_type" : "bossak",
82  "alpha_bossak" : -0.3
83  })");
84  Settings.ValidateAndAssignDefaults(default_parameters);
85  mBossak.Alpha = Settings["alpha_bossak"].GetDouble();
86  }
87 
90  {
91  }
92 
96 
100 
101  int Check(const ModelPart& rModelPart) const override
102  {
103  KRATOS_TRY
104 
105  std::vector<const VariableData*> lambda2_vars = GatherVariables(
106  rModelPart.Elements(), [](const AdjointExtensions& rExtensions,
107  std::vector<const VariableData*>& rVec) {
108  rExtensions.GetFirstDerivativesVariables(rVec);
109  });
110  std::vector<const VariableData*> lambda3_vars = GatherVariables(
111  rModelPart.Elements(), [](const AdjointExtensions& rExtensions,
112  std::vector<const VariableData*>& rVec) {
113  return rExtensions.GetSecondDerivativesVariables(rVec);
114  });
115  std::vector<const VariableData*> auxiliary_vars = GatherVariables(
116  rModelPart.Elements(), [](const AdjointExtensions& rExtensions,
117  std::vector<const VariableData*>& rVec) {
118  return rExtensions.GetAuxiliaryVariables(rVec);
119  });
120 
121  KRATOS_ERROR_IF(lambda2_vars.size() != lambda3_vars.size())
122  << "First derivatives variable list and second derivatives "
123  "variables list size mismatch.\n";
124  KRATOS_ERROR_IF(lambda2_vars.size() != auxiliary_vars.size())
125  << "First derivatives variable list and auxiliary variables list "
126  "size mismatch.\n";
127 
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();
132 
133  if (KratosComponents<Variable<array_1d<double, 3>>>::Has(r_lambda2_variable_name)) {
134  CheckVariables<array_1d<double, 3>>(rModelPart, r_lambda2_variable_name,
135  r_lambda3_variable_name,
136  r_auxiliary_variable_name);
137  } else if (KratosComponents<Variable<double>>::Has(r_lambda2_variable_name)) {
138  CheckVariables<double>(rModelPart, r_lambda2_variable_name,
139  r_lambda3_variable_name, r_auxiliary_variable_name);
140  } else {
141  KRATOS_ERROR << "Unsupported variable type "
142  << r_lambda2_variable_name << ".";
143  }
144  }
145 
146  return BaseType::Check(rModelPart);
147 
148  KRATOS_CATCH("");
149  }
150 
151  void Initialize(ModelPart& rModelPart) override
152  {
153  KRATOS_TRY;
154 
155  BaseType::Initialize(rModelPart);
156 
157  // Allocate auxiliary memory.
159  mLeftHandSide.resize(num_threads);
169 
170  VariableUtils().SetNonHistoricalVariableToZero(NUMBER_OF_NEIGHBOUR_ELEMENTS, rModelPart.Nodes());
171 
172  rModelPart.GetProcessInfo()[BOSSAK_ALPHA] = mBossak.Alpha;
173 
174  KRATOS_CATCH("");
175  }
176 
178  ModelPart& rModelPart,
179  SystemMatrixType& rA,
180  SystemVectorType& rDx,
181  SystemVectorType& rb) override
182  {
183  KRATOS_TRY;
184 
185  BaseType::InitializeSolutionStep(rModelPart, rA, rDx, rb);
186 
187  const auto& r_current_process_info = rModelPart.GetProcessInfo();
188  mBossak = CalculateBossakConstants(mBossak.Alpha, GetTimeStep(r_current_process_info));
189 
190  this->CalculateNodeNeighbourCount(rModelPart);
191 
192  KRATOS_CATCH("");
193  }
194 
196  ModelPart& rModelPart,
197  SystemMatrixType& rA,
198  SystemVectorType& rDx,
199  SystemVectorType& rb) override
200  {
201  KRATOS_TRY;
202 
203  BaseType::FinalizeSolutionStep(rModelPart, rA, rDx, rb);
204  this->UpdateAuxiliaryVariable(rModelPart);
205 
206  KRATOS_CATCH("");
207  }
208 
209  void Update(
210  ModelPart& rModelPart,
211  DofsArrayType& rDofSet,
212  SystemMatrixType& rA,
213  SystemVectorType& rDx,
214  SystemVectorType& rb) override
215  {
216  KRATOS_TRY;
217 
218  // Update degrees of freedom: adjoint variables associated to the
219  // residual of the physical problem.
220  this->mpDofUpdater->UpdateDofs(rDofSet, rDx);
221  // Update adjoint variables associated to time integration.
222  this->UpdateTimeSchemeAdjoints(rModelPart);
223 
224  KRATOS_CATCH("");
225  }
226 
228  Element& rCurrentElement,
229  LocalSystemMatrixType& rLHS_Contribution,
230  LocalSystemVectorType& rRHS_Contribution,
231  Element::EquationIdVectorType& rEquationId,
232  const ProcessInfo& rCurrentProcessInfo) override
233  {
234  KRATOS_TRY;
235 
236  const auto k = OpenMPUtils::ThisThread();
237  const auto& r_const_elem_ref = rCurrentElement;
238 
239  r_const_elem_ref.GetValuesVector(mAdjointValuesVector[k]);
240  const auto local_size = mAdjointValuesVector[k].size();
241  if (rRHS_Contribution.size() != local_size)
242  {
243  rRHS_Contribution.resize(local_size, false);
244  }
245  if (rLHS_Contribution.size1() != local_size || rLHS_Contribution.size2() != local_size)
246  {
247  rLHS_Contribution.resize(local_size, local_size, false);
248  }
250 
251  this->CalculateGradientContributions(rCurrentElement, rLHS_Contribution,
252  rRHS_Contribution, rCurrentProcessInfo);
253 
255  rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
256 
258  rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
259 
260  this->CalculatePreviousTimeStepContributions(
261  rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
262 
264  rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
265 
266  rCurrentElement.EquationIdVector(rEquationId, rCurrentProcessInfo);
267 
268  KRATOS_CATCH("");
269  }
270 
272  Element& rCurrentElement,
273  LocalSystemMatrixType& rLHS_Contribution,
274  Element::EquationIdVectorType& rEquationId,
275  const ProcessInfo& rCurrentProcessInfo) override
276  {
277  KRATOS_TRY;
278  LocalSystemVectorType RHS_Contribution;
279  CalculateSystemContributions(rCurrentElement, rLHS_Contribution, RHS_Contribution,
280  rEquationId, rCurrentProcessInfo);
281  KRATOS_CATCH("");
282  }
283 
285  Condition& rCurrentCondition,
286  LocalSystemMatrixType& rLHS_Contribution,
287  LocalSystemVectorType& rRHS_Contribution,
288  Condition::EquationIdVectorType& rEquationId,
289  const ProcessInfo& rCurrentProcessInfo) override
290  {
291  KRATOS_TRY;
292 
293  const auto k = OpenMPUtils::ThisThread();
294  const auto& r_const_cond_ref = rCurrentCondition;
295  r_const_cond_ref.GetValuesVector(mAdjointValuesVector[k]);
296  const auto local_size = mAdjointValuesVector[k].size();
297  if (rRHS_Contribution.size() != local_size)
298  {
299  rRHS_Contribution.resize(local_size, false);
300  }
301  if (rLHS_Contribution.size1() != local_size || rLHS_Contribution.size2() != local_size)
302  {
303  rLHS_Contribution.resize(local_size, local_size, false);
304  }
306 
307  this->CalculateGradientContributions(rCurrentCondition, rLHS_Contribution,
308  rRHS_Contribution, rCurrentProcessInfo);
309 
311  rCurrentCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
312 
314  rCurrentCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
315 
316  // It is not required to call CalculatePreviousTimeStepContributions here again
317  // since, the previous time step contributions from conditions are stored in variables
318  // mentioned in AdjointExtensions, and they are added via CalculateSystemContributions<ElementType>
319  // method.
320 
322  rCurrentCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
323 
324  rCurrentCondition.EquationIdVector(rEquationId, rCurrentProcessInfo);
325 
326  KRATOS_CATCH("");
327  }
328 
330  Condition& rCurrentCondition,
331  LocalSystemMatrixType& rLHS_Contribution,
332  Condition::EquationIdVectorType& rEquationId,
333  const ProcessInfo& rCurrentProcessInfo) override
334  {
335  KRATOS_TRY;
336  LocalSystemVectorType RHS_Contribution;
337  CalculateSystemContributions(rCurrentCondition,
338  rLHS_Contribution, RHS_Contribution,
339  rEquationId, rCurrentProcessInfo);
340  KRATOS_CATCH("");
341  }
342 
343  void Clear() override
344  {
345  this->mpDofUpdater->Clear();
346  }
347 
351 
353  std::string Info() const override
354  {
355  return "ResidualBasedAdjointBossakScheme";
356  }
357 
359  void PrintInfo(std::ostream& rOStream) const override
360  {
361  rOStream << Info();
362  }
363 
365  void PrintData(std::ostream& rOStream) const override
366  {
367  rOStream << Info();
368  }
372 
374 
375 protected:
378 
380  {
381  double Alpha;
382  double Beta;
383  double Gamma;
384  double C0;
385  double C1;
386  double C2;
387  double C3;
388  double C4;
389  double C5;
390  double C6;
391  double C7;
392  };
393 
394  AdjointResponseFunction::Pointer mpResponseFunction;
395 
397 
398  std::vector<LocalSystemMatrixType> mLeftHandSide;
399  std::vector<LocalSystemVectorType> mResponseGradient;
400  std::vector<LocalSystemMatrixType> mFirstDerivsLHS;
401  std::vector<LocalSystemVectorType> mFirstDerivsResponseGradient;
402  std::vector<LocalSystemMatrixType> mSecondDerivsLHS;
403  std::vector<LocalSystemVectorType> mSecondDerivsResponseGradient;
404  std::vector<LocalSystemVectorType> mAdjointValuesVector;
405  std::vector<std::vector<IndirectScalar<double>>> mAdjointIndirectVector2;
406  std::vector<std::vector<IndirectScalar<double>>> mAdjointIndirectVector3;
407  std::vector<std::vector<IndirectScalar<double>>> mAuxAdjointIndirectVector1;
408 
412 
414  Element& rElement,
415  LocalSystemMatrixType& rLHS_Contribution,
416  LocalSystemVectorType& rRHS_Contribution,
417  const ProcessInfo& rCurrentProcessInfo)
418  {
419  CalculateEntityGradientContributions(
420  rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
421  }
422 
424  Condition& rCondition,
425  LocalSystemMatrixType& rLHS_Contribution,
426  LocalSystemVectorType& rRHS_Contribution,
427  const ProcessInfo& rCurrentProcessInfo)
428  {
429  CalculateEntityGradientContributions(
430  rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
431  }
432 
434  Element& rElement,
435  LocalSystemMatrixType& rLHS_Contribution,
436  LocalSystemVectorType& rRHS_Contribution,
437  const ProcessInfo& rCurrentProcessInfo)
438  {
439  CalculateEntityFirstDerivativeContributions(
440  rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
441  }
442 
444  Condition& rCondition,
445  LocalSystemMatrixType& rLHS_Contribution,
446  LocalSystemVectorType& rRHS_Contribution,
447  const ProcessInfo& rCurrentProcessInfo)
448  {
449  CalculateEntityFirstDerivativeContributions(
450  rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
451  }
452 
454  Element& rElement,
455  LocalSystemMatrixType& rLHS_Contribution,
456  LocalSystemVectorType& rRHS_Contribution,
457  const ProcessInfo& rCurrentProcessInfo)
458  {
459  CalculateEntitySecondDerivativeContributions(
460  rElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
461  }
462 
464  Condition& rCondition,
465  LocalSystemMatrixType& rLHS_Contribution,
466  LocalSystemVectorType& rRHS_Contribution,
467  const ProcessInfo& rCurrentProcessInfo)
468  {
469  CalculateEntitySecondDerivativeContributions(
470  rCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
471  }
472 
486  Element& rCurrentElement,
487  LocalSystemMatrixType& rLHS_Contribution,
488  LocalSystemVectorType& rRHS_Contribution,
489  const ProcessInfo& rCurrentProcessInfo)
490  {
491  CalculateEntityResidualLocalContributions(
492  rCurrentElement, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
493  }
494 
508  Condition& rCurrentCondition,
509  LocalSystemMatrixType& rLHS_Contribution,
510  LocalSystemVectorType& rRHS_Contribution,
511  const ProcessInfo& rCurrentProcessInfo)
512  {
513  CalculateEntityResidualLocalContributions(
514  rCurrentCondition, rLHS_Contribution, rRHS_Contribution, rCurrentProcessInfo);
515  }
516 
526  Element& rElement,
527  LocalSystemVectorType& rAdjointTimeSchemeValues2,
528  LocalSystemVectorType& rAdjointTimeSchemeValues3,
529  AdjointResponseFunction& rAdjointResponseFunction,
530  const BossakConstants& rBossakConstants,
531  const ProcessInfo& rCurrentProcessInfo)
532  {
533  CalculateEntityTimeSchemeContributions(rElement, rAdjointTimeSchemeValues2,
534  rAdjointTimeSchemeValues3,
535  rCurrentProcessInfo);
536  }
537 
547  Condition& rCondition,
548  LocalSystemVectorType& rAdjointTimeSchemeValues2,
549  LocalSystemVectorType& rAdjointTimeSchemeValues3,
550  AdjointResponseFunction& rAdjointResponseFunction,
551  const BossakConstants& rBossakConstants,
552  const ProcessInfo& rCurrentProcessInfo)
553  {
554  CalculateEntityTimeSchemeContributions(rCondition, rAdjointTimeSchemeValues2,
555  rAdjointTimeSchemeValues3,
556  rCurrentProcessInfo);
557  }
558 
567  Element& rElement,
568  LocalSystemVectorType& rAdjointAuxiliaryValues,
569  AdjointResponseFunction& rAdjointResponseFunction,
570  const BossakConstants& rBossakConstants,
571  const ProcessInfo& rCurrentProcessInfo)
572  {
573  CalculateEntityAuxiliaryVariableContributions(
574  rElement, rAdjointAuxiliaryValues, rCurrentProcessInfo);
575  }
576 
585  Condition& rCondition,
586  LocalSystemVectorType& rAdjointAuxiliaryValues,
587  AdjointResponseFunction& rAdjointResponseFunction,
588  const BossakConstants& rBossakConstants,
589  const ProcessInfo& rCurrentProcessInfo)
590  {
591  CalculateEntityAuxiliaryVariableContributions(
592  rCondition, rAdjointAuxiliaryValues, rCurrentProcessInfo);
593  }
594 
595  virtual void CheckAndResizeThreadStorage(unsigned SystemSize)
596  {
597  const int k = OpenMPUtils::ThisThread();
598 
599  if (mLeftHandSide[k].size1() != SystemSize || mLeftHandSide[k].size2() != SystemSize)
600  {
601  mLeftHandSide[k].resize(SystemSize, SystemSize, false);
602  }
603 
604  if (mFirstDerivsLHS[k].size1() != SystemSize || mFirstDerivsLHS[k].size2() != SystemSize)
605  {
606  mFirstDerivsLHS[k].resize(SystemSize, SystemSize, false);
607  }
608 
609  if (mSecondDerivsLHS[k].size1() != SystemSize || mSecondDerivsLHS[k].size2() != SystemSize)
610  {
611  mSecondDerivsLHS[k].resize(SystemSize, SystemSize, false);
612  }
613 
614  if (mResponseGradient[k].size() != SystemSize)
615  {
616  mResponseGradient[k].resize(SystemSize, false);
617  }
618 
619  if (mFirstDerivsResponseGradient[k].size() != SystemSize)
620  {
621  mFirstDerivsResponseGradient[k].resize(SystemSize, false);
622  }
623 
624  if (mSecondDerivsResponseGradient[k].size() != SystemSize)
625  {
626  mSecondDerivsResponseGradient[k].resize(SystemSize, false);
627  }
628  }
629 
631 
632 private:
635 
639 
640  typename TSparseSpace::DofUpdaterPointerType mpDofUpdater =
641  TSparseSpace::CreateDofUpdater();
642 
646 
660  template<class TEntityType>
661  void CalculateEntityResidualLocalContributions(
662  TEntityType& rCurrentEntity,
663  LocalSystemMatrixType& rLHS_Contribution,
664  LocalSystemVectorType& rRHS_Contribution,
665  const ProcessInfo& rCurrentProcessInfo)
666  {
667  int k = OpenMPUtils::ThisThread();
668  auto& r_residual_adjoint = mAdjointValuesVector[k];
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);
672  }
673 
688  template<class TEntityType>
689  void CalculateEntityGradientContributions(
690  TEntityType& rCurrentEntity,
691  LocalSystemMatrixType& rLHS_Contribution,
692  LocalSystemVectorType& rRHS_Contribution,
693  const ProcessInfo& rCurrentProcessInfo)
694  {
695  int k = OpenMPUtils::ThisThread();
696  rCurrentEntity.CalculateLeftHandSide(mLeftHandSide[k], rCurrentProcessInfo);
697  this->mpResponseFunction->CalculateGradient(
698  rCurrentEntity, mLeftHandSide[k], mResponseGradient[k], rCurrentProcessInfo);
699  noalias(rLHS_Contribution) = mLeftHandSide[k];
700  noalias(rRHS_Contribution) = -1. * mResponseGradient[k];
701  }
702 
717  template<class TEntityType>
718  void CalculateEntityFirstDerivativeContributions(
719  TEntityType& rCurrentEntity,
720  LocalSystemMatrixType& rLHS_Contribution,
721  LocalSystemVectorType& rRHS_Contribution,
722  const ProcessInfo& rCurrentProcessInfo)
723  {
724  int k = OpenMPUtils::ThisThread();
725  rCurrentEntity.CalculateFirstDerivativesLHS(mFirstDerivsLHS[k], rCurrentProcessInfo);
726  mpResponseFunction->CalculateFirstDerivativesGradient(
727  rCurrentEntity, mFirstDerivsLHS[k],
728  mFirstDerivsResponseGradient[k], rCurrentProcessInfo);
729  noalias(rLHS_Contribution) += mBossak.C6 * mFirstDerivsLHS[k];
730  noalias(rRHS_Contribution) -=
732  }
733 
748  template<class TEntityType>
749  void CalculateEntitySecondDerivativeContributions(
750  TEntityType& rCurrentEntity,
751  LocalSystemMatrixType& rLHS_Contribution,
752  LocalSystemVectorType& rRHS_Contribution,
753  const ProcessInfo& rCurrentProcessInfo)
754  {
755  int k = OpenMPUtils::ThisThread();
756  rCurrentEntity.CalculateSecondDerivativesLHS(mSecondDerivsLHS[k], rCurrentProcessInfo);
757  mSecondDerivsLHS[k] *= (1.0 - mBossak.Alpha);
758  this->mpResponseFunction->CalculateSecondDerivativesGradient(
759  rCurrentEntity, mSecondDerivsLHS[k],
760  mSecondDerivsResponseGradient[k], rCurrentProcessInfo);
761  noalias(rLHS_Contribution) += mBossak.C7 * mSecondDerivsLHS[k];
762  noalias(rRHS_Contribution) -=
764  }
765 
784  void CalculatePreviousTimeStepContributions(
785  Element& rCurrentElement,
786  LocalSystemMatrixType& rLHS_Contribution,
787  LocalSystemVectorType& rRHS_Contribution,
788  const ProcessInfo& rCurrentProcessInfo)
789  {
790  const auto& r_geometry = rCurrentElement.GetGeometry();
791  const auto k = OpenMPUtils::ThisThread();
792  auto& r_extensions = *rCurrentElement.GetValue(ADJOINT_EXTENSIONS);
793 
794  unsigned local_index = 0;
795  for (unsigned i_node = 0; i_node < r_geometry.PointsNumber(); ++i_node)
796  {
797  auto& r_node = r_geometry[i_node];
798  r_extensions.GetFirstDerivativesVector(i_node, mAdjointIndirectVector2[k], 1);
799  r_extensions.GetSecondDerivativesVector(i_node, mAdjointIndirectVector3[k], 1);
800  r_extensions.GetAuxiliaryVector(i_node, mAuxAdjointIndirectVector1[k], 1);
801  const double weight = 1.0 / r_node.GetValue(NUMBER_OF_NEIGHBOUR_ELEMENTS);
802 
803  for (unsigned d = 0; d < mAdjointIndirectVector2[k].size(); ++d)
804  {
805  rRHS_Contribution[local_index] +=
806  weight *
810  ++local_index;
811  }
812  }
813  }
814 
835  template<class TEntityType>
836  void CalculateEntityTimeSchemeContributions(
837  TEntityType& rCurrentEntity,
838  LocalSystemVectorType& rAdjointTimeSchemeValues2,
839  LocalSystemVectorType& rAdjointTimeSchemeValues3,
840  const ProcessInfo& rProcessInfo)
841  {
842  KRATOS_TRY
843 
844  const int k = OpenMPUtils::ThisThread();
845  const auto& r_const_entity_ref = rCurrentEntity;
846  r_const_entity_ref.GetValuesVector(mAdjointValuesVector[k]);
847  this->CheckAndResizeThreadStorage(mAdjointValuesVector[k].size());
848 
850  rCurrentEntity.CalculateFirstDerivativesLHS(mFirstDerivsLHS[k], rProcessInfo);
851  this->mpResponseFunction->CalculateFirstDerivativesGradient(
852  rCurrentEntity, mFirstDerivsLHS[k], mFirstDerivsResponseGradient[k], rProcessInfo);
853 
854  rCurrentEntity.CalculateSecondDerivativesLHS(mSecondDerivsLHS[k], rProcessInfo);
855  mSecondDerivsLHS[k] *= (1.0 - mBossak.Alpha);
856  this->mpResponseFunction->CalculateSecondDerivativesGradient(
857  rCurrentEntity, mSecondDerivsLHS[k], mSecondDerivsResponseGradient[k], rProcessInfo);
858 
859  if (rAdjointTimeSchemeValues2.size() != mFirstDerivsResponseGradient[k].size())
860  rAdjointTimeSchemeValues2.resize(mFirstDerivsResponseGradient[k].size(), false);
861  noalias(rAdjointTimeSchemeValues2) =
864  if (rAdjointTimeSchemeValues3.size() != mSecondDerivsResponseGradient[k].size())
865  rAdjointTimeSchemeValues3.resize(mSecondDerivsResponseGradient[k].size(), false);
866  noalias(rAdjointTimeSchemeValues3) =
869 
870  KRATOS_CATCH("");
871  }
872 
885  template <class TEntityType>
886  void CalculateEntityAuxiliaryVariableContributions(
887  TEntityType& rCurrentEntity,
888  LocalSystemVectorType& rAdjointAuxiliaryValues,
889  const ProcessInfo& rProcessInfo)
890  {
891  KRATOS_TRY
892 
893  const int k = OpenMPUtils::ThisThread();
894  const auto& r_const_entity_ref = rCurrentEntity;
895  r_const_entity_ref.GetValuesVector(mAdjointValuesVector[k]);
896  this->CheckAndResizeThreadStorage(mAdjointValuesVector[k].size());
897 
898  rCurrentEntity.CalculateSecondDerivativesLHS(mSecondDerivsLHS[k], rProcessInfo);
900  this->mpResponseFunction->CalculateSecondDerivativesGradient(
901  rCurrentEntity, mSecondDerivsLHS[k], mSecondDerivsResponseGradient[k], rProcessInfo);
902 
903  if (rAdjointAuxiliaryValues.size() != mSecondDerivsLHS[k].size1())
904  rAdjointAuxiliaryValues.resize(mSecondDerivsLHS[k].size1(), false);
905  noalias(rAdjointAuxiliaryValues) =
908 
909  KRATOS_CATCH("");
910  }
911 
912  void CalculateNodeNeighbourCount(ModelPart& rModelPart)
913  {
914  // Calculate number of neighbour elements for each node.
915  VariableUtils().SetNonHistoricalVariableToZero(NUMBER_OF_NEIGHBOUR_ELEMENTS, rModelPart.Nodes());
916 
917  block_for_each(rModelPart.Elements(), [&](ModelPart::ElementType& rElement) {
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);
923  }
924  });
925 
926  rModelPart.GetCommunicator().AssembleNonHistoricalData(NUMBER_OF_NEIGHBOUR_ELEMENTS);
927  }
928 
929  void UpdateTimeSchemeAdjoints(ModelPart& rModelPart)
930  {
931  KRATOS_TRY;
932  std::vector<const VariableData*> lambda2_vars = GatherVariables(
933  rModelPart.Elements(), [](const AdjointExtensions& rExtensions,
934  std::vector<const VariableData*>& rVec) {
935  rExtensions.GetFirstDerivativesVariables(rVec);
936  });
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);
941  });
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);
946  });
947 
948  SetToZero_AdjointVars(lambda2_vars, rModelPart.Nodes());
949  SetToZero_AdjointVars(lambda3_vars, rModelPart.Nodes());
950 
951  const auto& r_process_info = rModelPart.GetProcessInfo();
952  UpdateEntityTimeSchemeContributions(rModelPart.Elements(), r_process_info);
953  UpdateEntityTimeSchemeContributions(rModelPart.Conditions(), r_process_info);
954 
955  // Finalize global assembly
956  Assemble_AdjointVars(lambda2_vars, rModelPart.GetCommunicator());
957  Assemble_AdjointVars(lambda3_vars, rModelPart.GetCommunicator());
958 
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();
963 
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);
972  } else {
973  KRATOS_ERROR << "Unsupported variable type "
974  << r_lambda2_variable_name << ".";
975  }
976  }
977 
978  KRATOS_CATCH("");
979  }
980 
988  template <class TEntityContainerType>
989  void UpdateEntityTimeSchemeContributions(
990  TEntityContainerType& rEntityContainer,
991  const ProcessInfo& rProcessInfo)
992  {
993  KRATOS_TRY
994 
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);
1001 
1002  const int k = OpenMPUtils::ThisThread();
1003 
1004  this->CalculateTimeSchemeContributions(
1005  rEntity, r_adjoint2_aux, r_adjoint3_aux, *this->mpResponseFunction,
1006  mBossak, rProcessInfo);
1007 
1008  auto& r_extensions = *rEntity.GetValue(ADJOINT_EXTENSIONS);
1009 
1010  // Assemble the contributions to the corresponding nodal unknowns.
1011  unsigned local_index = 0;
1012  auto& r_geometry = rEntity.GetGeometry();
1013  for (unsigned i_node = 0; i_node < r_geometry.PointsNumber(); ++i_node) {
1014 
1015  r_extensions.GetFirstDerivativesVector(i_node, mAdjointIndirectVector2[k], 0);
1016  r_extensions.GetSecondDerivativesVector(i_node, mAdjointIndirectVector3[k], 0);
1017 
1018  auto& r_node = r_geometry[i_node];
1019  r_node.SetLock();
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];
1023  ++local_index;
1024  }
1025  r_node.UnSetLock();
1026  }
1027  });
1028 
1029  KRATOS_CATCH("");
1030  }
1031 
1041  template<class TDataType>
1042  void UpdateTimeSchemeVariablesFromOldContributions(
1044  const std::string& rLambda2VariableName,
1045  const std::string& rLambda3VariableName,
1046  const std::string& rAuxiliaryVariableName)
1047  {
1048  KRATOS_TRY
1049 
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);
1053 
1054  block_for_each(rNodes, [&](ModelPart::NodeType& rNode) {
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);
1057 
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;
1061 
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);
1066  });
1067 
1068  KRATOS_CATCH("");
1069  }
1070 
1076  void UpdateAuxiliaryVariable(ModelPart& rModelPart)
1077  {
1078  KRATOS_TRY;
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);
1083  });
1084 
1085  SetToZero_AdjointVars(aux_vars, rModelPart.Nodes());
1086 
1087  const auto& r_process_info = rModelPart.GetProcessInfo();
1088  // Loop over elements to assemble the remaining terms
1089  UpdateEntityAuxiliaryVariableContributions(rModelPart.Elements(), r_process_info);
1090  // Loop over conditions to assemble the remaining terms
1091  UpdateEntityAuxiliaryVariableContributions(rModelPart.Conditions(), r_process_info);
1092 
1093  // Finalize global assembly
1094  Assemble_AdjointVars(aux_vars, rModelPart.GetCommunicator());
1095  KRATOS_CATCH("");
1096  }
1097 
1105  template <class TEntityContainerType>
1106  void UpdateEntityAuxiliaryVariableContributions(
1107  TEntityContainerType& rEntityContainer,
1108  const ProcessInfo& rProcessInfo)
1109  {
1110  KRATOS_TRY
1111 
1112  Vector aux_adjoint_vector;
1113  block_for_each(rEntityContainer, aux_adjoint_vector, [&, this](typename TEntityContainerType::value_type& rEntity, Vector& rAuxAdjointVectorTLS){
1114  const int k = OpenMPUtils::ThisThread();
1115 
1116  this->CalculateAuxiliaryVariableContributions(
1117  rEntity, rAuxAdjointVectorTLS, *this->mpResponseFunction, mBossak, rProcessInfo);
1118 
1119  auto& r_extensions = *rEntity.GetValue(ADJOINT_EXTENSIONS);
1120  // Assemble the contributions to the corresponding nodal unknowns.
1121  unsigned local_index = 0;
1122  auto& r_geometry = rEntity.GetGeometry();
1123 
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);
1127 
1128  r_node.SetLock();
1129  for (unsigned d = 0; d < mAuxAdjointIndirectVector1[k].size(); ++d) {
1130  mAuxAdjointIndirectVector1[k][d] -= rAuxAdjointVectorTLS[local_index];
1131  ++local_index;
1132  }
1133  r_node.UnSetLock();
1134  }
1135  });
1136 
1137  KRATOS_CATCH("");
1138  }
1139 
1149  template<class TDataType>
1150  void CheckVariables(
1151  const ModelPart& rModelPart,
1152  const std::string& rLambda2VariableName,
1153  const std::string& rLambda3VariableName,
1154  const std::string& rAuxiliaryVariableName) const
1155  {
1156  KRATOS_TRY
1157 
1158  KRATOS_ERROR_IF(!KratosComponents<Variable<TDataType>>::Has(rLambda2VariableName))
1159  << "Adjoint variable " << rLambda2VariableName
1160  << " is not found in variable list with required type.\n";
1161 
1162  KRATOS_ERROR_IF(!KratosComponents<Variable<TDataType>>::Has(rLambda3VariableName))
1163  << "Adjoint variable " << rLambda3VariableName
1164  << " is not found in variable list with required type.\n";
1165 
1166  KRATOS_ERROR_IF(!KratosComponents<Variable<TDataType>>::Has(rAuxiliaryVariableName))
1167  << "Adjoint variable " << rAuxiliaryVariableName
1168  << " is not found in variable list with required type.\n";
1169 
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);
1173 
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";
1186 
1187  KRATOS_CATCH("");
1188  }
1189 
1190  static BossakConstants CalculateBossakConstants(double Alpha, double DeltaTime)
1191  {
1192  BossakConstants bc;
1193  bc.Alpha = Alpha;
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);
1204  return bc;
1205  }
1206 
1207  static double GetTimeStep(const ProcessInfo& rCurrentProcessInfo)
1208  {
1209  const ProcessInfo& r_last_process_info =
1210  rCurrentProcessInfo.GetPreviousSolutionStepInfo(1);
1211 
1212  // Note: solution is backwards in time, but we still want a positive
1213  // time step
1214  // (it is the time step in the "forward" Bossak scheme).
1215  double time_step =
1216  r_last_process_info.GetValue(TIME) - rCurrentProcessInfo.GetValue(TIME);
1217  KRATOS_ERROR_IF(time_step <= 0.0)
1218  << "Backwards in time solution is not decreasing time from last "
1219  "step."
1220  << std::endl;
1221  return time_step;
1222  }
1223 
1224  struct Hash
1225  {
1226  std::size_t operator()(const VariableData* const& p) const
1227  {
1228  return p->Key();
1229  }
1230  };
1231 
1232  struct Pred
1233  {
1234  bool operator()(const VariableData* const l, const VariableData* const r) const
1235  {
1236  return *l == *r;
1237  }
1238  };
1239 
1240  // Gathers variables needed for assembly.
1241  static std::vector<const VariableData*> GatherVariables(
1242  const ModelPart::ElementsContainerType& rElements,
1243  std::function<void(const AdjointExtensions&, std::vector<const VariableData*>&)> GetLocalVars)
1244  {
1245  KRATOS_TRY;
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);
1251  const int k = OpenMPUtils::ThisThread();
1252  thread_vars[k].insert(rLocalVarsTLS.begin(), rLocalVarsTLS.end());
1253  });
1254  std::unordered_set<const VariableData*, Hash, Pred> all_vars;
1255  for (int i = 0; i < num_threads; ++i)
1256  {
1257  all_vars.insert(thread_vars[i].begin(), thread_vars[i].end());
1258  }
1259  return std::vector<const VariableData*>{all_vars.begin(), all_vars.end()};
1260  KRATOS_CATCH("");
1261  }
1262 
1263  static void SetToZero_AdjointVars(const std::vector<const VariableData*>& rVariables,
1265  {
1266  KRATOS_TRY;
1267  for (auto p_variable_data : rVariables)
1268  {
1269  if (KratosComponents<Variable<array_1d<double, 3>>>::Has(
1270  p_variable_data->Name()))
1271  {
1272  const auto& r_variable =
1273  KratosComponents<Variable<array_1d<double, 3>>>::Get(
1274  p_variable_data->Name());
1275  VariableUtils().SetHistoricalVariableToZero(r_variable, rNodes);
1276  }
1277  else if (KratosComponents<Variable<double>>::Has(p_variable_data->Name()))
1278  {
1279  const auto& r_variable =
1280  KratosComponents<Variable<double>>::Get(p_variable_data->Name());
1281  VariableUtils().SetHistoricalVariableToZero(r_variable, rNodes);
1282  }
1283  else
1284  {
1285  KRATOS_ERROR << "Variable \"" << p_variable_data->Name()
1286  << "\" not found!\n";
1287  }
1288  }
1289  KRATOS_CATCH("");
1290  }
1291 
1292  static void Assemble_AdjointVars(const std::vector<const VariableData*>& rVariables,
1293  Communicator& rComm)
1294  {
1295  KRATOS_TRY;
1296  for (auto p_variable_data : rVariables)
1297  {
1298  if (KratosComponents<Variable<array_1d<double, 3>>>::Has(
1299  p_variable_data->Name()))
1300  {
1301  const auto& r_variable =
1302  KratosComponents<Variable<array_1d<double, 3>>>::Get(
1303  p_variable_data->Name());
1304  rComm.AssembleCurrentData(r_variable);
1305  }
1306  else if (KratosComponents<Variable<double>>::Has(p_variable_data->Name()))
1307  {
1308  const auto& r_variable =
1309  KratosComponents<Variable<double>>::Get(p_variable_data->Name());
1310  rComm.AssembleCurrentData(r_variable);
1311  }
1312  else
1313  {
1314  KRATOS_ERROR << "Variable \"" << p_variable_data->Name()
1315  << "\" not found!\n";
1316  }
1317  }
1318  KRATOS_CATCH("");
1319  }
1320 
1324 
1328 
1332 
1334 
1335 }; /* Class ResidualBasedAdjointBossakScheme */
1336 
1338 
1341 
1343 
1344 } /* namespace Kratos.*/
1345 
1346 #endif /* KRATOS_RESIDUAL_BASED_ADJOINT_BOSSAK_SCHEME_H_INCLUDED defined */
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