ug4
linker.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
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__LIB_DISC__SPATIAL_DISC__DATA_LINKER__
34 #define __H__UG__LIB_DISC__SPATIAL_DISC__DATA_LINKER__
35 
36 #include "../std_user_data.h"
38 
39 namespace ug{
40 
42 
49 template <typename TImpl, typename TData, int dim>
51  : public StdUserData< StdDataLinker<TImpl, TData, dim>,
52  TData, dim, void,
53  DependentUserData<TData, dim> >
54 {
55  public:
56  virtual void operator() (TData& value,
57  const MathVector<dim>& globIP,
58  number time, int si) const;
59 
60  virtual void operator()(TData vValue[],
61  const MathVector<dim> vGlobIP[],
62  number time, int si, const size_t nip) const;
63 
64  template <int refDim>
65  inline void evaluate(TData vValue[],
66  const MathVector<dim> vGlobIP[],
67  number time, int si,
68  GridObject* elem,
69  const MathVector<dim> vCornerCoords[],
70  const MathVector<refDim> vLocIP[],
71  const size_t nip,
72  LocalVector* u,
73  const MathMatrix<refDim, dim>* vJT = NULL) const;
74 
75  virtual void compute(LocalVector* u, GridObject* elem,
76  const MathVector<dim> vCornerCoords[], bool bDeriv = false);
77  virtual void compute(LocalVectorTimeSeries* u, GridObject* elem,
78  const MathVector<dim> vCornerCoords[], bool bDeriv = false);
79 
80  protected:
81  template <int refDim>
82  void eval_deriv(LocalVector* u, GridObject* elem,
83  const MathVector<dim> vCornerCoords[], bool bDeriv = false);
84  template <int refDim>
86  const MathVector<dim> vCornerCoords[], bool bDeriv = false);
87 
88  public:
90  virtual bool requires_grid_fct() const;
91 
93  virtual bool continuous() const;
94 
96  virtual bool zero_derivative() const;
97 
98  public:
100  bool zero_derivative(size_t i) const
101  {
102  if(!m_vspICplUserData[i].valid()) return true;
103  return m_vspICplUserData[i]->zero_derivative();
104  }
105 
107  void set_num_input(size_t num)
108  {
109  m_vspICplUserData.resize(num);
110  m_vspUserDataInfo.resize(num);
111  }
112 
114  virtual void set_input(size_t i,
117  {
118  UG_ASSERT(i < m_vspICplUserData.size(), "invalid index");
120  m_vspUserDataInfo[i] = info;
121  }
122 
124  virtual size_t num_input() const {return num_needed_data();}
125 
127  virtual size_t num_needed_data() const {return m_vspICplUserData.size();}
128 
131  {
132  UG_ASSERT(i < m_vspICplUserData.size(), "Input not needed");
133  UG_ASSERT(m_vspICplUserData[i].valid(), "Data input not valid");
134  return m_vspICplUserData[i];
135  }
136 
138  virtual void check_setup() const;
139 
142 
143  protected:
145  size_t input_num_fct(size_t i) const
146  {
147  UG_ASSERT(i < m_vspUserDataInfo.size(), "Input invalid");
148  if(!m_vspUserDataInfo[i].valid()) return 0;
149  return m_vspUserDataInfo[i]->num_fct();
150  }
151 
153  size_t input_common_fct(size_t i, size_t fct) const
154  {
155  UG_ASSERT(i < m_vMap.size(), "Input Map invalid");
156  UG_ASSERT(fct < m_vMap[i].num_fct(), "Input Map invalid for fct");
157  return m_vMap[i][fct];
158  }
159 
161  size_t series_id(size_t i, size_t s) const
162  {
163  UG_ASSERT(i < m_vvSeriesID.size(), "invalid index");
164  UG_ASSERT(s < m_vvSeriesID[i].size(), "invalid index");
165  return m_vvSeriesID[i][s];
166  }
167 
169  virtual void local_ip_series_added(const size_t seriesID);
170 
172  virtual void local_ips_changed(const size_t seriesID, const size_t newNumIP);
173 
175  virtual void local_ip_series_to_be_cleared();
176 
178  virtual void global_ips_changed(const size_t seriesID, const MathVector<dim>* vPos, const size_t numIP);
179 
180  protected:
182  std::vector<SmartPtr<ICplUserData<dim> > > m_vspICplUserData;
183 
185  std::vector<SmartPtr<UserDataInfo> > m_vspUserDataInfo;
186 
188  std::vector<FunctionIndexMapping> m_vMap;
189 
191  std::vector<std::vector<size_t> > m_vvSeriesID;
192 
193  protected:
195  TImpl& getImpl() {return static_cast<TImpl&>(*this);}
196 
198  const TImpl& getImpl() const {return static_cast<const TImpl&>(*this);}
199 };
200 
201 } // end namespace ug
202 
203 // include implementation
204 #include "linker_impl.h"
205 
206 #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DATA_LINKER__ */
parameterString s
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
const TData & value(size_t s, size_t ip) const
returns the value at ip
Definition: user_data.h:512
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
Base class for UserData.
Definition: user_data.h:260
number time() const
get the current evaluation time
Definition: user_data.h:285
Definition: local_algebra.h:198
time series of local vectors
Definition: solution_time_series.h:167
A class for fixed size, dense matrices.
Definition: math_matrix.h:52
combines several UserDatas to a new UserData of a specified type
Definition: linker.h:54
void eval_deriv(LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
Definition: linker_impl.h:82
const TImpl & getImpl() const
const access to implementation
Definition: linker.h:198
TImpl & getImpl()
access to implementation
Definition: linker.h:195
void set_num_input(size_t num)
sets the number of inputs
Definition: linker.h:107
std::vector< FunctionIndexMapping > m_vMap
Function mapping for each input relative to common FunctionGroup.
Definition: linker.h:188
bool zero_derivative(size_t i) const
returns if the derivative of the i'th input is zero
Definition: linker.h:100
virtual void local_ips_changed(const size_t seriesID, const size_t newNumIP)
forwards the local positions to the data inputs
Definition: linker_impl.h:290
std::vector< SmartPtr< ICplUserData< dim > > > m_vspICplUserData
data input
Definition: linker.h:182
virtual void local_ip_series_to_be_cleared()
requests cleaning of the ip series in the data inputs
Definition: linker_impl.h:321
std::vector< std::vector< size_t > > m_vvSeriesID
series id the linker uses to get data from input
Definition: linker.h:191
size_t series_id(size_t i, size_t s) const
returns the series id set for the i'th input
Definition: linker.h:161
virtual size_t num_input() const
number of inputs
Definition: linker.h:124
virtual SmartPtr< ICplUserData< dim > > needed_data(size_t i)
return needed data
Definition: linker.h:130
size_t input_common_fct(size_t i, size_t fct) const
returns the number in the common FctGrp for a fct of an input
Definition: linker.h:153
std::vector< SmartPtr< UserDataInfo > > m_vspUserDataInfo
data input casted to IDependend data
Definition: linker.h:185
virtual void set_function_pattern(ConstSmartPtr< FunctionPattern > fctPatt)
updates the function group
Definition: linker_impl.h:198
virtual void set_input(size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info)
sets an input
Definition: linker.h:114
virtual void operator()(TData &value, const MathVector< dim > &globIP, number time, int si) const
returns value for a global position
Definition: linker_impl.h:46
virtual bool zero_derivative() const
returns if derivative is zero
Definition: linker_impl.h:179
virtual void global_ips_changed(const size_t seriesID, const MathVector< dim > *vPos, const size_t numIP)
forwards the global positions to the data inputs
Definition: linker_impl.h:338
virtual void local_ip_series_added(const size_t seriesID)
requests series id's from input data
Definition: linker_impl.h:242
virtual void check_setup() const
returns if data is ok
Definition: linker_impl.h:188
virtual void compute(LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
compute values (and derivatives iff compDeriv == true)
Definition: linker_impl.h:130
void evaluate(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< refDim, dim > *vJT=NULL) const
Definition: linker_impl.h:66
virtual bool requires_grid_fct() const
returns that a grid function is needed for evaluation
Definition: linker_impl.h:161
virtual size_t num_needed_data() const
number of other Data this data depends on
Definition: linker.h:127
size_t input_num_fct(size_t i) const
returns number of functions the input depends on
Definition: linker.h:145
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition: linker_impl.h:170
Definition: std_user_data.h:63
size_t num_fct() const
number of functions this export depends on
Definition: user_data.h:81
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
double number
Definition: types.h:124
static int input(void)
the ug namespace