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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3091 - (show annotations)
Fri Aug 13 07:47:57 2010 UTC (10 years, 1 month ago) by caltinay
File MIME type: text/plain
File size: 4989 byte(s)
-fixed cleanup on error when invoking escriptconvert in parallel
-fixed saving VTK files on one rank if data was loaded in chunks
-cleaned up EscriptDataset and split a couple of methods

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 <weipa/weipa.h>
18
19 #include <ostream>
20
21 class DBfile;
22
23 namespace escript {
24 class AbstractDomain;
25 class Data;
26 }
27
28
29 namespace weipa {
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 a domain and data variables
46 /// for 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 WEIPA_DLL_API
64 EscriptDataset();
65
66 #if HAVE_MPI
67 /// \brief Constructor with communicator.
68 WEIPA_DLL_API
69 EscriptDataset(MPI_Comm comm);
70 #endif
71
72 /// \brief Destructor.
73 WEIPA_DLL_API
74 ~EscriptDataset();
75
76 /// \brief Initialises with instances of escript domain and data.
77 WEIPA_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 WEIPA_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 WEIPA_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 WEIPA_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 WEIPA_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 WEIPA_DLL_API
111 bool saveVTK(const std::string fileName);
112
113 /// \brief Returns the dataset's converted domain so it can be reused.
114 WEIPA_DLL_API
115 MeshBlocks getConvertedDomain() { return meshBlocks; }
116
117 /// \brief Returns a vector with the dataset's variables.
118 WEIPA_DLL_API
119 const VarVector& getVariables() const { return variables; }
120
121 /// \brief Returns a vector with the mesh variables.
122 WEIPA_DLL_API
123 const VarVector& getMeshVariables() const { return meshVariables; }
124
125 private:
126 bool setDomain(const escript::AbstractDomain* domain);
127 bool setDomain(const std::string filePattern, int nBlocks);
128 bool setDomain(const MeshBlocks& domain);
129 bool addData(escript::Data& data, const std::string name);
130 bool addData(const std::string filePattern, const std::string name);
131
132 void convertMeshVariables();
133 void updateSampleDistribution(VarInfo& vi);
134 void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName);
135 void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi);
136 void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi,
137 bool useMeshFile = false);
138 void writeVarToVTK(const VarInfo& varInfo, std::ostream& os);
139
140 int cycle;
141 double time;
142 bool externalMesh;
143 MeshBlocks meshBlocks;
144 VarVector variables, meshVariables;
145 int mpiRank, mpiSize;
146 #if HAVE_MPI
147 MPI_Comm mpiComm;
148 #else
149 void* mpiComm;
150 #endif
151 };
152
153 } // namespace weipa
154
155 #endif // __ESCRIPTDATASET_H__
156

  ViewVC Help
Powered by ViewVC 1.1.26