14 #ifndef DUNE_GRIDGLUE_MERGING_PSURFACEMERGE_HH
15 #define DUNE_GRIDGLUE_MERGING_PSURFACEMERGE_HH
26 #include <dune/common/fvector.hh>
27 #include <dune/common/exceptions.hh>
28 #include <dune/common/bitsetvector.hh>
29 #include <dune/common/shared_ptr.hh>
30 #include <dune/common/version.hh>
32 #include <dune/grid/common/grid.hh>
38 #include <psurface/DirectionFunction.h>
39 #include <psurface/IntersectionPrimitive.h>
42 template <
int dim,
typename ctype>
class DirectionFunction;
44 #define PSURFACE_NAMESPACE
54 template<
int dim,
int dimworld,
typename T =
double>
56 :
public Merger<T,dim,dim,dimworld>
58 #if DUNE_VERSION_NEWER(DUNE_GEOMETRY,3,0)
59 static_assert( dim==1 || dim==2,
60 "PSurface can only handle the cases dim==1 and dim==2!");
62 static_assert( dim==dimworld || dim+1==dimworld,
63 "PSurface can only handle the cases dim==dimworld and dim+1==dimworld!");
65 dune_static_assert( dim==1 || dim==2,
66 "PSurface can only handle the cases dim==1 and dim==2!");
68 dune_static_assert( dim==dimworld || dim+1==dimworld,
69 "PSurface can only handle the cases dim==dimworld and dim+1==dimworld!");
75 enum {psurfaceDimworld = dimworld + (dim==dimworld)};
100 static Dune::FieldVector<ctype, dim> barycentricToReference(
const Dune::FieldVector<ctype, dim+1>& bar)
102 Dune::FieldVector<ctype, dim> result;
103 for (
int i=0; i<dim; i++)
104 result[i] = bar[i+1];
113 static Dune::FieldVector<ctype, dim+1> referenceToBarycentric(
const Dune::FieldVector<ctype, dim>& ref)
115 Dune::FieldVector<ctype, dim+1> result;
117 for (
int i=0; i<dim; i++) {
118 result[i+1] = ref[i];
132 static bool domainParentSmaller(
const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>& a,
const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>& b)
134 return a.tris[0] < b.tris[0];
143 static bool targetParentSmaller(
const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>* a,
const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>* b)
145 return a->tris[1] < b->tris[1];
155 struct OverlapManager
167 void setOverlaps(
const std::vector<PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype> >& unordered);
172 unsigned int nOverlaps()
const
174 return this->domOrder.size();
183 unsigned int firstDomainParent(
unsigned int parent)
const;
191 unsigned int firstTargetParent(
unsigned int parent)
const;
198 const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>& domain(
unsigned int idx)
const
200 return this->domOrder[idx];
208 const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>& target(
unsigned int idx)
const
210 return *this->tarOrder[idx];
218 unsigned int domainIndex(
unsigned int idx)
const
220 return (this->tarOrder[idx] - this->baseptr);
234 static void purge(V & v)
243 std::vector<PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype> > domOrder;
247 std::vector<PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>*> tarOrder;
250 PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>* baseptr;
259 struct ConstantDirection :
public PSURFACE_NAMESPACE AnalyticDirectionFunction<psurfaceDimworld,ctype>
261 PSURFACE_NAMESPACE StaticVector<ctype,psurfaceDimworld> operator()(
const PSURFACE_NAMESPACE StaticVector<ctype,psurfaceDimworld>& position)
const
263 PSURFACE_NAMESPACE StaticVector<ctype,psurfaceDimworld> result;
264 for (
size_t i=0; i<psurfaceDimworld-1; i++)
266 result[psurfaceDimworld-1] = dir;
278 std::vector<std::tr1::array<double,psurfaceDimworld> > domc_;
281 std::vector<std::tr1::array<double,psurfaceDimworld> > tarc_;
287 std::vector<std::tr1::array<int,dim+1> > domi_;
290 std::vector<std::tr1::array<int,dim+1> > tari_;
302 std::shared_ptr<const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > domainDirections_;
312 std::shared_ptr<const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections_;
316 #endif // if HAVE_PSURFACE
320 PSurfaceMerge(
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* domainDirections,
321 const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* targetDirections);
323 PSurfaceMerge(std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > domainDirections =
nullptr,
324 std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections =
nullptr);
338 void setSurfaceDirections(
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* domainDirections,
339 const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* targetDirections);
342 void setSurfaceDirections(std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > domainDirections,
343 std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections);
350 void build(
const std::vector<Dune::FieldVector<ctype,dimworld> >& grid1_coords,
351 const std::vector<unsigned int>& grid1_elements,
352 const std::vector<Dune::GeometryType>& grid1_element_types,
353 const std::vector<Dune::FieldVector<ctype,dimworld> >& grid2_coords,
354 const std::vector<unsigned int>& grid2_elements,
355 const std::vector<Dune::GeometryType>& grid2_element_types);
383 static void purge(V & v)
392 unsigned int grid1Parents(
unsigned int idx)
const;
393 unsigned int grid2Parents(
unsigned int idx)
const;
399 unsigned int grid1Parent(
unsigned int idx,
unsigned int parId = 0)
const;
406 unsigned int grid2Parent(
unsigned int idx,
unsigned int parId = 0)
const;
418 LocalCoords grid1ParentLocal(
unsigned int idx,
unsigned int corner,
unsigned int parId = 0)
const;
427 LocalCoords grid2ParentLocal(
unsigned int idx,
unsigned int corner,
unsigned int parId = 0)
const;
435 template<
int dim,
int dimworld,
typename T>
437 const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* targetDirections)
438 :
PSurfaceMerge(
Dune::stackobject_to_shared_ptr(*domainDirections),
Dune::stackobject_to_shared_ptr(*targetDirections))
441 template<
int dim,
int dimworld,
typename T>
443 std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections)
444 : domainDirections_(domainDirections)
445 , targetDirections_(targetDirections)
449 template<
int dim,
int dimworld,
typename T>
451 const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* targetDirections)
453 setSurfaceDirections(Dune::stackobject_to_shared_ptr(*domainDirections), Dune::stackobject_to_shared_ptr(*targetDirections));
456 template<
int dim,
int dimworld,
typename T>
458 std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections)
460 domainDirections_ = domainDirections;
461 targetDirections_ = targetDirections;
466 template<
int dim,
int dimworld,
typename T>
470 return this->olm_.nOverlaps();
473 template<
int dim,
int dimworld,
typename T>
481 template<
int dim,
int dimworld,
typename T>
488 template<
int dim,
int dimworld,
typename T>
492 return this->olm_.domain(idx).tris[0];
496 template<
int dim,
int dimworld,
typename T>
501 return this->olm_.domain(idx).tris[1];
504 #endif // HAVE_PSURFACE
506 #ifdef PSURFACE_EXTRA_TYPES
507 #define PSURFACE_EXTERN
509 #undef PSURFACE_EXTERN
512 #endif // DUNE_GRIDGLUE_MERGING_PSURFACEMERGE_HH
unsigned int parent(unsigned int idx, unsigned int parId=0) const
get index of grid-n's parent simplex for given merged grid simplex
Definition: merger.hh:156
void build(const std::vector< Dune::FieldVector< ctype, dimworld > > &grid1_coords, const std::vector< unsigned int > &grid1_elements, const std::vector< Dune::GeometryType > &grid1_element_types, const std::vector< Dune::FieldVector< ctype, dimworld > > &grid2_coords, const std::vector< unsigned int > &grid2_elements, const std::vector< Dune::GeometryType > &grid2_element_types)
builds the merged grid
Definition: psurfacemerge.cc:17
void setSurfaceDirections(const PSURFACE_NAMESPACE DirectionFunction< psurfaceDimworld, ctype > *domainDirections, const PSURFACE_NAMESPACE DirectionFunction< psurfaceDimworld, ctype > *targetDirections)
Set surface direction functions.
Definition: psurfacemerge.hh:450
T ctype
the numeric type used in this interface
Definition: psurfacemerge.hh:82
Definition: gridglue.hh:34
unsigned int nSimplices() const
get the number of simplices in the merged grid The indices are then in 0..nSimplices()-1 ...
Definition: psurfacemerge.hh:467
void clear()
clear the internal state, so that we can run a new merging process
Definition: psurfacemerge.hh:365
Abstract base for all classes that take extracted grids and build sets of intersections.
Definition: merger.hh:13
PSurfaceMerge(const PSURFACE_NAMESPACE DirectionFunction< psurfaceDimworld, ctype > *domainDirections, const PSURFACE_NAMESPACE DirectionFunction< psurfaceDimworld, ctype > *targetDirections)
Definition: psurfacemerge.hh:436
Standard implementation of the SurfaceMerge concept using the psurface library.
Definition: psurfacemerge.hh:55
Dune::FieldVector< T, dim > LocalCoords
the coordinate type used in this interface
Definition: psurfacemerge.hh:88
Dune::FieldVector< T, dimworld > WorldCoords
the coordinate type used in this interface
Definition: psurfacemerge.hh:85