OOFEM 3.0
Loading...
Searching...
No Matches
timestepcontroller.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/*
36 * The original idea for this class comes from
37 * Dubois-Pelerin, Y.: "Object-Oriented Finite Elements: Programming concepts and Implementation",
38 * PhD Thesis, EPFL, Lausanne, 1992.
39 */
40
41#include "timestepcontroller.h"
42#include "datastream.h"
43#include "contextioerr.h"
44#include "error.h"
45#include "classfactory.h"
46#include "engngm.h"
47#include "function.h"
48
49namespace oofem {
50
51
52void
53TimeStepController :: initializeFrom(InputRecord &ir)
54{
55
58
59}
60
61
62void
63TimeStepController :: saveContext(DataStream &stream)
64{
65
66}
67
68
69void
70TimeStepController :: restoreContext(DataStream &stream)
71{
72
73}
74
75
77TimeStepController :: giveNextStep()
78{
79 int istep = eModel->giveNumberOfFirstStep();
80 double totalTime = 1.;
81 StateCounterType counter = 1;
82 double dt = this->giveDeltaT();
83 if ( !currentStep ) {
84 currentStep = std::make_unique<TimeStep>(giveNumberOfTimeStepWhenIcApply(), eModel, 1, 0., dt, 0);
85 //currentStep = std::make_unique<TimeStep>(giveNumberOfTimeStepWhenIcApply(), eModel, 0, -dt, dt, 0);
86 }
87
88 auto mStepNum = currentStep->giveMetaStepNumber();
89 previousStep = std :: move(currentStep);
90 dt = this->giveCurrentMetaStep()->giveDeltaT(istep, previousStep);
91 totalTime = previousStep->giveTargetTime() + dt;
92 istep = previousStep->giveNumber() + 1;
93 counter = previousStep->giveSolutionStateCounter() + 1;
94
95 //
96 currentStep = std::make_unique<TimeStep>(istep, eModel, mStepNum, totalTime, dt, counter);
97 //
98 double intrinsicTime = previousStep->giveTargetTime() + this->alpha * dt;
99 currentStep->setIntrinsicTime(intrinsicTime);
100
101 return currentStep.get();
102}
103
104
105int
106TimeStepController :: instanciateMetaSteps(DataReader &dr)
107{
108 int totalNumberOfSteps=0;
109 // create meta steps
110 metaStepList.clear();
111 metaStepList.reserve(this->numberOfMetaSteps);
112 for ( int i = 1; i <= this->numberOfMetaSteps; i++ ) {
113 //MetaStep *mstep = new MetaStep(i, this);
114 metaStepList.emplace_back(i, eModel);
115 }
116
117 // read problem domains
118 auto mrecs=dr.giveGroupRecords("Metasteps",DataReader::IR_mstepRec,this->numberOfMetaSteps);
119 int i=0;
120 for(InputRecord& mrec: mrecs){
121 metaStepList[i].initializeFrom(mrec);
122 if(i > 0) {
123 metaStepList[i].setPreviousMetaStepFinalTime(metaStepList[i-1].giveFinalTime());
124 }
125 totalNumberOfSteps += metaStepList[i].giveNumberOfSteps();
126 i++;
127 }
128 return 1;
129}
130
131
132MetaStep *
133TimeStepController :: giveMetaStep(int i)
134{
135 if ( ( i > 0 ) && ( i <= this->numberOfMetaSteps ) ) {
136 return &this->metaStepList[i-1];
137 } else {
138 OOFEM_ERROR("undefined metaStep (%d)", i);
139 }
140
141 return NULL;
142}
143
144
145int
146TimeStepController :: instanciateDefaultMetaStep(InputRecord &ir)
147{
148
149 metaStepList.clear();
150 this->numberOfMetaSteps = 1;
151 metaStepList.reserve(1);
152 //
153 metaStepList.emplace_back(1, eModel);
154 metaStepList[0].initializeFrom(ir);
155 return 1;
156}
157
158
159void
160TimeStepController :: initMetaStepAttributes(MetaStep *mStep)
161{
162 // update attributes
163 eModel->updateAttributes(mStep); // virtual function
164}
165
166
167
168
169
170void
171TimeStepController :: postInitialize()
172{
173 int istep = eModel->giveNumberOfFirstStep(true);
174 for ( auto &metaStep: metaStepList ) {
175 istep = metaStep.setStepBounds(istep);
176 }
177
178
179}
180
181void
182TimeStepController :: reduceTimeStep()
183{
184 MetaStep *mS = this->giveCurrentMetaStep();
185 mS->reduceTimeStep();
186 this->currentStep->setTargetTime(this->currentStep->giveTargetTime()-this->currentStep->giveTimeIncrement()+mS->giveDeltaT());
187 this->currentStep->setIntrinsicTime(this->currentStep->giveIntrinsicTime()-this->currentStep->giveTimeIncrement()+mS->giveDeltaT());
188 this->currentStep->setTimeIncrement(mS->giveDeltaT());
189
190}
191
192void
193TimeStepController :: adaptTimeStep(int nIter)
194{
195
196 MetaStep *mS = this->giveCurrentMetaStep();
197 this->giveCurrentMetaStep()->adaptTimeStep(nIter, this->currentStep->giveTargetTime());
198 this->currentStep->setTimeIncrement(mS->giveDeltaT());
199
200}
201
202
203
204
205
206
207} // end namespace oofem
GroupRecords giveGroupRecords(const std::shared_ptr< InputRecord > &ir, InputFieldType ift, const std::string &name, InputRecordType irType, bool optional)
Definition datareader.C:46
DataReader * giveReader() const
std::shared_ptr< InputRecord > ptr()
void reduceTimeStep()
Reduce the time step length in case of no convergence.
Definition metastep.C:138
double giveDeltaT()
Returns the time step length.
Definition metastep.h:160
int giveNumberOfTimeStepWhenIcApply()
Returns the time step number, when initial conditions should apply.
std ::vector< MetaStep > metaStepList
List of problem metasteps.
std ::unique_ptr< TimeStep > previousStep
Previous time step.
std ::unique_ptr< TimeStep > currentStep
Current time step.
#define _IFT_EngngModel_nmsteps
Definition engngm.h:82
#define OOFEM_ERROR(...)
Definition error.h:79
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
long StateCounterType
StateCounterType type used to indicate solution state.
#define _IFT_TimeStepController_alpha

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