SundanceFieldWriterBase.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 "SundanceFieldWriterBase.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 FieldWriterBase::FieldWriterBase(const std::string& filename) 
00044   : filename_(filename),
00045     mesh_(),
00046     nProc_(0), 
00047     myRank_(-1),
00048     meshID_(-1),
00049     comments_(),
00050     pointScalarFields_(),
00051     cellScalarFields_(),
00052     pointVectorFields_(),
00053     cellVectorFields_(),
00054     pointScalarNames_(),
00055     cellScalarNames_(),
00056     pointVectorNames_(),
00057     cellVectorNames_(),
00058     undefinedValue_(0.0)
00059 {;}
00060 
00061 
00062 void FieldWriterBase::impersonateParallelProc(int nProc, int rank)
00063 {
00064   nProc_ = nProc;
00065   myRank_ = rank;
00066 }
00067 
00068 int FieldWriterBase::nProc() const
00069 {
00070   if (nProc_ < 1) return mesh().comm().getNProc(); 
00071   return nProc_;
00072 }
00073 
00074 int FieldWriterBase::myRank() const
00075 {
00076   if (myRank_ < 0) return mesh().comm().getRank(); 
00077   return myRank_;
00078 }
00079 
00080 
00081 
00082 
00083 void FieldWriterBase::addMesh(const Mesh& mesh) 
00084 {
00085   if (meshID_ < 0)
00086     {
00087       mesh_ = mesh;
00088       meshID_ = mesh.id();
00089     }
00090                      
00091   TEUCHOS_TEST_FOR_EXCEPTION(meshID_ != mesh.id(), std::runtime_error,
00092                      "FieldWriterBase::setMesh(): inconsistent meshes: "
00093                      "existing mesh has meshID=" << meshID_ << ", newly "
00094                      "added mesh has meshID=" << mesh.id());
00095 }
00096 
00097 void FieldWriterBase::addField(const std::string& name, 
00098                                const RCP<FieldBase>& expr) 
00099 {
00100 
00101   std::string fieldName = name;
00102 
00103   if (expr->numElems() > 1)
00104     {
00105       //TEUCHOS_TEST_FOR_EXCEPTION(expr->numElems() > 1, std::runtime_error,
00106       //                   "FieldWriterBase::addField not ready for vector fields");
00107 
00108     std::cout << "WARNING! : expr->numElems() > 1 , FieldWriterBase::addField only VTK can plot vector field " << std::endl;
00109     std::cout << "WARNING! : All expressions(in the list of the expressions) must be of the same kind!!! " << std::endl;
00110     /* Vector field plotting should be implemented for VTK files */
00111     /* We assume that all the expressions are the same !!!! */
00112     if (expr->isPointData()){
00113       pointVectorFields_.append(expr);
00114       pointVectorNames_.append(fieldName);
00115     }else{
00116       cellVectorFields_.append(expr);
00117       cellVectorNames_.append(fieldName);
00118     }
00119 
00120     } 
00121   else if (expr->isPointData()) 
00122     {
00123       /* expr is a single scalar field defined at points */
00124       pointScalarFields_.append(expr);
00125       pointScalarNames_.append(fieldName);
00126     }
00127   else if (expr->isCellData())
00128     {
00129       /* expr is a single scalar field defined on cells */
00130       cellScalarFields_.append(expr);
00131       cellScalarNames_.append(fieldName);
00132     }
00133 }
00134 
00135 void FieldWriterBase::addCommentLine(const std::string& line) 
00136 {
00137   comments_.append(line);
00138 }
00139 
00140 
00141 
00142 
00143 
00144 

Site Contact