Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
henrij22 committed Jan 15, 2024
1 parent 5412b18 commit dc2bf7a
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 44 deletions.
6 changes: 3 additions & 3 deletions dune/iga/hierarchicpatch/patchgrid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ namespace Dune::IGANEW {
* @param hostgrid The host grid wrapped by the PatchGrid
*/
explicit PatchGrid(const NURBSPatchData<dim, dimworld, ctype>& patchData,
const std::optional<PatchTrimData>& patchTrimData = std::nullopt)
const std::optional<PatchTrimData>& patchTrimData = std::nullopt,
const typename Trimmer::ParameterType& par = {})
: patchGeometries_(1, GeometryKernel::NURBSPatch<dim, dimworld, ctype>(patchData)),
trimmer_(std::make_unique<Trimmer>(*this, patchTrimData)) {
// trimmer_->createIdSetAndParameterGrid(*this);
trimmer_(std::make_unique<Trimmer>(*this, patchTrimData, par)) {
patchGeometriesUnElevated = patchGeometries_;
}

Expand Down
25 changes: 12 additions & 13 deletions dune/iga/hierarchicpatch/patchgridfactory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ namespace Dune {
using PatchGrid = IGANEW::PatchGrid<dim, dimworld, TrimmerType_, ScalarType>;
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
Expand All @@ -45,6 +41,11 @@ namespace Dune {
// @todo this does not really add the trimming curve to anything
void insertTrimmingCurve(const IGANEW::NURBSPatchData<dim - 1, dim, ctype>& 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
Expand All @@ -59,21 +60,19 @@ namespace Dune {
The receiver takes responsibility of the memory allocated for the grid
*/
std::unique_ptr<PatchGrid> createGrid() {
std::unique_ptr<PatchGrid> createGrid() const {
if (patchTrimData_) {
auto grid = std::make_unique<PatchGrid>(patchData_, patchTrimData_);

auto grid = std::make_unique<PatchGrid>(patchData_, patchTrimData_, parameters_);
return grid;
} else
return std::make_unique<PatchGrid>(patchData_);
// create Grid and setup Element trimming inf through additional (private) constructor
}
return std::make_unique<PatchGrid>(patchData_);
}

IGANEW::NURBSPatchData<dim, dimworld, ctype> patchData_;
std::optional<PatchTrimData> patchTrimData_;
std::vector<IGANEW::NURBSPatchData<dim - 1, dim, ctype>> trimCurves;
std::string json_;
TrimmerType trimmer;
TrimParameterType parameters_{};
};

} // namespace Dune
2 changes: 0 additions & 2 deletions dune/iga/io/ibrareader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ namespace Dune::IGANEW {
PatchTrimData trimData{};
if (trim) {
constructTrimmingCurves(brep, trimData);
trimData.prepare(&_patchData);
}

return std::make_tuple(_patchData, trimData);
Expand All @@ -121,7 +120,6 @@ namespace Dune::IGANEW {
private:
static void constructTrimmingCurves(const Ibra::Brep<dimworld>& brep, PatchTrimData& trimData) {
const std::vector<Ibra::BrepLoop> 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)
Expand Down
6 changes: 4 additions & 2 deletions dune/iga/test/testibrareader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ auto testIbraReader() {
using GridFactory = Dune::GridFactory<PatchGrid>;

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();
Expand Down
2 changes: 1 addition & 1 deletion dune/iga/trimmer/concepts.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Dune::IGANEW::Concept {
{ trimmer.parameterSpaceGrid() } -> std::convertible_to<const typename T::ParameterSpaceGrid&>;
{ trimmer.parameterSpaceGrid() } -> std::convertible_to<typename T::ParameterSpaceGrid&>;

{ trimmer.setup(std::declval<const typename T::ParameterType>()) } -> std::convertible_to<void>;
{ trimmer.setParameters(std::declval<const typename T::ParameterType>()) } -> std::convertible_to<void>;

// { trimmer.unTrimmedParameterSpaceGrid() } -> std::convertible_to<const typename T::UntrimmedParameterSpaceGrid&>;
// { trimmer.unTrimmedParameterSpaceGrid() } -> std::convertible_to<typename T::UntrimmedParameterSpaceGrid&>;
Expand Down
20 changes: 9 additions & 11 deletions dune/iga/trimmer/defaulttrimmer/patchtrimdata.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Dune::IGANEW::DefaultTrim {
template <typename GridImp>
struct PatchTrimDataImpl {
using TrimmingCurve = typename GridImp::GridFamily::TrimmerTraits::TrimmingCurve;
using PatchData = NURBSPatchData<GridImp::GridFamily::patchDim, GridImp::GridFamily::worldDim, typename GridImp::ctype>;
using ParameterType = typename GridImp::GridFamily::Trimmer::ParameterType;

struct BoundaryLoop {
void insertTrimCurve(const TrimmingCurve& curve) { curves_.push_back(curve); }
Expand All @@ -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;
Expand Down Expand Up @@ -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<size_t>(std::floor(val / splitter_) - 1);
auto curveIdx = static_cast<size_t>(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<idx_t> loopIndices_{};
};
Expand All @@ -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_;
}

Expand All @@ -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 <typename ParameterSpaceGrid>
void prepare(const ParameterType& parameters, const std::unique_ptr<ParameterSpaceGrid>& parameterSpaceGrid) {
manager_.splitter_ = parameters.splitter;
std::ranges::for_each(loops_, [&](const auto& loop) { manager_.addLoop(loop);});


Expand Down
6 changes: 1 addition & 5 deletions dune/iga/trimmer/defaulttrimmer/trimelement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ namespace Dune::IGANEW::DefaultTrim {
return patchTrimData.getIndices(std::get<Util::ClippingResult::NewVertex>(vV).trimmingCurveZ);
};

auto createTrimmingCurveSlice = [&](const TrimmingCurve& curve, double t1, double t2) -> TrimmingCurve {
return sliceCurve(curve, {t1, t2});
};

///
// Here the actual code is starting
///
Expand Down Expand Up @@ -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<double>::infinity();
Expand Down
22 changes: 17 additions & 5 deletions dune/iga/trimmer/defaulttrimmer/trimmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -469,12 +471,14 @@ namespace Dune::IGANEW {
* @param patch NURBS patch data.
* @param trimData Optional patch trim data.
*/
TrimmerImpl(GridImp& grid, const std::optional<PatchTrimData>& trimData)
TrimmerImpl(GridImp& grid, const std::optional<PatchTrimData>& trimData, const ParameterType& par = {})
: grid_{&grid},
leafIndexSet_(std::make_unique<LeafIndexSet>(*grid_)),
globalIdSet_(std::make_unique<GlobalIdSet>(*grid_)),
localIdSet_(std::make_unique<LocalIdSet>(*grid_)),
trimData_{trimData} {
trimData_{trimData},
parameters_(par) {
setup();
createParameterSpaceGrid();
setIndices();
}
Expand All @@ -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.
Expand Down Expand Up @@ -574,6 +584,8 @@ namespace Dune::IGANEW {
std::unique_ptr<UntrimmedParameterSpaceGrid> untrimmedParameterSpaceGrid_;

std::optional<PatchTrimData> trimData_;

ParameterType parameters_;
};

} // namespace DefaultTrim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
5 changes: 5 additions & 0 deletions dune/iga/trimmer/defaulttrimmer/trimmingutils/trimutils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace Dune::IGANEW::DefaultTrim::Util {
return linSpace[min_idx];
}

template <typename TrimmingCurve>
auto createTrimmingCurveSlice(const TrimmingCurve& curve, double t1, double t2) -> TrimmingCurve {
return sliceCurve(curve, {t1, t2});
}

template <typename TrimmingCurve>
auto createHostGeometry(auto& vertex1, auto& vertex2) -> TrimmingCurve {
const std::array<std::vector<double>, 1> knotSpans = {{{0, 0, 1, 1}}};
Expand Down
5 changes: 3 additions & 2 deletions dune/iga/trimmer/identitytrimmer/trimmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ namespace Dune::IGANEW {
* @param patch NURBS patch data.
* @param trimData Optional patch trim data.
*/
TrimmerImpl(GridImp& grid, const std::optional<typename GridFamily::PatchTrimData>& trimData)
TrimmerImpl(GridImp& grid, const std::optional<typename GridFamily::PatchTrimData>& trimData, const ParameterType& par = {})
: grid_{&grid},
leafIndexSet_(std::make_unique<LeafIndexSet>(*grid_)),
globalIdSet_(std::make_unique<GlobalIdSet>(*grid_)),
Expand All @@ -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.
Expand Down

0 comments on commit dc2bf7a

Please sign in to comment.