ug4
invdist_user_data.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3  * Author: Dmitry Logashenko
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  * Inverse Distance Weighting (IDW) interpolation for data sets
35  */
36 #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__IDW_USER_DATA__
37 #define __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__IDW_USER_DATA__
38 
39 #include <vector>
40 
41 // ug4 headers
42 #include "common/common.h"
43 #include "common/math/ugmath.h"
45 
46 namespace ug {
47 
49 
93 template <int WDim, typename TPntIterator, typename TData = number>
95 {
96 public:
97 
99  static const int dim = WDim;
100 
102  typedef TPntIterator t_pnt_iter;
103 
105  typedef TData data_type;
106 
107 public:
108 
110  static void compute
111  (
112  data_type & res,
113  const MathVector<dim> & pos,
114  t_pnt_iter pnt_beg,
115  t_pnt_iter pnt_end,
116  number order,
117  number small_dist = 1e-7
118  );
119 
121  static void compute
122  (
123  data_type & res,
124  const MathVector<dim> & pos,
125  number R,
126  t_pnt_iter pnt_beg,
127  t_pnt_iter pnt_end,
128  number order,
129  number small_dist = 1e-7
130  );
131 };
132 
134 
145 template <int WDim, typename TData = number>
147 : public StdGlobPosData<IDWUserData<WDim, TData>, TData, WDim>
148 {
149 public:
150 
152  static const int dim = WDim;
153 
155  typedef TData data_type;
156 
157 private:
158 
160  struct data_item
161  {
164 
165  data_item (const MathVector<dim> & x, const data_type & v) : pos (x), value (v) {};
166  data_item (const data_item & dat) : pos (dat.pos), value (dat.value) {};
167  };
168 
169 public:
170 
173  : m_order (dim + 1), m_R (0)
174  {}
175 
178  : m_order (order), m_R (R)
179  {}
180 
183 
184 public:
185 
187  void set_radius (number R) {m_R = R;}
188 
190  void set_order (number order) {m_order = order;}
191 
193  void clear () {m_data.clear ();}
194 
196  void load_data_from (std::istream & in);
197 
199  void load_data_from (const char * file_name);
200 
202  void append (const MathVector<dim> & x, const data_type & val) {m_data.push_back (data_item (x, val));}
203 
204 public:
205 
207  inline void evaluate (data_type & value, const MathVector<dim> & x, number time, int si) const
208  {
209  typedef typename std::vector<data_item>::const_iterator pnt_iter_type;
211  m_data.begin (), m_data.end (), m_order);
212  }
213 
214 private:
215 
216  std::vector<data_item> m_data;
219 };
220 
221 } // end namespace ug
222 
223 #include "invdist_user_data_impl.h"
224 
225 #endif // __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__IDW_USER_DATA__
226 
227 /* End of File */
const TData & value(size_t s, size_t ip) const
returns the value at ip
Definition: user_data.h:486
number time() const
get the current evaluation time
Definition: user_data.h:259
Class for inverse distance weighting based on a general data type.
Definition: invdist_user_data.h:95
static void compute(data_type &res, const MathVector< dim > &pos, t_pnt_iter pnt_beg, t_pnt_iter pnt_end, number order, number small_dist=1e-7)
computes the interpolation basing on all the interpolation points
Definition: invdist_user_data_impl.h:44
TPntIterator t_pnt_iter
type of the interpolation point iterator
Definition: invdist_user_data.h:102
static const int dim
dimensionality of the space (i.e. of the coordinate vectors)
Definition: invdist_user_data.h:99
TData data_type
type of the data to extrapolate
Definition: invdist_user_data.h:105
UserData interface for the IDW interpolation.
Definition: invdist_user_data.h:148
void append(const MathVector< dim > &x, const data_type &val)
appends an interpolation point to the list
Definition: invdist_user_data.h:202
static const int dim
dimensionality of the space (i.e. of the coordinate vectors)
Definition: invdist_user_data.h:152
IDWUserData(number order, number R)
class constructor that creates an empty object with given parameters
Definition: invdist_user_data.h:177
void clear()
deletes all the interpolation points from the list
Definition: invdist_user_data.h:193
void load_data_from(std::istream &in)
loads data from a given stream (and appends the loaded points to the current list)
Definition: invdist_user_data_impl.h:131
~IDWUserData()
virtual destructor
Definition: invdist_user_data.h:182
std::vector< data_item > m_data
interpolation points
Definition: invdist_user_data.h:216
number m_order
order of the interpolation
Definition: invdist_user_data.h:217
TData data_type
type of the data to extrapolate
Definition: invdist_user_data.h:155
void evaluate(data_type &value, const MathVector< dim > &x, number time, int si) const
evaluates the data at a given point
Definition: invdist_user_data.h:207
void set_order(number order)
sets the order of the interpolation
Definition: invdist_user_data.h:190
void set_radius(number R)
sets the radius of the neighbourhood where the interpolation points are taken from
Definition: invdist_user_data.h:187
number m_R
radius of the neighbourhood to look for the interpolation points in (0 == infinite)
Definition: invdist_user_data.h:218
IDWUserData()
class constructor that creates an empty object with default parameters
Definition: invdist_user_data.h:172
Definition: std_glob_pos_data.h:55
double number
Definition: types.h:124
the ug namespace
type of a interpolation point data item
Definition: invdist_user_data.h:161
data_type value
value at that point
Definition: invdist_user_data.h:163
MathVector< dim > pos
(global) geometrical coordinates of the point
Definition: invdist_user_data.h:162
data_item(const MathVector< dim > &x, const data_type &v)
Definition: invdist_user_data.h:165
data_item(const data_item &dat)
Definition: invdist_user_data.h:166