-
Notifications
You must be signed in to change notification settings - Fork 1
/
convection_diffusion_plugin.cpp
413 lines (359 loc) · 19 KB
/
convection_diffusion_plugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*
* Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
* Author: Andreas Vogel
*
* This file is part of UG4.
*
* UG4 is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License version 3 (as published by the
* Free Software Foundation) with the following additional attribution
* requirements (according to LGPL/GPL v3 §7):
*
* (1) The following notice must be displayed in the Appropriate Legal Notices
* of covered and combined works: "Based on UG4 (www.ug4.org/license)".
*
* (2) The following notice must be displayed at a prominent place in the
* terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
*
* (3) The following bibliography is recommended for citation and must be
* preserved in all covered files:
* "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
* parallel geometric multigrid solver on hierarchically distributed grids.
* Computing and visualization in science 16, 4 (2013), 151-164"
* "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
* flexible software system for simulating pde based models on high performance
* computers. Computing and visualization in science 16, 4 (2013), 165-179"
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
/**
* File for registration of ConvectionDiffusion routines.
*/
#include "bridge/util.h"
#include "bridge/util_domain_dependent.h"
#include "convection_diffusion_base.h"
#include "convection_diffusion_sss.h"
#include "fv1/convection_diffusion_fv1.h"
#include "fe/convection_diffusion_fe.h"
#include "fe/convection_diffusion_stab_fe.h"
#include "fvcr/convection_diffusion_fvcr.h"
#include "fv/convection_diffusion_fv.h"
#include "fractfv1/convection_diffusion_fractfv1.h"
#include "convection_diffusion_plugin.h"
using namespace std;
using namespace ug::bridge;
namespace ug{
namespace ConvectionDiffusionPlugin{
/**
* \defgroup convection_diffusion Convection Diffusion
* \ingroup plugins
* This plugin provides the discretization of convection and diffusion problems.
* \{
*/
/**
* Class exporting the functionality of the plugin. All functionality that is to
* be used in scripts or visualization must be registered here.
*/
struct Functionality
{
/**
* Function called for the registration of Domain dependent parts
* of the plugin. All Functions and Classes depending on the Domain
* are to be placed here when registering. The method is called for all
* available Domain types, based on the current build options.
*
* @param reg registry
* @param parentGroup group for sorting of functionality
*/
template <typename TDomain, typename TRegistry=ug::bridge::Registry>
static void Domain(TRegistry& reg, string grp)
{
static const int dim = TDomain::dim;
string suffix = GetDomainSuffix<TDomain>();
string tag = GetDomainTag<TDomain>();
// Convection Diffusion Base
{
typedef ConvectionDiffusionBase<TDomain> T;
typedef IElemDisc<TDomain> TBase;
string name = string("ConvectionDiffusionBase").append(suffix);
reg.template add_class_<T, TBase >(name, grp)
.add_method("set_diffusion", static_cast<void (T::*)(SmartPtr<CplUserData<MathMatrix<dim, dim>, dim> >)>(&T::set_diffusion), "", "Diffusion")
.add_method("set_diffusion", static_cast<void (T::*)(number)>(&T::set_diffusion), "", "Diagonal Diffusion")
#ifdef UG_FOR_LUA
.add_method("set_diffusion", static_cast<void (T::*)(const char*)>(&T::set_diffusion), "", "Diffusion")
.add_method("set_diffusion", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_diffusion), "", "Diffusion")
#endif
.add_method("set_velocity", static_cast<void (T::*)(SmartPtr<CplUserData<MathVector<dim>, dim> >)>(&T::set_velocity), "", "Velocity Field")
.add_method("set_velocity", static_cast<void (T::*)(const std::vector<number>&)>(&T::set_velocity), "", "Velocity Field")
#ifdef UG_FOR_LUA
.add_method("set_velocity", static_cast<void (T::*)(const char*)>(&T::set_velocity), "", "Velocity Field")
.add_method("set_velocity", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_velocity), "", "Velocity Field")
#endif
.add_method("set_flux", static_cast<void (T::*)(SmartPtr<CplUserData<MathVector<dim>, dim> >)>(&T::set_flux), "", "Flux")
.add_method("set_flux", static_cast<void (T::*)(const std::vector<number>&)>(&T::set_flux), "", "Flux")
#ifdef UG_FOR_LUA
.add_method("set_flux", static_cast<void (T::*)(const char*)>(&T::set_flux), "", "Flux")
.add_method("set_flux", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_flux), "", "Flux")
#endif
.add_method("set_reaction_rate", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_reaction_rate), "", "Reaction Rate")
.add_method("set_reaction_rate", static_cast<void (T::*)(number)>(&T::set_reaction_rate), "", "Reaction Rate")
#ifdef UG_FOR_LUA
.add_method("set_reaction_rate", static_cast<void (T::*)(const char*)>(&T::set_reaction_rate), "", "Reaction Rate")
.add_method("set_reaction_rate", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_reaction_rate), "", "Reaction Rate")
#endif
.add_method("set_reaction", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_reaction), "", "Reaction")
.add_method("set_reaction", static_cast<void (T::*)(number)>(&T::set_reaction), "", "Reaction")
#ifdef UG_FOR_LUA
.add_method("set_reaction", static_cast<void (T::*)(const char*)>(&T::set_reaction), "", "Reaction")
.add_method("set_reaction", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_reaction), "", "Reaction")
#endif
.add_method("set_reaction_rate_explicit", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_reaction_rate_explicit), "", "Reaction Rate Explicit")
.add_method("set_reaction_rate_explicit", static_cast<void (T::*)(number)>(&T::set_reaction_rate_explicit), "", "Reaction Rate Explicit")
#ifdef UG_FOR_LUA
.add_method("set_reaction_rate_explicit", static_cast<void (T::*)(const char*)>(&T::set_reaction_rate_explicit), "", "Reaction Rate Explicit")
#endif
.add_method("set_reaction_explicit", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_reaction_explicit), "", "Reaction Explicit")
.add_method("set_reaction_explicit", static_cast<void (T::*)(number)>(&T::set_reaction_explicit), "", "Reaction Explicit")
#ifdef UG_FOR_LUA
.add_method("set_reaction_explicit", static_cast<void (T::*)(const char*)>(&T::set_reaction_explicit), "", "Reaction Explicit")
#endif
.add_method("set_source_explicit", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_source_explicit), "", "Source Explicit")
.add_method("set_source_explicit", static_cast<void (T::*)(number)>(&T::set_source_explicit), "", "Source Explicit")
#ifdef UG_FOR_LUA
.add_method("set_source_explicit", static_cast<void (T::*)(const char*)>(&T::set_source_explicit), "", "Source Explicit")
#endif
.add_method("set_source", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_source), "", "Source")
.add_method("set_source", static_cast<void (T::*)(number)>(&T::set_source), "", "Source")
#ifdef UG_FOR_LUA
.add_method("set_source", static_cast<void (T::*)(const char*)>(&T::set_source), "", "Source")
.add_method("set_source", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_source), "", "Source")
#endif
.add_method("set_vector_source", static_cast<void (T::*)(SmartPtr<CplUserData<MathVector<dim>, dim> >)>(&T::set_vector_source), "", "Vector Source")
#ifdef UG_FOR_LUA
.add_method("set_vector_source", static_cast<void (T::*)(const char*)>(&T::set_vector_source), "", "Vector Source")
.add_method("set_vector_source", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_vector_source), "", "Vector Source")
#endif
.add_method("set_mass_scale", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_mass_scale), "", "Mass Scale")
.add_method("set_mass_scale", static_cast<void (T::*)(number)>(&T::set_mass_scale), "", "Mass Scale")
#ifdef UG_FOR_LUA
.add_method("set_mass_scale", static_cast<void (T::*)(const char*)>(&T::set_mass_scale), "", "Mass Scale")
.add_method("set_mass_scale", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_mass_scale), "", "Mass Scale")
#endif
.add_method("set_mass", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_mass), "", "Mass")
.add_method("set_mass", static_cast<void (T::*)(number)>(&T::set_mass), "", "Mass")
#ifdef UG_FOR_LUA
.add_method("set_mass", static_cast<void (T::*)(const char*)>(&T::set_mass), "", "Mass")
.add_method("set_mass", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_mass), "", "Mass")
#endif
.add_method("value", &T::value)
.add_method("gradient", &T::gradient);
/*
.add_method("set_partial_velocity", &T::set_partial_velocity)
.add_method("set_partial_flux", &T::set_partial_flux)
.add_method("set_partial_mass", &T::set_partial_mass);
*/
reg.add_class_to_group(name, "ConvectionDiffusionBase", tag);
}
// Convection Diffusion FV1
{
typedef ConvectionDiffusionFV1<TDomain> T;
typedef ConvectionDiffusionBase<TDomain> TBase;
string name = string("ConvectionDiffusionFV1").append(suffix);
reg.template add_class_<T, TBase >(name, grp)
.template add_constructor<void (*)(const char*,const char*)>("Function(s)#Subset(s)")
.add_method("set_condensed_FV", &T::set_condensed_FV, "", "[De-]Activates the condensed FV scvf ip's")
.add_method("set_upwind", &T::set_upwind, "", "Sets the upwind type for the convective terms")
.add_method("set_singular_sources_and_sinks", &T::set_sss_manager, "", "Sets the singular sources and sinks manager")
.add_method("singular_sources_and_sinks", &T::sss_manager, "", "Returns the singular sources and sinks manager")
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "ConvectionDiffusionFV1", tag);
}
// Convection Diffusion FE
{
typedef ConvectionDiffusionFE<TDomain> T;
typedef ConvectionDiffusionBase<TDomain> TBase;
string name = string("ConvectionDiffusionFE").append(suffix);
reg.template add_class_<T, TBase >(name, grp)
.template add_constructor<void (*)(const char*,const char*)>("Function(s)#Subset(s)")
.add_method("set_quad_order", &T::set_quad_order)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "ConvectionDiffusionFE", tag);
}
// Convection Diffusion (FE) stabilization
{
typedef ConvectionDiffusionStabFE<TDomain> T;
typedef IElemDisc<TDomain> TBase;
string name = string("ConvectionDiffusionStabFE").append(suffix);
reg.template add_class_<T, TBase >(name, grp)
.template add_constructor<void (*)(const char*,const char*)>("Function(s)#Subset(s)")
.template add_constructor<void (*)(const char*,const char*,number)>("Function(s)#Subset(s)#stabilization")
.template add_constructor<void (*)(const char*,const char*,number,number)>("Function(s)#Subset(s)#stabilization")
.add_method("set_quad_order", &T::set_quad_order)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "ConvectionDiffusionStabFE", tag);
}
// Convection Diffusion FVCR
{
typedef ConvectionDiffusionFVCR<TDomain> T;
typedef ConvectionDiffusionBase<TDomain> TBase;
string name = string("ConvectionDiffusionFVCR").append(suffix);
reg.template add_class_<T, TBase >(name, grp)
.template add_constructor<void (*)(const char*,const char*)>("Function(s)#Subset(s)")
.add_method("set_upwind", &T::set_upwind)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "ConvectionDiffusionFVCR", tag);
}
// Convection Diffusion FV
{
typedef ConvectionDiffusionFV<TDomain> T;
typedef ConvectionDiffusionBase<TDomain> TBase;
string name = string("ConvectionDiffusionFV").append(suffix);
reg.template add_class_<T, TBase >(name, grp)
.template add_constructor<void (*)(const char*,const char*)>("Function(s)#Subset(s)")
.add_method("set_quad_order", &T::set_quad_order)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "ConvectionDiffusionFV", tag);
}
}
template <int dim, typename TRegistry=ug::bridge::Registry>
static void Dimension(TRegistry& reg, string grp)
{
string dimSuffix = GetDimensionSuffix<dim>();
string dimTag = GetDimensionTag<dim>();
// singular sources and sinks
{
typedef CDSingularSourcesAndSinks<dim> T;
typedef typename T::point_sss_type TPointSSS;
typedef typename T::line_sss_type TLineSSS;
string point_name = string("CDPointSourcesSink").append(dimSuffix);
reg.template add_class_<TPointSSS>(point_name, grp)
.template add_constructor<void (*) (const std::vector<number>&)> ()
.add_method ("set", static_cast<void (TPointSSS::*) (number)> (&TPointSSS::set))
.add_method ("set", static_cast<void (TPointSSS::*) (typename TPointSSS::user_data_type)> (&TPointSSS::set))
#ifdef UG_FOR_LUA
.add_method ("set", static_cast<void (TPointSSS::*) (LuaFunctionHandle)> (&TPointSSS::set))
#endif
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(point_name, "CDPointSourcesSink", dimTag);
string line_name = string("CDLineSourcesSink").append(dimSuffix);
reg.template add_class_<TLineSSS>(line_name, grp)
.template add_constructor<void (*) (const std::vector<number>&, const std::vector<number>&)> ()
.add_method ("set", static_cast<void (TLineSSS::*) (number)> (&TLineSSS::set))
#ifdef UG_FOR_LUA
.add_method ("set", static_cast<void (TLineSSS::*) (LuaFunctionHandle)> (&TLineSSS::set))
#endif
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(line_name, "CDLineSourcesSink", dimTag);
string name = string("CDSingularSourcesAndSinks").append(dimSuffix);
reg.template add_class_<T>(name, grp)
.add_constructor()
.add_method ("add_point", static_cast<void (T::*) (SmartPtr<TPointSSS>)> (&T::add_point))
.add_method ("add_line", static_cast<void (T::*) (SmartPtr<TLineSSS>)> (&T::add_line))
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "CDSingularSourcesAndSinks", dimTag);
}
}
}; // end Functionality
/**
* Class exporting the functionality of the plugin restricted to 2 and 3 spatial
* dimensions. All functionality that is to be used in scripts or visualization
* only in 2d and 3d must be registered here.
*/
struct Functionality2d3d
{
/**
* Function called for the registration of Domain dependent parts
* of the plugin. All Functions and Classes depending on the Domain
* are to be placed here when registering. The method is called for all
* available Domain types, based on the current build options.
*
* @param reg registry
* @param parentGroup group for sorting of functionality
*/
template <typename TDomain, typename TRegistry=ug::bridge::Registry>
static void Domain(TRegistry& reg, string grp)
{
static const int dim = TDomain::dim;
string suffix = GetDomainSuffix<TDomain>();
string tag = GetDomainTag<TDomain>();
// Convection Diffusion FV1 for the low-dimensional fractures
{
typedef ConvectionDiffusionFractFV1<TDomain> T;
typedef ConvectionDiffusionBase<TDomain> TBase;
string name = string("ConvectionDiffusionFractFV1").append(suffix);
reg.template add_class_<T, TBase >(name, grp)
.template add_constructor<void (*)(const char*,const char*)>("Function(s)#Subset(s)")
.add_method("set_fract_manager", static_cast<void (T::*)(SmartPtr<DegeneratedLayerManager<dim> >)>(&T::set_fract_manager), "Sets the fracture manager", "Deg. fracture manager")
.add_method("set_upwind", &T::set_upwind)
.add_method("set_aperture", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_aperture), "", "Fract. aperture")
.add_method("set_aperture", static_cast<void (T::*)(number)>(&T::set_aperture), "", "Fract. aperture")
#ifdef UG_FOR_LUA
.add_method("set_aperture", static_cast<void (T::*)(const char*)>(&T::set_aperture), "", "Fract. aperture")
.add_method("set_aperture", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_aperture), "", "Fract. aperture")
#endif
.add_method("set_ortho_velocity", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_ortho_velocity), "", "Orthogonal Velocity Field")
.add_method("set_ortho_velocity", static_cast<void (T::*)(number)>(&T::set_ortho_velocity), "", "Orthogonal Velocity Field")
#ifdef UG_FOR_LUA
.add_method("set_ortho_velocity", static_cast<void (T::*)(const char*)>(&T::set_ortho_velocity), "", "Orthogonal Velocity Field")
.add_method("set_ortho_velocity", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_ortho_velocity), "", "Orthogonal Velocity Field")
#endif
.add_method("set_ortho_diffusion", static_cast<void (T::*)(SmartPtr<CplUserData<number, dim> >)>(&T::set_ortho_diffusion), "", "Orthogonal Diffusion")
.add_method("set_ortho_diffusion", static_cast<void (T::*)(number)>(&T::set_ortho_diffusion), "", "Orthogonal Diffusion")
#ifdef UG_FOR_LUA
.add_method("set_ortho_diffusion", static_cast<void (T::*)(const char*)>(&T::set_ortho_diffusion), "", "Orthogonal Diffusion")
.add_method("set_ortho_diffusion", static_cast<void (T::*)(LuaFunctionHandle)>(&T::set_ortho_diffusion), "", "Orthogonal Diffusion")
#endif
.add_method("set_singular_sources_and_sinks", &T::set_sss_manager, "", "Sets the singular sources and sinks manager")
.add_method("singular_sources_and_sinks", &T::sss_manager, "", "Returns the singular sources and sinks manager")
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "ConvectionDiffusionFractFV1", tag);
}
}
}; // end Functionality2d3d
// end group convection_diffusion
/// \}
} // end namespace ConvectionDiffusionPlugin
#ifndef UG_USE_PYBIND11
//! This function is called when the plugin is loaded.
extern "C"
void InitUGPlugin_ConvectionDiffusion(ug::bridge::Registry* reg, string grp)
{
grp.append("/SpatialDisc/ElemDisc");
typedef ConvectionDiffusionPlugin::Functionality Functionality;
typedef ConvectionDiffusionPlugin::Functionality2d3d Functionality2d3d;
try{
RegisterDimensionDependent<Functionality>(*reg,grp);
RegisterDomainDependent<Functionality>(*reg,grp);
RegisterDomain2d3dDependent<Functionality2d3d>(*reg,grp);
}
UG_REGISTRY_CATCH_THROW(grp);
}
#else // UG_USE_PYBIND11
template <typename TRegistry=ug::bridge::Registry>
void InitUGPlugin_ConvectionDiffusion_(TRegistry* reg, string grp)
{
grp.append("/SpatialDisc/ElemDisc");
typedef ConvectionDiffusionPlugin::Functionality Functionality;
typedef ConvectionDiffusionPlugin::Functionality2d3d Functionality2d3d;
try{
RegisterDimensionDependent<Functionality>(*reg,grp);
RegisterDomainDependent<Functionality, TRegistry>(*reg,grp);
RegisterDomain2d3dDependent<Functionality2d3d, TRegistry>(*reg,grp);
}
UG_REGISTRY_CATCH_THROW(grp);
}
//! This function is called when the plugin is loaded.
extern "C" void
InitUGPlugin_ConvectionDiffusion(ug::bridge::Registry* reg, string grp)
{ InitUGPlugin_ConvectionDiffusion_(reg, grp); }
#ifdef UG_USE_PYBIND11
namespace ConvectionDiffusionPlugin{
void Init(ug::pybind::Registry* reg, string grp)
{ InitUGPlugin_ConvectionDiffusion_<ug::pybind::Registry>(reg, grp); }
}
#endif
#endif // UG_USE_PYBIND11
}// namespace ug