Skip to content
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
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

### `<grid>`
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:

- `<numberOfCells>`: 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 `<boundingBox>`:
- `<boundingBox>` 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]
]
}
```

### `<object>`
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
Expand Down
27 changes: 16 additions & 11 deletions src/app/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ namespace po = boost::program_options;

Grid parseGridFromJSON(const nlohmann::json &j)
{
std::array<int,3> nCells = {
if (j.find("planes") != j.end()) {
return j["planes"];
}
else {
std::array<int, 3> nCells = {
j["numberOfCells"][0],
j["numberOfCells"][1],
j["numberOfCells"][2]
};
std::array<double,3> 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<double, 3> 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)
Expand Down
2 changes: 2 additions & 0 deletions src/app/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

#include "types/Mesh.h"
#include <string>
#include <nlohmann/json.hpp>

namespace meshlib::app {

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);

}
34 changes: 34 additions & 0 deletions test/app/launcherTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <gtest/gtest.h>

#include "app/launcher.h"
#include "types/Mesh.h"
#include <nlohmann/json.hpp>
#include <fstream>

using namespace meshlib::app;

Expand All @@ -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<double>{600, 603.25},
std::vector<double>{25.0, 30.5, 92, 130, 1000},
std::vector<double>{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;
Expand Down
10 changes: 10 additions & 0 deletions testData/cases/longPolyline/RectilinearGrid.tessellator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"grid": {
"planes": [
[600, 603.25],
[25.0, 30.5, 92, 130, 1000],
[1000, 1111, 1111.1]
]
},
"object": {"filename": "longPolyline.vtu"}
}
Loading