DUNE PDELab (2.8)

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
6#warning Support for PSurface is deprecated and will be removed after Dune 2.8.
7
11#include <memory>
12
14
15#if HAVE_PSURFACE
16#include <psurface/PSurface.h>
17#include "psurface/AmiraMeshIO.h"
18#if HAVE_PSURFACE_2_0
19#include <psurface/Hdf5IO.h>
20#endif
21
22#if HAVE_AMIRAMESH
23#include <amiramesh/AmiraMesh.h>
24#endif
25
26
27namespace Dune {
28
39 template <int dim, class field_type = double>
40 class PSurfaceBoundary
41 {
42 static_assert((dim==1 or dim==2), "PSurfaceBoundaries can only have dimensions 1 or 2!");
43
44 public:
45
47 class PSurfaceBoundarySegment : public Dune::BoundarySegment<dim+1>
48 {
49 public:
50
56 PSurfaceBoundarySegment(const std::shared_ptr<PSurfaceBoundary<dim, field_type> >& psurfaceBoundary, int segment)
57 : psurfaceBoundary_(psurfaceBoundary),
58 segment_(segment)
59 {}
60
62 virtual Dune::FieldVector<double, dim+1> operator()(const Dune::FieldVector<double,dim>& local) const {
63
65
66 // Transform local to barycentric coordinates
67 psurface::StaticVector<field_type, dim> barCoords;
68
69 if (dim==2) {
70 barCoords[0] = 1 - local[0] - local[1];
71 barCoords[1] = local[0];
72 } else { // dim==1
73 barCoords[0] = 1 - local[0];
74 }
75
76 psurface::StaticVector<field_type,dim+1> r;
77
78 if (!psurfaceBoundary_->getPSurfaceObject()->positionMap(segment_, barCoords, r))
79 DUNE_THROW(Dune::GridError, "psurface::positionMap returned error code");
80
81 for (int i=0; i<dim+1; i++)
82 result[i] = r[i];
83
84 return result;
85 }
86
87 std::shared_ptr<PSurfaceBoundary<dim, field_type> > psurfaceBoundary_;
88 int segment_;
89 };
90
91
92
94 PSurfaceBoundary(psurface::PSurface<dim, field_type>* psurface)
95 : psurface_(psurface)
96 {}
97
105 psurface::PSurface<dim, field_type>* getPSurfaceObject()
106 {
107 return psurface_.get();
108 }
109
117 static std::shared_ptr<PSurfaceBoundary<dim, field_type> > read(const std::string& filename)
118 {
119 psurface::PSurface<dim, field_type>* newDomain;
120
121#if HAVE_PSURFACE_2_0
122 // Try to read the file as an hdf5 file
123 if (filename.find(".h5")==filename.length()-3) {
124 newDomain = psurface::Hdf5IO<field_type,dim>::read(filename);
125 if (newDomain)
126 return std::make_shared<PSurfaceBoundary<dim, field_type> >(newDomain);
127 }
128#endif
129
130#if HAVE_AMIRAMESH
131 std::unique_ptr<AmiraMesh> am(AmiraMesh::read(filename.c_str()));
132
133 if (!am.get())
134 DUNE_THROW(IOError, "An error has occurred while reading " << filename);
135
136 newDomain
137 = (psurface::PSurface<dim, field_type>*) psurface::AmiraMeshIO<field_type>::readAmiraMesh(am.get(), filename.c_str());
138
139 if (!newDomain)
140 DUNE_THROW(IOError, "An error has occurred while reading " << filename);
141
142 return std::make_shared<PSurfaceBoundary<dim, field_type> >(newDomain);
143#else
144 DUNE_THROW(IOError, "The given file is not in a supported format!");
145#endif
146 }
147
148 private:
149
150 std::unique_ptr<psurface::PSurface<dim, field_type> > psurface_;
151
152 };
153
154}
155
156#endif // #if HAVE_PSURFACE
157#endif // #ifndef DUNE_GRID_IO_FILE_AMIRAMESH_PSURFACE_BOUNDARY_HH
vector space out of a tensor product of fields.
Definition: fvector.hh:95
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:216
Dune namespace.
Definition: alignedallocator.hh:11
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:92
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)