Skip to content

Commit

Permalink
Merge pull request #12297 from KratosMultiphysics/feature/voxel-mesh-…
Browse files Browse the repository at this point in the history
…modeler

[Core] Add Voxel Mesh Generation Modeler
  • Loading branch information
jcotela authored May 16, 2024
2 parents 407368d + 5542da6 commit 94a3e3b
Show file tree
Hide file tree
Showing 68 changed files with 7,831 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kratos/includes/kratos_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "modeler/serial_model_part_combinator_modeler.h"
#include "modeler/combine_model_part_modeler.h"
#include "modeler/connectivity_preserve_modeler.h"
#include "modeler/voxel_mesh_generator_modeler.h"

namespace Kratos {
///@name Kratos Classes
Expand Down Expand Up @@ -495,6 +496,7 @@ class KRATOS_API(KRATOS_CORE) KratosApplication {
const SerialModelPartCombinatorModeler mSerialModelPartCombinatorModeler;
const CombineModelPartModeler mCombineModelPartModeler;
const ConnectivityPreserveModeler mConnectivityPreserveModeler;
const VoxelMeshGeneratorModeler mVoxelMeshGeneratorModeler;

// Base constitutive law definition
const ConstitutiveLaw mConstitutiveLaw;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Pooyan Dadvand
//

// System includes

// External includes

// Project includes
#include "geometries/geometry.h"
#include "color_and_intersect_with_cells_in_touch.h"

namespace Kratos {

ColorAndIntersectWithCellsInTouch::ColorAndIntersectWithCellsInTouch(VoxelMeshGeneratorModeler& rModeler, Parameters ColoringParameters):
VoxelMesherColoring(rModeler, ColoringParameters)
{}


void ColorAndIntersectWithCellsInTouch::Apply() const
{
auto parameters = GetParameters();
auto& r_model_part = GetModelPart(parameters["model_part_name"].GetString());

const int inside_color = parameters["color"].GetInt();
const std::string input_entities = parameters["input_entities"].GetString();

auto& r_skin_intersections = GetIntersections(inside_color);

if (input_entities == "elements") {
for(auto& r_geometrical_object : r_model_part.Elements()) {
auto& r_geometry = r_geometrical_object.GetGeometry();
CheckGeometryType(r_geometry.GetGeometryType());
ApplyColorToCellsInTouchWithGeometryAndComputeIntersection(r_geometry, inside_color, r_skin_intersections);
}
} else if(input_entities == "conditions") {
for(auto& r_geometrical_object : r_model_part.Conditions()) {
auto& r_geometry = r_geometrical_object.GetGeometry();
CheckGeometryType(r_geometry.GetGeometryType());
ApplyColorToCellsInTouchWithGeometryAndComputeIntersection(r_geometry, inside_color, r_skin_intersections);
}
} else if(input_entities == "geometries") {
for(auto& r_geometry : r_model_part.Geometries()) {
CheckGeometryType(r_geometry.GetGeometryType());
ApplyColorToCellsInTouchWithGeometryAndComputeIntersection(r_geometry, inside_color, r_skin_intersections);
}
} else {
KRATOS_ERROR << "The input_entities " << parameters["input_entities"] << " is not supported. The supported input_entities are elements and conditions" << std::endl;
}
}


Parameters ColorAndIntersectWithCellsInTouch::GetDefaultParameters() const {
return Parameters(R"({
"type" : "Undefined_coloring_type",
"model_part_name": "Undefined",
"color": -1,
"cell_color": -1,
"input_entities": "elements",
"outside_color": 0
})");
}


void ColorAndIntersectWithCellsInTouch::ApplyColorToCellsInTouchWithGeometryAndComputeIntersection(
const Element::GeometryType& rGeometry,
int InsideColor,
Internals::SkinIntersection& rSkinIntersection) const
{
auto& r_colors = GetMeshColors();

auto p_work_geometry = rSkinIntersection.ConvertToWorkGeometry(rGeometry);
array_1d<std::size_t, 3> min_position(3,0);
array_1d<std::size_t, 3> max_position(3,0);
r_colors.CalculateOuterMinMaxNodePositions(rGeometry, min_position, max_position);
for(std::size_t k = min_position[2] ; k < max_position[2] ; k++){
for(std::size_t j = min_position[1] ; j < max_position[1] ; j++){
for(std::size_t i = min_position[0] ; i < max_position[0] ; i++){
Point cell_min_point = r_colors.GetPoint(i,j,k);
Point cell_max_point = r_colors.GetPoint(i+1,j+1,k+1);
if(rGeometry.HasIntersection(cell_min_point,cell_max_point)){
r_colors.GetElementalColor(i,j,k) = InsideColor;

rSkinIntersection.ComputeCutInsideCell(p_work_geometry, cell_min_point, cell_max_point, i, j, k);
}
}
}
}
}

}
45 changes: 45 additions & 0 deletions kratos/modeler/coloring/color_and_intersect_with_cells_in_touch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Pooyan Dadvand
//

#pragma once

// System includes

// External includes

// Project includes
#include "geometries/geometry.h"
#include "voxel_mesher_coloring.h"

namespace Kratos {

class ColorAndIntersectWithCellsInTouch: public VoxelMesherColoring {

public:
ColorAndIntersectWithCellsInTouch(VoxelMeshGeneratorModeler& rModeler, Parameters ColoringParameters);

~ColorAndIntersectWithCellsInTouch() override = default;

void Apply() const override;

Parameters GetDefaultParameters() const override;

private:

void ApplyColorToCellsInTouchWithGeometryAndComputeIntersection(
const Geometry<Node>& rGeometry,
int InsideColor,
Internals::SkinIntersection& rSkinIntersection) const;

};

}
67 changes: 67 additions & 0 deletions kratos/modeler/coloring/color_cell_faces.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Pooyan Dadvand
//

// System includes

// External includes

// Project includes
#include "geometries/geometry.h"
#include "color_cell_faces.h"

namespace Kratos {

ColorCellFaces::ColorCellFaces(VoxelMeshGeneratorModeler& rModeler, Parameters ColoringParameters):
VoxelMesherColoring(rModeler, ColoringParameters)
{}


void ColorCellFaces::Apply() const
{
auto parameters = GetParameters();
auto& r_model_part = GetModelPart(parameters["model_part_name"].GetString());
CartesianMeshColors& r_colors = GetMeshColors();

const int outside_color = parameters["outside_color"].GetInt();
const int interface_color = parameters["color"].GetInt();
const int cell_color = parameters["cell_color"].GetInt();
const std::string input_entities = parameters["input_entities"].GetString();

array_1d< std::size_t, 3 > min_ray_position{0, 0, 0};
array_1d< std::size_t, 3 > max_ray_position{0, 0, 0};

r_colors.CalculateMinMaxCenterOfElementPositions(r_model_part.Nodes(), min_ray_position, max_ray_position);
r_colors.InitializeRays(min_ray_position, max_ray_position, "center_of_elements");

if(input_entities == "elements") {
for(auto& element : r_model_part.Elements()) {
Element::GeometryType& r_geometry = element.GetGeometry();
CheckGeometryType(r_geometry.GetGeometryType());
r_colors.AddGeometry(r_geometry, false);
}
} else if(input_entities == "conditions") {
for(auto& condition : r_model_part.Conditions()) {
auto& r_geometry = condition.GetGeometry();
CheckGeometryType(r_geometry.GetGeometryType());
r_colors.AddGeometry(r_geometry, false);
}
} else if(input_entities == "geometries") {
for(auto& r_geometry : r_model_part.Geometries()) {
CheckGeometryType(r_geometry.GetGeometryType());
r_colors.AddGeometry(r_geometry, false);
}
}

r_colors.CalculateElementalFaceColors(min_ray_position, max_ray_position, interface_color, outside_color, cell_color);
}

}
35 changes: 35 additions & 0 deletions kratos/modeler/coloring/color_cell_faces.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Pooyan Dadvand
//

#pragma once

// System includes

// External includes

// Project includes
#include "voxel_mesher_coloring.h"

namespace Kratos {

class ColorCellFaces: public VoxelMesherColoring {

public:
ColorCellFaces(VoxelMeshGeneratorModeler& rModeler, Parameters ColoringParameters);

~ColorCellFaces() override = default;

void Apply() const override;

};

}
38 changes: 38 additions & 0 deletions kratos/modeler/coloring/color_cell_faces_between_colors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Pooyan Dadvand
//

// System includes

// External includes

// Project includes
#include "geometries/geometry.h"
#include "color_cell_faces_between_colors.h"

namespace Kratos {

ColorCellFacesBetweenColors::ColorCellFacesBetweenColors(VoxelMeshGeneratorModeler& rModeler, Parameters ColoringParameters):
VoxelMesherColoring(rModeler, ColoringParameters)
{}


void ColorCellFacesBetweenColors::Apply() const
{
Parameters parameters = GetParameters();
const int outside_color = parameters["outside_color"].GetInt();
const int interface_color = parameters["color"].GetInt();
const int cell_color = parameters["cell_color"].GetInt();

GetMeshColors().CalculateElementalFaceColorsBetweenColors(interface_color, outside_color, cell_color);
}

}
34 changes: 34 additions & 0 deletions kratos/modeler/coloring/color_cell_faces_between_colors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Pooyan Dadvand
//

#pragma once

// System includes

// External includes

// Project includes
#include "voxel_mesher_coloring.h"

namespace Kratos {

class ColorCellFacesBetweenColors: public VoxelMesherColoring {

public:
ColorCellFacesBetweenColors(VoxelMeshGeneratorModeler& rModeler, Parameters ColoringParameters);

~ColorCellFacesBetweenColors() override = default;

void Apply() const override;
};

}
Loading

0 comments on commit 94a3e3b

Please sign in to comment.