ug4
fv1_sss.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3  * Author: Michael Lampe
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 /*
34  * Singular sources and sinks for the FV discretizations:
35  */
36 
37 #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__FV_SINGULAR_SOURCES_AND_SINKS__
38 #define __H__UG__LIB_DISC__SPATIAL_DISC__FV_SINGULAR_SOURCES_AND_SINKS__
39 
40 #include <vector>
41 
42 // ug4 headers
45 
46 namespace ug {
47 
49 template <int dim, typename TData>
50 class FVPointSourceOrSink : public TData
51 {
52 private:
54 
55 public:
56 
59  (
60  const MathVector<dim>& _point
61  )
62  : point(_point) {}
63 
66  (
67  const MathVector<dim>& _point,
68  const TData& _data
69  )
70  : TData(_data), point(_point) {}
71 
74  (
75  const std::vector<number>& _point
76  )
77  {
78  if (_point.size () != dim)
79  UG_THROW ("FVPointSourceOrSink: Number of coordinates does not match the dimension.");
80  for (size_t i = 0; i < dim; i++) point[i] = _point[i];
81  }
82 
84  const MathVector<dim>& position () {return point;}
85 
87  template <typename TElem, typename TAAPos, typename TFVGeom>
88  bool corresponds_to
89  (
90  TElem* elem,
91  Grid& grid,
92  TAAPos& aaPos,
93  const TFVGeom& geo,
94  size_t co
95  );
96 };
97 
99 template<int dim, typename TData>
100 class FVLineSourceOrSink : public TData
101 {
102 private:
105 
106 public:
107 
110  (
111  const MathVector<dim>& _point1,
112  const MathVector<dim>& _point2
113  )
114  : point1(_point1), point2(_point2) {}
115 
118  (
119  const MathVector<dim>& _point1,
120  const MathVector<dim>& _point2,
121  const TData& _data
122  )
123  : TData(_data), point1(_point1), point2(_point2) {}
124 
127  (
128  const std::vector<number>& _point1,
129  const std::vector<number>& _point2
130  )
131  {
132  if (_point1.size () != dim || _point2.size () != dim)
133  UG_THROW ("FVLineSourceOrSink: Number of coordinates does not match the dimension.");
134  for (size_t i = 0; i < dim; i++)
135  {
136  point1[i] = _point1[i]; point2[i] = _point2[i];
137  }
138  }
139 
142 
144  const MathVector<dim>& to_position () {return point2;}
145 
147  template <typename TElem, typename TAAPos, typename TFVGeom>
148  bool corresponds_to
149  (
150  TElem* elem,
151  Grid& grid,
152  TAAPos& aaPos,
153  const TFVGeom& geo,
154  size_t co,
155  MathVector<dim>& ls,
156  MathVector<dim>& le
157  );
158 };
159 
162 template<typename TData>
163 class FVLineSourceOrSink<1, TData> : public TData
164 {
165 private:
166  static const int dim = 1;
169 
170 public:
171 
174  (
175  const MathVector<dim>& _point1,
176  const MathVector<dim>& _point2
177  )
178  : point1(_point1), point2(_point2) {}
179 
182  (
183  const MathVector<dim>& _point1,
184  const MathVector<dim>& _point2,
185  const TData& _data
186  )
187  : TData(_data), point1(_point1), point2(_point2) {}
188 
191  (
192  const std::vector<number>& _point1,
193  const std::vector<number>& _point2
194  )
195  {
196  UG_THROW ("FVLineSourceOrSink: Line sources and sinks are not supported in 1d.");
197  }
198 
201 
203  const MathVector<dim>& to_position () {return point2;}
204 
206  template <typename TElem, typename TAAPos, typename TFVGeom>
208  (
209  TElem* elem,
210  Grid& grid,
211  TAAPos& aaPos,
212  const TFVGeom& geo,
213  size_t co,
214  MathVector<dim>& ls,
215  MathVector<dim>& le
216  )
217  {
218  UG_THROW ("FVLineSourceOrSink: Line sources and sinks are not supported in 1d.");
219  return false;
220  }
221 };
222 
224 template <int dim, typename TPointData, typename TLineData = TPointData>
226 {
227 public:
230 
231 private:
232  typename std::vector<SmartPtr<point_sss_type> > ListP;
233  typename std::vector<SmartPtr<line_sss_type> > ListL;
234 
235 public:
236 
239 
242  (
243  SmartPtr<point_sss_type> point_sss
244  )
245  {
246  ListP.push_back (point_sss);
247  }
248 
250  void add_line
251  (
252  SmartPtr<line_sss_type> line_sss
253  )
254  {
255  ListL.push_back (line_sss);
256  }
257 
259  size_t num_points () {return ListP.size ();}
260 
262  point_sss_type * point (size_t i) {return ListP[i].get();}
263 
266  {
267  for (size_t i = 0; i < ListP.size (); i++)
268  ((TPointData *) ListP[i].get())->init ();
269  }
270 
272  template <typename TElem, typename TAAPos, typename TFVGeom>
274  {
277 
279  TElem * m_elem;
281  TAAPos & m_aaPos;
282  const TFVGeom & m_geo;
283  size_t m_co;
285  size_t m_index;
286 
287  public:
288 
291  (
292  master_type* sss,
293  TElem* elem,
294  Grid& grid,
295  TAAPos& aaPos,
296  const TFVGeom& geo,
297  size_t co
298  )
299  : m_sss (sss), m_elem (elem), m_grid (grid), m_aaPos (aaPos), m_geo (geo), m_co (co)
300  {
302  next_sss (0);
303  }
304 
307  : m_elem (op.m_elem), m_grid (op.m_grid), m_aaPos (op.m_aaPos),
308  m_geo (op.m_geo), m_co (op.m_co), m_elem_bbox (op.m_elem_bbox),
309  m_index (op.m_index)
310  {}
311 
313  this_type& rewind () {m_index = 0; return * this;}
314 
317 
319  bool is_over () {return m_index >= m_sss->num_points ();}
320 
323  {
324  next_sss (m_index + 1);
325  return * this;
326  }
327 
328  private:
329  void next_sss (size_t index);
330  };
331 
333  size_t num_lines () {return ListL.size ();}
334 
336  line_sss_type * line (size_t i) {return ListL[i].get();}
337 
340  {
341  for (size_t i = 0; i < ListL.size (); i++)
342  ((TLineData *) ListL[i].get())->init ();
343  }
344 
346  template <typename TElem, typename TAAPos, typename TFVGeom>
348  {
351 
353  TElem * m_elem;
355  TAAPos & m_aaPos;
356  const TFVGeom & m_geo;
357  size_t m_co;
359 
360  size_t m_index;
363 
364  public:
365 
368  (
369  master_type* sss,
370  TElem* elem,
371  Grid& grid,
372  TAAPos& aaPos,
373  const TFVGeom& geo,
374  size_t co
375  )
376  : m_sss (sss), m_elem (elem), m_grid (grid), m_aaPos (aaPos), m_geo (geo), m_co (co)
377  {
379  next_sss (0, m_ls, m_le);
380  }
381 
384  : m_elem (op.m_elem), m_grid (op.m_grid), m_aaPos (op.m_aaPos),
385  m_geo (op.m_geo), m_co (op.m_co), m_elem_bbox (op.m_elem_bbox),
386  m_index (op.m_index)
387  {}
388 
390  this_type& rewind () {m_index = 0; return * this;}
391 
394 
396  const MathVector<dim>& seg_start () {return m_ls;}
397 
399  const MathVector<dim>& seg_end () {return m_le;}
400 
402  bool is_over () {return m_index >= m_sss->num_lines ();}
403 
406  {
407  next_sss (m_index + 1, m_ls, m_le);
408  return * this;
409  }
410 
411  private:
412  void next_sss (size_t index, MathVector<dim>& ls, MathVector<dim>& le);
413  };
414 };
415 
416 } // namespace ug
417 
418 #include "fv1_sss_impl.h"
419 
420 #endif // __H__UG__LIB_DISC__SPATIAL_DISC__FV_SINGULAR_SOURCES_AND_SINKS__
421 
422 /* End of File */
Definition: smart_pointer.h:108
const MathVector< dim > & to_position()
returns the end of the line segment
Definition: fv1_sss.h:203
FVLineSourceOrSink(const MathVector< dim > &_point1, const MathVector< dim > &_point2)
class constructor (with the default constructor for data)
Definition: fv1_sss.h:174
FVLineSourceOrSink(const MathVector< dim > &_point1, const MathVector< dim > &_point2, const TData &_data)
class constructor (with the copy constructor for data)
Definition: fv1_sss.h:182
MathVector< dim > point1
beginning of the line segment
Definition: fv1_sss.h:167
MathVector< dim > point2
end of the line segment
Definition: fv1_sss.h:168
bool corresponds_to(TElem *elem, Grid &grid, TAAPos &aaPos, const TFVGeom &geo, size_t co, MathVector< dim > &ls, MathVector< dim > &le)
test whether a source/sink point corresponds to a given corner of the element
Definition: fv1_sss.h:208
FVLineSourceOrSink(const std::vector< number > &_point1, const std::vector< number > &_point2)
class constructor (with the default constructor for data)
Definition: fv1_sss.h:191
const MathVector< dim > & from_position()
returns the beginning of the line segment
Definition: fv1_sss.h:200
Base class for line sources and sinks.
Definition: fv1_sss.h:101
FVLineSourceOrSink(const MathVector< dim > &_point1, const MathVector< dim > &_point2, const TData &_data)
class constructor (with the copy constructor for data)
Definition: fv1_sss.h:118
MathVector< dim > point1
beginning of the line segment
Definition: fv1_sss.h:103
FVLineSourceOrSink(const std::vector< number > &_point1, const std::vector< number > &_point2)
class constructor (with the default constructor for data)
Definition: fv1_sss.h:127
const MathVector< dim > & from_position()
returns the beginning of the line segment
Definition: fv1_sss.h:141
MathVector< dim > point2
end of the line segment
Definition: fv1_sss.h:104
const MathVector< dim > & to_position()
returns the end of the line segment
Definition: fv1_sss.h:144
bool corresponds_to(TElem *elem, Grid &grid, TAAPos &aaPos, const TFVGeom &geo, size_t co, MathVector< dim > &ls, MathVector< dim > &le)
test whether a source/sink point corresponds to a given corner of the element
Definition: fv1_sss_impl.h:98
FVLineSourceOrSink(const MathVector< dim > &_point1, const MathVector< dim > &_point2)
class constructor (with the default constructor for data)
Definition: fv1_sss.h:110
Base class for the point sources and sinks.
Definition: fv1_sss.h:51
bool corresponds_to(TElem *elem, Grid &grid, TAAPos &aaPos, const TFVGeom &geo, size_t co)
test whether a source/sink point corresponds to a given corner of the element
Definition: fv1_sss_impl.h:52
FVPointSourceOrSink(const std::vector< number > &_point)
class constructor (with the default constructor for data)
Definition: fv1_sss.h:74
const MathVector< dim > & position()
returns the point of the source/sink
Definition: fv1_sss.h:84
FVPointSourceOrSink(const MathVector< dim > &_point)
class constructor (with the default constructor for data)
Definition: fv1_sss.h:59
MathVector< dim > point
the point of the source/sink
Definition: fv1_sss.h:53
FVPointSourceOrSink(const MathVector< dim > &_point, const TData &_data)
class constructor (with the copy constructor for data)
Definition: fv1_sss.h:66
class of line source and sink iterator for a given scv
Definition: fv1_sss.h:348
line_iterator(this_type &op)
copy constructor
Definition: fv1_sss.h:383
line_sss_type * operator*()
access operator
Definition: fv1_sss.h:393
this_type & operator++()
moves to the next valid source or sink
Definition: fv1_sss.h:405
MathVector< dim > m_le
the 2nd of the intersection points with the bnd of the scv
Definition: fv1_sss.h:362
const TFVGeom & m_geo
Definition: fv1_sss.h:356
const MathVector< dim > & seg_start()
the 1st of the intersection points with the bnd of the scv
Definition: fv1_sss.h:396
line_iterator(master_type *sss, TElem *elem, Grid &grid, TAAPos &aaPos, const TFVGeom &geo, size_t co)
class constructor (sets the iterator to the beginnging of the list)
Definition: fv1_sss.h:368
void next_sss(size_t index, MathVector< dim > &ls, MathVector< dim > &le)
Definition: fv1_sss_impl.h:242
FVSingularSourcesAndSinks< dim, TPointData, TLineData > master_type
Definition: fv1_sss.h:350
const MathVector< dim > & seg_end()
the 2nd of the intersection points with the bnd of the scv
Definition: fv1_sss.h:399
AABox< MathVector< dim > > m_elem_bbox
Definition: fv1_sss.h:358
Grid & m_grid
Definition: fv1_sss.h:354
master_type * m_sss
Definition: fv1_sss.h:352
bool is_over()
checks whether we are at the end
Definition: fv1_sss.h:402
size_t m_co
Definition: fv1_sss.h:357
this_type & rewind()
moves the iterator to the beginning of the list
Definition: fv1_sss.h:390
MathVector< dim > m_ls
the 1st of the intersection points with the bnd of the scv
Definition: fv1_sss.h:361
TAAPos & m_aaPos
Definition: fv1_sss.h:355
size_t m_index
index of the current source/sink
Definition: fv1_sss.h:360
line_iterator< TElem, TAAPos, TFVGeom > this_type
Definition: fv1_sss.h:349
TElem * m_elem
Definition: fv1_sss.h:353
class of point source and sink iterator for a given scv
Definition: fv1_sss.h:274
TAAPos & m_aaPos
Definition: fv1_sss.h:281
AABox< MathVector< dim > > m_elem_bbox
Definition: fv1_sss.h:284
point_sss_type * operator*()
access operator
Definition: fv1_sss.h:316
TElem * m_elem
Definition: fv1_sss.h:279
point_iterator(this_type &op)
copy constructor
Definition: fv1_sss.h:306
point_iterator< TElem, TAAPos, TFVGeom > this_type
Definition: fv1_sss.h:275
this_type & operator++()
moves to the next valid source or sink
Definition: fv1_sss.h:322
Grid & m_grid
Definition: fv1_sss.h:280
master_type * m_sss
Definition: fv1_sss.h:278
bool is_over()
checks whether we are at the end
Definition: fv1_sss.h:319
size_t m_index
index of the current source/sink
Definition: fv1_sss.h:285
point_iterator(master_type *sss, TElem *elem, Grid &grid, TAAPos &aaPos, const TFVGeom &geo, size_t co)
class constructor (sets the iterator to the beginnging of the list)
Definition: fv1_sss.h:291
void next_sss(size_t index)
Definition: fv1_sss_impl.h:222
size_t m_co
Definition: fv1_sss.h:283
this_type & rewind()
moves the iterator to the beginning of the list
Definition: fv1_sss.h:313
const TFVGeom & m_geo
Definition: fv1_sss.h:282
FVSingularSourcesAndSinks< dim, TPointData, TLineData > master_type
Definition: fv1_sss.h:276
Manager class for point and line sources and sinks.
Definition: fv1_sss.h:226
void init_all_point_sss()
calls the init-functions of all point sinks (if there are any in TPointData)
Definition: fv1_sss.h:265
FVPointSourceOrSink< dim, TPointData > point_sss_type
Definition: fv1_sss.h:228
point_sss_type * point(size_t i)
return a point sink with a given index
Definition: fv1_sss.h:262
std::vector< SmartPtr< line_sss_type > > ListL
Definition: fv1_sss.h:233
void add_line(SmartPtr< line_sss_type > line_sss)
add a line source or sink
Definition: fv1_sss.h:251
FVLineSourceOrSink< dim, TLineData > line_sss_type
Definition: fv1_sss.h:229
size_t num_points()
returns the number of the point sources and sinks
Definition: fv1_sss.h:259
std::vector< SmartPtr< point_sss_type > > ListP
Definition: fv1_sss.h:232
FVSingularSourcesAndSinks()
class constructor
Definition: fv1_sss.h:238
void init_all_line_sss()
calls the init-functions of all line sinks (if there are any in TLineData)
Definition: fv1_sss.h:339
line_sss_type * line(size_t i)
return a line sink with a given index
Definition: fv1_sss.h:336
size_t num_lines()
returns the number of the line sources and sinks
Definition: fv1_sss.h:333
void add_point(SmartPtr< point_sss_type > point_sss)
add a point source or sink
Definition: fv1_sss.h:242
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
static const int dim
#define UG_THROW(msg)
Definition: error.h:57
SM_edge_weight_map< typename T::value_type, ug::BidirectionalMatrix< T > > get(edge_weight_t, ug::BidirectionalMatrix< T > const &g)
Definition: bidirectional_boost.h:157
the ug namespace
AABox< typename TAAPos::ValueType > CalculateBoundingBox(Vertex *e, TAAPos aaPos)
calculates the smallest axis aligned box that contains the given vertex
Definition: bounding_box_util.h:43
Definition: shapes.h:60