Commit 7fed0713 authored by Stenger, Florian's avatar Stenger, Florian
Browse files

SurfaceDistanceCoordFunction-ctor

parent 83078057
......@@ -7,6 +7,7 @@
#include <dune/curvedsurfacegrid/surfacedistance/vertexmap.hh>
#include <dune/curvedsurfacegrid/surfacedistance/vtureader.hh>
#include <dune/grid/geometrygrid/coordfunction.hh>
#include <cfloat>
#define COLLECTOR_BENCHMARK 0
......@@ -27,6 +28,48 @@ double dbl_time(){
namespace Dune
{
//convertDuneGridToCrvsrfMesh
template<class GridPtr>
crvsrf::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);
for(const auto &vertexEntity : vertices(gridView)){
const auto &vertex = vertexEntity.geometry().corner(0);
for(int i = 0; i < grid->dimensionworld; ++i){
if(vertex[i] < minc[i]) minc[i] = vertex[i];
if(vertex[i] > maxc[i]) maxc[i] = vertex[i];
}
}
crvsrf::Mesh *surface_mesh = new crvsrf::Mesh(grid->dimension, grid->dimensionworld);
crvsrf::VertexMap<int> vmap(minc, maxc, grid->dimensionworld);
//build mesh
int next_index = 0;
for(const auto &element : elements(gridView)){
if(element.geometry().corners() != 3){
crvsrf::error("Element is not a triangle in convertDuneGridToCrvsrfMesh.");
}
int32_t el[grid->dimension + 1];
for(int i = 0; i <= grid->dimension; ++i){
auto coords = element.geometry().corner(i);
crvsrf::Vertex v(coords[0], coords[1], coords[2]);
if(!vmap.find_3d(v, el[i])){
surface_mesh->add_vertex(v);
el[i] = next_index;
vmap.insert(v, next_index);
++next_index;
}
}
surface_mesh->add_element(el);
}
return surface_mesh;
}
//CenterSphereCoordFunction
struct CenterSphereCoordFunction
: public AnalyticalCoordFunction<double, 3, 3, CenterSphereCoordFunction>
......@@ -114,26 +157,50 @@ namespace Dune
{
const bool coordCaching = cached;
//!template<class T> struct typewrapper{};
/*!template<class GridPtr>
SurfaceDistanceCoordFunction(const GridPtr &gridPtr,
double expansion_width=-1.0, bool no_scaling=false)
: SurfaceDistanceCoordFunction(typewrapper<gridPtr>(), gpof, expansion_width, no_scaling)
{}*/
//constructor using a pre-loaded Dune-surface-grid
template<class GridPtr>
SurfaceDistanceCoordFunction(const GridPtr &gridPtr,
double expansion_width=-1.0, bool no_scaling=false) : cache(nullptr){
if(gridPtr->dimension != 2 || gridPtr->dimensionworld != 3){
crvsrf::error("SurfaceDistanceCoordFunction needs a triangle-surface-mesh!");
}
surface_mesh = convertDuneGridToCrvsrfMesh(gridPtr);
backgrid = new crvsrf::BackGrid(*surface_mesh, expansion_width, no_scaling);
if(cached){
crvsrf::Vertex c_begin, c_end;
surface_mesh->determine_coordinate_extrema(c_begin, c_end);
crvsrf::Vertex c_expansion = (c_end - c_begin) * 0.1;
cache = new crvsrf::VertexMap<crvsrf::Vertex>(c_begin - c_expansion, c_end + c_expansion, 3);
}
}
//constructor using vtu-reader to read "file"
SurfaceDistanceCoordFunction(const std::string &file, double expansion_width=-1.0,
bool no_scaling=false) : cache(nullptr){
SurfaceDistanceCoordFunction(const char *file,
double expansion_width=-1.0, bool no_scaling=false) : cache(nullptr){
surface_mesh = new crvsrf::Mesh(2, 3);
read_vtu_file(file, *surface_mesh);
backgrid = new crvsrf::BackGrid(*surface_mesh, expansion_width, no_scaling);
crvsrf::Vertex c_begin, c_end;
surface_mesh->determine_coordinate_extrema(c_begin, c_end);
crvsrf::Vertex c_expansion = (c_end - c_begin) * 0.1;
if(cached){
crvsrf::Vertex c_begin, c_end;
surface_mesh->determine_coordinate_extrema(c_begin, c_end);
crvsrf::Vertex c_expansion = (c_end - c_begin) * 0.1;
cache = new crvsrf::VertexMap<crvsrf::Vertex>(c_begin - c_expansion, c_end + c_expansion, 3);
}
}
//constructor using a pre-loaded Dune-surface-mesh
/*!SurfaceDistanceCoordFunction(Grid &mesh, double expansion_width=-1.0, bool no_scaling=false){
surface_mesh = convert_dune_mesh_to_crvsrf::mesh...
backgrid = new BackGrid(*surface_mesh, expansion_width, no_scaling);
//! implement cache-init
}*/
//constructor using vtu-reader to read "file"
SurfaceDistanceCoordFunction(const std::string &file,
double expansion_width=-1.0, bool no_scaling=false)
: SurfaceDistanceCoordFunction(file.c_str(), expansion_width, no_scaling)
{}
//destructor
~SurfaceDistanceCoordFunction(){
......@@ -218,7 +285,6 @@ namespace Dune
#endif
};
//operator() (cached)
template<>
inline FieldVector<double, 3> SurfaceDistanceCoordFunction<true>::operator()(
......
......@@ -29,6 +29,13 @@ template<typename T> struct VertexMap{
void clear();
void split();
void insert(const Vertex &v, const T &data);
bool find(const Vertex &v, T &result){
switch(dim_of_world){
case 1: return find_1d(v, result);
case 2: return find_2d(v, result);
default: return find_3d(v, result);
}
}
bool find_1d(const Vertex &v, T &result);
bool find_2d(const Vertex &v, T &result);
bool find_3d(const Vertex &v, T &result);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment