13 #if !defined(KRATOS_VELOCITY_PRESSURE_NORM_SQUARE_RESPONSE_FUNCTION_H_INCLUDED)
14 #define KRATOS_VELOCITY_PRESSURE_NORM_SQUARE_RESPONSE_FUNCTION_H_INCLUDED
86 "main_model_part_name": "PLEASE_SPECIFY_MODEL_PART_NAME",
87 "norm_model_part_name": "PLEASE_SPECIFY_MODEL_PART_NAME",
88 "velocity_norm_factor": 1.0,
89 "pressure_norm_factor": 1.0,
90 "entities" : ["elements"]
95 mMainModelPartName = Settings["main_model_part_name"].
GetString();
96 mNormModelPartName = Settings[
"norm_model_part_name"].
GetString();
97 mVelocityNormFactor = Settings[
"velocity_norm_factor"].
GetDouble();
98 mPressureNormFactor = Settings[
"pressure_norm_factor"].
GetDouble();
101 mIsConditions =
false;
103 for (
const auto& entity : entities) {
104 if (entity ==
"elements") {
106 }
else if (entity ==
"conditions") {
107 mIsConditions =
true;
109 KRATOS_ERROR <<
"Unsupported entity type provided under "
110 "\"entities\". Supported entity types are:\n"
112 <<
"\t conditions\n.";
132 auto& r_main_model_part = mrModel.
GetModelPart(mMainModelPartName);
133 auto& r_norm_model_part = mrModel.
GetModelPart(mNormModelPartName);
135 if (mIsElements && !mIsConditions) {
139 if (number_of_entities == 0) {
141 <<
"Only \"elements\" are chosen as entities "
142 "and no elements are found in "
143 << r_norm_model_part.Name() <<
" model part. Therefore trying to compute response function on conditions.\n";
144 mIsConditions =
true;
154 total_entities += r_norm_model_part.GetCommunicator().GlobalNumberOfElements();
159 total_entities += r_norm_model_part.GetCommunicator().GlobalNumberOfConditions();
164 <<
"No entities were found in "
165 << r_norm_model_part.Name() <<
" to calculate response function value. Please check model part.\n";
171 const Element& rAdjointElement,
172 const Matrix& rResidualGradient,
173 Vector& rResponseGradient,
176 rResponseGradient.
clear();
181 const Matrix& rResidualGradient,
182 Vector& rResponseGradient,
185 rResponseGradient.
clear();
189 const Element& rAdjointElement,
190 const Matrix& rResidualGradient,
191 Vector& rResponseGradient,
194 CalculateEntityFirstDerivatives<Element>(
195 rAdjointElement, rResidualGradient, rResponseGradient, rProcessInfo);
200 const Matrix& rResidualGradient,
201 Vector& rResponseGradient,
204 CalculateEntityFirstDerivatives<Condition>(
205 rAdjointCondition, rResidualGradient, rResponseGradient, rProcessInfo);
209 const Element& rAdjointElement,
210 const Matrix& rResidualGradient,
211 Vector& rResponseGradient,
214 rResponseGradient.
clear();
219 const Matrix& rResidualGradient,
220 Vector& rResponseGradient,
223 rResponseGradient.
clear();
229 const Matrix& rSensitivityMatrix,
230 Vector& rSensitivityGradient,
233 CalculateEntitySensitivityDerivatives(rAdjointElement, rSensitivityGradient, rProcessInfo);
239 const Matrix& rSensitivityMatrix,
240 Vector& rSensitivityGradient,
243 CalculateEntitySensitivityDerivatives(rAdjointCondition, rSensitivityGradient, rProcessInfo);
250 double norm_square = 0.0;
252 norm_square += block_for_each<SumReduction<double>>(
255 return CalculateEntityValue<Element>(rElement, rMatrix);
260 norm_square += block_for_each<SumReduction<double>>(
263 return CalculateEntityValue<Condition>(rCondition, rMatrix);
280 std::string mMainModelPartName;
281 std::string mNormModelPartName;
283 double mVelocityNormFactor;
284 double mPressureNormFactor;
292 template<
class TEntityType>
293 double CalculateEntityValue(
294 const TEntityType& rEntity,
295 Matrix& rShapeFunctions)
const
297 if (rEntity.Is(STRUCTURE)) {
298 const auto& r_geometry = rEntity.GetGeometry();
300 this->CalculateGeometryData(r_geometry, rShapeFunctions);
303 const double volume = r_geometry.DomainSize();
317 template<
class TEntityType>
318 void CalculateEntityFirstDerivatives(
319 const TEntityType& rEntity,
320 const Matrix& rResidualGradient,
321 Vector& rResponseGradient,
322 const ProcessInfo& rProcessInfo)
const
326 const auto& r_geometry = rEntity.GetGeometry();
327 const IndexType number_of_nodes = r_geometry.PointsNumber();
332 if (rResponseGradient.size() != rResidualGradient.size2()) {
333 rResponseGradient.resize(rResidualGradient.size2());
336 if (rEntity.Is(STRUCTURE)) {
338 this->CalculateGeometryData(r_geometry, shape_functions);
346 const double volume_2 = std::pow(r_geometry.DomainSize(), 2);
348 const double coeff_1 = volume_2 * 2.0 * mVelocityNormFactor;
349 const double coeff_2 = volume_2 * 2.0 * mPressureNormFactor *
pressure;
355 rResponseGradient[local_index++] = coeff_1 *
N[
c] *
velocity[
k];
359 rResponseGradient[local_index] = coeff_2 *
N[
c];
362 local_index += skip_size + 1;
365 rResponseGradient.clear();
371 template<
class TEntityType>
372 void CalculateEntitySensitivityDerivatives(
373 const TEntityType& rEntity,
374 Vector& rResponseGradient,
375 const ProcessInfo& rProcessInfo)
const
379 const auto& r_geometry = rEntity.GetGeometry();
380 const IndexType number_of_nodes = r_geometry.PointsNumber();
388 if (rEntity.Is(STRUCTURE)) {
390 this->CalculateGeometryData(r_geometry, shape_functions);
393 const double volume = r_geometry.DomainSize();
400 const double lx = r_geometry[0].X() - r_geometry[1].X();
401 const double ly = r_geometry[0].Y() - r_geometry[1].Y();
405 const double lx_derivative =
406 (
c == 0 &&
k == 0) * (1.0) + (
c == 1 &&
k == 0) * (-1.0);
407 const double ly_derivative =
408 (
c == 0 &&
k == 1) * (1.0) + (
c == 1 &&
k == 1) * (-1.0);
409 const double volume_derivative =
410 (1.0 /
volume) * (lx * lx_derivative + ly * ly_derivative);
414 2 *
volume * volume_derivative;
415 value += mPressureNormFactor * std::pow(
pressure, 2) * 2 *
416 volume * volume_derivative;
422 rResponseGradient.clear();
428 void CalculateGeometryData(
430 Matrix& rNContainer)
const
433 const unsigned int number_of_gauss_points =
434 rGeometry.IntegrationPointsNumber(r_integrations_method);
436 const std::size_t number_of_nodes = rGeometry.PointsNumber();
438 if (rNContainer.size1() != number_of_gauss_points ||
439 rNContainer.size2() != number_of_nodes) {
440 rNContainer.resize(number_of_gauss_points, number_of_nodes,
false);
442 rNContainer = rGeometry.ShapeFunctionsValues(r_integrations_method);
A base class for adjoint response functions.
Definition: adjoint_response_function.h:39
SizeType GlobalNumberOfElements() const
Definition: communicator.cpp:106
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
Geometry< NodeType > GeometryType
definition of the geometry type with given NodeType
Definition: element.h:83
void clear()
Definition: amatrix_interface.h:284
This class aims to manage different model parts across multi-physics simulations.
Definition: model.h:60
ModelPart & GetModelPart(const std::string &rFullModelPartName)
This method returns a model part given a certain name.
Definition: model.cpp:107
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Element ElementType
Definition: model_part.h:120
Communicator & GetCommunicator()
Definition: model_part.h:1821
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
std::vector< std::string > GetStringArray() const
This method returns the array of strings in the current Parameter.
Definition: kratos_parameters.cpp:693
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
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
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 SetFlag(const Flags &rFlag, const bool FlagValue, TContainerType &rContainer)
Sets a flag according to a given status over a given container.
Definition: variable_utils.h:900
A response function for norm square calculation.
Definition: velocity_pressure_norm_square_response_function.h:59
void Initialize() override
Definition: velocity_pressure_norm_square_response_function.h:128
void CalculatePartialSensitivity(Element &rAdjointElement, const Variable< array_1d< double, 3 >> &rVariable, const Matrix &rSensitivityMatrix, Vector &rSensitivityGradient, const ProcessInfo &rProcessInfo) override
Calculate the partial sensitivity w.r.t. design variable.
Definition: velocity_pressure_norm_square_response_function.h:226
double CalculateValue(ModelPart &rModelPart) override
Calculate the scalar valued response function.
Definition: velocity_pressure_norm_square_response_function.h:246
std::size_t IndexType
Definition: velocity_pressure_norm_square_response_function.h:68
void CalculatePartialSensitivity(Condition &rAdjointCondition, const Variable< array_1d< double, 3 >> &rVariable, const Matrix &rSensitivityMatrix, Vector &rSensitivityGradient, const ProcessInfo &rProcessInfo) override
Calculate the partial sensitivity w.r.t. design variable.
Definition: velocity_pressure_norm_square_response_function.h:236
void CalculateSecondDerivativesGradient(const Element &rAdjointElement, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. second derivatives of primal solution.
Definition: velocity_pressure_norm_square_response_function.h:208
typename ElementType::GeometryType GeometryType
Definition: velocity_pressure_norm_square_response_function.h:66
void CalculateGradient(const Condition &rAdjointCondition, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. primal solution.
Definition: velocity_pressure_norm_square_response_function.h:179
VelocityPressureNormSquareResponseFunction(Parameters Settings, Model &rModel)
Constructor.
Definition: velocity_pressure_norm_square_response_function.h:77
void CalculateSecondDerivativesGradient(const Condition &rAdjointCondition, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. second derivatives of primal solution.
Definition: velocity_pressure_norm_square_response_function.h:217
void CalculateFirstDerivativesGradient(const Element &rAdjointElement, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. first derivatives of primal solution.
Definition: velocity_pressure_norm_square_response_function.h:188
void CalculateGradient(const Element &rAdjointElement, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. primal solution.
Definition: velocity_pressure_norm_square_response_function.h:170
~VelocityPressureNormSquareResponseFunction() override
Destructor.
Definition: velocity_pressure_norm_square_response_function.h:120
KRATOS_CLASS_POINTER_DEFINITION(VelocityPressureNormSquareResponseFunction)
void CalculateFirstDerivativesGradient(const Condition &rAdjointCondition, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. first derivatives of primal solution.
Definition: velocity_pressure_norm_square_response_function.h:198
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static void EvaluateInPoint(const GeometryType &rGeometry, const Vector &rShapeFunction, const int Step, const TRefVariableValuePairArgs &... rValueVariablePairs)
Evaluates given list of variable pairs at gauss point locations at step.
Definition: fluid_calculation_utilities.h:75
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_WARNING(label)
Definition: logger.h:265
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
float velocity
Definition: PecletTest.py:54
int domain_size
Definition: face_heat.py:4
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
int block_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:16
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
int k
Definition: quadrature.py:595
N
Definition: sensitivityMatrix.py:29
volume
Definition: sp_statistics.py:15
float pressure
Definition: test_pureconvectionsolver_benchmarking.py:101