Skip to content

Commit

Permalink
Fixed ibrareader to return a unique_ptr #32
Browse files Browse the repository at this point in the history
  • Loading branch information
henrij22 committed Nov 6, 2023
1 parent 1b971f1 commit e59aef1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions dune/iga/io/ibra/ibrareader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Dune::IGA {
using PatchData = Dune::IGA::NURBSPatchData<gridDim, worldDim>;
using ControlPointNetType = Dune::IGA::MultiDimensionNet<gridDim, ControlPoint>;

static std::shared_ptr<Grid> read(const std::string& fileName, const bool trim = true,
static std::unique_ptr<Grid> read(const std::string& fileName, const bool trim = true,
std::array<int, 2> elevateDegree = {0, 0},
std::array<int, 2> preKnotRefine = {0, 0},
std::array<int, 2> postKnotRefine = {0, 0}) {
Expand All @@ -40,7 +40,7 @@ namespace Dune::IGA {
template <typename InputStringType>
requires(not std::convertible_to<
std::string, InputStringType> and not std::convertible_to<InputStringType, const char*>) static std::
shared_ptr<Grid> read(InputStringType& ibraInputFile, const bool trim = true,
unique_ptr<Grid> read(InputStringType& ibraInputFile, const bool trim = true,
std::array<int, 2> elevateDegree = {0, 0}, std::array<int, 2> preKnotRefine = {0, 0},
std::array<int, 2> postKnotRefine = {0, 0}) {
using json = nlohmann::json;
Expand Down Expand Up @@ -129,9 +129,9 @@ namespace Dune::IGA {
auto trimData = constructGlobalBoundaries(brep);

if (trim)
return std::make_shared<Grid>(_patchData, trimData);
return std::make_unique<Grid>(_patchData, trimData);
else
return std::make_shared<Grid>(_patchData);
return std::make_unique<Grid>(_patchData);

Check warning on line 134 in dune/iga/io/ibra/ibrareader.hh

View check run for this annotation

Codecov / codecov/patch

dune/iga/io/ibra/ibrareader.hh#L134

Added line #L134 was not covered by tests
}

private:
Expand Down
14 changes: 7 additions & 7 deletions dune/iga/test/trimmedGridTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ auto testPatchGeometrySurface() {
auto testIbraReader() {
TestSuite t;

std::shared_ptr<NURBSGrid<2, 2>> grid = IbraReader<2, 2>::read("auxiliaryFiles/element.ibra");
auto grid = IbraReader<2, 2>::read("auxiliaryFiles/element.ibra");

// Check n_ele = 1, n_vert = 4
t.check(grid->size(0) == 1);
Expand All @@ -202,7 +202,7 @@ auto testIbraReader() {
t.check(ele.geometry().center() == expectedElementCenters[indexSet.index(ele)]);

// Test Instantiation
std::shared_ptr<NURBSGrid<2, 3>> grid3D = IbraReader<2, 3>::read("auxiliaryFiles/shell.ibra");
auto grid3D = IbraReader<2, 3>::read("auxiliaryFiles/shell.ibra");
grid3D->globalRefine(2);

return t;
Expand All @@ -217,7 +217,7 @@ auto testDataCollectorAndVtkWriter() {
std::vector<std::string> geometries{"element_trim_xb", "surface-hole"};

for (auto& fileName : geometries) {
std::shared_ptr<NURBSGrid<2, 2>> grid = IbraReader<2, 2>::read("auxiliaryFiles/" + fileName + ".ibra");
auto grid = IbraReader<2, 2>::read("auxiliaryFiles/" + fileName + ".ibra");

for (auto r : std::views::iota(0, 4)) {
if (r > 0) grid->globalRefine(1);
Expand Down Expand Up @@ -334,7 +334,7 @@ auto testMapsInTrimmedPatch() {
}

// Load next example Grid
std::shared_ptr<NURBSGrid<2, 2>> grid2 = IbraReader<2, 2>::read("auxiliaryFiles/element_trim_xb.ibra");
auto grid2 = IbraReader<2, 2>::read("auxiliaryFiles/element_trim_xb.ibra");
grid2->globalRefine(1);
auto& patch_2_1 = grid2->getPatch();

Expand Down Expand Up @@ -396,7 +396,7 @@ auto testIntegrationPoints() {
/// 1. test case A = 10 * 10, r = 3
auto targetArea = 10 * 10 - (std::numbers::pi * std::pow(3, 2));

std::shared_ptr<NURBSGrid<2, 2>> grid = IbraReader<2, 2>::read("auxiliaryFiles/surface-hole.ibra");
auto grid = IbraReader<2, 2>::read("auxiliaryFiles/surface-hole.ibra");
grid->globalRefine(1);

double area = calculateArea(grid->leafGridView(), std::nullopt);
Expand All @@ -422,7 +422,7 @@ auto testIntegrationPoints() {
targetArea = 20 * 2 - (std::numbers::pi * std::pow(0.3, 2));

std::cout << "Grid 2 \n";
std::shared_ptr<NURBSGrid<2, 2>> grid2 = IbraReader<2, 2>::read("auxiliaryFiles/infty_pwh.ibra");
auto grid2 = IbraReader<2, 2>::read("auxiliaryFiles/infty_pwh.ibra");
grid2->globalRefine(1);

area = calculateArea(grid2->leafGridView());
Expand Down Expand Up @@ -454,7 +454,7 @@ auto testNurbsBasis() {
}
};

std::shared_ptr<NURBSGrid<2, 2>> grid = IbraReader<2, 2>::read("auxiliaryFiles/element_trim_xb.ibra");
auto grid = IbraReader<2, 2>::read("auxiliaryFiles/element_trim_xb.ibra");
runBasisChecks(grid, 4);

grid = IbraReader<2, 2>::read("auxiliaryFiles/element_trim_xb.ibra", true, {1, 1});
Expand Down

0 comments on commit e59aef1

Please sign in to comment.