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
Version: 0.1.0
Maintainer: florian.stenger@tu-dresden.de
#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
add_subdirectory(surfacedistance)
add_subdirectory(test)
set(HEADERS
install(FILES
backuprestore.hh
capabilities.hh
concepts.hh
coordfunctionimplementations.hh
coordprovider.hh
curvedsurfacegrid.hh
datahandle.hh
declaration.hh
......@@ -20,7 +18,9 @@ set(HEADERS
intersection.hh
intersectioniterator.hh
iterator.hh
)
install(FILES ${HEADERS}
localgeometrywrapper.hh
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 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CRVSRF_BACKUPRESTORE_HH
#define DUNE_CRVSRF_BACKUPRESTORE_HH
#ifndef DUNE_CURVED_SURFACE_GRID_BACKUPRESTORE_HH
#define DUNE_CURVED_SURFACE_GRID_BACKUPRESTORE_HH
#include <dune/grid/common/backuprestore.hh>
......@@ -9,84 +9,80 @@
namespace Dune
{
namespace crvsrf
namespace Curved
{
// BackupRestoreFacilities
// -----------------------
template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities< Grid > ::v >
template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities<Grid> ::v >
class BackupRestoreFacilities
{};
template< class Grid >
class BackupRestoreFacilities< Grid, true >
class BackupRestoreFacilities<Grid, true>
{
typedef BackupRestoreFacilities< Grid, true > This;
using Self = BackupRestoreFacilities<Grid, true>;
protected:
BackupRestoreFacilities ()
{}
private:
BackupRestoreFacilities ( const This & );
This &operator= ( const This & );
BackupRestoreFacilities (const Self&);
Self& operator= (const Self&);
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
// -------------------------------------------
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator >
struct BackupRestoreFacility< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > >
template< class GridFunction, int order >
struct BackupRestoreFacility<CurvedSurfaceGrid<GridFunction, order>>
{
typedef CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > Grid;
typedef BackupRestoreFacility< HostGrid > HostBackupRestoreFacility;
using Grid = CurvedSurfaceGrid<GridFunction, order>;
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
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
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
HostGrid *hostGrid = HostBackupRestoreFacility::restore( filename );
CoordFunction *coordFunction = new CoordFunction();
return new Grid( hostGrid, coordFunction );
assert(false && "Restore not yet implemented for CurvedSurfaceGrid");
return nullptr;
}
static Grid *restore ( const std::istream &stream )
static Grid* restore (const std::istream& stream)
{
// notice: We should also restore the coordinate function
HostGrid *hostGrid = HostBackupRestoreFacility::restore( stream );
CoordFunction *coordFunction = new CoordFunction();
return new Grid( hostGrid, coordFunction );
assert(false && "Restore not yet implemented for CurvedSurfaceGrid");
return nullptr;
}
};
} // 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 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CRVSRF_CAPABILITIES_HH
#define DUNE_CRVSRF_CAPABILITIES_HH
#ifndef DUNE_CURVED_SURFACE_GRID_CAPABILITIES_HH
#define DUNE_CURVED_SURFACE_GRID_CAPABILITIES_HH
#include <cassert>
......@@ -11,6 +11,7 @@
#include <dune/grid/common/capabilities.hh>
#include <dune/grid/geometrygrid/capabilities.hh>
#include <dune/curvedsurfacegrid/declaration.hh>
#include <dune/curvedsurfacegrid/gridfunctions/gridfunction.hh>
namespace Dune
{
......@@ -24,61 +25,66 @@ namespace Dune
// Capabilities from dune-grid
// ---------------------------
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator >
struct hasSingleGeometryType< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > >
template< class GridFunction, int order >
struct hasSingleGeometryType< CurvedSurfaceGrid<GridFunction,order> >
{
using HostGrid = GridOf_t<GridFunction>;
static const bool v = hasSingleGeometryType< HostGrid > :: v;
static const unsigned int topologyId = hasSingleGeometryType< HostGrid > :: topologyId;
};
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator, int codim >
struct hasEntity< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator >, codim >
template< class GridFunction, int order, int codim >
struct hasEntity< CurvedSurfaceGrid<GridFunction,order>, codim >
{
static const bool v = true;
};
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator, int codim >
struct hasEntityIterator< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator >, codim >
template< class GridFunction, int order, int codim >
struct hasEntityIterator< CurvedSurfaceGrid<GridFunction,order>, codim >
{
static const bool v = true;
};
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator, int codim >
struct canCommunicate< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator >, codim >
template< class GridFunction, int order, int codim >
struct canCommunicate< CurvedSurfaceGrid<GridFunction,order>, codim >
{
using HostGrid = GridOf_t<GridFunction>;
static const bool v = canCommunicate< HostGrid, codim >::v && hasEntity< HostGrid, codim >::v;
};
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator >
struct hasBackupRestoreFacilities< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > >
template< class GridFunction, int order >
struct hasBackupRestoreFacilities< CurvedSurfaceGrid<GridFunction,order> >
{
using HostGrid = GridOf_t<GridFunction>;
static const bool v = hasBackupRestoreFacilities< HostGrid >::v;
};
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator >
struct isLevelwiseConforming< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > >
template< class GridFunction, int order >
struct isLevelwiseConforming< CurvedSurfaceGrid<GridFunction,order> >
{
using HostGrid = GridOf_t<GridFunction>;
static const bool v = isLevelwiseConforming< HostGrid >::v;
};
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator >
struct isLeafwiseConforming< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > >
template< class GridFunction, int order >
struct isLeafwiseConforming< CurvedSurfaceGrid<GridFunction,order> >
{
using HostGrid = GridOf_t<GridFunction>;
static const bool v = isLeafwiseConforming< HostGrid >::v;
};
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator >
struct threadSafe< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > >
template< class GridFunction, int order >
struct threadSafe< CurvedSurfaceGrid<GridFunction,order> >
{
static const bool v = false;
};
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator >
struct viewThreadSafe< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator > >
template< class GridFunction, int order >
struct viewThreadSafe< CurvedSurfaceGrid<GridFunction,order> >
{
static const bool v = false;
};
......@@ -88,9 +94,10 @@ namespace Dune
// hasHostEntity
// -------------
template< class HostGrid, class CoordFunction, int order, bool geoCaching, class Allocator, int codim >
struct hasHostEntity< CurvedSurfaceGrid< HostGrid, CoordFunction, order, geoCaching, Allocator >, codim >
template< class GridFunction, int order, int codim >
struct hasHostEntity< CurvedSurfaceGrid<GridFunction,order>, codim >
{
using HostGrid = GridOf_t<GridFunction>;
static const bool v = hasEntity< HostGrid, codim >::v;
};
......@@ -98,4 +105,4 @@ 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
#define DUNE_CURVED_SURFACE_GRID_CONCEPTS_HH
#include <dune/common/concept.hh>
#include <dune/curvedsurfacegrid/gridfunctions/gridentityset.hh>
#include <dune/functions/common/functionconcepts.hh>
namespace Dune {
namespace Concept {
template< class LocalContext >
struct LocalFunction
{
using LocalCoordinate = typename LocalContext::Geometry::LocalCoordinate;
template< class LF >
auto require(LF&& lf) -> decltype(
lf.bind(std::declval<LocalContext>()),
lf.unbind(),
lf.localContext(),
requireConcept<Dune::Functions::Concept::Callable<LocalCoordinate>>(lf),
requireConvertible<LocalContext>(lf.localContext())
);
};
template< class LF, class LocalContext >
constexpr bool isLocalFunction()
{ return models<Concept::LocalFunction<LocalContext>, LF>(); }
template< class HostGrid >
struct GridFunction
{
using EntitySet = GridEntitySet<HostGrid,0>;
using LocalContext = typename EntitySet::Element;
using GlobalCoordinate = typename EntitySet::GlobalCoordinate;
template< class GF >
auto require(GF&& gf) -> decltype(
localFunction(gf),
gf.entitySet(),
requireConcept<Dune::Functions::Concept::Callable<GlobalCoordinate>>(gf),
requireConcept<LocalFunction<LocalContext>>(localFunction(gf))
);
};
template< class GF, class HostGrid >
constexpr bool isGridFunction()
{ return models<Concept::GridFunction<HostGrid>, GF>(); }
} // end namespace Concept
} // end namespace Dune
#endif // DUNE_CURVED_SURFACE_GRID_CONCEPTS_HH
\ No newline at end of file
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CRVSRF_COORDFUNCTIONIMPLEMENTATIONS_HH
#define DUNE_CRVSRF_COORDFUNCTIONIMPLEMENTATIONS_HH
#ifndef DUNE_CURVED_SURFACE_GRID_COORDFUNCTIONIMPLEMENTATIONS_HH
#define DUNE_CURVED_SURFACE_GRID_COORDFUNCTIONIMPLEMENTATIONS_HH
#include <dune/curvedsurfacegrid/surfacedistance/surfacedistance.hh>
#include <dune/curvedsurfacegrid/surfacedistance/vertexmap.hh>
#include <dune/curvedsurfacegrid/surfacedistance/vtureader.hh>
#include <dune/grid/geometrygrid/coordfunction.hh>
#include <cfloat>
#define COLLECTOR_BENCHMARK 0
......@@ -30,11 +29,11 @@ namespace Dune
//convertDuneGridToCrvsrfMesh
template<class GridPtr>
crvsrf::Mesh *convertDuneGridToCrvsrfMesh(GridPtr &grid){
Curved::Mesh *convertDuneGridToCrvsrfMesh(GridPtr &grid){
auto gridView = grid->leafGridView();
//determine coordinate-extrema
crvsrf::Vertex minc(DBL_MAX, DBL_MAX, DBL_MAX), maxc(-DBL_MAX, -DBL_MAX, -DBL_MAX);
Curved::Vertex minc(DBL_MAX, DBL_MAX, DBL_MAX), maxc(-DBL_MAX, -DBL_MAX, -DBL_MAX);
for(const auto &vertexEntity : vertices(gridView)){
const auto &vertex = vertexEntity.geometry().corner(0);
for(int i = 0; i < grid->dimensionworld; ++i){
......@@ -43,19 +42,19 @@ namespace Dune
}
}
crvsrf::Mesh *surface_mesh = new crvsrf::Mesh(grid->dimension, grid->dimensionworld);
crvsrf::VertexMap<int> vmap(minc, maxc, grid->dimensionworld);
Curved::Mesh *surface_mesh = new Curved::Mesh(grid->dimension, grid->dimensionworld);
Curved::VertexMap<int> vmap(minc, maxc, grid->dimensionworld);
//build mesh
int next_index = 0;
for(const auto &element : elements(gridView)){
if(element.geometry().corners() != 3){