00001 #include "velreader2d.h" 00002 #include<iostream> 00003 #include<fstream> 00004 using namespace std; 00005 VelReader2D::VelReader2D(std::string filename,OrthoMesh &mesh) 00006 :mesh(mesh) 00007 { 00008 file=filename; 00009 m_vFNC.reinit(mesh.numFaces()); 00010 } 00011 00012 00013 void VelReader2D::getNormalVelocityAtFaces(VecDouble &vFNC) 00014 { 00015 vFNC=m_vFNC; 00016 00017 } 00018 void VelReader2D::printOutput() 00019 { 00020 } 00021 00022 00023 void VelReader2D::iterate(TransportBase &trans) 00024 { 00025 00026 OrthoMesh::Cell_It cell = mesh.begin_cell(); 00027 OrthoMesh::Cell_It endc = mesh.end_cell(); 00028 std::ifstream indata; 00029 indata.open(file.c_str()); 00030 if (!indata) 00031 { 00032 throw new Exception("VelReader2D: File %s does not exist",file.c_str()); 00033 00034 } 00035 for(;cell!=endc;cell++) 00036 { 00037 double data1,data2,data3,data4; 00038 00039 /*indata.open(file.c_str()); 00040 if (!indata) 00041 { 00042 throw new Exception("VelReader2D: File %s does not exist",file.c_str()); 00043 00044 }*/ 00045 m_vFNC(cell->face_index_up()) = 0; 00046 m_vFNC(cell->face_index_bottom()) =0; 00047 /*indata >>data1; 00048 indata >>data2; 00049 indata >>data3; 00050 indata >>data4; 00051 m_vFNC(cell->face_index_left())=data1; 00052 m_vFNC(cell->face_index_right())=data2; 00053 m_vFNC(cell->face_index_front())=data3; 00054 m_vFNC(cell->face_index_back())=data4;*/ 00055 indata >>data1; 00056 if(indata.eof()) 00057 throw new Exception("VelReader2D:Data file has %d lines and we expected %d lines",cell->index()+1,m_vFNC.size()); 00058 00059 m_vFNC(cell->face_index_left())=-data1; 00060 indata >>data2; 00061 m_vFNC(cell->face_index_right())=data2; 00062 indata >>data3; 00063 m_vFNC(cell->face_index_front())=-data3; 00064 indata >>data4; 00065 m_vFNC(cell->face_index_back())=data4; 00066 //indata.close(); 00067 //throw new Exception("End of the file reached"); 00068 00069 } 00070 indata.close(); 00071 if(indata.eof()) 00072 throw new Exception("VelReader2D:Data file has more lines than expected. It should have %d lines",mesh.numCells()); 00073 00074 /*DEBUG PURPOSES 00075 cout<< "Printing m_vFNC vector"<< m_vFNC.size()<<"\n"; 00076 00077 for(int i= 0;i< m_vFNC.size();i++) 00078 { 00079 //throw new Exception("The face number:%d fluid field:%f\n ",i,m_vFNC(i)); 00080 cout<< "The face number: "<< i <<" fluid field: "<< m_vFNC(i)<< "\n"; 00081 }*/ 00082 00083 } 00084 00085 00086 void VelReader2D::getVelocitiesAtFaces(Matrix &vel) 00087 { 00088 assert(vel.m() == mesh.numFaces() && vel.n() == 3); 00089 00090 vel = 0.0; 00091 //Get the face iterator and the number of faces. 00092 OrthoMesh::Face_It face = mesh.begin_face(); 00093 OrthoMesh::Face_It endf = mesh.end_face(); 00094 00095 //For each face 00096 for (;face!=endf;face++) 00097 { 00098 vel(face->index(),face->getNormalOrientation()) = m_vFNC(face->index()); 00099 } 00100 00101 }