Plugins
Loading...
Searching...
No Matches
levset_lin_extrapol.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020: 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 * Extrapolation over the embedded boundary based on the linearization of the
35 * function to extrapolate by a linear function in the element.
36 */
37#ifndef __H__UG__PLUGINS__LEVSET_LIN_EXTRAPOL__
38#define __H__UG__PLUGINS__LEVSET_LIN_EXTRAPOL__
39
40#include <vector>
41
42// ug4 headers
45
46namespace ug {
47namespace LevelSet {
48
50
58template <typename TDomain, typename TAlgebra>
60{
62
63public:
64
66 static constexpr number small_lsf_value = 1e-8;
67
69
77 static bool lsf_inside
78 (
79 number lsf_val
80 )
81 {
82 return lsf_val < - small_lsf_value;
83 }
84
86 typedef TDomain domain_type;
87
89 typedef typename TDomain::grid_type grid_type;
90
92 typedef TAlgebra algebra_type;
93
96
98 typedef typename algebra_type::vector_type vector_type;
99
101 typedef typename algebra_type::matrix_type matrix_type;
102
105
108
111
113 typedef typename domain_type::position_accessor_type position_accessor_type;
114
116 static const int dim = domain_type::dim;
117
122
123private:
124
127
128public:
129
132 (
134 )
135 {
136 if (spLSF.valid () && (spLSF->local_finite_element_id (0) != LFEID (LFEID::LAGRANGE, dim, 1)
137 || spLSF->dd()->num_fct () != 1))
138 UG_THROW ("LevSetGFExtrapolation: The Level-Set Function must be scalar piecewise linear.");
139 m_spLSF = spLSF;
141 }
142
144 void project_LSF ();
145
148 (
150 ) const
151 {
152 if (m_spLSF.invalid ()) return; // there is no LSF, so no matter!
153
154 if (m_vICData.size () != dd->num_fct ())
155 UG_THROW ("LevSetGFExtrapolation: Mismatch of number of the functions!");
156 for (size_t fct = 0; fct < dd->num_fct (); fct++)
157 if (dd->local_finite_element_id (fct) != LFEID (LFEID::LAGRANGE, dim, 1))
158 UG_THROW ("LevSetGFExtrapolation: The Level-Set Function works currently only with piecewise linear functions.");
159 }
160
163 (
164 SmartPtr<approx_space_type> spApproxSpace
165 )
166 {
167 size_t old_num_fct = m_vICData.size ();
168 size_t num_fct = spApproxSpace->num_fct ();
169 m_vICData.resize (num_fct);
170 for (size_t fct = old_num_fct; fct < num_fct; fct++)
171 {
172 m_vICData[fct].Dirichlet = true;
173 m_vICData[fct].func = SPNULL;
174 m_vICData[fct].value = 0;
175 m_vICData[fct].excl_ss.set_subset_handler (spApproxSpace->subset_handler ());
176 }
177 }
178
181 (
182 SmartPtr<approx_space_type> spApproxSpace,
183 const char* fct_name,
184 number value
185 )
186 {
187 prepare_interface_bc (spApproxSpace);
188 size_t fct = spApproxSpace->fct_id_by_name (fct_name);
189 m_vICData[fct].Dirichlet = true;
190 m_vICData[fct].func = SPNULL; // we do not use the function here
191 m_vICData[fct].value = value;
192 }
193
196 (
197 SmartPtr<approx_space_type> spApproxSpace,
198 const char* fct_name,
200 )
201 {
202 prepare_interface_bc (spApproxSpace);
203 size_t fct = spApproxSpace->fct_id_by_name (fct_name);
204 m_vICData[fct].Dirichlet = true;
205 m_vICData[fct].func = func;
206 m_vICData[fct].value = 0; // a dummy value
207 }
208
211 (
212 SmartPtr<approx_space_type> spApproxSpace,
213 const char* fct_name
214 )
215 {
216 prepare_interface_bc (spApproxSpace);
217 size_t fct = spApproxSpace->fct_id_by_name (fct_name);
218 m_vICData[fct].Dirichlet = false;
219 m_vICData[fct].func = SPNULL; // a dummy value
220 m_vICData[fct].value = 0; // a dummy value
221 }
222
225 (
226 SmartPtr<approx_space_type> spApproxSpace,
227 const char* subset_names
228 )
229 {
230 std::string ss_names (subset_names);
231 std::vector<std::string> v_ss_names;
232 TokenizeTrimString (ss_names, v_ss_names);
233 m_excl_ssg.set_subset_handler (spApproxSpace->subset_handler ());
234 m_excl_ssg.add (v_ss_names);
235 }
236
237private:
238
241 (
242 size_t fct
243 ) const;
244
247 (
248 size_t co
249 ) const
250 {
251 return m_co_excluded [co];
252 }
253
254//---- Extrapolation ----//
255public:
256
259 (
260 size_t n_co,
261 GridObject * pElem,
262 int si,
263 int g_level,
264 bool use_hanging,
265 const MathVector<dim> vCornerCoords [],
266 number time
267 );
268
271 (
272 size_t co
273 ) const
274 {return lsf_inside (m_locLSF.value (0, co));}
275
278 (
279 size_t co
280 ) const
281 {return m_locLSF.value (0, co);}
282
284 template <typename TElem>
286 (
287 LocalVector& locU,
288 size_t base_co
289 ) const;
290
293 (
294 size_t num_co,
295 size_t base_co,
296 number * u,
297 size_t fct
298 ) const;
299
302 (
303 size_t num_co,
304 number * u,
305 size_t fct
306 ) const;
307
309 template <typename TElem>
311 (
312 LocalVector& locD,
313 size_t base_co
314 );
315
317 template <typename TElem>
319 (
320 LocalMatrix& locM,
321 size_t base_co
322 );
323
325 template <typename TElem>
327 (
328 LocalMatrix& locM,
329 LocalVector& locB,
330 size_t base_co
331 );
332
334 template <typename TElem>
336 (
337 LocalMatrix& locM,
338 LocalVector& locB
339 );
340
341private:
342
344 template <int refDim>
346 (
347 size_t num_co,
348 size_t base_co,
349 number * u,
350 size_t fct
351 ) const;
352
354 template <int refDim>
356 (
357 size_t num_co,
358 number * u,
359 size_t fct
360 ) const;
361
362//---- Resetting data in the outer parts ----//
363public:
364
367 (
368 vector_type & d,
369 const DoFDistribution * dd
370 ) const;
371
374 (
375 vector_type & u,
376 const DoFDistribution * dd,
377 number time
378 );
379
382 (
383 matrix_type & A,
384 const DoFDistribution * dd
385 ) const;
386
387private:
388
390 template <typename TElem>
392 (
393 vector_type & u,
394 size_t fct,
395 const DoFDistribution * dd,
396 number time,
399 );
400
403 {
406 size_t m_fct;
411
413 (
414 this_type * pThis,
415 vector_type & u,
416 size_t fct,
417 const DoFDistribution * dd,
418 number time,
421 ) : m_pThis (pThis), m_u (u), m_fct (fct), m_dd (dd), m_time (time), m_aaBC (aaBC), m_aaNumElem (aaNumElem) {};
422
423 template <typename TElem> void operator () (TElem &)
424 {
425 m_pThis->template sum_up_near_if_outer_values_for_<TElem> (m_u, m_fct, m_dd, m_time, m_aaBC, m_aaNumElem);
426 }
427 };
428
430 void prepare_grid_levels ();
431
432private:
433
440
442 std::vector<GLData> m_vGLData;
443
452
453 std::vector<ICData> m_vICData;
454
456
457// temporaty data (valid for the initialization with a particular element)
458
461
463 int m_si;
467
469
470}; // class LevSetGFExtrapolation
471
473
480template <typename TDomain, typename TAlgebra>
482: public LSGFDomainDiscretization<TDomain, TAlgebra, LevSetGFlinearExtrapolation<TDomain, TAlgebra> >
483{
486
489
490public:
491
494 : base_type (pApproxSpace)
495 {}
496};
497
498} // namespace LevelSet
499} // end namespace ug
500
502
503#endif // __H__UG__PLUGINS__LEVSET_LIN_EXTRAPOL__
504
505/* End of File */
bool valid() const
Global assembler for the simple extrapolation method.
Definition levset_lin_extrapol.h:483
LSGFlinearDomainDiscretization(SmartPtr< approx_space_type > pApproxSpace)
default Constructor
Definition levset_lin_extrapol.h:493
LSGFDomainDiscretization< TDomain, TAlgebra, LevSetGFlinearExtrapolation< TDomain, TAlgebra > > base_type
Type of the base class.
Definition levset_lin_extrapol.h:485
ApproximationSpace< TDomain > approx_space_type
Type of approximation space.
Definition levset_lin_extrapol.h:488
Level-set extrapolation for the ghost-fluid method based on piecewise linear LS functions.
Definition levset_lin_extrapol.h:60
algebra_type::vector_type vector_type
vector type (for the functions to extrapolate)
Definition levset_lin_extrapol.h:98
void check_dd(ConstSmartPtr< DoFDistribution > dd) const
checks the dof distribution of the solution
Definition levset_lin_extrapol.h:148
GridFunction< domain_type, lsf_algebra_type > ls_grid_func_type
grid function type for the LSF
Definition levset_lin_extrapol.h:104
bool m_co_excluded[max_num_corners]
if corners are excluded by subsets (only for cut elements)
Definition levset_lin_extrapol.h:466
LevSetGFlinearExtrapolation()
class constructor
Definition levset_lin_extrapol.h:119
void extrapolate_by_lsf_in_(size_t num_co, size_t base_co, number *u, size_t fct) const
extrapolates a component of the solution to the vertices behind the interface (w.r....
Definition levset_lin_extrapol_impl.h:372
void sum_up_near_if_outer_values_for_(vector_type &u, size_t fct, const DoFDistribution *dd, number time, Grid::VertexAttachmentAccessor< ANumber > &aaBC, Grid::VertexAttachmentAccessor< AUInt > &aaNumElem)
sets the values at the outer vertices near the interface (for one type of the elements)
Definition levset_lin_extrapol_impl.h:896
TDomain domain_type
domain type
Definition levset_lin_extrapol.h:86
number m_time
the physical time from the current initialization
Definition levset_lin_extrapol.h:468
std::vector< ICData > m_vICData
the boundary conditions at the interface
Definition levset_lin_extrapol.h:453
number lsf_at(size_t co) const
returns the effective value of the LSF at a corner (use after check_elem_lsf)
Definition levset_lin_extrapol.h:278
LocalIndices m_indLSF
indices of the LSF dof's
Definition levset_lin_extrapol.h:459
void set_Dirichlet_for(SmartPtr< approx_space_type > spApproxSpace, const char *fct_name, SmartPtr< CplUserData< number, dim > > func)
adds a Dirichlet BC with a given value
Definition levset_lin_extrapol.h:196
void set_Dirichlet_for(SmartPtr< approx_space_type > spApproxSpace, const char *fct_name, number value)
adds a Dirichlet BC with a given value
Definition levset_lin_extrapol.h:181
void set_Neumann0_for(SmartPtr< approx_space_type > spApproxSpace, const char *fct_name)
adds a Neumann-0
Definition levset_lin_extrapol.h:211
number boundary_value(size_t fct) const
gets the BC value
Definition levset_lin_extrapol_impl.h:308
LevSetGFlinearExtrapolation< TDomain, TAlgebra > this_type
Definition levset_lin_extrapol.h:61
static const size_t max_num_corners
max. number of corners of an grid element
Definition levset_lin_extrapol.h:126
const MathVector< dim > * m_vCornerCoords
array of coordinates of the corners
Definition levset_lin_extrapol.h:465
static constexpr number small_lsf_value
the threshold for the level-set function
Definition levset_lin_extrapol.h:66
void clear_outer_vectors(LocalVector &locD, size_t base_co)
sets the values of the vector at the non-base vertices to 0
Definition levset_lin_extrapol_impl.h:520
TAlgebra algebra_type
algebra type for the functions to extrapolate
Definition levset_lin_extrapol.h:92
void eliminate_extrapolated(LocalMatrix &locM, size_t base_co)
eliminates the matrix connections to the vertices behind the interface
Definition levset_lin_extrapol_impl.h:539
void extrapolate_sol_by_lsf(LocalVector &locU, size_t base_co) const
extrapolates all the components of the solution to the vertices behind the interface (w....
Definition levset_lin_extrapol_impl.h:331
static bool lsf_inside(number lsf_val)
returns true if the given value should correspond to the 'inside' subdomain
Definition levset_lin_extrapol.h:78
std::vector< GLData > m_vGLData
data on the grid levels
Definition levset_lin_extrapol.h:442
void set_outer_matrices(matrix_type &A, const DoFDistribution *dd) const
sets the matrices at outer vertices to identity
Definition levset_lin_extrapol_impl.h:964
static const int dim
dimensionality (the World dimension)
Definition levset_lin_extrapol.h:116
void prepare_grid_levels()
projects the level-set functions to the coarser grid levels
Definition levset_lin_extrapol_impl.h:695
void clear_outer_values(vector_type &d, const DoFDistribution *dd) const
sets the values at the outer vertices to 0
Definition levset_lin_extrapol_impl.h:745
int check_elem_lsf(size_t n_co, GridObject *pElem, int si, int g_level, bool use_hanging, const MathVector< dim > vCornerCoords[], number time)
checks whether the element is intersected by the interface, or what, and prepares the data
Definition levset_lin_extrapol_impl.h:234
GridObject * m_pElem
the current grid element
Definition levset_lin_extrapol.h:462
LocalVector m_locLSF
corner values of the LFS (if initialized)
Definition levset_lin_extrapol.h:460
void set_outer_values(vector_type &u, const DoFDistribution *dd, number time)
sets the values at the outer vertices to given values
Definition levset_lin_extrapol_impl.h:796
CPUAlgebra lsf_algebra_type
algebra type for the LSF
Definition levset_lin_extrapol.h:95
SmartPtr< ls_grid_func_type > m_spLSF
original Level-Set function
Definition levset_lin_extrapol.h:441
SubsetGroup m_excl_ssg
subsets to exclude
Definition levset_lin_extrapol.h:455
algebra_type::matrix_type matrix_type
matrix type
Definition levset_lin_extrapol.h:101
void exclude_subsets(SmartPtr< approx_space_type > spApproxSpace, const char *subset_names)
excludes a (boundary) subsets from the extrapolation; note that this resets the old excluded subsets
Definition levset_lin_extrapol.h:225
domain_type::position_accessor_type position_accessor_type
type of the position attachment accessor
Definition levset_lin_extrapol.h:113
ApproximationSpace< domain_type > approx_space_type
type of approximation space
Definition levset_lin_extrapol.h:110
StdInjection< domain_type, lsf_algebra_type > projection_type
type of the projection of the LSF to the coarser grid levels
Definition levset_lin_extrapol.h:107
void project_LSF()
projects the values of the LSF to the coarser levels
Definition levset_lin_extrapol_impl.h:732
void prepare_interface_bc(SmartPtr< approx_space_type > spApproxSpace)
prepares the boundary conditions at the interface: sets all them to Dirichlet-0
Definition levset_lin_extrapol.h:163
TDomain::grid_type grid_type
grid type for the domain
Definition levset_lin_extrapol.h:89
void extrapolate_by_lsf(size_t num_co, size_t base_co, number *u, size_t fct) const
extrapolates a component of the solution to the vertices behind the interface (w.r....
Definition levset_lin_extrapol_impl.h:416
void set_LSF(SmartPtr< ls_grid_func_type > spLSF)
set the level-set function and check it
Definition levset_lin_extrapol.h:132
bool corner_excluded(size_t co) const
checks if the corner is excluded
Definition levset_lin_extrapol.h:247
MathVector< dim > m_elemCenter
center of the element
Definition levset_lin_extrapol.h:464
bool corner_inside(size_t co) const
returns true if the corner is "inside" (use after check_elem_lsf)
Definition levset_lin_extrapol.h:271
int m_si
subset index of the element
Definition levset_lin_extrapol.h:463
number & value(size_t fct, size_t dof)
void add(const char *name)
void set_subset_handler(ConstSmartPtr< ISubsetHandler > sh)
UG_API std::vector< std::string > TokenizeTrimString(const std::string &str, const char delimiter=',')
const NullSmartPtr SPNULL
#define UG_THROW(msg)
double number
Class for the level-set function on the coarser levels.
Definition levset_lin_extrapol.h:436
SmartPtr< ls_grid_func_type > lsf_on_gl
level-set function on the level
Definition levset_lin_extrapol.h:437
SmartPtr< projection_type > inject
the canonical restriction for the grid level
Definition levset_lin_extrapol.h:438
Class for the specification of the boundary conditions at the interface (for one component/function)
Definition levset_lin_extrapol.h:446
SubsetGroup excl_ss
subsets to exclude
Definition levset_lin_extrapol.h:450
SmartPtr< CplUserData< number, dim > > func
variable Dirichlet value (for the Dirichlet BC)
Definition levset_lin_extrapol.h:448
number value
Dirichlet value (for the Dirichlet BC, if func is NULL)
Definition levset_lin_extrapol.h:449
bool Dirichlet
false for Neumann-0 BC, true for Dirichlet BC
Definition levset_lin_extrapol.h:447
helper class for the loop over all the element types
Definition levset_lin_extrapol.h:403
Grid::VertexAttachmentAccessor< ANumber > & m_aaBC
Definition levset_lin_extrapol.h:409
vector_type & m_u
Definition levset_lin_extrapol.h:405
size_t m_fct
Definition levset_lin_extrapol.h:406
number m_time
Definition levset_lin_extrapol.h:408
const DoFDistribution * m_dd
Definition levset_lin_extrapol.h:407
void operator()(TElem &)
Definition levset_lin_extrapol.h:423
SumUpNearIfOuterValues(this_type *pThis, vector_type &u, size_t fct, const DoFDistribution *dd, number time, Grid::VertexAttachmentAccessor< ANumber > &aaBC, Grid::VertexAttachmentAccessor< AUInt > &aaNumElem)
Definition levset_lin_extrapol.h:413
Grid::VertexAttachmentAccessor< AUInt > & m_aaNumElem
Definition levset_lin_extrapol.h:410
this_type * m_pThis
Definition levset_lin_extrapol.h:404