Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
henrij22 committed Jan 15, 2024
1 parent dc2bf7a commit ba84e38
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 71 deletions.
2 changes: 1 addition & 1 deletion dune/iga/hierarchicpatch/patchgrid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace Dune::IGANEW {
*/
explicit PatchGrid(const NURBSPatchData<dim, dimworld, ctype>& patchData,
const std::optional<PatchTrimData>& patchTrimData = std::nullopt,
const typename Trimmer::ParameterType& par = {})
const typename Trimmer::ParameterType& par = {})
: patchGeometries_(1, GeometryKernel::NURBSPatch<dim, dimworld, ctype>(patchData)),
trimmer_(std::make_unique<Trimmer>(*this, patchTrimData, par)) {
patchGeometriesUnElevated = patchGeometries_;
Expand Down
8 changes: 2 additions & 6 deletions dune/iga/hierarchicpatch/patchgridfactory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ namespace Dune {
using PatchTrimData = typename TrimmerType::PatchTrimData;

public:
using TrimParameterType = typename TrimmerType::ParameterType;
using TrimParameterType = typename TrimmerType::ParameterType;

/** @brief Type used by the grid for coordinates */
typedef typename PatchGrid::ctype ctype;


/** @brief Insert a patch into the grid
@param patchData The patch data
@param patchTrimData Trimming data for this patch
Expand All @@ -41,10 +40,7 @@ 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;
}
void insertTrimParameters(const TrimParameterType& par) { parameters_ = par; }

/** @brief Insert a patch into the grid
@param patchData The patch data
Expand Down
3 changes: 1 addition & 2 deletions dune/iga/test/testibrareader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ auto testIbraReader() {
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/trim_2edges.ibra", true, {0, 0});
// gridFactory.insertJson("auxiliaryfiles/trim_multi.ibra", true, {1, 1});
gridFactory.insertJson("auxiliaryfiles/element_trim_xb.ibra", true, {1, 1});
// gridFactory.insertJson("auxiliaryfiles/pipe_trim.ibra", true, {1, 1});
Expand Down
14 changes: 7 additions & 7 deletions dune/iga/test/trimtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@

#include <dune/iga/hierarchicpatch/patchgridfactory.hh>
#include <dune/iga/patchgrid.hh>
#include <dune/iga/trimmer/defaulttrimmer/trimmer.hh>
#include <dune/iga/trimmer/defaulttrimmer/trimelement.hh>
#include <dune/iga/trimmer/defaulttrimmer/trimmer.hh>

using namespace Dune::IGANEW;

auto testExample1(){
auto testExample1() {
Dune::TestSuite t("", Dune::TestSuite::ThrowPolicy::ThrowOnRequired);

// Setup
using GridFactory = Dune::GridFactory<PatchGrid<2, 2, DefaultTrim::PatchGridFamily>>;
using Trimmer = DefaultTrim::TrimmerImpl<2, 2, double>;
using GridFactory = Dune::GridFactory<PatchGrid<2, 2, DefaultTrim::PatchGridFamily>>;
using Trimmer = DefaultTrim::TrimmerImpl<2, 2, double>;
using ElementTrimData = Trimmer::ElementTrimData;

auto gridFactory = GridFactory();
Expand All @@ -34,12 +34,12 @@ auto testExample1(){
const Dune::YaspGrid grid{tensorCoordinates};

const auto& patchTrimData = gridFactory.patchTrimData_.value();
auto trimmer = Trimmer{};
auto trimmer = Trimmer{};

for (auto& ele : elements(grid.leafGridView())) {
ElementTrimData elementTrimData = trimmer.trimElement(ele, patchTrimData);
auto& vertexInfos = elementTrimData.vertices();
auto& edgeInfos = elementTrimData.edges();
auto& vertexInfos = elementTrimData.vertices();
auto& edgeInfos = elementTrimData.edges();
}

return t;
Expand Down
4 changes: 2 additions & 2 deletions dune/iga/trimmer/defaulttrimmer/elementtrimdata.hh
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ namespace Dune::IGANEW::DefaultTrim {

// Getter
[[nodiscard]] ElementTrimFlag flag() const { return flag_; }
[[nodiscard]] const std::vector<VertexInfo>& vertices() const {return vertices_;}
[[nodiscard]] const std::vector<EdgeInfo>& edges() const {return edges_;}
[[nodiscard]] const std::vector<VertexInfo>& vertices() const { return vertices_; }
[[nodiscard]] const std::vector<EdgeInfo>& edges() const { return edges_; }

private:
ElementTrimFlag flag_;
Expand Down
24 changes: 7 additions & 17 deletions dune/iga/trimmer/defaulttrimmer/patchtrimdata.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ namespace Dune::IGANEW::DefaultTrim {
std::vector<TrimmingCurve> curves_;
};



class CurveManager {
friend PatchTrimDataImpl;

public:
using idx_t = u_int64_t;

void addLoop(const BoundaryLoop& loop) {
Clipper2Lib::PathD path;
for (idx_t i = loops_.empty() ? splitter_ : loops_.back().back().z + 1;
const auto& curve : loop.curves()) {
for (idx_t i = loops_.empty() ? splitter_ : loops_.back().back().z + 1; const auto& curve : loop.curves()) {
if (curve.degree().front() == 1) {
auto p1 = curve.corner(0);
auto p2 = curve.corner(1);
Expand All @@ -49,11 +47,8 @@ namespace Dune::IGANEW::DefaultTrim {
[[nodiscard]] auto getIndices(const idx_t val) const -> std::pair<size_t, size_t> {
size_t loopIdx = 0;
if (loops_.size() > 1) {
auto it = std::ranges::find_if(loopIndices_, [&](const idx_t t) {
return val > t;
});
if (it == loopIndices_.end())
DUNE_THROW(Dune::IOError, "Invalid z-Value");
auto it = std::ranges::find_if(loopIndices_, [&](const idx_t t) { return val > t; });
if (it == loopIndices_.end()) DUNE_THROW(Dune::IOError, "Invalid z-Value");
loopIdx = std::ranges::distance(loopIndices_.begin(), it);
}
// \todo multiplt loop e.g. - size of all loops before
Expand All @@ -77,8 +72,7 @@ namespace Dune::IGANEW::DefaultTrim {

const auto& loops() const { return loops_; }
const auto& clipperLoops() const {
if (not finished_)
DUNE_THROW(Dune::GridError, "Call trimmer.setup() before quering for loops");
if (not finished_) DUNE_THROW(Dune::GridError, "Call trimmer.setup() before quering for loops");
return manager_.loops_;
}

Expand All @@ -92,15 +86,12 @@ namespace Dune::IGANEW::DefaultTrim {
auto getCurve(const std::pair<size_t, size_t>& indices) const -> const TrimmingCurve& {
return loops_[indices.first].curves()[indices.second];
}
auto getSplitter() const -> typename CurveManager::idx_t {
return manager_.splitter_;
}
auto getSplitter() const -> typename CurveManager::idx_t { return manager_.splitter_; }

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

std::ranges::for_each(loops_, [&](const auto& loop) { manager_.addLoop(loop); });

finished_ = true;
}
Expand All @@ -109,7 +100,6 @@ namespace Dune::IGANEW::DefaultTrim {
bool finished_ = false;
std::vector<BoundaryLoop> loops_;
CurveManager manager_;

};

} // namespace Dune::IGANEW::DefaultTrim
22 changes: 11 additions & 11 deletions dune/iga/trimmer/defaulttrimmer/trimelement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,19 @@ namespace Dune::IGANEW::DefaultTrim {
auto getPt = [](auto&& vV) { return vV.pt; };
auto getHostIdx = [](const auto& vV) { return std::get<Util::ClippingResult::HostVertex>(vV).hostIdx; };
auto getEdgeIdx = [](const auto& vV) { return std::get<Util::ClippingResult::NewVertex>(vV).onEdgeIdx; };
auto getTrimmingCurveIdx
= [&](auto& vV) -> std::pair<size_t, size_t> {
return patchTrimData.getIndices(std::get<Util::ClippingResult::NewVertex>(vV).trimmingCurveZ);
};
auto getTrimmingCurveIdx = [&](auto& vV) -> std::pair<size_t, size_t> {
return patchTrimData.getIndices(std::get<Util::ClippingResult::NewVertex>(vV).trimmingCurveZ);
};

///
// Here the actual code is starting
///

// State
std::vector<FieldVector<ScalarType, dim>> foundVertices;
bool isOnNewEdge = false;
bool isOnNewEdge = false;
std::pair currentCurveIdx = {std::numeric_limits<size_t>::infinity(), std::numeric_limits<size_t>::infinity()};
double currentT = std::numeric_limits<double>::infinity();
double currentT = std::numeric_limits<double>::infinity();

for (const auto i : std::views::iota(0u, result.vertices_.size())) {
auto vV1 = result.vertices_[i];
Expand Down Expand Up @@ -90,9 +89,9 @@ namespace Dune::IGANEW::DefaultTrim {
currentCurveIdx = getTrimmingCurveIdx(vV1);
FieldVector<ScalarType, dim> curvePoint;
std::tie(currentT, curvePoint)
= Util::callFindIntersection(patchTrimData.getCurve(currentCurveIdx), getEdgeIdx(vV1), pt1, corners);
= Util::callFindIntersection(patchTrimData.getCurve(currentCurveIdx), getEdgeIdx(vV1), pt1, corners);
std::cout << "Found: " << curvePoint << " From Clipping: " << pt1.x << " " << pt1.y << " t: " << currentT
<< std::endl;
<< std::endl;
foundVertices.push_back(curvePoint);
}
assert(getTrimmingCurveIdx(vV2) == currentCurveIdx);
Expand All @@ -109,7 +108,8 @@ namespace Dune::IGANEW::DefaultTrim {
isOnNewEdge = true;
currentT = tParam;
} else {
auto elementTrimmingCurve = Util::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 All @@ -124,8 +124,8 @@ namespace Dune::IGANEW::DefaultTrim {

FieldVector<ScalarType, dim> p;
if (foundVertices.empty())
std::tie(std::ignore, p)
= Util::callFindIntersection(patchTrimData.getCurve(getTrimmingCurveIdx(vV1)), getEdgeIdx(vV1), pt1, corners);
std::tie(std::ignore, p) = Util::callFindIntersection(patchTrimData.getCurve(getTrimmingCurveIdx(vV1)),
getEdgeIdx(vV1), pt1, corners);
else
p = foundVertices.back();

Expand Down
17 changes: 7 additions & 10 deletions dune/iga/trimmer/defaulttrimmer/trimmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ namespace Dune::IGANEW {
class TrimmerImpl;
template <int dim, int dimworld, typename ScalarType>
struct PatchGridFamily {
using ctype = ScalarType;
static constexpr int patchDim = dim;
static constexpr int worldDim = dimworld;
using Grid = PatchGrid<dim, dimworld, PatchGridFamily, ScalarType>;
using Trimmer = TrimmerImpl<dim, dimworld, ScalarType>;
using ctype = ScalarType;
static constexpr int patchDim = dim;
static constexpr int worldDim = dimworld;
using Grid = PatchGrid<dim, dimworld, PatchGridFamily, ScalarType>;
using Trimmer = TrimmerImpl<dim, dimworld, ScalarType>;

using GlobalIdSet = PatchGridGlobalIdSet<const Grid>;

Expand Down Expand Up @@ -498,16 +498,13 @@ namespace Dune::IGANEW {
GridImp* grid_;

void setup() {
if (trimData_.has_value())
trimData_->prepare(parameters_, untrimmedParameterSpaceGrid_);
if (trimData_.has_value()) trimData_->prepare(parameters_, untrimmedParameterSpaceGrid_);
}
/**
* @brief Change the parameters to the trimmer.
* @param par The parameters.
*/
void setParameters(const ParameterType& par) {
parameters_ = par;
}
void setParameters(const ParameterType& par) { parameters_ = par; }

/**
* @brief Get a const reference to the parameter space grid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Dune::IGANEW::DefaultTrim::Util {
-> std::tuple<ElementTrimFlag, ClippingResult> {
using namespace Clipper2Lib;

auto eleGeo = element.geometry();
auto eleGeo = element.geometry();

PathD eleRect;
for (const auto i : std::views::iota(0u, 4u)) {
Expand Down Expand Up @@ -66,12 +66,11 @@ namespace Dune::IGANEW::DefaultTrim::Util {
return;
}

const auto edgeIdx = giveEdgeIdx(e1bot.z, e1top.z);
const auto curveZ = e2bot.z;
const auto edgeIdx = giveEdgeIdx(e1bot.z, e1top.z);
const auto curveZ = e2bot.z;

// Now check that we don't have a parallel intersection
if (checkParallel(patchTrimData.getCurve(curveZ), edgeIdx))
return;
if (checkParallel(patchTrimData.getCurve(curveZ), edgeIdx)) return;

result.addNewVertex(edgeIdx, pt, curveZ);
});
Expand All @@ -97,15 +96,15 @@ namespace Dune::IGANEW::DefaultTrim::Util {
auto pt = curve.corner(i);
PointD ptClipper{pt[0], pt[1]};

if (auto [isHost, idx] = isHostVertex(ptClipper, eleRect); isHost)
result.addOriginalVertex(idx);
if (auto [isHost, idx] = isHostVertex(ptClipper, eleRect); isHost) result.addOriginalVertex(idx);

for (auto e = 0; e < edgeLookUp.size(); ++e) {
if (const auto& edgeIdx = edgeLookUp[e];
isPointOnLine(pt, eleGeo.corner(edgeIdx.front()), eleGeo.corner(edgeIdx.back()))
isPointOnLine(pt, eleGeo.corner(edgeIdx.front()), eleGeo.corner(edgeIdx.back()))
&& !checkParallel(curve, e)) {
// \todo this needs to be done more generically
const size_t newIdx = i == 0 ? (cI + 1) * patchTrimData.getSplitter() : (cI + 1) * patchTrimData.getSplitter() + patchTrimData.getSplitter() - 1;
const size_t newIdx = i == 0 ? (cI + 1) * patchTrimData.getSplitter()
: (cI + 1) * patchTrimData.getSplitter() + patchTrimData.getSplitter() - 1;
result.addNewVertex(e, ptClipper, newIdx);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion dune/iga/trimmer/defaulttrimmer/trimmingutils/cliputils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace Dune::IGANEW::DefaultTrim::Util {
std::ranges::rotate(vertices_, it);
else
std::cout << "Warning, no HostVertex" << std::endl;
//DUNE_THROW(Dune::NotImplemented, "Algorithm needs at least one HostVertex to work");
// DUNE_THROW(Dune::NotImplemented, "Algorithm needs at least one HostVertex to work");
}

void report() const {
Expand Down
8 changes: 4 additions & 4 deletions dune/iga/trimmer/defaulttrimmer/trimmingutils/trimutils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ namespace Dune::IGANEW::DefaultTrim::Util {
return GeometryKernel::NURBSPatch(patchData);
}

auto callFindIntersection(const auto& curvePatchGeo, const int edgeIdx, const auto& ip,
const auto& corners) -> std::pair<double, FieldVector<double, 2>> {
auto callFindIntersection(const auto& curvePatchGeo, const int edgeIdx, const auto& ip, const auto& corners)
-> std::pair<double, FieldVector<double, 2>> {
// @todo gerneralize for more than one loop
auto pos = corners[edgeIdx];
auto dir = edgeDirections[edgeIdx];
auto pos = corners[edgeIdx];
auto dir = edgeDirections[edgeIdx];

auto guessTParam = FieldVector<double, 2>{findGoodStartingPoint(curvePatchGeo, ip), 0.5};

Expand Down
3 changes: 2 additions & 1 deletion dune/iga/trimmer/identitytrimmer/trimmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ namespace Dune::IGANEW {
* @param patch NURBS patch data.
* @param trimData Optional patch trim data.
*/
TrimmerImpl(GridImp& grid, const std::optional<typename GridFamily::PatchTrimData>& trimData, const ParameterType& par = {})
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 Down

0 comments on commit ba84e38

Please sign in to comment.