Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void AddExplicitFilterUtils(
namespace py = pybind11;

py::class_<ExplicitFilterUtils<TContainerType>, typename ExplicitFilterUtils<TContainerType>::Pointer>(m, rName.c_str())
.def(py::init<const ModelPart&, const std::string&, const std::size_t, const std::size_t>(), py::arg("model_part"), py::arg("kernel_function_type"), py::arg("max_number_of_neighbours"), py::arg("echo_level"))
.def(py::init<const ModelPart&, const std::string&, const std::size_t, const std::size_t, bool>(), py::arg("model_part"), py::arg("kernel_function_type"), py::arg("max_number_of_neighbours"), py::arg("echo_level"), py::arg("node_cloud_mesh") = false)
.def("SetRadius", &ExplicitFilterUtils<TContainerType>::SetRadius, py::arg("filter_radius"))
.def("SetDamping", &ExplicitFilterUtils<TContainerType>::SetDamping, py::arg("damping"))
.def("ForwardFilterField", &ExplicitFilterUtils<TContainerType>::ForwardFilterField, py::arg("mesh_independent_control_space_field"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,27 @@ Expression::ConstPointer GetNodalDomainSizeExpression(
template<class TEntityType>
double GetDomainSize(
const EntityPoint<TEntityType>& rPoint,
Expression const * const pExpression)
Expression const * const pExpression,
const bool NodeCloudMesh)
{
if (NodeCloudMesh == true){
KRATOS_ERROR << "NodeCloudMesh == true can be used only with ModelPart::NodeType." << std::endl;
}
return rPoint.GetEntity().GetGeometry().DomainSize();
}

template<>
double GetDomainSize(
const EntityPoint<ModelPart::NodeType>& rPoint,
Expression const * const pExpression)
Expression const * const pExpression,
const bool NodeCloudMesh)
{
return pExpression->Evaluate(rPoint.Id(), rPoint.Id(), 0);
if (NodeCloudMesh == true){
return 1.0;
}
else{
return pExpression->Evaluate(rPoint.Id(), rPoint.Id(), 0);
}
}

struct MeshIndependentType
Expand Down Expand Up @@ -111,10 +121,11 @@ void ComputeWeightForAllNeighbors(
const std::vector<typename EntityPoint<TEntityType>::Pointer>& rNeighbourNodes,
const std::vector<double>& rSquaredDistances,
const IndexType NumberOfNeighbours,
Expression const * const pExpression)
Expression const * const pExpression,
const bool NodeCloudMesh)
{
for (IndexType i = 0; i < NumberOfNeighbours; ++i) {
const double domain_size = GetDomainSize(*rNeighbourNodes[i], pExpression);
const double domain_size = GetDomainSize(*rNeighbourNodes[i], pExpression, NodeCloudMesh);
const double filter_weight = rFilterFunction.ComputeWeight(Radius, std::sqrt(rSquaredDistances[i])) * domain_size;
rListOfWeights[i] = filter_weight;
rSumOfWeights += filter_weight;
Expand All @@ -128,10 +139,12 @@ ExplicitFilterUtils<TContainerType>::ExplicitFilterUtils(
const ModelPart& rModelPart,
const std::string& rKernelFunctionType,
const IndexType MaxNumberOfNeighbours,
const IndexType EchoLevel)
const IndexType EchoLevel,
const bool NodeCloudMesh)
: mrModelPart(rModelPart),
mMaxNumberOfNeighbors(MaxNumberOfNeighbours),
mEchoLevel(EchoLevel)
mEchoLevel(EchoLevel),
mNodeCloudMesh(NodeCloudMesh)
{
mpKernelFunction = Kratos::make_unique<FilterFunction>(rKernelFunctionType);
}
Expand Down Expand Up @@ -270,7 +283,7 @@ ContainerExpression<TContainerType> ExplicitFilterUtils<TContainerType>::Forward
double sum_of_weights = 0.0;
ExplicitFilterUtilsHelperUtilities::ComputeWeightForAllNeighbors(
sum_of_weights, rTLS.mListOfWeights, *mpKernelFunction, radius,
entity_point, rTLS.mNeighbourEntityPoints, rTLS.mResultingSquaredDistances, number_of_neighbors, this->mpNodalDomainSizeExpression.get());
entity_point, rTLS.mNeighbourEntityPoints, rTLS.mResultingSquaredDistances, number_of_neighbors, this->mpNodalDomainSizeExpression.get(), mNodeCloudMesh);

mpDamping->Apply(rTLS.mListOfDampedWeights, rTLS.mListOfWeights, Index, number_of_neighbors, rTLS.mNeighbourEntityPoints);

Expand Down Expand Up @@ -339,12 +352,12 @@ ContainerExpression<TContainerType> ExplicitFilterUtils<TContainerType>::Generic
double sum_of_weights = 0.0;
ExplicitFilterUtilsHelperUtilities::ComputeWeightForAllNeighbors(
sum_of_weights, rTLS.mListOfWeights, *mpKernelFunction, radius,
entity_point, rTLS.mNeighbourEntityPoints, rTLS.mResultingSquaredDistances, number_of_neighbors, this->mpNodalDomainSizeExpression.get());
entity_point, rTLS.mNeighbourEntityPoints, rTLS.mResultingSquaredDistances, number_of_neighbors, this->mpNodalDomainSizeExpression.get(), mNodeCloudMesh);

