SundanceFieldWriterBase.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #ifndef SUNDANCE_FIELDWRITERBASE_H
00043 #define SUNDANCE_FIELDWRITERBASE_H
00044 
00045 
00046 #include "SundanceDefs.hpp"
00047 #include "SundanceMesh.hpp"
00048 #include "SundanceFieldBase.hpp"
00049 
00050 namespace Sundance
00051 {
00052 using namespace Teuchos;
00053 /**
00054  * FieldWriterBase is a base class for objects that write fields
00055  * and/or meshes to a stream. 
00056  */
00057 class FieldWriterBase : public Playa::Handleable<FieldWriterBase>,
00058                         public ObjectWithClassVerbosity<FieldWriterBase>
00059 {
00060 public:
00061   /** */
00062   FieldWriterBase(const std::string& filename);
00063 
00064   /** virtual dtor */
00065   virtual ~FieldWriterBase(){;}
00066 
00067   /** */
00068   void addMesh(const Mesh& mesh);
00069 
00070   /** add a comment */
00071   virtual void addCommentLine(const std::string& line) ;
00072 
00073   /** add a field, tagging it with the given std::string as a name */
00074   virtual void addField(const std::string& name, 
00075     const RCP<FieldBase>& field) ;
00076 
00077   /** */
00078   virtual void write() const = 0 ;
00079 
00080   /**  */
00081   virtual void impersonateParallelProc(int nProc, int rank) ;
00082 
00083   /** set the numerical value to be written at cells on which
00084    * a field is undefined. */
00085   void setUndefinedValue(const double& x) {undefinedValue_ = x;}
00086 
00087 protected:
00088 
00089   /** */
00090   double undefinedValue() const {return undefinedValue_;}
00091   /** */
00092   int nProc() const ;
00093 
00094   /** */
00095   int myRank() const ;
00096 
00097   /** */
00098   const std::string& filename() const {return filename_;}
00099 
00100   /** */
00101   const Mesh& mesh() const {return mesh_;}
00102 
00103   /** Indicate whether the given writer subtype does anything special
00104    * for vector fields. Default is false, in which case
00105    * vectors are simply written as a list of scalars.
00106    */
00107   virtual bool supportsSpecializedVectors() const {return false;}
00108 
00109   const Array<string>& comments() const {return comments_;}
00110   Array<string>& comments() {return comments_;}
00111 
00112   const Array<RCP<FieldBase> >& pointScalarFields() const {return pointScalarFields_;}
00113   Array<RCP<FieldBase> >& pointScalarFields() {return pointScalarFields_;}
00114 
00115   const Array<RCP<FieldBase> >& cellScalarFields() const {return cellScalarFields_;}
00116   Array<RCP<FieldBase> >& cellScalarFields() {return cellScalarFields_;}
00117 
00118   const Array<string>& pointScalarNames() const {return pointScalarNames_;}
00119   Array<string>& pointScalarNames() {return pointScalarNames_;}
00120 
00121   const Array<string>& cellScalarNames() const {return cellScalarNames_;}
00122   Array<string>& cellScalarNames() {return cellScalarNames_;}
00123 
00124   const Array<RCP<FieldBase> >& pointVectorFields() const {return pointVectorFields_;}
00125   Array<RCP<FieldBase> >& pointVectorFields() {return pointVectorFields_;}
00126 
00127   const Array<RCP<FieldBase> >& cellVectorFields() const {return cellVectorFields_;}
00128   Array<RCP<FieldBase> >& cellVectorFields() {return cellVectorFields_;}
00129 
00130   const Array<string>& pointVectorNames() const {return pointVectorNames_;}
00131   Array<string>& pointVectorNames() {return pointVectorNames_;}
00132 
00133   const Array<string>& cellVectorNames() const {return cellVectorNames_;}
00134   Array<string>& cellVectorNames() {return cellVectorNames_;}
00135 
00136   virtual void writeCommentLine(const std::string& line) const {;}
00137 
00138 private:
00139   std::string filename_;
00140 
00141   Mesh mesh_;
00142 
00143   int nProc_;
00144 
00145   int myRank_;
00146 
00147   int meshID_;
00148 
00149   Array<string> comments_;
00150 
00151   Array<RCP<FieldBase> > pointScalarFields_;
00152   Array<RCP<FieldBase> > cellScalarFields_;
00153   Array<RCP<FieldBase> > pointVectorFields_;
00154   Array<RCP<FieldBase> > cellVectorFields_;
00155   Array<string> pointScalarNames_;
00156   Array<string> cellScalarNames_;
00157   Array<string> pointVectorNames_;
00158   Array<string> cellVectorNames_;
00159 
00160   double undefinedValue_;
00161 };
00162 
00163 /**
00164  * FieldWriterFactoryBase
00165  */
00166 class FieldWriterFactoryBase : public Playa::Handleable<FieldWriterFactoryBase>
00167 {
00168 public:
00169   /** Create a writer with the specified filename */
00170   virtual RCP<FieldWriterBase> createWriter(const string& name) const = 0 ;
00171 }; 
00172 
00173 }
00174 
00175 
00176 
00177 #endif

Site Contact