/[escript]/trunk/dataexporter/src/EscriptDataset.h
ViewVC logotype

Contents of /trunk/dataexporter/src/EscriptDataset.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2910 - (show annotations)
Wed Feb 3 03:22:31 2010 UTC (9 years, 6 months ago) by caltinay
File MIME type: text/plain
File size: 5158 byte(s)
Added a libescriptreader.a target which does not depend on escript or finley
at runtime. This will be used for the VisIt plugin so is not built by default.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14 #ifndef __ESCRIPTDATASET_H__
15 #define __ESCRIPTDATASET_H__
16
17 #include <escriptexport/escriptexport.h>
18
19 #include <ostream>
20
21 class DBfile;
22
23 namespace escript {
24 class AbstractDomain;
25 class Data;
26 }
27
28
29 namespace escriptexport {
30
31 typedef std::vector<escript::Data> DataVec;
32 typedef std::vector<DataVar_ptr> DataBlocks;
33 typedef std::vector<FinleyMesh_ptr> MeshBlocks;
34
35 struct VarInfo {
36 std::string varName;
37 DataBlocks dataBlocks;
38 IntVec sampleDistribution;
39 bool valid;
40 };
41
42 typedef std::vector<VarInfo> VarVector;
43
44
45 /// \brief Represents an escript dataset including domain and variables for
46 /// one timestep.
47 //
48 /// This class represents an escript/finley dataset complete with domain and
49 /// variable data. It can read the dataset from NetCDF files generated by the
50 /// dump() methods within escript or through an escript domain instance plus
51 /// a number of escript::Data instances. Subsequently, the dataset can be
52 /// saved in the Silo file format or accessed through a number of accessor
53 /// methods.
54 ///
55 /// If the data is distributed via MPI then all ranks should create an instance
56 /// of this class and call the respective methods. NetCDF files that stem from
57 /// a parallel run can be read on one processor or on the same number of MPI
58 /// processes as they were created with.
59 class EscriptDataset
60 {
61 public:
62 /// \brief Default constructor.
63 ESCRIPTEXPORT_DLL_API
64 EscriptDataset();
65
66 #if HAVE_MPI
67 /// \brief Constructor with communicator.
68 ESCRIPTEXPORT_DLL_API
69 EscriptDataset(MPI_Comm comm);
70 #endif
71
72 /// \brief Destructor.
73 ESCRIPTEXPORT_DLL_API
74 ~EscriptDataset();
75
76 /// \brief Initialises with instances of escript domain and data.
77 ESCRIPTEXPORT_DLL_API
78 bool initFromEscript(const escript::AbstractDomain* mesh,
79 DataVec& escriptVars, const StringVec& varNames);
80
81 /// \brief Loads mesh and variables from escript NetCDF files.
82 ///
83 /// \param meshFilePattern a printf-style pattern for the mesh file names
84 /// (e.g. "mesh.%02d.nc")
85 /// \param varFiles a vector of file name patterns for variables
86 /// \param varNames a vector of variable names
87 /// \param nBlocks number of blocks/chunks to load
88 ///
89 /// \note If MPI is enabled nBlocks must be equal to the size of the
90 /// communicator or this method fails.
91 ESCRIPTEXPORT_DLL_API
92 bool loadNetCDF(const std::string meshFilePattern,
93 const StringVec& varFiles, const StringVec& varNames,
94 int nBlocks);
95
96 /// \brief Loads only variables from escript NetCDF files using given mesh.
97 ESCRIPTEXPORT_DLL_API
98 bool loadNetCDF(const MeshBlocks& mesh, const StringVec& varFiles,
99 const StringVec& varNames);
100
101 /// \brief Sets the cycle number and time value for this dataset.
102 ESCRIPTEXPORT_DLL_API
103 void setCycleAndTime(int c, double t) { cycle=c; time=t; }
104
105 /// \brief Saves the dataset in the Silo file format.
106 ESCRIPTEXPORT_DLL_API
107 bool saveSilo(const std::string fileName, bool useMultiMesh=true);
108
109 /// \brief Saves the dataset in the VTK XML file format.
110 /// \note NOT IMPLEMENTED.
111 ESCRIPTEXPORT_DLL_API
112 bool saveVTK(const std::string fileName);
113
114 /// \brief Returns the dataset's mesh.
115 ESCRIPTEXPORT_DLL_API
116 MeshBlocks extractMesh() { keepMesh = true; return meshBlocks; }
117
118 /// \brief Returns the dataset's mesh.
119 ESCRIPTEXPORT_DLL_API
120 const MeshBlocks& getMesh() const { return meshBlocks; }
121
122 /// \brief Returns a vector with the dataset's variables.
123 ESCRIPTEXPORT_DLL_API
124 const VarVector& getVariables() const { return variables; }
125
126 /// \brief Returns a vector with the mesh variables.
127 ESCRIPTEXPORT_DLL_API
128 const VarVector& getMeshVariables() const { return meshVariables; }
129
130 private:
131 bool loadMeshFromNetCDF();
132 bool loadVarFromNetCDF(const std::string& fileName,
133 const std::string& varName);
134 void convertMeshVariables();
135 void updateSampleDistribution(VarInfo& vi);
136 void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName);
137 void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi);
138 void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi,
139 bool useMeshFile = false);
140 void writeVarToVTK(const VarInfo& varInfo, std::ostream& os);
141
142 int numParts;
143 int cycle;
144 double time;
145 bool keepMesh, externalMesh;
146 std::string meshFmt;
147 MeshBlocks meshBlocks;
148 VarVector variables, meshVariables;
149 int mpiRank, mpiSize;
150 #if HAVE_MPI
151 MPI_Comm mpiComm;
152 #else
153 void* mpiComm;
154 #endif
155 };
156
157 } // namespace escriptexport
158
159 #endif // __ESCRIPTDATASET_H__
160

  ViewVC Help
Powered by ViewVC 1.1.26