OOFEM 3.0
Loading...
Searching...
No Matches
poiexportmodule.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 "poiexportmodule.h"
36#include "timestep.h"
37#include "domain.h"
38#include "engngm.h"
43#include "spatiallocalizer.h"
45#include "element.h"
46#include "classfactory.h"
47
48#include <string>
49#include <fstream>
50#include <ios>
51
52namespace oofem {
54
55POIExportModule :: POIExportModule(int n, EngngModel *e) : ExportModule(n, e), internalVarsToExport(), primaryVarsToExport(), POIList()
56{
57}
58
59
60POIExportModule :: ~POIExportModule()
61{
62}
63
64
65void
66POIExportModule :: initializeFrom(InputRecord &ir)
67{
68 ExportModule :: initializeFrom(ir);
69
70 int val;
71
74
75 val = 0;
77 mtype = ( POIEM_MapperType ) val;
78
79 std :: string poiFileName;
81 this->readPOIFile(poiFileName); // parse poi file
82}
83
84void
85POIExportModule :: readPOIFile(const std :: string &poiFileName)
86{
87 POI_dataType poi;
88 int nPOI;
89 // Open the file;
90 std :: ifstream file(poiFileName.c_str(), std :: ios :: in);
91 if ( !file.is_open() ) {
92 OOFEM_ERROR("Failed to open POI data file: %s\n. Did you specify poifilename?", poiFileName.c_str() );
93 }
94
95 file >> nPOI; // Not actually needed.
96
97 while ( file >> poi.id >> poi.x >> poi.y >> poi.z >> poi.region ) {
98 POIList.push_back(poi);
99 }
100}
101
102
103void
104POIExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
105{
106 if ( !( testTimeStepOutput(tStep) || forcedOutput ) ) {
107 return;
108 }
109
110 FILE *stream = this->giveOutputStream(tStep);
111
112 fprintf(stream, "# POI DataFile\n");
113 fprintf( stream, "Output for time %f\n", tStep->giveTargetTime() );
114
115 this->exportPrimaryVars(stream, tStep);
116 this->exportIntVars(stream, tStep);
117
118 fclose(stream);
119}
120
121void
122POIExportModule :: initialize()
123{
124 ExportModule :: initialize();
125}
126
127
128void
129POIExportModule :: terminate()
130{ }
131
132
133FILE *
134POIExportModule :: giveOutputStream(TimeStep *tStep)
135{
136 FILE *answer;
137 std :: string fileName = this->giveOutputBaseFileName(tStep) + ".poi";
138
139 if ( ( answer = fopen(fileName.c_str(), "w") ) == NULL ) {
140 OOFEM_ERROR("failed to open file %s", fileName.c_str() );
141 }
142
143 return answer;
144}
145
146void
147POIExportModule :: exportIntVars(FILE *stream, TimeStep *tStep)
148{
149 int i, n = internalVarsToExport.giveSize();
151 FloatArray poiCoords(3);
152
153 if ( n == 0 ) {
154 return;
155 }
156
157 // loop over POIs
158 POI_dataType &poi = *POIList.begin();
159 poiCoords.at(1) = poi.x;
160 poiCoords.at(2) = poi.y;
161 poiCoords.at(3) = poi.z;
162 //int region = poi.region;
163
164 for ( i = 1; i <= n; i++ ) {
166 fprintf(stream, "\n\nPOI_INTVAR_DATA %d\n", type);
167 this->exportIntVarAs(type, stream, tStep);
168 }
169
170 this->giveMapper()->finish(tStep);
171}
172
173
174void
175POIExportModule :: exportIntVarAs(InternalStateType valID, FILE *stream, TimeStep *tStep)
176{
177 int region;
178 IntArray toMap(1);
179 Domain *d = emodel->giveDomain(1);
180 FloatArray poiCoords(3);
181 FloatArray val;
182
183 toMap.at(1) = ( int ) valID;
184
185 // loop over POIs
186 for ( auto &poi: POIList ) {
187 poiCoords.at(1) = poi.x;
188 poiCoords.at(2) = poi.y;
189 poiCoords.at(3) = poi.z;
190 region = poi.region;
191
192 this->giveMapper()->__init(d, toMap, poiCoords, * d->giveSet(region), tStep);
193 if ( !this->giveMapper()->__mapVariable(val, poiCoords, valID, tStep) ) {
194 OOFEM_WARNING("Failed to map variable");
195 val.clear();
196 }
197 fprintf(stream, "%10d ", poi.id);
198 for ( auto &x : val ) {
199 fprintf( stream, " %15e", x );
200 }
201
202 fprintf(stream, "\n");
203 }
204}
205
206
208POIExportModule :: giveMapper()
209{
210 if ( !this->mapper ) {
211 if ( this->mtype == POI_CPT ) {
212 this->mapper = std::make_unique<MMAClosestIPTransfer>();
213 } else if ( this->mtype == POI_SFT ) {
214 this->mapper = std::make_unique<MMAShapeFunctProjection>();
215 } else if ( this->mtype == POI_LST ) {
216 this->mapper = std::make_unique<MMALeastSquareProjection>();
217 } else {
218 OOFEM_ERROR("unsupported smoother type ID");
219 }
220 }
221
222 return this->mapper.get();
223}
224
225
226void
227POIExportModule :: exportPrimaryVars(FILE *stream, TimeStep *tStep)
228{
229 // should be performed over regions
230
231 int n = primaryVarsToExport.giveSize();
232 Domain *d = emodel->giveDomain(1);
233
234 if ( n == 0 ) {
235 return;
236 }
237
238 fprintf(stream, "\n\nPOINT_DATA %d\n", d->giveNumberOfDofManagers());
239
240 for ( int i = 1; i <= n; i++ ) {
242 this->exportPrimVarAs(type, stream, tStep);
243 }
244}
245
246
247void
248POIExportModule :: exportPrimVarAs(UnknownType valID, FILE *stream, TimeStep *tStep)
249{
250 Domain *d = emodel->giveDomain(1);
251 FloatArray pv, coords(3), lcoords, closest;
253
254 if ( valID == DisplacementVector ) {
255 type = ISVT_VECTOR;
256 } else if ( valID == FluxVector || valID == Humidity ) {
257 type = ISVT_SCALAR;
258 } else {
259 OOFEM_ERROR("unsupported UnknownType");
260 }
261
262 // print header
263 if ( type == ISVT_SCALAR ) {
264 fprintf(stream, "SCALARS prim_scalar_%d\n", ( int ) valID);
265 } else if ( type == ISVT_VECTOR ) {
266 fprintf(stream, "VECTORS vector_%d float\n", ( int ) valID);
267 } else {
268 OOFEM_ERROR("unsupported variable type");
269 }
270
271
273 // loop over POIs
274 for ( auto &poi: POIList ) {
275 coords.at(1) = poi.x;
276 coords.at(2) = poi.y;
277 coords.at(3) = poi.z;
278 //region = poi.region;
279
280 Element *source = sl->giveElementClosestToPoint(lcoords, closest, coords);
281 if ( source ) {
282 // ask interface
283 source->computeField(VM_Total, tStep, lcoords, pv);
284
285 fprintf(stream, "%10d ", poi.id);
286 for ( auto &p : pv ) {
287 fprintf( stream, " %15e ", p );
288 }
289
290 fprintf(stream, "\n");
291 } else {
292 OOFEM_ERROR("no element containing POI(%e,%e,%e) found",
293 coords.at(1), coords.at(2), coords.at(3) );
294 }
295 }
296}
297} // end namespace oofem
#define REGISTER_ExportModule(class)
SpatialLocalizer * giveSpatialLocalizer()
Definition domain.C:1255
Set * giveSet(int n)
Definition domain.C:366
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition domain.h:461
virtual void computeField(ValueModeType mode, TimeStep *tStep, const FloatArray &lcoords, FloatArray &answer)
Definition element.h:520
std::string giveOutputBaseFileName(TimeStep *tStep)
EngngModel * emodel
Problem pointer.
bool testTimeStepOutput(TimeStep *tStep)
double & at(Index i)
Definition floatarray.h:202
int & at(std::size_t i)
Definition intarray.h:104
void exportIntVars(FILE *stream, TimeStep *tStep)
MaterialMappingAlgorithm * giveMapper()
void exportPrimVarAs(UnknownType valID, FILE *stream, TimeStep *tStep)
void exportIntVarAs(InternalStateType valID, FILE *stream, TimeStep *tStep)
std ::unique_ptr< MaterialMappingAlgorithm > mapper
Mapper.
enum oofem::POIExportModule::POIEM_MapperType mtype
void exportPrimaryVars(FILE *stream, TimeStep *tStep)
IntArray primaryVarsToExport
List of primary unknowns to export.
POIEM_MapperType
Smoother type.
IntArray internalVarsToExport
List of InternalStateType values, identifying the selected vars for export.
void readPOIFile(const std ::string &poiFileName)
std ::list< POI_dataType > POIList
List of POIs.
FILE * giveOutputStream(TimeStep *tStep)
Returns the output stream for given solution step.
virtual Element * giveElementClosestToPoint(FloatArray &lcoords, FloatArray &closest, const FloatArray &coords, int region=0)=0
double giveTargetTime()
Returns target time.
Definition timestep.h:164
#define OOFEM_WARNING(...)
Definition error.h:80
#define OOFEM_ERROR(...)
Definition error.h:79
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
InternalStateValueType
Determines the type of internal variable.
@ ISVT_SCALAR
Scalar.
@ ISVT_UNDEFINED
Undefined.
@ ISVT_VECTOR
Vector.
#define _IFT_POIExportModule_vars
#define _IFT_POIExportModule_mtype
#define _IFT_POIExportModule_primvars
#define _IFT_POIExportModule_poifilename

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