OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
gpexportmodule.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 "gpexportmodule.h"
36 #include "gausspoint.h"
37 #include "material.h"
38 #include "element.h"
39 #include "integrationrule.h"
40 #include "timestep.h"
41 #include "engngm.h"
42 #include "classfactory.h"
43 
44 namespace oofem {
46 
48 {
49  ncoords = -1; // means: export as many coordinates as available
50 }
51 
52 
54 { }
55 
56 
59 {
60  IRResultType result; // Required by IR_GIVE_FIELD macro
61 
65 }
66 
67 
68 void
69 GPExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
70 {
71  if ( !testTimeStepOutput(tStep) ) {
72  return;
73  }
74 
75  double weight;
76  FloatArray gcoords, intvar;
77 
78  Domain *d = emodel->giveDomain(1);
79  FILE *stream = this->giveOutputStream(tStep);
80 
81  // print the header
82  fprintf(stream, "%%# gauss point data file\n");
83  fprintf(stream, "%%# output for time %g\n", tStep->giveTargetTime() );
84  fprintf(stream, "%%# variables: ");
85  fprintf(stream, "%d ", vartypes.giveSize());
86  for ( auto &vartype : vartypes ) {
87  fprintf( stream, "%d ", vartype );
88  }
89 
90  fprintf(stream, "\n %%# for interpretation see internalstatetype.h\n");
91 
92  // loop over elements
93  for ( auto &elem : d->giveElements() ) {
94  //iRule = elem->giveDefaultIntegrationRulePtr();
95  //int numIntRules = elem->giveNumberOfIntegrationRules();
96  for ( int i = 0; i < elem->giveNumberOfIntegrationRules(); i++ ) {
97  IntegrationRule *iRule = elem->giveIntegrationRule(i);
98 
99  // loop over Gauss points
100  for ( GaussPoint *gp: *iRule ) {
101  // export:
102  // 1) element number
103  // 2) material number ///@todo deprecated returns -1
104  // 3) Integration rule number
105  // 4) Gauss point number
106  // 5) contributing volume around Gauss point
107  weight = elem->computeVolumeAround(gp);
108  fprintf(stream, "%d %d %d %d %.6e ", elem->giveNumber(), -1, i + 1, gp->giveNumber(), weight);
109 
110  // export Gauss point coordinates
111  if ( ncoords ) { // no coordinates exported if ncoords==0
112  elem->computeGlobalCoordinates( gcoords, gp->giveNaturalCoordinates() );
113  int nc = gcoords.giveSize();
114  if ( ncoords >= 0 ) {
115  fprintf(stream, "%d ", ncoords);
116  } else {
117  fprintf(stream, "%d ", nc);
118  }
119 
120  if ( ncoords > 0 && ncoords < nc ) {
121  nc = ncoords;
122  }
123 
124  for ( auto &c : gcoords ) {
125  fprintf( stream, "%.6e ", c );
126  }
127 
128  for ( int ic = nc + 1; ic <= ncoords; ic++ ) {
129  fprintf(stream, "%g ", 0.0);
130  }
131  }
132 
133  // export internal variables
134  for ( auto vartype : vartypes ) {
135  elem->giveIPValue(intvar, gp, ( InternalStateType )vartype, tStep);
136  fprintf(stream, "%d ", intvar.giveSize());
137  for ( auto &val : intvar ) {
138  fprintf( stream, "%.6e ", val );
139  }
140  }
141 
142  fprintf(stream, "\n");
143  }
144  }
145 
146 #if 0
147  // for CST elements write also nodal coordinates
148  // (non-standard part, used only exceptionally)
149  int nnode = elem->giveNumberOfNodes();
150  if ( nnode == 3 ) {
151  for ( int inod = 1; inod <= 3; inod++ ) {
152  fprintf( stream, "%f %f ", elem->giveNode(inod)->giveCoordinate(1), elem->giveNode(inod)->giveCoordinate(2) );
153  }
154  }
155 #endif
156  }
157 
158  fclose(stream);
159 }
160 
161 void
163 {
165 }
166 
167 
168 void
170 { }
171 
172 
173 FILE *
175 {
176  FILE *answer;
177 
178  std :: string fileName = this->giveOutputBaseFileName(tStep) + ".gp";
179  if ( ( answer = fopen(fileName.c_str(), "w") ) == NULL ) {
180  OOFEM_ERROR("failed to open file %s", fileName.c_str());
181  }
182 
183  return answer;
184 }
185 } // namespace oofem
IntArray vartypes
Identification numbers of variables to be exported.
InternalStateType
Type representing the physical meaning of element or constitutive model internal variable.
bool testTimeStepOutput(TimeStep *tStep)
Tests if given time step output is required.
Definition: exportmodule.C:148
int ncoords
Number of coordinates to be exported (at each Gauss point)
Class and object Domain.
Definition: domain.h:115
FILE * giveOutputStream(TimeStep *tStep)
Returns the output stream for given solution step.
virtual void initialize()
Definition: exportmodule.C:86
double giveTargetTime()
Returns target time.
Definition: timestep.h:146
Represents export output module - a base class for all output modules.
Definition: exportmodule.h:71
virtual void terminate()
Terminates the receiver.
Abstract base class representing integration rule.
virtual ~GPExportModule()
Destructor.
virtual void doOutput(TimeStep *tStep, bool forcedOutput=false)
Writes the output.
#define _IFT_GPExportModule_vartypes
#define OOFEM_ERROR(...)
Definition: error.h:61
EngngModel * emodel
Problem pointer.
Definition: exportmodule.h:77
Class representing vector of real numbers.
Definition: floatarray.h:82
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: exportmodule.C:58
Class representing the general Input Record.
Definition: inputrecord.h:101
virtual void initialize()
Represents GP (Gauss point) export module.
std::vector< std::unique_ptr< Element > > & giveElements()
Definition: domain.h:279
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
int giveSize() const
Definition: intarray.h:203
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
#define _IFT_GPExportModule_ncoords
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
std::string giveOutputBaseFileName(TimeStep *tStep)
Gives the appropriate name (minus specific file extension).
Definition: exportmodule.C:125
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Class representing integration point in finite element program.
Definition: gausspoint.h:93
Class representing solution step.
Definition: timestep.h:80
REGISTER_ExportModule(ErrorCheckingExportModule)

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