Commit 18d9ad99 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'feature/curvedgeometry3' into 'master'

Curved Geometry from LocalFunction

See merge request iwr/dune-curvedsurfacegrid!5
parents 3123de92 c3a618bf
from sympy import *
import numpy as np
import collections
x, y, z = symbols("x y z")
a, b, c = symbols("a b c")
# simplify entries of an array
def simplify_all(A):
if isinstance(A, collections.Iterable):
return list(map(lambda a: simplify_all(a), A))
else:
return simplify(A)
def add(A,B):
if isinstance(A, collections.Iterable):
return list(map(lambda a,b: add(a,b), A,B))
else:
return A + B
def negate(A):
if isinstance(A, collections.Iterable):
return list(map(lambda a: negate(a), A))
else:
return -A
X = [x,y,z]
# normal vector
div = sqrt(b**4*c**4*x**2 + a**4*c**4*y**2 + a**4*b**4**z**2)
N = [b**2*c**2*x/div, a**2*c**2*y/div, a**2*b**2*z/div]
print("N = ")
print("return {")
for i in range(3):
print(" ",ccode(N[i]),",")
print("};")
print("")
# projection
P = [[ (1 if i==j else 0) - N[i]*N[j] for j in range(3)] for i in range(3)]
# parametrization
nrm_X = sqrt(x**2 + y**2 + z**2)
X0 = [x/nrm_X, y/nrm_X, z/nrm_X]
u = atan(X0[1]/X0[0])
v = acos(X0[2])
X1 = [a*cos(u)*sin(v), b*sin(u)*sin(v), c*cos(v)]
# jacobian of parametrization
J = [[diff(X1[i],X[j]) for i in range(3)] for j in range(3)]
print("J = ")
print("return {")
for i in range(3):
print(" {")
for j in range(3):
print(" ",ccode(simplify(J[i][j])),",")
print(" },")
print("};")
print("")
# P(F)_j
def project1(F):
return simplify_all([
np.sum([
P[i][j] * F[i]
for i in range(3)])
for j in range(3)])
# P(F)_kl
def project2(F):
return simplify_all([[
np.sum([np.sum([
P[i][k] * P[j][l] * F[i][j]
for j in range(3)]) for i in range(3)])
for l in range(3)] for k in range(3)])
# P(F)_lmn
def project3(F):
return simplify_all([[[
np.sum([np.sum([np.sum([
P[i][l] * P[j][m] * P[k][n] * F[i][j][k]
for k in range(3)]) for j in range(3)]) for i in range(3)])
for n in range(3)] for m in range(3)] for l in range(3)])
# P(F)_mnop
def project4(F):
return simplify_all([[[[
np.sum([np.sum([np.sum([np.sum([
P[i][m] * P[j][n] * P[k][o] * P[l][p] * F[i][j][k][l]
for l in range(3)]) for k in range(3)]) for j in range(3)]) for i in range(3)])
for p in range(3)] for o in range(3)] for n in range(3)] for m in range(3)])
# Euclidean gradient
def Grad0(f):
return simplify_all([
diff(f, X[i])
for i in range(3)])
# surface gradient (covariant derivative of scalars)
def grad0(f):
return project1(Grad0(f))
def Grad1(T):
return simplify_all([[
diff(T[i], X[j])
for j in range(3)] for i in range(3)])
# surface shape operator
#B = negate(project2(Grad1(N)))
# covariant derivative of vector field
def grad1(T):
return simplify_all(add(project2(Grad1(T)), [[
np.sum([
B[i][j] * T[k] * N[k]
for k in range(3)])
for j in range(3)] for i in range(3)]))
def Grad2(T):
return simplify_all([[[
diff(T[i][j], X[k])
for k in range(3)] for j in range(3)] for i in range(3)])
def grad2(T):
return simplify_all([[[
np.sum([np.sum([np.sum([
P[L1][I1] * P[L2][I2] * P[L3][K] * diff(T[L1][L2], X[L3])
for L3 in range(3)]) for L2 in range(3)]) for L1 in range(3)]) +
np.sum([np.sum([
B[K][I1] * P[J2][I2] * T[L][J2] * N[L]
for J2 in range(3)]) for L in range(3)]) +
np.sum([np.sum([
B[K][I2] * P[J1][I1] * T[J1][L] * N[L]
for J1 in range(3)]) for L in range(3)])
for K in range(3)] for I2 in range(3)] for I1 in range(3)])
def Grad3(T):
return simplify_all([[[[
diff(T[i][j][k], X[l])
for l in range(3)] for k in range(3)] for j in range(3)] for i in range(3)])
def grad3(T):
return simplify_all(add(project4(Grad3(T)), [[[[
np.sum([np.sum([np.sum([
B[K][I1] * P[J2][I2] * P[J3][I3] * T[L][J2][J3] * N[L]
for J2 in range(3)]) for J3 in range(3)]) for L in range(3)]) +
np.sum([np.sum([np.sum([
B[K][I2] * P[J1][I1] * P[J3][I3] * T[J1][L][J3] * N[L]
for J1 in range(3)]) for J3 in range(3)]) for L in range(3)]) +
np.sum([np.sum([np.sum([
B[K][I3] * P[J1][I1] * P[J2][I2] * T[J1][J2][L] * N[L]
for J1 in range(3)]) for J2 in range(3)]) for L in range(3)])
for K in range(3)] for I3 in range(3)] for I2 in range(3)] for I1 in range(3)]))
# normal-rotation of scalar field
def rot0(f):
return [diff(f*N[2],y) - diff(f*N[1],z),
diff(f*N[0],z) - diff(f*N[2],x),
diff(f*N[1],x) - diff(f*N[0],y)]
def Div1(F):
return diff(F[0],x) + diff(F[1],y) + diff(F[2],z)
def div1(F):
return Div1(project1(F))
# def div2(t):
# F = Matrix([div1(t.row(0).T), div1(t.row(1).T), div1(t.row(2).T)])
# return P*F
# div(T)_I1,I2
def div3(T):
return simplify_all([[
np.sum([np.sum([np.sum([np.sum([np.sum([
P[L1][I1] * P[L2][I2] * P[L3][K] * P[L4][K] * diff(T[L1][L2][L3],X[L4])
for K in range(3)]) for L4 in range(3)]) for L3 in range(3)]) for L2 in range(3)]) for L1 in range(3)]) +
np.sum([np.sum([
B[I3][I1] * T[L][I2][I3] * N[L] +
B[I3][I2] * T[I1][L][I3] * N[L] +
B[I3][I3] * T[I1][I2][L] * N[L]
for I3 in range(3)]) for L in range(3)])
for I2 in range(3)] for I1 in range(3)])
#p0 = simplify_all( rot0(x*y*z) ) # => vector
#print("p0 = ", p0)
# p1 = simplify_all( grad1(p0) ) # => 2-tensor
# print("p1 = ", p1)
# f = simplify_all( add(negate(div3(grad2(p1))), p1) )
# print("f = ", f)
#F = simplify( -div2(grad1(p0)) + p0 )
#print("F = ", F)
#print("F*N = ", simplify(F.dot(N)))
\ No newline at end of file
...@@ -7,5 +7,5 @@ Module: dune-curvedsurfacegrid ...@@ -7,5 +7,5 @@ Module: dune-curvedsurfacegrid
Version: 0.1.0 Version: 0.1.0
Maintainer: florian.stenger@tu-dresden.de Maintainer: florian.stenger@tu-dresden.de
#depending on #depending on
Depends: dune-common dune-geometry dune-grid dune-localfunctions dune-curvilineargeometry Depends: dune-common dune-geometry dune-grid dune-localfunctions dune-curvedgeometry dune-functions
Suggests: dune-alugrid dune-foamgrid Suggests: dune-alugrid dune-foamgrid
add_subdirectory(surfacedistance)
add_subdirectory(test)
set(HEADERS install(FILES
backuprestore.hh backuprestore.hh
capabilities.hh capabilities.hh
concepts.hh
coordfunctionimplementations.hh coordfunctionimplementations.hh
coordprovider.hh
curvedsurfacegrid.hh curvedsurfacegrid.hh
datahandle.hh datahandle.hh
declaration.hh declaration.hh
...@@ -20,7 +18,9 @@ set(HEADERS ...@@ -20,7 +18,9 @@ set(HEADERS
intersection.hh intersection.hh
intersectioniterator.hh intersectioniterator.hh
iterator.hh iterator.hh
) localgeometrywrapper.hh
install(FILES ${HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/curvedsurfacegrid) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/curvedsurfacegrid)
add_subdirectory(gridfunctions)
add_subdirectory(surfacedistance)
add_subdirectory(test)
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2: // vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CRVSRF_BACKUPRESTORE_HH #ifndef DUNE_CURVED_SURFACE_GRID_BACKUPRESTORE_HH
#define DUNE_CRVSRF_BACKUPRESTORE_HH #define DUNE_CURVED_SURFACE_GRID_BACKUPRESTORE_HH
#include <dune/grid/common/backuprestore.hh> #include <dune/grid/common/backuprestore.hh>
...@@ -9,84 +9,80 @@ ...@@ -9,84 +9,80 @@
namespace Dune namespace Dune
{ {
namespace Curved
namespace crvsrf
{ {
// BackupRestoreFacilities // BackupRestoreFacilities
// ----------------------- // -----------------------
template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities< Grid > ::v > template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities<Grid> ::v >
class BackupRestoreFacilities class BackupRestoreFacilities
{}; {};
template< class Grid > template< class Grid >
class BackupRestoreFacilities< Grid, true > class BackupRestoreFacilities<Grid, true>
{ {
typedef BackupRestoreFacilities< Grid, true > This; using Self = BackupRestoreFacilities<Grid, true>;
protected: protected:
BackupRestoreFacilities () BackupRestoreFacilities ()
{} {}
private: private:
BackupRestoreFacilities ( const This & ); BackupRestoreFacilities (const Self&);
This &operator= ( const This & ); Self& operator= (const Self&);
protected: protected:
const Grid &asImp () const const Grid& asImp () const
{ {
return static_cast< const Grid & >( *this ); return static_cast<const Grid&>(*this);
} }
Grid &asImp () Grid& asImp ()
{ {
return static_cast< Grid & >( *this ); return static_cast<Grid&>(*this);
} }
}; };
} // namespace crvsrf } // namespace Curved
// BackupRestoreFacility for CurvedSurfaceGrid // BackupRestoreFacility for CurvedSurfaceGrid
// ------------------------------------------- // -------------------------------------------
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator > template< class GridFunction, int order >
struct BackupRestoreFacility< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > > struct BackupRestoreFacility<CurvedSurfaceGrid<GridFunction, order>>
{ {
typedef CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > Grid; using Grid = CurvedSurfaceGrid<GridFunction, order>;
typedef BackupRestoreFacility< HostGrid > HostBackupRestoreFacility; using HostGrid = typename Grid::HostGrid;
using HostBackupRestoreFacility = BackupRestoreFacility<HostGrid>;
static void backup ( const Grid &grid, const std::string &filename ) static void backup (const Grid& grid, const std::string& filename)
{ {
// notice: We should also backup the coordinate function // notice: We should also backup the coordinate function
HostBackupRestoreFacility::backup( grid.hostGrid(), filename ); HostBackupRestoreFacility::backup(grid.hostGrid(), filename);
} }
static void backup ( const Grid &grid, const std::ostream &stream ) static void backup (const Grid& grid, const std::ostream& stream)
{ {
// notice: We should also backup the coordinate function // notice: We should also backup the coordinate function
HostBackupRestoreFacility::backup( grid.hostGrid(), stream ); HostBackupRestoreFacility::backup(grid.hostGrid(), stream);
} }
static Grid *restore ( const std::string &filename ) static Grid* restore (const std::string& filename)
{ {
// notice: We should also restore the coordinate function assert(false && "Restore not yet implemented for CurvedSurfaceGrid");
HostGrid *hostGrid = HostBackupRestoreFacility::restore( filename ); return nullptr;
CoordFunction *coordFunction = new CoordFunction();
return new Grid( hostGrid, coordFunction );
} }
static Grid *restore ( const std::istream &stream ) static Grid* restore (const std::istream& stream)
{ {
// notice: We should also restore the coordinate function assert(false && "Restore not yet implemented for CurvedSurfaceGrid");
HostGrid *hostGrid = HostBackupRestoreFacility::restore( stream ); return nullptr;
CoordFunction *coordFunction = new CoordFunction();
return new Grid( hostGrid, coordFunction );
} }
}; };
} // namespace Dune } // namespace Dune
#endif // #ifndef DUNE_CRVSRF_BACKUPRESTORE_HH #endif // DUNE_CURVED_SURFACE_GRID_BACKUPRESTORE_HH
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2: // vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CRVSRF_CAPABILITIES_HH #ifndef DUNE_CURVED_SURFACE_GRID_CAPABILITIES_HH
#define DUNE_CRVSRF_CAPABILITIES_HH #define DUNE_CURVED_SURFACE_GRID_CAPABILITIES_HH
#include <cassert> #include <cassert>
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <dune/grid/common/capabilities.hh> #include <dune/grid/common/capabilities.hh>
#include <dune/grid/geometrygrid/capabilities.hh> #include <dune/grid/geometrygrid/capabilities.hh>
#include <dune/curvedsurfacegrid/declaration.hh> #include <dune/curvedsurfacegrid/declaration.hh>
#include <dune/curvedsurfacegrid/gridfunctions/gridfunction.hh>
namespace Dune namespace Dune
{ {
...@@ -24,61 +25,66 @@ namespace Dune ...@@ -24,61 +25,66 @@ namespace Dune
// Capabilities from dune-grid // Capabilities from dune-grid
// --------------------------- // ---------------------------
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator > template< class GridFunction, int order >
struct hasSingleGeometryType< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > > struct hasSingleGeometryType< CurvedSurfaceGrid<GridFunction,order> >
{ {
using HostGrid = GridOf_t<GridFunction>;
static const bool v = hasSingleGeometryType< HostGrid > :: v; static const bool v = hasSingleGeometryType< HostGrid > :: v;
static const unsigned int topologyId = hasSingleGeometryType< HostGrid > :: topologyId; static const unsigned int topologyId = hasSingleGeometryType< HostGrid > :: topologyId;
}; };
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator, int codim > template< class GridFunction, int order, int codim >
struct hasEntity< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator >, codim > struct hasEntity< CurvedSurfaceGrid<GridFunction,order>, codim >
{ {
static const bool v = true; static const bool v = true;
}; };
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator, int codim > template< class GridFunction, int order, int codim >
struct hasEntityIterator< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator >, codim > struct hasEntityIterator< CurvedSurfaceGrid<GridFunction,order>, codim >
{ {
static const bool v = true; static const bool v = true;
}; };
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator, int codim > template< class GridFunction, int order, int codim >
struct canCommunicate< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator >, codim > struct canCommunicate< CurvedSurfaceGrid<GridFunction,order>, codim >
{ {
using HostGrid = GridOf_t<GridFunction>;
static const bool v = canCommunicate< HostGrid, codim >::v && hasEntity< HostGrid, codim >::v; static const bool v = canCommunicate< HostGrid, codim >::v && hasEntity< HostGrid, codim >::v;
}; };
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator > template< class GridFunction, int order >
struct hasBackupRestoreFacilities< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > > struct hasBackupRestoreFacilities< CurvedSurfaceGrid<GridFunction,order> >
{ {
using HostGrid = GridOf_t<GridFunction>;
static const bool v = hasBackupRestoreFacilities< HostGrid >::v; static const bool v = hasBackupRestoreFacilities< HostGrid >::v;
}; };
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator > template< class GridFunction, int order >
struct isLevelwiseConforming< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > > struct isLevelwiseConforming< CurvedSurfaceGrid<GridFunction,order> >
{ {
using HostGrid = GridOf_t<GridFunction>;
static const bool v = isLevelwiseConforming< HostGrid >::v; static const bool v = isLevelwiseConforming< HostGrid >::v;
}; };
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator > template< class GridFunction, int order >
struct isLeafwiseConforming< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > > struct isLeafwiseConforming< CurvedSurfaceGrid<GridFunction,order> >
{ {
using HostGrid = GridOf_t<GridFunction>;
static const bool v = isLeafwiseConforming< HostGrid >::v; static const bool v = isLeafwiseConforming< HostGrid >::v;
}; };
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator > template< class GridFunction, int order >
struct threadSafe< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > > struct threadSafe< CurvedSurfaceGrid<GridFunction,order> >
{ {
static const bool v = false; static const bool v = false;
}; };
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator > template< class GridFunction, int order >
struct viewThreadSafe< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > > struct viewThreadSafe< CurvedSurfaceGrid<GridFunction,order> >
{ {
static const bool v = false; static const bool v = false;
}; };
...@@ -88,9 +94,10 @@ namespace Dune ...@@ -88,9 +94,10 @@ namespace Dune
// hasHostEntity // hasHostEntity
// ------------- // -------------
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator, int codim > template< class GridFunction, int order, int codim >
struct hasHostEntity< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator >, codim > struct hasHostEntity< CurvedSurfaceGrid<GridFunction,order>, codim >
{ {
using HostGrid = GridOf_t<GridFunction>;
static const bool v = hasEntity< HostGrid, codim >::v; static const bool v = hasEntity< HostGrid, codim >::v;
}; };
...@@ -98,4 +105,4 @@ namespace Dune ...@@ -98,4 +105,4 @@ namespace Dune
} // namespace Dune } // namespace Dune
#endif // #ifndef DUNE_CRVSRF_CAPABILITIES_HH #endif // DUNE_CURVED_SURFACE_GRID_CAPABILITIES_HH
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CURVED_SURFACE_GRID_CONCEPTS_HH