-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
162 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// SPDX-FileCopyrightText: 2023 The dune-iga developers [email protected] | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#pragma once | ||
|
||
#include <dune/iga/io/vtk/vtkrefinedgeometries.hh> | ||
|
||
namespace Dune::IGA { | ||
|
||
namespace Impl { | ||
struct Comparator | ||
{ | ||
bool operator()(const Dune::FieldVector<double, 2>& p1, const Dune::FieldVector<double, 2>& p2) const { | ||
if (p1[0] < p2[0]) | ||
return true; | ||
if (p1[0] > p2[0]) | ||
return false; | ||
return p1[1] < p2[1]; | ||
}; | ||
}; | ||
} // namespace Impl | ||
|
||
template <typename UnstructuredGrid, typename PatchGrid> | ||
std::unique_ptr<UnstructuredGrid> createUnstructuredGridImpl(PatchGrid* patchGrid) { | ||
auto gridView = patchGrid->leafGridView(); | ||
auto& idSet = patchGrid->globalIdSet(); | ||
|
||
IGARefinedGeometries geometries(gridView, 0, 0); | ||
|
||
std::set<FieldVector<double, 2>, Impl::Comparator> vertices; | ||
|
||
for (const auto& element : elements(gridView)) { | ||
auto id = idSet.id(element); | ||
auto geometry = element.geometry(); | ||
|
||
std::ranges::transform(geometries.getVertices(id), std::inserter(vertices, vertices.begin()), | ||
[&](const auto& v) { return geometry.global(v); }); | ||
} | ||
|
||
auto gridFactory = Dune::GridFactory<UnstructuredGrid>(); | ||
|
||
for (const auto& v : vertices) { | ||
gridFactory.insertVertex(v); | ||
} | ||
|
||
|
||
// Reconstruct grid | ||
for (const auto& element : elements(gridView)) { | ||
auto geometry = element.geometry(); | ||
auto id = idSet.id(element); | ||
|
||
auto gt = geometries.geometryType(id); | ||
unsigned int nSubI = gt == GeometryTypes::simplex(2) ? 3 : 4; | ||
|
||
auto& eleVertices = geometries.getVertices(id); | ||
|
||
for (auto subEleIdx : std::views::iota(0u, geometries.nElements(id))) { | ||
std::vector<unsigned int> elementVertices; | ||
|
||
for (auto subEntityIndex : std::views::iota(0u, nSubI)) { | ||
auto localVertexIdx = geometries.vertexSubIndex(id, subEleIdx, subEntityIndex); | ||
Dune::FieldVector<double, 2> vertex = geometry.global(eleVertices[localVertexIdx]); | ||
|
||
// Find Idx | ||
auto it = vertices.find(vertex); | ||
assert(it != vertices.end()); | ||
|
||
elementVertices.push_back(std::distance(vertices.begin(), it)); | ||
} | ||
gridFactory.insertElement(gt, elementVertices); | ||
} | ||
} | ||
|
||
return gridFactory.createGrid(); | ||
|
||
|
||
} | ||
} // namespace Dune::IGA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-FileCopyrightText: 2023 The Ikarus Developers [email protected] | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
#define DUNE_CHECK_BOUNDS | ||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "testhelper.hh" | ||
|
||
#include <cfenv> | ||
|
||
#include <dune/common/exceptions.hh> | ||
#include <dune/common/float_cmp.hh> | ||
#include <dune/common/fvector.hh> | ||
#include <dune/common/parallel/mpihelper.hh> | ||
#include <dune/common/test/testsuite.hh> | ||
#include <dune/iga/hierarchicpatch/patchgridfactory.hh> | ||
#include <dune/iga/io/griddrawer.hh> | ||
#include <dune/iga/io/vtk/igadatacollector.hh> | ||
#include <dune/iga/patchgrid.hh> | ||
#include <dune/iga/trimmer/defaulttrimmer/trimmer.hh> | ||
#include <dune/iga/trimmer/identitytrimmer/trimmer.hh> | ||
#include <dune/vtk/vtkwriter.hh> | ||
#include <dune/grid/uggrid.hh> | ||
|
||
using namespace Dune::IGA; | ||
|
||
|
||
auto testUnstructuredGridCreation() { | ||
Dune::TestSuite t("", Dune::TestSuite::ThrowPolicy::ThrowOnRequired); | ||
|
||
using PatchGrid = PatchGrid<2, 2, DefaultTrim::PatchGridFamily>; | ||
using GridFactory = Dune::GridFactory<PatchGrid>; | ||
|
||
auto gridFactory = GridFactory(); | ||
gridFactory.insertTrimParameters(typename GridFactory::TrimParameterType{100}); | ||
|
||
gridFactory.insertJson("auxiliaryfiles/quarter_plate.ibra", true, {3, 3}); | ||
|
||
auto grid = gridFactory.createUnstructedGrid<Dune::UGGrid<2>>(); | ||
|
||
Dune::Vtk::VtkWriter writer(grid->leafGridView()); | ||
writer.write("out/unstructuredGrid"); | ||
|
||
return t; | ||
} | ||
|
||
|
||
int main(int argc, char** argv) try { | ||
// feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); | ||
|
||
// Initialize MPI, if necessary | ||
Dune::MPIHelper::instance(argc, argv); | ||
Dune::TestSuite t("", Dune::TestSuite::ThrowPolicy::ThrowOnRequired); | ||
|
||
createOutputFolder("out"); | ||
Preferences::getInstance().targetAccuracy(1e-3); | ||
|
||
t.subTest(testUnstructuredGridCreation()); | ||
|
||
|
||
t.report(); | ||
|
||
return t.exit(); | ||
} catch (Dune::Exception& e) { | ||
std::cerr << "Dune reported error: " << e << std::endl; | ||
return 1; | ||
} |