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 
43 #include <tinyxml.h>
44 
45 namespace Nektar
46 {
47 namespace LibUtilities
48 {
49 static std::vector<NekDouble> NullNekDoubleVector;
50 static std::vector<LibUtilities::PointsType> NullPointsTypeVector;
51 static std::vector<unsigned int> NullUnsignedIntVector;
52 
53 typedef std::map<std::string, std::string> FieldMetaDataMap;
54 static FieldMetaDataMap NullFieldMetaDataMap;
55 static std::vector<std::vector<NekDouble> > NullVectorNekDoubleVector =
56  boost::assign::list_of(NullNekDoubleVector);
57 
59 {
61  ShapeType shapeType,
62  const std::vector<unsigned int> &elementIDs,
63  const std::vector<LibUtilities::BasisType> &basis,
64  bool uniOrder,
65  const std::vector<unsigned int> &numModes,
66  const std::vector<std::string> &fields,
67  int NumHomoDir = 0,
68  const std::vector<NekDouble> &HomoLengths
69  = NullNekDoubleVector,
70  bool homoStrips = false,
71  const std::vector<unsigned int> &HomoSIDs
72  = NullUnsignedIntVector,
73  const std::vector<unsigned int> &HomoZIDs
74  = NullUnsignedIntVector,
75  const std::vector<unsigned int> &HomoYIDs
76  = NullUnsignedIntVector,
77  const std::vector<LibUtilities::PointsType> &points
78  = NullPointsTypeVector,
79  bool pointsDef = false,
80  const std::vector<unsigned int> &numPoints
81  = NullUnsignedIntVector,
82  bool numPointsDef = false)
83  : m_shapeType(shapeType), m_elementIDs(elementIDs), m_basis(basis),
84  m_numHomogeneousDir(NumHomoDir), m_homogeneousLengths(HomoLengths),
85  m_homoStrips(homoStrips), m_homogeneousSIDs(HomoSIDs),
86  m_homogeneousZIDs(HomoZIDs), m_homogeneousYIDs(HomoYIDs),
87  m_points(points), m_pointsDef(pointsDef), m_uniOrder(uniOrder),
88  m_numModes(numModes), m_numPoints(numPoints),
89  m_numPointsDef(numPointsDef), m_fields(fields)
90  {
91  }
92 
94  std::vector<unsigned int> m_elementIDs;
95  std::vector<LibUtilities::BasisType> m_basis;
97  std::vector<NekDouble> m_homogeneousLengths;
99  std::vector<unsigned int> m_homogeneousSIDs;
100  std::vector<unsigned int> m_homogeneousZIDs;
101  std::vector<unsigned int> m_homogeneousYIDs;
102  /// True if filesystem is shared.
104  /// Define the type of points per direction.
105  std::vector<LibUtilities::PointsType> m_points;
107  /// Define order of the element group.
108  /// * UniOrder: same order for each element
109  /// * MixOrder: definition of a different order for each element.
111  /// Define number of modes per direction.
112  std::vector<unsigned int> m_numModes;
113  std::vector<unsigned int> m_numPoints;
115  std::vector<std::string> m_fields;
116 };
117 
118 typedef boost::shared_ptr<FieldDefinitions> FieldDefinitionsSharedPtr;
119 
120 /// Write a field file in serial only
122  const std::string &outFile,
123  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
124  std::vector<std::vector<NekDouble> > &fielddata,
125  const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
126 
127 /// Imports an FLD file
129  const std::string &infilename,
130  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
131  std::vector<std::vector<NekDouble> > &fielddata
132  = NullVectorNekDoubleVector,
133  FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
134  const Array<OneD, int> ElementiDs = NullInt1DArray);
135 
136 /// Class for operating on FLD files
137 class FieldIO
138 {
139 public:
140  /// Constructor
142  bool sharedFilesystem = false);
143 
144  /// Write data in FLD format
146  const std::string &outFile,
147  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
148  std::vector<std::vector<NekDouble> > &fielddata,
149  const FieldMetaDataMap &fieldinfomap
150  = NullFieldMetaDataMap);
151 
152  /// Imports an FLD file.
154  const std::string &infilename,
155  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
156  std::vector<std::vector<NekDouble> > &fielddata
157  = NullVectorNekDoubleVector,
158  FieldMetaDataMap &fieldinfomap
159  = NullFieldMetaDataMap,
160  const Array<OneD, int> ElementiDs = NullInt1DArray);
161 
162  /// Imports the definition of the meta data
164  std::string filename,
165  FieldMetaDataMap &fieldmetadatamap);
166 
167  /// Imports the definition of the meta data
169  TiXmlDocument &doc, FieldMetaDataMap &fieldmetadatamap);
170 
171  /// Imports the definition of the fields.
173  TiXmlDocument &doc,
174  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
175  bool expChild);
176 
177  /// Imports the data fileds.
179  TiXmlDocument &doc,
180  const std::vector<FieldDefinitionsSharedPtr> &fielddefs,
181  std::vector<std::vector<NekDouble> > &fielddata);
182 
184  const std::string &outfile,
185  const std::vector<std::string> fileNames,
186  std::vector<std::vector<unsigned int> > &elementList,
187  const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
188 
189 protected:
190  /// Communicator to use when writing parallel format
192 
193  /// True if same filesystem accessible by all processes.
195 
197  TiXmlElement *root, const FieldMetaDataMap &fieldmetadatamap);
198 
200  const std::vector<unsigned int> &elmtids, std::string &idString);
201 
202  LIB_UTILITIES_EXPORT std::string SetUpOutput(const std::string outname);
203 
205  const std::string outname,
206  const std::vector<FieldDefinitionsSharedPtr> &fielddefs,
207  const FieldMetaDataMap &fieldmetadatamap);
208 
210  const std::string &inFile,
211  std::vector<std::string> &fileNames,
212  std::vector<std::vector<unsigned int> > &elementList,
213  FieldMetaDataMap &fieldmetadatamap);
214 
216  const FieldDefinitionsSharedPtr &fielddefs);
217 
218  LIB_UTILITIES_EXPORT virtual std::string GetFileEnding() const
219  {
220  return "fld";
221  };
222 
223 };
224 
225 typedef boost::shared_ptr<FieldIO> FieldIOSharedPtr;
226 }
227 }
228 #endif
std::vector< unsigned int > m_numPoints
Definition: FieldIO.h:113
void ImportFieldDefs(TiXmlDocument &doc, std::vector< FieldDefinitionsSharedPtr > &fielddefs, bool expChild)
Imports the definition of the fields.
Definition: FieldIO.cpp:726
std::vector< unsigned int > m_homogeneousYIDs
Definition: FieldIO.h:101
void ImportFieldData(TiXmlDocument &doc, const std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata)
Imports the data fileds.
Definition: FieldIO.cpp:1018
std::vector< NekDouble > m_homogeneousLengths
Definition: FieldIO.h:97
FieldIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem=false)
Constructor.
Definition: FieldIO.cpp:149
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:409
boost::shared_ptr< FieldDefinitions > FieldDefinitionsSharedPtr
Definition: FieldIO.h:118
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, bool homoStrips=false, const std::vector< unsigned int > &HomoSIDs=NullUnsignedIntVector, 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:60
void ImportMultiFldFileIDs(const std::string &inFile, std::vector< std::string > &fileNames, std::vector< std::vector< unsigned int > > &elementList, FieldMetaDataMap &fieldmetadatamap)
Definition: FieldIO.cpp:577
std::string SetUpOutput(const std::string outname)
Definition: FieldIO.cpp:1192
std::vector< unsigned int > m_homogeneousZIDs
Definition: FieldIO.h:100
bool m_uniOrder
Define order of the element group.
Definition: FieldIO.h:110
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:53
int CheckFieldDefinition(const FieldDefinitionsSharedPtr &fielddefs)
Definition: FieldIO.cpp:1355
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:115
std::vector< unsigned int > m_homogeneousSIDs
Definition: FieldIO.h:99
void GenerateSeqString(const std::vector< unsigned int > &elmtids, std::string &idString)
Definition: FieldIO.cpp:1146
std::vector< LibUtilities::BasisType > m_basis
Definition: FieldIO.h:95
static std::vector< NekDouble > NullNekDoubleVector
Definition: FieldIO.h:49
bool m_sharedFilesystem
True if same filesystem accessible by all processes.
Definition: FieldIO.h:194
std::vector< unsigned int > m_numModes
Define number of modes per direction.
Definition: FieldIO.h:112
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:1087
#define LIB_UTILITIES_EXPORT
bool m_sharedFilesystem
True if filesystem is shared.
Definition: FieldIO.h:103
static std::vector< std::vector< NekDouble > > NullVectorNekDoubleVector
Definition: FieldIO.h:55
static std::vector< unsigned int > NullUnsignedIntVector
Definition: FieldIO.h:51
boost::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:225
std::vector< unsigned int > m_elementIDs
Definition: FieldIO.h:94
std::vector< std::string > m_fields
Definition: FieldIO.h:115
LibUtilities::CommSharedPtr m_comm
Communicator to use when writing parallel format.
Definition: FieldIO.h:191
void SetUpFieldMetaData(const std::string outname, const std::vector< FieldDefinitionsSharedPtr > &fielddefs, const FieldMetaDataMap &fieldmetadatamap)
Definition: FieldIO.cpp:1285
static std::vector< LibUtilities::PointsType > NullPointsTypeVector
Definition: FieldIO.h:50
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:537
std::vector< LibUtilities::PointsType > m_points
Define the type of points per direction.
Definition: FieldIO.h:105
Class for operating on FLD files.
Definition: FieldIO.h:137
void ImportFieldMetaData(std::string filename, FieldMetaDataMap &fieldmetadatamap)
Imports the definition of the meta data.
Definition: FieldIO.cpp:637
virtual std::string GetFileEnding() const
Definition: FieldIO.h:218
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:160
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:81
static Array< OneD, int > NullInt1DArray
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:54