avtBoxlibFileFormat.h

00001 /*****************************************************************************
00002 *
00003 * Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC
00004 * Produced at the Lawrence Livermore National Laboratory
00005 * LLNL-CODE-442911
00006 * All rights reserved.
00007 *
00008 * This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
00009 * full copyright notice is contained in the file COPYRIGHT located at the root
00010 * of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
00011 *
00012 * Redistribution  and  use  in  source  and  binary  forms,  with  or  without
00013 * modification, are permitted provided that the following conditions are met:
00014 *
00015 *  - Redistributions of  source code must  retain the above  copyright notice,
00016 *    this list of conditions and the disclaimer below.
00017 *  - Redistributions in binary form must reproduce the above copyright notice,
00018 *    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
00019 *    documentation and/or other materials provided with the distribution.
00020 *  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
00021 *    be used to endorse or promote products derived from this software without
00022 *    specific prior written permission.
00023 *
00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
00025 * AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
00027 * ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
00028 * LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
00029 * DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
00030 * DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
00031 * SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
00032 * CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
00033 * LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
00034 * OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00035 * DAMAGE.
00036 *
00037 *****************************************************************************/
00038 
00039 // ************************************************************************* //
00040 //                         avtBoxlibFileFormat.h                             //
00041 // ************************************************************************* //
00042 
00043 #ifndef AVT_BOXLIB_FILE_FORMAT_H
00044 #define AVT_BOXLIB_FILE_FORMAT_H
00045 
00046 #include <avtSTMDFileFormat.h>
00047 
00048 #include <vector>
00049 #include <string>
00050 
00051 class VisMF;
00052 
00053 // ****************************************************************************
00054 //  Class: avtBoxlibFileFormat
00055 //
00056 //  Purpose:
00057 //      A file format reader for single-timestep, 3D AMR Boxlib files.
00058 //
00059 //  Programmer:  Akira Haddox
00060 //  Creation:    July 25, 2003
00061 //
00062 //  Modifications:
00063 //
00064 //    Hank Childs, Sat Nov  8 18:38:08 PST 2003
00065 //    Overhauled class.  Made a STMD (from MTMD) to clean up class and also
00066 //    to overcome current (overcome-able) infrastructure limitations with
00067 //    SILs changing in MTMD.  Also added true AMR capabilities.
00068 //
00069 //    Hank Childs, Sun Mar  6 16:21:15 PST 2005
00070 //    Add support for GeoDyne material names.
00071 //
00072 //    Hank Childs, Thu Jun 23 14:46:22 PDT 2005
00073 //    Broadcast Header from proc. 0
00074 //
00075 //    Mark C. Miller, Wed Nov  9 12:35:15 PST 2005
00076 //    Added GetCycleFromFilename
00077 //
00078 //    Kathleen Bonnell, Thu Sep 25 09:09:54 PDT 2008 
00079 //    Removed GetType, as it is redefined in derived classes
00080 //    avtBoxlib2DFileFormat and avtBoxlib3DFileFormat.
00081 //
00082 //    Hank Childs, Wed Oct  8 16:56:47 PDT 2008
00083 //    Add data member for coordinate system.
00084 //
00085 // ****************************************************************************
00086 
00087 class avtBoxlibFileFormat : public avtSTMDFileFormat
00088 {
00089   public:
00090                           avtBoxlibFileFormat(const char *);
00091     virtual              ~avtBoxlibFileFormat();
00092     
00093     virtual bool          HasInvariantSIL(void) const { return false; };
00094     virtual bool          HasInvariantMetaData(void) const { return false; };
00095     
00096     virtual int           GetCycle(void) { return cycle; };
00097     virtual int           GetCycleFromFilename(const char *f) const;
00098  
00099     virtual vtkDataSet   *GetMesh(int, const char *);
00100     virtual vtkDataArray *GetVar(int, const char *);
00101     virtual vtkDataArray *GetVectorVar(int, const char *);
00102 
00103     virtual void          PopulateDatabaseMetaData(avtDatabaseMetaData *);
00104 
00105     virtual void         *GetAuxiliaryData(const char *var, int,
00106                                            const char *type, void *args,
00107                                            DestructorFunction &);
00108     
00109     virtual void          FreeUpResources(void);
00110     virtual void          ActivateTimestep(void);
00111 
00112   protected:
00113     // This relative location of the multifab files.  It contains entries for
00114     // all levels. There is no predefined length.
00115     std::vector<std::string>                multifabFilenames;
00116 
00117     // For each level and variable, which multifab file the variable
00118     // is stored in, and at what index (component in the file it is stored as.)
00119     // Indexed by level, variable.
00120     std::vector<std::vector<int> >          fabfileIndex;
00121     std::vector<std::vector<int> >          componentIds;
00122 
00123     std::string                             rootPath;
00124 
00125     int                                     nLevels;
00126     int                                     coordSys;
00127     std::vector<int>                        patchesPerLevel;
00128     // These entries are per patch.
00129     std::vector<double>                     xMin;
00130     std::vector<double>                     xMax;
00131     std::vector<double>                     yMin;
00132     std::vector<double>                     yMax;
00133 #if BL_SPACEDIM==3
00134     std::vector<double>                     zMin;
00135     std::vector<double>                     zMax;
00136 #endif
00137     // These entries are per level.
00138     std::vector<double>                     deltaX;
00139     std::vector<double>                     deltaY;
00140 #if BL_SPACEDIM==3
00141     std::vector<double>                     deltaZ;
00142 #endif
00143     // This entry is per level, but level 0 is omitted.
00144     std::vector<int>                        refinement_ratio;
00145 
00146     bool                                    haveReadTimeAndCycle;
00147     double                                  time;
00148     int                                     cycle;
00149     std::string                             timestepPath;
00150     bool                                    initializedReader;
00151     bool                                    vf_names_for_materials;
00152     
00153     // Scalar vars listed in header.
00154     int                                     nVars;
00155     std::vector<std::string>                varNames;
00156     std::vector<int>                        varCentering;
00157     std::vector<bool>                       varUsedElsewhere;
00158 
00159     // Vectors are combinations of scalar vars. The index to those
00160     // variables are stored in vectorComponents.
00161     int                                     nVectors;
00162     std::vector<std::string>                vectorNames;
00163     std::vector<std::vector<int> >          vectorComponents;
00164     std::vector<int>                        vectorCentering;
00165 
00166     // Variable readers.
00167     // Indexed by multifabFile
00168     std::vector<VisMF *>                    mfReaders;
00169 
00170     // The VisMF class is buggy when it comes to freeing up
00171     // memory.  The "clearlist" is used to sidestep those issues.
00172     std::vector<int>                        clearlist;
00173 
00174     // Problem range
00175     double                                  probLo[BL_SPACEDIM];
00176     double                                  probHi[BL_SPACEDIM];
00177     
00178     int                                     nMaterials;
00179 
00180     static const int                        dimension = BL_SPACEDIM;
00181 
00182     void                                   *GetMaterial(const char *, int,
00183                                                         const char *, 
00184                                                         DestructorFunction &);
00185     void                                   *GetSpatialIntervalTree(
00186                                                         DestructorFunction &);
00187     VisMF*                                  GetVisMF(int index);
00188     void                                    ReadHeader(void);
00189     void                                    InitializeReader(void);
00190     void                                    CalculateDomainNesting(void);
00191 
00192     vtkDataSet *CreateGrid(double lo[BL_SPACEDIM],
00193                            double hi[BL_SPACEDIM],
00194                            double delta[BL_SPACEDIM]) const;
00195 
00196     int                 GetGlobalPatchNumber(int level, int patch) const;
00197     void                GetLevelAndLocalPatchNumber(int global_patch,
00198                                   int &level, int &local_patch) const;
00199     void                GetDimensions(int *, int level, int patch) const;
00200     void                GetDimensions(int *, double*, double*, double*) const;
00201 };
00202 
00203 #endif