Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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;
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 =
82  const std::vector<unsigned int> &HomoZIDs =
84  const std::vector<unsigned int> &HomoYIDs =
86  const std::vector<LibUtilities::PointsType> &points =
88  bool pointsDef = false,
89  const std::vector<unsigned int> &numPoints =
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