OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
eigenvaluedynamic.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 "../sm/EngineeringModels/eigenvaluedynamic.h"
36 #include "timestep.h"
37 #include "floatmatrix.h"
38 #include "floatarray.h"
39 #include "exportmodulemanager.h"
40 #include "verbose.h"
41 #include "classfactory.h"
42 #include "datastream.h"
43 #include "geneigvalsolvertype.h"
44 #include "contextioerr.h"
45 #include "classfactory.h"
46 #include "dofmanager.h"
47 #include "dof.h"
48 #include "domain.h"
49 #include "unknownnumberingscheme.h"
50 
51 #ifdef __OOFEG
52  #include "oofeggraphiccontext.h"
53 #endif
54 
55 namespace oofem {
56 REGISTER_EngngModel(EigenValueDynamic);
57 
59 {
60  if ( !nMethod ) {
61  nMethod.reset( classFactory.createGeneralizedEigenValueSolver(solverType, this->giveDomain(1), this) );
62  if ( !nMethod ) {
63  OOFEM_ERROR("solver creation failed");
64  }
65  }
66 
67  return nMethod.get();
68 }
69 
72 {
73  IRResultType result; // Required by IR_GIVE_FIELD macro
74  //EngngModel::instanciateFrom (ir);
75 
77 
78  // numberOfSteps set artificially to numberOfRequiredEigenValues
79  // in order to allow
80  // use restoreContext function for different eigenValues
81  // numberOfSteps = numberOfRequiredEigenValues;
82  numberOfSteps = 1;
83 
85  if ( rtolv < 1.e-12 ) {
86  rtolv = 1.e-12;
87  }
88 
89  if ( rtolv > 0.01 ) {
90  rtolv = 0.01;
91  }
92 
93  int val = 0;
96 
97  val = 0; //Default Skyline
100 
102 
103  if(suppressOutput) {
104  printf("Suppressing output.\n");
105  }
106  else {
107 
108  if ( ( outputStream = fopen(this->dataOutputFileName.c_str(), "w") ) == NULL ) {
109  OOFEM_ERROR("Can't open output file %s", this->dataOutputFileName.c_str());
110  }
111 
112  fprintf(outputStream, "%s", PRG_HEADER);
113  fprintf(outputStream, "\nStarting analysis on: %s\n", ctime(& this->startTime) );
114  fprintf(outputStream, "%s\n", simulationDescription.c_str());
115  }
116 
117  return IRRT_OK;
118 }
119 
120 
122 // returns unknown quantity like displacement, eigenvalue.
123 // This function translates this request to numerical method language
124 {
125  int eq = dof->__giveEquationNumber();
126 #ifdef DEBUG
127  if ( eq == 0 ) {
128  OOFEM_ERROR("invalid equation number");
129  }
130 #endif
131 
132  switch ( mode ) {
133  case VM_Total: // EigenVector
134  case VM_Incremental:
135  return eigVec.at( eq, ( int ) tStep->giveTargetTime() );
136 
137  default:
138  OOFEM_ERROR("Unknown is of undefined type for this problem");
139  }
140 
141  return 0.;
142 }
143 
144 
146 {
147  int istep = giveNumberOfFirstStep();
148  StateCounterType counter = 1;
149 
150  if ( currentStep ) {
151  istep = currentStep->giveNumber() + 1;
152  counter = currentStep->giveSolutionStateCounter() + 1;
153  }
154 
155  previousStep = std :: move(currentStep);
156  currentStep.reset( new TimeStep(istep, this, 1, ( double ) istep, 0., counter) );
157 
158  return currentStep.get();
159 }
160 
161 
163 {
164  //
165  // creates system of governing eq's and solves them at given time step
166  //
167  // first assemble problem at current time step
168 
169 #ifdef VERBOSE
170  OOFEM_LOG_INFO("Assembling stiffness and mass matrices\n");
171 #endif
172 
173  if ( tStep->giveNumber() == 1 ) {
174  //
175  // first step assemble stiffness Matrix
176  //
177 
179  stiffnessMatrix->buildInternalStructure( this, 1, EModelDefaultEquationNumbering() );
180 
182  massMatrix->buildInternalStructure( this, 1, EModelDefaultEquationNumbering() );
183 
184  this->assemble( *stiffnessMatrix, tStep, TangentAssembler(TangentStiffness),
186  this->assemble( *massMatrix, tStep, MassMatrixAssembler(),
188  //
189  // create resulting objects eigVec and eigVal
190  //
192  eigVec.zero();
194  eigVal.zero();
195  }
196 
197  //
198  // set-up numerical model
199  //
200  this->giveNumericalMethod( this->giveMetaStep( tStep->giveMetaStepNumber() ) );
201 
202  //
203  // call numerical model to solve arised problem
204  //
205 #ifdef VERBOSE
206  OOFEM_LOG_INFO("Solving ...\n");
207 #endif
208 
210 
211  stiffnessMatrix.reset(NULL);
212  massMatrix.reset(NULL);
213 }
214 
215 
217 { }
218 
219 
221 {
222  if ( !suppressOutput ) {
223  this->printOutputAt(this->giveOutputStream(), tStep);
224  fflush( this->giveOutputStream() );
225  }
226 
227  for ( int i = 1; i <= numberOfRequiredEigenValues; i++ ) {
228  // export using export manager
229  tStep->setTime( ( double ) i ); // we use time as intrinsic eigen value index
230  tStep->setNumber(i);
232  }
233 }
234 
235 
237 {
238  Domain *domain = this->giveDomain(1);
239 
240  // print loadcase header
241  fprintf(file, "\nOutput for time %.3e \n\n", 1.0);
242  // print eigen values on output
243  fprintf(file, "\n\nEigen Values (Omega^2) are:\n-----------------\n");
244 
245  for ( int i = 1; i <= numberOfRequiredEigenValues; i++ ) {
246  fprintf(file, "%15.8e ", eigVal.at(i) );
247  if ( ( i % 5 ) == 0 ) {
248  fprintf(file, "\n");
249  }
250  }
251 
252  fprintf(file, "\n\n");
253 
254  for ( int i = 1; i <= numberOfRequiredEigenValues; i++ ) {
255  fprintf(file, "\nOutput for eigen value no. %.3e \n", ( double ) i);
256  fprintf(file, "Printing eigen vector no. %d, corresponding eigen value is %15.8e\n\n",
257  i, eigVal.at(i) );
258  tStep->setTime( ( double ) i ); // we use time as intrinsic eigen value index
259 
260  if ( this->requiresUnknownsDictionaryUpdate() ) {
261  for ( auto &dman : domain->giveDofManagers() ) {
262  this->updateDofUnknownsDictionary(dman.get(), tStep);
263  }
264  }
265 
266 
267  for ( auto &dman : domain->giveDofManagers() ) {
268  dman->updateYourself(tStep);
269  dman->printOutputAt(file, tStep);
270  }
271  }
272 }
273 
274 
276 {
277  contextIOResultType iores;
278 
279  if ( ( iores = EngngModel :: saveContext(stream, mode) ) != CIO_OK ) {
280  THROW_CIOERR(iores);
281  }
282 
283  if ( ( iores = eigVal.storeYourself(stream) ) != CIO_OK ) {
284  THROW_CIOERR(iores);
285  }
286 
287  if ( ( eigVec.storeYourself(stream) ) != CIO_OK ) {
288  THROW_CIOERR(iores);
289  }
290 
291  return CIO_OK;
292 }
293 
294 
296 {
297  contextIOResultType iores;
298 
299  if ( ( iores = EngngModel :: restoreContext(stream, mode) ) != CIO_OK ) {
300  THROW_CIOERR(iores);
301  }
302 
303  if ( ( iores = eigVal.restoreYourself(stream) ) != CIO_OK ) {
304  THROW_CIOERR(iores);
305  }
306 
307  if ( ( iores = eigVec.restoreYourself(stream) ) != CIO_OK ) {
308  THROW_CIOERR(iores);
309  }
310 
311  return CIO_OK;
312 }
313 
314 
316 {
317  this->activeVector = i;
320  }
321 
322  this->giveCurrentStep()->setTime( ( double ) activeVector );
323 }
324 
325 } // end namespace oofem
GenEigvalSolverType
Types of general eigenvalue solvers.
The representation of EngngModel default unknown numbering.
FILE * outputStream
Output stream.
Definition: engngm.h:242
std::unique_ptr< TimeStep > currentStep
Current time step.
Definition: engngm.h:231
std::string simulationDescription
Definition: engngm.h:316
Class and object Domain.
Definition: domain.h:115
virtual int giveNumberOfDomainEquations(int di, const UnknownNumberingScheme &num)
Returns number of equations for given domain in active (current time step) time step.
Definition: engngm.C:391
std::string dataOutputFileName
Path to output stream.
Definition: engngm.h:238
Class representing meta step.
Definition: metastep.h:62
SparseMtrx * createSparseMtrx(SparseMtrxType type)
Creates new instance of sparse matrix corresponding to given keyword.
Definition: classfactory.C:105
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
contextIOResultType storeYourself(DataStream &stream) const
Definition: floatarray.C:872
std::unique_ptr< TimeStep > previousStep
Previous time step.
Definition: engngm.h:233
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
MetaStep * giveMetaStep(int i)
Returns the i-th meta step.
Definition: engngm.C:1765
ValueModeType
Type representing the mode of UnknownType or CharType, or similar types.
Definition: valuemodetype.h:78
virtual int requiresUnknownsDictionaryUpdate()
Indicates if EngngModel requires Dofs dictionaries to be updated.
Definition: engngm.h:845
long StateCounterType
StateCounterType type used to indicate solution state.
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode)
Stores the state of model to output stream.
This base class is an abstraction for numerical algorithm.
Definition: nummet.h:80
virtual void doStepOutput(TimeStep *tStep)
Prints the ouput of the solution step (using virtual this->printOutputAtservice) to the stream detemi...
Implementation for assembling tangent matrices in standard monolithic FE-problems.
virtual bool hasField(InputFieldType id)=0
Returns true if record contains field identified by idString keyword.
time_t startTime
Solution start time.
Definition: engngm.h:259
double giveTargetTime()
Returns target time.
Definition: timestep.h:146
void setTime(double newt)
Sets target and intrinsic time to be equal.
Definition: timestep.h:154
void doOutput(TimeStep *tStep, bool substepFlag=false)
Writes the output.
std::vector< std::unique_ptr< DofManager > > & giveDofManagers()
Definition: domain.h:400
Implementation for assembling the consistent mass matrix.
virtual int __giveEquationNumber() const =0
Returns equation number of receiver, usually assigned by emodel.
virtual void setActiveVector(int i)
Only relevant for eigen value analysis. Otherwise does noting.
REGISTER_EngngModel(ProblemSequence)
#define _IFT_EigenValueDynamic_stype
#define THROW_CIOERR(e)
Definition: contextioerr.h:61
contextIOResultType storeYourself(DataStream &stream) const
Definition: floatmatrix.C:1852
virtual NumericalMethod * giveNumericalMethod(MetaStep *mStep)
Returns reference to receiver&#39;s numerical method.
virtual void updateYourself(TimeStep *tStep)
Updates internal state after finishing time step.
virtual void assemble(SparseMtrx &answer, TimeStep *tStep, const MatrixAssembler &ma, const UnknownNumberingScheme &s, Domain *domain)
Assembles characteristic matrix of required type into given sparse matrix.
Definition: engngm.C:803
int giveNumber()
Returns receiver&#39;s number.
Definition: timestep.h:129
#define OOFEM_LOG_INFO(...)
Definition: logger.h:127
FILE * giveOutputStream()
Returns file descriptor of output file.
Definition: engngm.C:1791
#define _IFT_EngngModel_smtype
Definition: engngm.h:82
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description in input reader.
#define OOFEM_ERROR(...)
Definition: error.h:61
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode)
Restores the state of model from output stream.
int numberOfSteps
Total number of time steps.
Definition: engngm.h:209
virtual void solveYourselfAt(TimeStep *tStep)
Solves problem for given time step.
SparseMtrxType
Enumerative type used to identify the sparse matrix type.
virtual double giveUnknownComponent(ValueModeType type, TimeStep *tStep, Domain *d, Dof *dof)
Returns requested unknown.
contextIOResultType restoreYourself(DataStream &stream)
Definition: floatarray.C:895
#define _IFT_EngngModel_suppressOutput
Definition: engngm.h:84
virtual int giveNumberOfFirstStep(bool force=false)
Returns number of first time step used by receiver.
Definition: engngm.h:730
double at(int i, int j) const
Coefficient access function.
Definition: floatmatrix.h:176
ExportModuleManager * exportModuleManager
Export module manager.
Definition: engngm.h:250
#define _IFT_EigenValueDynamic_rtolv
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode)
Stores the state of model to output stream.
Definition: engngm.C:1527
contextIOResultType restoreYourself(DataStream &stream)
Definition: floatmatrix.C:1877
Initializes the variable VERBOSE, in order to get a few intermediate messages on screen: beginning an...
std::unique_ptr< SparseGeneralEigenValueSystemNM > nMethod
Numerical method used to solve the problem.
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
#define _IFT_EigenValueDynamic_nroot
virtual void updateDofUnknownsDictionary(DofManager *, TimeStep *)
Updates necessary values in Dofs unknown dictionaries.
Definition: engngm.h:859
int giveMetaStepNumber()
Returns receiver&#39;s meta step number.
Definition: timestep.h:135
std::unique_ptr< SparseMtrx > stiffnessMatrix
void resize(int rows, int cols)
Checks size of receiver towards requested bounds.
Definition: floatmatrix.C:1358
Class representing the general Input Record.
Definition: inputrecord.h:101
void zero()
Zeroes all coefficients of receiver.
Definition: floatarray.C:658
virtual TimeStep * giveNextStep()
Returns next time step (next to current step) of receiver.
ClassFactory & classFactory
Definition: classfactory.C:59
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
void zero()
Zeroes all coefficient of receiver.
Definition: floatmatrix.C:1326
bool suppressOutput
Flag for suppressing output to file.
Definition: engngm.h:314
SparseGeneralEigenValueSystemNM * createGeneralizedEigenValueSolver(GenEigvalSolverType name, Domain *d, EngngModel *m)
Definition: classfactory.C:411
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
virtual TimeStep * giveCurrentStep(bool force=false)
Returns current time step.
Definition: engngm.h:683
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode)
Restores the state of model from output stream.
Definition: engngm.C:1592
GenEigvalSolverType solverType
the oofem namespace is to define a context or scope in which all oofem names are defined.
Domain * giveDomain(int n)
Service for accessing particular problem domain.
Definition: engngm.C:1720
#define IR_GIVE_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:69
Abstract class Dof represents Degree Of Freedom in finite element mesh.
Definition: dof.h:93
std::unique_ptr< SparseMtrx > massMatrix
double rtolv
Relative tolerance.
Class representing solution step.
Definition: timestep.h:80
void setNumber(int i)
Set receiver&#39;s number.
Definition: timestep.h:131
virtual void printOutputAt(FILE *file, TimeStep *tStep)
Prints output of receiver to output domain stream, for given time step.
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631

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