Plugins
Loading...
Searching...
No Matches
levset_simple_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 interface based on the simple linear extrapolation along the ray.
35 */
36#ifndef __H__UG__PLUGINS__LEVSET_SIMPLE_EXTRAPOL__
37#define __H__UG__PLUGINS__LEVSET_SIMPLE_EXTRAPOL__
38
39#include <vector>
40
41// ug4 headers
44
45namespace ug {
46namespace LevelSet {
47
49
57template <typename TDomain, typename TAlgebra>
59{
61
62public:
63
65 static constexpr number small_lsf_value = 1e-8;
66
68
76 static bool lsf_inside
77 (
78 number lsf_val
79 )
80 {
81 return lsf_val < - small_lsf_value;
82 }
83
85 typedef TDomain domain_type;
86
88 typedef typename TDomain::grid_type grid_type;
89
91 typedef TAlgebra algebra_type;
92
95
97 typedef typename algebra_type::vector_type vector_type;
98
100 typedef typename algebra_type::matrix_type matrix_type;
101
104
107
110
112 typedef typename domain_type::position_accessor_type position_accessor_type;
113
115 static const int dim = domain_type::dim;
116
117private:
118
127
130
131public:
132
137
140 (
142 )
143 {
144 if (spLSF.valid () && (spLSF->local_finite_element_id (0) != LFEID (LFEID::LAGRANGE, dim, 1)
145 || spLSF->dd()->num_fct () != 1))
146 UG_THROW ("LevSetGFExtrapolation: The Level-Set Function must be scalar piecewise linear.");
147 m_spLSF = spLSF;
149 }
150
152 void project_LSF ();
153
156 (
158 ) const
159 {
160 if (m_spLSF.invalid ()) return; // there is no LSF, so no matter!
161
162 if (m_vICData.size () != dd->num_fct ())
163 UG_THROW ("LevSetGFExtrapolation: Mismatch of number of the functions!");
164 for (size_t fct = 0; fct < dd->num_fct (); fct++)
165 if (dd->local_finite_element_id (fct) != LFEID (LFEID::LAGRANGE, dim, 1))
166 UG_THROW ("LevSetGFExtrapolation: The Level-Set Function works currently only with piecewise linear functions.");
167 }
168
171 (
172 SmartPtr<approx_space_type> spApproxSpace
173 )
174 {
175 m_vICData.resize (spApproxSpace->num_fct ());
176 }
177
180 (
181 SmartPtr<approx_space_type> spApproxSpace,
182 const char* fct_name,
183 number value
184 )
185 {
186 prepare_interface_bc (spApproxSpace);
187 size_t fct = spApproxSpace->fct_id_by_name (fct_name);
188 m_vICData[fct].bc_kind = DIRICHLET_BC;
189 m_vICData[fct].func = SPNULL; // we do not use the function here
190 m_vICData[fct].value = value;
191 }
192
195 (
196 SmartPtr<approx_space_type> spApproxSpace,
197 const char* fct_name,
199 )
200 {
201 prepare_interface_bc (spApproxSpace);
202 size_t fct = spApproxSpace->fct_id_by_name (fct_name);
203 m_vICData[fct].bc_kind = DIRICHLET_BC;
204 m_vICData[fct].func = func;
205 m_vICData[fct].value = 0; // a dummy value
206 }
207
210 (
211 SmartPtr<approx_space_type> spApproxSpace,
212 const char* fct_name,
213 number value
214 )
215 {
216 prepare_interface_bc (spApproxSpace);
217 size_t fct = spApproxSpace->fct_id_by_name (fct_name);
218 m_vICData[fct].bc_kind = DIRICHLET_PLAIN_BC;
219 m_vICData[fct].func = SPNULL; // we do not use the function here
220 m_vICData[fct].value = value;
221 }
222
225 (
226 SmartPtr<approx_space_type> spApproxSpace,
227 const char* fct_name,
229 )
230 {
231 prepare_interface_bc (spApproxSpace);
232 size_t fct = spApproxSpace->fct_id_by_name (fct_name);
233 m_vICData[fct].bc_kind = DIRICHLET_PLAIN_BC;
234 m_vICData[fct].func = func;
235 m_vICData[fct].value = 0; // a dummy value
236 }
237
240 (
241 SmartPtr<approx_space_type> spApproxSpace,
242 const char* fct_name
243 )
244 {
245 prepare_interface_bc (spApproxSpace);
246 size_t fct = spApproxSpace->fct_id_by_name (fct_name);
247 m_vICData[fct].bc_kind = NEUMANN_0_BC;
248 m_vICData[fct].func = SPNULL; // a dummy value
249 m_vICData[fct].value = 0; // a dummy value
250 }
251
254 (
255 SmartPtr<approx_space_type> spApproxSpace,
256 const char* subset_names
257 )
258 {
259 std::string ss_names (subset_names);
260 std::vector<std::string> v_ss_names;
261 TokenizeTrimString (ss_names, v_ss_names);
262 m_excl_ssg.set_subset_handler (spApproxSpace->subset_handler ());
263 m_excl_ssg.add (v_ss_names);
264 }
265
266private:
267
270 (
271 size_t fct
272 ) const;
273
276 (
277 size_t co
278 ) const
279 {
280 return m_co_excluded [co];
281 }
282
283//---- Extrapolation ----//
284public:
285
288 (
289 size_t n_co,
290 GridObject * pElem,
291 int si,
292 int g_level,
293 bool use_hanging,
294 const MathVector<dim> vCornerCoords [],
295 number time
296 );
297
300 (
301 size_t co
302 ) const
303 {return lsf_inside (m_locLSF.value (0, co));}
304
307 (
308 size_t co
309 ) const
310 {return m_locLSF.value (0, co);}
311
313 template <typename TElem>
315 (
316 LocalVector& locU,
317 size_t base_co
318 ) const;
319
322 (
323 size_t num_co,
324 size_t base_co,
325 number * u,
326 size_t fct
327 ) const;
328
331 (
332 size_t num_co,
333 number * u,
334 size_t fct
335 ) const;
336
338 template <typename TElem>
340 (
341 LocalVector& locD,
342 size_t base_co
343 );
344
346 template <typename TElem>
348 (
349 LocalMatrix& locM,
350 size_t base_co
351 );
352
354 template <typename TElem>
356 (
357 LocalMatrix& locM,
358 LocalVector& locB,
359 size_t base_co
360 );
361
363 template <typename TElem>
365 (
366 LocalMatrix& locM,
367 LocalVector& locB
368 );
369
370//---- Resetting data in the outer parts ----//
371public:
372
375 (
376 vector_type & d,
377 const DoFDistribution * dd
378 ) const;
379
382 (
383 vector_type & u,
384 const DoFDistribution * dd,
385 number time
386 );
387
390 (
391 matrix_type & A,
392 const DoFDistribution * dd
393 ) const;
394
395private:
396
398 template <typename TElem>
400 (
401 vector_type & u,
402 size_t fct,
403 const DoFDistribution * dd,
404 number time,
407 );
408
411 {
414 size_t m_fct;
419
421 (
422 this_type * pThis,
423 vector_type & u,
424 size_t fct,
425 const DoFDistribution * dd,
426 number time,
429 ) : m_pThis (pThis), m_u (u), m_fct (fct), m_dd (dd), m_time (time), m_aaBC (aaBC), m_aaNumElem (aaNumElem) {};
430
431 template <typename TElem> void operator () (TElem &)
432 {
433 m_pThis->template sum_up_near_if_outer_values_for_<TElem> (m_u, m_fct, m_dd, m_time, m_aaBC, m_aaNumElem);
434 }
435 };
436
438 void prepare_grid_levels ();
439
440private:
441
448
450 std::vector<GLData> m_vGLData;
451
462
463 std::vector<ICData> m_vICData;
464
466
467// temporaty data (valid for the initialization with a particular element)
468
471
473 int m_si;
477
479
480}; // class LevSetGFExtrapolation
481
483
490template <typename TDomain, typename TAlgebra>
492: public LSGFDomainDiscretization<TDomain, TAlgebra, LevSetGFsimpleExtrapolation<TDomain, TAlgebra> >
493{
496
499
500public:
501
504 : base_type (pApproxSpace)
505 {}
506};
507
508} // namespace LevelSet
509} // end namespace ug
510
512
513#endif // __H__UG__PLUGINS__LEVSET_SIMPLE_EXTRAPOL__
514
515/* End of File */
bool valid() const
Global assembler for the simple extrapolation method.
Definition levset_simple_extrapol.h:493
LSGFsimpleDomainDiscretization(SmartPtr< approx_space_type > pApproxSpace)
default Constructor
Definition levset_simple_extrapol.h:503
ApproximationSpace< TDomain > approx_space_type
Type of approximation space.
Definition levset_simple_extrapol.h:498
LSGFDomainDiscretization< TDomain, TAlgebra, LevSetGFsimpleExtrapolation< TDomain, TAlgebra > > base_type
Type of the base class.
Definition levset_simple_extrapol.h:495
Level-set extrapolation for the ghost-fluid method based on piecewise linear LS functions.
Definition levset_simple_extrapol.h:59
void eliminate_extrapolated(LocalMatrix &locM, size_t base_co)
eliminates the matrix connections to the vertices behind the interface
Definition levset_simple_extrapol_impl.h:317
CPUAlgebra lsf_algebra_type
algebra type for the LSF
Definition levset_simple_extrapol.h:94
void set_outer_values(vector_type &u, const DoFDistribution *dd, number time)
sets the values at the outer vertices to given values
Definition levset_simple_extrapol_impl.h:588
void set_outer_matrices(matrix_type &A, const DoFDistribution *dd) const
sets the matrices at outer vertices to identity
Definition levset_simple_extrapol_impl.h:756
t_fs_bc
types of boundary conditions at the moving boundary
Definition levset_simple_extrapol.h:121
@ NEUMANN_0_BC
Definition levset_simple_extrapol.h:124
@ DIRICHLET_PLAIN_BC
Definition levset_simple_extrapol.h:123
@ DIRICHLET_BC
Definition levset_simple_extrapol.h:122
@ MAX_FS_BC
Definition levset_simple_extrapol.h:125
ApproximationSpace< domain_type > approx_space_type
type of approximation space
Definition levset_simple_extrapol.h:109
MathVector< dim > m_elemCenter
center of the element (only initialized for cut elements)
Definition levset_simple_extrapol.h:474
void set_plain_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_simple_extrapol.h:225
bool corner_excluded(size_t co) const
checks if the corner is excluded
Definition levset_simple_extrapol.h:276
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_simple_extrapol.h:180
void check_dd(ConstSmartPtr< DoFDistribution > dd) const
checks the dof distribution of the solution
Definition levset_simple_extrapol.h:156
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_simple_extrapol_impl.h:197
static const int dim
dimensionality (the World dimension)
Definition levset_simple_extrapol.h:115
void set_LSF(SmartPtr< ls_grid_func_type > spLSF)
set the level-set function and check it
Definition levset_simple_extrapol.h:140
void project_LSF()
projects the values of the LSF to the coarser levels
Definition levset_simple_extrapol_impl.h:524
void clear_outer_values(vector_type &d, const DoFDistribution *dd) const
sets the values at the outer vertices to 0
Definition levset_simple_extrapol_impl.h:537
LocalIndices m_indLSF
indices of the LSF dof's
Definition levset_simple_extrapol.h:469
const MathVector< dim > * m_vCornerCoords
array of coordinates of the corners
Definition levset_simple_extrapol.h:475
domain_type::position_accessor_type position_accessor_type
type of the position attachment accessor
Definition levset_simple_extrapol.h:112
bool corner_inside(size_t co) const
returns true if the corner is "inside" (use after check_elem_lsf)
Definition levset_simple_extrapol.h:300
StdInjection< domain_type, lsf_algebra_type > projection_type
type of the projection of the LSF to the coarser grid levels
Definition levset_simple_extrapol.h:106
LevSetGFsimpleExtrapolation< TDomain, TAlgebra > this_type
Definition levset_simple_extrapol.h:60
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 not, and prepares the data
Definition levset_simple_extrapol_impl.h:56
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_simple_extrapol_impl.h:153
bool m_co_excluded[max_num_corners]
if corners are excluded by subsets (only for cut elements)
Definition levset_simple_extrapol.h:476
number lsf_at(size_t co) const
returns the effective value of the LSF at a corner (use after check_elem_lsf)
Definition levset_simple_extrapol.h:307
std::vector< GLData > m_vGLData
data on the grid levels
Definition levset_simple_extrapol.h:450
algebra_type::vector_type vector_type
vector type (for the functions to extrapolate)
Definition levset_simple_extrapol.h:97
SubsetGroup m_excl_ssg
subsets to exclude
Definition levset_simple_extrapol.h:465
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_simple_extrapol_impl.h:688
algebra_type::matrix_type matrix_type
matrix type
Definition levset_simple_extrapol.h:100
TAlgebra algebra_type
algebra type for the functions to extrapolate
Definition levset_simple_extrapol.h:91
TDomain domain_type
domain type
Definition levset_simple_extrapol.h:85
static bool lsf_inside(number lsf_val)
returns true if the given value should correspond to the 'inside' subdomain
Definition levset_simple_extrapol.h:77
number m_time
the physical time from the current initialization
Definition levset_simple_extrapol.h:478
TDomain::grid_type grid_type
grid type for the domain
Definition levset_simple_extrapol.h:88
LevSetGFsimpleExtrapolation()
class constructor
Definition levset_simple_extrapol.h:134
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_simple_extrapol_impl.h:298
SmartPtr< ls_grid_func_type > m_spLSF
original Level-Set function
Definition levset_simple_extrapol.h:449
number boundary_value(size_t fct) const
gets the BC value
Definition levset_simple_extrapol_impl.h:130
void prepare_grid_levels()
projects the level-set functions to the coarser grid levels
Definition levset_simple_extrapol_impl.h:487
int m_si
subset index of the element
Definition levset_simple_extrapol.h:473
GridObject * m_pElem
the current grid element
Definition levset_simple_extrapol.h:472
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_simple_extrapol.h:195
static constexpr number small_lsf_value
the threshold for the level-set function
Definition levset_simple_extrapol.h:65
std::vector< ICData > m_vICData
the boundary conditions at the interface
Definition levset_simple_extrapol.h:463
LocalVector m_locLSF
corner values of the LFS (if initialized)
Definition levset_simple_extrapol.h:470
void set_plain_Dirichlet_for(SmartPtr< approx_space_type > spApproxSpace, const char *fct_name, number value)
adds a Dirichlet BC with a given value
Definition levset_simple_extrapol.h:210
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_simple_extrapol.h:254
static const size_t max_num_corners
max. number of corners of an grid element
Definition levset_simple_extrapol.h:129
GridFunction< domain_type, lsf_algebra_type > ls_grid_func_type
grid function type for the LSF
Definition levset_simple_extrapol.h:103
void prepare_interface_bc(SmartPtr< approx_space_type > spApproxSpace)
prepares the boundary conditions at the interface: sets all them to Dirichlet-0
Definition levset_simple_extrapol.h:171
void set_Neumann0_for(SmartPtr< approx_space_type > spApproxSpace, const char *fct_name)
adds a Neumann-0
Definition levset_simple_extrapol.h:240
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_simple_extrapol.h:444
SmartPtr< projection_type > inject
the canonical restriction for the grid level
Definition levset_simple_extrapol.h:446
SmartPtr< ls_grid_func_type > lsf_on_gl
level-set function on the level
Definition levset_simple_extrapol.h:445
Class for the specification of the boundary conditions at the interface (for one component/function)
Definition levset_simple_extrapol.h:454
t_fs_bc bc_kind
type of the interface conditions on the free surface
Definition levset_simple_extrapol.h:455
SmartPtr< CplUserData< number, dim > > func
variable value (for the BC)
Definition levset_simple_extrapol.h:456
number value
value (for the Dirichlet BC, if func is NULL)
Definition levset_simple_extrapol.h:457
ICData()
Default constructor.
Definition levset_simple_extrapol.h:460
helper class for the loop over all the element types
Definition levset_simple_extrapol.h:411
size_t m_fct
Definition levset_simple_extrapol.h:414
vector_type & m_u
Definition levset_simple_extrapol.h:413
void operator()(TElem &)
Definition levset_simple_extrapol.h:431
Grid::VertexAttachmentAccessor< AUInt > & m_aaNumElem
Definition levset_simple_extrapol.h:418
number m_time
Definition levset_simple_extrapol.h:416
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_simple_extrapol.h:421
this_type * m_pThis
Definition levset_simple_extrapol.h:412
const DoFDistribution * m_dd
Definition levset_simple_extrapol.h:415
Grid::VertexAttachmentAccessor< ANumber > & m_aaBC
Definition levset_simple_extrapol.h:417