OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 - 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 "poiexportmodule.h"
36 #include "timestep.h"
37 #include "domain.h"
38 #include "engngm.h"
40 #include "mmaclosestiptransfer.h"
43 #include "spatiallocalizer.h"
44 #include "internalstatevaluetype.h"
45 #include "element.h"
46 #include "classfactory.h"
47 
48 #include <string>
49 #include <fstream>
50 #include <ios>
51 
52 namespace oofem {
54 
55 POIExportModule :: POIExportModule(int n, EngngModel *e) : ExportModule(n, e), internalVarsToExport(), primaryVarsToExport(), POIList()
56 {
57 }
58 
59 
61 {
62 }
63 
64 
67 {
68  IRResultType result; // Required by IR_GIVE_FIELD macro
69  int val;
70 
73 
74  val = 0;
76  mtype = ( POIEM_MapperType ) val;
77 
78  std :: string poiFileName;
80  this->readPOIFile(poiFileName); // parse poi file
81 
83 }
84 
85 void
86 POIExportModule :: readPOIFile(const std :: string &poiFileName)
87 {
88  POI_dataType poi;
89  int nPOI;
90  // Open the file;
91  std :: ifstream file(poiFileName.c_str(), std :: ios :: in);
92  if ( !file.is_open() ) {
93  OOFEM_ERROR("Failed to open time data file: %s\n", poiFileName.c_str() );
94  }
95 
96  file >> nPOI; // Not actually needed.
97 
98  while ( file >> poi.id >> poi.x >> poi.y >> poi.z >> poi.region ) {
99  POIList.push_back(poi);
100  }
101 }
102 
103 
104 void
105 POIExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
106 {
107  if ( !( testTimeStepOutput(tStep) || forcedOutput ) ) {
108  return;
109  }
110 
111  FILE *stream = this->giveOutputStream(tStep);
112 
113  fprintf(stream, "# POI DataFile\n");
114  fprintf( stream, "Output for time %f\n", tStep->giveTargetTime() );
115 
116  this->exportPrimaryVars(stream, tStep);
117  this->exportIntVars(stream, tStep);
118 
119  fclose(stream);
120 }
121 
122 void
124 {
126 }
127 
128 
129 void
131 { }
132 
133 
134 FILE *
136 {
137  FILE *answer;
138  std :: string fileName = this->giveOutputBaseFileName(tStep) + ".poi";
139 
140  if ( ( answer = fopen(fileName.c_str(), "w") ) == NULL ) {
141  OOFEM_ERROR("failed to open file %s", fileName.c_str() );
142  }
143 
144  return answer;
145 }
146 
147 void
149 {
150  int i, n = internalVarsToExport.giveSize();
151  InternalStateType type;
152  FloatArray poiCoords(3);
153 
154  if ( n == 0 ) {
155  return;
156  }
157 
158  // loop over POIs
159  POI_dataType &poi = *POIList.begin();
160  poiCoords.at(1) = poi.x;
161  poiCoords.at(2) = poi.y;
162  poiCoords.at(3) = poi.z;
163  //int region = poi.region;
164 
165  for ( i = 1; i <= n; i++ ) {
167  fprintf(stream, "\n\nPOI_INTVAR_DATA %d\n", type);
168  this->exportIntVarAs(type, stream, tStep);
169  }
170 
171  this->giveMapper()->finish(tStep);
172 }
173 
174 
175 void
177 {
178  int region;
179  IntArray toMap(1);
180  Domain *d = emodel->giveDomain(1);
181  FloatArray poiCoords(3);
182  FloatArray val;
183 
184  toMap.at(1) = ( int ) valID;
185 
186  // loop over POIs
187  for ( auto &poi: POIList ) {
188  poiCoords.at(1) = poi.x;
189  poiCoords.at(2) = poi.y;
190  poiCoords.at(3) = poi.z;
191  region = poi.region;
192 
193  this->giveMapper()->__init(d, toMap, poiCoords, * d->giveSet(region), tStep);
194  if ( !this->giveMapper()->__mapVariable(val, poiCoords, valID, tStep) ) {
195  OOFEM_WARNING("Failed to map variable");
196  val.clear();
197  }
198  fprintf(stream, "%10d ", poi.id);
199  for ( auto &x : val ) {
200  fprintf( stream, " %15e", x );
201  }
202 
203  fprintf(stream, "\n");
204  }
205 }
206 
207 
210 {
211  if ( !this->mapper ) {
212  if ( this->mtype == POI_CPT ) {
213  this->mapper.reset( new MMAClosestIPTransfer() );
214  } else if ( this->mtype == POI_SFT ) {
215  this->mapper.reset( new MMAShapeFunctProjection() );
216  } else if ( this->mtype == POI_LST ) {
217  this->mapper.reset( new MMALeastSquareProjection() );
218  } else {
219  OOFEM_ERROR("unsupported smoother type ID");
220  }
221  }
222 
223  return this->mapper.get();
224 }
225 
226 
227 void
229 {
230  // should be performed over regions
231 
232  int n = primaryVarsToExport.giveSize();
233  Domain *d = emodel->giveDomain(1);
234 
235  if ( n == 0 ) {
236  return;
237  }
238 
239  fprintf(stream, "\n\nPOINT_DATA %d\n", d->giveNumberOfDofManagers());
240 
241  for ( int i = 1; i <= n; i++ ) {
243  this->exportPrimVarAs(type, stream, tStep);
244  }
245 }
246 
247 
248 void
250 {
251  Domain *d = emodel->giveDomain(1);
252  FloatArray pv, coords(3), lcoords, closest;
254 
255  if ( valID == DisplacementVector ) {
256  type = ISVT_VECTOR;
257  } else if ( valID == FluxVector || valID == Humidity ) {
258  type = ISVT_SCALAR;
259  } else {
260  OOFEM_ERROR("unsupported UnknownType");
261  }
262 
263  // print header
264  if ( type == ISVT_SCALAR ) {
265  fprintf(stream, "SCALARS prim_scalar_%d\n", ( int ) valID);
266  } else if ( type == ISVT_VECTOR ) {
267  fprintf(stream, "VECTORS vector_%d float\n", ( int ) valID);
268  } else {
269  OOFEM_ERROR("unsupported variable type");
270  }
271 
272 
274  // loop over POIs
275  for ( auto &poi: POIList ) {
276  coords.at(1) = poi.x;
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 _IFT_POIExportModule_poifilename
The base class for all spatial localizers.
InternalStateType
Type representing the physical meaning of element or constitutive model internal variable.
The class implements the transfer of state variables based on Least square fit over old mesh integrat...
bool testTimeStepOutput(TimeStep *tStep)
Tests if given time step output is required.
Definition: exportmodule.C:148
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Class and object Domain.
Definition: domain.h:115
The class implements the closest integration point transfer of state variables.
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition: domain.h:432
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
POIEM_MapperType
Smoother type.
void clear()
Clears receiver (zero size).
Definition: floatarray.h:206
void exportPrimVarAs(UnknownType valID, FILE *stream, TimeStep *tStep)
Exports single variable.
void exportPrimaryVars(FILE *stream, TimeStep *tStep)
Export primary variables.
virtual void initialize()
Definition: exportmodule.C:86
double giveTargetTime()
Returns target time.
Definition: timestep.h:146
Abstract base class for all finite elements.
Definition: element.h:145
InternalStateValueType
Determines the type of internal variable.
The class representing the general material model mapping algorithm.
Represents export output module - a base class for all output modules.
Definition: exportmodule.h:71
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
virtual void terminate()
Terminates the receiver.
void exportIntVarAs(InternalStateType valID, FILE *stream, TimeStep *tStep)
Exports single variable.
enum oofem::POIExportModule::POIEM_MapperType mtype
virtual void initialize()
virtual ~POIExportModule()
Destructor.
#define OOFEM_ERROR(...)
Definition: error.h:61
#define _IFT_POIExportModule_mtype
EngngModel * emodel
Problem pointer.
Definition: exportmodule.h:77
UnknownType
Type representing particular unknown (its physical meaning).
Definition: unknowntype.h:55
SpatialLocalizer * giveSpatialLocalizer()
Returns receiver&#39;s associated spatial localizer.
Definition: domain.C:1184
virtual int __mapVariable(FloatArray &answer, const FloatArray &coords, InternalStateType type, TimeStep *tStep)=0
Maps and update the unknown of given type from old mesh oldd to new mesh to which gp belongs to...
std::unique_ptr< MaterialMappingAlgorithm > mapper
Mapper.
Represents POI (Point Of Interest) export module.
Set * giveSet(int n)
Service for accessing particular domain set.
Definition: domain.C:363
FILE * giveOutputStream(TimeStep *tStep)
Returns the output stream for given solution step.
std::list< POI_dataType > POIList
List of POIs.
void exportIntVars(FILE *stream, TimeStep *tStep)
Export internal variables.
virtual void doOutput(TimeStep *tStep, bool forcedOutput=false)
Writes the output.
Class representing vector of real numbers.
Definition: floatarray.h:82
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
The class implements the transfer of state variables based on projection using shape functions...
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: exportmodule.C:58
virtual Element * giveElementClosestToPoint(FloatArray &lcoords, FloatArray &closest, const FloatArray &coords, int region=0)=0
Returns the element closest to a given point.
Class representing the general Input Record.
Definition: inputrecord.h:101
MaterialMappingAlgorithm * giveMapper()
void readPOIFile(const std::string &poiFileName)
#define _IFT_POIExportModule_vars
IntArray internalVarsToExport
List of InternalStateType values, identifying the selected vars for export.
IntArray primaryVarsToExport
List of primary unknowns to export.
virtual void __init(Domain *dold, IntArray &varTypes, const FloatArray &coords, Set &sourceElemSet, TimeStep *tStep, bool iCohesiveZoneGP=false)=0
Initializes the receiver state before mapping.
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
virtual void finish(TimeStep *tStep)=0
Finishes the mapping for given time step.
#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
#define _IFT_POIExportModule_primvars
virtual void computeField(ValueModeType mode, TimeStep *tStep, const FloatArray &lcoords, FloatArray &answer)
Computes the unknown vector interpolated at the specified local coordinates.
Definition: element.h:508
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
std::string giveOutputBaseFileName(TimeStep *tStep)
Gives the appropriate name (minus specific file extension).
Definition: exportmodule.C:125
#define OOFEM_WARNING(...)
Definition: error.h:62
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:30 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011