00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2003-2007 California Institute of Technology 00004 // The Header file for the Silo wrapper 00005 // by Daniel Ortiz and Santiago Lombeyda 00006 00007 #include <iostream> 00008 #include <silo.h> 00009 #include <string> 00010 #include <cstring> 00011 #include "SiloMesh.h" 00012 #include "SiloVariable.h" 00013 00014 #ifndef SILOCREATOR_CLASS 00015 #define SILOCREATOR_CLASS 00016 00017 // C++ strings 00018 using std::string; 00019 using std::cerr; 00020 using std::endl; 00021 00022 class SiloCreator{ 00023 00024 private: 00025 DBfile *file; // pointer to the silo file 00026 bool open; // is file open? 00027 00028 //Directory 00029 string path; // current location in the silo tree 00030 00031 //Mesh 00032 char * meshname; // name of the current mesh 00033 int ndims; // number of dimensions of the current mesh 00034 int datatype; // the datatype of the current mesh 00035 float xlength; // length of the x-axis 00036 float ylength; // length of the y-axis 00037 float zlength; // length of the z-axis 00038 int nodex; // number of nodes on x-axis 00039 int nodey; // number of nodes on y-axis 00040 int nodez; // number of nodes on z-axis 00041 float moriginx; // x value at origin 00042 float moriginy; // y value at origin 00043 float moriginz; // z value at origin 00044 bool Pointers; // Pointers are on or off 00045 float * xaxis; // pointer of floats defining x axis 00046 float * yaxis; // pointer of floats defining y axis 00047 float * zaxis; // pointer of floats defining z axis 00048 00049 00050 //Variable 00051 char * variablename; 00052 char * varmeshname; 00053 int nvars; 00054 char ** varnames; 00055 float ** vars; 00056 int vardatacentering; 00057 int vardims[3]; 00058 int varndims; 00059 00060 //MultiMesh 00061 char * multimeshname; 00062 char ** meshnames; 00063 int * meshtypes; 00064 int nmesh; 00065 00066 //MultiVar 00067 char * multivarname; 00068 char ** mvarnames; 00069 int nvar; 00070 int * vartypes; 00071 00072 public: 00073 00074 // Constructor: (creates the silo file in the current UNIX directory) 00075 // Arguments: String - name of file 00076 // String - file description 00077 00078 SiloCreator(char *); 00079 SiloCreator(char *, char *); 00080 00081 // Destructor: closes file 00082 ~SiloCreator(); 00083 00084 // DBFile closer, can be called by Destructor 00085 void Close(); 00086 00087 // ========================================== 00088 // Director/Tree Manipulations 00089 // ========================================== 00090 00091 // SetDirectory: sets the path of the pointer in the directory tree 00092 // Arguments: String - absolute path of directory, or path from current directory 00093 00094 void SetDirectory( char *); 00095 00096 // SettoRoot: this function sets the current directory to root 00097 00098 void SetToRoot(); 00099 00100 00101 // MakeDirectory: makes a new directory in the current directory 00102 // Arguments: String - the name of the directory 00103 00104 void MakeDirectory(char *); 00105 00106 // MakeAndSetDirectory: makes a new node(directory) in the current directory and sets the current directory to it 00107 // Arguments: Cstring - the name of the new directory 00108 00109 void MakeAndSetDirectory( char*); 00110 00111 // GetDirectory: returns the path of the current directory 00112 00113 char * GetDirectory(); 00114 00115 // ======================================= 00116 // Mesh Manipulations 00117 // ======================================= 00118 00119 // SetMeshName: sets the mesh name 00120 // Arguments: Cstring - the name of the mesh 00121 00122 void SetMeshName(char *); 00123 00124 // GetMeshName: returns the a string of the mesh name 00125 00126 char * GetMeshName(); 00127 00128 // SetDimension: sets the number of dimensions in the file ( i.e 1D, 2D.... nD) 00129 // Arguments: Integer - number of dimensions 00130 00131 void SetDimension(int); 00132 00133 // GetDimension: returns the current number of dimensions 00134 00135 int GetDimension(); 00136 00137 // FloatData: sets the datatype of mesh to float (default) 00138 00139 void FloatData(); 00140 00141 // DoubleData: sets the datatype of the mesh to double 00142 00143 void DoubleData(); 00144 00145 // IntData: sets the datatype of the mesh to double 00146 00147 void IntData(); 00148 00149 // SetMeshOrigin: sets the origin of the mesh 00150 // Argument: Float - X value at origin 00151 // Float - Y value at origin 00152 // Float - Z value at origin 00153 00154 void SetMeshOrigin( float , float , float); 00155 00156 // SetLenghts: sets the physical distance of each axis (1D - 3D feature) 00157 // Argument: Float- Length of the x-axis 00158 // Float- Length of the y-axis 00159 // Float- Lenght of the z-axis 00160 void SetMeshLengths( float, float, float); 00161 00162 // SetNumberofNodes - sets the amount of nodes for each axis ( 1D - 3D feature) 00163 // Argument: Int - number of nodes on x-axis 00164 // Int - number of nodes on y-axis 00165 // Int - number of nodes on z-axis 00166 00167 void SetNumberofMeshNodes( int, int, int); 00168 00169 // SetMesh - sets all the relevant data for a mesh 00170 // Argument: String - string of mesh name 00171 // Integer - number of dimensions 00172 // Float - length of the x-axis 00173 // Float - length of the y-axis 00174 // Float - length of the z-axis 00175 // Integer - number of nodes on x-axis 00176 // Integer - number of nodes on y-axis 00177 // Integer - number of nodes on z-axis 00178 // Float - x value at origin 00179 // Float - y value at origin 00180 // Float - z value at origin 00181 void SetMesh( char *, int, float, float, float, int , int ,int, float, float, float); 00182 00183 00184 // SetMesh - sets all the relevant data for the mesh 00185 // Argument: String - string of mesh name 00186 // Integer - the number of dimensions 00187 // Array of Floats - array of lengths of axii (xyz) 00188 // Array of Integers - array of # of nodes (xyz) 00189 // Array of Floats - array of origin values (xyz) 00190 00191 void SetMesh( char *, int, float *, int *, float *); 00192 00193 // SetMesh - sets all the relevant data for the mesh 00194 // Arguments: String - string of mesh name 00195 // Integer * - dimensions of the mesh (xyz) 00196 // Float * - the min float value of the mesh (xyz) 00197 // Float * - the max float value of the mesh (xyz) 00198 00199 void SetMesh(char *, int , int *, float *, float *); 00200 00201 // SetMesh - sets all the relevant data for the mesh 00202 // Arguments - SiloMesh * - pointer holding all mesh data 00203 00204 void SetMesh(SiloMesh *); 00205 00206 // SexXaxis- Sets the x-axis 00207 00208 void SetXaxis( float *); 00209 00210 // SexXaxis- Sets the x-axis 00211 00212 void SetYaxis( float *); 00213 00214 // SexXaxis- Sets the x-axis 00215 00216 void SetZaxis( float *); 00217 00218 // SetMesh - pointer version of the previous Set function 00219 00220 void SetMesh(char *, float *, int , float *, int, float *, int); 00221 00222 // DrawMesh- draws mesh into file 00223 00224 void DrawMesh(); 00225 00226 //================================================================= 00227 // Mesh Variables ( data, vectors, tensors, ...) 00228 //================================================================= 00229 00230 // SetVariableName: sets the name of the mesh variables (i.e. Density, Pressure, ..) - header name 00231 // Arguments: Cstring - string of variable name 00232 00233 void SetVariableName(char *); 00234 00235 // SetMeshBinding: this function binds the variable to a mesh 00236 // Arguments: Cstring - string of mesh name 00237 00238 void SetMeshBinding(char *); 00239 00240 // SetNumberofVariables: this function sets the number of variables ( 1- scalar, 2-n vector) 00241 // Arguments: Int - the number of the variables 00242 void SetNumberofVariables(int); 00243 00244 00245 // SetVariableNames : this function sets names for each variable (to be use if your using muli-variables) 00246 // Arguments - Array of Cstrings- names of the variables 00247 void SetMultiVariableNames(char **); 00248 00249 // SetVariableDataCentering : this function sets the variable data type 00250 // Arguments - Var Data Centering- either DB_NODECENT or DB_ZONECENT 00251 void SetVariableDataCentering(int); 00252 00253 // SetVariableData : this function sets the variable data 00254 // Arguments - Array of Float Pointers - pointer to arrays of data 00255 void SetVariableData(float **); 00256 00257 // SetVariable: this function sets all of the necessary variable data 00258 // Arguments - Cstring - variable name 00259 // Int - data dimensions 00260 // Array of Ints - size of each dimnsion on data 00261 // Cstring - mesh name 00262 // Int - number of variables 00263 // Array of Cstrings - names of variables 00264 // Array of Float Pointers - pointers to arrays of data 00265 // Var Data Centering- either DB_NODECENT or DB_ZONECENT 00266 void SetVariable(char *, int i, int *, char *, int ,float **, int ivardatatype=DB_NODECENT); 00267 void SetVariable(SiloVariable *); 00268 00269 // DrawVariable: this function adds the variable to the silo file for drawing 00270 void DrawVariable(); 00271 void SetVariableDataDims(int, int *); 00272 00273 00274 //===================================================================== 00275 // MultiMesh Manipulations 00276 //===================================================================== 00277 00278 // CreateMultiMesh - this function creates a new multi mesh ( there is 00279 // only one active multimesh at a time) 00280 // Arguments - Cstring - the name of the multimesh 00281 00282 void CreateMultiMesh(char *); 00283 00284 // SetMultiMesh - this function sets the multimesh (QuadMeshes) 00285 // Arguments - Cstring - the name of the meshs with paths e.g( /dir/dir2/mesh) 00286 // Integer - the number of meshse 00287 00288 void SetMultiMesh(int, char **); 00289 00290 // SetMultiMesh - this function sets the multimesh QuadMeshes) 00291 // Arguments - Cstring - the name of the meshs with paths e.g( /dir/dir2/mesh) 00292 // Integer - the number of meshse 00293 00294 void SetMultiMesh(int, SiloMesh**); 00295 00296 // WriteMultiMesh - this function writes the multi mesh to the silo file 00297 00298 void WriteMultiMesh(); 00299 00300 //========================================================================= 00301 // MultiVar Manipulations 00302 //========================================================================= 00303 00304 // CreateMultiVar - this function creates a new multi var ( there is only one active 00305 // multivar at a time 00306 // Arguments - Cstring - the name of the multivar 00307 00308 void CreateMultiVar(char *); 00309 00310 // SetMultiVar - this function sets the multivar (MultiVar) 00311 // Arguments - Cstring - the name of the var path e.g(/dir/dir2/var) 00312 // Integer - the number of variables 00313 00314 void SetMultiVar(int, char **); 00315 00316 //WriteMultiVar - this function writes the current multi variable to the silo file 00317 00318 void SetMultiVar(int, SiloVariable **); 00319 00320 void WriteMultiVar(); 00321 00322 00323 00324 private: 00325 static int ith_file; 00326 char * SplitFilenameAndPath(char *,char * &newfilename, char * &newpath); 00327 char * SetFilenameToFullPath(char *); 00328 00329 }; 00330 00331 #endif