OOFEM 3.0
Loading...
Searching...
No Matches
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 - 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 "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
44namespace oofem {
46
47GPExportModule :: GPExportModule(int n, EngngModel *e) : ExportModule(n, e)
48{
49 ncoords = -1; // means: export as many coordinates as available
50}
51
52
53GPExportModule :: ~GPExportModule()
54{ }
55
56
57void
58GPExportModule :: initializeFrom(InputRecord &ir)
59{
60 ExportModule :: initializeFrom(ir);
63}
64
65
66void
67GPExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
68{
69 if ( !testTimeStepOutput(tStep) ) {
70 return;
71 }
72
73 double weight;
74 FloatArray gcoords, intvar;
75
76 Domain *d = emodel->giveDomain(1);
77 FILE *stream = this->giveOutputStream(tStep);
78
79 // print the header
80 fprintf(stream, "%%# gauss point data file\n");
81 fprintf(stream, "%%# output for time %g\n", tStep->giveTargetTime() );
82 fprintf(stream, "%%# variables: ");
83 fprintf(stream, "%d ", vartypes.giveSize());
84 for ( auto &vartype : vartypes ) {
85 fprintf( stream, "%d ", vartype );
86 }
87
88 fprintf(stream, "\n %%# for interpretation see internalstatetype.h\n");
89
90 elements.resize(0);
91 for ( int ireg = 1; ireg <= this->giveNumberOfRegions(); ireg++ ) {
92 elements.followedBy(this->giveRegionSet(ireg)->giveElementList());
93 }
94
95 // loop over elements
96 for ( auto &elem : d->giveElements() ) {
97 if ( elements.contains(elem -> giveNumber()) ){
98
99 //iRule = elem->giveDefaultIntegrationRulePtr();
100 //int numIntRules = elem->giveNumberOfIntegrationRules();
101 for ( int i = 0; i < elem->giveNumberOfIntegrationRules(); i++ ) {
102 IntegrationRule *iRule = elem->giveIntegrationRule(i);
103
104 // loop over Gauss points
105 for ( GaussPoint *gp: *iRule ) {
106 // export:
107 // 1) element number
108 // 2) material number ///@todo deprecated returns -1
109 // 3) Integration rule number
110 // 4) Gauss point number
111 // 5) contributing volume around Gauss point
112 weight = elem->computeVolumeAround(gp);
113 fprintf(stream, "%d %d %d %d %.6e ", elem->giveNumber(), -1, i + 1, gp->giveNumber(), weight);
114
115 // export Gauss point coordinates
116 if ( ncoords ) { // no coordinates exported if ncoords==0
117 elem->computeGlobalCoordinates( gcoords, gp->giveNaturalCoordinates() );
118 int nc = gcoords.giveSize();
119 if ( ncoords >= 0 ) {
120 fprintf(stream, "%d ", ncoords);
121 } else {
122 fprintf(stream, "%d ", nc);
123 }
124
125 if ( ncoords > 0 && ncoords < nc ) {
126 nc = ncoords;
127 }
128
129 for ( auto &c : gcoords ) {
130 fprintf( stream, "%.6e ", c );
131 }
132
133 for ( int ic = nc + 1; ic <= ncoords; ic++ ) {
134 fprintf(stream, "%g ", 0.0);
135 }
136 }
137
138 // export internal variables
139 for ( auto vartype : vartypes ) {
140 elem->giveIPValue(intvar, gp, ( InternalStateType )vartype, tStep);
141 fprintf(stream, "%d ", (int)intvar.giveSize());
142 for ( auto &val : intvar ) {
143 fprintf( stream, "%.6e ", val );
144 }
145 }
146
147 fprintf(stream, "\n");
148 }
149 }
150
151 #if 0
152 // for CST elements write also nodal coordinates
153 // (non-standard part, used only exceptionally)
154 int nnode = elem->giveNumberOfNodes();
155 if ( nnode == 3 ) {
156 for ( int inod = 1; inod <= 3; inod++ ) {
157 fprintf( stream, "%f %f ", elem->giveNode(inod)->giveCoordinate(1), elem->giveNode(inod)->giveCoordinate(2) );
158 }
159 }
160#endif
161 }
162 }
163 fclose(stream);
164}
165
166void
167GPExportModule :: initialize()
168{
169 ExportModule :: initialize();
170}
171
172
173void
174GPExportModule :: terminate()
175{ }
176
177
178FILE *
179GPExportModule :: giveOutputStream(TimeStep *tStep)
180{
181 FILE *answer;
182
183 std :: string fileName = this->giveOutputBaseFileName(tStep) + ".gp";
184 if ( ( answer = fopen(fileName.c_str(), "w") ) == NULL ) {
185 OOFEM_ERROR("failed to open file %s", fileName.c_str());
186 }
187
188 return answer;
189}
190} // namespace oofem
#define REGISTER_ExportModule(class)
std ::vector< std ::unique_ptr< Element > > & giveElements()
Definition domain.h:294
std::string giveOutputBaseFileName(TimeStep *tStep)
Set * giveRegionSet(int i)
Returns element set.
int giveNumberOfRegions()
Returns number of regions (aka regionSets).
EngngModel * emodel
Problem pointer.
bool testTimeStepOutput(TimeStep *tStep)
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
FILE * giveOutputStream(TimeStep *tStep)
Returns the output stream for given solution step.
IntArray elements
List of elements.
IntArray vartypes
Identification numbers of variables to be exported.
int ncoords
Number of coordinates to be exported (at each Gauss point).
double giveTargetTime()
Returns target time.
Definition timestep.h:164
#define OOFEM_ERROR(...)
Definition error.h:79
#define _IFT_GPExportModule_ncoords
#define _IFT_GPExportModule_vartypes
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
#define IR_GIVE_FIELD(__ir, __value, __id)
Definition inputrecord.h:67

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