Skip to content

Commit

Permalink
add more options
Browse files Browse the repository at this point in the history
  • Loading branch information
henrij22 committed May 17, 2024
1 parent 0776c00 commit 9b079cc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
44 changes: 40 additions & 4 deletions dune/iga/test/testintersections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,41 @@ auto testInsideOutside(auto& grid) {
return t;
}

auto runBasisTest(Dune::TestSuite& t, const std::string& fileName, bool trimmed, int refLevel) {
auto testReportFullIntersections() {
TestSuite t;

Preferences::getInstance().reportTrimmedIntersections(false);

using PatchGrid = PatchGrid<2, 2, DefaultTrim::PatchGridFamily>;
using GridFactory = Dune::GridFactory<PatchGrid>;

auto gridFactory = GridFactory();
gridFactory.insertTrimParameters(GridFactory::TrimParameterType{100});
gridFactory.insertJson("auxiliaryfiles/element_trim.ibra", true, {2, 2});

const auto grid = gridFactory.createGrid();

auto count = [](const auto& ele, const auto& gridView) {
size_t i = 0;
for (const auto& intersection : intersections(gridView, ele))
++i;
return i;
};

auto leafGridView = grid->leafGridView();
for (const auto& ele : elements(leafGridView))
t.check(count(ele, leafGridView) == 4);

auto levelGridView = grid->levelGridView(grid->maxLevel());
for (const auto& ele : elements(leafGridView))
t.check(count(ele, levelGridView) == 4);

Preferences::getInstance().reportTrimmedIntersections(true);

return t;
}

auto runIntersectionTest(Dune::TestSuite& t, const std::string& fileName, bool trimmed, int refLevel) {
constexpr int gridDim = 2;
constexpr int dimworld = 2;

Expand Down Expand Up @@ -266,9 +300,11 @@ int main(int argc, char** argv) try {
Dune::MPIHelper::instance(argc, argv);
Dune::TestSuite t("", Dune::TestSuite::ThrowPolicy::AlwaysThrow);

runBasisTest(t, "auxiliaryfiles/element_trim.ibra", true, 0);
runBasisTest(t, "auxiliaryfiles/element_trim.ibra", true, 1);
runBasisTest(t, "auxiliaryfiles/element_trim.ibra", true, 2);
runIntersectionTest(t, "auxiliaryfiles/element_trim.ibra", true, 0);
runIntersectionTest(t, "auxiliaryfiles/element_trim.ibra", true, 1);
runIntersectionTest(t, "auxiliaryfiles/element_trim.ibra", true, 2);

t.subTest(testReportFullIntersections());

t.report();

Expand Down
4 changes: 3 additions & 1 deletion dune/iga/trimmer/defaulttrimmer/trimmedlocalgeometry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public:
/** @brief Return the element type identifier
*/
[[nodiscard]] GeometryType type() const {
return GeometryTypes::none(mydimension);
if (Preferences::getInstance().reportTrimmedElementGeometryTypeAsNone())
return GeometryTypes::none(mydimension);
return GeometryTypes::cube(mydimension);
}

// return whether we have an affine mapping (true for straight lines)
Expand Down
8 changes: 4 additions & 4 deletions dune/iga/trimmer/defaulttrimmer/trimmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ namespace DefaultTrim {
using IntersectionIterator = PatchGridLevelIntersectionIterator<const GridImp>;
auto& localEntity = ent.impl().getLocalEntity();

if (not localEntity.isTrimmed())
if (not localEntity.isTrimmed() or not Preferences::getInstance().reportTrimmedIntersections())
return IntersectionIterator(
grid_, parameterSpaceGrid().levelGridView(ent.level()).ibegin(localEntity.getHostEntity()));
return IntersectionIterator(grid_, localEntity, IntersectionIterator::PositionToken::Begin,
Expand All @@ -319,7 +319,7 @@ namespace DefaultTrim {
using IntersectionIterator = PatchGridLevelIntersectionIterator<const GridImp>;
auto& localEntity = ent.impl().getLocalEntity();

if (not localEntity.isTrimmed())
if (not localEntity.isTrimmed() or not Preferences::getInstance().reportTrimmedIntersections())
return IntersectionIterator(grid_,
parameterSpaceGrid().levelGridView(ent.level()).iend(localEntity.getHostEntity()));
return IntersectionIterator(grid_, localEntity, IntersectionIterator::PositionToken::End,
Expand All @@ -331,7 +331,7 @@ namespace DefaultTrim {
using IntersectionIterator = PatchGridLeafIntersectionIterator<const GridImp>;
auto& localEntity = ent.impl().getLocalEntity();

if (not localEntity.isTrimmed())
if (not localEntity.isTrimmed() or not Preferences::getInstance().reportTrimmedIntersections())
return IntersectionIterator(grid_, parameterSpaceGrid().leafGridView().ibegin(localEntity.getHostEntity()));
return IntersectionIterator(grid_, localEntity, IntersectionIterator::PositionToken::Begin,
parameterSpaceGrid().leafGridView().ibegin(localEntity.getHostEntity()));
Expand All @@ -342,7 +342,7 @@ namespace DefaultTrim {
using IntersectionIterator = PatchGridLeafIntersectionIterator<const GridImp>;
auto& localEntity = ent.impl().getLocalEntity();

if (not localEntity.isTrimmed())
if (not localEntity.isTrimmed() or not Preferences::getInstance().reportTrimmedIntersections())
return IntersectionIterator(grid_, parameterSpaceGrid().leafGridView().iend(localEntity.getHostEntity()));
return IntersectionIterator(grid_, localEntity, IntersectionIterator::PositionToken::End,
parameterSpaceGrid().leafGridView().ibegin(localEntity.getHostEntity()));
Expand Down
26 changes: 22 additions & 4 deletions dune/iga/trimmer/defaulttrimmer/trimmerpreferences.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public:
Preferences(const Preferences&) = delete;
Preferences& operator=(const Preferences&) = delete;

int boundaryDivisions() {
std::lock_guard lock(mtx);
int boundaryDivisions() const {
return boundaryDivisions_;
}

Expand All @@ -28,15 +27,32 @@ public:
this->boundaryDivisions_ = _boundaryDivisions;
}

double targetAccuracy() {
std::lock_guard lock(mtx);
double targetAccuracy() const {
return targetAccuracy_;
}
void targetAccuracy(double _targetAccuracy) {
std::lock_guard lock(mtx);
this->targetAccuracy_ = _targetAccuracy;
}

bool reportTrimmedElementGeometryTypeAsNone() const {
return reportTrimmedElementGeometryTypeAsNone_;
}

void reportTrimmedElementGeometryTypeAsNone(bool _reportTrimmedElementGeometryTypeAsNone) {
std::lock_guard lock(mtx);
this->reportTrimmedElementGeometryTypeAsNone_ = _reportTrimmedElementGeometryTypeAsNone;
}

bool reportTrimmedIntersections() const {
return reportTrimmedIntersections_;
}

void reportTrimmedIntersections(bool _reportTrimmedIntersections_) {
std::lock_guard lock(mtx);
this->reportTrimmedIntersections_ = _reportTrimmedIntersections_;
}

private:
// Private constructor for Singleton pattern
Preferences()
Expand All @@ -46,4 +62,6 @@ private:
std::mutex mtx; // Mutex for thread safety
int boundaryDivisions_;
double targetAccuracy_;
bool reportTrimmedElementGeometryTypeAsNone_{true};
bool reportTrimmedIntersections_{true};
};

0 comments on commit 9b079cc

Please sign in to comment.