-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrichards_plugin.cpp
More file actions
427 lines (348 loc) · 12.3 KB
/
Copy pathrichards_plugin.cpp
File metadata and controls
427 lines (348 loc) · 12.3 KB
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
// SPDX-FileCopyrightText: 2025 Goethe Universitaet Frankfurt
// SPDX-License-Identifier: EUPL-1.2
// SPDX-FileContributor: Arne Naegel
// SPDX-FileType: SOURCE
#if __cplusplus >= 201703L
#define _HAS_AUTO_PTR_ETC 0 // activate for boost, if c++17 and beyond
#endif
#include <string>
#include "bridge/util.h"
// replace this with util_domain_dependent.h or util_algebra_dependent.h
// to speed up compilation time
#include "bridge/util_domain_algebra_dependent.h"
#include "common/ug_config.h"
#include "common/error.h"
#include "van_genuchten.h"
#include "richards_linker.h"
#include "richards_elem_disc.h"
#ifdef UG_PARALLEL
#include "pcl/pcl_util.h"
#endif
using namespace std;
using namespace ug::bridge;
namespace ug{
namespace Richards{
/**
* \defgroup sample_plugin Sample
* \ingroup plugins
* This is a small sample plugin.
* \{
*/
void RichardsSaysHello()
{
#ifdef UG_PARALLEL
pcl::SynchronizeProcesses();
cout << "Hello, I'm your plugin on proc " <<
pcl::ProcRank() << "." << endl;
pcl::SynchronizeProcesses();
#else
UG_LOG("Hello, I'm your personal plugin in serial environment!\n");
#endif
}
void CrashFct(const string& reason)
{
UG_THROW("I crash because: "<< reason);
}
void CrashFctFatal(const string& reason)
{
UG_THROW("I crash fatal because: "<< reason);
}
void RichardsCrashes()
{
try{
CrashFct("Some funny reason");
}
catch(bad_alloc& err)
{
UG_LOG("Bad Alloc");
}
UG_CATCH_THROW("Something wrong in PluginCrashes");
}
void RichardsCrashesFatal()
{
try{
CrashFctFatal("Some fatal reason");
}
catch(bad_alloc& err)
{
UG_LOG("Bad Alloc");
}
UG_CATCH_THROW("Something wrong in PluginCrashesFatal");
}
/**
* 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 and Algebra dependent parts
* of the plugin. All Functions and Classes depending on both Domain and Algebra
* are to be placed here when registering. The method is called for all
* available Domain and Algebra types, based on the current build options.
*
* @param reg registry
* @param parentGroup group for sorting of functionality
*/
template <typename TDomain, typename TAlgebra>
static void DomainAlgebra(Registry& reg, string grp)
{
// useful defines
string suffix = GetDomainAlgebraSuffix<TDomain,TAlgebra>();
string tag = GetDomainAlgebraTag<TDomain,TAlgebra>();
}
/**
* 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>
static void Domain(Registry& reg, string grp)
{
// useful defines
string suffix = GetDomainSuffix<TDomain>();
string tag = GetDomainTag<TDomain>();
{
string name = string("RichardsElemDisc").append(suffix);
typedef RichardsElemDisc<TDomain> T;
typedef typename RichardsElemDisc<TDomain>::base_type TBase;
reg.add_class_<T,TBase>(name, grp)
.template add_constructor<void (*)(char*, char*) >("")
.add_method("set_storage_data", &T::set_storage_data)
.add_method("get_storage_data", &T::get_storage_data)
.add_method("set_flux_data", &T::set_flux_data)
.add_method("get_flux_data", &T::get_flux_data)
.add_method("set_conductivity_data", &T::set_conductivity_data)
.add_method("get_conductivity_data", &T::get_conductivity_data)
// . add_method("set_conductivity", &T::set_conductivity)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "RichardsElemDisc", tag);
}
{
string name = string("RichardsElemDiscFactory").append(suffix);
typedef RichardsElemDiscFactory<TDomain> T;
reg.add_class_<T>(name, grp)
.template add_constructor<void (*)() >("")
.add_method("create_richards", &T::create_richards)
.add_method("set_saturation", &T::set_saturation)
.add_method("set_conductivity", &T::set_conductivity)
.add_method("set_abs_conductivity", &T::set_abs_conductivity)
.add_method("set_function", &T::set_function)
.add_method("set_gravity", &T::set_function)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "RichardsElemDiscFactory", tag);
}
{
string name = string("SelectVTKData").append(suffix);
reg.add_function(name, &SelectVTKData<TDomain>, grp);
}
}
/**
* Function called for the registration of Dimension dependent parts
* of the plugin. All Functions and Classes depending on the Dimension
* are to be placed here when registering. The method is called for all
* available Dimension types, based on the current build options.
*
* @param reg registry
* @param parentGroup group for sorting of functionality
*/
template <typename T, int dim>
static void add_user_data(const char* idstring, Registry& reg, const string grp, const string suffix, const string tag)
{
string name = string(idstring).append(suffix);
//typedef RichardsSaturation<dim> T;
typedef typename T::user_data_base_type TUserData;
typedef typename T::base_type::TModel TModel;
typedef IRichardsLinker<dim> TCap;
reg.add_class_<T,TUserData,TCap>(name, grp)
.template add_constructor<void (*)(const TModel&) >("")
.add_method("set_capillary", &T::set_capillary)
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, idstring, tag);
}
template <int dim>
static void Dimension(Registry& reg, string grp)
{
// useful defines
string suffix = GetDimensionSuffix<dim>();
string tag = GetDimensionTag<dim>();
{
// This is an abstract base class for pressure dependent quantities, e.g. saturations.
string name = string("IRichardsLinker").append(suffix);
typedef IRichardsLinker<dim> T;
reg.add_class_<T>(name, grp);
reg.add_class_to_group(name, "IRichardsLinker", tag);
}
// user data
{
// van Genuchten
typedef RichardsSaturation<dim> S;
add_user_data<S, dim>("RichardsSaturation", reg, grp, suffix, tag);
typedef RichardsConductivity<dim> C;
add_user_data<C, dim>("RichardsConductivity", reg, grp, suffix, tag);
}
{
// Haverkamp
typedef HaverkampSaturation<dim> S;
add_user_data<S, dim>("HaverkampSaturation", reg, grp, suffix, tag);
typedef HaverkampConductivity<dim> C;
add_user_data<C, dim>("HaverkampConductivity", reg, grp, suffix, tag);
}
{
// Exponential
typedef ExponentialSaturation<dim> S;
add_user_data<S, dim>("ExponentialSaturation", reg, grp, suffix, tag);
typedef ExponentialConductivity<dim> C;
add_user_data<C, dim>("ExponentialConductivity", reg, grp, suffix, tag);
}
{
string name = string("RichardsUserDataFactory").append(suffix);
typedef typename Richards::UserDataFactory<dim> T;
reg.add_class_<T>(name, grp)
.template add_constructor<void (*)(typename T::input_type) >("")
// Exponential
.add_method("create_saturation", static_cast<typename T::return_type (T::*)(const ExponentialModel &)>(&T::create_saturation) )
.add_method("create_conductivity", static_cast<typename T::return_type (T::*)(const ExponentialModel &)>(&T::create_conductivity) )
// van Genuchten-Mualem
.add_method("create_saturation", static_cast<typename T::return_type (T::*)(const VanGenuchtenModel &)>(&T::create_saturation) )
.add_method("create_conductivity", static_cast<typename T::return_type (T::*)(const VanGenuchtenModel &)>(&T::create_conductivity) )
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "RichardsUserDataFactory", tag);
}
{
string name = string("OnSurfaceCondition").append(suffix);
typedef OnSurfaceCondition<dim> T;
typedef typename T::user_data_base_type TUserData;
reg.add_class_<T,TUserData>(name, grp)
.template add_constructor<void (*)(SmartPtr<typename T::TVectorData>) >("")
.set_construct_as_smart_pointer(true);
reg.add_class_to_group(name, "OnSurfaceCondition", tag);
}
}
/**
* Function called for the registration of Algebra dependent parts
* of the plugin. All Functions and Classes depending on Algebra
* are to be placed here when registering. The method is called for all
* available Algebra types, based on the current build options.
*
* @param reg registry
* @param parentGroup group for sorting of functionality
*/
template <typename TAlgebra>
static void Algebra(Registry& reg, string grp)
{
// useful defines
string suffix = GetAlgebraSuffix<TAlgebra>();
string tag = GetAlgebraTag<TAlgebra>();
}
/**
* Function called for the registration of Domain and Algebra independent parts
* of the plugin. All Functions and Classes not depending on Domain and Algebra
* are to be placed here when registering.
*
* @param reg registry
* @param parentGroup group for sorting of functionality
*/
static void Common(Registry& reg, string grp)
{
/* reg.add_function("RichardsSaysHello", &RichardsSaysHello, grp)
.add_function("RichardsCrashes", &RichardsCrashes, grp)
.add_function("RichardsCrashesFatal", &RichardsCrashesFatal, grp)
.add_function("CreateVanGenuchtenModel", &CreateVanGenuchtenModel, grp);
*/
{
typedef ExponentialModel T;
string name = string("ExponentialModel");
// Parameters (JSON constructible)
typedef typename T::parameter_type P;
reg.add_class_<P>(std::string("ExponentialModelParameters"), grp)
.add_constructor<void (*)() >("json-string containing the parameters", "", "", "");
#ifdef UG_JSON
reg.add_function("JSONSerializer_ExponentialModelParameters", &JSONSerializer<P>, grp);
#endif
// Model
reg.add_class_<T>(name, grp)
.add_constructor<void (*)(const P&) >("parameters", "", "", "")
.add_method("config_string", &T::config_string)
.add_method("saturation", &T::Saturation)
.add_method("saturation_deriv", &T::dSaturation_dH)
.add_method("permeability", &T::Saturation)
.add_method("permeability_deriv", &T::dSaturation_dH)
.add_method("conductivity", &T::Conductivity)
.add_method("conductivity_deriv", &T::dConductivity_dH);
}
{
typedef VanGenuchtenModel T;
string name = string("VanGenuchtenModel");
// Parameters (JSON constructible)
typedef typename T::parameter_type P;
reg.add_class_<P>(std::string("VanGenuchtenModelParameters"), grp)
.add_constructor<void (*)() >("json-string containing the parameters", "", "", "");
#ifdef UG_JSON
reg.add_function("JSONSerializer_VanGenuchtenModelParameters", &JSONSerializer<P>, grp);
#endif
// Model
reg.add_class_<T>(name, grp)
.add_constructor<void (*)(const P&) >("parameters", "", "", "")
.add_method("config_string", &T::config_string)
.add_method("saturation", &T::Saturation)
.add_method("saturation_deriv", &T::dSaturation_dH)
.add_method("conductivity", &T::Conductivity)
.add_method("conductivity_deriv", &T::dConductivity_dH);
}
{
string name = string("HaverkampModel");
typedef HaverkampModel T;
reg.add_class_<T>(name, grp)
#ifdef UG_JSON
.add_constructor<void (*)(const char*) >("json-string containing the parameters", "", "", "")
#endif
.add_method("config_string", &T::config_string)
.add_method("saturation", &T::Saturation)
.add_method("saturation_deriv", &T::dSaturation_dH)
.add_method("conductivity", &T::Conductivity)
.add_method("conductivity_deriv", &T::dConductivity_dH);
}
#ifdef UG_JSON
{
string name = string("RichardsModelFactory");
typedef RichardsModelFactory T;
reg.add_class_<T>(name, grp)
.template add_constructor<void (*)() >("")
.add_method("create_exponential", &T::create_exponential)
.add_method("create_van_genuchten", &T::create_van_genuchten)
.add_method("create_haverkamp", &T::create_haverkamp)
.set_construct_as_smart_pointer(true);
}
#endif
}
}; // end Functionality
// end group sample_plugin
/// \}
}// end of namespace Richards
/**
* This function is called when the plugin is loaded.
*/
extern "C" void
InitUGPlugin_Richards(Registry* reg, string grp)
{
grp.append("/Richards");
typedef Richards::Functionality Functionality;
try{
RegisterCommon<Functionality>(*reg,grp);
RegisterDimensionDependent<Functionality>(*reg,grp);
RegisterDomainDependent<Functionality>(*reg,grp);
RegisterAlgebraDependent<Functionality>(*reg,grp);
RegisterDomainAlgebraDependent<Functionality>(*reg,grp);
}
UG_REGISTRY_CATCH_THROW(grp);
}
extern "C" UG_API void
FinalizeUGPlugin_Richards()
{
}
}// end of namespace ug