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

Launcher #17

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ if (TESSELLATOR_ENABLE_CGAL)
add_subdirectory(cgal)
endif()

add_subdirectory(app)
add_subdirectory(core)
add_subdirectory(drivers)
add_subdirectory(meshers)
add_subdirectory(app)
15 changes: 14 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ message(STATUS "Creating build system for tessellator-app")

add_library(tessellator-app
"vtkIO.cpp"
"launcher.cpp"
)

find_package(VTK COMPONENTS
Expand All @@ -11,6 +12,18 @@ find_package(VTK COMPONENTS
IOXML
)

find_package(Boost COMPONENTS program_options)

find_package(nlohmann_json)

target_link_libraries(tessellator-app
${VTK_LIBRARIES}
)
Boost::program_options
nlohmann_json::nlohmann_json
)

add_executable(tessellator
"tessellator.cpp"
)

target_link_libraries(tessellator tessellator-app tessellator-meshers)
16 changes: 0 additions & 16 deletions src/app/Launcher.h

This file was deleted.

83 changes: 83 additions & 0 deletions src/app/launcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "launcher.h"
#include "vtkIO.h"

#include "meshers/StructuredMesher.h"
#include "utils/GridTools.h"

#include <boost/program_options.hpp>
#include <nlohmann/json.hpp>

#include <iostream>
#include <filesystem>
#include <fstream>
#include <array>


namespace meshlib::app {

namespace po = boost::program_options;

Mesh readMesh(const std::string &fileName)
{
nlohmann::json j;
{
std::ifstream i(fileName);
i >> j;
}

Mesh res = vtkIO::readMesh(j["object"]);

auto g = j["grid"];
std::array<int,3> nCells = {
g["numberOfCells"][0],
g["numberOfCells"][1],
g["numberOfCells"][2]
};
std::array<double,3> min, max;
min = g["boundingBox"]["min"];
max = g["boundingBox"]["max"];

// res.grid = {
// GridTools::linspace(min[0], max[0], nCells[0]),
// GridTools::linspace(min[1], max[1], nCells[1]),
// GridTools::linspace(min[2], max[2], nCells[2])
// };
return res;
}

int launcher(int argc, char* argv[])
{
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("input,i", po::value<std::string>(), "input file");

po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(desc).run(), vm);
po::notify(vm);

if (vm.count("help") || !vm.count("input")) {
std::cout << desc << std::endl;
return EXIT_SUCCESS;
}

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

Mesh mesh = readMesh(inputFilename);

// Mesh
meshlib::meshers::StructuredMesher mesher{mesh,};
Mesh resultMesh = mesher.mesh();

// Output
std::string basename = std::filesystem::path(inputFilename).stem();
std::string outputFilename = basename + ".out.vtp";
meshlib::vtkIO::exportMeshToVTP(outputFilename, resultMesh);

return EXIT_SUCCESS;
}

}
9 changes: 9 additions & 0 deletions src/app/launcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "types/Mesh.h"

namespace meshlib::app {

int launcher(int argc, char* argv[]);

}
6 changes: 6 additions & 0 deletions src/app/tessellator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "launcher.h"

int main(int argc, char* argv[])
{
return meshlib::app::launcher(argc, argv);
}
1 change: 1 addition & 0 deletions src/app/vtkIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ namespace meshlib::vtkIO

void exportMeshToVTP(const std::string& fn, const Mesh& mesh);
void exportGridToVTP(const std::string& fn, const Grid& grid);

}
20 changes: 0 additions & 20 deletions src/drivers/CMakeLists.txt

This file was deleted.

17 changes: 0 additions & 17 deletions src/drivers/DriverInterface.h

This file was deleted.

20 changes: 20 additions & 0 deletions src/meshers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
message(STATUS "Creating build system for tessellator-meshers")

add_library(tessellator-meshers
"MesherBase.cpp"
"StructuredMesher.cpp"
)
target_link_libraries(tessellator-meshers tessellator-core tessellator-utils)

if (TESSELLATOR_ENABLE_CGAL)
target_sources(tessellator-meshers PRIVATE
"OffgridMesher.cpp"
)
target_link_libraries(tessellator-meshers tessellator-cgal)
endif()

