OOFEM 3.0
Loading...
Searching...
No Matches
calculatorfunction.C
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#include "calculatorfunction.h"
36#include "parser.h"
37#include "dynamicinputrecord.h"
38#include "classfactory.h"
39#include "error.h"
40
41#include <sstream>
42
43namespace oofem {
45
46CalculatorFunction :: CalculatorFunction(int n, Domain *d) : Function(n, d) { }
47
48void
57
58
59void
60CalculatorFunction :: giveInputRecord(DynamicInputRecord &input)
61{
62 Function :: giveInputRecord(input);
66}
67
68
69void
70CalculatorFunction :: evaluate(FloatArray &answer, const std :: map< std :: string, FunctionArgument > &valDict, GaussPoint *gp, double param)
71{
72 Parser myParser;
73 int err;
74
75 std :: ostringstream buff;
76 for ( const auto &named_arg: valDict ) {
77 const FunctionArgument &arg = named_arg.second;
78 if ( arg.type == FunctionArgument :: FAT_double ) {
79 buff << named_arg.first << "=" << arg.val0 << ";";
80 } else if ( arg.type == FunctionArgument :: FAT_FloatArray ) {
81 for ( int i = 1; i <= arg.val1.giveSize(); ++i ) {
82 buff << named_arg.first << i << "=" << arg.val1.at(i) << ";";
83 }
84 } else if ( arg.type == FunctionArgument :: FAT_int ) {
85 buff << named_arg.first << "=" << arg.val2 << ";";
86 } else if ( arg.type == FunctionArgument :: FAT_IntArray ) {
87 for ( int i = 1; i <= arg.val3.giveSize(); ++i ) {
88 buff << named_arg.first << i << "=" << arg.val3.at(i) << ";";
89 }
90 }
91 }
92 buff << fExpression;
93 answer.resize(1);
94 answer.at(1) = myParser.eval(buff.str().c_str(), err);
95 if ( err ) {
96 OOFEM_ERROR("parser syntax error");
97 }
98}
99
100
101double CalculatorFunction :: evaluateAtTime(double time)
102{
103 Parser myParser;
104 int err;
105 double result;
106
107 std :: ostringstream buff;
108 buff << "t=" << time << ";" << fExpression;
109 result = myParser.eval(buff.str().c_str(), err);
110 if ( err ) {
111 OOFEM_ERROR("parser syntax error");
112 }
113
114 return result;
115}
116
117double CalculatorFunction :: evaluateVelocityAtTime(double time)
118{
119 Parser myParser;
120 int err;
121 double result;
122
123 if ( dfdtExpression.size() == 0 ) {
124 OOFEM_ERROR("derivative not provided");
125 return 0.;
126 }
127
128 std :: ostringstream buff;
129 buff << "t=" << time << ";" << dfdtExpression;
130 result = myParser.eval(buff.str().c_str(), err);
131 if ( err ) {
132 OOFEM_ERROR("parser syntax error");
133 }
134
135 return result;
136}
137
138
139double CalculatorFunction :: evaluateAccelerationAtTime(double time)
140{
141 Parser myParser;
142 int err;
143 double result;
144
145 if ( d2fdt2Expression.size() == 0 ) {
146 OOFEM_ERROR("derivative not provided");
147 return 0.;
148 }
149
150 std :: ostringstream buff;
151 buff << "t=" << time << ";" << d2fdt2Expression;
152 result = myParser.eval(buff.str().c_str(), err);
153 if ( err ) {
154 OOFEM_ERROR("parser syntax error");
155 }
156
157 return result;
158}
159} // end namespace oofem
#define _IFT_CalculatorFunction_d2fdt2
#define _IFT_CalculatorFunction_dfdt
#define _IFT_CalculatorFunction_f
#define REGISTER_Function(class)
std::string d2fdt2Expression
Expression for second time derivative.
std::string dfdtExpression
Expression for first time derivative.
std::string fExpression
Expression for the function value.
void setField(int item, InputFieldType id)
void resize(Index s)
Definition floatarray.C:94
double & at(Index i)
Definition floatarray.h:202
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
FunctionArgumentType type
Determines which of the types the instance points towards.
Definition function.h:72
Function(int n, Domain *d)
Definition function.C:44
int & at(std::size_t i)
Definition intarray.h:104
int giveSize() const
Definition intarray.h:211
double eval(const char *string, int &err)
Definition parser.C:419
#define OOFEM_ERROR(...)
Definition error.h:79
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
#define IR_GIVE_FIELD(__ir, __value, __id)
Definition inputrecord.h:67

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011