diff --git a/README.md b/README.md index 4e3a2bc..b777cec 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,56 @@ This can be done using a `CMakeUserPreset.json` file, for example: } ``` +## Usage + +The main binary is `tessellator`, which uses a tessellator json format, which will be explained below. + +```shell + tessellator -i MESH_NAME.tessellator.json +``` + +## JSON Format +The two main entries are as follows: + +### `` +This object must always be present and contains the structure of the grid, which will be used to slice and adjust the mesh provided. It must contain one of these two sets of entries: + +- ``: is an array of three positive integers which indicate the number of cells in each Cartesian direction. In case of having this entry, it also must contain a ``: + - `` is represented by an array which contairs two triplets of integers, representing the minimum and maximum values of the gread in each cartesian direction. + +```json + "grid": { + "numberOfCells": [20, 20, 30], + "boundingBox": [ + [-1, -1, -1], + [ 1, 1, 2] + ] + } +``` + +- `planes`: This array contains other three arrays of floating point numbers. Each number must be in sequential order, from lowest to highest, each value representing the position of every plane forming the cells of the grid. This allows the definition of a non-uniform (rectilinear) grid. + +```json + "grid": { + "planes": [ + [600, 603.25], + [25.0, 30.5, 92, 130, 1000], + [1000, 1111, 1111.1] + ] + } +``` + +### `` +This contains the information about the mesh file. It must contain the following entry: + +- `filename`: with an string containing the name of the mesh file. Its location is relative to that of the json file. + + Example: + +```json + "object": {"filename": "thinCylinder.stl"} +``` + ## Contributing ## Citing this work diff --git a/src/app/launcher.cpp b/src/app/launcher.cpp index 8ff0c0c..b8dd444 100644 --- a/src/app/launcher.cpp +++ b/src/app/launcher.cpp @@ -23,20 +23,25 @@ namespace po = boost::program_options; Grid parseGridFromJSON(const nlohmann::json &j) { - std::array nCells = { + if (j.find("planes") != j.end()) { + return j["planes"]; + } + else { + std::array nCells = { j["numberOfCells"][0], j["numberOfCells"][1], j["numberOfCells"][2] - }; - std::array min, max; - min = j["boundingBox"][0]; - max = j["boundingBox"][1]; - - return { - utils::GridTools::linspace(min[0], max[0], nCells[0]+1), - utils::GridTools::linspace(min[1], max[1], nCells[1]+1), - utils::GridTools::linspace(min[2], max[2], nCells[2]+1) - }; + }; + std::array min, max; + min = j["boundingBox"][0]; + max = j["boundingBox"][1]; + + return { + utils::GridTools::linspace(min[0], max[0], nCells[0] + 1), + utils::GridTools::linspace(min[1], max[1], nCells[1] + 1), + utils::GridTools::linspace(min[2], max[2], nCells[2] + 1) + }; + } } Mesh readMesh(const std::string &fn) diff --git a/src/app/launcher.h b/src/app/launcher.h index e54b2f5..d65d218 100644 --- a/src/app/launcher.h +++ b/src/app/launcher.h @@ -2,6 +2,7 @@ #include "types/Mesh.h" #include +#include namespace meshlib::app { @@ -9,5 +10,6 @@ const std::string conformal_mesher ("conformal"); const std::string staircase_mesher ("staircase"); int launcher(int argc, const char* argv[]); +Grid parseGridFromJSON(const nlohmann::json& j); } \ No newline at end of file diff --git a/test/app/launcherTest.cpp b/test/app/launcherTest.cpp index 9abbf1b..3942428 100644 --- a/test/app/launcherTest.cpp +++ b/test/app/launcherTest.cpp @@ -1,6 +1,9 @@ #include #include "app/launcher.h" +#include "types/Mesh.h" +#include +#include using namespace meshlib::app; @@ -15,6 +18,37 @@ TEST_F(LauncherTest, prints_help) EXPECT_EQ(meshlib::app::launcher(ac, av), EXIT_SUCCESS); } +TEST_F(LauncherTest, parse_rectilinear_grid) +{ + int ac = 3; + std::string fileName = "testData/cases/longPolyline/RectilinearGrid.tessellator.json"; + nlohmann::json j; + { + std::ifstream i(fileName); + i >> j; + } + + meshlib::Grid grid = meshlib::app::parseGridFromJSON(j["grid"]); + + meshlib::Grid expectedGrid({ + std::vector{600, 603.25}, + std::vector{25.0, 30.5, 92, 130, 1000}, + std::vector{1000, 1111, 1111.1} + }); + + for (std::size_t axis = 0; axis < 3; ++axis) { + const auto& planes = grid[axis]; + const auto& expectedPlanes = expectedGrid[axis]; + + EXPECT_EQ(planes.size(), expectedPlanes.size()); + + + for (std::size_t planeIndex = 0; planeIndex < grid[axis].size(); ++planeIndex) { + EXPECT_EQ(planes[planeIndex], expectedPlanes[planeIndex]); + } + } +} + TEST_F(LauncherTest, launches_alhambra_case) { int ac = 3; diff --git a/testData/cases/longPolyline/RectilinearGrid.tessellator.json b/testData/cases/longPolyline/RectilinearGrid.tessellator.json new file mode 100644 index 0000000..3e77db9 --- /dev/null +++ b/testData/cases/longPolyline/RectilinearGrid.tessellator.json @@ -0,0 +1,10 @@ +{ + "grid": { + "planes": [ + [600, 603.25], + [25.0, 30.5, 92, 130, 1000], + [1000, 1111, 1111.1] + ] + }, + "object": {"filename": "longPolyline.vtu"} +} \ No newline at end of file