if(TESSELLATOR_EXECUTION_POLICIES)
add_definitions(-DTESSELLATOR_EXECUTION_POLICIES)
find_package(TBB CONFIG REQUIRED)
target_link_libraries(tessellator-meshers TBB::tbb)
endif()
24 changes: 12 additions & 12 deletions src/drivers/DriverBase.cpp → src/meshers/MesherBase.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#include "DriverBase.h"
#include "MesherBase.h"

#include <iostream>

#include "utils/MeshTools.h"
#include "utils/GridTools.h"

namespace meshlib {
namespace drivers {
namespace meshers {


using namespace utils;
using namespace meshTools;


void DriverBase::log(const std::string& msg, std::size_t level)
void MesherBase::log(const std::string& msg, std::size_t level)
{
std::cout << "[Tessellator] ";
for (std::size_t i = 0; i < level; i++) {
Expand All @@ -23,56 +23,56 @@ void DriverBase::log(const std::string& msg, std::size_t level)
std::cout << msg << std::endl;
}

void DriverBase::logNumberOfQuads(std::size_t nQuads)
void MesherBase::logNumberOfQuads(std::size_t nQuads)
{
std::stringstream msg;
msg << "Mesh contains " << nQuads << " quads.";
log(msg.str(), 2);
}

void DriverBase::logNumberOfTriangles(std::size_t nTris)
void MesherBase::logNumberOfTriangles(std::size_t nTris)
{
std::stringstream msg;
msg << "Mesh contains " << nTris << " triangles.";
log(msg.str(), 2);
}

void DriverBase::logNumberOfLines(std::size_t nLines)
void MesherBase::logNumberOfLines(std::size_t nLines)
{
std::stringstream msg;
msg << "Mesh contains " << nLines << " lines.";
log(msg.str(), 2);
}


void DriverBase::logNumberOfNodes(std::size_t nNodes)
void MesherBase::logNumberOfNodes(std::size_t nNodes)
{
std::stringstream msg;
msg << "Mesh contains " << nNodes << " nodes.";
log(msg.str(), 2);
}

void DriverBase::logGridSize(const Grid& g)
void MesherBase::logGridSize(const Grid& g)
{
std::stringstream msg;
msg << "Grid size is "
<< g[0].size() - 1 << "x" << g[1].size() - 1 << "x" << g[2].size() - 1;
log(msg.str(), 2);
}

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

logGridSize(inputMesh.grid);
logNumberOfTriangles(countMeshElementsIf(inputMesh, isTriangle));

enlargedGrid_ = getEnlargedGridIncludingAllElements(inputMesh);
}

Mesh DriverBase::buildSurfaceMesh(const Mesh& inputMesh) {
Mesh MesherBase::buildSurfaceMesh(const Mesh& inputMesh) {
return buildMeshFilteringElements(inputMesh, isNotTetrahedron);
}

Grid DriverBase::buildNonSlicingGrid(const Grid& primal, const Grid& enlarged)
Grid MesherBase::buildNonSlicingGrid(const Grid& primal, const Grid& enlarged)
{
assert(primal.size() >= 2);
assert(enlarged.size() >= 2);
Expand All @@ -92,7 +92,7 @@ Grid DriverBase::buildNonSlicingGrid(const Grid& primal, const Grid& enlarged)
return resultGrid;
}

Grid DriverBase::buildSlicingGrid(const Grid& primal, const Grid& enlarged)
Grid MesherBase::buildSlicingGrid(const Grid& primal, const Grid& enlarged)
{
const auto nonSlicing{ buildNonSlicingGrid(primal, enlarged) };
Grid r;
Expand Down
9 changes: 4 additions & 5 deletions src/drivers/DriverBase.h → src/meshers/MesherBase.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#pragma once

#include "types/Mesh.h"
#include "DriverInterface.h"

namespace meshlib {
namespace drivers {
namespace meshers {

class DriverBase : public DriverInterface {
class MesherBase {
public:
DriverBase(const Mesh& in);
virtual ~DriverBase() = default;
MesherBase(const Mesh& in);
virtual ~MesherBase() = default;
virtual Mesh mesh() const = 0;

protected:
Expand Down
Loading
Loading