Plugins
Loading...
Searching...
No Matches
ls_filinker.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021: 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 * Linkers for extracting data near the level set
35 */
36#ifndef __H__UG__PLUGINS__LEVEL_SET_FILTER_LINKER_H__
37#define __H__UG__PLUGINS__LEVEL_SET_FILTER_LINKER_H__
38
39#include "common/common.h"
40
43
44namespace ug {
45namespace LevelSet {
46
53template <typename TDomain, typename TAlgebra, typename TData>
55: public StdDataLinker< LSFilterLinker<TDomain, TAlgebra, TData>, TData, TDomain::dim>
56{
58
59public:
60
61 // world dimension of grid function
62 static const int dim = TDomain::dim;
63
64 // domain type
65 typedef TDomain domain_type;
66
67 // algebra type
68 typedef TAlgebra algebra_type;
69
70 // extrapolation type
72
73 // type of the data
74 typedef TData data_type;
75
76 // constructor
78 (
80 SmartPtr<extrapol_type> spExtrapol
81 )
82 : m_spExtrapolation (spExtrapol)
83 {
84 if (spData.invalid ())
85 UG_THROW ("LSFilterLinker: No valid data specified.");
86 this->set_num_input(1);
87 m_spData = spData;
88 m_spDData = spData.template cast_dynamic<DependentUserData<data_type, dim> > ();
89 this->set_input (0, spData, spData);
90 }
91
92 inline void evaluate (data_type& value,
93 const MathVector<dim>& globIP,
94 number time, int si) const
95 {
96 UG_THROW ("LSFilterLinker needs the grid element.");
97 }
98
99 template <int refDim>
100 inline void evaluate
101 (
102 data_type vValue[],
103 const MathVector<dim> vGlobIP[],
104 number time,
105 int si,
106 GridObject* elem,
107 const MathVector<dim> vCornerCoords[],
108 const MathVector<refDim> vLocIP[],
109 const size_t nip,
110 LocalVector* u,
111 const MathMatrix<refDim, dim>* vJT = NULL
112 ) const
113 {
114 // check if the element is inside/cut/outside
115 if (m_spExtrapolation.valid ())
116 {
117 const ReferenceObjectID roid = elem->reference_object_id ();
118 const DimReferenceElement<dim>& rRefElem = ReferenceElementProvider::get<dim> (roid);
119
120 if (((extrapol_type *) m_spExtrapolation.get())->check_elem_lsf
121 (rRefElem.num(0), elem, si, false, vCornerCoords, time) == 0)
122 { // element is cut
123 (* m_spData) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
124 return;
125 }
126 }
127
128 // element is not cut, set the value to 0
129 for (size_t ip = 0; ip < nip; ++ip)
130 vValue[ip] = 0;
131 }
132
133 template <int refDim>
135 (
136 data_type vValue[],
137 const MathVector<dim> vGlobIP[],
138 number time,
139 int si,
140 GridObject* elem,
141 const MathVector<dim> vCornerCoords[],
142 const MathVector<refDim> vLocIP[],
143 const size_t nip,
144 LocalVector* u,
145 bool bDeriv,
146 int s,
147 std::vector<std::vector<data_type> > vvvDeriv[],
148 const MathMatrix<refDim, dim>* vJT = NULL
149 ) const
150 {
151 // check if the element is inside/cut/outside
152 if (m_spExtrapolation.valid ())
153 {
154 const ReferenceObjectID roid = elem->reference_object_id ();
155 const DimReferenceElement<dim>& rRefElem = ReferenceElementProvider::get<dim> (roid);
156
157 if (((extrapol_type *) m_spExtrapolation.get())->check_elem_lsf
158 (rRefElem.num(0), elem, si, false, vCornerCoords, time) == 0)
159 { // element is cut
160 const data_type* vV = m_spData->values (s);
161 for (size_t i = 0; i < nip; i++)
162 {
163 vValue[i] = vV[i];
164
165 if (! bDeriv) continue;
166 for (size_t fct = 0; fct < m_spDData->num_fct(); fct++)
167 {
168 const data_type* vDData = m_spDData->deriv (s, i, 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[i][c_fct][sh] = vDData [sh];
172 }
173 }
174 return;
175 }
176 }
177
178 // element not cut, set the output to zero
179 for (size_t ip = 0; ip < nip; ++ip)
180 vValue[ip] = 0;
181 if (bDeriv && ! this->zero_derivative ())
182 this->set_zero (vvvDeriv, nip);
183 }
184
185private:
186
187 // extrapolation by the level-set function
189
190 // the data for the cut elements
193};
194
201template <typename TDomain, typename TAlgebra, typename TData>
203: public StdDataLinker< LSFilterLinker2<TDomain, TAlgebra, TData>, TData, TDomain::dim>
204{
206
207public:
208
209 // world dimension of grid function
210 static const int dim = TDomain::dim;
211
212 // domain type
213 typedef TDomain domain_type;
214
215 // algebra type
216 typedef TAlgebra algebra_type;
217
218 // extrapolation type
220
221 // type of the data
222 typedef TData data_type;
223
224 // constructor
226 (
229 SmartPtr<extrapol_type> spExtrapol
230 )
231 : m_spExtrapolation (spExtrapol)
232 {
233 if (spData_ce.invalid () || spData_we.invalid ())
234 UG_THROW ("LSFilterLinker2: No valid data specified.");
235 this->set_num_input(2);
236
237 m_spData_ce = spData_ce;
238 m_spDData_ce = spData_ce.template cast_dynamic<DependentUserData<data_type, dim> > ();
239 this->set_input (0, spData_ce, spData_ce);
240
241 m_spData_we = spData_we;
242 m_spDData_we = spData_we.template cast_dynamic<DependentUserData<data_type, dim> > ();
243 this->set_input (1, spData_we, spData_we);
244 }
245
246 inline void evaluate (data_type& value,
247 const MathVector<dim>& globIP,
248 number time, int si) const
249 {
250 UG_THROW ("LSFilterLinker2 needs the grid element.");
251 }
252
253 template <int refDim>
254 inline void evaluate
255 (
256 data_type vValue[],
257 const MathVector<dim> vGlobIP[],
258 number time,
259 int si,
260 GridObject* elem,
261 const MathVector<dim> vCornerCoords[],
262 const MathVector<refDim> vLocIP[],
263 const size_t nip,
264 LocalVector* u,
265 const MathMatrix<refDim, dim>* vJT = NULL
266 ) const
267 {
268 // check if the element is inside/cut/outside
269 if (m_spExtrapolation.valid ())
270 {
271 const ReferenceObjectID roid = elem->reference_object_id ();
272 const DimReferenceElement<dim>& rRefElem = ReferenceElementProvider::get<dim> (roid);
273
274 if (((extrapol_type *) m_spExtrapolation.get())->check_elem_lsf
275 (rRefElem.num(0), elem, si, false, vCornerCoords, time) == 0)
276 { // element is cut
277 (* m_spData_ce) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
278 return;
279 }
280 }
281
282 // element is not cut, set the value to 0
283 (* m_spData_we) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
284 }
285
286 template <int refDim>
288 (
289 data_type vValue[],
290 const MathVector<dim> vGlobIP[],
291 number time,
292 int si,
293 GridObject* elem,
294 const MathVector<dim> vCornerCoords[],
295 const MathVector<refDim> vLocIP[],
296 const size_t nip,
297 LocalVector* u,
298 bool bDeriv,
299 int s,
300 std::vector<std::vector<data_type> > vvvDeriv[],
301 const MathMatrix<refDim, dim>* vJT = NULL
302 ) const
303 {
304 // check if the element is inside/cut/outside
305 if (m_spExtrapolation.valid ())
306 {
307 const ReferenceObjectID roid = elem->reference_object_id ();
308 const DimReferenceElement<dim>& rRefElem = ReferenceElementProvider::get<dim> (roid);
309
310 if (((extrapol_type *) m_spExtrapolation.get())->check_elem_lsf
311 (rRefElem.num(0), elem, si, false, vCornerCoords, time) == 0)
312 { // element is cut
313 const data_type* vV = m_spData_ce->values (s);
314 for (size_t i = 0; i < nip; i++)
315 {
316 vValue[i] = vV[i];
317
318 if (! bDeriv) continue;
319 for (size_t fct = 0; fct < m_spDData_ce->num_fct(); fct++)
320 {
321 const data_type* vDData = m_spDData_ce->deriv (s, i, fct);
322 const size_t c_fct = this->input_common_fct (0, fct);
323 for (size_t sh = 0; sh < this->num_sh (c_fct); sh++)
324 vvvDeriv[i][c_fct][sh] = vDData [sh];
325 }
326 }
327 return;
328 }
329 }
330
331 // element not cut, use the second data set
332 const data_type* vV = m_spData_we->values (s);
333 for (size_t i = 0; i < nip; i++)
334 {
335 vValue[i] = vV[i];
336
337 if (! bDeriv) continue;
338 for (size_t fct = 0; fct < m_spDData_we->num_fct(); fct++)
339 {
340 const data_type* vDData = m_spDData_we->deriv (s, i, fct);
341 const size_t c_fct = this->input_common_fct (0, fct);
342 for (size_t sh = 0; sh < this->num_sh (c_fct); sh++)
343 vvvDeriv[i][c_fct][sh] = vDData [sh];
344 }
345 }
346 }
347
348private:
349
350 // extrapolation by the level-set function
352
353 // the data for the cut elements
356
357 // the data for the whole elements
360};
361
362} // namespace LevelSet
363} // end namespace ug
364
365#endif // __H__UG__PLUGINS__LEVEL_SET_FILTER_LINKER_H__
366
367/* End of File */
parameterString s
Definition Biogas.lua:2
TData & value(size_t s, size_t ip)
virtual ReferenceObjectID reference_object_id() const=0
number time() const
const MathVector< dim > & ip(size_t s, size_t ip) const
Definition ls_filinker.h:204
static const int dim
Definition ls_filinker.h:210
void evaluate(data_type &value, const MathVector< dim > &globIP, number time, int si) const
Definition ls_filinker.h:246
TDomain domain_type
Definition ls_filinker.h:213
StdDataLinker< LSFilterLinker< TDomain, TAlgebra, TData >, TData, TDomain::dim > base_type
Definition ls_filinker.h:205
SmartPtr< DependentUserData< data_type, dim > > m_spDData_we
Definition ls_filinker.h:359
TAlgebra algebra_type
Definition ls_filinker.h:216
SmartPtr< DependentUserData< data_type, dim > > m_spDData_ce
Definition ls_filinker.h:355
LSFilterLinker2(SmartPtr< CplUserData< data_type, dim > > spData_ce, SmartPtr< CplUserData< data_type, dim > > spData_we, SmartPtr< extrapol_type > spExtrapol)
Definition ls_filinker.h:226
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 ls_filinker.h:288
SmartPtr< extrapol_type > m_spExtrapolation
Definition ls_filinker.h:351
TData data_type
Definition ls_filinker.h:222
SmartPtr< CplUserData< data_type, dim > > m_spData_ce
Definition ls_filinker.h:354
IInterfaceExtrapolation< domain_type, algebra_type > extrapol_type
Definition ls_filinker.h:219
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 ls_filinker.h:255
SmartPtr< CplUserData< data_type, dim > > m_spData_we
Definition ls_filinker.h:358
Definition ls_filinker.h:56
TAlgebra algebra_type
Definition ls_filinker.h:68
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 ls_filinker.h:135
SmartPtr< DependentUserData< data_type, dim > > m_spDData
Definition ls_filinker.h:192
static const int dim
Definition ls_filinker.h:62
TData data_type
Definition ls_filinker.h:74
IInterfaceExtrapolation< domain_type, algebra_type > extrapol_type
Definition ls_filinker.h:71
SmartPtr< extrapol_type > m_spExtrapolation
Definition ls_filinker.h:188
TDomain domain_type
Definition ls_filinker.h:65
void evaluate(data_type &value, const MathVector< dim > &globIP, number time, int si) const
Definition ls_filinker.h:92
SmartPtr< CplUserData< data_type, dim > > m_spData
Definition ls_filinker.h:191
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 ls_filinker.h:101
StdDataLinker< LSFilterLinker< TDomain, TAlgebra, TData >, TData, TDomain::dim > base_type
Definition ls_filinker.h:57
LSFilterLinker(SmartPtr< CplUserData< data_type, dim > > spData, SmartPtr< extrapol_type > spExtrapol)
Definition ls_filinker.h:78
size_t num(int dim) const
virtual void set_input(size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info)
#define UG_THROW(msg)
double number
ReferenceObjectID