src/HDF5FileBuilder.cpp

Go to the documentation of this file.
00001 #include <new>
00002 #include <iostream>
00003 #include "HDF5FileBuilder.h"
00004 
00005 using namespace std;
00006 
00011 HDF5FileBuilder::HDF5FileBuilder(const char* outputFile)
00012     : _bc_face_counter(0) {
00013 
00014     // Open HDF5 file here
00015     cout << "Create file '" << outputFile << "': ";
00016     file = H5Fcreate(outputFile, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
00017     assert (file >= 0);    
00018     cout << "OK" << endl;
00019 }
00020 
00021 // File closing operations here
00022 HDF5FileBuilder::~HDF5FileBuilder() {
00023     cout << "Close file: "; 
00024     status = H5Fclose(file);
00025     assert (status >= 0);
00026     cout << "OK" << endl;
00027 }
00028 
00029 // Set on row in node coordinate matrix
00030 void HDF5FileBuilder::set_coord(int i, double x, double y, double z) {
00031     _coord[3*i + 0] = x;
00032     _coord[3*i + 1] = y;
00033     _coord[3*i + 2] = z;
00034 }
00035 
00036 // Initialize the node matrix as an mx3 matrix
00037 void HDF5FileBuilder::init_coord(int nof_node) {
00038     //allocate buffer 'n that's it.
00039     _nof_node = nof_node;
00040     _coord = new double[3*nof_node];    
00041 }
00042 
00043 // Flush node coordinate buffer 
00044 void HDF5FileBuilder::finalize_coord() {
00045 
00046     cout << ".Create node coordinate dataspace: ";
00047     dimsf[0]=_nof_node;
00048     dimsf[1]=3;
00049     pointspace = H5Screate_simple(2, dimsf, NULL); 
00050     assert (pointspace >= 0);
00051     cout << "OK" << endl;
00052 
00053     // Creating the dataset within the dataspace                      
00054     cout << "..Create coordinate dataset: ";
00055     points = H5Dcreate(file, "coords", REALFILETYPE, pointspace, H5P_DEFAULT);
00056     assert (points >= 0);
00057     cout << "OK" << endl;
00058     
00059     cout << "..Writing dataset to dataspace: ";
00060     status = H5Dwrite(points, REALMEMTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &_coord[0]);
00061     assert (status >= 0);
00062     cout << "OK" << endl;
00063 
00064     // Close the dataspaces and dataset
00065     cout << ".Close dataspace and dataset: ";
00066     status = H5Sclose(pointspace);
00067     assert (status >= 0);
00068     status = H5Dclose(points);
00069     assert (status >= 0);
00070     cout << "OK" << endl;
00071 
00072     // Free memory
00073     delete _coord;
00074 }
00075 
00076 //initialize tetrahedra mesh matrix
00077 void HDF5FileBuilder::init_tet(int nof_tet) {
00078    //allocate buffer 'n that's it.
00079     _nof_tet = nof_tet;
00080     _tet_node = new int[4*_nof_tet];    
00081     _material = new int[_nof_tet];    
00082 }
00083 
00084 //Set one row of matrix of node ids of nodes forming tetrahedron t 
00085 void HDF5FileBuilder::set_tet(int t, int id0, int id1, int id2, int id3, int material) {
00086     _tet_node[4*t + 0] = id0;
00087     _tet_node[4*t + 1] = id1;
00088     _tet_node[4*t + 2] = id2;
00089     _tet_node[4*t + 3] = id3;
00090     _material[t] = material;
00091 }
00092 
00093 // Flush terahedra buffer
00094 void HDF5FileBuilder::finalize_tet() {
00095     cout << ".Create tetrahedra nodes dataspace: ";
00096     dimsf[0]=_nof_tet;
00097     dimsf[1]=4;
00098     tetspace = H5Screate_simple(2, dimsf, NULL); 
00099     assert (tetspace >= 0);
00100     cout << "OK" << endl;
00101 
00102     // Creating the dataset within the dataspace                      
00103     cout << "..Create dataset: ";
00104     tets = H5Dcreate(file, "tetids", INTFILETYPE, tetspace, H5P_DEFAULT);
00105     assert (tets >= 0);
00106     cout << "OK" << endl;
00107 
00108     cout << "..Writing dataset to dataspace: ";
00109     status = H5Dwrite(tets, INTMEMTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &_tet_node[0]);
00110     assert (status >= 0);
00111     cout << "OK" << endl;
00112 
00113     // Close the dataspaces and dataset
00114     cout << ".Close dataspace and dataset: ";
00115     status = H5Sclose(tetspace);
00116     assert (status >= 0);
00117     status = H5Dclose(tets);
00118     assert (status >= 0);
00119     cout << "OK" << endl;
00120 
00121     // Free memory
00122     delete _tet_node;
00123 
00124 
00125     // 
00126     // OSCAR: Add the material indices stored in _material
00127     //
00128     cout << ".Create materials dataspace: ";
00129     dimsf[0]=_nof_tet;
00130     dimsf[1]=1;
00131     matspace = H5Screate_simple(2, dimsf, NULL); 
00132     assert (matspace >= 0);
00133     cout << "OK" << endl;
00134 
00135     // Creating the dataset within the dataspace                      
00136     cout << "..Create dataset: ";
00137     mats = H5Dcreate(file, "matids", INTFILETYPE, matspace, H5P_DEFAULT);
00138     assert (mats >= 0);
00139     cout << "OK" << endl;
00140 
00141     cout << "..Writing dataset to dataspace: ";
00142     status = H5Dwrite(mats, INTMEMTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &_material[0]);
00143     assert (status >= 0);
00144     cout << "OK" << endl;
00145 
00146     // Close the dataspaces and dataset
00147     cout << ".Close dataspace and dataset: ";
00148     status = H5Sclose(matspace);
00149     assert (status >= 0);
00150     status = H5Dclose(mats);
00151     assert (status >= 0);
00152     cout << "OK" << endl;
00153 
00154     // Free memory
00155     delete _material;
00156    
00157 }
00158 
00159 //Initialize boundary face matrix
00160 void HDF5FileBuilder::init_bc(int nof_bc_face) {
00161    //allocate buffer 'n that's it.
00162     _nof_bc_face = nof_bc_face;
00163     _bc_face = new int[4*_nof_bc_face];    
00164 
00165     _bc_face_counter = 0; //Face iterator set to zero
00166 }
00167 
00168 //Set one row of boundary condition bc_id to boundary triangle formed of nodes id0, id1 and id2.
00169 void HDF5FileBuilder::set_bc(int id0, int id1, int id2, int bc_id) {
00170 
00171     _bc_face[4*_bc_face_counter + 0] = bc_id;
00172     _bc_face[4*_bc_face_counter + 1] = id0;
00173     _bc_face[4*_bc_face_counter + 2] = id1;
00174     _bc_face[4*_bc_face_counter + 3] = id2;
00175 
00176     _bc_face_counter++;
00177 }
00178 
00180 void HDF5FileBuilder::finalize_bc(int nof_sym) {
00181     cout << ".Create boundary/symmetry face dataspace: ";
00182     dimsf[0]=_nof_bc_face;
00183     dimsf[1]=4;
00184     edgespace = H5Screate_simple(2, dimsf, NULL); 
00185     assert (edgespace >= 0);
00186     cout << "OK" << endl;
00187 
00188     // Creating the dataset within the dataspace                      
00189     cout << "..Create dataset: ";
00190     edges = H5Dcreate(file, "surface", INTFILETYPE, edgespace, H5P_DEFAULT);
00191     assert (edges >= 0);
00192     cout << "OK" << endl;
00193 
00194     cout << "..Writing dataset to dataspace: ";
00195     status = H5Dwrite(edges, INTMEMTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &_bc_face[0]);
00196     assert (status >= 0);
00197     cout << "OK" << endl;
00198 
00199     // Close the dataspaces and dataset
00200     cout << ".Close dataspace and dataset: ";
00201     status = H5Sclose(edgespace);
00202     assert (status >= 0);
00203     status = H5Dclose(edges);
00204     assert (status >= 0);
00205     cout << "OK" << endl;
00206 
00207     // Free memory
00208     delete _bc_face;
00209 }

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