forked from libMesh/libmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsed_function.h
780 lines (650 loc) · 23.9 KB
/
parsed_function.h
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
// The libMesh Finite Element Library.
// Copyright (C) 2002-2020 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library 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.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef LIBMESH_PARSED_FUNCTION_H
#define LIBMESH_PARSED_FUNCTION_H
#include "libmesh/libmesh_config.h"
#include "libmesh/function_base.h"
#include "libmesh/auto_ptr.h" // libmesh_make_unique
#ifdef LIBMESH_HAVE_FPARSER
// Local includes
#include "libmesh/dense_vector.h"
#include "libmesh/int_range.h"
#include "libmesh/vector_value.h"
#include "libmesh/point.h"
// FParser includes
#include "libmesh/fparser_ad.hh"
// C++ includes
#include <algorithm> // std::find
#include <cmath>
#include <cmath>
#include <cstddef>
#include <iomanip>
#include <limits>
#include <sstream>
#include <string>
#include <vector>
namespace libMesh
{
/**
* A Function generated (via FParser) by parsing a mathematical
* expression. All overridden virtual functions are documented in
* function_base.h.
*
* \author Roy Stogner
* \date 2012
* \brief A Function defined by a std::string.
*/
template <typename Output=Number, typename OutputGradient=Gradient>
class ParsedFunction : public FunctionBase<Output>
{
public:
explicit
ParsedFunction (const std::string & expression,
const std::vector<std::string> * additional_vars=nullptr,
const std::vector<Output> * initial_vals=nullptr);
/**
* Constructors
* - This class contains unique_ptrs so it can't be default copy
* constructed or assigned, only default moved and deleted.
*/
ParsedFunction (const ParsedFunction &);
ParsedFunction & operator= (const ParsedFunction &);
ParsedFunction (ParsedFunction &&) = default;
ParsedFunction & operator= (ParsedFunction &&) = default;
virtual ~ParsedFunction () = default;
/**
* Re-parse with new expression.
*/
void reparse (const std::string & expression);
virtual Output operator() (const Point & p,
const Real time = 0) override;
/**
* Query if the automatic derivative generation was successful.
*/
virtual bool has_derivatives() { return _valid_derivatives; }
virtual Output dot(const Point & p,
const Real time = 0);
virtual OutputGradient gradient(const Point & p,
const Real time = 0);
virtual void operator() (const Point & p,
const Real time,
DenseVector<Output> & output) override;
virtual Output component (unsigned int i,
const Point & p,
Real time) override;
const std::string & expression() { return _expression; }
/**
* \returns The address of a parsed variable so you can supply a parameterized value.
*/
virtual Output & getVarAddress(const std::string & variable_name);
virtual std::unique_ptr<FunctionBase<Output>> clone() const override;
/**
* \returns The value of an inline variable.
*
* \note Will *only* be correct if the inline variable value is
* independent of input variables, if the inline variable is not
* redefined within any subexpression, and if the inline variable
* takes the same value within any subexpressions where it appears.
*/
Output get_inline_value(const std::string & inline_var_name) const;
/**
* Changes the value of an inline variable.
*
* \note Forever after, the variable value will take the given
* constant, independent of input variables, in every subexpression
* where it is already defined.
*
* \note Currently only works if the inline variable is not
* redefined within any one subexpression.
*/
void set_inline_value(const std::string & inline_var_name,
Output newval);
protected:
/**
* Re-parse with minor changes to expression.
*/
void partial_reparse (const std::string & expression);
/**
* Helper function for parsing out variable names.
*/
std::size_t find_name (const std::string & varname,
const std::string & expr) const;
/**
* \returns \p true if the expression is time-dependent, false otherwise.
*/
bool expression_is_time_dependent( const std::string & expression ) const;
private:
/**
* Set the _spacetime argument vector.
*/
void set_spacetime(const Point & p,
const Real time = 0);
/**
* Evaluate the ith FunctionParser and check the result.
*/
inline Output eval(FunctionParserADBase<Output> & parser,
const std::string & libmesh_dbg_var(function_name),
unsigned int libmesh_dbg_var(component_idx)) const;
std::string _expression;
std::vector<std::string> _subexpressions;
std::vector<std::unique_ptr<FunctionParserADBase<Output>>> parsers;
std::vector<Output> _spacetime;
// derivative functions
std::vector<std::unique_ptr<FunctionParserADBase<Output>>> dx_parsers;
#if LIBMESH_DIM > 1
std::vector<std::unique_ptr<FunctionParserADBase<Output>>> dy_parsers;
#endif
#if LIBMESH_DIM > 2
std::vector<std::unique_ptr<FunctionParserADBase<Output>>> dz_parsers;
#endif
std::vector<std::unique_ptr<FunctionParserADBase<Output>>> dt_parsers;
bool _valid_derivatives;
// Variables/values that can be parsed and handled by the function parser
std::string variables;
std::vector<std::string> _additional_vars;
std::vector<Output> _initial_vals;
};
/*----------------------- Inline functions ----------------------------------*/
template <typename Output, typename OutputGradient>
inline
ParsedFunction<Output,OutputGradient>::ParsedFunction (const std::string & expression,
const std::vector<std::string> * additional_vars,
const std::vector<Output> * initial_vals) :
_expression (), // overridden by parse()
// Size the spacetime vector to account for space, time, and any additional
// variables passed
_spacetime (LIBMESH_DIM+1 + (additional_vars ? additional_vars->size() : 0)),
_valid_derivatives (true),
_additional_vars (additional_vars ? *additional_vars : std::vector<std::string>()),
_initial_vals (initial_vals ? *initial_vals : std::vector<Output>())
{
// time-dependence established in reparse function
this->reparse(expression);
this->_initialized = true;
}
template <typename Output, typename OutputGradient>
inline
ParsedFunction<Output,OutputGradient>::ParsedFunction (const ParsedFunction<Output,OutputGradient> & other) :
FunctionBase<Output>(other),
_expression(other._expression),
_subexpressions(other._subexpressions),
_spacetime(other._spacetime),
_valid_derivatives(other._valid_derivatives),
variables(other.variables),
_additional_vars(other._additional_vars),
_initial_vals(other._initial_vals)
{
// parsers can be generated from scratch by reparsing expression
this->reparse(this->_expression);
this->_initialized = true;
}
template <typename Output, typename OutputGradient>
inline
ParsedFunction<Output,OutputGradient> &
ParsedFunction<Output,OutputGradient>::operator= (const ParsedFunction<Output,OutputGradient> & other)
{
// Use copy-and-swap idiom
ParsedFunction<Output,OutputGradient> tmp(other);
std::swap(tmp, *this);
return *this;
}
template <typename Output, typename OutputGradient>
inline
void
ParsedFunction<Output,OutputGradient>::reparse (const std::string & expression)
{
variables = "x";
#if LIBMESH_DIM > 1
variables += ",y";
#endif
#if LIBMESH_DIM > 2
variables += ",z";
#endif
variables += ",t";
// If additional vars were passed, append them to the string
// that we send to the function parser. Also add them to the
// end of our spacetime vector
for (auto i : index_range(_additional_vars))
{
variables += "," + _additional_vars[i];
// Initialize extra variables to the vector passed in or zero
// Note: The initial_vals vector can be shorter than the additional_vars vector
_spacetime[LIBMESH_DIM+1 + i] =
(i < _initial_vals.size()) ? _initial_vals[i] : 0;
}
this->partial_reparse(expression);
this->_is_time_dependent = this->expression_is_time_dependent(expression);
}
template <typename Output, typename OutputGradient>
inline
Output
ParsedFunction<Output,OutputGradient>::operator() (const Point & p, const Real time)
{
set_spacetime(p, time);
return eval(*parsers[0], "f", 0);
}
template <typename Output, typename OutputGradient>
inline
Output
ParsedFunction<Output,OutputGradient>::dot (const Point & p, const Real time)
{
set_spacetime(p, time);
return eval(*dt_parsers[0], "df/dt", 0);
}
template <typename Output, typename OutputGradient>
inline
OutputGradient
ParsedFunction<Output,OutputGradient>::gradient (const Point & p, const Real time)
{
OutputGradient grad;
set_spacetime(p, time);
grad(0) = eval(*dx_parsers[0], "df/dx", 0);
#if LIBMESH_DIM > 1
grad(1) = eval(*dy_parsers[0], "df/dy", 0);
#endif
#if LIBMESH_DIM > 2
grad(2) = eval(*dz_parsers[0], "df/dz", 0);
#endif
return grad;
}
template <typename Output, typename OutputGradient>
inline
void
ParsedFunction<Output,OutputGradient>::operator()
(const Point & p,
const Real time,
DenseVector<Output> & output)
{
set_spacetime(p, time);
unsigned int size = output.size();
libmesh_assert_equal_to (size, parsers.size());
// The remaining locations in _spacetime are currently fixed at construction
// but could potentially be made dynamic
for (unsigned int i=0; i != size; ++i)
output(i) = eval(*parsers[i], "f", i);
}
/**
* \returns The vector component \p i at coordinate
* \p p and time \p time.
*/
template <typename Output, typename OutputGradient>
inline
Output
ParsedFunction<Output,OutputGradient>::component (unsigned int i,
const Point & p,
Real time)
{
set_spacetime(p, time);
libmesh_assert_less (i, parsers.size());
// The remaining locations in _spacetime are currently fixed at construction
// but could potentially be made dynamic
libmesh_assert_less(i, parsers.size());
return eval(*parsers[i], "f", i);
}
/**
* \returns The address of a parsed variable so you can supply a parameterized value
*/
template <typename Output, typename OutputGradient>
inline
Output &
ParsedFunction<Output,OutputGradient>::getVarAddress (const std::string & variable_name)
{
const std::vector<std::string>::iterator it =
std::find(_additional_vars.begin(), _additional_vars.end(), variable_name);
libmesh_error_msg_if(it == _additional_vars.end(),
"ERROR: Requested variable not found in parsed function");
// Iterator Arithmetic (How far from the end of the array is our target address?)
return _spacetime[_spacetime.size() - (_additional_vars.end() - it)];
}
template <typename Output, typename OutputGradient>
inline
std::unique_ptr<FunctionBase<Output>>
ParsedFunction<Output,OutputGradient>::clone() const
{
return libmesh_make_unique<ParsedFunction>(_expression,
&_additional_vars,
&_initial_vals);
}
template <typename Output, typename OutputGradient>
inline
Output
ParsedFunction<Output,OutputGradient>::get_inline_value (const std::string & inline_var_name) const
{
libmesh_assert_greater (_subexpressions.size(), 0);
#ifndef NDEBUG
bool found_var_name = false;
#endif
Output old_var_value(0.);
for (const auto & subexpression : _subexpressions)
{
const std::size_t varname_i =
find_name(inline_var_name, subexpression);
if (varname_i == std::string::npos)
continue;
const std::size_t assignment_i =
subexpression.find(":", varname_i+1);
libmesh_assert_not_equal_to(assignment_i, std::string::npos);
libmesh_assert_equal_to(subexpression[assignment_i+1], '=');
for (std::size_t i = varname_i+1; i != assignment_i; ++i)
libmesh_assert_equal_to(subexpression[i], ' ');
std::size_t end_assignment_i =
subexpression.find(";", assignment_i+1);
libmesh_assert_not_equal_to(end_assignment_i, std::string::npos);
std::string new_subexpression =
subexpression.substr(0, end_assignment_i+1) +
inline_var_name;
#ifdef LIBMESH_HAVE_FPARSER
// Parse and evaluate the new subexpression.
// Add the same constants as we used originally.
FunctionParserADBase<Output> fp;
fp.AddConstant("NaN", std::numeric_limits<Real>::quiet_NaN());
fp.AddConstant("pi", std::acos(Real(-1)));
fp.AddConstant("e", std::exp(Real(1)));
libmesh_error_msg_if
(fp.Parse(new_subexpression, variables) != -1, // -1 for success
"ERROR: FunctionParser is unable to parse modified expression: "
<< new_subexpression << '\n' << fp.ErrorMsg());
Output new_var_value = this->eval(fp, new_subexpression, 0);
#ifdef NDEBUG
return new_var_value;
#else
if (found_var_name)
{
libmesh_assert_equal_to(old_var_value, new_var_value);
}
else
{
old_var_value = new_var_value;
found_var_name = true;
}
#endif
#else
libmesh_error_msg("ERROR: This functionality requires fparser!");
#endif
}
libmesh_assert(found_var_name);
return old_var_value;
}
template <typename Output, typename OutputGradient>
inline
void
ParsedFunction<Output,OutputGradient>::set_inline_value (const std::string & inline_var_name,
Output newval)
{
libmesh_assert_greater (_subexpressions.size(), 0);
#ifndef NDEBUG
bool found_var_name = false;
#endif
for (auto & subexpression : _subexpressions)
{
const std::size_t varname_i =
find_name(inline_var_name, subexpression);
if (varname_i == std::string::npos)
continue;
#ifndef NDEBUG
found_var_name = true;
#endif
const std::size_t assignment_i =
subexpression.find(":", varname_i+1);
libmesh_assert_not_equal_to(assignment_i, std::string::npos);
libmesh_assert_equal_to(subexpression[assignment_i+1], '=');
for (std::size_t i = varname_i+1; i != assignment_i; ++i)
libmesh_assert_equal_to(subexpression[i], ' ');
std::size_t end_assignment_i =
subexpression.find(";", assignment_i+1);
libmesh_assert_not_equal_to(end_assignment_i, std::string::npos);
std::ostringstream new_subexpression;
new_subexpression << subexpression.substr(0, assignment_i+2)
<< std::setprecision(std::numeric_limits<Output>::digits10+2)
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
<< '(' << newval.real() << '+'
<< newval.imag() << 'i' << ')'
#else
<< newval
#endif
<< subexpression.substr(end_assignment_i,
std::string::npos);
subexpression = new_subexpression.str();
}
libmesh_assert(found_var_name);
std::string new_expression;
for (const auto & subexpression : _subexpressions)
{
new_expression += '{';
new_expression += subexpression;
new_expression += '}';
}
this->partial_reparse(new_expression);
}
template <typename Output, typename OutputGradient>
inline
void
ParsedFunction<Output,OutputGradient>::partial_reparse (const std::string & expression)
{
_expression = expression;
_subexpressions.clear();
parsers.clear();
size_t nextstart = 0, end = 0;
while (end != std::string::npos)
{
// If we're past the end of the string, we can't make any more
// subparsers
if (nextstart >= expression.size())
break;
// If we're at the start of a brace delimited section, then we
// parse just that section:
if (expression[nextstart] == '{')
{
nextstart++;
end = expression.find('}', nextstart);
}
// otherwise we parse the whole thing
else
end = std::string::npos;
// We either want the whole end of the string (end == npos) or
// a substring in the middle.
_subexpressions.push_back
(expression.substr(nextstart, (end == std::string::npos) ?
std::string::npos : end - nextstart));
// fparser can crash on empty expressions
libmesh_error_msg_if(_subexpressions.back().empty(),
"ERROR: FunctionParser is unable to parse empty expression.\n");
// Parse (and optimize if possible) the subexpression.
// Add some basic constants, to Real precision.
auto fp = libmesh_make_unique<FunctionParserADBase<Output>>();
fp->AddConstant("NaN", std::numeric_limits<Real>::quiet_NaN());
fp->AddConstant("pi", std::acos(Real(-1)));
fp->AddConstant("e", std::exp(Real(1)));
libmesh_error_msg_if
(fp->Parse(_subexpressions.back(), variables) != -1, // -1 for success
"ERROR: FunctionParser is unable to parse expression: "
<< _subexpressions.back() << '\n' << fp->ErrorMsg());
// use of derivatives is optional. suppress error output on the console
// use the has_derivatives() method to check if AutoDiff was successful.
// also enable immediate optimization
fp->SetADFlags(FunctionParserADBase<Output>::ADSilenceErrors |
FunctionParserADBase<Output>::ADAutoOptimize);
// optimize original function
fp->Optimize();
// generate derivatives through automatic differentiation
auto dx_fp = libmesh_make_unique<FunctionParserADBase<Output>>(*fp);
if (dx_fp->AutoDiff("x") != -1) // -1 for success
_valid_derivatives = false;
dx_parsers.push_back(std::move(dx_fp));
#if LIBMESH_DIM > 1
auto dy_fp = libmesh_make_unique<FunctionParserADBase<Output>>(*fp);
if (dy_fp->AutoDiff("y") != -1) // -1 for success
_valid_derivatives = false;
dy_parsers.push_back(std::move(dy_fp));
#endif
#if LIBMESH_DIM > 2
auto dz_fp = libmesh_make_unique<FunctionParserADBase<Output>>(*fp);
if (dz_fp->AutoDiff("z") != -1) // -1 for success
_valid_derivatives = false;
dz_parsers.push_back(std::move(dz_fp));
#endif
auto dt_fp = libmesh_make_unique<FunctionParserADBase<Output>>(*fp);
if (dt_fp->AutoDiff("t") != -1) // -1 for success
_valid_derivatives = false;
dt_parsers.push_back(std::move(dt_fp));
// If at end, use nextstart=maxSize. Else start at next
// character.
nextstart = (end == std::string::npos) ?
std::string::npos : end + 1;
// Store fp for later use
parsers.push_back(std::move(fp));
}
}
template <typename Output, typename OutputGradient>
inline
std::size_t
ParsedFunction<Output,OutputGradient>::find_name (const std::string & varname,
const std::string & expr) const
{
const std::size_t namesize = varname.size();
std::size_t varname_i = expr.find(varname);
while ((varname_i != std::string::npos) &&
(((varname_i > 0) &&
(std::isalnum(expr[varname_i-1]) ||
(expr[varname_i-1] == '_'))) ||
((varname_i+namesize < expr.size()) &&
(std::isalnum(expr[varname_i+namesize]) ||
(expr[varname_i+namesize] == '_')))))
{
varname_i = expr.find(varname, varname_i+1);
}
return varname_i;
}
template <typename Output, typename OutputGradient>
inline
bool
ParsedFunction<Output,OutputGradient>::expression_is_time_dependent( const std::string & expression ) const
{
bool is_time_dependent = false;
// By definition, time is "t" for FunctionBase-based objects, so we just need to
// see if this expression has the variable "t" in it.
if (this->find_name(std::string("t"), expression) != std::string::npos)
is_time_dependent = true;
return is_time_dependent;
}
// Set the _spacetime argument vector
template <typename Output, typename OutputGradient>
inline
void
ParsedFunction<Output,OutputGradient>::set_spacetime (const Point & p,
const Real time)
{
_spacetime[0] = p(0);
#if LIBMESH_DIM > 1
_spacetime[1] = p(1);
#endif
#if LIBMESH_DIM > 2
_spacetime[2] = p(2);
#endif
_spacetime[LIBMESH_DIM] = time;
// The remaining locations in _spacetime are currently fixed at construction
// but could potentially be made dynamic
}
// Evaluate the ith FunctionParser and check the result
template <typename Output, typename OutputGradient>
inline
Output
ParsedFunction<Output,OutputGradient>::eval (FunctionParserADBase<Output> & parser,
const std::string & libmesh_dbg_var(function_name),
unsigned int libmesh_dbg_var(component_idx)) const
{
#ifndef NDEBUG
Output result = parser.Eval(_spacetime.data());
int error_code = parser.EvalError();
if (error_code)
{
libMesh::err << "ERROR: FunctionParser is unable to evaluate component "
<< component_idx
<< " of expression '"
<< function_name
<< "' with arguments:\n";
for (const auto & item : _spacetime)
libMesh::err << '\t' << item << '\n';
libMesh::err << '\n';
// Currently no API to report error messages, we'll do it manually
std::string error_message = "Reason: ";
switch (error_code)
{
case 1:
error_message += "Division by zero";
break;
case 2:
error_message += "Square Root error (negative value)";
break;
case 3:
error_message += "Log error (negative value)";
break;
case 4:
error_message += "Trigonometric error (asin or acos of illegal value)";
break;
case 5:
error_message += "Maximum recursion level reached";
break;
default:
error_message += "Unknown";
break;
}
libmesh_error_msg(error_message);
}
return result;
#else
return parser.Eval(_spacetime.data());
#endif
}
} // namespace libMesh
#else // !LIBMESH_HAVE_FPARSER
namespace libMesh {
template <typename Output=Number>
class ParsedFunction : public FunctionBase<Output>
{
public:
ParsedFunction (const std::string & /* expression */,
const std::vector<std::string> * = nullptr,
const std::vector<Output> * = nullptr) : _dummy(0)
{
libmesh_not_implemented();
}
/**
* When !LIBMESH_HAVE_FPARSER, this class is not implemented, so
* let's make that explicit by deleting the special functions.
*/
ParsedFunction (ParsedFunction &&) = delete;
ParsedFunction (const ParsedFunction &) = delete;
ParsedFunction & operator= (const ParsedFunction &) = delete;
ParsedFunction & operator= (ParsedFunction &&) = delete;
virtual ~ParsedFunction () = default;
virtual Output operator() (const Point &,
const Real /* time */ = 0)
{ return 0.; }
virtual void operator() (const Point &,
const Real /* time */,
DenseVector<Output> & /* output */) {}
virtual void init() {}
virtual void clear() {}
virtual Output & getVarAddress(const std::string & /*variable_name*/) { return _dummy; }
virtual std::unique_ptr<FunctionBase<Output>> clone() const
{
return libmesh_make_unique<ParsedFunction<Output>>("");
}
private:
Output _dummy;
};
} // namespace libMesh
#endif // LIBMESH_HAVE_FPARSER
#endif // LIBMESH_PARSED_FUNCTION_H