78 std::string gradient_mode = responseSettings[
"gradient_mode"].
GetString();
80 if (gradient_mode.compare(
"semi_analytic") == 0)
86 KRATOS_ERROR <<
"Specified gradient_mode '" << gradient_mode <<
"' not recognized. The only option is: semi_analytic" << std::endl;
114 double strain_energy = 0.0;
117 for (
auto& elem_i : mrModelPart.
Elements())
119 const bool element_is_active = elem_i.
IsDefined(ACTIVE) ? elem_i.Is(ACTIVE) :
true;
120 if(element_is_active)
127 const auto& rConstElemRef = elem_i;
128 rConstElemRef.GetValuesVector(
u,0);
130 elem_i.CalculateLocalSystem(LHS,RHS,CurrentProcessInfo);
137 return strain_energy;
192 return "StrainEnergyResponseFunctionUtility";
198 rOStream <<
"StrainEnergyResponseFunctionUtility";
247 for (
auto& elem_i : mrModelPart.
Elements())
249 const bool element_is_active = elem_i.
IsDefined(ACTIVE) ? elem_i.Is(ACTIVE) :
true;
250 if(element_is_active)
257 const auto& rConstElemRef = elem_i;
258 rConstElemRef.GetValuesVector(
u,0);
264 elem_i.CalculateRightHandSide(RHS, CurrentProcessInfo);
265 for (
auto& node_i : elem_i.GetGeometry())
267 array_3d gradient_contribution(3, 0.0);
272 gradient_contribution[0] =
inner_prod(lambda, derived_RHS);
276 gradient_contribution[1] =
inner_prod(lambda, derived_RHS);
280 gradient_contribution[2] =
inner_prod(lambda, derived_RHS);
283 noalias(node_i.FastGetSolutionStepValue(SHAPE_SENSITIVITY)) += gradient_contribution;
293 const bool condition_is_active = cond_i.IsDefined(ACTIVE) ? cond_i.Is(ACTIVE) :
true;
294 if (condition_is_active)
301 const auto& rConstCondRef = cond_i;
302 rConstCondRef.GetValuesVector(
u,0);
306 cond_i.CalculateRightHandSide(RHS, CurrentProcessInfo);
307 for (
auto& node_i : cond_i.GetGeometry())
309 array_3d gradient_contribution(3, 0.0);
313 node_i.X0() += mDelta;
314 cond_i.CalculateRightHandSide(perturbed_RHS, CurrentProcessInfo);
315 gradient_contribution[0] =
inner_prod(lambda, (perturbed_RHS - RHS) / mDelta);
316 node_i.X0() -= mDelta;
319 perturbed_RHS =
Vector(0);
322 node_i.Y0() += mDelta;
323 cond_i.CalculateRightHandSide(perturbed_RHS, CurrentProcessInfo);
324 gradient_contribution[1] =
inner_prod(lambda, (perturbed_RHS - RHS) / mDelta);
325 node_i.Y0() -= mDelta;
328 perturbed_RHS =
Vector(0);
331 node_i.Z0() += mDelta;
332 cond_i.CalculateRightHandSide(perturbed_RHS, CurrentProcessInfo);
333 gradient_contribution[2] =
inner_prod(lambda, (perturbed_RHS - RHS) / mDelta);
334 node_i.Z0() -= mDelta;
337 noalias(node_i.FastGetSolutionStepValue(SHAPE_SENSITIVITY)) += gradient_contribution;
358 const bool condition_is_active = cond_i.
IsDefined(ACTIVE) ? cond_i.Is(ACTIVE) :
true;
359 if (condition_is_active)
365 const auto& rConstCondRef = cond_i;
366 rConstCondRef.GetValuesVector(
u,0);
369 cond_i.CalculateRightHandSide(RHS, CurrentProcessInfo);
370 for (
auto& node_i : cond_i.GetGeometry())
372 array_3d gradient_contribution(3, 0.0);
376 node_i.X0() += mDelta;
377 cond_i.CalculateRightHandSide(perturbed_RHS, CurrentProcessInfo);
378 gradient_contribution[0] =
inner_prod(0.5*
u, (perturbed_RHS - RHS) / mDelta);
379 node_i.X0() -= mDelta;
382 perturbed_RHS =
Vector(0);
385 node_i.Y0() += mDelta;
386 cond_i.CalculateRightHandSide(perturbed_RHS, CurrentProcessInfo);
387 gradient_contribution[1] =
inner_prod(0.5*
u, (perturbed_RHS - RHS) / mDelta);
388 node_i.Y0() -= mDelta;
391 perturbed_RHS =
Vector(0);
394 node_i.Z0() += mDelta;
395 cond_i.CalculateRightHandSide(perturbed_RHS, CurrentProcessInfo);
396 gradient_contribution[2] =
inner_prod(0.5*
u, (perturbed_RHS - RHS) / mDelta);
397 node_i.Z0() -= mDelta;
400 noalias(node_i.FastGetSolutionStepValue(SHAPE_SENSITIVITY)) += gradient_contribution;
static void CalculateRightHandSideDerivative(Element &rElement, const Vector &rRHS, const Variable< double > &rDesignVariable, const double &rPertubationSize, Matrix &rOutput, const ProcessInfo &rCurrentProcessInfo)
Definition: finite_difference_utility.cpp:22
bool IsDefined(Flags const &rOther) const
Definition: flags.h:279
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
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
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Short class definition.
Definition: strain_energy_response_function_utility.h:59
double CalculateValue()
Definition: strain_energy_response_function_utility.h:109
KRATOS_CLASS_POINTER_DEFINITION(StrainEnergyResponseFunctionUtility)
Pointer definition of StrainEnergyResponseFunctionUtility.
void CalculateGradient()
Definition: strain_energy_response_function_utility.h:143
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: strain_energy_response_function_utility.h:196
void CalculateStateDerivativePartByFiniteDifferencing()
Definition: strain_energy_response_function_utility.h:239
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: strain_energy_response_function_utility.h:202
void CalculateResponseDerivativePartByFiniteDifferencing()
Definition: strain_energy_response_function_utility.h:346
std::string Info() const
Turn back information as a string.
Definition: strain_energy_response_function_utility.h:190
void Initialize()
Definition: strain_energy_response_function_utility.h:104
virtual ~StrainEnergyResponseFunctionUtility()
Destructor.
Definition: strain_energy_response_function_utility.h:91
void CalculateAdjointField()
Definition: strain_energy_response_function_utility.h:229
StrainEnergyResponseFunctionUtility(ModelPart &model_part, Parameters responseSettings)
Default constructor.
Definition: strain_energy_response_function_utility.h:74
array_1d< double, 3 > array_3d
Definition: strain_energy_response_function_utility.h:64
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void SetHistoricalVariableToZero(const Variable< TType > &rVariable, NodesContainerType &rNodes)
Sets the nodal value of any variable to zero.
Definition: variable_utils.h:757
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
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
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
model_part
Definition: face_heat.py:14
u
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:30
double precision, dimension(3, 3), public delta
Definition: TensorModule.f:16