Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds sphere test case #20

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
13 changes: 4 additions & 9 deletions src/app/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,14 @@ Mesh readMesh(const std::string &fn)
std::filesystem::path objPathFromInput = j["object"]["filename"];
std::filesystem::path meshObjectPath = caseFolder / objPathFromInput;

std::cout << "Reading mesh groups from: " << meshObjectPath;
std::cout << "-- Reading mesh groups from: " << meshObjectPath;
Mesh res = vtkIO::readMeshGroups(meshObjectPath);
std::cout << "....... [OK]" << std::endl;

std::cout << "Reading grid from input file";
std::cout << "-- Reading grid from input file";
res.grid = parseGridFromJSON(j["grid"]);
std::cout << "....... [OK]" << std::endl;

std::cout << "Grid has "
<< res.grid[0].size()-1 << "x"
<< res.grid[1].size()-1 << "x"
<< res.grid[2].size()-1 << " cells" << std::endl;

return res;
}

Expand All @@ -83,7 +78,7 @@ int launcher(int argc, const char* argv[])

// Input
std::string inputFilename = vm["input"].as<std::string>();
std::cout << "Input file is: " << inputFilename << std::endl;
std::cout << "-- Input file is: " << inputFilename << std::endl;

Mesh mesh = readMesh(inputFilename);

Expand All @@ -97,7 +92,7 @@ int launcher(int argc, const char* argv[])

std::filesystem::path outputFolder = std::filesystem::path(inputFilename).parent_path();
auto basename = std::filesystem::path(inputFilename).stem().stem().string();
meshlib::vtkIO::exportMeshToVTP(outputFolder / (basename + ".tessellator.out.vtp"), resultMesh);
meshlib::vtkIO::exportMeshToVTP(outputFolder / (basename + ".tessellator.str.vtp"), resultMesh);
meshlib::vtkIO::exportGridToVTP(outputFolder / (basename + ".tessellator.grid.vtp"), resultMesh.grid);

return EXIT_SUCCESS;
Expand Down
7 changes: 5 additions & 2 deletions src/meshers/MesherBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ void MesherBase::logGridSize(const Grid& g)
log(msg.str(), 2);
}

MesherBase::MesherBase(const Mesh& inputMesh) : originalGrid_{inputMesh.grid}{

MesherBase::MesherBase(const Mesh& inputMesh) : originalGrid_{inputMesh.grid}
{
log("Input mesh information.", 1);
logGridSize(inputMesh.grid);
logNumberOfTriangles(countMeshElementsIf(inputMesh, isTriangle));

log("Building enlarged grid.", 1);
enlargedGrid_ = getEnlargedGridIncludingAllElements(inputMesh);
logGridSize(inputMesh.grid);
}

Mesh MesherBase::buildSurfaceMesh(const Mesh& inputMesh) {
Expand Down
38 changes: 18 additions & 20 deletions src/meshers/StructuredMesher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ using namespace core;
using namespace meshTools;


Mesh StructuredMesher::buildSurfaceMesh(const Mesh& inputMesh, const Mesh & volumeSurface)
{
auto resultMesh = MesherBase::buildSurfaceMesh(inputMesh);
mergeMesh(resultMesh, volumeSurface);
return resultMesh;
}


StructuredMesher::StructuredMesher(const Mesh& inputMesh, int decimalPlacesInCollapser) :
MesherBase(inputMesh),
Expand All @@ -34,8 +29,15 @@ StructuredMesher::StructuredMesher(const Mesh& inputMesh, int decimalPlacesInCol

log("Processing surface mesh.");
process(surfaceMesh_);

log("Surface mesh built succesfully.", 1);
}

log("Initial hull mesh built succesfully.");
Mesh StructuredMesher::buildSurfaceMesh(const Mesh& inputMesh, const Mesh & volumeSurface)
{
auto resultMesh = MesherBase::buildSurfaceMesh(inputMesh);
mergeMesh(resultMesh, volumeSurface);
return resultMesh;
}

void StructuredMesher::process(Mesh& mesh) const
Expand Down Expand Up @@ -65,28 +67,24 @@ void StructuredMesher::process(Mesh& mesh) const
logNumberOfQuads(countMeshElementsIf(mesh, isQuad));
logNumberOfLines(countMeshElementsIf(mesh, isLine));


log("Removing repeated elements.", 1);
Cleaner::removeRepeatedElements(mesh);

logNumberOfQuads(countMeshElementsIf(mesh, isQuad));
logNumberOfLines(countMeshElementsIf(mesh, isLine));

log("Recovering original grid size.", 1);
reduceGrid(mesh, originalGrid_);

logNumberOfQuads(countMeshElementsIf(mesh, isQuad));
logNumberOfLines(countMeshElementsIf(mesh, isLine));

}


Mesh StructuredMesher::mesh() const
{
log("Building primal mesh.");
Mesh resultMesh{ surfaceMesh_ };

logNumberOfQuads(countMeshElementsIf(resultMesh, isQuad));
logNumberOfLines(countMeshElementsIf(resultMesh, isLine));
logNumberOfNodes(countMeshElementsIf(resultMesh, isNode));

reduceGrid(resultMesh, originalGrid_);
Cleaner::cleanCoords(resultMesh);

log("Primal mesh built succesfully.", 1);
return resultMesh;
return surfaceMesh_;
}

}
12 changes: 11 additions & 1 deletion test/app/launcherTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ TEST_F(LauncherTest, prints_help)
TEST_F(LauncherTest, launches_alhambra_case)
{
int ac = 3;
const char* av[] = { NULL, "-i", "testData/cases/alhambra.tessellator.json"};
const char* av[] = { NULL, "-i", "testData/cases/alhambra/alhambra.tessellator.json"};
int exitCode;
EXPECT_NO_THROW(exitCode = meshlib::app::launcher(ac, av));
EXPECT_EQ(exitCode, EXIT_SUCCESS);
}


TEST_F(LauncherTest, launches_sphere_case)
{
int ac = 3;
const char* av[] = { NULL, "-i", "testData/cases/sphere/sphere.tessellator.json"};
int exitCode;
EXPECT_NO_THROW(exitCode = meshlib::app::launcher(ac, av));
EXPECT_EQ(exitCode, EXIT_SUCCESS);
}
2 changes: 1 addition & 1 deletion testData/cases/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*tessellator.out.vtp
*tessellator.str.vtp
*tessellator.grid.vtp
File renamed without changes.
Binary file added testData/cases/sphere/sphere.stl
Binary file not shown.
10 changes: 10 additions & 0 deletions testData/cases/sphere/sphere.tessellator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"grid": {
"numberOfCells": [100, 100, 100],
"boundingBox": [
[-100.0, -100.0, -100.0],
[ 100.0, 100.0, 100.0]
]
},
"object": {"filename": "sphere.stl"}
}
Loading