OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
timestep.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 /*
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 "timestep.h"
42 #include "engngm.h"
43 #include "datastream.h"
44 #include "contextioerr.h"
45 #include "error.h"
46 
47 namespace oofem {
48 TimeStep :: TimeStep(int n, EngngModel *e, int mn, double tt, double dt, StateCounterType counter, TimeDiscretizationType td) :
49  eModel(e), targetTime(tt), intrinsicTime(tt), deltaT(dt), solutionStateCounter(counter),
50  number(n), version(0), subStepNumber(0), mStepNumber(mn), timeDiscretization(td)
51 {
52  // Target time and intrinsic time is the same in the constructor.
53 }
54 
56 {
57  eModel = e;
58  deltaT = 0.0;
59  targetTime = 0.0;
60  intrinsicTime = 0.0;
62  number = -1;
63  version = 0;
64  mStepNumber = 0;
65  subStepNumber = 0;
66 }
67 
69 {
70  eModel = src.eModel;
71  targetTime = src.targetTime;
73  deltaT = src.deltaT;
75  number = src.number;
76  version = src.version;
79 }
80 
81 TimeStep :: TimeStep(const TimeStep &previous, double dt)
82 {
83  eModel = previous.eModel;
84  targetTime = previous.targetTime + dt;
85  intrinsicTime = previous.intrinsicTime + dt;
86  deltaT = dt;
88  number = previous.number + 1;
89  version = 0;
90  mStepNumber = previous.mStepNumber ? previous.mStepNumber : 1;
91  subStepNumber = 0;
92 }
93 
94 
95 TimeStep &
97 {
98  eModel = src.eModel;
99  targetTime = src.targetTime;
101  deltaT = src.deltaT;
103  number = src.number;
104  version = src.version;
105  mStepNumber = src.mStepNumber;
107 
108  return * this;
109 }
110 
111 
112 
113 
115 // Not accepted in-line.
116 {
117  if ( isTheCurrentTimeStep() ) {
118  return eModel->givePreviousStep();
119  } else {
120  OOFEM_ERROR("Could not return previous step of noncurrent step");
121  }
122 
123  return NULL; // to make compiler happy
124 }
125 
126 
128 // Returns True if the time history contains steps after the receiver,
129 // else returns False.
130 {
131  return ( number != eModel->giveNumberOfSteps() );
132 }
133 
135 {
136  // Returns True if the receiver is the first time step,
137  // according to first step number
138  // else returns False.
139 
140  return ( number == eModel->giveNumberOfFirstStep() );
141 }
142 
143 
145 {
146  // Returns True if the receiver is the time step,
147  // when Initial conditions apply
148  // else returns False.
149 
151 }
152 
153 
154 
156 // Not accepted in-line.
157 {
158  return this == eModel->giveCurrentStep();
159 }
160 
161 
164 {
165  // write step number
166  if ( !stream.write(number) ) {
168  }
169 
170  // write meta step number
171  if ( !stream.write(mStepNumber) ) {
173  }
174 
175  // write target time
176  if ( !stream.write(this->targetTime) ) {
178  }
179 
180  // write intrinsic time
181  if ( !stream.write(this->intrinsicTime) ) {
183  }
184 
185  // write deltaT
186  if ( !stream.write(this->deltaT) ) {
188  }
189 
190  // write solutionStateCounter
191  if ( !stream.write(this->solutionStateCounter) ) {
193  }
194 
195  // write timeDiscretization
196  int tDiscretization = ( int ) timeDiscretization;
197  if ( !stream.write(tDiscretization) ) {
199  }
200 
201  // return result back
202  return CIO_OK;
203 }
204 
207 {
208  // read step number
209  if ( !stream.read(number) ) {
211  }
212 
213  // read meta step number
214  if ( !stream.read(mStepNumber) ) {
216  }
217 
218  // read target time
219  if ( !stream.read(this->targetTime) ) {
221  }
222 
223  // read intrinsic time
224  if ( !stream.read(this->intrinsicTime) ) {
226  }
227 
228  // read deltaT
229  if ( !stream.read(this->deltaT) ) {
231  }
232 
233  // read solutionStateCounter
234  if ( !stream.read(this->solutionStateCounter) ) {
236  }
237 
238  // read timeDiscretization
239  int tDiscretization = 0;
240  if ( !stream.read(tDiscretization) ) {
242  }
243  timeDiscretization = ( TimeDiscretizationType ) tDiscretization;
244 
245  // return result back
246  return CIO_OK;
247 }
248 } // end namespace oofem
double intrinsicTime
Current intrinsic time, which may represents imposing time of boundary condition or time entering con...
Definition: timestep.h:88
TimeDiscretizationType timeDiscretization
Time discretization.
Definition: timestep.h:108
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
EngngModel * eModel
Engineering model reference.
Definition: timestep.h:84
long StateCounterType
StateCounterType type used to indicate solution state.
int version
Receiver's version, used for special applications; default set to 0.
Definition: timestep.h:100
StateCounterType solutionStateCounter
Solution state counter.
Definition: timestep.h:92
General IO error.
virtual int read(int *data, int count)=0
Reads count integer values into array pointed by data.
#define THROW_CIOERR(e)
Definition: contextioerr.h:61
bool isTheFirstStep()
Check if receiver is first step.
Definition: timestep.C:134
virtual int write(const int *data, int count)=0
Writes count integer values from array pointed by data.
TimeDiscretizationType
Time discretization used by transient solvers.
#define OOFEM_ERROR(...)
Definition: error.h:61
contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the receiver state previously written in stream.
Definition: timestep.C:206
int mStepNumber
Corresponding meta step number.
Definition: timestep.h:106
int giveNumberOfSteps(bool force=false)
Returns total number of steps.
Definition: engngm.h:744
TimeStep(int n, EngngModel *e, int mn, double tt, double dt, StateCounterType counter, TimeDiscretizationType td=TD_Unspecified)
Creates a new solution step.
Definition: timestep.C:48
virtual int giveNumberOfFirstStep(bool force=false)
Returns number of first time step used by receiver.
Definition: engngm.h:730
TimeStep * givePreviousStep()
Returns pointer to previous solution step.
Definition: timestep.C:114
bool isTheCurrentTimeStep()
Check if receiver is current solution step.
Definition: timestep.C:155
int giveNumberOfTimeStepWhenIcApply()
Returns the time step number, when initial conditions should apply.
Definition: engngm.h:754
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
virtual TimeStep * givePreviousStep(bool force=false)
Returns previous time step.
Definition: engngm.h:693
int number
Receiver's number.
Definition: timestep.h:94
double deltaT
Current intrinsic time increment.
Definition: timestep.h:90
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
virtual TimeStep * giveCurrentStep(bool force=false)
Returns current time step.
Definition: engngm.h:683
bool isIcApply()
Check if receiver is solution step when initial conditions should apply.
Definition: timestep.C:144
double targetTime
Current target time, which represents time at the end of a time step.
Definition: timestep.h:86
TimeStep & operator=(const TimeStep &)
Definition: timestep.C:96
the oofem namespace is to define a context or scope in which all oofem names are defined.
bool isNotTheLastStep()
Check if solution step is not the last step.
Definition: timestep.C:127
contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Stores receiver state to output stream.
Definition: timestep.C:163
Class representing solution step.
Definition: timestep.h:80
int subStepNumber
Receiver's substep (iteration) number.
Definition: timestep.h:104

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:31 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011