SundanceFieldWriterBase.hpp
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 #ifndef SUNDANCE_FIELDWRITERBASE_H
00032 #define SUNDANCE_FIELDWRITERBASE_H
00033 
00034 
00035 #include "SundanceDefs.hpp"
00036 #include "SundanceMesh.hpp"
00037 #include "SundanceFieldBase.hpp"
00038 
00039 namespace Sundance
00040 {
00041 using namespace Teuchos;
00042 /**
00043  * FieldWriterBase is a base class for objects that write fields
00044  * and/or meshes to a stream. 
00045  */
00046 class FieldWriterBase : public Playa::Handleable<FieldWriterBase>,
00047                         public ObjectWithClassVerbosity<FieldWriterBase>
00048 {
00049 public:
00050   /** */
00051   FieldWriterBase(const std::string& filename);
00052 
00053   /** virtual dtor */
00054   virtual ~FieldWriterBase(){;}
00055 
00056   /** */
00057   void addMesh(const Mesh& mesh);
00058 
00059   /** add a comment */
00060   virtual void addCommentLine(const std::string& line) ;
00061 
00062   /** add a field, tagging it with the given std::string as a name */
00063   virtual void addField(const std::string& name, 
00064     const RCP<FieldBase>& field) ;
00065 
00066   /** */
00067   virtual void write() const = 0 ;
00068 
00069   /**  */
00070   virtual void impersonateParallelProc(int nProc, int rank) ;
00071 
00072   /** set the numerical value to be written at cells on which
00073    * a field is undefined. */
00074   void setUndefinedValue(const double& x) {undefinedValue_ = x;}
00075 
00076 protected:
00077 
00078   /** */
00079   double undefinedValue() const {return undefinedValue_;}
00080   /** */
00081   int nProc() const ;
00082 
00083   /** */
00084   int myRank() const ;
00085 
00086   /** */
00087   const std::string& filename() const {return filename_;}
00088 
00089   /** */
00090   const Mesh& mesh() const {return mesh_;}
00091 
00092   /** Indicate whether the given writer subtype does anything special
00093    * for vector fields. Default is false, in which case
00094    * vectors are simply written as a list of scalars.
00095    */
00096   virtual bool supportsSpecializedVectors() const {return false;}
00097 
00098   const Array<string>& comments() const {return comments_;}
00099   Array<string>& comments() {return comments_;}
00100 
00101   const Array<RCP<FieldBase> >& pointScalarFields() const {return pointScalarFields_;}
00102   Array<RCP<FieldBase> >& pointScalarFields() {return pointScalarFields_;}
00103 
00104   const Array<RCP<FieldBase> >& cellScalarFields() const {return cellScalarFields_;}
00105   Array<RCP<FieldBase> >& cellScalarFields() {return cellScalarFields_;}
00106 
00107   const Array<string>& pointScalarNames() const {return pointScalarNames_;}
00108   Array<string>& pointScalarNames() {return pointScalarNames_;}
00109 
00110   const Array<string>& cellScalarNames() const {return cellScalarNames_;}
00111   Array<string>& cellScalarNames() {return cellScalarNames_;}
00112 
00113   const Array<RCP<FieldBase> >& pointVectorFields() const {return pointVectorFields_;}
00114   Array<RCP<FieldBase> >& pointVectorFields() {return pointVectorFields_;}
00115 
00116   const Array<RCP<FieldBase> >& cellVectorFields() const {return cellVectorFields_;}
00117   Array<RCP<FieldBase> >& cellVectorFields() {return cellVectorFields_;}
00118 
00119   const Array<string>& pointVectorNames() const {return pointVectorNames_;}
00120   Array<string>& pointVectorNames() {return pointVectorNames_;}
00121 
00122   const Array<string>& cellVectorNames() const {return cellVectorNames_;}
00123   Array<string>& cellVectorNames() {return cellVectorNames_;}
00124 
00125   virtual void writeCommentLine(const std::string& line) const {;}
00126 
00127 private:
00128   std::string filename_;
00129 
00130   Mesh mesh_;
00131 
00132   int nProc_;
00133 
00134   int myRank_;
00135 
00136   int meshID_;
00137 
00138   Array<string> comments_;
00139 
00140   Array<RCP<FieldBase> > pointScalarFields_;
00141   Array<RCP<FieldBase> > cellScalarFields_;
00142   Array<RCP<FieldBase> > pointVectorFields_;
00143   Array<RCP<FieldBase> > cellVectorFields_;
00144   Array<string> pointScalarNames_;
00145   Array<string> cellScalarNames_;
00146   Array<string> pointVectorNames_;
00147   Array<string> cellVectorNames_;
00148 
00149   double undefinedValue_;
00150 };
00151 
00152 /**
00153  * FieldWriterFactoryBase
00154  */
00155 class FieldWriterFactoryBase : public Playa::Handleable<FieldWriterFactoryBase>
00156 {
00157 public:
00158   /** Create a writer with the specified filename */
00159   virtual RCP<FieldWriterBase> createWriter(const string& name) const = 0 ;
00160 }; 
00161 
00162 }
00163 
00164 
00165 
00166 #endif

Site Contact