OOFEM 3.0
Loading...
Searching...
No Matches
function.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 "function.h"
36#include "timestep.h"
37#include "error.h"
38#include "domain.h"
39#include "gausspoint.h"
40#include "datastream.h"
41#include "contextioerr.h"
42
43namespace oofem {
44Function :: Function(int n, Domain *d) :
45 FEMComponent(n, d)
46{ this->parameterType=0; }
47
48double
49Function :: giveFunctionParameter(int paramID)
50{
51 if(this->giveDomain()->giveElement(this->giveNumber())!=NULL)
52 return 1.;
53 return 0.;
54}
55
56double
57Function :: evaluate(TimeStep *tStep, ValueModeType mode)
58{
59 if ( mode == VM_Total ) {
60 return this->evaluateAtTime( tStep->giveIntrinsicTime() );
61 } else if ( mode == VM_Velocity ) {
62 return this->evaluateVelocityAtTime( tStep->giveIntrinsicTime() );
63 } else if ( mode == VM_Acceleration ) {
64 return this->evaluateAccelerationAtTime( tStep->giveIntrinsicTime() );
65 } else if ( mode == VM_Incremental ) {
66 return this->evaluateAtTime( tStep->giveIntrinsicTime() ) - this->evaluateAtTime( tStep->giveIntrinsicTime() - tStep->giveTimeIncrement() );
67 } else if ((mode == VM_Intermediate) || (mode == VM_TotalIntrinsic)) {
68 return this->evaluateAtTime( tStep->giveIntrinsicTime() );
69 } else {
70 OOFEM_ERROR("unsupported mode(%d)", mode);
71 }
72
73 // return 0.;
74}
75
76
77double
78Function :: evaluateAtTime(double t)
79{
80 FloatArray v;
81 this->evaluate(v, {{"t",t}});
82 if ( v.giveSize() != 1 ) {
83 OOFEM_ERROR("Function doesn't return scalar results.");
84 }
85 return v.at(1);
86}
87
88
89void
90Function :: evaluate(FloatArray &answer, const std :: map< std :: string, FunctionArgument > &valDict, GaussPoint *gp, double param)
91{
92 if(this->parameterType==0)
93 {
94 auto it = valDict.find("t");
95 if ( it == valDict.end() )
96 {
97 OOFEM_ERROR("Missing necessary argument \"t\"");
98 }else{
99 answer = Vec1(this->evaluateAtTime(it->second.val0));
100 }
101 }
102 else if(this->parameterType==1)
103 {
104 answer = Vec1(this->evaluateAtTime(param));
105 }
106 else
107 OOFEM_ERROR("Unknown parameter type %d",parameterType);
108}
109
110double
111Function :: evaluate(const std :: map< std :: string, FunctionArgument > &valDict)
112{
113 FloatArray ans;
114 this->evaluate(ans, valDict);
115 if ( ans.giveSize() != 1 ) {
116 OOFEM_ERROR("Function does not return scalar value");
117 }
118 return ans[0];
119}
120
121void
122Function :: saveContext(DataStream &stream, ContextMode mode)
123{
124 FEMComponent :: saveContext(stream, mode);
125
126 if ( mode & CM_Definition ) {
127 if ( !stream.write(parameterType) ) {
129 }
130 }
131}
132
133
134void
135Function :: restoreContext(DataStream &stream, ContextMode mode)
136{
137 FEMComponent :: restoreContext(stream, mode);
138
139 if ( mode & CM_Definition ) {
140 if ( !stream.read(parameterType) ) {
142 }
143 }
144}
145
146} // end namespace oofem
virtual int read(int *data, std::size_t count)=0
Reads count integer values into array pointed by data.
virtual int write(const int *data, std::size_t count)=0
Writes count integer values from array pointed by data.
Domain * giveDomain() const
Definition femcmpnn.h:97
int giveNumber() const
Definition femcmpnn.h:104
FEMComponent(int n, Domain *d)
Definition femcmpnn.h:88
double & at(Index i)
Definition floatarray.h:202
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
virtual double evaluateAtTime(double t)
Definition function.C:78
virtual double evaluate(TimeStep *tStep, ValueModeType mode)
Definition function.C:57
virtual double evaluateAccelerationAtTime(double t)=0
virtual double evaluateVelocityAtTime(double t)=0
double giveTimeIncrement()
Returns solution step associated time increment.
Definition timestep.h:168
double giveIntrinsicTime()
Returns intrinsic time, e.g. time in which constitutive model is evaluated.
Definition timestep.h:166
#define THROW_CIOERR(e)
#define CM_Definition
Definition contextmode.h:47
#define OOFEM_ERROR(...)
Definition error.h:79
long ContextMode
Definition contextmode.h:43
@ CIO_IOERR
General IO error.
static FloatArray Vec1(const double &a)
Definition floatarray.h:605

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