12 #ifndef KRATOS_LOCAL_TEMPERATURE_AVERAGE_RESPONSE_FUNCTION_H_INCLUDED
13 #define KRATOS_LOCAL_TEMPERATURE_AVERAGE_RESPONSE_FUNCTION_H_INCLUDED
44 mTargetModelPartName = Settings[
"model_part_name"].
GetString();
46 auto& r_target_model_part = GetTargetModelPart(rModelPart, mTargetModelPartName);
47 auto& r_nodes = r_target_model_part.Nodes();
48 mNumNodes = r_nodes.size();
51 variable_utils.
SetFlag(STRUCTURE,
true,r_nodes);
54 for (
auto& r_node : r_nodes)
56 r_node.SetValue(NUMBER_OF_NEIGHBOUR_ELEMENTS,0);
61 auto& r_elements = rModelPart.
Elements();
62 const int num_elements = r_elements.size();
64 #pragma omp parallel for
65 for (
int i = 0;
i < num_elements;
i++)
67 auto i_elem = r_elements.begin() +
i;
68 auto& r_geom = i_elem->GetGeometry();
69 for (
unsigned int i = 0;
i < r_geom.PointsNumber();
i++)
71 auto& r_node = r_geom[
i];
72 if (r_node.Is(STRUCTURE))
75 r_node.GetValue(NUMBER_OF_NEIGHBOUR_ELEMENTS) += 1;
107 const Matrix& rResidualGradient,
108 Vector& rResponseGradient,
111 ComputePointTemperatureSensitivityContribution(rResidualGradient, rAdjointElement.
GetGeometry().
Points(),rResponseGradient);
115 const Matrix& rResidualGradient,
116 Vector& rResponseGradient,
123 const Matrix& rResidualGradient,
124 Vector& rResponseGradient,
127 ComputePointTemperatureSensitivityContribution(rResidualGradient, rAdjointElement.
GetGeometry().
Points(),rResponseGradient);
131 const Matrix& rResidualGradient,
132 Vector& rResponseGradient,
135 ComputePointTemperatureSensitivityContribution(rResidualGradient, rAdjointElement.
GetGeometry().
Points(),rResponseGradient);
140 const Matrix& rSensitivityMatrix,
141 Vector& rSensitivityGradient,
144 if (rSensitivityGradient.size() != rSensitivityMatrix.size1())
145 rSensitivityGradient.
resize(rSensitivityMatrix.size1(),
false);
151 const Matrix& rSensitivityMatrix,
152 Vector& rSensitivityGradient,
155 if (rSensitivityGradient.size() != rSensitivityMatrix.size1())
156 rSensitivityGradient.
resize(rSensitivityMatrix.size1(),
false);
164 GetTargetModelPart(rModelPart, mTargetModelPartName);
166 const double domain_aggregated_temperature =
171 const int total_nodes = r_communicator.GetDataCommunicator().SumAll(number_of_nodes);
173 return domain_aggregated_temperature /
static_cast<double>(total_nodes);
199 std::string mTargetModelPartName;
205 void ComputePointTemperatureSensitivityContribution(
206 const Matrix& rDerivativesOfResidual,
208 Vector& rLocalSensitivityContribution)
const
210 if (rLocalSensitivityContribution.size() != rDerivativesOfResidual.size1())
211 rLocalSensitivityContribution.
resize(rDerivativesOfResidual.size1(),
false);
213 noalias(rLocalSensitivityContribution) =
ZeroVector(rLocalSensitivityContribution.size());
215 const unsigned int num_nodes = rNodes.
size();
217 for (
unsigned int i = 0;
i < num_nodes;
i++)
219 if (rNodes[
i].Is(STRUCTURE))
221 double factor = 1.0 / (rNodes[
i].GetValue(NUMBER_OF_NEIGHBOUR_ELEMENTS)*mNumNodes);
222 rLocalSensitivityContribution[
i] =
factor;
227 ModelPart& GetTargetModelPart(ModelPart& rModelPart,
const std::string& rTargetModelPartName)
230 if (rModelPart.Name() == rTargetModelPartName)
234 else if (rModelPart.HasSubModelPart(rTargetModelPartName))
236 return rModelPart.GetSubModelPart(rTargetModelPartName);
240 KRATOS_ERROR <<
"Unknown ModelPart " << rTargetModelPartName <<
"." << std::endl;
A base class for adjoint response functions.
Definition: adjoint_response_function.h:39
The Commmunicator class manages communication for distributed ModelPart instances.
Definition: communicator.h:67
virtual bool AssembleNonHistoricalData(Variable< int > const &ThisVariable)
Definition: communicator.cpp:527
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
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
Definition: local_temperature_average_response_function.h:28
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: local_temperature_average_response_function.h:130
void CalculatePartialSensitivity(Condition &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: local_temperature_average_response_function.h:149
void CalculateGradient(const Element &rAdjointElement, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. primal solution.
Definition: local_temperature_average_response_function.h:106
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: local_temperature_average_response_function.h:138
~LocalTemperatureAverageResponseFunction() override
Destructor.
Definition: local_temperature_average_response_function.h:87
KRATOS_CLASS_POINTER_DEFINITION(LocalTemperatureAverageResponseFunction)
LocalTemperatureAverageResponseFunction(Parameters Settings, ModelPart &rModelPart)
Constructor.
Definition: local_temperature_average_response_function.h:40
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: local_temperature_average_response_function.h:122
double CalculateValue(ModelPart &rModelPart) override
Calculate the scalar valued response function.
Definition: local_temperature_average_response_function.h:160
void CalculateGradient(const Condition &rAdjointCondition, const Matrix &rResidualGradient, Vector &rResponseGradient, const ProcessInfo &rProcessInfo) override
Calculate the local gradient w.r.t. primal solution.
Definition: local_temperature_average_response_function.h:114
void Initialize() override
Definition: local_temperature_average_response_function.h:99
SizeType NumberOfNodes() const
Definition: mesh.h:259
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
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::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
size_type size() const
Definition: pointer_vector.h:255
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
TDataType SumHistoricalVariable(const TVarType &rVariable, const ModelPart &rModelPart, const unsigned int BuffStep=0)
This method accumulates and return a variable value For a nodal historical variable,...
Definition: variable_utils.h:1253
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
integer i
Definition: TensorModule.f:17
float factor
for node in (self.combined_model_part).Nodes: pold = node.GetSolutionStepValue(PRESSURE,...
Definition: ulf_PGLASS.py:254