Line data Source code
1 : /*
2 : * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
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 : #include "convection_diffusion_base.h"
34 : #include "lib_disc/spatial_disc/user_data/const_user_data.h"
35 : #include "lib_disc/spatial_disc/user_data/data_export.h"
36 : #ifdef UG_FOR_LUA
37 : #include "bindings/lua/lua_user_data.h"
38 : #endif
39 :
40 : namespace ug{
41 : namespace ConvectionDiffusionPlugin{
42 :
43 : ////////////////////////////////////////////////////////////////////////////////
44 : // user data
45 : ////////////////////////////////////////////////////////////////////////////////
46 :
47 : //////// Diffusion
48 :
49 : template<typename TDomain>
50 0 : void ConvectionDiffusionBase<TDomain>::
51 : set_diffusion(SmartPtr<CplUserData<MathMatrix<dim, dim>, dim> > user)
52 : {
53 0 : m_imDiffusion.set_data(user);
54 0 : }
55 :
56 : template<typename TDomain>
57 0 : void ConvectionDiffusionBase<TDomain>::set_diffusion(number val)
58 : {
59 0 : if(val == 0.0) set_diffusion(SmartPtr<CplUserData<MathMatrix<dim, dim>, dim> >());
60 0 : else set_diffusion(make_sp(new ConstUserMatrix<dim>(val)));
61 0 : }
62 :
63 : #ifdef UG_FOR_LUA
64 : template<typename TDomain>
65 0 : void ConvectionDiffusionBase<TDomain>::set_diffusion(const char* fctName)
66 : {
67 0 : set_diffusion(LuaUserDataFactory<MathMatrix<dim,dim>, dim>::create(fctName));
68 0 : }
69 : template<typename TDomain>
70 0 : void ConvectionDiffusionBase<TDomain>::set_diffusion(LuaFunctionHandle fct)
71 : {
72 0 : set_diffusion(make_sp(new LuaUserData<MathMatrix<dim,dim>, dim>(fct)));
73 0 : }
74 : #endif
75 :
76 : //////// Velocity
77 :
78 : template<typename TDomain>
79 0 : void ConvectionDiffusionBase<TDomain>::
80 : set_velocity(SmartPtr<CplUserData<MathVector<dim>, dim> > user)
81 : {
82 0 : m_imVelocity.set_data(user);
83 0 : }
84 :
85 : template<typename TDomain>
86 0 : void ConvectionDiffusionBase<TDomain>::set_velocity(const std::vector<number>& vVel)
87 : {
88 : bool bZero = true;
89 0 : for(size_t i = 0; i < vVel.size(); ++i){
90 0 : if(vVel[i] != 0.0) bZero = false;
91 : }
92 :
93 0 : if(bZero) set_velocity(SmartPtr<CplUserData<MathVector<dim>, dim> >());
94 0 : else set_velocity(SmartPtr<ConstUserVector<dim> >(new ConstUserVector<dim>(vVel)));
95 0 : }
96 :
97 : #ifdef UG_FOR_LUA
98 : template<typename TDomain>
99 0 : void ConvectionDiffusionBase<TDomain>::
100 : set_velocity(const char* fctName)
101 : {
102 0 : set_velocity(LuaUserDataFactory<MathVector<dim>,dim>::create(fctName));
103 0 : }
104 : template<typename TDomain>
105 0 : void ConvectionDiffusionBase<TDomain>::
106 : set_velocity(LuaFunctionHandle fct)
107 : {
108 0 : set_velocity(make_sp(new LuaUserData<MathVector<dim>,dim>(fct)));
109 0 : }
110 : #endif
111 :
112 : //////// Flux
113 :
114 : template<typename TDomain>
115 0 : void ConvectionDiffusionBase<TDomain>::
116 : set_flux(SmartPtr<CplUserData<MathVector<dim>, dim> > user)
117 : {
118 0 : m_imFlux.set_data(user);
119 0 : }
120 :
121 : template<typename TDomain>
122 0 : void ConvectionDiffusionBase<TDomain>::set_flux(const std::vector<number>& vVel)
123 : {
124 : bool bZero = true;
125 0 : for(size_t i = 0; i < vVel.size(); ++i){
126 0 : if(vVel[i] != 0.0) bZero = false;
127 : }
128 :
129 0 : if(bZero) set_flux(SmartPtr<CplUserData<MathVector<dim>, dim> >());
130 0 : else set_flux(SmartPtr<ConstUserVector<dim> >(new ConstUserVector<dim>(vVel)));
131 0 : }
132 :
133 : #ifdef UG_FOR_LUA
134 : template<typename TDomain>
135 0 : void ConvectionDiffusionBase<TDomain>::
136 : set_flux(const char* fctName)
137 : {
138 0 : set_flux(LuaUserDataFactory<MathVector<dim>,dim>::create(fctName));
139 0 : }
140 : template<typename TDomain>
141 0 : void ConvectionDiffusionBase<TDomain>::
142 : set_flux(LuaFunctionHandle fct)
143 : {
144 0 : set_flux(make_sp(new LuaUserData<MathVector<dim>,dim>(fct)));
145 0 : }
146 : #endif
147 :
148 : //////// Reaction Rate
149 :
150 : template<typename TDomain>
151 0 : void ConvectionDiffusionBase<TDomain>::
152 : set_reaction_rate(SmartPtr<CplUserData<number, dim> > user)
153 : {
154 0 : m_imReactionRate.set_data(user);
155 0 : }
156 :
157 : template<typename TDomain>
158 0 : void ConvectionDiffusionBase<TDomain>::
159 : set_reaction_rate(number val)
160 : {
161 0 : if(val == 0.0) set_reaction_rate(SmartPtr<CplUserData<number, dim> >());
162 0 : else set_reaction_rate(make_sp(new ConstUserNumber<dim>(val)));
163 0 : }
164 :
165 : #ifdef UG_FOR_LUA
166 : template<typename TDomain>
167 0 : void ConvectionDiffusionBase<TDomain>::
168 : set_reaction_rate(const char* fctName)
169 : {
170 0 : set_reaction_rate(LuaUserDataFactory<number,dim>::create(fctName));
171 0 : }
172 : template<typename TDomain>
173 0 : void ConvectionDiffusionBase<TDomain>::
174 : set_reaction_rate(LuaFunctionHandle fct)
175 : {
176 0 : set_reaction_rate(make_sp(new LuaUserData<number,dim>(fct)));
177 0 : }
178 : #endif
179 :
180 : //////// Reaction Rate Explicit
181 :
182 : template<typename TDomain>
183 0 : void ConvectionDiffusionBase<TDomain>::
184 : set_reaction_rate_explicit(SmartPtr<CplUserData<number, dim> > user)
185 : {
186 0 : m_imReactionRateExpl.set_data(user);
187 0 : }
188 :
189 : template<typename TDomain>
190 0 : void ConvectionDiffusionBase<TDomain>::
191 : set_reaction_rate_explicit(number val)
192 : {
193 0 : if(val == 0.0) set_reaction_rate_explicit(SmartPtr<CplUserData<number, dim> >());
194 0 : else set_reaction_rate_explicit(make_sp(new ConstUserNumber<dim>(val)));
195 0 : }
196 :
197 : #ifdef UG_FOR_LUA
198 : template<typename TDomain>
199 0 : void ConvectionDiffusionBase<TDomain>::
200 : set_reaction_rate_explicit(const char* fctName)
201 : {
202 0 : set_reaction_rate_explicit(LuaUserDataFactory<number,dim>::create(fctName));
203 0 : }
204 : #endif
205 :
206 : //////// Reaction
207 :
208 : template<typename TDomain>
209 0 : void ConvectionDiffusionBase<TDomain>::
210 : set_reaction(SmartPtr<CplUserData<number, dim> > user)
211 : {
212 0 : m_imReaction.set_data(user);
213 0 : }
214 :
215 : template<typename TDomain>
216 0 : void ConvectionDiffusionBase<TDomain>::
217 : set_reaction(number val)
218 : {
219 0 : if(val == 0.0) set_reaction(SmartPtr<CplUserData<number, dim> >());
220 0 : else set_reaction(make_sp(new ConstUserNumber<dim>(val)));
221 0 : }
222 :
223 : #ifdef UG_FOR_LUA
224 : template<typename TDomain>
225 0 : void ConvectionDiffusionBase<TDomain>::
226 : set_reaction(const char* fctName)
227 : {
228 0 : set_reaction(LuaUserDataFactory<number,dim>::create(fctName));
229 0 : }
230 : template<typename TDomain>
231 0 : void ConvectionDiffusionBase<TDomain>::
232 : set_reaction(LuaFunctionHandle fct)
233 : {
234 0 : set_reaction(make_sp(new LuaUserData<number,dim>(fct)));
235 0 : }
236 : #endif
237 :
238 : //////// Reaction Explicit
239 :
240 : template<typename TDomain>
241 0 : void ConvectionDiffusionBase<TDomain>::
242 : set_reaction_explicit(SmartPtr<CplUserData<number, dim> > user)
243 : {
244 0 : m_imReactionExpl.set_data(user);
245 0 : }
246 :
247 : template<typename TDomain>
248 0 : void ConvectionDiffusionBase<TDomain>::
249 : set_reaction_explicit(number val)
250 : {
251 0 : if(val == 0.0) set_reaction_explicit(SmartPtr<CplUserData<number, dim> >());
252 0 : else set_reaction_explicit(make_sp(new ConstUserNumber<dim>(val)));
253 0 : }
254 :
255 : #ifdef UG_FOR_LUA
256 : template<typename TDomain>
257 0 : void ConvectionDiffusionBase<TDomain>::
258 : set_reaction_explicit(const char* fctName)
259 : {
260 0 : set_reaction_explicit(LuaUserDataFactory<number,dim>::create(fctName));
261 0 : }
262 : #endif
263 :
264 :
265 : //////// Source
266 :
267 : template<typename TDomain>
268 0 : void ConvectionDiffusionBase<TDomain>::
269 : set_source(SmartPtr<CplUserData<number, dim> > user)
270 : {
271 0 : m_imSource.set_data(user);
272 0 : }
273 :
274 : template<typename TDomain>
275 0 : void ConvectionDiffusionBase<TDomain>::
276 : set_source(number val)
277 : {
278 0 : if(val == 0.0) set_source(SmartPtr<CplUserData<number, dim> >());
279 0 : else set_source(make_sp(new ConstUserNumber<dim>(val)));
280 0 : }
281 :
282 : #ifdef UG_FOR_LUA
283 : template<typename TDomain>
284 0 : void ConvectionDiffusionBase<TDomain>::
285 : set_source(const char* fctName)
286 : {
287 0 : set_source(LuaUserDataFactory<number,dim>::create(fctName));
288 0 : }
289 :
290 : template<typename TDomain>
291 0 : void ConvectionDiffusionBase<TDomain>::
292 : set_source(LuaFunctionHandle fct)
293 : {
294 0 : set_source(make_sp(new LuaUserData<number,dim>(fct)));
295 0 : }
296 : #endif
297 :
298 : //////// Source explicit
299 :
300 : template<typename TDomain>
301 0 : void ConvectionDiffusionBase<TDomain>::
302 : set_source_explicit(SmartPtr<CplUserData<number, dim> > user)
303 : {
304 0 : m_imSourceExpl.set_data(user);
305 0 : }
306 :
307 : template<typename TDomain>
308 0 : void ConvectionDiffusionBase<TDomain>::
309 : set_source_explicit(number val)
310 : {
311 0 : if(val == 0.0) set_source_explicit(SmartPtr<CplUserData<number, dim> >());
312 0 : else set_source_explicit(make_sp(new ConstUserNumber<dim>(val)));
313 0 : }
314 :
315 : #ifdef UG_FOR_LUA
316 : template<typename TDomain>
317 0 : void ConvectionDiffusionBase<TDomain>::
318 : set_source_explicit(const char* fctName)
319 : {
320 0 : set_source_explicit(LuaUserDataFactory<number,dim>::create(fctName));
321 0 : }
322 : #endif
323 :
324 :
325 : //////// Vector Source
326 :
327 : template<typename TDomain>
328 0 : void ConvectionDiffusionBase<TDomain>::
329 : set_vector_source(SmartPtr<CplUserData<MathVector<dim>, dim> > user)
330 : {
331 0 : m_imVectorSource.set_data(user);
332 0 : }
333 :
334 : template<typename TDomain>
335 0 : void ConvectionDiffusionBase<TDomain>::set_vector_source(const std::vector<number>& vVel)
336 : {
337 : bool bZero = true;
338 0 : for(size_t i = 0; i < vVel.size(); ++i){
339 0 : if(vVel[i] != 0.0) bZero = false;
340 : }
341 :
342 0 : if(bZero) set_vector_source(SmartPtr<CplUserData<MathVector<dim>, dim> >());
343 0 : else set_vector_source(SmartPtr<ConstUserVector<dim> >(new ConstUserVector<dim>(vVel)));
344 0 : }
345 :
346 : #ifdef UG_FOR_LUA
347 : template<typename TDomain>
348 0 : void ConvectionDiffusionBase<TDomain>::set_vector_source(const char* fctName)
349 : {
350 0 : set_vector_source(LuaUserDataFactory<MathVector<dim>,dim>::create(fctName));
351 0 : }
352 : template<typename TDomain>
353 0 : void ConvectionDiffusionBase<TDomain>::
354 : set_vector_source(LuaFunctionHandle fct)
355 : {
356 0 : set_vector_source(make_sp(new LuaUserData<MathVector<dim>,dim>(fct)));
357 0 : }
358 : #endif
359 :
360 : //////// Mass Scale
361 :
362 : template<typename TDomain>
363 0 : void ConvectionDiffusionBase<TDomain>::
364 : set_mass_scale(SmartPtr<CplUserData<number, dim> > user)
365 : {
366 0 : m_imMassScale.set_data(user);
367 0 : }
368 :
369 : template<typename TDomain>
370 0 : void ConvectionDiffusionBase<TDomain>::
371 : set_mass_scale(number val)
372 : {
373 0 : if(val == 0.0) set_mass_scale(SmartPtr<CplUserData<number, dim> >());
374 0 : else set_mass_scale(make_sp(new ConstUserNumber<dim>(val)));
375 0 : }
376 :
377 : #ifdef UG_FOR_LUA
378 : template<typename TDomain>
379 0 : void ConvectionDiffusionBase<TDomain>::
380 : set_mass_scale(const char* fctName)
381 : {
382 0 : set_mass_scale(LuaUserDataFactory<number,dim>::create(fctName));
383 0 : }
384 : template<typename TDomain>
385 0 : void ConvectionDiffusionBase<TDomain>::
386 : set_mass_scale(LuaFunctionHandle fct)
387 : {
388 0 : set_mass_scale(make_sp(new LuaUserData<number,dim>(fct)));
389 0 : }
390 : #endif
391 :
392 : //////// Mass
393 :
394 : template<typename TDomain>
395 0 : void ConvectionDiffusionBase<TDomain>::
396 : set_mass(SmartPtr<CplUserData<number, dim> > user)
397 : {
398 0 : m_imMass.set_data(user);
399 0 : }
400 :
401 : template<typename TDomain>
402 0 : void ConvectionDiffusionBase<TDomain>::
403 : set_mass(number val)
404 : {
405 0 : if(val == 0.0) set_mass(SmartPtr<CplUserData<number, dim> >());
406 0 : else set_mass(make_sp(new ConstUserNumber<dim>(val)));
407 0 : }
408 :
409 : #ifdef UG_FOR_LUA
410 : template<typename TDomain>
411 0 : void ConvectionDiffusionBase<TDomain>::
412 : set_mass(const char* fctName)
413 : {
414 0 : set_mass(LuaUserDataFactory<number,dim>::create(fctName));
415 0 : }
416 : template<typename TDomain>
417 0 : void ConvectionDiffusionBase<TDomain>::
418 : set_mass(LuaFunctionHandle fct)
419 : {
420 0 : set_mass(make_sp(new LuaUserData<number,dim>(fct)));
421 0 : }
422 : #endif
423 :
424 : ////////////////////////////////////////////////////////////////////////////////
425 : // Exports
426 : ////////////////////////////////////////////////////////////////////////////////
427 :
428 : template <typename TDomain>
429 : typename ConvectionDiffusionBase<TDomain>::NumberExport
430 0 : ConvectionDiffusionBase<TDomain>::
431 0 : value() {return m_exValue;}
432 :
433 :
434 : template <typename TDomain>
435 : typename ConvectionDiffusionBase<TDomain>::GradExport
436 0 : ConvectionDiffusionBase<TDomain>::
437 0 : gradient() {return m_exGrad;}
438 :
439 : ////////////////////////////////////////////////////////////////////////////////
440 : // Constructor
441 : ////////////////////////////////////////////////////////////////////////////////
442 :
443 : template<typename TDomain>
444 0 : void ConvectionDiffusionBase<TDomain>::
445 : init_imports()
446 : {
447 : // register imports
448 0 : this->register_import(m_imDiffusion);
449 0 : this->register_import(m_imVelocity);
450 0 : this->register_import(m_imFlux);
451 0 : this->register_import(m_imReactionRate);
452 0 : this->register_import(m_imReaction);
453 0 : this->register_import(m_imReactionRateExpl);
454 0 : this->register_import(m_imReactionExpl);
455 0 : this->register_import(m_imSourceExpl);
456 0 : this->register_import(m_imSource);
457 0 : this->register_import(m_imVectorSource);
458 0 : this->register_import(m_imMassScale);
459 0 : this->register_import(m_imMass);
460 :
461 : m_imMassScale.set_mass_part();
462 : m_imMass.set_mass_part();
463 : m_imSource.set_rhs_part();
464 : m_imVectorSource.set_rhs_part();
465 : m_imSourceExpl.set_expl_part();
466 : m_imReactionExpl.set_expl_part();
467 : m_imReactionRateExpl.set_expl_part();
468 0 : }
469 :
470 : template<typename TDomain>
471 0 : ConvectionDiffusionBase<TDomain>::
472 : ConvectionDiffusionBase(const char* functions, const char* subsets)
473 : : IElemDisc<TDomain>(functions,subsets),
474 0 : m_exValue(new DataExport<number, dim>(functions)),
475 0 : m_exGrad(new DataExport<MathVector<dim>, dim>(functions))
476 : {
477 : // check number of functions
478 0 : if(this->num_fct() != 1)
479 0 : UG_THROW("Wrong number of functions: The ElemDisc 'ConvectionDiffusion'"
480 : " needs exactly "<<1<<" symbolic function.");
481 : // init all imports
482 0 : init_imports();
483 :
484 : // default value for mass scale
485 0 : set_mass_scale(1.0);
486 0 : }
487 :
488 : ////////////////////////////////////////////////////////////////////////////////
489 : // explicit template instantiations
490 : ////////////////////////////////////////////////////////////////////////////////
491 :
492 : #ifdef UG_DIM_1
493 : template class ConvectionDiffusionBase<Domain1d>;
494 : #endif
495 : #ifdef UG_DIM_2
496 : template class ConvectionDiffusionBase<Domain2d>;
497 : #endif
498 : #ifdef UG_DIM_3
499 : template class ConvectionDiffusionBase<Domain3d>;
500 : #endif
501 :
502 : } // end namespace ConvectionDiffusionPlugin
503 : } // namespace ug
|