Dune Core Modules (2.4.2)

psurfaceboundary.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_GRID_IO_FILE_AMIRAMESH_PSURFACE_BOUNDARY_HH
4#define DUNE_GRID_IO_FILE_AMIRAMESH_PSURFACE_BOUNDARY_HH
5
10
11#if HAVE_PSURFACE
12#include <psurface/PSurface.h>
13#include "psurface/AmiraMeshIO.h"
14#if HAVE_PSURFACE_2_0
15#include <psurface/Hdf5IO.h>
16#endif
17
18#if HAVE_AMIRAMESH
19#include <amiramesh/AmiraMesh.h>
20#endif
21
22
23namespace Dune {
24
35 template <int dim>
36 class PSurfaceBoundary
37 {
38 static_assert((dim==1 or dim==2), "PSurfaceBoundaries can only have dimensions 1 or 2!");
39
40 public:
41
43 class PSurfaceBoundarySegment : public Dune::BoundarySegment<dim+1>
44 {
45 public:
46
52 PSurfaceBoundarySegment(const shared_ptr<PSurfaceBoundary<dim> >& psurfaceBoundary, int segment)
53 : psurfaceBoundary_(psurfaceBoundary),
54 segment_(segment)
55 {}
56
58 virtual Dune::FieldVector<double, dim+1> operator()(const Dune::FieldVector<double,dim>& local) const {
59
61
62 // Transform local to barycentric coordinates
63 psurface::StaticVector<float,dim> barCoords;
64
65 if (dim==2) {
66 barCoords[0] = 1 - local[0] - local[1];
67 barCoords[1] = local[0];
68 } else { // dim==1
69 barCoords[0] = 1 - local[0];
70 }
71
72 psurface::StaticVector<float,dim+1> r;
73
74 if (!psurfaceBoundary_->getPSurfaceObject()->positionMap(segment_, barCoords, r))
75 DUNE_THROW(Dune::GridError, "psurface::positionMap returned error code");
76
77 for (int i=0; i<dim+1; i++)
78 result[i] = r[i];
79
80 return result;
81 }
82
83 shared_ptr<PSurfaceBoundary<dim> > psurfaceBoundary_;
84 int segment_;
85 };
86
87
88
90 PSurfaceBoundary(psurface::PSurface<dim,float>* psurface)
91 : psurface_(psurface)
92 {}
93
101 psurface::PSurface<dim,float>* getPSurfaceObject()
102 {
103 return psurface_.get();
104 }
105
113 static shared_ptr<PSurfaceBoundary<dim> > read(const std::string& filename)
114 {
115 psurface::PSurface<dim,float>* newDomain;
116
117#if HAVE_PSURFACE_2_0
118 // Try to read the file as an hdf5 file
119 if (filename.find(".h5")==filename.length()-3) {
120 newDomain = psurface::Hdf5IO<float,dim>::read(filename);
121 if (newDomain)
122 return make_shared<PSurfaceBoundary<dim> >(newDomain);
123 }
124#endif
125
126#if HAVE_AMIRAMESH
127 std::unique_ptr<AmiraMesh> am(AmiraMesh::read(filename.c_str()));
128
129 if (!am.get())
130 DUNE_THROW(IOError, "An error has occured while reading " << filename);
131
132 newDomain
133 = (psurface::PSurface<dim,float>*) psurface::AmiraMeshIO<float>::readAmiraMesh(am.get(), filename.c_str());
134
135 if (!newDomain)
136 DUNE_THROW(IOError, "An error has occured while reading " << filename);
137
138 return make_shared<PSurfaceBoundary<dim> >(newDomain);
139#else
140 DUNE_THROW(IOError, "The given file is not in a supported format!");
141#endif
142 }
143
144 private:
145
146 std::unique_ptr<psurface::PSurface<dim,float> > psurface_;
147
148 };
149
150}
151
152#endif // #if HAVE_PSURFACE
153#endif // #ifndef DUNE_GRID_IO_FILE_AMIRAMESH_PSURFACE_BOUNDARY_HH
vector space out of a tensor product of fields.
Definition: fvector.hh:94
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Provide a generic factory class for unstructured grids.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Dune namespace.
Definition: alignment.hh:10
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:30
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)