Skip to content
Snippets Groups Projects
Commit 6172bc7e authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'feature/more-examples' into 'master'

Add example for flat torus and graph parametrization

See merge request !15
parents dc2452c0 b3163b17
No related branches found
No related tags found
1 merge request!15Add example for flat torus and graph parametrization
Pipeline #6591 passed
......@@ -77,16 +77,16 @@ void graph()
YaspGrid<2> refGrid({4.0*M_PI, 4.0*M_PI}, {8, 8});
// 2. Define the geometry mapping
auto torus = [](const FieldVector<double,2>& u)
auto g = [](const FieldVector<double,2>& u)
{
return FieldVector<double,3>{u[0], u[1],
std::sin(u[0])*std::cos(u[1])
};
};
auto torusGF = analyticDiscreteFunction(torus, refGrid, /*order*/ 3);
auto gGF = analyticDiscreteFunction(g, refGrid, /*order*/ 3);
// 3. Wrap the reference grid to build a curved grid
CurvedGrid grid{refGrid, torusGF};
CurvedGrid grid{refGrid, gGF};
write_grid<3>(grid, "graph.vtu");
}
......
......@@ -19,10 +19,41 @@
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/io/file/vtk.hh>
using namespace Dune;
namespace Dune {
namespace Curved {
struct Torus
{
double const r1 = 2.0, r2 = 1.0;
auto operator() (FieldVector<double,2> const& u) const
{
return FieldVector<double,3>{
(r1 + r2*std::cos(u[0])) * std::cos(u[1]),
(r1 + r2*std::cos(u[0])) * std::sin(u[1]),
r2*std::sin(u[0])
};
}
friend auto derivative (Torus t)
{
return [r1=t.r1,r2=t.r2](FieldVector<double,2> const& u)
{
return FieldMatrix<double,3,2>{
{-r2*std::sin(u[0])*std::cos(u[1]),-(r1 + r2*std::cos(u[0]))*std::sin(u[1])},
{-r2*std::sin(u[0])*std::sin(u[1]), (r1 + r2*std::cos(u[0]))*std::cos(u[1])},
{ r2*std::cos(u[0]), 0.0}
};
};
}
};
}}
int main(int argc, char** argv)
{
using namespace Dune;
MPIHelper::instance(argc, argv);
// 1. Construct a reference grid [0,1]x[0,1]
......@@ -32,16 +63,10 @@ int main(int argc, char** argv)
CurvedGrid grid1{grid0, [](auto const& x) { return (2.0*M_PI)*x; }, 1};
// 2. Define the geometry mapping
auto torus = [](FieldVector<double,2> const& u) {
return FieldVector<double,3>{
(2 + std::cos(u[0])) * std::cos(u[1]),
(2 + std::cos(u[0])) * std::sin(u[1]),
std::sin(u[0])
};
};
auto torus = Curved::Torus{};
// 3. Wrap the reference grid to build a curved grid, with Lagrange elements of order 3
CurvedGrid grid2{grid1, torus, 3};
CurvedGrid grid2{grid1, torus};
// 4. Write grid to vtu file
SubsamplingVTKWriter writer{grid2.leafGridView(), refinementIntervals(3)};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment