ug4
cylinder_cut_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_cut_projector
34 #define __H__UG_cylinder_cut_projector
35 
36 #include "refinement_projector.h"
37 
38 namespace ug{
39 
41 
50 public:
52  m_center (0, 0, 0),
53  m_axis (0, 0, 1),
54  m_radius (1)
55  {}
56 
58  const vector3& axis,
59  number radius) :
60  m_center (center),
61  m_axis (axis),
63  {}
64 
67  const vector3& center,
68  const vector3& axis,
69  number radius) :
71  m_center (center),
72  m_axis (axis),
74  {}
75 
76 
77 
78  virtual ~CylinderCutProjector () {}
79 
81  const vector3& center () const {return m_center;}
82 
83  void set_axis (const vector3& axis) {m_axis = axis;}
84  const vector3& axis () const {return m_axis;}
85 
87  number radius () const {return m_radius;}
88 
90  virtual number new_vertex(Vertex* vrt, Edge* parent)
91  {
92  number t0, t1;
93  vector3 from = pos(parent->vertex(0));
94  vector3 dir;
95  VecSubtract(dir, pos(parent->vertex(1)), from);
96 
97  if(RayCylinderIntersection(t0, t1, from, dir, m_center, m_axis, m_radius))
98  {
99  // if there are two intersections with parameters between 0 and 1,
100  // we'll return their median.
101  bool t0IsFine = (t0 >= 0) && (t0 <= 1);
102  bool t1IsFine = (t1 >= 0) && (t1 <= 1);
103  if(t0IsFine){
104  if(t1IsFine) {
105  vector3 v0, v1, p;
106  VecScaleAdd(v0, 1., from, t0, dir);
107  VecScaleAdd(v1, 1., from, t1, dir);
108  VecScaleAdd(p, 0.5, v0, 0.5, v1);
109  set_pos(vrt, p);
110  }
111  else {
112  vector3 p;
113  VecScaleAdd(p, 1., from, t0, dir);
114  set_pos(vrt, p);
115  }
116  return 1;
117  }
118  else if(t1IsFine) {
119  vector3 p;
120  VecScaleAdd(p, 1., from, t1, dir);
121  set_pos(vrt, p);
122  return 1;
123  }
124  }
125 
126  RefinementProjector::new_vertex(vrt, parent);
127  return 1;
128  }
129 
130 private:
132 
133  template <class Archive>
134  void serialize( Archive& ar, const unsigned int version)
135  {
136  ar & make_nvp("center", m_center);
137  ar & make_nvp("axis", m_axis);
138  ar & make_nvp("radius", m_radius);
140  }
141 
145 };
146 
147 }// end of namespace
148 
149 #endif //__H__UG_cylinder_cut_projector
parameterString p
#define UG_EMPTY_BASE_CLASS_SERIALIZATION(clsDerived, clsBase)
Definition: boost_serialization.h:51
Refines linearily except for when a refined edge intersects the given cylinder.
Definition: cylinder_cut_projector.h:49
number radius() const
Definition: cylinder_cut_projector.h:87
const vector3 & center() const
Definition: cylinder_cut_projector.h:81
CylinderCutProjector(SPIGeometry3d geometry, const vector3 &center, const vector3 &axis, number radius)
Definition: cylinder_cut_projector.h:66
void set_axis(const vector3 &axis)
Definition: cylinder_cut_projector.h:83
number m_radius
Definition: cylinder_cut_projector.h:144
CylinderCutProjector(const vector3 &center, const vector3 &axis, number radius)
Definition: cylinder_cut_projector.h:57
vector3 m_center
Definition: cylinder_cut_projector.h:142
void serialize(Archive &ar, const unsigned int version)
Definition: cylinder_cut_projector.h:134
void set_radius(number radius)
Definition: cylinder_cut_projector.h:86
void set_center(const vector3 &center)
Definition: cylinder_cut_projector.h:80
CylinderCutProjector()
Definition: cylinder_cut_projector.h:51
friend class boost::serialization::access
Definition: cylinder_cut_projector.h:131
const vector3 & axis() const
Definition: cylinder_cut_projector.h:84
vector3 m_axis
Definition: cylinder_cut_projector.h:143
virtual number new_vertex(Vertex *vrt, Edge *parent)
called when a new vertex was created from an old edge.
Definition: cylinder_cut_projector.h:90
virtual ~CylinderCutProjector()
Definition: cylinder_cut_projector.h:78
Base-class for edges.
Definition: grid_base_objects.h:397
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:366
Adjusts vertex coordinates during refinement.
Definition: refinement_projector.h:55
void set_pos(Vertex *v, const vector3 &p)
Definition: refinement_projector.h:157
virtual number new_vertex(Vertex *vrt, Vertex *parent)
called when a new vertex was created from an old vertex.
Definition: refinement_projector.h:121
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
double number
Definition: types.h:124
bool RayCylinderIntersection(number &tMinOut, number &tMaxOut, const vector3 &rayFrom, const vector3 &rayDir, const vector3 &cylCenter, const vector3 &cylAxis, number cylRadius)
returns the parameter values at which a given ray intersects an infinite cylinder.
Definition: math_util.cpp:386
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition: math_vector_functions_common_impl.hpp:265
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
the ug namespace