13 #if !defined(KRATOS_DRAG_RESPONSE_FUNCTION_H_INCLUDED)
14 #define KRATOS_DRAG_RESPONSE_FUNCTION_H_INCLUDED
46 template <
unsigned int TDim>
61 : mrModelPart(rModelPart)
67 "structure_model_part_name": "PLEASE_SPECIFY_STRUCTURE_MODEL_PART",
68 "drag_direction": [1.0, 0.0, 0.0]
73 mStructureModelPartName = Settings["structure_model_part_name"].
GetString();
75 if (Settings[
"drag_direction"].IsArray() ==
false ||
76 Settings[
"drag_direction"].size() != 3)
78 KRATOS_ERROR <<
"Invalid \"drag_direction\"." << std::endl;
81 for (
unsigned int d = 0;
d < TDim; ++
d)
82 mDragDirection[
d] = Settings[
"drag_direction"][
d].GetDouble();
84 if (std::abs(
norm_2(mDragDirection) - 1.0) > 1
e-3)
86 const double magnitude =
norm_2(mDragDirection);
88 KRATOS_ERROR <<
"\"drag_direction\" is zero." << std::endl;
91 <<
"Non unit magnitude in \"drag_direction\"." << std::endl;
92 KRATOS_WARNING(
"DragResponseFunction") <<
"Normalizing ..." << std::endl;
94 for (
unsigned int d = 0;
d < TDim; ++
d)
95 mDragDirection[
d] /= magnitude;
129 const Matrix& rResidualGradient,
130 Vector& rResponseGradient,
133 CalculateDragContribution(
139 const Matrix& rResidualGradient,
140 Vector& rResponseGradient,
143 rResponseGradient.
clear();
147 const Matrix& rResidualGradient,
148 Vector& rResponseGradient,
151 CalculateDragContribution(
156 const Matrix& rResidualGradient,
157 Vector& rResponseGradient,
160 rResponseGradient.
clear();
164 const Matrix& rResidualGradient,
165 Vector& rResponseGradient,
168 CalculateDragContribution(
173 const Matrix& rResidualGradient,
174 Vector& rResponseGradient,
177 rResponseGradient.
clear();
182 const Matrix& rSensitivityMatrix,
183 Vector& rSensitivityGradient,
188 CalculateDragContribution(
189 rSensitivityMatrix, rAdjointElement.
GetGeometry().
Points(), rSensitivityGradient);
196 const Matrix& rSensitivityMatrix,
197 Vector& rSensitivityGradient,
200 if (rSensitivityGradient.size() != rSensitivityMatrix.size1())
201 rSensitivityGradient.
resize(rSensitivityMatrix.size1(),
false);
203 rSensitivityGradient.
clear();
209 KRATOS_ERROR <<
"DragResponseFunction::CalculateValue(ModelPart& "
210 "rModelPart) is not implemented!!!\n";
235 std::string mStructureModelPartName;
250 if (mrModelPart.HasSubModelPart(mStructureModelPartName) ==
false)
251 KRATOS_ERROR <<
"No sub model part \"" << mStructureModelPartName
252 <<
"\"" << std::endl;
257 void CalculateDragContribution(
const Matrix& rDerivativesOfResidual,
259 Vector& rDerivativesOfDrag)
const
261 constexpr std::size_t max_size = 50;
262 BoundedVector<double, max_size> drag_flag_vector(rDerivativesOfResidual.size2());
263 drag_flag_vector.clear();
265 const unsigned num_nodes = rNodes.size();
266 const unsigned local_size = rDerivativesOfResidual.size2() / num_nodes;
268 for (
unsigned i_node = 0; i_node < num_nodes; ++i_node)
270 if (rNodes[i_node].Is(STRUCTURE))
272 for (
unsigned d = 0;
d < TDim; ++
d)
273 drag_flag_vector[i_node *
local_size +
d] = mDragDirection[
d];
277 if (rDerivativesOfDrag.size() != rDerivativesOfResidual.size1())
278 rDerivativesOfDrag.resize(rDerivativesOfResidual.size1(),
false);
280 noalias(rDerivativesOfDrag) =
prod(rDerivativesOfResidual, drag_flag_vector);
A base class for adjoint response functions.
Definition: adjoint_response_function.h:39
Base class for all Conditions.
Definition: condition.h:59
A response function for drag.
Definition: drag_response_function.h:48
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: drag_response_function.h:155
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: drag_response_function.h:194
double CalculateValue(ModelPart &rModelPart) override
Calculate the scalar valued response function.
Definition: drag_response_function.h:206
void CalculateGradient(const Condition &rAdjointCondition, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. primal solution.
Definition: drag_response_function.h:137
~DragResponseFunction() override
Destructor.
Definition: drag_response_function.h:102
void Initialize() override
Definition: drag_response_function.h:114
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: drag_response_function.h:146
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: drag_response_function.h:163
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: drag_response_function.h:172
void CalculateGradient(const Element &rAdjointElement, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. primal solution.
Definition: drag_response_function.h:128
KRATOS_CLASS_POINTER_DEFINITION(DragResponseFunction)
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: drag_response_function.h:180
DragResponseFunction(Parameters Settings, ModelPart &rModelPart)
Constructor.
Definition: drag_response_function.h:60
Base class for all Elements.
Definition: element.h:60
Geometry< NodeType >::PointsArrayType NodesArrayType
definition of nodes container type, redefined from GeometryType
Definition: element.h:86
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
const PointsArrayType & Points() const
Definition: geometry.h:1768
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
void clear()
Definition: amatrix_interface.h:284
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
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
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
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#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::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
int d
Definition: ode_solve.py:397
e
Definition: run_cpp_mpi_tests.py:31