From dc2bf7aee739a837e800a4af968878eefbe60ff3 Mon Sep 17 00:00:00 2001 From: Henrik Jakob Date: Mon, 15 Jan 2024 17:51:19 +0100 Subject: [PATCH] save --- dune/iga/hierarchicpatch/patchgrid.hh | 6 ++--- dune/iga/hierarchicpatch/patchgridfactory.hh | 25 +++++++++---------- dune/iga/io/ibrareader.hh | 2 -- dune/iga/test/testibrareader.cpp | 6 +++-- dune/iga/trimmer/concepts.hh | 2 +- .../trimmer/defaulttrimmer/patchtrimdata.hh | 20 +++++++-------- .../iga/trimmer/defaulttrimmer/trimelement.hh | 6 +---- dune/iga/trimmer/defaulttrimmer/trimmer.hh | 22 ++++++++++++---- .../trimmingutils/clipelementrectangle.hh | 1 + .../defaulttrimmer/trimmingutils/trimutils.hh | 5 ++++ dune/iga/trimmer/identitytrimmer/trimmer.hh | 5 ++-- 11 files changed, 56 insertions(+), 44 deletions(-) diff --git a/dune/iga/hierarchicpatch/patchgrid.hh b/dune/iga/hierarchicpatch/patchgrid.hh index 38598d7f..446e467e 100644 --- a/dune/iga/hierarchicpatch/patchgrid.hh +++ b/dune/iga/hierarchicpatch/patchgrid.hh @@ -157,10 +157,10 @@ namespace Dune::IGANEW { * @param hostgrid The host grid wrapped by the PatchGrid */ explicit PatchGrid(const NURBSPatchData& patchData, - const std::optional& patchTrimData = std::nullopt) + const std::optional& patchTrimData = std::nullopt, + const typename Trimmer::ParameterType& par = {}) : patchGeometries_(1, GeometryKernel::NURBSPatch(patchData)), - trimmer_(std::make_unique(*this, patchTrimData)) { - // trimmer_->createIdSetAndParameterGrid(*this); + trimmer_(std::make_unique(*this, patchTrimData, par)) { patchGeometriesUnElevated = patchGeometries_; } diff --git a/dune/iga/hierarchicpatch/patchgridfactory.hh b/dune/iga/hierarchicpatch/patchgridfactory.hh index f70aa134..dcb2c8d0 100644 --- a/dune/iga/hierarchicpatch/patchgridfactory.hh +++ b/dune/iga/hierarchicpatch/patchgridfactory.hh @@ -16,17 +16,13 @@ namespace Dune { using PatchGrid = IGANEW::PatchGrid; using TrimmerType = typename PatchGrid::Trimmer; using PatchTrimData = typename TrimmerType::PatchTrimData; + + public: using TrimParameterType = typename TrimmerType::ParameterType; /** @brief Type used by the grid for coordinates */ typedef typename PatchGrid::ctype ctype; - public: - /** @brief Forward setting to trimmer - @param parameter The parameters - */ - // @todo this is never called and does nothing - void setupTrimmer(const TrimParameterType& parameter) { trimmer.setup(parameter); } /** @brief Insert a patch into the grid @param patchData The patch data @@ -45,6 +41,11 @@ namespace Dune { // @todo this does not really add the trimming curve to anything void insertTrimmingCurve(const IGANEW::NURBSPatchData& curve) { trimCurves.push_back(curve); } + + void insertTrimParameters(const TrimParameterType& par) { + parameters_ = par; + } + /** @brief Insert a patch into the grid @param patchData The patch data @param patchTrimData Trimming data for this patch @@ -59,21 +60,19 @@ namespace Dune { The receiver takes responsibility of the memory allocated for the grid */ - std::unique_ptr createGrid() { + std::unique_ptr createGrid() const { if (patchTrimData_) { - auto grid = std::make_unique(patchData_, patchTrimData_); - + auto grid = std::make_unique(patchData_, patchTrimData_, parameters_); return grid; - } else - return std::make_unique(patchData_); - // create Grid and setup Element trimming inf through additional (private) constructor + } + return std::make_unique(patchData_); } IGANEW::NURBSPatchData patchData_; std::optional patchTrimData_; std::vector> trimCurves; std::string json_; - TrimmerType trimmer; + TrimParameterType parameters_{}; }; } // namespace Dune diff --git a/dune/iga/io/ibrareader.hh b/dune/iga/io/ibrareader.hh index 69826b7a..4fcd3a29 100644 --- a/dune/iga/io/ibrareader.hh +++ b/dune/iga/io/ibrareader.hh @@ -112,7 +112,6 @@ namespace Dune::IGANEW { PatchTrimData trimData{}; if (trim) { constructTrimmingCurves(brep, trimData); - trimData.prepare(&_patchData); } return std::make_tuple(_patchData, trimData); @@ -121,7 +120,6 @@ namespace Dune::IGANEW { private: static void constructTrimmingCurves(const Ibra::Brep& brep, PatchTrimData& trimData) { const std::vector loops = brep.loops; - assert(!loops.empty() && "Only one boundary loop is currently supported"); for (int i = 0; const Ibra::BrepLoop& loop : loops) { trimData.addLoop(); for (const Ibra::BrepTrim& trim : loop.trims) diff --git a/dune/iga/test/testibrareader.cpp b/dune/iga/test/testibrareader.cpp index 2b9e9884..b3e094c8 100644 --- a/dune/iga/test/testibrareader.cpp +++ b/dune/iga/test/testibrareader.cpp @@ -26,11 +26,13 @@ auto testIbraReader() { using GridFactory = Dune::GridFactory; auto gridFactory = GridFactory(); + gridFactory.insertTrimParameters(GridFactory::TrimParameterType{120}); + // gridFactory.insertJson("auxiliaryfiles/trim_2edges.ibra", true, {0, 0}); - gridFactory.insertJson("auxiliaryfiles/element_trim.ibra", true, {1, 1}); + // gridFactory.insertJson("auxiliaryfiles/element_trim.ibra", true, {1, 1}); // gridFactory.insertJson("auxiliaryfiles/trim_multi.ibra", true, {1, 1}); - // gridFactory.insertJson("auxiliaryfiles/element_trim_xb.ibra", true, {1, 1}); + gridFactory.insertJson("auxiliaryfiles/element_trim_xb.ibra", true, {1, 1}); // gridFactory.insertJson("auxiliaryfiles/pipe_trim.ibra", true, {1, 1}); auto grid = gridFactory.createGrid(); diff --git a/dune/iga/trimmer/concepts.hh b/dune/iga/trimmer/concepts.hh index 2ac8829a..87eb6271 100644 --- a/dune/iga/trimmer/concepts.hh +++ b/dune/iga/trimmer/concepts.hh @@ -47,7 +47,7 @@ namespace Dune::IGANEW::Concept { { trimmer.parameterSpaceGrid() } -> std::convertible_to; { trimmer.parameterSpaceGrid() } -> std::convertible_to; - { trimmer.setup(std::declval()) } -> std::convertible_to; + { trimmer.setParameters(std::declval()) } -> std::convertible_to; // { trimmer.unTrimmedParameterSpaceGrid() } -> std::convertible_to; // { trimmer.unTrimmedParameterSpaceGrid() } -> std::convertible_to; diff --git a/dune/iga/trimmer/defaulttrimmer/patchtrimdata.hh b/dune/iga/trimmer/defaulttrimmer/patchtrimdata.hh index 4dad879e..e2792684 100644 --- a/dune/iga/trimmer/defaulttrimmer/patchtrimdata.hh +++ b/dune/iga/trimmer/defaulttrimmer/patchtrimdata.hh @@ -7,7 +7,7 @@ namespace Dune::IGANEW::DefaultTrim { template struct PatchTrimDataImpl { using TrimmingCurve = typename GridImp::GridFamily::TrimmerTraits::TrimmingCurve; - using PatchData = NURBSPatchData; + using ParameterType = typename GridImp::GridFamily::Trimmer::ParameterType; struct BoundaryLoop { void insertTrimCurve(const TrimmingCurve& curve) { curves_.push_back(curve); } @@ -21,9 +21,9 @@ namespace Dune::IGANEW::DefaultTrim { class CurveManager { + friend PatchTrimDataImpl; public: using idx_t = u_int64_t; - explicit CurveManager(const idx_t splitter = 100) : splitter_(splitter) {} void addLoop(const BoundaryLoop& loop) { Clipper2Lib::PathD path; @@ -57,17 +57,13 @@ namespace Dune::IGANEW::DefaultTrim { loopIdx = std::ranges::distance(loopIndices_.begin(), it); } // \todo multiplt loop e.g. - size of all loops before - size_t curveIdx = static_cast(std::floor(val / splitter_) - 1); + auto curveIdx = static_cast(std::floor(val / splitter_) - 1); return std::make_pair(loopIdx, curveIdx); } - [[nodiscard]] auto getSplitter() const -> idx_t { - return splitter_; - } - - Clipper2Lib::PathsD loops_; private: + Clipper2Lib::PathsD loops_; idx_t splitter_{}; std::vector loopIndices_{}; }; @@ -82,7 +78,7 @@ namespace Dune::IGANEW::DefaultTrim { const auto& loops() const { return loops_; } const auto& clipperLoops() const { if (not finished_) - DUNE_THROW(Dune::GridError, "Call prepare() before quering for loops"); + DUNE_THROW(Dune::GridError, "Call trimmer.setup() before quering for loops"); return manager_.loops_; } @@ -97,10 +93,12 @@ namespace Dune::IGANEW::DefaultTrim { return loops_[indices.first].curves()[indices.second]; } auto getSplitter() const -> typename CurveManager::idx_t { - return manager_.getSplitter(); + return manager_.splitter_; } - void prepare(PatchData* patchData) { + template + void prepare(const ParameterType& parameters, const std::unique_ptr& parameterSpaceGrid) { + manager_.splitter_ = parameters.splitter; std::ranges::for_each(loops_, [&](const auto& loop) { manager_.addLoop(loop);}); diff --git a/dune/iga/trimmer/defaulttrimmer/trimelement.hh b/dune/iga/trimmer/defaulttrimmer/trimelement.hh index 49c00972..86e3c9b1 100644 --- a/dune/iga/trimmer/defaulttrimmer/trimelement.hh +++ b/dune/iga/trimmer/defaulttrimmer/trimelement.hh @@ -42,10 +42,6 @@ namespace Dune::IGANEW::DefaultTrim { return patchTrimData.getIndices(std::get(vV).trimmingCurveZ); }; - auto createTrimmingCurveSlice = [&](const TrimmingCurve& curve, double t1, double t2) -> TrimmingCurve { - return sliceCurve(curve, {t1, t2}); - }; - /// // Here the actual code is starting /// @@ -113,7 +109,7 @@ namespace Dune::IGANEW::DefaultTrim { isOnNewEdge = true; currentT = tParam; } else { - auto elementTrimmingCurve = createTrimmingCurveSlice(patchTrimData.getCurve(currentCurveIdx), currentT, tParam); + auto elementTrimmingCurve = Util::createTrimmingCurveSlice(patchTrimData.getCurve(currentCurveIdx), currentT, tParam); elementTrimData.addEdgeNewNew(elementTrimmingCurve, curvePoint); isOnNewEdge = false; currentT = std::numeric_limits::infinity(); diff --git a/dune/iga/trimmer/defaulttrimmer/trimmer.hh b/dune/iga/trimmer/defaulttrimmer/trimmer.hh index 018c2e2f..90044260 100644 --- a/dune/iga/trimmer/defaulttrimmer/trimmer.hh +++ b/dune/iga/trimmer/defaulttrimmer/trimmer.hh @@ -160,7 +160,9 @@ namespace Dune::IGANEW { /** * @brief Parameter struct representing parameters for the trimming operation. */ - struct Parameter {}; + struct Parameter { + size_t splitter = 100; + }; // /** // * @brief ElementTrimData struct representing trim data for an element. @@ -469,12 +471,14 @@ namespace Dune::IGANEW { * @param patch NURBS patch data. * @param trimData Optional patch trim data. */ - TrimmerImpl(GridImp& grid, const std::optional& trimData) + TrimmerImpl(GridImp& grid, const std::optional& trimData, const ParameterType& par = {}) : grid_{&grid}, leafIndexSet_(std::make_unique(*grid_)), globalIdSet_(std::make_unique(*grid_)), localIdSet_(std::make_unique(*grid_)), - trimData_{trimData} { + trimData_{trimData}, + parameters_(par) { + setup(); createParameterSpaceGrid(); setIndices(); } @@ -493,11 +497,17 @@ namespace Dune::IGANEW { GridImp* grid_; + void setup() { + if (trimData_.has_value()) + trimData_->prepare(parameters_, untrimmedParameterSpaceGrid_); + } /** - * @brief Pass parameters to the trimmer. + * @brief Change the parameters to the trimmer. * @param par The parameters. */ - void setup(const ParameterType&) {} + void setParameters(const ParameterType& par) { + parameters_ = par; + } /** * @brief Get a const reference to the parameter space grid. @@ -574,6 +584,8 @@ namespace Dune::IGANEW { std::unique_ptr untrimmedParameterSpaceGrid_; std::optional trimData_; + + ParameterType parameters_; }; } // namespace DefaultTrim diff --git a/dune/iga/trimmer/defaulttrimmer/trimmingutils/clipelementrectangle.hh b/dune/iga/trimmer/defaulttrimmer/trimmingutils/clipelementrectangle.hh index 3a285708..22a32395 100644 --- a/dune/iga/trimmer/defaulttrimmer/trimmingutils/clipelementrectangle.hh +++ b/dune/iga/trimmer/defaulttrimmer/trimmingutils/clipelementrectangle.hh @@ -89,6 +89,7 @@ namespace Dune::IGANEW::DefaultTrim::Util { } // Add startpoints of trimming curves to the vertices if they are on one of the element edges + // \todo not exactly sure but i think this only has to check the outer boundary loop for (auto cI = 0; cI < patchTrimData.loops().front().curves().size(); ++cI) { const auto& curve = patchTrimData.loops().front().curves()[cI]; diff --git a/dune/iga/trimmer/defaulttrimmer/trimmingutils/trimutils.hh b/dune/iga/trimmer/defaulttrimmer/trimmingutils/trimutils.hh index b8ddcc42..cd7fd33c 100644 --- a/dune/iga/trimmer/defaulttrimmer/trimmingutils/trimutils.hh +++ b/dune/iga/trimmer/defaulttrimmer/trimmingutils/trimutils.hh @@ -20,6 +20,11 @@ namespace Dune::IGANEW::DefaultTrim::Util { return linSpace[min_idx]; } + template + auto createTrimmingCurveSlice(const TrimmingCurve& curve, double t1, double t2) -> TrimmingCurve { + return sliceCurve(curve, {t1, t2}); + } + template auto createHostGeometry(auto& vertex1, auto& vertex2) -> TrimmingCurve { const std::array, 1> knotSpans = {{{0, 0, 1, 1}}}; diff --git a/dune/iga/trimmer/identitytrimmer/trimmer.hh b/dune/iga/trimmer/identitytrimmer/trimmer.hh index 10eda16e..09ce5004 100644 --- a/dune/iga/trimmer/identitytrimmer/trimmer.hh +++ b/dune/iga/trimmer/identitytrimmer/trimmer.hh @@ -266,7 +266,7 @@ namespace Dune::IGANEW { * @param patch NURBS patch data. * @param trimData Optional patch trim data. */ - TrimmerImpl(GridImp& grid, const std::optional& trimData) + TrimmerImpl(GridImp& grid, const std::optional& trimData, const ParameterType& par = {}) : grid_{&grid}, leafIndexSet_(std::make_unique(*grid_)), globalIdSet_(std::make_unique(*grid_)), @@ -293,7 +293,8 @@ namespace Dune::IGANEW { * @brief Pass parameters to the trimmer. * @param par The parameters. */ - void setup(const ParameterType&) {} + void setup() {} + void setParameters(const ParameterType&) {} /** * @brief Get a const reference to the parameter space grid.