ug4
adapter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022: G-CSC, Goethe University Frankfurt
3  * Authors: Arne Naegel
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  * andreasvogel used scale_add_linker ass template
35  */
36 
37 #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__LINKER_ADAPTER__
38 #define __H__UG__LIB_DISC__SPATIAL_DISC__LINKER_ADAPTER__
39 
40 #include "linker.h"
41 
42 namespace ug{
43 
44 
45 template <int dim>
47  : public StdDataLinker< UserVectorEntryAdapter<dim>, number, dim>
48 {
49 public:
52 
53  typedef number data_type;
55 
58 
59  public:
60 
62  {
63  this->set_num_input(_INPUT_+1); // this linker has one inoput
64  }
65 
66 
67  inline void evaluate (data_type& value,
68  const MathVector<dim>& globIP,
69  number time, int si) const
70  {
71  encapsulated_type dummy;
72  (*m_spEncaps)(dummy, globIP, time, si);
73  value = dummy[m_index];
74  }
75 
76  template <int refDim>
77  inline void evaluate(data_type vValue[],
78  const MathVector<dim> vGlobIP[],
79  number time, int si,
80  GridObject* elem,
81  const MathVector<dim> vCornerCoords[],
82  const MathVector<refDim> vLocIP[],
83  const size_t nip,
84  LocalVector* u,
85  const MathMatrix<refDim, dim>* vJT = NULL) const
86  {
87  std::vector<encapsulated_type> dummy(nip);
88 
89 
90  (*m_spEncaps)(&dummy[0], vGlobIP, time, si,
91  elem, vCornerCoords, vLocIP, nip, u, vJT);
92 
93 
94  for (size_t ip=0; ip<nip; ++ip)
95  { vValue[ip] = dummy[ip][m_index]; }
96  }
97 
98  template <int refDim>
99  void eval_and_deriv(data_type vValue[],
100  const MathVector<dim> vGlobIP[],
101  number time, int si,
102  GridObject* elem,
103  const MathVector<dim> vCornerCoords[],
104  const MathVector<refDim> vLocIP[],
105  const size_t nip,
106  LocalVector* u,
107  bool bDeriv,
108  int s,
109  std::vector<std::vector<data_type > > vvvDeriv[],
110  const MathMatrix<refDim, dim>* vJT = NULL) const
111  {
112  // get the data of the ip series
113  const encapsulated_type* vDummy = m_spEncaps->values(s);
114 
115  for(size_t ip = 0; ip < nip; ++ip)
116  { vValue[ip] = vDummy[ip][m_index]; }
117 
118  // check if something to do
119  if(!bDeriv || this->zero_derivative()) return;
120 
121  // clear all derivative values
122  this->set_zero(vvvDeriv, nip);
123 
124  // Derivatives w.r.t input
125  if( m_spDEncaps.invalid() || m_spDEncaps->zero_derivative()) return;
126 
127  // loop integration points
128  for(size_t ip = 0; ip < nip; ++ip){
129 
130  // loop functions
131  for(size_t fct = 0; fct < m_spDEncaps->num_fct(); ++fct)
132  {
133  // get derivative of w.r.t. to all functions
134  const encapsulated_type* vDInputFct = m_spDEncaps->deriv(s, ip, fct);
135 
136  // get common fct id for this function
137  const size_t commonFct = this->input_common_fct(_INPUT_, fct);
138 
139  // loop all shapes and set the derivative
140  for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
141  {
142  UG_ASSERT(commonFct < vvvDeriv[ip].size(), commonFct<<", "<<vvvDeriv[ip].size());
143  vvvDeriv[ip][commonFct][sh] += vDInputFct[sh][m_index]; // TODO: double check this!
144  }
145 
146  }
147  }
148 
149  }
150 
151  public:
153  void set_vector(SmartPtr<input_type> data, size_t index)
154  {
155  m_spEncaps = data; // for evaluation
156  m_spDEncaps = data.template cast_dynamic<DependentUserData<encapsulated_type, dim> >(); // for derivatives
157  base_type::set_input(_INPUT_, data, data);
158  m_index = index;
159  }
160 
161 
162 
163  protected:
164  size_t m_index;
165 
166  const static int _INPUT_= 0;
167 
171 
172 
173 };
174 
175 } // namespace ug
176 
177 #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__LINKER_ADAPTER__ */
parameterString s
Definition: smart_pointer.h:108
Type based UserData.
Definition: user_data.h:501
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
const MathVector< dim > & ip(size_t s, size_t ip) const
returns global ip
Definition: user_data.h:401
number time() const
get the current evaluation time
Definition: user_data.h:285
Definition: local_algebra.h:198
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 set_num_input(size_t num)
sets the number of inputs
Definition: linker.h:107
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
virtual void set_input(size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info)
sets an input
Definition: linker.h:114
virtual bool zero_derivative() const
returns if derivative is zero
Definition: linker_impl.h:179
Definition: adapter.h:48
StdDataLinker< UserVectorEntryAdapter< dim >, number, dim > base_type
Base class type.
Definition: adapter.h:51
void set_vector(SmartPtr< input_type > data, size_t index)
set conc import
Definition: adapter.h:153
SmartPtr< input_type > m_spEncaps
import for concentration
Definition: adapter.h:169
CplUserData< data_type, dim > user_data_base_type
Definition: adapter.h:54
void eval_and_deriv(data_type 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, bool bDeriv, int s, std::vector< std::vector< data_type > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition: adapter.h:99
static const int _INPUT_
Definition: adapter.h:166
void evaluate(data_type 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: adapter.h:77
void evaluate(data_type &value, const MathVector< dim > &globIP, number time, int si) const
Definition: adapter.h:67
number data_type
Definition: adapter.h:53
UserVectorEntryAdapter()
Definition: adapter.h:61
MathVector< dim > encapsulated_type
Definition: adapter.h:56
SmartPtr< DependentUserData< encapsulated_type, dim > > m_spDEncaps
Definition: adapter.h:170
CplUserData< encapsulated_type, dim > input_type
Definition: adapter.h:57
size_t m_index
Definition: adapter.h:164
static const int dim
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
double number
Definition: types.h:124
the ug namespace