OOFEM 3.0
Loading...
Searching...
No Matches
metastep.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 "metastep.h"
36#include "function.h"
37
38namespace oofem {
39MetaStep :: MetaStep(int n, EngngModel *e) :
40 eModel(e),
42 number(n)
43{}
44
45MetaStep :: MetaStep(int n, EngngModel *e, int nsteps, InputRecord &attrib) :
46 eModel(e),
47 numberOfSteps(nsteps),
48 attributes(attrib.clone()),
49 number(n)
50{}
51
52
53void
54MetaStep :: initializeFrom(InputRecord &ir)
55{
56 timeStepReductionStrategyType = "NoReduction";
57 // read time step reduction strategy type
59 // create and initialize time step reduction strategy
60 timeStepReductionStrategy = classFactory.createTimeStepReductionStrategy(this->timeStepReductionStrategyType.c_str(),1);
61 timeStepReductionStrategy->initializeFrom(ir);
62 // default value of dT is 1;
63 deltaT = 1.;
65 prescribedTimes.clear();
67 // compute minDeltaT as min of deltaT and mindeltaT form timeStepReudctionStrategy
68 minDeltaT = std::min(deltaT, timeStepReductionStrategy->giveMinDeltaT());
69
70 if ( finalTime < 0 ) {
71 OOFEM_ERROR("Final time of the analysis can't be negative");
72 } else if(finalTime == 0) {
74 if ( numberOfSteps < 0 ) {
75 OOFEM_ERROR("Numer of steps has to be positive number");
76 } else {
77 dtFunction = 0;
80 } else if ( ir.hasField(_IFT_MetaStep_prescribedTimes) ) {
82 if ( prescribedTimes.giveSize() > 0 ) {
83 numberOfSteps = prescribedTimes.giveSize();
85 }
86 } else {
87 //@todo: how to get dt
89 }
90 }
91 }
92
93 this->attributes = ir.clone();
94}
95
96int
97MetaStep :: setStepBounds(int startStepNumber)
98{
99 sindex = startStepNumber;
100
101 return sindex + numberOfSteps;
102}
103
104void
105MetaStep :: setNumberOfSteps(int newNumberOfSteps)
106{
107 this->numberOfSteps = newNumberOfSteps;
108}
109
110int
111MetaStep :: isStepValid(int solStepNumber)
112{
113 return solStepNumber >= sindex && solStepNumber < ( sindex + numberOfSteps );
114}
115
116
117double
118MetaStep :: giveDeltaT(int n, std::unique_ptr<TimeStep> &previousStep)
119{
120 //@todo: Handle the dTfunction and discrete times appropriately
121 if ( giveDtFunction() ) {
122 return giveDtFunction()->evaluateAtTime(n);
123 }
124
125 if ( discreteTimes.giveSize() > 0 ) {
126 return this->giveDiscreteTime(n) - this->giveDiscreteTime(n - 1);
127 }
128
129 if ( this->prescribedTimes.giveSize() > 0 ) {
130 return this->prescribedTimes.at(previousStep->giveNumber() + 1) - previousStep->giveTargetTime();
131 }
132
133 return deltaT;
134}
135
136
137void
138MetaStep :: reduceTimeStep()
139{
140 double dT = deltaT * this->timeStepReductionStrategy->giveNoConvergenceTimeIncrementReductionFactor();
141 if(dT >= this->timeStepReductionStrategy->give_dTmin()) {
142 this->deltaT = dT;
143 } else {
144 OOFEM_ERROR("Minimum time increment reached");
145 }
146}
147
148void
149MetaStep :: adaptTimeStep(int niter, double targetTime)
150{
151 auto dT_iter = this->timeStepReductionStrategy->giveReqIterTimeIncrementAdaptationFactor(niter);
152 auto dT_MatMax = this->timeStepReductionStrategy->giveMaterialTimeIncrementAdaptationFactorMax();
153 auto dT_MatMin = this->timeStepReductionStrategy->giveMaterialTimeIncrementAdaptationFactorMin();
154 auto dT = this->deltaT;
155
156 if(dT_iter < 1) {
157 dT *= std::min(dT_MatMin, dT_iter);
158 } else {
159 if(dT_MatMin < 1) {
160 dT *= dT_MatMin;
161 } else {
162 dT *= std::max(dT_MatMax, dT_iter);
163 }
164 }
165
166 double dtmin = this->timeStepReductionStrategy->give_dTmin();
167 double dtmax = this->timeStepReductionStrategy->give_dTmax();
168
169 if(dT > dtmax){
170 OOFEM_WARNING("Setting time increment to the maximum value dTmax, %f", dtmax);
171 dT = dtmax;
172 }else if(dT < dtmin){
173 OOFEM_WARNING("Setting time increment to the minimum value dTmin, %f", dtmin);
174 dT = dtmin;
175 }
176
177 if( targetTime + dT > this->finalTime ) {
178 dT = finalTime - targetTime;
179 }
180
181
182 this->deltaT = dT;
183
184}
185
186
187void
188MetaStep :: setTimeStepReductionFactor(double tsrf)
189{
190 this->timeStepReductionStrategy->setTimeStepIncrementAdaptationFactor(tsrf);
191}
192
193
194
195} // end namespace oofem
virtual bool hasField(InputFieldType id)=0
Returns true if record contains field identified by idString keyword.
virtual std::shared_ptr< InputRecord > clone() const =0
double previousMetaStepFinalTime
final time of the previous meta step
Definition metastep.h:103
std::string timeStepReductionStrategyType
Time step reduction strategy type - default no reduction of time step.
Definition metastep.h:97
double giveDiscreteTime(int n)
Definition metastep.h:173
std::shared_ptr< InputRecord > attributes
Engineering model attributes.
Definition metastep.h:85
double finalTime
final time of the metastep
Definition metastep.h:83
double minDeltaT
Minimal value of the time step.
Definition metastep.h:101
FloatArray prescribedTimes
Specified times where the problem is solved.
Definition metastep.h:91
int number
Receiver number.
Definition metastep.h:89
EngngModel * eModel
Engineering model of receiver.
Definition metastep.h:77
int dtFunction
Associated time function for time step increment.
Definition metastep.h:93
int sindex
Start solution step number for which receiver is responsible.
Definition metastep.h:87
std ::unique_ptr< TimeStepReductionStrategy > timeStepReductionStrategy
Time step reduction strategy type.
Definition metastep.h:99
int numberOfSteps
Number of subsequent steps the receiver represent.
Definition metastep.h:79
double deltaT
Intrinsic time increment.
Definition metastep.h:81
Function * giveDtFunction()
Definition metastep.h:156
FloatArray discreteTimes
Specified times where the problem is solved merge with prescribedTimes.
Definition metastep.h:95
#define OOFEM_WARNING(...)
Definition error.h:80
#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
#define _IFT_MetaStep_nsteps
Definition metastep.h:47
#define _IFT_MetaStep_dtFunction
Function that determines size of time step.
Definition metastep.h:51
#define _IFT_MetaStep_deltaT
Definition metastep.h:49
#define _IFT_MetaStep_timeReductionStrategyType
Definition metastep.h:53
#define _IFT_MetaStep_prescribedTimes
Definition metastep.h:50
#define _IFT_MetaStep_finalT
Definition metastep.h:48
ClassFactory & classFactory

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