Skip to content

Commit

Permalink
Merge pull request #11297 from KratosMultiphysics/optapp/explicit_ver…
Browse files Browse the repository at this point in the history
…tex_morphing_new

[OptApp] Adding explicit vertex morphing
  • Loading branch information
sunethwarna authored Jul 6, 2023
2 parents 2c9d815 + 0e76405 commit 425667f
Show file tree
Hide file tree
Showing 11 changed files with 940 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// license: OptimizationApplication/license.txt
//
// Main author: Suneth Warnakulasuriya
//

// System includes

// External includes

// Project includes

// Application includes
#include "custom_utilities/filtering/explicit_vertex_morphing_filter.h"

// Include base h
#include "add_custom_filters_to_python.h"

namespace Kratos {
namespace Python {

namespace Detail
{

template <class TContainerType>
void AddExplicitVertexMorphingFilter(
pybind11::module& m,
const std::string& rName)
{
namespace py = pybind11;

py::class_<ExplicitVertexMorphingFilter<TContainerType>, typename ExplicitVertexMorphingFilter<TContainerType>::Pointer>(m, rName.c_str())
.def(py::init<const ModelPart&, const std::string&, const std::size_t>(), py::arg("model_part"), py::arg("kernel_function_type"), py::arg("max_number_of_neighbours"))
.def("SetFilterRadius", &ExplicitVertexMorphingFilter<TContainerType>::SetFilterRadius, py::arg("filter_radius"))
.def("FilterField", &ExplicitVertexMorphingFilter<TContainerType>::FilterField, py::arg("unfiltered_field"))
.def("FilterIntegratedField", &ExplicitVertexMorphingFilter<TContainerType>::FilterIntegratedField, py::arg("filtered_field"))
.def("Update", &ExplicitVertexMorphingFilter<TContainerType>::Update)
.def("__str__", &ExplicitVertexMorphingFilter<TContainerType>::Info)
;
}

} // namespace Detail

void AddCustomFiltersToPython(pybind11::module& m)
{
Detail::AddExplicitVertexMorphingFilter<ModelPart::NodesContainerType>(m, "NodalExplicitVertexMorphingFilter");
Detail::AddExplicitVertexMorphingFilter<ModelPart::ConditionsContainerType>(m, "ConditionExplicitVertexMorphingFilter");
Detail::AddExplicitVertexMorphingFilter<ModelPart::ElementsContainerType>(m, "ElementExplicitVertexMorphingFilter");

}

} // namespace Python.
} // namespace Kratos.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// license: OptimizationApplication/license.txt
//
// Main author: Suneth Warnakulasuriya
//

#pragma once

// System includes

// External includes

// Project includes
#include "includes/define_python.h"

namespace Kratos {
namespace Python {

void AddCustomFiltersToPython(pybind11::module& m);

} // namespace Python.
} // namespace Kratos.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "custom_python/add_custom_response_utilities_to_python.h"
#include "custom_python/add_custom_utilities_to_python.h"
#include "custom_python/add_custom_constitutive_laws_to_python.h"
#include "custom_python/add_custom_filters_to_python.h"
#include "custom_python/add_custom_control_utilities_to_python.h"

// ==============================================================================
Expand All @@ -57,6 +58,7 @@ PYBIND11_MODULE(KratosOptimizationApplication, m)
AddCustomStrategiesToPython(m);
AddCustomUtilitiesToPython(m);
AddCustomConstitutiveLawsToPython(m);
AddCustomFiltersToPython(m);

auto response_utils = m.def_submodule("ResponseUtils");
AddCustomResponseUtilitiesToPython(response_utils);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// license: OptimizationApplication/license.txt
//
// Main author: Suneth Warnakulasuriya
//

// System includes

// Project includes
#include "includes/define.h"
#include "geometries/point.h"
#include "includes/model_part.h"

// Application includes

// Include base h
#include "entity_point.h"

namespace Kratos {

template<class TEntityType>
EntityPoint<TEntityType>::EntityPoint(
const TEntityType& rEntity,
const IndexType Id)
: Point(GetPoint(rEntity)),
mId(Id),
mpEntity(&rEntity)
{
}

template<class TEntityType>
IndexType EntityPoint<TEntityType>::Id() const
{
return mId;
}

template<class TEntityType>
const TEntityType& EntityPoint<TEntityType>::GetEntity() const
{
return *mpEntity;
}

template<class TEntityType>
Point EntityPoint<TEntityType>::GetPoint(const TEntityType& rEntity)
{
if constexpr(std::is_same_v<TEntityType, ModelPart::NodeType>) {
return rEntity;
} else {
return rEntity.GetGeometry().Center();
}
}

//template instantiations
template class EntityPoint<ModelPart::NodeType>;
template class EntityPoint<ModelPart::ConditionType>;
template class EntityPoint<ModelPart::ElementType>;

} // namespace Kratos
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// license: OptimizationApplication/license.txt
//
// Main author: Suneth Warnakulasuriya
//

#pragma once

// System includes

// Project includes
#include "includes/define.h"
#include "geometries/point.h"

// Application includes

namespace Kratos {

///@name Kratos Classes
///@{

template<class TEntityType>
class KRATOS_API(OPTIMIZATION_APPLICATION) EntityPoint : public Point
{
public:
///@name Type definitions
///@{

using EntityType = TEntityType;

/// Pointer definition of ContainerData
KRATOS_CLASS_POINTER_DEFINITION(EntityPoint);

///@}
///@name Life cycle
///@{

EntityPoint() = default;

EntityPoint(
const TEntityType& rEntity,
const IndexType Id);

IndexType Id() const;

const TEntityType& GetEntity() const;

///@}
private:
///@name Private member variables
///@{

const IndexType mId = 0;

const TEntityType* mpEntity;

///@}
///@name Private static methods
///@{

static Point GetPoint(const TEntityType& rEntity);

///@}
};

///@}
} // namespace Kratos
Loading

0 comments on commit 425667f

Please sign in to comment.