ug4
cylinder_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_cylinder_projector_new
34 #define __H__UG_cylinder_projector_new
35 
37 #include "refinement_projector.h"
38 
39 namespace ug{
41 
50 public:
52  m_center (0, 0, 0),
53  m_axis (0, 0, 1),
54  m_radius (-1),
56  {}
57 
59  const vector3& axis) :
60  m_center (center),
61  m_axis (axis),
62  m_radius (-1),
64  {}
65 
67  const vector3& axis,
68  number radius) :
69  m_center (center),
70  m_axis (axis),
71  m_radius (radius),
73  {}
74 
76  const vector3& axis,
77  number radius,
78  number influenceRadius) :
79  m_center (center),
80  m_axis (axis),
81  m_radius (radius),
82  m_influenceRadius (influenceRadius)
83  {}
84 
87  const vector3& center,
88  const vector3& axis,
89  number radius,
90  number influenceRadius) :
92  m_center (center),
93  m_axis (axis),
94  m_radius (radius),
95  m_influenceRadius (influenceRadius)
96  {}
97 
98  virtual ~CylinderProjector () {}
99 
101  const vector3& center () const {return m_center;}
102 
103  void set_axis (const vector3& axis) {m_axis = axis;}
104  const vector3& axis () const {return m_axis;}
105 
107  number radius () const {return m_radius;}
108 
109  void set_influence_radius (number influenceRadius) {m_influenceRadius = influenceRadius;}
111 
113  virtual number new_vertex(Vertex* vrt, Edge* parent)
114  {
115  return perform_projection(vrt, parent);
116  }
117 
119  virtual number new_vertex(Vertex* vrt, Face* parent)
120  {
121  return perform_projection(vrt, parent);
122  }
123 
125  virtual number new_vertex(Vertex* vrt, Volume* parent)
126  {
127  return perform_projection(vrt, parent);
128  }
129 
130 private:
131 
132  template <class TElem>
133  number perform_projection(Vertex* vrt, TElem* parent)
134  {
135  // calculate the new position by linear interpolation and project that point
136  // onto the cylinder.
137  typename TElem::ConstVertexArray vrts = parent->vertices();
138  size_t numVrts = parent->num_vertices();
139 
140  if(numVrts == 0){
141  set_pos(vrt, vector3(0, 0, 0));
142  return 1;
143  }
144 
145  number avDist = 0;
146  vector3 parentCenter (0, 0, 0);
147 
148  for(size_t i = 0; i < numVrts; ++i){
149  vector3 p = pos(vrts[i]);
150  avDist += DistancePointToRay(p, m_center, m_axis);
151  parentCenter += p;
152  }
153 
154  avDist /= (number)numVrts;
155  VecScale(parentCenter, parentCenter, 1. / (number)numVrts);
156 
157  vector3 proj, v;
158  ProjectPointToRay(proj, parentCenter, m_center, m_axis);
159  VecSubtract(v, parentCenter, proj);
160  number len = VecLength(v);
161  if(len > SMALL * avDist){ // if avDist is very small, len may be small, too
162  VecScale(v, v, avDist/len);
163  proj += v;
164  set_pos(vrt, proj);
165  }
166  else
167  set_pos(vrt, parentCenter);
168 
169  if(m_influenceRadius > 0) {
171  const number dist = m_radius - m_influenceRadius;
172  if(dist > 0)
173  return clip<number>((len - m_influenceRadius) / dist, 0, 1);
174  return len > m_radius ? 1 : 0;
175  }
176  else if(m_radius >= 0){
177  const number dist = m_influenceRadius - m_radius;
178  if(dist > 0)
179  return clip<number>(1 - (len - m_radius) / dist, 0, 1);
180  return len < m_radius ? 1 : 0;
181  }
182  else
183  return clip<number>(1 - len / m_influenceRadius, 0, 1);
184  }
185  return 1;
186  }
187 
188 
190 
191  template <class Archive>
192  void serialize( Archive& ar, const unsigned int version)
193  {
194  ar & make_nvp("center", m_center);
195  ar & make_nvp("axis", m_axis);
196  ar & make_nvp("radius", m_radius);
197  ar & make_nvp("influence radius", m_influenceRadius);
199  }
200 
205 };
206 
207 }// end of namespace
208 
209 #endif //__H__UG_cylinder_projector_new
parameterString p
#define UG_EMPTY_BASE_CLASS_SERIALIZATION(clsDerived, clsBase)
Definition: boost_serialization.h:51
Projects new vertices onto a sphere during refinement.
Definition: cylinder_projector.h:49
virtual number new_vertex(Vertex *vrt, Volume *parent)
called when a new vertex was created from an old volume.
Definition: cylinder_projector.h:125
void set_axis(const vector3 &axis)
Definition: cylinder_projector.h:103
vector3 m_center
Definition: cylinder_projector.h:201
void set_radius(number radius)
Definition: cylinder_projector.h:106
void serialize(Archive &ar, const unsigned int version)
Definition: cylinder_projector.h:192
vector3 m_axis
Definition: cylinder_projector.h:202
CylinderProjector(const vector3 &center, const vector3 &axis, number radius)
Definition: cylinder_projector.h:66
number radius() const
Definition: cylinder_projector.h:107
virtual ~CylinderProjector()
Definition: cylinder_projector.h:98
const vector3 & center() const
Definition: cylinder_projector.h:101
CylinderProjector()
Definition: cylinder_projector.h:51
virtual number new_vertex(Vertex *vrt, Face *parent)
called when a new vertex was created from an old face.
Definition: cylinder_projector.h:119
number influence_radius() const
Definition: cylinder_projector.h:110
virtual number new_vertex(Vertex *vrt, Edge *parent)
called when a new vertex was created from an old edge.
Definition: cylinder_projector.h:113
CylinderProjector(SPIGeometry3d geometry, const vector3 &center, const vector3 &axis, number radius, number influenceRadius)
Definition: cylinder_projector.h:86
const vector3 & axis() const
Definition: cylinder_projector.h:104
friend class boost::serialization::access
Definition: cylinder_projector.h:189
number m_radius
Definition: cylinder_projector.h:203
number m_influenceRadius
Definition: cylinder_projector.h:204
CylinderProjector(const vector3 &center, const vector3 &axis, number radius, number influenceRadius)
Definition: cylinder_projector.h:75
number perform_projection(Vertex *vrt, TElem *parent)
Definition: cylinder_projector.h:133
void set_influence_radius(number influenceRadius)
Definition: cylinder_projector.h:109
void set_center(const vector3 &center)
Definition: cylinder_projector.h:100
CylinderProjector(const vector3 &center, const vector3 &axis)
Definition: cylinder_projector.h:58
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Adjusts vertex coordinates during refinement.
Definition: refinement_projector.h:55
void set_pos(Vertex *v, const vector3 &p)
Definition: refinement_projector.h:157
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
number DistancePointToRay(const vector_t &v, const vector_t &from, const vector_t &dir)
calculates the distance of a point to a ray
Definition: math_util_impl.hpp:225
number ProjectPointToRay(vector_t &vOut, const vector_t &v, const vector_t &from, const vector_t &dir)
finds the projection of v onto the ray defined by from and dir
Definition: math_util_impl.hpp:160
vector_t::value_type VecLength(const vector_t &v)
returns the length of v. Slower than VecLengthSq.
Definition: math_vector_functions_common_impl.hpp:341
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition: math_vector_functions_common_impl.hpp:226
MathVector< 3, number > vector3
a 3d vector
Definition: ugmath_types.h:72
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
scales a MathVector<N>
Definition: math_vector_functions_common_impl.hpp:252
the ug namespace
const number SMALL
Definition: math_constants.h:41