Plugins
Loading...
Searching...
No Matches
level_set.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 * Author: Christian Wehner
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#ifndef __H__UG__PLUGINS__LEVEL_SET__LEVEL_SET_H__
34#define __H__UG__PLUGINS__LEVEL_SET__LEVEL_SET_H__
35
36#include <vector>
37
38#include "common/common.h"
47#include <boost/function.hpp>
48#ifdef UG_FOR_LUA
50#endif
51
52namespace ug{
53namespace LevelSet{
54
55template<typename TGridFunction>
57{
59 typedef typename TGridFunction::domain_type domain_type;
60
62 typedef typename TGridFunction::algebra_type algebra_type;
63
65 static const int dim = domain_type::dim;
66
67 // for debug type of scv-size attachment
68 // typedef typename Grid::VertexAttachmentAccessor<Attachment<number> > aaDiv;
69
71 typedef typename domain_type::grid_type grid_type;
72
74 typedef typename domain_type::position_accessor_type position_accessor_type;
75
78
81
83 typedef typename TGridFunction::template dim_traits<dim>::grid_base_object ElemType;
84
86 typedef typename TGridFunction::template traits<Edge>::const_iterator EdgeConstIterator;
87
89 typedef typename TGridFunction::template traits<Vertex>::const_iterator VertexConstIterator;
90
92 typedef typename TGridFunction::template dim_traits<dim>::const_iterator ElemIterator;
93
94 public:
97 m_dt(0.0), m_time(0), m_gamma(1.0), m_delta(0.0),
98 m_divFree(false),
99 m_nrOfSteps(1),
100 m_maxCFL(0),m_print(false),m_timestep_nr(0),m_limiter(false),
107 {
108 set_source(0.0);
109 }
110
113
115 void set_dt(number deltaT){ UG_LOG("Set dt="<<deltaT<<"\n"); m_dt=deltaT; };
116
118 void set_nr_of_steps(size_t n){m_nrOfSteps = n;};
119
120 void set_reinit(size_t n){ m_gamma=0;m_delta=1;m_nrOfSteps=n; };
121 void set_divfree(bool b){m_divFree=b;};
122 void set_gamma(number gamma){m_gamma =gamma;}
123 void set_delta(number delta){m_delta =delta;}
124 void set_time(number t){m_time = t;}
126 void set_info(bool b){m_print=b;};
127 void set_limiter(bool b){m_limiter=b;};
128 void set_timestep_nr(size_t n){m_timestep_nr = n;};
129
131 bool advect_lsf(TGridFunction& uNew,TGridFunction& u);
132
134 bool compute_error(TGridFunction& numsol);
135
137
139 {
141 vel->set_entry(0, vel_x);
142 if (dim>1) vel->set_entry(1, vel_x);
143 if (dim>2) vel->set_entry(2, vel_x);
144 set_velocity(vel);
145 }
146
147 void set_velocity(number vel_x, number vel_y)
148 {
150 vel->set_entry(0, vel_x);
151 vel->set_entry(1, vel_y);
152 if (dim>2){
153 UG_THROW("ConvectionDiffusion: Setting velocity vector of dimension 2"
154 " to a Discretization for world dim " << dim);
155 }
156 set_velocity(vel);
157 }
158
159 void set_velocity(number vel_x, number vel_y, number vel_z)
160 {
162 vel->set_entry(0, vel_x);
163 vel->set_entry(1, vel_y);
164 vel->set_entry(2, vel_z);
165 if (dim<3){
166 UG_THROW("ConvectionDiffusion: Setting velocity vector of dimension 3"
167 " to a Discretization for world dim " << dim);
168 }
169 set_velocity(vel);
170 }
171
172#ifdef UG_FOR_LUA
173 void set_velocity(const char* fctName)
174 {
176 }
177#endif
178
181#ifdef UG_FOR_LUA
182 void set_source(const char* fctName)
183 {
185 }
186#endif
187
190#ifdef UG_FOR_LUA
191 void set_dirichlet_data(const char* fctName)
192 {
194 }
195#endif
196
197 bool runtimetest (TGridFunction& u);
198
199 bool compute_normal(TGridFunction& vx,TGridFunction& vy,TGridFunction& u);
200 bool compute_dnormal(TGridFunction& dnormal,TGridFunction& vx,TGridFunction& vy,TGridFunction& phi,TGridFunction& u);
201 bool compute_ddnormal(TGridFunction& ddnormal,TGridFunction& dnormal,TGridFunction& vx,TGridFunction& vy,TGridFunction& phi,TGridFunction& u);
202
204 bool set_dirichlet_boundary(TGridFunction& uNew,const char* subsets){
205 try{
206 m_dirichlet_sg = uNew.subset_grp_by_name(subsets);
207 }UG_CATCH_THROW("ERROR while parsing Subsets.");
208
209 return true;
210 };
211
212 bool set_outflow_boundary(TGridFunction& uNew,const char* subsets){
213 try{
214 m_neumann_sg = uNew.subset_grp_by_name(subsets);
215 }UG_CATCH_THROW("ERROR while parsing Subsets.");
216
217 return true;
218 }
219
221
222 bool init_ls_subsets(TGridFunction& phi);
223 void create_ls_subsets(TGridFunction& phi);
224 bool update_ls_subsets(TGridFunction& phi);
225
231 void set_elements_active(int signi,int signj){
232 set_elements_active(signi);
233 set_elements_active(signj);
234 }
235 void set_elements_active(int signi,int signj,int signk){
236 set_elements_active(signi,signj);
237 set_elements_active(signk);
238 }
239 void set_elements_inactive(int sign){
243 }
244 void set_elements_inactive(int signi,int signj){
247 }
248 void set_elements_inactive(int signi,int signj,int signk){
249 set_elements_inactive(signi,signj);
251 }
252 void set_nodes_active(int sign){
256 }
257 void set_nodes_active(int signi,int signj){
258 set_nodes_active(signi);
259 set_nodes_active(signj);
260 }
261 void set_nodes_active(int signi,int signj,int signk){
262 set_nodes_active(signi,signj);
263 set_nodes_active(signk);
264 }
265 void set_nodes_inactive(int sign){
266 if (sign==-1) m_inactive_sg.add(m_inside_nodes_si);
267 if (sign==0) m_inactive_sg.add(m_onls_nodes_si);
269 }
270 void set_nodes_inactive(int signi,int signj){
271 set_nodes_inactive(signi);
272 set_nodes_inactive(signj);
273 }
274 void set_nodes_inactive(int signi,int signj,int signk){
275 set_nodes_inactive(signi,signj);
276 set_nodes_inactive(signk);
277 }
278 bool overwrite(TGridFunction&,TGridFunction&,TGridFunction&,int);
279 bool overwrite(TGridFunction&,number,TGridFunction&,int);
280
281 protected:
282
284 bool calculate_vertex_vol(TGridFunction& u, aaVol& aaVolVolume);
285
286 bool calculate_vertex_grad_vol(TGridFunction& u, aaGrad& aaGradient, aaVol& aaVolume );
287
288 bool calculate_vertex_grad_vol_sign(TGridFunction&, aaGrad& ,aaVol& ,TGridFunction& ,int);
289
290 template <typename TElem>
291 bool assemble_element(TElem& elem, DimFV1Geometry<dim>& geo, grid_type& grid,TGridFunction& uNew,const TGridFunction& uOld,aaGrad& aaGradient, aaVol& aaVolume );
292
293 bool assign_dirichlet(TGridFunction&);
294 bool limit_grad(TGridFunction& uOld, aaGrad& aaGradient);
295
296 private:
306 size_t m_limiter;
316
323};
324
325} // end namespace LevelSet
326} // end namespace ug
327
328// include implementation
329#include "level_set_impl.h"
330
331#endif /* __H__UG__PLUGINS__LEVEL_SET__LEVEL_SET_H__ */
Definition level_set.h:57
void create_ls_subsets(TGridFunction &phi)
Definition level_set_impl.h:1580
void set_limiter(bool b)
Definition level_set.h:127
void set_nodes_inactive(int sign)
Definition level_set.h:265
TGridFunction::algebra_type algebra_type
algebra type
Definition level_set.h:62
bool calculate_vertex_vol(TGridFunction &u, aaVol &aaVolVolume)
fills the scvVolume attachment for all element types
Definition level_set_impl.h:860
int m_inside_nodes_si
Definition level_set.h:313
bool compute_ddnormal(TGridFunction &ddnormal, TGridFunction &dnormal, TGridFunction &vx, TGridFunction &vy, TGridFunction &phi, TGridFunction &u)
Definition level_set_impl.h:1294
bool set_outflow_boundary(TGridFunction &uNew, const char *subsets)
Definition level_set.h:212
void set_delta(number delta)
Definition level_set.h:123
number m_dt
Definition level_set.h:297
void set_nr_of_steps(size_t n)
set nr of time steps to perform in advect_lsf (default is 1)
Definition level_set.h:118
void set_dirichlet_data(SmartPtr< CplUserData< number, dim > > d)
Definition level_set.h:188
void set_divfree(bool b)
Definition level_set.h:121
bool update_ls_subsets(TGridFunction &phi)
Definition level_set_impl.h:1423
void set_timestep_nr(size_t n)
Definition level_set.h:128
SmartPtr< CplUserData< number, dim > > m_imSource
Data import for the right-hand side.
Definition level_set.h:320
int m_onls_nodes_si
Definition level_set.h:315
void set_info(bool b)
Definition level_set.h:126
bool compute_error(TGridFunction &numsol)
computes error w.r.t. the analytical solution (taken from the dirichlet bc)
Definition level_set_impl.h:917
TGridFunction::template traits< Vertex >::const_iterator VertexConstIterator
vertex base iterator
Definition level_set.h:89
TGridFunction::template dim_traits< dim >::grid_base_object ElemType
type of base grid object
Definition level_set.h:83
bool assemble_element(TElem &elem, DimFV1Geometry< dim > &geo, grid_type &grid, TGridFunction &uNew, const TGridFunction &uOld, aaGrad &aaGradient, aaVol &aaVolume)
Definition level_set_impl.h:276
number get_time()
Definition level_set.h:125
domain_type::grid_type grid_type
grid type
Definition level_set.h:71
void set_elements_inactive(int sign)
Definition level_set.h:239
void set_dt(number deltaT)
set time step
Definition level_set.h:115
bool compute_normal(TGridFunction &vx, TGridFunction &vy, TGridFunction &u)
Definition level_set_impl.h:1168
void set_reinit(size_t n)
Definition level_set.h:120
bool m_divFree
Definition level_set.h:301
void set_source(SmartPtr< CplUserData< number, dim > > user)
Definition level_set.h:179
number m_maxCFL
Definition level_set.h:303
void set_elements_active(int signi, int signj)
Definition level_set.h:231
Grid::VertexAttachmentAccessor< Attachment< number > > aaVol
type of volume-size attachment
Definition level_set.h:77
bool limit_grad(TGridFunction &uOld, aaGrad &aaGradient)
Definition level_set_impl.h:53
~FV1LevelSetDisc()
Destructor.
Definition level_set.h:112
size_t m_nrOfSteps
Definition level_set.h:302
void set_elements_inactive(int signi, int signj)
Definition level_set.h:244
bool runtimetest(TGridFunction &u)
Definition level_set_impl.h:1597
void set_velocity(SmartPtr< CplUserData< MathVector< dim >, dim > > user)
Definition level_set.h:136
number m_gamma
Definition level_set.h:299
number m_delta
Definition level_set.h:300
domain_type::position_accessor_type position_accessor_type
type of the position accessor
Definition level_set.h:74
TGridFunction::template dim_traits< dim >::const_iterator ElemIterator
grid element iterator
Definition level_set.h:92
int m_onls_elements_si
Definition level_set.h:312
void set_time(number t)
Definition level_set.h:124
int m_inside_elements_si
Definition level_set.h:310
size_t m_timestep_nr
Definition level_set.h:305
void set_dirichlet_data(number val)
Definition level_set.h:189
SmartPtr< CplUserData< number, dim > > m_imDirichlet
Data import for the Dirichlet values.
Definition level_set.h:322
SubsetGroup m_dirichlet_sg
Definition level_set.h:308
void set_elements_active(int signi, int signj, int signk)
Definition level_set.h:235
int m_outside_elements_si
Definition level_set.h:311
void set_elements_active(int sign)
Definition level_set.h:226
void set_nodes_inactive(int signi, int signj)
Definition level_set.h:270
bool assign_dirichlet(TGridFunction &)
Definition level_set_impl.h:640
void set_gamma(number gamma)
Definition level_set.h:122
void set_velocity(number vel_x)
Definition level_set.h:138
number m_time
Definition level_set.h:298
void set_source(number val)
Definition level_set.h:180
void set_nodes_active(int sign)
Definition level_set.h:252
bool compute_dnormal(TGridFunction &dnormal, TGridFunction &vx, TGridFunction &vy, TGridFunction &phi, TGridFunction &u)
Definition level_set_impl.h:1233
size_t m_limiter
Definition level_set.h:306
void set_velocity(number vel_x, number vel_y, number vel_z)
Definition level_set.h:159
Grid::VertexAttachmentAccessor< Attachment< MathVector< dim > > > aaGrad
type of gradient attachment
Definition level_set.h:80
bool calculate_vertex_grad_vol_sign(TGridFunction &, aaGrad &, aaVol &, TGridFunction &, int)
Definition level_set_impl.h:997
TGridFunction::domain_type domain_type
domain type
Definition level_set.h:59
void set_elements_inactive(int signi, int signj, int signk)
Definition level_set.h:248
void set_nodes_active(int signi, int signj, int signk)
Definition level_set.h:261
SmartPtr< CplUserData< MathVector< dim >, dim > > m_imVelocity
Data import for the Velocity field.
Definition level_set.h:318
void set_nodes_active(int signi, int signj)
Definition level_set.h:257
int m_outside_nodes_si
Definition level_set.h:314
FV1LevelSetDisc()
Constructor.
Definition level_set.h:96
bool overwrite(TGridFunction &, TGridFunction &, TGridFunction &, int)
Definition level_set_impl.h:1360
TGridFunction::template traits< Edge >::const_iterator EdgeConstIterator
edge iterator
Definition level_set.h:86
bool set_dirichlet_boundary(TGridFunction &uNew, const char *subsets)
boundary condition subset handling
Definition level_set.h:204
bool init_ls_subsets(TGridFunction &phi)
subset handling methods:
Definition level_set_impl.h:1572
bool calculate_vertex_grad_vol(TGridFunction &u, aaGrad &aaGradient, aaVol &aaVolume)
Definition level_set_impl.h:485
void set_nodes_inactive(int signi, int signj, int signk)
Definition level_set.h:274
bool advect_lsf(TGridFunction &uNew, TGridFunction &u)
computes the time steps of the discretization of the level-set equation
Definition level_set_impl.h:696
bool m_print
Definition level_set.h:304
void set_velocity(number vel_x, number vel_y)
Definition level_set.h:147
SubsetGroup m_inactive_sg
Definition level_set.h:309
static const int dim
world dimension
Definition level_set.h:65
SubsetGroup m_neumann_sg
Definition level_set.h:307
bool contains(const char *name) const
void remove(const char *name)
void add(const char *name)
SmartPtr< TGrid > grid()
#define UG_CATCH_THROW(msg)
#define UG_THROW(msg)
#define UG_LOG(msg)
double number
SmartPtr< T, FreePolicy > make_sp(T *inst)