OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 - 2013 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 
43 namespace oofem {
44 REGISTER_Function(CalculatorFunction);
45 
47 
50 {
51  IRResultType result;
52 
56 
57  return Function :: initializeFrom(ir);
58 }
59 
60 
61 void
63 {
68 }
69 
70 
71 void
72 CalculatorFunction :: evaluate(FloatArray &answer, const std :: map< std :: string, FunctionArgument > &valDict)
73 {
74  Parser myParser;
75  int err;
76 
77  std :: ostringstream buff;
78  for ( const auto &named_arg: valDict ) {
79  const FunctionArgument &arg = named_arg.second;
80  if ( arg.type == FunctionArgument :: FAT_double ) {
81  buff << named_arg.first << "=" << arg.val0 << ";";
82  } else if ( arg.type == FunctionArgument :: FAT_FloatArray ) {
83  for ( int i = 1; i <= arg.val1.giveSize(); ++i ) {
84  buff << named_arg.first << i << "=" << arg.val1.at(i) << ";";
85  }
86  } else if ( arg.type == FunctionArgument :: FAT_int ) {
87  buff << named_arg.first << "=" << arg.val2 << ";";
88  } else if ( arg.type == FunctionArgument :: FAT_IntArray ) {
89  for ( int i = 1; i <= arg.val3.giveSize(); ++i ) {
90  buff << named_arg.first << i << "=" << arg.val3.at(i) << ";";
91  }
92  }
93  }
94  buff << fExpression;
95  answer.resize(1);
96  answer.at(1) = myParser.eval(buff.str().c_str(), err);
97  if ( err ) {
98  OOFEM_ERROR("parser syntax error");
99  }
100 }
101 
102 
104 {
105  Parser myParser;
106  int err;
107  double result;
108 
109  std :: ostringstream buff;
110  buff << "t=" << time << ";" << fExpression;
111  result = myParser.eval(buff.str().c_str(), err);
112  if ( err ) {
113  OOFEM_ERROR("parser syntax error");
114  }
115 
116  return result;
117 }
118 
120 {
121  Parser myParser;
122  int err;
123  double result;
124 
125  if ( dfdtExpression.size() == 0 ) {
126  OOFEM_ERROR("derivative not provided");
127  return 0.;
128  }
129 
130  std :: ostringstream buff;
131  buff << "t=" << time << ";" << dfdtExpression;
132  result = myParser.eval(buff.str().c_str(), err);
133  if ( err ) {
134  OOFEM_ERROR("parser syntax error");
135  }
136 
137  return result;
138 }
139 
140 
142 {
143  Parser myParser;
144  int err;
145  double result;
146 
147  if ( d2fdt2Expression.size() == 0 ) {
148  OOFEM_ERROR("derivative not provided");
149  return 0.;
150  }
151 
152  std :: ostringstream buff;
153  buff << "t=" << time << ";" << d2fdt2Expression;
154  result = myParser.eval(buff.str().c_str(), err);
155  if ( err ) {
156  OOFEM_ERROR("parser syntax error");
157  }
158 
159  return result;
160 }
161 } // end namespace oofem
void setField(int item, InputFieldType id)
virtual void giveInputRecord(DynamicInputRecord &ir)
Setups the input record string of receiver.
virtual double evaluateVelocityAtTime(double t)
Returns the first time derivative of the function at given time.
Class and object Domain.
Definition: domain.h:115
std::string dfdtExpression
Expression for first time derivative.
#define _IFT_CalculatorFunction_dfdt
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
virtual void evaluate(FloatArray &answer, const std::map< std::string, FunctionArgument > &valDict)
REGISTER_Function(CalculatorFunction)
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
Definition: femcmpnn.C:77
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
#define _IFT_CalculatorFunction_d2fdt2
Wrapper for values of varying types.
Definition: function.h:60
#define _IFT_CalculatorFunction_f
std::string d2fdt2Expression
Expression for second time derivative.
#define OOFEM_ERROR(...)
Definition: error.h:61
virtual double evaluateAtTime(double t)
Returns the value of the function at given time.
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: femcmpnn.C:89
virtual IRResultType initializeFrom(InputRecord *ir)
Reads the fields.
FunctionArgumentType type
Determines which of the types the instance points towards.
Definition: function.h:71
Class representing vector of real numbers.
Definition: floatarray.h:82
Abstract base class representing a function with vector input and output.
Definition: function.h:88
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
Class representing the general Input Record.
Definition: inputrecord.h:101
Class representing the a dynamic Input Record.
virtual double evaluateAccelerationAtTime(double t)
Returns the second time derivative of the function at given time.
std::string fExpression
Expression for the function value.
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
int giveSize() const
Definition: intarray.h:203
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
the oofem namespace is to define a context or scope in which all oofem names are defined.
#define IR_GIVE_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:69
CalculatorFunction(int n, Domain *d)
Constructor.
Class for evaluating mathematical expressions in strings.
Definition: parser.h:54
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631
double eval(const char *string, int &err)
Definition: parser.C:378

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:27 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011