ug4
Loading...
Searching...
No Matches
raster_layers_projector.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016: G-CSC, Goethe University Frankfurt
3 * Author: Sebastian Reiter
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG_raster_layers_projector
34#define __H__UG_raster_layers_projector
35
39
40namespace ug{
41
43public:
46
48
52
57
59 {
60 if(g == geometry())
61 return;
62
66 }
67
69 {m_layers = layers;}
70
73
74 number average_rel_z(Vertex* e) const {return m_aaRelZ[e];}
75
76 template <class TElem>
77 number average_rel_z(TElem* e) const
78 {
79 typename TElem::ConstVertexArray vrts = e->vertices();
80 const size_t numVrts = e->num_vertices();
81 if(numVrts == 0)
82 return 0;
83
84 number relZ = 0;
85 for(size_t i = 0; i < numVrts; ++i){
86 relZ += m_aaRelZ[vrts[i]];
87 }
88
89 return relZ / (number)numVrts;
90 }
91
92 virtual number new_vertex(Vertex* vrt, Vertex* parent)
93 {
94 m_aaRelZ[vrt] = m_aaRelZ[parent];
95 set_pos(vrt, pos(parent));
96 return 1;
97 }
98
99 virtual number new_vertex(Vertex* vrt, Edge* parent)
100 {
101 return new_vertex_impl(vrt, parent);
102 }
103
104 virtual number new_vertex(Vertex* vrt, Face* parent)
105 {
106 return new_vertex_impl(vrt, parent);
107 }
108
109 virtual number new_vertex(Vertex* vrt, Volume* parent)
110 {
111 return new_vertex_impl(vrt, parent);
112 }
113
114private:
115 template <class TParent>
116 number new_vertex_impl(Vertex* vrt, TParent* parent)
117 {
118 const number relZ = average_rel_z(parent);
119 m_aaRelZ[vrt] = relZ;
120 vector3 p = geom().element_center(parent);
121 p.z() = m_layers->relative_to_global_height(vector2(p.x(), p.y()), relZ);
122 set_pos(vrt, p);
123 return 1;
124 }
125
127 {
128 static const std::string attName("RasterLayersProjector_ARelZ");
129 if(!GlobalAttachments::is_declared(attName)){
130 GlobalAttachments::declare_attachment<rel_z_attachment_t>(attName);
131 }
132
133 m_aRelZ = GlobalAttachments::attachment<rel_z_attachment_t>(attName);
134
135 IGeometry3d& g = geom();
136 if(!g.grid().has_attachment<Vertex>(m_aRelZ)){
137 g.grid().attach_to_vertices(m_aRelZ);
138 }
139 m_aaRelZ.access(g.grid(), m_aRelZ);
140 }
141
143 {
145 if(geom.valid() && geom->grid().has_vertex_attachment(m_aRelZ)){
146 geom->grid().detach_from_vertices(m_aRelZ);
148 }
149 }
150
152
153 template <class Archive>
154 void serialize( Archive& ar, const unsigned int version)
155 {
156 using namespace ug;
158 if(m_layers.invalid())
160 ar & *m_layers;
161 }
163 }
164
166 }
167
171};
172
174
175}// end of namespace
176
177#endif //__H__UG_raster_layers_projector
parameterString p
#define UG_EMPTY_BASE_CLASS_SERIALIZATION(clsDerived, clsBase)
Definition boost_serialization.h:51
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition smart_pointer.h:212
void invalidate()
Definition attachment_pipe.h:556
Base-class for edges.
Definition grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition grid_base_objects.h:510
static bool is_declared(const std::string &name)
Definition global_attachments.h:111
bool access(Grid &grid, TAttachment &a)
Definition grid.h:189
Definition raster_layer_util.h:59
Definition raster_layers_projector.h:42
SPRasterLayers m_layers
Definition raster_layers_projector.h:168
rel_z_attachment_t m_aRelZ
Definition raster_layers_projector.h:169
void set_layers(SPRasterLayers layers)
Definition raster_layers_projector.h:68
RasterLayersProjector(SPIGeometry3d geometry, SPRasterLayers layers)
Definition raster_layers_projector.h:53
void set_geometry(SPIGeometry3d g)
Definition raster_layers_projector.h:58
virtual number new_vertex(Vertex *vrt, Volume *parent)
called when a new vertex was created from an old volume.
Definition raster_layers_projector.h:109
rel_z_attachment_accessor_t m_aaRelZ
Definition raster_layers_projector.h:170
RasterLayersProjector()
Definition raster_layers_projector.h:47
ANumber rel_z_attachment_t
Definition raster_layers_projector.h:44
number average_rel_z(Vertex *e) const
Definition raster_layers_projector.h:74
void remove_attachments()
Definition raster_layers_projector.h:142
rel_z_attachment_t rel_z_attachment() const
Definition raster_layers_projector.h:71
number new_vertex_impl(Vertex *vrt, TParent *parent)
Definition raster_layers_projector.h:116
virtual number new_vertex(Vertex *vrt, Edge *parent)
called when a new vertex was created from an old edge.
Definition raster_layers_projector.h:99
void add_attachments()
Definition raster_layers_projector.h:126
virtual number new_vertex(Vertex *vrt, Vertex *parent)
called when a new vertex was created from an old vertex.
Definition raster_layers_projector.h:92
void serialize(Archive &ar, const unsigned int version)
Definition raster_layers_projector.h:154
virtual number new_vertex(Vertex *vrt, Face *parent)
called when a new vertex was created from an old face.
Definition raster_layers_projector.h:104
RasterLayersProjector(SPIGeometry3d geometry)
Definition raster_layers_projector.h:49
friend class boost::serialization::access
Definition raster_layers_projector.h:151
Grid::VertexAttachmentAccessor< ANumber > rel_z_attachment_accessor_t
Definition raster_layers_projector.h:45
rel_z_attachment_accessor_t rel_z_attachment_accessor() const
Definition raster_layers_projector.h:72
number average_rel_z(TElem *e) const
Definition raster_layers_projector.h:77
Adjusts vertex coordinates during refinement.
Definition refinement_projector.h:55
IGeometry3d & geom()
Definition refinement_projector.h:165
void set_pos(Vertex *v, const vector3 &p)
Definition refinement_projector.h:157
virtual void set_geometry(SPIGeometry3d geometry)
Definition refinement_projector.h:76
vector3 pos(Vertex *v) const
Definition refinement_projector.h:149
virtual SPIGeometry3d geometry() const
Definition refinement_projector.h:81
Base-class for all vertex-types.
Definition grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition grid_base_objects.h:754
double number
Definition types.h:124
MathVector< 2, number > vector2
a 2d vector
Definition ugmath_types.h:69
the ug namespace
@ AT_GUI
Definition boost_serialization.h:66
@ AT_DATA
Definition boost_serialization.h:65
IGeometry< 3 > IGeometry3d
Definition geometry.h:93
SmartPtr< RasterLayersProjector > SPRasterLayersProjector
Definition raster_layers_projector.h:173
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:836
Provides custom information for different archives.
Definition boost_serialization.h:71