Nektar++
FieldIO.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File FieldIO.h
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Field IO prototype definitions
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_FIELDIO_H
37 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_FIELDIO_H
38 
45 #include <tinyxml.h>
46 
47 // These are required for the Write(...) and Import(...) functions.
48 #include <boost/archive/iterators/base64_from_binary.hpp>
49 #include <boost/archive/iterators/binary_from_base64.hpp>
50 #include <boost/archive/iterators/transform_width.hpp>
51 #include <boost/iostreams/copy.hpp>
52 #include <boost/iostreams/filter/zlib.hpp>
53 #include <boost/iostreams/filtering_stream.hpp>
54 #include <boost/assign/list_of.hpp>
55 
56 namespace Nektar
57 {
58  namespace LibUtilities
59  {
60 
61  static std::vector<NekDouble> NullNekDoubleVector;
62  static std::vector<LibUtilities::PointsType> NullPointsTypeVector;
63  static std::vector<unsigned int> NullUnsignedIntVector;
64 
65  typedef std::map<std::string, std::string> FieldMetaDataMap;
66  static FieldMetaDataMap NullFieldMetaDataMap;
67  static std::vector<std::vector< NekDouble> > NullVectorNekDoubleVector = boost::assign::list_of(NullNekDoubleVector);
68 
70  {
72  const std::vector<unsigned int> &elementIDs,// vector[2]
73  const std::vector<LibUtilities::BasisType> &basis,
74  bool uniOrder,
75  // UniOrder = vector[dimension] - MixOrder
76  // = vector[element*dimension]
77  const std::vector<unsigned int> &numModes,
78  const std::vector<std::string> &fields,
79  int NumHomoDir = 0,
80  const std::vector<NekDouble> &HomoLengths =
81  NullNekDoubleVector,
82  const std::vector<unsigned int> &HomoZIDs =
83  NullUnsignedIntVector,
84  const std::vector<unsigned int> &HomoYIDs =
85  NullUnsignedIntVector,
86  const std::vector<LibUtilities::PointsType> &points =
87  NullPointsTypeVector,
88  bool pointsDef = false,
89  const std::vector<unsigned int> &numPoints =
90  NullUnsignedIntVector,
91  bool numPointsDef = false):
92  m_shapeType(shapeType),
93  m_elementIDs(elementIDs),
94  m_basis(basis),
95  m_numHomogeneousDir(NumHomoDir),
96  m_homogeneousLengths(HomoLengths),
97  m_homogeneousZIDs(HomoZIDs),
98  m_homogeneousYIDs(HomoYIDs),
99  m_points(points),
100  m_pointsDef(pointsDef),
101  m_uniOrder(uniOrder),
102  m_numModes(numModes),
103  m_numPoints(numPoints),
104  m_numPointsDef(numPointsDef),
105  m_fields(fields)
106  {
107  }
108 
110  std::vector<unsigned int> m_elementIDs;
111  std::vector<LibUtilities::BasisType> m_basis;
113  std::vector<NekDouble> m_homogeneousLengths;
114  std::vector<unsigned int> m_homogeneousZIDs;
115  std::vector<unsigned int> m_homogeneousYIDs;
116 
117  /// Define the type of points per direction.
118  std::vector<LibUtilities::PointsType> m_points;
120  /// Define order of the element group.
121  /// * UniOrder: same order for each element
122  /// * MixOrder: definition of a different order for each element.
124  /// Define number of modes per direction.
125  std::vector<unsigned int> m_numModes;
126  std::vector<unsigned int> m_numPoints;
128  std::vector<std::string> m_fields;
129  };
130 
131  typedef boost::shared_ptr<FieldDefinitions> FieldDefinitionsSharedPtr;
132 
133 
134  /// Write a field file in serial only
136  const std::string &outFile,
137  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
138  std::vector<std::vector<NekDouble> > &fielddata,
139  const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
140 
141  /// Imports an FLD file
143  const std::string& infilename,
144  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
145  std::vector<std::vector<NekDouble> > &fielddata = NullVectorNekDoubleVector,
146  FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
147  const Array<OneD, int> ElementiDs = NullInt1DArray);
148 
149 
150  /// Class for operating on FLD files
151  class FieldIO
152  {
153  public:
154  /// Constructor
157 
158  /// Write data in FLD format
160  const std::string &outFile,
161  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
162  std::vector<std::vector<NekDouble> > &fielddata,
163  const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
164 
165  /// Imports an FLD file.
167  const std::string& infilename,
168  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
169  std::vector<std::vector<NekDouble> > &fielddata = NullVectorNekDoubleVector,
170  FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
171  const Array<OneD, int> ElementiDs = NullInt1DArray);
172 
173  /// Imports the definition of the meta data
175  std::string filename,
176  FieldMetaDataMap &fieldmetadatamap);
177 
178  /// Imports the definition of the meta data
180  TiXmlDocument &doc,
181  FieldMetaDataMap &fieldmetadatamap);
182 
183  /// Imports the definition of the fields.
185  TiXmlDocument &doc,
186  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
187  bool expChild);
188 
189  /// Imports the data fileds.
191  TiXmlDocument &doc,
192  const std::vector<FieldDefinitionsSharedPtr> &fielddefs,
193  std::vector<std::vector<NekDouble> > &fielddata);
194 
196  const std::string &outfile,
197  const std::vector<std::string> fileNames,
198  std::vector<std::vector<unsigned int> > &elementList,
199  const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
200 
201 
202  private:
203  /// Communicator to use when writing parallel format
205 
207  TiXmlElement * root,
208  const FieldMetaDataMap &fieldmetadatamap);
209 
211  const std::vector<unsigned int> &elmtids,
212  std::string &idString);
213 
214  LIB_UTILITIES_EXPORT std::string SetUpOutput(
215  const std::string outname,
216  const std::vector<FieldDefinitionsSharedPtr> &fielddefs,
217  const FieldMetaDataMap &fieldmetadatamap);
218 
220  const std::string &inFile,
221  std::vector<std::string> &fileNames,
222  std::vector<std::vector<unsigned int> > &elementList,
223  FieldMetaDataMap &fieldmetadatamap);
224 
226  const FieldDefinitionsSharedPtr &fielddefs);
227 
229  std::vector<NekDouble>& in,
230  string& out);
231 
232  LIB_UTILITIES_EXPORT int Inflate(string& in,
233  std::vector<NekDouble>& out);
234  };
235 
236  typedef boost::shared_ptr<FieldIO> FieldIOSharedPtr;
237  }
238 }
239 #endif
std::vector< unsigned int > m_numPoints
Definition: FieldIO.h:126
void ImportFieldDefs(TiXmlDocument &doc, std::vector< FieldDefinitionsSharedPtr > &fielddefs, bool expChild)
Imports the definition of the fields.
Definition: FieldIO.cpp:700
std::vector< unsigned int > m_homogeneousYIDs
Definition: FieldIO.h:115
static std::vector< std::vector< NekDouble > > NullVectorNekDoubleVector
Definition: FieldIO.h:67
void ImportFieldData(TiXmlDocument &doc, const std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata)
Imports the data fileds.
Definition: FieldIO.cpp:950
std::vector< NekDouble > m_homogeneousLengths
Definition: FieldIO.h:113
std::string SetUpOutput(const std::string outname, const std::vector< FieldDefinitionsSharedPtr > &fielddefs, const FieldMetaDataMap &fieldmetadatamap)
Definition: FieldIO.cpp:1113
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata=NullVectorNekDoubleVector, FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap, const Array< OneD, int > ElementiDs=NullInt1DArray)
Imports an FLD file.
Definition: FieldIO.cpp:383
boost::shared_ptr< FieldDefinitions > FieldDefinitionsSharedPtr
Definition: FieldIO.h:131
void ImportMultiFldFileIDs(const std::string &inFile, std::vector< std::string > &fileNames, std::vector< std::vector< unsigned int > > &elementList, FieldMetaDataMap &fieldmetadatamap)
Definition: FieldIO.cpp:551
FieldIO(LibUtilities::CommSharedPtr pComm)
Constructor.
Definition: FieldIO.cpp:140
std::vector< unsigned int > m_homogeneousZIDs
Definition: FieldIO.h:114
FieldDefinitions(ShapeType shapeType, const std::vector< unsigned int > &elementIDs, const std::vector< LibUtilities::BasisType > &basis, bool uniOrder, const std::vector< unsigned int > &numModes, const std::vector< std::string > &fields, int NumHomoDir=0, const std::vector< NekDouble > &HomoLengths=NullNekDoubleVector, const std::vector< unsigned int > &HomoZIDs=NullUnsignedIntVector, const std::vector< unsigned int > &HomoYIDs=NullUnsignedIntVector, const std::vector< LibUtilities::PointsType > &points=NullPointsTypeVector, bool pointsDef=false, const std::vector< unsigned int > &numPoints=NullUnsignedIntVector, bool numPointsDef=false)
Definition: FieldIO.h:71
bool m_uniOrder
Define order of the element group.
Definition: FieldIO.h:123
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:65
int CheckFieldDefinition(const FieldDefinitionsSharedPtr &fielddefs)
Definition: FieldIO.cpp:1339
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > ElementiDs)
Imports an FLD file.
Definition: FieldIO.cpp:106
void GenerateSeqString(const std::vector< unsigned int > &elmtids, std::string &idString)
Definition: FieldIO.cpp:1067
std::vector< LibUtilities::BasisType > m_basis
Definition: FieldIO.h:111
static std::vector< NekDouble > NullNekDoubleVector
Definition: FieldIO.h:61
std::vector< unsigned int > m_numModes
Define number of modes per direction.
Definition: FieldIO.h:125
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
void AddInfoTag(TiXmlElement *root, const FieldMetaDataMap &fieldmetadatamap)
add information about provenance and fieldmetadata
Definition: FieldIO.cpp:1008
int Inflate(string &in, std::vector< NekDouble > &out)
Definition: FieldIO.cpp:1277
#define LIB_UTILITIES_EXPORT
static std::vector< unsigned int > NullUnsignedIntVector
Definition: FieldIO.h:63
boost::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:236
std::vector< unsigned int > m_elementIDs
Definition: FieldIO.h:110
std::vector< std::string > m_fields
Definition: FieldIO.h:128
LibUtilities::CommSharedPtr m_comm
Communicator to use when writing parallel format.
Definition: FieldIO.h:204
static std::vector< LibUtilities::PointsType > NullPointsTypeVector
Definition: FieldIO.h:62
void WriteMultiFldFileIDs(const std::string &outfile, const std::vector< std::string > fileNames, std::vector< std::vector< unsigned int > > &elementList, const FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap)
Definition: FieldIO.cpp:511
std::vector< LibUtilities::PointsType > m_points
Define the type of points per direction.
Definition: FieldIO.h:118
Class for operating on FLD files.
Definition: FieldIO.h:151
int Deflate(std::vector< NekDouble > &in, string &out)
Definition: FieldIO.cpp:1224
void ImportFieldMetaData(std::string filename, FieldMetaDataMap &fieldmetadatamap)
Imports the definition of the meta data.
Definition: FieldIO.cpp:611
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap)
Write data in FLD format.
Definition: FieldIO.cpp:150
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap)
Write a field file in serial only.
Definition: FieldIO.cpp:72
static Array< OneD, int > NullInt1DArray
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:66