27 namespace AdvectDetail
42 template <
class LocalCoordinate>
43 std::pair<int,double> intersectedFace(Dune::GeometryType
const& gt, LocalCoordinate
const& xi, LocalCoordinate
const& dxi)
45 using Scalar =
typename LocalCoordinate::field_type;
51 double minStep = std::numeric_limits<Scalar>::infinity();
53 for (
int i=0; i<xi.N(); ++i)
56 Scalar stepi = -xi[i]/dxi[i];
64 LocalCoordinate one(1.0);
65 Scalar dxione = one*dxi;
66 if (dxione > 0 && (1-one*xi)/dxione < minStep)
68 minStep = (1-one*xi)/dxione;
75 throw DetailedException(
"Vanishing direction provided for face-ray intersection.",__FILE__,__LINE__);
78 if (LocalCoordinate::dimension==1)
79 return std::make_pair(imin,minStep);
80 if (LocalCoordinate::dimension==2)
82 constexpr int sube[] = { 1, 0, 2 };
83 return std::make_pair(sube[imin],minStep);
85 if (LocalCoordinate::dimension==3)
87 constexpr int sube[] = { 2, 1, 0, 3 };
88 return std::make_pair(sube[imin],minStep);
100 return std::make_pair(-1,-1.0);
120 template <
class Function,
class Velocity>
124 using GridView =
typename Function::Space::GridView;
129 using GlobalPosition = std::pair<Cell,Position>;
152 GlobalPosition y(cell,xi);
153 for (
int i=0; i<n; ++i)
154 y = advectPosition(y,-tau/n*v.value(y.first,y.second));
157 return f.
value(y.first,y.second);
175 auto const& geo = y.first.geometry();
178 auto dxi =
transpose(geo.jacobianInverseTransposed(xi))*dy;
188 auto encounter = AdvectDetail::intersectedFace(geo.type(),xi,dxi);
189 auto xinext = xi+encounter.second*dxi;
192 for (
auto const& face: intersections(f.space().gridView(),y.first))
193 if (face.indexInInside()==encounter.first)
196 return advectPosition(
GlobalPosition(face.outside(),face.geometryInOutside().global(face.geometryInInside().local(xinext))),
197 (1-encounter.second)*dy);
213 template <
class Function,
class Velocity>
Function is the interface for evaluatable functions .
ValueType value(Cell const &cell, Dune::FieldVector< typename Cell::Geometry::ctype, Cell::dimension > const &localCoordinate) const
A weak function view that defines an advected function.
GlobalPosition< GridView > Position
typename Function::Space::GridView GridView
Kaskade::Cell< GridView > Cell
AdvectedFunctionView(Function const &f_, Velocity const &v_, double tau_, int n_=1)
Constructor.
Function::ValueType value(Cell const &cell, Position const &xi) const
This file contains various utility functions that augment the basic functionality of Dune.
FEFunctionSpace and FunctionSpaceElement and the like.
auto makeAdvectedFunctionView(Function const &f, Velocity const &v, double tau, int n=1)
Creates a weak function view for advecting FE functions.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
LocalCoordinate::field_type checkInside(Dune::GeometryType const >, LocalCoordinate const &x)
Checks whether a point is inside or outside the reference element, and how much.