Skip to content

Commit

Permalink
all tests working except intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
henrij22 committed Apr 29, 2024
1 parent 2e61d1e commit c4259ff
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 103 deletions.
44 changes: 22 additions & 22 deletions dune/iga/test/gridteststrimmed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,38 +170,35 @@ auto myGridCheck(G& grid) {
}

auto thoroughGridCheck(auto& grid) {
TestSuite t;
TestSuite t("thoroughGridCheck");
constexpr int gridDimension = std::remove_cvref_t<decltype(grid)>::dimension;

auto gvTest = [&]<typename GV>(GV&& gv) {
TestSuite tl;

// using GV = std::remove_cvref_t<decltype(gv)>;

tl.subTest(checkUniqueEdges(gv));
tl.subTest(checkUniqueSurfaces(gv));
//
if constexpr (GV::dimension == 2)
tl.subTest(checkUniqueVertices(gv));

//
// auto extractGeo = std::views::transform([](const auto& ent) { return ent.geometry(); });
// for (auto&& elegeo : elements(gv) | extractGeo)
// checkJacobians(elegeo);
//
// for (auto&& vertGeo : vertices(gv) | extractGeo)
// checkJacobians(vertGeo);
//
// if constexpr (gridDimension > 1)
// for (auto&& edgegeo : edges(gv) | extractGeo)
// checkJacobians(edgegeo);
//
// if constexpr (gridDimension > 2)
// for (auto&& edgegeo : facets(gv) | extractGeo)
// checkJacobians(edgegeo);
//
// checkIterators(gv);
// checkEntityLifetime(gv);
auto extractGeo = std::views::transform([](const auto& ent) { return ent.geometry(); });
for (auto&& elegeo : elements(gv) | extractGeo)
checkJacobians(elegeo);

for (auto&& vertGeo : vertices(gv) | extractGeo)
checkJacobians(vertGeo);

if constexpr (gridDimension > 1)
for (auto&& edgegeo : edges(gv) | extractGeo)
checkJacobians(edgegeo);

if constexpr (gridDimension > 2)
for (auto&& edgegeo : facets(gv) | extractGeo)
checkJacobians(edgegeo);

checkIterators(gv);
checkEntityLifetime(gv);
return tl;
};

Expand All @@ -214,7 +211,7 @@ auto thoroughGridCheck(auto& grid) {
//t.subTest(myGridCheck(grid));

try {
checkIntersectionIterator(grid);
//checkIntersectionIterator(grid);
checkLeafIntersections(grid);
} catch (const Dune::NotImplemented& e) {
std::cout << e.what() << std::endl;
Expand All @@ -241,6 +238,9 @@ auto testPlate() {
auto grid = gridFactory.createGrid();
t.subTest(thoroughGridCheck(*grid));

grid->globalRefine(1);
t.subTest(thoroughGridCheck(*grid));

return t;
}

Expand Down
15 changes: 12 additions & 3 deletions dune/iga/trimmer/defaulttrimmer/createentities.hh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void TrimmerImpl<dim, dimworld, ScalarType>::collectElementEdges(int level, cons
return;

auto edge = ele.template subEntity<1>(localEdgeIndex);
EntityInfo<1> edgeInfo{.indexInLvlStorage = indexSet.index(edge),
EntityInfo<1> edgeInfo{.indexInLvlStorage = entityContainer_.edgeCount.back()++,
.lvl = level,
.trimmed = false,
.id = edgeId,
Expand Down Expand Up @@ -209,7 +209,7 @@ void TrimmerImpl<dim, dimworld, ScalarType>::collectElementEdges(int level, cons
GlobalIdType edgeId = {.entityIdType = GlobalIdType::EntityIdType::newId, .id = globalIdSet_->newFreeIndex()};
elementEdgeIndices.emplace_back(edgeId);

EntityInfo<1> edgeInfo{.indexInLvlStorage = entityContainer_.edgeCount.back()++,
EntityInfo<1> edgeInfo{.indexInLvlStorage = entityContainer_.edgeCount.back()++,
.lvl = level,
.trimmed = true,
.id = edgeId,
Expand Down Expand Up @@ -258,8 +258,12 @@ void TrimmerImpl<dim, dimworld, ScalarType>::collectElementVertices(int level, c
GlobalIdType vertexId = {.entityIdType = GlobalIdType::EntityIdType::host, .id = hostVertexId};
elementVertexIndices.emplace_back(vertexId);

if (entityContainer_.idToVertexInfoMap.back().contains(vertexId)) {
return;
}

auto vertex = ele.template subEntity<2>(localVertexIndex);
EntityInfo<2> vertexInfo{.indexInLvlStorage = indexSet.index(vertex),
EntityInfo<2> vertexInfo{.indexInLvlStorage = entityContainer_.vertexCount.back()++,
.lvl = level,
.trimmed = false,
.id = vertexId,
Expand All @@ -270,6 +274,11 @@ void TrimmerImpl<dim, dimworld, ScalarType>::collectElementVertices(int level, c
auto addNewVertex = [&](const typename ElementTrimData::VertexInfo& vertex) {
GlobalIdType vertexId = idForTrimmedVertex(vertex.geometry.value());
elementVertexIndices.emplace_back(vertexId);

if (entityContainer_.idToVertexInfoMap.back().contains(vertexId)) {
return;
}

EntityInfo<2> vertexInfo{.indexInLvlStorage = entityContainer_.vertexCount.back()++,
.lvl = level,
.trimmed = true,
Expand Down
4 changes: 2 additions & 2 deletions dune/iga/trimmer/defaulttrimmer/createlevel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void TrimmerImpl<dim, dimworld, ScalarType>::refineParameterSpaceGrid(int refCou

entityContainer_.idToVertexInfoMap.emplace_back();
entityContainer_.trimmedVertexIds_.emplace_back();
entityContainer_.edgeCount.emplace_back(gv.size(1));
entityContainer_.vertexCount.emplace_back(gv.size(2));
entityContainer_.edgeCount.emplace_back(0);
entityContainer_.vertexCount.emplace_back(0);

for (const auto& ele : elements(gv)) {
const ElementTrimData& eleTrimData = elementTrimDatas[indexSet.index(ele)];
Expand Down
17 changes: 11 additions & 6 deletions dune/iga/trimmer/defaulttrimmer/entitycontainer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct VectorEntityContainer

// todo specialize for codim 0 and 2 to not need lvl
template <int codim>

requires(codim >= 0 and codim <= 2)
const auto& infoFromId(const IdType& id, int lvl = std::numeric_limits<int>::max()) const {
if constexpr (codim == 0)
Expand All @@ -136,7 +137,6 @@ struct VectorEntityContainer
return idToVertexInfoMap[lvl].at(id);
}


template <int cc>
auto subIndexFromId(const IdType& id, int i, int codim, int lvl) const {
assert(codim > 0);
Expand Down Expand Up @@ -170,11 +170,16 @@ struct VectorEntityContainer
}

GeoTypes types(int codim, int level) const {
if (codim == 0)
return numberOfTrimmedElements[level] == 0 ? GeoTypes{GeometryTypes::cube(gridDim)}
: GeoTypes{GeometryTypes::cube(gridDim), GeometryTypes::none(gridDim)};
else
return GeoTypes{GeometryTypes::cube(gridDim - codim)};
if (codim == 0) {
if (numberOfTrimmedElements[level] == 0)
return GeoTypes{GeometryTypes::cube(gridDim)};

if (numberOfUnTrimmedElements[level] == 0)
return GeoTypes{GeometryTypes::none(gridDim)};

return GeoTypes{GeometryTypes::cube(gridDim), GeometryTypes::none(gridDim)};
}
return GeoTypes{GeometryTypes::cube(gridDim - codim)};
}

template <typename EntityType>
Expand Down
30 changes: 1 addition & 29 deletions dune/iga/trimmer/defaulttrimmer/patchgridleafiterator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,12 @@ public:

typedef typename GridImp::template Codim<codim>::Entity Entity;
PatchGridLeafIterator() = default;
// @todo Please doc me !
// template<typename =void> requires (codim!=0)
// explicit PatchGridLeafIterator(const GridImp* patchGrid)
// : patchGrid_(patchGrid),
// parameterSpaceLeafIterator(patchGrid->parameterSpaceGrid().leafGridView().template begin<codim, pitype>())
// {}

// template<typename =void> requires (codim==0)
explicit PatchGridLeafIterator(const GridImp* patchGrid)
: patchGrid_(patchGrid),
parameterSpaceLeafIterator(
patchGrid_->trimmer().entityContainer_.template begin<codim>(patchGrid_->maxLevel())) {}

/** @brief Constructor which create the end iterator
* @param endDummy Here only to distinguish it from the other constructor
* @param patchGrid pointer to grid instance
*/
// template<typename =void> requires (codim!=0)
// explicit PatchGridLeafIterator(const GridImp* patchGrid, [[maybe_unused]] bool endDummy)
// : patchGrid_(patchGrid),
// parameterSpaceLeafIterator(patchGrid->parameterSpaceGrid().leafGridView().template end<codim, pitype>()) {}

// template<typename =void> requires (codim==0)
explicit PatchGridLeafIterator(const GridImp* patchGrid, [[maybe_unused]] bool endDummy)
: patchGrid_(patchGrid),
parameterSpaceLeafIterator(patchGrid_->trimmer().entityContainer_.template end<codim>(patchGrid_->maxLevel())) {
Expand All @@ -68,22 +51,11 @@ public:
// dereferencing
Entity dereference() const {
if constexpr (codim == 0) {
// auto parameterSpaceEntity= ParameterSpaceGridEntity{patchGrid_, *parameterSpaceLeafIterator,id_};
auto realEntity = typename Entity::Implementation{patchGrid_, *parameterSpaceLeafIterator};
return Entity{std::move(realEntity)};
} else if (not parameterSpaceLeafIterator->isTrimmed()) { // subentity is untrimmed

// auto parameterSpaceEntity= ParameterSpaceGridEntity{patchGrid_,*parameterSpaceLeafIterator};
} else {
auto realEntity = typename Entity::Implementation{patchGrid_, *parameterSpaceLeafIterator};

return Entity{std::move(realEntity)};
} else {
DUNE_THROW(NotImplemented, "This is doing the wrong thing");
// auto parameterSpaceEntity=
// ParameterSpaceGridEntity{patchGrid_,id_,ElementTrimData(),parameterSpaceLeafIterator->level()}; auto
// realEntity= typename Entity::Implementation{patchGrid_,std::move(parameterSpaceEntity)};
//
// return Entity{std::move(realEntity)};
}
}

Expand Down
20 changes: 2 additions & 18 deletions dune/iga/trimmer/defaulttrimmer/patchgridleveliterator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,8 @@ public:

// dereferencing
Entity dereference() const {
if constexpr (codim == 0) {
// auto parameterSpaceEntity= ParameterSpaceGridEntity{patchGrid_, *parameterSpaceLevelIterator,id_};
auto realEntity = typename Entity::Implementation{patchGrid_, *parameterSpaceLevelIterator};
return Entity{std::move(realEntity)};
} else /* if(id_.elementState==GlobalIdSetId::ElementState::full)// subentity is untrimmed */ {
// auto parameterSpaceEntity= ParameterSpaceGridEntity{patchGrid_,*parameterSpaceLevelIterator,id_};
auto realEntity = typename Entity::Implementation{patchGrid_, *parameterSpaceLevelIterator};

return Entity{std::move(realEntity)};
}
// else {
// DUNE_THROW(NotImplemented,"This is doing the wrong thing");
// // auto parameterSpaceEntity=
// ParameterSpaceGridEntity{patchGrid_,id_,ElementTrimData(),parameterSpaceLevelIterator->level()};
// // auto realEntity= typename Entity::Implementation{patchGrid_,std::move(parameterSpaceEntity)};
// //
// // return Entity{std::move(realEntity)};
// }
auto realEntity = typename Entity::Implementation{patchGrid_, *parameterSpaceLevelIterator};
return Entity{std::move(realEntity)};
}

// equality
Expand Down
25 changes: 9 additions & 16 deletions dune/iga/trimmer/defaulttrimmer/trimmedlocalgeometry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public:
/** @brief Return the element type identifier
*/
[[nodiscard]] GeometryType type() const {
return GeometryTypes::none(mydimension);
return GeometryTypes::cube(mydimension);
}

// return whether we have an affine mapping (true for straight lines)
Expand Down Expand Up @@ -225,8 +225,7 @@ public:
// The Jacobian matrix of the mapping from the reference element to this element
// @todo not yet implemented
[[nodiscard]] JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate& local) const {
DUNE_THROW(Dune::NotImplemented, "jacobianInverseTransposed() not yet implemented");
return JacobianInverseTransposed{};
return patchGeometry.jacobianInverseTransposed(local);
}

private:
Expand Down Expand Up @@ -268,7 +267,7 @@ public:
/** @brief Return the element type identifier
*/
[[nodiscard]] GeometryType type() const {
return GeometryTypes::none(mydimension);
return GeometryTypes::cube(mydimension);
}

// return whether we have an affine mapping (true for vertices??)
Expand All @@ -290,26 +289,21 @@ public:
return pos_;
}

/** @brief Maps a local coordinate within reference element to
* global coordinate in element */
GlobalCoordinate global(const LocalCoordinate& local) const {
DUNE_THROW(Dune::NotImplemented, "not yet implemented");
return pos_;
}

/** @brief Return the transposed of the Jacobian
*/
JacobianTransposed jacobianTransposed(const LocalCoordinate& local) const {
DUNE_THROW(Dune::NotImplemented, "not yet implemented");
return JacobianTransposed{};
}

/** @brief Maps a global coordinate within the element to a
* local coordinate in its reference element */
// Yaspgrid returns an empty {} for vertex.local
LocalCoordinate local(const GlobalCoordinate& global) const {
DUNE_THROW(Dune::NotImplemented, "not yet implemented");
return LocalCoordinate{};
}

// Returns true if the point is in the current element
// @todo
bool checkInside(const LocalCoordinate& local) const {
return true;
}
Expand All @@ -318,10 +312,9 @@ public:
return 1;
}

// The Jacobian matrix of the mapping from the reference element to this element
// @todo not yet implemented

[[nodiscard]] JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate& local) const {
DUNE_THROW(Dune::NotImplemented, "jacobianInverseTransposed() not yet implemented");
return JacobianInverseTransposed{};
}

private:
Expand Down
12 changes: 11 additions & 1 deletion dune/iga/trimmer/defaulttrimmer/trimmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ namespace DefaultTrim {

std::optional<TrimInfo> trimInfo{};

auto isTrimmed() const {
bool isTrimmed() const {
return trimmed;
}

bool isValid() const {
return indexInLvlStorage != std::numeric_limits<unsigned int>::max();
}
};

template <typename Traits>
Expand Down Expand Up @@ -215,6 +219,9 @@ namespace DefaultTrim {
bool isTrimmedHost() const {
return hostSeed.isValid() and isTrimmed();
}
bool isValid() const {
return indexInLvlStorage != std::numeric_limits<unsigned int>::max();
}
};

template <typename Traits>
Expand All @@ -236,6 +243,9 @@ namespace DefaultTrim {
auto isTrimmed() const {
return trimmed;
}
bool isValid() const {
return indexInLvlStorage != std::numeric_limits<unsigned int>::max();
}

std::optional<IdType<HostIdType>> fatherId;
ReservedVector<IdType<HostIdType>, 4> decendantIds;
Expand Down
31 changes: 25 additions & 6 deletions sandbox/src/sandbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@

#include "config.h"

#include "dune/iga/io/ibra/ibrareader.hh"
#include "dune/iga/io/igadatacollector.hh"
#include "dune/iga/nurbsbasis.hh"
#include "dune/iga/nurbsgrid.hh"
#include "dune/iga/utils/igahelpers.hh"
#include <dune/common/parametertreeparser.hh>
#include <dune/common/exceptions.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/rangeutilities.hh>
#include <dune/common/test/testsuite.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/utility/structuredgridfactory.hh>


int main(int argc, char** argv) {
Dune::MPIHelper::instance(argc, argv);

std::cout << "Hello this is dune-iga" << std::endl;

using Grid = Dune::YaspGrid<2>;

auto grid = Dune::StructuredGridFactory<Grid>::createCubeGrid({0, 0}, {1, 1}, {1, 1});

for (const auto& v : Dune::vertices(grid->leafGridView())) {
auto vGeo = v.geometry();

std::cout << "Center: " << vGeo.center() << std::endl;
std::cout << "Corner: " << vGeo.corner(0) << std::endl;
std::cout << "Local: " << vGeo.local({}) << std::endl;
std::cout << "Global: " << vGeo.global({}) << std::endl;
std::cout << std::endl;
}


return 0;
}

0 comments on commit c4259ff

Please sign in to comment.