GridBDataWriter.h

00001 #ifndef gridripper_amr1d_io_GridBDataWriter_h
00002 #define gridripper_amr1d_io_GridBDataWriter_h
00003 
00004 #include <gridripper/io/BDataFlags.h>
00005 #include <gridripper/amr1d/Grid.h>
00006 #include <gridripper/amr1d/GridIterator.h>
00007 #include <gridripper/io/IOException.h>
00008 #include <gridripper/tvalarray.h>
00009 #include <iostream>
00010 
00011 namespace gridripper { namespace amr1d { namespace io {
00012 
00013 using namespace gridripper::io;
00014 using namespace gridripper::amr1d;
00015 
00023 class GridBDataWriter
00024 {
00025     // File format.
00026     //
00027     // Header Block
00028     //      0   8 double T
00029     //      8   4 int    numGridPoints
00030     //     12   2 short  nc    (number of components)
00031     //     14   4 int    flags
00032     //     18   4 int    baseGrid.maxi + 1
00033     //     22   4 int    xmultiplier = r^maxAllowedLevel
00034     //     26   8 double dx
00035     // end
00036     // Block 1 if (flags & 2) != 0
00037     //      0   4 int    numBytes
00038     //      4   4 int    numLevels
00039     //     for i to numLevels
00040     //         x   4 int    numGrids
00041     //         for j to numGrids
00042     //             x   4 int timeStepCount
00043     //             x   4 int lastRegridTime
00044     //         end
00045     //     end
00046     // end
00047     // Block 2 if (flags & 32) != 0
00048     //      0   2 int    numConstraintEqs
00049     //      2   2 int    numAuxQuantities (unused)
00050     // end
00051     // Block 3 if (flags & 128) != 0
00052     //      for i to nc
00053     //             x   2     short   size
00054     //             x   size  byte[]  <name of field i>
00055     //      end
00056     // end
00057     // Main Block
00058     //      for i to numGridPoints
00059     //          if (flags & 1024) == 0
00060     //              0           4 int    kx = x/dx
00061     //          for j to nc
00062     //              if (flags & (256|512)) == BDATA_FIELD_PREC_FLOAT (=256)
00063     //                  0       4 float f[i]
00064     //              else if (flags & (256|512)) == BDATA_FIELD_PREC_DOUBLE (=0)
00065     //                  0       8 double f[i]
00066     //          end
00067     //          for j to numConstraintEqs
00068     //              x       4 float constraintEqLHS
00069     //              x       4 float constraintEqRHS
00070     //              if (flags & 64) != 0
00071     //                  x       4 float constraintEqLHS-constraintEqRHS
00072     //              end
00073     //          end
00074     //          Block 4 if (flags & 4) != 0
00075     //              0       8 double energyDensity
00076     //          end
00077     //          Block 5 if (flags & 1) != 0 && kx % xmultiplier == 0
00078     //              0       8 double energyLoss[kx/xmultiplier]
00079     //          end
00080     //      end
00081     // end
00082 
00083 private:
00084     static int MAXBUFSIZE;
00085 
00086     int refinementRatio;
00087     int maxAllowedLevel;
00088 
00089     const tvalarray< tvector<Grid*> >& grids;
00090     int finestLevel;
00091     GridIterator gridIterator;
00092     int numGridPoints;
00093     int block1NumBytes;
00094 
00095 public:
00096     GridBDataWriter(int r, int maxlevel, const tvalarray< tvector<Grid*> >& g,
00097                 int finestl);
00098 
00099     int getBestBufSize() const;
00100 
00101     void write(ostream& os) throw(IOException&);
00102 };
00103 
00104 } } } // namespace gridripper::amr1d::io
00105 
00106 #endif /* gridripper_amr1d_io_GridBDataWriter_h */

Generated on Wed Jun 17 18:46:47 2009 for GridRipper by  doxygen 1.5.6