2017-03-01 16:30:39 -05:00
|
|
|
#ifndef SILO_INTERFACE
|
|
|
|
|
#define SILO_INTERFACE
|
2017-01-23 10:42:21 -05:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
|
|
#include "common/Array.h"
|
2021-01-06 11:58:43 -05:00
|
|
|
#include "common/MPI.h"
|
2017-01-23 10:42:21 -05:00
|
|
|
#include "common/Communication.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_SILO
|
|
|
|
|
#include <silo.h>
|
|
|
|
|
#else
|
|
|
|
|
typedef int DBfile;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace silo {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum FileMode { READ, WRITE, CREATE };
|
|
|
|
|
|
2017-03-01 15:48:17 -05:00
|
|
|
enum class VariableType : int { NodeVariable=1, EdgeVariable=2, SurfaceVariable=2, VolumeVariable=3, NullVariable=0 };
|
|
|
|
|
|
|
|
|
|
enum class VariableDataType { DOUBLE, FLOAT, INT, UNKNOWN };
|
2017-01-23 10:42:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Open silo file
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function opens a silo file
|
2017-01-23 10:42:21 -05:00
|
|
|
* @param[in] filename File to open
|
|
|
|
|
* @param[in] mode Open the file for reading or writing
|
|
|
|
|
* @return This function returns a handle to the file
|
|
|
|
|
*/
|
|
|
|
|
DBfile* open( const std::string& filename, FileMode mode );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Close silo file
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function closes a silo file
|
2017-01-23 10:42:21 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
*/
|
|
|
|
|
void close( DBfile* fid );
|
|
|
|
|
|
|
|
|
|
|
2017-03-01 15:48:17 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Get the variable type
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function returns the type of variable data
|
2017-03-01 15:48:17 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] name Name of variable
|
|
|
|
|
*/
|
|
|
|
|
VariableDataType varDataType( DBfile *dbfile, const std::string& name );
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 08:22:29 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Write data to silo
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes an arbitrary array to silo
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] varname Variable name
|
|
|
|
|
* @param[in] data Data to write
|
|
|
|
|
*/
|
|
|
|
|
template<class TYPE>
|
|
|
|
|
void write( DBfile* fid, const std::string& varname, const std::vector<TYPE>& data );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Write data to silo
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes an arbitrary array to silo
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] varname Variable name
|
|
|
|
|
* @return Data read
|
|
|
|
|
*/
|
|
|
|
|
template<class TYPE>
|
|
|
|
|
std::vector<TYPE> read( DBfile* fid, const std::string& varname );
|
|
|
|
|
|
|
|
|
|
|
2017-01-23 10:42:21 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Write a uniform grid
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes a uniform grid to silo as a Quadmesh
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
2017-01-23 10:42:21 -05:00
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @param[in] range Range of mesh { xmin, xmax, ymin, ymax, zmin, zmax }
|
|
|
|
|
* @param[in] N Number of cells in each direction
|
|
|
|
|
*/
|
|
|
|
|
template<int NDIM>
|
|
|
|
|
void writeUniformMesh( DBfile* fid, const std::string& meshname,
|
|
|
|
|
const std::array<double,2*NDIM>& range, const std::array<int,NDIM>& N );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2017-01-31 08:22:29 -05:00
|
|
|
* @brief Read a uniform grid
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function reads a uniform grid from silo
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
2017-01-23 10:42:21 -05:00
|
|
|
* @param[in] meshname Mesh name
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[out] range Range of mesh { xmin, xmax, ymin, ymax, zmin, zmax }
|
|
|
|
|
* @param[out] N Number of cells in each direction
|
2017-01-23 10:42:21 -05:00
|
|
|
*/
|
2017-01-31 08:22:29 -05:00
|
|
|
void readUniformMesh( DBfile* fid, const std::string& meshname,
|
|
|
|
|
std::vector<double>& range, std::vector<int>& N );
|
2017-01-23 10:42:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2017-01-31 08:22:29 -05:00
|
|
|
* @brief Write a uniform grid variable
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes a uniform grid variable to silo as a Quadmesh
|
2017-01-23 10:42:21 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @param[in] N Number of cells in each direction
|
|
|
|
|
* @param[in] varname Variable name
|
|
|
|
|
* @param[in] data Variable data
|
|
|
|
|
* @param[in] type Variable type
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template< int NDIM, class TYPE >
|
2017-01-23 10:42:21 -05:00
|
|
|
void writeUniformMeshVariable( DBfile* fid, const std::string& meshname, const std::array<int,NDIM>& N,
|
2017-03-01 15:48:17 -05:00
|
|
|
const std::string& varname, const Array<TYPE>& data, VariableType type );
|
2017-01-23 10:42:21 -05:00
|
|
|
|
|
|
|
|
|
2017-02-03 11:26:08 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Read a uniform mesh grid variable
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function read a uniform mesh variable to silo
|
2017-02-03 11:26:08 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] varname Variable name
|
|
|
|
|
* @return Variable data
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
|
|
|
|
Array<TYPE> readUniformMeshVariable( DBfile* fid, const std::string& varname );
|
2017-02-03 11:26:08 -05:00
|
|
|
|
|
|
|
|
|
2017-01-31 08:22:29 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Write a pointmesh
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes a pointmesh to silo
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @param[in] ndim Number of dimensions
|
|
|
|
|
* @param[in] N Number of points
|
|
|
|
|
* @param[in] coords Coordinates of the points
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
2017-01-31 08:22:29 -05:00
|
|
|
void writePointMesh( DBfile* fid, const std::string& meshname,
|
2017-03-01 15:48:17 -05:00
|
|
|
int ndim, int N, const TYPE *coords[] );
|
2017-01-31 08:22:29 -05:00
|
|
|
|
|
|
|
|
|
2017-02-03 11:26:08 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Read a pointmesh
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function reads a pointmesh from silo
|
2017-02-03 11:26:08 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @return Returns the coordinates as a N x ndim array
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
|
|
|
|
Array<TYPE> readPointMesh( DBfile* fid, const std::string& meshname );
|
2017-02-03 11:26:08 -05:00
|
|
|
|
|
|
|
|
|
2017-01-31 08:22:29 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Write a pointmesh grid variable
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes a pointmesh variable to silo
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @param[in] varname Variable name
|
|
|
|
|
* @param[in] data Variable data
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
2017-01-31 08:22:29 -05:00
|
|
|
void writePointMeshVariable( DBfile* fid, const std::string& meshname,
|
2017-03-01 15:48:17 -05:00
|
|
|
const std::string& varname, const Array<TYPE>& data );
|
2017-01-31 08:22:29 -05:00
|
|
|
|
|
|
|
|
|
2017-02-03 11:26:08 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Read a pointmesh grid variable
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function reads a pointmesh variable from silo
|
2017-02-03 11:26:08 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] varname Variable name
|
|
|
|
|
* @return Variable data
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
|
|
|
|
Array<TYPE> readPointMeshVariable( DBfile* fid, const std::string& varname );
|
2017-02-03 11:26:08 -05:00
|
|
|
|
|
|
|
|
|
2017-01-31 08:22:29 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Write a triangle mesh
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes a triangle (or simplex) based mesh to silo
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @param[in] ndim Number of dimensions for the coordinates
|
|
|
|
|
* @param[in] ndim_tri Number of dimensions for the triangles (2: surface, 3: volume)
|
|
|
|
|
* @param[in] N Number of points
|
|
|
|
|
* @param[in] coords Coordinates of the points
|
|
|
|
|
* @param[in] N_tri Number of triangles
|
|
|
|
|
* @param[in] tri Coordinates of the points
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
2017-01-31 08:22:29 -05:00
|
|
|
void writeTriMesh( DBfile* fid, const std::string& meshname,
|
2017-03-01 15:48:17 -05:00
|
|
|
int ndim, int ndim_tri, int N, const TYPE *coords[], int N_tri, const int *tri[] );
|
2017-01-31 08:22:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2017-02-03 11:26:08 -05:00
|
|
|
* @brief Read a triangle mesh
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function reads a triangle (or simplex) based mesh to silo
|
2017-02-03 11:26:08 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @param[in] coords Coordinates of the points
|
|
|
|
|
* @param[in] tri Coordinates of the points
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
|
|
|
|
void readTriMesh( DBfile* fid, const std::string& meshname, Array<TYPE>& coords, Array<int>& tri );
|
2017-02-03 11:26:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Write a triangle mesh grid variable
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes a triangle mesh variable to silo
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
2020-05-28 13:12:09 -04:00
|
|
|
* @param[in] ndim Number of dimensions
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @param[in] varname Variable name
|
|
|
|
|
* @param[in] data Variable data
|
2017-03-01 15:48:17 -05:00
|
|
|
* @param[in] type Variable type
|
2017-01-31 08:22:29 -05:00
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
2017-01-31 08:22:29 -05:00
|
|
|
void writeTriMeshVariable( DBfile* fid, int ndim, const std::string& meshname,
|
2017-03-01 15:48:17 -05:00
|
|
|
const std::string& varname, const Array<TYPE>& data, VariableType type );
|
2017-01-31 08:22:29 -05:00
|
|
|
|
2017-02-03 11:26:08 -05:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Read a triangle mesh grid variable
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function read a triangle mesh variable to silo
|
2017-02-03 11:26:08 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] varname Variable name
|
|
|
|
|
* @return Variable data
|
|
|
|
|
*/
|
2017-03-01 15:48:17 -05:00
|
|
|
template<class TYPE>
|
|
|
|
|
Array<TYPE> readTriMeshVariable( DBfile* fid, const std::string& varname );
|
2017-02-03 11:26:08 -05:00
|
|
|
|
|
|
|
|
|
2017-01-31 08:22:29 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Write a multimesh
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes a multimesh to silo
|
2017-01-31 08:22:29 -05:00
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] meshname Mesh name
|
|
|
|
|
* @param[in] subMeshNames Names of the sub meshes in the form "filename:meshname"
|
|
|
|
|
* @param[in] subMeshTypes Type of each submesh
|
|
|
|
|
*/
|
|
|
|
|
void writeMultiMesh( DBfile* fid, const std::string& meshname,
|
|
|
|
|
const std::vector<std::string>& subMeshNames,
|
|
|
|
|
const std::vector<int>& subMeshTypes );
|
|
|
|
|
|
|
|
|
|
|
2017-01-23 10:42:21 -05:00
|
|
|
/*!
|
|
|
|
|
* @brief Write a multivariable
|
2020-05-28 13:12:09 -04:00
|
|
|
* @details This function writes a multivariable to silo
|
2017-01-23 10:42:21 -05:00
|
|
|
* @return This function returns a handle to the file
|
|
|
|
|
* @param[in] fid Handle to the open file
|
|
|
|
|
* @param[in] varname Mesh name
|
|
|
|
|
* @param[in] subVarNames Names of the sub meshes in the form "filename:meshname"
|
|
|
|
|
* @param[in] subVarTypes Type of each submesh
|
|
|
|
|
* @param[in] ndim Dimension of variable (used to determine suffix)
|
|
|
|
|
* @param[in] nvar Number of subvariables (used to determine suffix)
|
|
|
|
|
*/
|
|
|
|
|
void writeMultiVar( DBfile* fid, const std::string& varname,
|
|
|
|
|
const std::vector<std::string>& subVarNames,
|
2017-01-31 08:22:29 -05:00
|
|
|
const std::vector<int>& subVarTypes );
|
2017-01-23 10:42:21 -05:00
|
|
|
|
2017-03-01 16:30:39 -05:00
|
|
|
|
2017-01-23 10:42:21 -05:00
|
|
|
}; // silo namespace
|
|
|
|
|
#endif
|
2017-03-01 16:30:39 -05:00
|
|
|
|
|
|
|
|
#include "IO/silo.hpp"
|
|
|
|
|
|