src/HDF5Reader.cpp

Go to the documentation of this file.
00001 #include "HDF5Reader.h"
00002 using namespace std;
00003 
00009 HDF5Reader::~HDF5Reader() {
00010 //File closing operations here
00011     cout << "Close file: "; 
00012     _status = H5Fclose(_file);
00013     assert (_status >= 0);
00014     cout << "OK" << endl;
00015 }
00016 
00017 HDF5Reader::HDF5Reader(const char* inputFile, MeshBuilder* builder)
00018     : _builder(builder), _inputFile(inputFile), _dataset(0) {
00019 
00020 // Open HDF5 file here
00021     _file = H5Fopen(_inputFile, H5F_ACC_RDONLY, H5P_DEFAULT);
00022     assert(_file  >= 0);
00023     if (_file < 0)
00024         throw FileIOError(_inputFile, "error opening file");
00025     
00026 
00027 }
00028 void HDF5Reader::read() {
00029 
00030 //Read number of nodes
00031     _dataset = H5Dopen(_file, "/coords");
00032     hid_t x = H5Dget_space(_dataset);
00033     H5Sget_simple_extent_dims(x, _dimsf, NULL);
00034     _nof_node = _dimsf[0];
00035     _builder->init_coord(_nof_node); //initialize builder with number of nodes
00036 
00037 //Read node coordinates
00038     double* nodes = new double[_dimsf[0] * _dimsf[1]];
00039     _status = H5Dread(_dataset, REALMEMTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nodes[0]);
00040     assert (_status >=0);
00041 
00042     for (int i = 0; i < _nof_node; i ++) {
00043         _builder->set_coord(i, nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]);
00044     }
00045 
00046     delete nodes;
00047     _builder->finalize_coord();
00048 
00049 //Read number of tets
00050     _dataset = H5Dopen(_file, "/tetids");
00051     x = H5Dget_space(_dataset);
00052     H5Sget_simple_extent_dims(x, _dimsf, NULL);
00053     int nof_tets = _dimsf[0];
00054     _builder->init_coord(nof_tets);
00055 
00056 //Read tetnodes and materials
00057     int* tetids = new int[_dimsf[0] * _dimsf[1]];
00058     _status = H5Dread(_dataset, INTMEMTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &tetids[0]);
00059     assert (_status >=0);
00060 
00061 //Read number of materials
00062     _dataset = H5Dopen(_file, "/matids");
00063     x = H5Dget_space(_dataset);
00064     H5Sget_simple_extent_dims(x, _dimsf, NULL);
00065 
00066     //Read tetnodes and materials
00067     int* matids = new int[_dimsf[0]];
00068     _status = H5Dread(_dataset, INTMEMTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &matids[0]);
00069     assert (_status >=0);
00070 
00071     for (int i = 0; i < nof_tets; i ++) {
00072       _builder->set_tet(i, tetids[4 * i], tetids[4 * i + 1], tetids[4 * i + 2], tetids[4 * i + 3], matids[i]);
00073     }
00074 
00075     delete tetids;
00076     delete matids;
00077     _builder->finalize_tet();
00078 
00079 //Read number of boundary faces
00080     _dataset = H5Dopen(_file, "/surface");
00081     x = H5Dget_space(_dataset);
00082     H5Sget_simple_extent_dims(x, _dimsf, NULL);
00083     int nof_bc_face = _dimsf[0];
00084     _builder->init_coord(nof_bc_face);
00085 
00086 //Read boundary face data
00087     int* faceids = new int[_dimsf[0] * _dimsf[1]];
00088     _status = H5Dread(_dataset, INTMEMTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &faceids[0]);
00089     assert (_status >=0);
00090 
00091     int nof_bc[4] = {0, 0, 0, 0};
00092     for (int i = 0; i < nof_bc_face; i ++) {
00093         nof_bc[faceids[4 * i]] += 1;
00094         _builder->set_bc(faceids[4 * i + 1], faceids[4 * i + 2], faceids[4 * i + 3], faceids[4 * i]);
00095     }
00096     
00097 //Symmetry planes
00098     int nof_sym;
00099     for (nof_sym = 3; nof_sym >= 0 && nof_bc[nof_sym] == 0; nof_sym --);
00100     
00101     assert(nof_sym >= 0);
00102     for (int i = 1; i < nof_sym; i ++)
00103         if(nof_bc[i] == 0)
00104             throw FileIOError(_inputFile, "empty symmetry plane detected");
00105             
00106     delete faceids;
00107     _builder->finalize_bc(nof_sym);
00108 
00109 }
00110 

Generated on Fri Oct 26 13:35:12 2007 for FEMAXX (Finite Element Maxwell Eigensolver) by  doxygen 1.4.7