src/netgenreader.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           netgenreader.cpp  -  description
00003                              -------------------
00004     begin                : Fri Dec 12 2003
00005     copyright            : (C) 2003 by Roman Geus
00006     email                : roman.geus@psi.ch
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <cassert>
00019 
00020 #include "ioerror.h"
00021 #include "netgenreader.h"
00022 
00023 using namespace std;
00024 
00025 NetgenReader::~NetgenReader() {
00026 }
00027 
00028 NetgenReader::NetgenReader(istream* istr, MeshBuilder* builder)
00029     : _istr(istr), _builder(builder) {}
00030 
00031 void NetgenReader::read() {
00032     const string file_name = "<input stream>";
00033     istream& istr = *_istr;
00034 
00035     int line = 0;
00036 
00037     // read number of nodes
00038     int nof_node;
00039     istr >> nof_node;
00040     line ++;
00041     if (istr.fail())
00042         throw FileIOError(file_name, line, "error reading number of nodes");
00043     _builder->init_coord(nof_node);
00044 
00045     // read node coordinates
00046     double x, y, z;
00047     for (int i = 0; i < nof_node; i ++) {
00048         istr >> x >> y >> z;
00049         line ++;
00050         if (istr.fail())
00051             throw FileIOError(file_name, line, "error reading node coordinates");
00052         _builder->set_coord(i, x, y, z);
00053     }
00054     _builder->finalize_coord();
00055 
00056     // read number of tets
00057     int nof_tet;
00058     istr >> nof_tet;
00059     line ++;
00060     if (istr.fail())
00061         throw FileIOError(file_name, line, "error reading number of elements");
00062     _builder->init_tet(nof_tet);
00063 
00064     // read tetnode
00065     int node_ids[4], node_id, mat;
00066     for (int t = 0; t < nof_tet; t ++) {
00067         istr >> mat;
00068         for (int i = 0; i < 4; i ++) {
00069             istr >> node_id;
00070             node_id --;
00071             if (node_id < 0 || node_id >= nof_node)
00072                 throw FileIOError(file_name, line, "node number out of range");
00073             node_ids[i] = node_id;
00074         }
00075         line ++;
00076         if (istr.fail())
00077             throw FileIOError(file_name, line, "error reading node numbers");
00078         _builder->set_tet(t, node_ids[0], node_ids[1], node_ids[2], node_ids[3], mat);
00079     }
00080     _builder->finalize_tet();
00081 
00082     // read number of boundary faces
00083     int nof_bc_face;
00084     istr >> nof_bc_face;
00085     line ++;
00086     if (istr.fail())
00087         throw FileIOError(file_name, line, "error reading number of boundary faces");
00088     _builder->init_bc(nof_bc_face);
00089 
00090     // read boundary face data
00091     int nof_bc[4] = {0, 0, 0, 0};
00092     int face_node[3];
00093     for (int i = 0; i < nof_bc_face; i ++) {
00094         int bc_id;
00095         istr >> bc_id;
00096         nof_bc[bc_id] += 1;
00097         for (int j = 0; j < 3; j ++) {
00098             istr >> node_id;
00099             node_id --;
00100             if (node_id < 0 || node_id >= nof_node)
00101                 throw FileIOError(file_name, line, "node number out of range");
00102             face_node[j] = node_id;
00103         }
00104         line ++;
00105         if (istr.fail())
00106             throw FileIOError(file_name, line, "error reading boundary data");
00107         _builder->set_bc(face_node[0], face_node[1], face_node[2], bc_id);
00108     }
00109 
00110     // symmetry planes
00111     int nof_sym;
00112     for (nof_sym = 3; nof_sym >= 0 && nof_bc[nof_sym] == 0; nof_sym --);
00113   
00114     assert(nof_sym >= 0);
00115     for (int i = 1; i < nof_sym; i ++)
00116         if (nof_bc[i] == 0)
00117             throw FileIOError(file_name, "empty symmetry plane detected");
00118     _builder->finalize_bc(nof_sym);
00119 }

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