19 #if !defined(KRATOS_TOPOLOGY_FILTERING_UTILITIES_H_INCLUDED)
20 #define KRATOS_TOPOLOGY_FILTERING_UTILITIES_H_INCLUDED
32 #include "custom_utilities/filter_function.h"
95 Element::Pointer mpElement;
133 mSearchRadius(SearchRadius),
134 mMaxElementsAffected(MaxElementsAffected)
167 if ( strcmp( FilterType ,
"sensitivity" ) == 0 ){
169 KRATOS_INFO(
"[TopOpt]") <<
" Sensitivity filter chosen as filter for sensitivities" << std::endl;
171 if ( strcmp( FilterFunctionType ,
"linear" ) == 0 )
172 KRATOS_INFO(
"[TopOpt]") <<
" Linear filter kernel selected" << std::endl;
174 KRATOS_ERROR <<
"No valid FilterFunction selected for the simulation. Selected one: " << FilterFunctionType << std::endl;
181 for(ModelPart::ElementsContainerType::iterator elem_i = mrModelPart.
ElementsBegin(); elem_i!=mrModelPart.
ElementsEnd(); elem_i++)
186 for(
unsigned int i=0;
i<geom.
size();
i++)
187 noalias(center_coord) += (geom[
i].GetInitialPosition());
188 center_coord /=
static_cast<double>(geom.
size());
192 PositionList.push_back( pGP );
197 const int BucketSize = 4;
198 tree MyTree(PositionList.begin(),PositionList.end(),BucketSize);
201 std::vector<double> resulting_squared_distances(mMaxElementsAffected);
204 KRATOS_INFO(
"[TopOpt]") <<
" Filtered tree created [ spent time = " << timer_tree.
ElapsedSeconds() <<
" ] " << std::endl;
210 for(ModelPart::ElementsContainerType::iterator elem_i = mrModelPart.
ElementsBegin(); elem_i!=mrModelPart.
ElementsEnd(); elem_i++)
216 for(
unsigned int i=0;
i<geom.
size();
i++)
217 noalias(center_coord) += (geom[
i].GetInitialPosition());
218 center_coord /=
static_cast<double>(geom.
size());
223 const int num_nodes_found = MyTree.
SearchInRadius(ElemPositionItem,mSearchRadius,Results.begin(),resulting_squared_distances.begin(),mMaxElementsAffected);
232 double distance = 0.0;
234 for(
int ElementPositionItem_j = 0; ElementPositionItem_j < num_nodes_found; ElementPositionItem_j++)
238 elemental_distance = *Results[ElementPositionItem_j] - center_coord;
239 distance = std::sqrt(
inner_prod(elemental_distance,elemental_distance));
243 Hxdc =
H*(Results[ElementPositionItem_j]->GetOriginElement()->GetValue(DCDX))
244 *(Results[ElementPositionItem_j]->GetOriginElement()->GetValue(X_PHYS));
250 dcdx_filtered[
i++] = Hxdc_sum / (H_sum*
std::max(0.001,elem_i->GetValue(X_PHYS)) );
255 for(ModelPart::ElementsContainerType::iterator elem_i = mrModelPart.
ElementsBegin();
257 elem_i->SetValue(DCDX,dcdx_filtered[
i++]);
259 KRATOS_INFO(
"[TopOpt]") <<
" Filtered sensitivities calculated [ spent time = " <<
timer.ElapsedSeconds() <<
" ] " << std::endl;
262 KRATOS_ERROR <<
"No valid FilterType selected for the simulation. Selected one: " << FilterType << std::endl;
277 if ( strcmp( FilterType ,
"density" ) == 0 ){
279 KRATOS_INFO(
"[TopOpt]") <<
" Density filter chosen as filter for densities" << std::endl;
281 if ( strcmp( FilterFunctionType ,
"linear" ) == 0 )
282 KRATOS_INFO(
"[TopOpt]") <<
" Linear filter kernel selected" << std::endl;
284 KRATOS_ERROR <<
"No valid FilterFunction selected for the simulation. Selected one: " << FilterFunctionType << std::endl;
291 for(ModelPart::ElementsContainerType::iterator elem_i = mrModelPart.
ElementsBegin(); elem_i!=mrModelPart.
ElementsEnd(); elem_i++)
296 for(
unsigned int i=0;
i<geom.
size();
i++)
297 noalias(center_coord) += (geom[
i].GetInitialPosition());
298 center_coord /=
static_cast<double>(geom.
size());
302 PositionList.push_back( pGP );
307 const int BucketSize = 4;
308 tree MyTree(PositionList.begin(),PositionList.end(),BucketSize);
311 std::vector<double> resulting_squared_distances(mMaxElementsAffected);
314 KRATOS_INFO(
"[TopOpt]") <<
" Filtered tree created [ spent time = " << timer_tree.
ElapsedSeconds() <<
" ] " << std::endl;
320 for(ModelPart::ElementsContainerType::iterator elem_i = mrModelPart.
ElementsBegin(); elem_i!=mrModelPart.
ElementsEnd(); elem_i++)
326 for(
unsigned int i=0;
i<geom.
size();
i++)
327 noalias(center_coord) += (geom[
i].GetInitialPosition());
328 center_coord /=
static_cast<double>(geom.
size());
333 int num_nodes_found = 0;
335 num_nodes_found = MyTree.
SearchInRadius(ElemPositionItem,mSearchRadius,Results.begin(),resulting_squared_distances.begin(),mMaxElementsAffected);
343 double distance = 0.0;
345 double beta_max = 150;
349 for(
int ElementPositionItem_j = 0; ElementPositionItem_j < num_nodes_found; ElementPositionItem_j++)
353 elemental_distance = *Results[ElementPositionItem_j] - center_coord;
354 distance = std::sqrt(
inner_prod(elemental_distance,elemental_distance));
358 Hxdx =
H*(Results[ElementPositionItem_j]->GetOriginElement()->GetValue(X_PHYS));
367 x_try = Hxdx_sum / (H_sum);
368 double beta =
std::min(beta_max,beta_0*pow(2,((Opt_iter-1)/
tau)));
369 x_phys_filtered[
i++]= ((std::tanh(beta*
nu)+std::tanh(beta*(x_try-
nu)))/(std::tanh(beta*
nu)+std::tanh(beta*(1-
nu))));
374 for(ModelPart::ElementsContainerType::iterator elem_i = mrModelPart.
ElementsBegin();
376 elem_i->SetValue(X_PHYS, x_phys_filtered[
i++]);
378 KRATOS_INFO(
"[TopOpt]") <<
" Filtered densities calculated [ spent time = " <<
timer.ElapsedSeconds() <<
" ] " << std::endl;
381 KRATOS_ERROR <<
"No valid FilterType selected for the simulation. Selected one: " << FilterType << std::endl;
403 virtual std::string
Info()
const
405 return "TopologyFilteringUtilities";
411 rOStream <<
"TopologyFilteringUtilities";
474 const double mSearchRadius;
475 const int mMaxElementsAffected;
Short class definition.
Definition: bucket.h:57
Definition: builtin_timer.h:26
double ElapsedSeconds() const
Definition: builtin_timer.h:40
Short class definition.
Definition: filter_function.h:37
double ComputeWeight(const Array3DType &ICoord, const Array3DType &JCoord, const double Radius) const
Definition: filter_function.cpp:63
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
Point class.
Definition: point.h:59
Definition: topology_filtering_utilities.h:72
ElementPositionItem()
Definition: topology_filtering_utilities.h:77
Element::Pointer GetOriginElement()
Definition: topology_filtering_utilities.h:88
ElementPositionItem(array_1d< double, 3 > Coords, Element::Pointer pElement)
Definition: topology_filtering_utilities.h:83
KRATOS_CLASS_POINTER_DEFINITION(ElementPositionItem)
Solution utility to filter results.
Definition: topology_filtering_utilities.h:65
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: topology_filtering_utilities.h:110
KRATOS_CLASS_POINTER_DEFINITION(TopologyFilteringUtilities)
Pointer definition of TopologyFilteringUtilities.
Tree< KDTreePartition< BucketType > > tree
Definition: topology_filtering_utilities.h:121
TopologyFilteringUtilities(ModelPart &model_part, const double SearchRadius, const int MaxElementsAffected)
Default constructor.
Definition: topology_filtering_utilities.h:131
ModelPart::NodesContainerType NodesContainerType
Definition: topology_filtering_utilities.h:107
ModelPart::ElementsContainerType ElementsArrayType
Definition: topology_filtering_utilities.h:104
Bucket< 3ul, PointType, ElementPositionVector, PointTypePointer, ElementPositionIterator, DistanceIterator > BucketType
Definition: topology_filtering_utilities.h:120
virtual std::string Info() const
Turn back information as a string.
Definition: topology_filtering_utilities.h:403
std::vector< PointType::Pointer >::iterator ElementPositionIterator
Definition: topology_filtering_utilities.h:116
ModelPart::NodeIterator NodeIterator
Definition: topology_filtering_utilities.h:109
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: topology_filtering_utilities.h:415
std::vector< double >::iterator DistanceIterator
Definition: topology_filtering_utilities.h:118
ModelPart::ElementIterator ElementIterator
Definition: topology_filtering_utilities.h:105
ElementPositionItem::Pointer PointTypePointer
Definition: topology_filtering_utilities.h:114
ModelPart::NodesContainerType NodesArrayType
Definition: topology_filtering_utilities.h:108
ElementPositionItem PointType
Definition: topology_filtering_utilities.h:113
virtual ~TopologyFilteringUtilities()
Destructor.
Definition: topology_filtering_utilities.h:139
std::vector< double > DistanceVector
Definition: topology_filtering_utilities.h:117
ModelPart::ElementsContainerType ElementsContainerType
Definition: topology_filtering_utilities.h:103
void ApplyFilterSensitivity(char FilterType[], char FilterFunctionType[])
With the calculated sensitivities, an additional filter to avoid checkerboard effects is used here.
Definition: topology_filtering_utilities.h:158
void ApplyFilterDensity(char FilterType[], char FilterFunctionType[], int Opt_iter)
Definition: topology_filtering_utilities.h:268
std::vector< PointType::Pointer > ElementPositionVector
Definition: topology_filtering_utilities.h:115
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: topology_filtering_utilities.h:409
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
SizeType SearchInRadius(PointType const &ThisPoint, CoordinateType Radius, IteratorType Results, DistanceIteratorType ResultsDistances, SizeType MaxNumberOfResults)
Search for points within a given radius of a point.
Definition: tree.h:434
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_INFO(label)
Definition: logger.h:250
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
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
tau
Definition: generate_convection_diffusion_explicit_element.py:115
H
Definition: generate_droplet_dynamics.py:257
nu
Definition: isotropic_damage_automatic_differentiation.py:135
integer i
Definition: TensorModule.f:17