14 #ifndef DUNE_GRIDGLUE_MERGING_PSURFACEMERGE_HH
15 #define DUNE_GRIDGLUE_MERGING_PSURFACEMERGE_HH
25 #include <dune/common/fvector.hh>
26 #include <dune/common/exceptions.hh>
27 #include <dune/common/bitsetvector.hh>
28 #include <dune/common/shared_ptr.hh>
29 #include <dune/common/version.hh>
31 #include <dune/grid/common/grid.hh>
37 #include <psurface/DirectionFunction.h>
38 #include <psurface/IntersectionPrimitive.h>
41 template <
int dim,
typename ctype>
class DirectionFunction;
43 #define PSURFACE_NAMESPACE
53 template<
int dim,
int dimworld,
typename T =
double>
55 :
public Merger<T,dim,dim,dimworld>
57 static_assert( dim==1 || dim==2,
58 "PSurface can only handle the cases dim==1 and dim==2!");
60 static_assert( dim==dimworld || dim+1==dimworld,
61 "PSurface can only handle the cases dim==dimworld and dim+1==dimworld!");
66 enum {psurfaceDimworld = dimworld + (dim==dimworld)};
91 static Dune::FieldVector<ctype, dim> barycentricToReference(
const Dune::FieldVector<ctype, dim+1>& bar)
93 Dune::FieldVector<ctype, dim> result;
94 for (
int i=0; i<dim; i++)
104 static Dune::FieldVector<ctype, dim+1> referenceToBarycentric(
const Dune::FieldVector<ctype, dim>& ref)
106 Dune::FieldVector<ctype, dim+1> result;
108 for (
int i=0; i<dim; i++) {
109 result[i+1] = ref[i];
123 static bool domainParentSmaller(
const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>& a,
const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>& b)
125 return a.tris[0] < b.tris[0];
134 static bool targetParentSmaller(
const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>* a,
const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>* b)
136 return a->tris[1] < b->tris[1];
146 struct OverlapManager
158 void setOverlaps(
const std::vector<PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype> >& unordered);
163 unsigned int nOverlaps()
const
165 return this->domOrder.size();
174 unsigned int firstDomainParent(
unsigned int parent)
const;
182 unsigned int firstTargetParent(
unsigned int parent)
const;
189 const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>& domain(
unsigned int idx)
const
191 return this->domOrder[idx];
199 const PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>& target(
unsigned int idx)
const
201 return *this->tarOrder[idx];
209 unsigned int domainIndex(
unsigned int idx)
const
211 return (this->tarOrder[idx] - this->baseptr);
225 static void purge(V & v)
234 std::vector<PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype> > domOrder;
238 std::vector<PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>*> tarOrder;
241 PSURFACE_NAMESPACE IntersectionPrimitive<dim,ctype>* baseptr;
250 struct ConstantDirection :
public PSURFACE_NAMESPACE AnalyticDirectionFunction<psurfaceDimworld,ctype>
252 PSURFACE_NAMESPACE StaticVector<ctype,psurfaceDimworld> operator()(
const PSURFACE_NAMESPACE StaticVector<ctype,psurfaceDimworld>& position)
const
254 PSURFACE_NAMESPACE StaticVector<ctype,psurfaceDimworld> result;
255 for (
size_t i=0; i<psurfaceDimworld-1; i++)
257 result[psurfaceDimworld-1] = dir;
269 std::vector<std::tr1::array<double,psurfaceDimworld> > domc_;
272 std::vector<std::tr1::array<double,psurfaceDimworld> > tarc_;
278 std::vector<std::tr1::array<int,dim+1> > domi_;
281 std::vector<std::tr1::array<int,dim+1> > tari_;
293 std::shared_ptr<const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > domainDirections_;
303 std::shared_ptr<const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections_;
307 #endif // if HAVE_PSURFACE
311 PSurfaceMerge(
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* domainDirections,
312 const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* targetDirections);
314 PSurfaceMerge(std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > domainDirections =
nullptr,
315 std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections =
nullptr);
329 void setSurfaceDirections(
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* domainDirections,
330 const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* targetDirections);
333 void setSurfaceDirections(std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > domainDirections,
334 std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections);
341 void build(
const std::vector<Dune::FieldVector<ctype,dimworld> >& grid1_coords,
342 const std::vector<unsigned int>& grid1_elements,
343 const std::vector<Dune::GeometryType>& grid1_element_types,
344 const std::vector<Dune::FieldVector<ctype,dimworld> >& grid2_coords,
345 const std::vector<unsigned int>& grid2_elements,
346 const std::vector<Dune::GeometryType>& grid2_element_types);
374 static void purge(V & v)
383 unsigned int grid1Parents(
unsigned int idx)
const;
384 unsigned int grid2Parents(
unsigned int idx)
const;
390 unsigned int grid1Parent(
unsigned int idx,
unsigned int parId = 0)
const;
397 unsigned int grid2Parent(
unsigned int idx,
unsigned int parId = 0)
const;
409 LocalCoords grid1ParentLocal(
unsigned int idx,
unsigned int corner,
unsigned int parId = 0)
const;
418 LocalCoords grid2ParentLocal(
unsigned int idx,
unsigned int corner,
unsigned int parId = 0)
const;
426 template<
int dim,
int dimworld,
typename T>
428 const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* targetDirections)
429 :
PSurfaceMerge(
Dune::stackobject_to_shared_ptr(*domainDirections),
Dune::stackobject_to_shared_ptr(*targetDirections))
432 template<
int dim,
int dimworld,
typename T>
434 std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections)
435 : domainDirections_(domainDirections)
436 , targetDirections_(targetDirections)
440 template<
int dim,
int dimworld,
typename T>
442 const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype>* targetDirections)
444 setSurfaceDirections(Dune::stackobject_to_shared_ptr(*domainDirections), Dune::stackobject_to_shared_ptr(*targetDirections));
447 template<
int dim,
int dimworld,
typename T>
449 std::shared_ptr<
const PSURFACE_NAMESPACE DirectionFunction<psurfaceDimworld,ctype> > targetDirections)
451 domainDirections_ = domainDirections;
452 targetDirections_ = targetDirections;
457 template<
int dim,
int dimworld,
typename T>
461 return this->olm_.nOverlaps();
464 template<
int dim,
int dimworld,
typename T>
472 template<
int dim,
int dimworld,
typename T>
479 template<
int dim,
int dimworld,
typename T>
483 return this->olm_.domain(idx).tris[0];
487 template<
int dim,
int dimworld,
typename T>
492 return this->olm_.domain(idx).tris[1];
495 #endif // HAVE_PSURFACE
497 #ifdef PSURFACE_EXTRA_TYPES
498 #define PSURFACE_EXTERN
500 #undef PSURFACE_EXTERN
503 #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:441
T ctype
the numeric type used in this interface
Definition: psurfacemerge.hh:73
unsigned int nSimplices() const
get the number of simplices in the merged grid The indices are then in 0..nSimplices()-1 ...
Definition: psurfacemerge.hh:458
void clear()
clear the internal state, so that we can run a new merging process
Definition: psurfacemerge.hh:356
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:427
Definition: gridglue.hh:33
Standard implementation of the SurfaceMerge concept using the psurface library.
Definition: psurfacemerge.hh:54
Dune::FieldVector< T, dim > LocalCoords
the coordinate type used in this interface
Definition: psurfacemerge.hh:79
Dune::FieldVector< T, dimworld > WorldCoords
the coordinate type used in this interface
Definition: psurfacemerge.hh:76