Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
interval_linker.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2022: 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 * A linker that cuts out values of a given userdata objection in some interval.
35 */
36#ifndef __H__UG__LIB_DISC__SPATIAL_DISC__INTERVAL_LINKER__
37#define __H__UG__LIB_DISC__SPATIAL_DISC__INTERVAL_LINKER__
38
39/* ug4 headers */
40#include "common/common.h"
41
42#include "linker.h"
43
44namespace ug {
45
50template <int dim>
52 : public StdDataLinker<IntervalNumberLinker<dim>, number, dim>
53{
56
57public:
58
61 (
63 MathVector<dim>& minCoord,
64 MathVector<dim>& maxCoord
65 )
66 {
67 init (spData, minCoord, maxCoord);
68 }
69
72 (
74 std::vector<number> min_coord,
75 std::vector<number> max_coord
76 )
77 {
78 if (min_coord.size () != dim || max_coord.size () != dim)
79 UG_THROW ("IntervalNumberLinker: Illegal sizes of the boundar arrays!");
80 MathVector<dim> minCoord, maxCoord;
81 for (size_t i = 0; i < dim; i++)
82 {
83 minCoord[i] = min_coord[i]; maxCoord[i] = max_coord[i];
84 }
85
86 init (spData, minCoord, maxCoord);
87 }
88
90 void set_default (number v) {def_val = v;}
91
93 virtual bool requires_grid_fct() const {return true;}
94
96 inline void evaluate
97 (
99 const MathVector<dim>& glob_ip,
100 number time,
101 int si
102 ) const
103 {
104 if (is_in (glob_ip))
105 (* m_spData) (value, glob_ip, time, si);
106 else
107 value = def_val;
108 }
109
111 template <int refDim>
112 inline void evaluate
113 (
114 number vValue[],
115 const MathVector<dim> vGlobIP[],
116 number time,
117 int si,
118 GridObject* elem,
119 const MathVector<dim> vCornerCoords[],
120 const MathVector<refDim> vLocIP[],
121 const size_t nip,
122 LocalVector* u,
123 const MathMatrix<refDim, dim>* vJT = NULL
124 ) const
125 {
126 // Compute all, then replace:
127
128 (*m_spData) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
129
130 for (size_t ip = 0; ip < nip; ip++)
131 if (! is_in (vGlobIP[ip]))
132 vValue[ip] = def_val;
133 }
134
136 template <int refDim>
138 (
139 number vValue[],
140 const MathVector<dim> vGlobIP[],
141 number time,
142 int si,
143 GridObject* elem,
144 const MathVector<dim> vCornerCoords[],
145 const MathVector<refDim> vLocIP[],
146 const size_t nip,
147 LocalVector* u,
148 bool bDeriv,
149 int s,
150 std::vector<std::vector<number> > vvvDeriv[],
151 const MathMatrix<refDim, dim>* vJT = NULL
152 ) const
153 {
154 if (this->zero_derivative ())
155 bDeriv = false;
156 else
157 this->set_zero (vvvDeriv, nip);
158
159 const number* vValues = m_spData->values (s);
160
161 for (size_t ip = 0; ip < nip; ip++)
162 if (is_in (vGlobIP[ip]))
163 {
164 vValue[ip] = vValues[ip];
165 if (bDeriv)
166 for (size_t fct = 0; fct < m_spDData->num_fct (); fct++)
167 {
168 const number* vDValues = m_spDData->deriv (s, ip, fct);
169 const size_t c_fct = this->input_common_fct (0, fct);
170 for (size_t sh = 0; sh < this->num_sh (c_fct); sh++)
171 vvvDeriv[ip][c_fct][sh] = vDValues [sh];
172 }
173 }
174 else
175 vValue[ip] = def_val;
176 // The derivatives are all initialized with 0.
177 }
178
179private:
180
182 void init
183 (
185 MathVector<dim>& minCoord,
186 MathVector<dim>& maxCoord
187 )
188 {
189 this->set_num_input (1);
190 m_spData = spData;
191 m_spDData = spData.template cast_dynamic<DependentUserData<number, dim> > ();
192 this->set_input (0, spData, spData);
193 m_minCoord = minCoord; m_maxCoord = maxCoord;
194
195 def_val = 0;
196 }
197
199 bool is_in
200 (
201 const MathVector<dim>& x // the point
202 ) const
203 {
204 for (size_t i = 0; i < dim; i++)
205 if (x[i] < m_minCoord[i] || x[i] > m_maxCoord[i])
206 return false;
207 return true;
208 }
209
213
216
217// the default value
219};
220
221} // end namespace ug
222
223#endif // __H__UG__LIB_DISC__SPATIAL_DISC__INTERVAL_LINKER__
224
225/* End of File */
parameterString s
Definition smart_pointer.h:108
Type based UserData.
Definition user_data.h:501
const TData * values(size_t s) const
returns all values for a series
Definition user_data.h:516
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
number time() const
get the current evaluation time
Definition user_data.h:285
const MathVector< dim > & ip(size_t s, size_t ip) const
returns global ip
Definition user_data.h:401
Definition interval_linker.h:53
void evaluate(number &value, const MathVector< dim > &glob_ip, number time, int si) const
Evaluation for the global coordinates.
Definition interval_linker.h:97
virtual bool requires_grid_fct() const
Returns true because without a grid function, we do not get the element.
Definition interval_linker.h:93
IntervalNumberLinker(SmartPtr< CplUserData< number, dim > > spData, std::vector< number > min_coord, std::vector< number > max_coord)
Constructor.
Definition interval_linker.h:72
void eval_and_deriv(number 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< number > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Computation of the values and the derivatives.
Definition interval_linker.h:138
void set_default(number v)
sets the default values out of the interval
Definition interval_linker.h:90
number def_val
Definition interval_linker.h:218
void evaluate(number 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
Computation without the derivatives.
Definition interval_linker.h:113
IntervalNumberLinker(SmartPtr< CplUserData< number, dim > > spData, MathVector< dim > &minCoord, MathVector< dim > &maxCoord)
Constructor.
Definition interval_linker.h:61
void init(SmartPtr< CplUserData< number, dim > > spData, MathVector< dim > &minCoord, MathVector< dim > &maxCoord)
a general initializer (to call from a constructor)
Definition interval_linker.h:183
SmartPtr< CplUserData< number, dim > > m_spData
data to filter
Definition interval_linker.h:211
MathVector< dim > m_minCoord
the interval
Definition interval_linker.h:215
MathVector< dim > m_maxCoord
Definition interval_linker.h:215
StdDataLinker< IntervalNumberLinker< dim >, number, dim > base_type
Base class type.
Definition interval_linker.h:55
SmartPtr< DependentUserData< number, dim > > m_spDData
Definition interval_linker.h:212
bool is_in(const MathVector< dim > &x) const
checks if the point is in the interval
Definition interval_linker.h:200
Definition local_algebra.h:198
A class for fixed size, dense matrices.
Definition math_matrix.h:63
a mathematical Vector with N entries.
Definition math_vector.h:97
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
virtual void init()
#define UG_THROW(msg)
Definition error.h:57
double number
Definition types.h:124
the ug namespace