Memosa-FVM  0.2
FluentDataExporter.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _FLUENTDATAEXPORTER_H_
6 #define _FLUENTDATAEXPORTER_H_
7 
8 #include "atype.h"
9 
10 #include "FluentReader.h"
11 #include "ArrayWriter.h"
12 
13 template<class T>
15 {
16 public:
17  typedef Array<T> TArray;
18 
20  const string fileName,
21  const bool binary,
22  const int atypeComponent) :
23  _reader(reader),
24  _fp(fopen(fileName.c_str(),"wb")),
25  _binary(binary),
26  _atypeComponent(atypeComponent),
27  _sectionID(_binary ? 3300 : 300)
28  {
29  if (!_fp)
30  throw CException("FluentDataExporter: cannot open file " + fileName +
31  "for writing");
32  }
33 
34  void init()
35  {
36  fprintf(_fp,"(4 (60 0 0 1 2 4 4 4 8 8 4))\n");
37  }
38 
39  void closeSection()
40  {
41  if (_binary)
42  fprintf(_fp,"\nEnd of Binary Section 3300");
43  fprintf(_fp,"))\n");
44  }
45 
46  void writeScalarField(const Field& field,
47  const int fluentFieldId)
48  {
49  FaceZonesMap& faceZones = _reader.getFaceZones();
50  CellZonesMap& cellZones = _reader.getCellZones();
51 
53 
54  foreach(const CellZonesMap::value_type& pos, cellZones)
55  {
56  const FluentCellZone& cz = *pos.second;
57  const Mesh& mesh = *cz.mesh;
58 
59  const StorageSite& cells = mesh.getCells();
60  const StorageSite& faces = mesh.getFaces();
61 
62  if (field.hasArray(cells))
63  {
64  const TArray& aCell = dynamic_cast<const TArray&>(field[cells]);
65  fprintf(_fp,"(%d (%d %d 1 0 1 %d %d)\n(",
66  _sectionID, fluentFieldId, cz.ID,
67  cz.iBeg+1,cz.iEnd+1);
68  writer.write(_fp,aCell,0,cells.getSelfCount());
69  closeSection();
70 
71  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
72  {
73  const FaceGroup& fg = *fgPtr;
74  const StorageSite& faces = fg.site;
75 
76  const FluentFaceZone& fz = *faceZones[fg.id];
77  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
78 
79  fprintf(_fp,"(%d (%d %d 1 0 1 %d %d)\n(",
80  _sectionID, fluentFieldId, fz.ID,
81  fz.iBeg+1,fz.iEnd+1);
82 
83  int cbeg = faceCells(0,1);
84 
85  writer.write(_fp,aCell,cbeg,faces.getSelfCount());
86  closeSection();
87  }
88  }
89  if (field.hasArray(faces))
90  {
91  const TArray& aFaces = dynamic_cast<const TArray&>(field[faces]);
92 
93  int faceOffset =0;
94  foreach(int fzId, cz.interiorZoneIds)
95  {
96  const FluentFaceZone& fz = *faceZones[fzId];
97  const int count = fz.iEnd-fz.iBeg+1;
98  fprintf(_fp,"(%d (%d %d 1 0 1 %d %d)\n(",
99  _sectionID, fluentFieldId, fz.ID,
100  fz.iBeg+1,fz.iEnd+1);
101  writer.write(_fp,aFaces,faceOffset,count);
102  closeSection();
103  faceOffset += count;
104  }
105 
106  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
107  {
108  const FaceGroup& fg = *fgPtr;
109  const StorageSite& faces = fg.site;
110 
111  const FluentFaceZone& fz = *faceZones[fg.id];
112 
113  fprintf(_fp,"(%d (%d %d 1 0 1 %d %d)\n(",
114  _sectionID, fluentFieldId, fz.ID,
115  fz.iBeg+1,fz.iEnd+1);
116 
117  writer.write(_fp,aFaces,faces.getOffset(),faces.getSelfCount());
118  closeSection();
119  }
120  }
121 
122  }
123  }
124 
125  void writeVectorField(const Field& field,const int fluentFieldId)
126  {
127 
129 
130  FaceZonesMap& faceZones = _reader.getFaceZones();
131  CellZonesMap& cellZones = _reader.getCellZones();
132 
133  for(int nd=0; nd<3; nd++)
134  {
136 
137  foreach(const CellZonesMap::value_type& pos, cellZones)
138  {
139  const FluentCellZone& cz = *pos.second;
140  const Mesh& mesh = *cz.mesh;
141 
142  const StorageSite& cells = mesh.getCells();
143 
144  if (field.hasArray(cells))
145  {
146  const VectorT3Array& aCell = dynamic_cast<const VectorT3Array&>(field[cells]);
147 
148  fprintf(_fp,"(%d (%d %d 1 0 1 %d %d)\n(",
149  _sectionID, fluentFieldId+nd, cz.ID,
150  cz.iBeg+1,cz.iEnd+1);
151  writer.write(_fp,aCell,0,cells.getSelfCount());
152  closeSection();
153 
154  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
155  {
156  const FaceGroup& fg = *fgPtr;
157  const StorageSite& faces = fg.site;
158 
159  const FluentFaceZone& fz = *faceZones[fg.id];
160  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
161 
162  fprintf(_fp,"(%d (%d %d 1 0 1 %d %d)\n(",
163  _sectionID, fluentFieldId+nd, fz.ID,
164  fz.iBeg+1,fz.iEnd+1);
165 
166  int cbeg = faceCells(0,1);
167 
168  writer.write(_fp,aCell,cbeg,faces.getSelfCount());
169  closeSection();
170  }
171  }
172  }
173  }
174 
175  }
176 
177  void finish()
178  {
179  fclose(_fp);
180  }
181 
182 private:
184  FILE *_fp;
185  const bool _binary;
186  const int _atypeComponent;
187  const int _sectionID;
188 };
189 #endif
const FaceGroupList & getBoundaryFaceGroups() const
Definition: Mesh.h:187
virtual void write(FILE *fp, const ArrayType &array, const int iBeg, int count, const Array< bool > *mask=0)
Definition: ArrayWriter.h:105
shared_ptr< FaceGroup > FaceGroupPtr
Definition: Mesh.h:46
int getSelfCount() const
Definition: StorageSite.h:40
bool hasArray(const StorageSite &s) const
Definition: Field.cpp:37
Definition: Mesh.h:28
void writeVectorField(const Field &field, const int fluentFieldId)
void writeScalarField(const Field &field, const int fluentFieldId)
map< int, FluentFaceZone * > FaceZonesMap
Definition: FluentReader.h:70
Definition: Field.h:14
void write(FILE *fp, const Array< T > &array, const int iBeg, int count, const Array< bool > *mask=0)
Definition: ArrayWriter.h:60
Definition: Mesh.h:49
Array< Vector< double, 3 > > VectorT3Array
Definition: CellMark.cpp:7
FaceZonesMap & getFaceZones()
Definition: FluentReader.h:95
const int id
Definition: Mesh.h:41
map< int, FluentCellZone * > CellZonesMap
Definition: FluentReader.h:71
CellZonesMap & getCellZones()
Definition: FluentReader.h:96
const StorageSite & getFaces() const
Definition: Mesh.h:108
const StorageSite & getCells() const
Definition: Mesh.h:109
FluentReader & _reader
const CRConnectivity & getFaceCells(const StorageSite &site) const
Definition: Mesh.cpp:388
Definition: Array.h:14
int getOffset() const
Definition: StorageSite.h:87
vector< int > interiorZoneIds
Definition: FluentReader.h:41
FluentDataExporter(FluentReader &reader, const string fileName, const bool binary, const int atypeComponent)
StorageSite site
Definition: Mesh.h:40