SundanceTriangleWriter.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #include "SundanceTriangleWriter.hpp"
00032 #include "PlayaExceptions.hpp"
00033 #include "SundanceOut.hpp"
00034 #include "PlayaTabs.hpp"
00035 
00036 
00037 using namespace Sundance;
00038 using namespace Sundance;
00039 using namespace Sundance;
00040 using namespace Teuchos;
00041 
00042 
00043 void TriangleWriter::write() const 
00044 {
00045   std::string f = filename();
00046   if (nProc() > 1) f = f + Teuchos::toString(myRank());
00047 
00048   /* write header information on root proc only */
00049   if (nProc() > 1 && myRank()==0) writeHeader(filename());
00050 
00051   /* write local mesh on all procs */
00052   writePoints(f);
00053   writeCells(f);
00054   writeEdges(f);
00055   if (mesh().spatialDim() > 2)
00056     {
00057       writeFaces(f);
00058     }
00059   if (nProc() > 1) writeParallelInfo(f);
00060 }
00061 
00062 void TriangleWriter::writeHeader(const std::string& filename) const 
00063 {
00064   std::string hdrfile = filename + ".hdr";
00065   std::ofstream os(hdrfile.c_str());
00066 
00067   os << nProc() << std::endl;
00068   for (int p=0; p<nProc(); p++) 
00069     {
00070       os << filename + Teuchos::toString(p) << std::endl;
00071     }
00072 
00073   os << pointScalarNames().length() << std::endl;
00074   for (int i=0; i<pointScalarNames().length(); i++)
00075     {
00076       os << i << " " << pointScalarNames()[i] << std::endl;
00077     }
00078   os << cellScalarNames().length() << std::endl;
00079   for (int i=0; i<cellScalarNames().length(); i++)
00080     {
00081       os << i << " " << cellScalarNames()[i] << std::endl;
00082     }
00083   
00084   for (int i=0; i<comments().length(); i++)
00085     {
00086       os << "# " << comments()[i] << std::endl;
00087     }
00088 }
00089 
00090 
00091 void TriangleWriter::writePoints(const std::string& filename) const 
00092 {
00093   int nPts = mesh().numCells(0);
00094   int dim = mesh().spatialDim();
00095   int nAttr = pointScalarFields().length();
00096   int nBdryMarkers = 0;
00097 
00098   std::string nodefile = filename + ".node";
00099   std::ofstream os(nodefile.c_str());
00100 
00101   os << nPts << " " << dim << " " << nAttr << " " << nBdryMarkers << std::endl;
00102 
00103   for (int i=0; i<nPts; i++)
00104     {
00105       os << i+indexOffset_;
00106       const Point& x = mesh().nodePosition(i);
00107       for (int d=0; d<dim; d++)
00108         {
00109           os << " " << x[d];
00110         }
00111       /*
00112       for (int f=0; f<nAttr; f++)
00113         {
00114           double val = pointScalarFields()[f].probeAtMeshPoint(i);
00115           os << " " << val;
00116         }
00117       */
00118       for (int b=0; b<nBdryMarkers; b++)
00119         {
00120     //bvbw          SUNDANCE_ERROR("Boundary markers not supported yet");
00121     assert(0);
00122         }
00123       os << std::endl;
00124     }
00125   
00126   for (int i=0; i<comments().length(); i++)
00127     {
00128       os << "# " << comments()[i] << std::endl;
00129     }
00130 }
00131 
00132 void TriangleWriter::writeFaces(const std::string& filename) const 
00133 {
00134   std::string facefile = filename + ".face";
00135   std::ofstream os(facefile.c_str());
00136 
00137   int dim = 2;
00138   int nFaces = mesh().numCells(dim);
00139   int dummySign;
00140 
00141   os << nFaces << " 0" << std::endl;
00142 
00143   for (int c=0; c<nFaces; c++)
00144     {
00145       os << c + indexOffset_;
00146       int nNodes = 3;
00147       
00148       for (int i=0; i<nNodes; i++)
00149         {
00150           os << " " << mesh().facetLID(2,c,0,i,dummySign) + indexOffset_;
00151         }
00152       os << std::endl;
00153     }
00154   
00155   for (int i=0; i<comments().length(); i++)
00156     {
00157       os << "# " << comments()[i] << std::endl;
00158     }
00159 }
00160 
00161 void TriangleWriter::writeEdges(const std::string& filename) const 
00162 {
00163   std::string edgefile = filename + ".edge";
00164   std::ofstream os(edgefile.c_str());
00165 
00166   int dim = 1;
00167   int nEdges = mesh().numCells(dim);
00168   int nNodes = 2;
00169   int dummySign;
00170 
00171   os << nEdges << " 0" << std::endl;
00172 
00173   for (int c=0; c<nEdges; c++)
00174     {
00175       os << c + indexOffset_;
00176       for (int i=0; i<nNodes; i++)
00177         {
00178           os << " " << mesh().facetLID(1,c,0,i,dummySign) + indexOffset_;
00179         }
00180       os << std::endl;
00181     }
00182   
00183   for (int i=0; i<comments().length(); i++)
00184     {
00185       os << "# " << comments()[i] << std::endl;
00186     }
00187 }
00188 
00189 void TriangleWriter::writeCells(const std::string& filename) const 
00190 {
00191   std::string elefile = filename + ".ele";
00192   std::ofstream os(elefile.c_str());
00193 
00194   int dim = mesh().spatialDim();
00195   int nCells = mesh().numCells(dim);
00196   int nAttr = cellScalarFields().length();
00197   int dummySign;
00198 
00199   os << nCells << " " << dim+1 << " " << nAttr << std::endl;
00200 
00201   for (int c=0; c<nCells; c++)
00202     {
00203       os << c + indexOffset_;
00204       int nNodes = dim+1;
00205       
00206       for (int i=0; i<nNodes; i++)
00207         {
00208           os << " " << mesh().facetLID(dim,c,0,i,dummySign) + indexOffset_;
00209         }
00210       /*
00211       for (int f=0; f<nAttr; f++)
00212         {
00213           os << " " << cellScalarFields()[f].average(cell).value();
00214         }
00215       */
00216       os << std::endl;
00217     }
00218   
00219   for (int i=0; i<comments().length(); i++)
00220     {
00221       os << "# " << comments()[i] << std::endl;
00222     }
00223 }
00224 
00225 
00226 void TriangleWriter::writeParallelInfo(const std::string& filename) const 
00227 {
00228   std::string parfile = filename + ".par";
00229   std::ofstream os(parfile.c_str());
00230 
00231   int dim = mesh().spatialDim();
00232   int nCells = mesh().numCells(dim);
00233   int nEdges = mesh().numCells(1);
00234   int nPts = mesh().numCells(0);
00235 
00236   os << myRank() << " " << nProc() << std::endl;
00237 
00238   os << nPts << std::endl;
00239   for (int i=0; i<nPts; i++)
00240     {
00241       os << i << " " << mesh().mapLIDToGID(0,i) 
00242          << " " << mesh().ownerProcID(0,i) << std::endl;
00243     }
00244 
00245   os << nCells << std::endl;
00246   for (int c=0; c<nCells; c++)
00247     {
00248       os << c << " " << mesh().mapLIDToGID(dim,c) 
00249          << " " << mesh().ownerProcID(dim,c) << std::endl;
00250     }
00251 
00252   os << nEdges << std::endl;
00253   for (int c=0; c<nEdges; c++)
00254     {
00255       os << c << " " << mesh().mapLIDToGID(1,c) 
00256          << " " << mesh().ownerProcID(1,c) << std::endl;
00257     }
00258 
00259   if (dim > 2)
00260     {
00261       int nFaces = mesh().numCells(2);
00262       os << nFaces << std::endl;
00263       for (int c=0; c<nFaces; c++)
00264         {
00265           os << c << " " << mesh().mapLIDToGID(2,c) 
00266              << " " << mesh().ownerProcID(2,c) << std::endl;
00267         }
00268     }
00269   
00270   for (int i=0; i<comments().length(); i++)
00271     {
00272       os << "# " << comments()[i] << std::endl;
00273     }
00274 }
00275 
00276 

Site Contact