mpDamping->Apply(rTLS.mListOfDampedWeights, rTLS.mListOfWeights, Index, number_of_neighbors, rTLS.mNeighbourEntityPoints);

const IndexType current_data_begin = Index * stride;
const double domain_size = ExplicitFilterUtilsHelperUtilities::GetDomainSize(entity_point, mpNodalDomainSizeExpression.get());
const double domain_size = ExplicitFilterUtilsHelperUtilities::GetDomainSize(entity_point, mpNodalDomainSizeExpression.get(), mNodeCloudMesh);

for (IndexType j = 0; j < stride; ++j) {
const auto& r_damped_weights = rTLS.mListOfDampedWeights[j];
Expand Down Expand Up @@ -394,7 +407,7 @@ void ExplicitFilterUtils<TContainerType>::GetIntegrationWeights(ContainerExpress

IndexPartition<IndexType>(r_container.size()).for_each([&](const IndexType Index){
const EntityPoint<EntityType> entity(*(r_container.begin() + Index), Index);
const auto integration_weight = ExplicitFilterUtilsHelperUtilities::GetDomainSize(entity, this->mpNodalDomainSizeExpression.get());
const auto integration_weight = ExplicitFilterUtilsHelperUtilities::GetDomainSize(entity, this->mpNodalDomainSizeExpression.get(), mNodeCloudMesh);
const IndexType current_data_begin = Index * stride;
for (IndexType j = 0; j < stride; ++j) {
double& current_index_value = *(p_expression->begin() + current_data_begin + j);
Expand Down Expand Up @@ -458,7 +471,7 @@ void ExplicitFilterUtils<TContainerType>::CalculateMatrix(Matrix& rOutput) const
double sum_of_weights = 0.0;
ExplicitFilterUtilsHelperUtilities::ComputeWeightForAllNeighbors(
sum_of_weights, list_of_weights, *mpKernelFunction, radius,
*mEntityPointVector[Index], rTLS.mNeighbourEntityPoints, rTLS.mResultingSquaredDistances, number_of_neighbors, this->mpNodalDomainSizeExpression.get());
*mEntityPointVector[Index], rTLS.mNeighbourEntityPoints, rTLS.mResultingSquaredDistances, number_of_neighbors, this->mpNodalDomainSizeExpression.get(), mNodeCloudMesh);

double* data_begin = (rOutput.data().begin() + Index * number_of_entities);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class KRATOS_API(OPTIMIZATION_APPLICATION) ExplicitFilterUtils
const ModelPart& rModelPart,
const std::string& rKernelFunctionType,
const IndexType MaxNumberOfNeighbours,
const IndexType EchoLevel);
const IndexType EchoLevel,
const bool NodeCloudMesh);

///@}
///@name Public operations
Expand Down Expand Up @@ -160,6 +161,8 @@ class KRATOS_API(OPTIMIZATION_APPLICATION) ExplicitFilterUtils

typename KDTree::Pointer mpSearchTree;

bool mNodeCloudMesh;

///@}
///@name Private operations
///@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ExplicitFilter(Filter):
def GetDefaultParameters(cls) -> Kratos.Parameters:
return Kratos.Parameters("""{
"filter_type" : "explicit_filter",
"node_cloud_mesh" : false,
"filter_function_type" : "linear",
"max_nodes_in_filter_radius": 100000,
"echo_level" : 0,
Expand Down Expand Up @@ -67,11 +68,16 @@ def Initialize(self) -> None:
filter_function_type = self.parameters["filter_function_type"].GetString()
max_nodes_in_filter_radius = self.parameters["max_nodes_in_filter_radius"].GetInt()
echo_level = self.parameters["echo_level"].GetInt()
node_cloud_mesh = self.parameters["node_cloud_mesh"].GetBool()
if self.data_location in [Kratos.Globals.DataLocation.NodeHistorical, Kratos.Globals.DataLocation.NodeNonHistorical]:
self.filter_utils = KratosOA.NodeExplicitFilterUtils(self.model_part, filter_function_type, max_nodes_in_filter_radius, echo_level)
self.filter_utils = KratosOA.NodeExplicitFilterUtils(self.model_part, filter_function_type, max_nodes_in_filter_radius, echo_level, node_cloud_mesh)
elif self.data_location == Kratos.Globals.DataLocation.Condition:
if node_cloud_mesh == True:
raise RuntimeError("You need to have elements to filter variables as conditions.")
self.filter_utils = KratosOA.ConditionExplicitFilterUtils(self.model_part, filter_function_type, max_nodes_in_filter_radius, echo_level)
elif self.data_location == Kratos.Globals.DataLocation.Element:
if node_cloud_mesh == True:
raise RuntimeError("You need to have elements to filter variables as conditions.")
self.filter_utils = KratosOA.ElementExplicitFilterUtils(self.model_part, filter_function_type, max_nodes_in_filter_radius, echo_level)

self.Update()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfPoints="57" NumberOfCells="85">
<Points>
<DataArray type="Float64" Name="Position" NumberOfComponents="3" format="ascii">
-5.000000e-01 -5.000000e-01 0.000000e+00 -2.929923e-01 -5.000000e-01 0.000000e+00 -5.000000e-01 -3.201494e-01 9.462072e-02 -2.662187e-01 -3.738052e-01 4.520345e-02 -3.192065e-01 -2.389770e-01 2.114700e-01 -7.137459e-02 -5.000000e-01 0.000000e+00 -5.000000e-01 -1.504873e-01 3.076450e-01 -1.318939e-01 -2.274113e-01 2.152750e-01 -1.869972e-02 -3.703914e-01 4.673946e-02 -2.886095e-01 -8.288689e-02 3.382304e-01 1.393438e-01 -5.000000e-01 0.000000e+00 -5.000000e-01 7.202739e-02 3.462325e-01 8.988429e-02 -2.141406e-01 1.911282e-01 -1.745100e-02 -4.697009e-02 3.206695e-01 1.942056e-01 -3.616797e-01 4.286300e-02 -1.913550e-01 1.345223e-01 3.243611e-01 -5.000000e-01 2.507794e-01 3.388251e-01 -3.362954e-01 2.603596e-01 3.360584e-01 3.512003e-01 -5.000000e-01 0.000000e+00 1.973595e-01 -3.297214e-02 2.360385e-01 3.003216e-01 -1.974321e-01 1.243422e-01 6.818244e-02 1.519563e-01 2.913132e-01 -1.839958e-01 3.003445e-01 3.156089e-01 4.025091e-01 -3.524456e-01 3.702279e-02 -6.068592e-02 2.811153e-01 3.056838e-01 -5.000000e-01 3.889778e-01 3.390485e-01 -3.962334e-01 4.022558e-01 3.340615e-01 -2.313558e-01 4.025169e-01 3.216266e-01 5.204180e-02 3.047941e-01 2.865577e-01 3.945260e-01 -2.505335e-02 7.126845e-02 -1.176785e-01 4.027081e-01 3.077951e-01 3.140964e-01 1.345393e-01 1.277096e-01 1.556782e-01 2.827242e-01 2.426690e-01 5.526046e-01 -5.000000e-01 0.000000e+00 -5.000000e-01 5.000000e-01 3.355202e-01 -3.973838e-01 5.000000e-01 3.275357e-01 -4.767212e-03 4.030576e-01 2.859749e-01 -2.877968e-01 5.000000e-01 3.197776e-01 5.612722e-01 -3.065697e-01 0.000000e+00 -1.737573e-01 5.000000e-01 3.036881e-01 1.004235e-01 4.031141e-01 2.669496e-01 2.787259e-01 2.985828e-01 1.580002e-01 -6.309599e-02 5.000000e-01 2.943479e-01 5.683802e-01 -1.137751e-01 0.000000e+00 2.064581e-01 4.032120e-01 2.118134e-01 4.809829e-02 5.000000e-01 2.769805e-01 4.095707e-01 2.663091e-01 4.846368e-02 1.531911e-01 5.000000e-01 2.364388e-01 5.700729e-01 9.241886e-02 0.000000e+00 3.111695e-01 4.035230e-01 1.213958e-01 2.557911e-01 5.000000e-01 1.651439e-01 5.689338e-01 2.574772e-01 0.000000e+00 4.642457e-01 4.031836e-01 1.991678e-02 3.610078e-01 5.000000e-01 7.837617e-02 5.670536e-01 3.903282e-01 0.000000e+00 4.636742e-01 5.000000e-01 1.820048e-02 5.655497e-01 5.000000e-01 0.000000e+00
</DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" NumberOfComponents="1" format="ascii">
56 55 52 47 45 40 37 35 26 53 50 49 42 39 30 55 53 52 45 42 36 26 34 25 50 47 44 39 37 27 40 45 36 40 36 28 49 50 44 49 44 41 52 53 49 52 49 46 44 47 40 44 40 32 26 35 34 30 39 27 30 27 22 36 42 30 36 30 24 27 37 26 27 26 17 56 52 54 28 36 24 28 24 21 46 49 41 46 41 31 22 27 17 22 17 15 17 26 16 41 44 32 41 32 31 32 40 28 32 28 21 24 30 22 24 22 15 52 46 51 51 54 52 25 16 26 21 24 15 15 17 11 46 31 48 48 51 46 16 11 17 43 48 29 11 6 9 29 48 31 29 31 19 19 31 21 29 19 20 20 19 12 29 20 43 12 19 13 20 12 14 13 19 21 13 21 15 12 13 7 14 12 8 20 14 23 9 6 4 7 13 9 8 12 7 23 14 18 23 18 33 11 9 15 15 9 13 14 8 10 14 10 18 20 23 43 4 6 2 9 4 7 7 4 3 3 4 2 7 3 8 8 3 5 8 5 10 5 3 1 0 3 2 0 1 3 33 38 23 23 38 43 31 32 21
</DataArray>
<DataArray type="Int32" Name="offsets" NumberOfComponents="1" format="ascii">
3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108 111 114 117 120 123 126 129 132 135 138 141 144 147 150 153 156 159 162 165 168 171 174 177 180 183 186 189 192 195 198 201 204 207 210 213 216 219 222 225 228 231 234 237 240 243 246 249 252 255
</DataArray>
<DataArray type="UInt8" Name="types" NumberOfComponents="1" format="ascii">
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
</DataArray>
</Cells>
<PointData/>
<CellData/>
</Piece>
</UnstructuredGrid>
</VTKFile>
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ def test_FilterQuartic(self):
def test_FilterSigmoidal(self):
self.__RunTestCase("sigmoidal", "cosine", "explicit_filter_reference_sigmoidal.vtu")

def __RunTestCase(self, filter_function_type: str, damping_function_type: str, ref_file: str) -> None:
def test_FilterSigmoidalNodeCloudMesh(self):
self.__RunTestCase("sigmoidal", "cosine", "explicit_filter_reference_sigmoidal_cloud_mesh.vtu", True)

def __RunTestCase(self, filter_function_type: str, damping_function_type: str, ref_file: str, node_cloud_mesh=False) -> None:
settings = Kratos.Parameters("""{
"filter_type" : "explicit_filter",
"filter_function_type" : "linear",
"max_nodes_in_filter_radius": 100000,
"node_cloud_mesh": false,
"echo_level" : 0,
"filter_radius_settings":{
"filter_radius_type": "constant",
Expand All @@ -234,6 +238,7 @@ def __RunTestCase(self, filter_function_type: str, damping_function_type: str, r
}""")
settings["filter_function_type"].SetString(filter_function_type)
settings["filtering_boundary_conditions"]["damping_function_type"].SetString(damping_function_type)
settings["node_cloud_mesh"].SetBool(node_cloud_mesh)
vm_filter = FilterFactory(self.model, "test", KratosOA.SHAPE, Kratos.Globals.DataLocation.NodeHistorical, settings)
vm_filter.SetComponentDataView(ComponentDataView("test", self.optimization_problem))
vm_filter.Initialize()
Expand Down