14 #define CHOFFSET(object, member) (int)((char*)&(object.member) - (char*)&object) 16 #ifdef CH_USE_HDF5 // if you don't have CH_USE_HDF5, then this file is useless 41 #include "BoxTools_ExternC_Mangler.H" 43 #include "NamespaceHeader.H" 51 for (
int i=0; i<b.size(); ++i) b[i]= &(a_allocatedBuffers[i][0]);
52 read(item, b, box, comps);
82 const int& a_refRatio,
96 bool setGhost =
false);
112 const std::string&
name =
"boxes");
123 const std::string& a_name,
126 bool newForm =
false);
139 const std::string& a_name,
182 const std::string&
name =
"boxes");
209 const std::string& a_dataName =
"data" );
221 const std::string& a_name,
224 bool redefineData =
true);
251 const std::string& a_name,
254 bool redefineData =
true);
320 const std::string& a_filename,
322 const char *a_globalGroupName=
"Chombo_global");
356 const std::string& a_filename,
358 const char *a_globalGroupName=
"Chombo_global");
392 int setGroup(
const std::string& groupAbsPath);
420 const std::string&
getGroup()
const;
422 const hid_t&
fileID()
const;
427 static map<std::string, std::string>
groups;
537 int writeToLocation(hid_t loc_id)
const;
538 int readFromLocation(hid_t loc_id);
544 static herr_t attributeScan(hid_t loc_id,
const char *
name,
void *opdata);
560 #if ( H5_VERS_MAJOR == 1 && H5_VERS_MINOR > 6 ) 563 #if ( H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 6 && H5_VERS_RELEASE >= 4 ) 572 hid_t
H5Type(
const T* dummy);
575 hid_t
H5Type(
const int* dummy);
578 hid_t
H5Type(
const long long* dummy);
581 hid_t
H5Type(
const float* dummy);
584 hid_t
H5Type(
const double* dummy);
607 const std::string&
name,
615 const std::string&
name,
647 #include "NamespaceFooter.H" 655 int linearSize(
const CH_XDIR::OffsetBuffer& a_input);
659 void linearIn(CH_XDIR::OffsetBuffer& a_outputT,
const void*
const a_inBuf);
663 void linearOut(
void*
const a_outBuf,
const CH_XDIR::OffsetBuffer& a_inputT);
671 #include "NamespaceHeader.H" 679 a_types[0] = H5T_NATIVE_INT;
686 a_types[0] = H5T_NATIVE_CHAR;
745 const char*
name =
"FArrayBox";
754 const char*
name =
"BaseFab<int>";
763 const char*
name =
"BaseFab<char>";
774 a_types[0] = H5T_NATIVE_CHAR;
781 a_sizes[0] = item.
size(box, comps);
788 item.linearOut(a_allocatedBuffers[0], box, comps);
795 item.linearIn(a_allocatedBuffers[0], box, comps);
799 inline const char*
name(
const T& a_dummySpecializationArg)
801 static const char*
name =
"unknown";
812 for (
int t=0; t<types; t++) offsets[t][0] = 0;
814 if (T::preAllocatable()==0)
817 unsigned int index = 1;
820 Box region = layout[it()];
821 region.
grow(outputGhost);
822 dataSize(dummy, thisSize, region, comps);
823 for (
unsigned int i=0; i<thisSize.
size(); ++i)
826 offsets[i][index] = offsets[i][index-1] + thisSize[i];
840 Box region = layout[dit()];
841 region.
grow(outputGhost);
842 dataSize(a_data[dit()], thisSize, region, comps);
849 for (
int i=0; i<
numProc(); ++i)
852 for (
int num=0; num<offbuf.
index.
size(); num++)
854 int index = offbuf.
index[num];
855 for (
unsigned int j=0; j<types; ++j)
858 offsets[j][index+1] = offbuf.
offsets[num][j];
862 for (
int i=0; i<layout.
size(); i++)
864 for (
unsigned int j=0; j<types; ++j)
867 offsets[j][i+1] += offsets[j][i];
881 const std::string& a_name,
IntVect outputGhost,
882 const Interval& in_comps,
bool newForm)
910 for (
unsigned int i=0; i<types.
size(); ++i)
912 flatdims[0] = offsets[i][offsets[i].
size()-1];
917 strcpy(dataname,
"Mask");
921 sprintf(dataname,
"%sRegular", a_name.c_str());
926 sprintf(dataname,
"%s:datatype=%i",a_name.c_str(), i);
928 dataspace[i] = H5Screate_simple(1, flatdims, NULL);
930 dataset[i] = H5Dcreate(a_handle.
groupID(), dataname,
932 dataspace[i], H5P_DEFAULT);
936 hid_t offsetspace, offsetData;
937 for (
unsigned int i=0; i<types.
size(); ++i)
939 flatdims[0] = offsets[i].
size();
944 strcpy(dataname,
"MaskOffsets");
948 sprintf(dataname,
"%sOffsets",a_name.c_str());
953 sprintf(dataname,
"%s:offsets=%i",a_name.c_str(), i);
955 offsetspace = H5Screate_simple(1, flatdims, NULL);
957 offsetData = H5Dcreate(a_handle.
groupID(), dataname,
958 H5T_NATIVE_LLONG, offsetspace, H5P_DEFAULT);
962 hid_t memdataspace = H5Screate_simple(1, flatdims, NULL);
964 err = H5Dwrite(offsetData, H5T_NATIVE_LLONG, memdataspace, offsetspace,
965 H5P_DEFAULT, &(offsets[i][0]));
967 H5Sclose(memdataspace);
969 H5Sclose(offsetspace);
970 H5Dclose(offsetData);
979 std::string group = a_handle.
getGroup();
980 a_handle.
setGroup(group+
"/"+a_name+
"_attributes");
989 for (
unsigned int i=0; i<types.
size(); ++i)
991 type_size[i] = H5Tget_size(types[i]);
1000 for (
int i=0; i<offsets[0].
size(); i++)
1008 for (
unsigned int i=0; i<types.
size(); ++i)
1010 long long size = (offsets[i][index+1] - offsets[i][index])
1014 if (size > bufferCapacity[i])
1016 bufferCapacity[i] = size;
1021 for (
unsigned int i=0; i<types.
size(); ++i)
1023 buffers[i] =
mallocMT(bufferCapacity[i]);
1024 if (buffers[i] == NULL)
1026 pout() <<
" i=" << i
1027 <<
" types.size() = " << types.
size()
1028 <<
" bufferCapacity[i] = " << (int)bufferCapacity[i]
1037 #ifdef TRY_MPI_COLLECTIVES_ 1038 hid_t DXPL = H5Pcreate(H5P_DATASET_XFER);
1039 H5Pset_dxpl_mpio(DXPL, H5FD_MPIO_COLLECTIVE);
1043 const T& data = a_data[it()];
1046 box.
grow(outputGhost);
1047 write(data, buffers, box, comps);
1048 for (
unsigned int i=0; i<types.
size(); ++i)
1050 offset[0] = offsets[i][index];
1051 count[0] = offsets[i][index+1] - offset[0];
1054 err = H5Sselect_hyperslab(dataspace[i], H5S_SELECT_SET,
1058 hid_t memdataspace = H5Screate_simple(1, count, NULL);
1060 #ifdef TRY_MPI_COLLECTIVES_ 1061 err = H5Dwrite(dataset[i], types[i], memdataspace, dataspace[i],
1064 err = H5Dwrite(dataset[i], types[i], memdataspace, dataspace[i],
1065 H5P_DEFAULT, buffers[i]);
1068 H5Sclose(memdataspace);
1077 #ifdef TRY_MPI_COLLECTIVES_ 1084 for (
unsigned int i=0; i<types.
size(); ++i)
1087 H5Sclose(dataspace[i]);
1088 H5Dclose(dataset[i]);
1096 const std::string& a_name,
const IntVect& outputGhost,
const Interval& in_comps)
1103 std::string group = a_handle.
getGroup();
1104 a_handle.
setGroup(group+
"/"+a_name+
"_attributes");
1117 std::string group = a_handle.
getGroup();
1118 if (a_handle.
setGroup(group+
"/"+a_name+
"_attributes"))
1120 std::string message =
"error opening " 1121 +a_handle.
getGroup()+
"/"+a_name+
"_attributes" ;
1127 int ncomp = info.
m_int[
"comps"];
1129 if (a_comps.
end() > 0 && ncomp < a_comps.
end())
1131 MayDay::Error(
"attempt to read component interval that is not available");
1133 if (a_comps.
size() == 0)
1134 a_data.
define(a_layout, ncomp, ghost);
1136 a_data.
define(a_layout, a_comps.
size(), ghost);
1166 for (
unsigned int i=0; i<types.
size(); ++i)
1168 sprintf(dataname,
"%s:datatype=%i",a_name.c_str(), i);
1169 dataset[i] = H5Dopen(a_handle.
groupID(), dataname);
1174 dataspace[i] = H5Dget_space(dataset[i]);
1175 if (dataspace[i] < 0)
1181 hid_t offsetspace, offsetData;
1182 hsize_t flatdims[1];
1183 for (
unsigned int i=0; i<types.
size(); ++i)
1185 flatdims[0] = offsets[i].
size();
1186 sprintf(dataname,
"%s:offsets=%i",a_name.c_str(), i);
1187 offsetspace = H5Screate_simple(1, flatdims, NULL);
1189 offsetData = H5Dopen(a_handle.
groupID(), dataname);
1191 hid_t memdataspace = H5Screate_simple(1, flatdims, NULL);
1193 err = H5Dread(offsetData, H5T_NATIVE_LLONG, memdataspace, offsetspace,
1194 H5P_DEFAULT, &(offsets[i][0]));
1196 H5Sclose(memdataspace);
1197 H5Sclose(offsetspace);
1198 H5Dclose(offsetData);
1202 std::string group = a_handle.
getGroup();
1205 std::string message =
"error opening "+a_handle.
getGroup()+
"/"+a_name ;
1212 int ncomps = info.
m_int[
"comps"];
1216 outputGhost = info.
m_intvect[
"outputGhost"];
1226 if (a_comps.
size() != 0)
1232 a_data.
define(a_layout, ncomps);
1243 for (
unsigned int i=0; i<types.
size(); ++i)
1245 type_size[i] = H5Tget_size(types[i]);
1252 T& data = a_data[it()];
1256 for (
unsigned int i=0; i<types.
size(); ++i)
1261 offset[0] = offsets[i][index];
1262 count[0] = offsets[i][index+1] - offset[0];
1269 int size = count[0] * type_size[i];
1270 while (size > buffers[i].size())
1272 buffers[i].
resize(2*buffers[i].size());
1275 err = H5Sselect_hyperslab(dataspace[i], H5S_SELECT_SET,
1279 hid_t memdataspace = H5Screate_simple(1, count, NULL);
1281 err = H5Dread(dataset[i], types[i], memdataspace, dataspace[i],
1282 H5P_DEFAULT, &(buffers[i][0]));
1284 H5Sclose(memdataspace);
1292 box.
grow(outputGhost);
1293 read(data, buffers, box, comps);
1297 for (
unsigned int i=0; i<types.
size(); ++i)
1300 H5Sclose(dataspace[i]);
1301 H5Dclose(dataset[i]);
1313 const Box& a_domain,
1314 const int& a_refRatio,
1320 std::string currentGroup = a_handle.
getGroup();
1321 sprintf(levelName,
"/level_%i",a_level);
1322 error = a_handle.
setGroup(currentGroup + levelName);
1323 if (error != 0)
return 1;
1326 meta.
m_real[
"dx"] = a_dx;
1327 meta.
m_real[
"dt"] = a_dt;
1328 meta.
m_real[
"time"] = a_time;
1329 meta.
m_box[
"prob_domain"] = a_domain;
1330 meta.
m_int[
"ref_ratio"] = a_refRatio;
1333 if (error != 0)
return 2;
1335 error =
write(a_handle, a_data.boxLayout());
1336 if (error != 0)
return 3;
1338 error =
write(a_handle, a_data,
"data", outputGhost, comps);
1339 if (error != 0)
return 4;
1365 std::string currentGroup = a_handle.
getGroup();
1366 sprintf(levelName,
"/level_%i",a_level);
1367 error = a_handle.
setGroup(currentGroup + levelName);
1368 if (error != 0)
return 1;
1372 if (error != 0)
return 2;
1373 a_dx = meta.
m_real[
"dx"];
1374 a_dt = meta.
m_real[
"dt"];
1375 a_time = meta.
m_real[
"time"];
1376 a_domain = meta.
m_box[
"prob_domain"];
1377 a_refRatio = meta.
m_int[
"ref_ratio"];
1379 error =
read(a_handle, boxes);
1386 if (error != 0)
return 3;
1388 error =
read(a_handle, a_data,
"data", layout, a_comps,
true);
1390 if (error != 0)
return 4;
1397 #include "NamespaceFooter.H" 1399 #else // CH_USE_HDF5 1402 #define HOFFSET(S,M) (offsetof(S,M)) 1404 #endif // CH_USE_HDF5 not defined std::ostream & pout()
Use this in place of std::cout for program output.
int open(const std::string &a_filename, mode a_mode, const char *a_globalGroupName="Chombo_global")
{ File functions}
virtual void define(const BoxLayout &boxes, int comps, const DataFactory< T > &factory=DefaultDataFactory< T >())
Definition: BoxLayoutDataI.H:83
IntVect & min(const IntVect &p)
Definition: IntVect.H:1041
Interval interval() const
Definition: BoxLayoutData.H:264
#define freeMT(a_a)
Definition: memtrack.H:159
#define CH_SPACEDIM
Definition: SPACE.H:52
#define CH_assert(cond)
Definition: CHArray.H:37
int readBoxes(HDF5Handle &a_handle, Vector< Vector< Box > > &boxes)
reads the set of Boxes out from the level_* groups of a Chombo HDF5 AMR file
mode
Definition: CH_HDF5.H:289
void writeDataset(hid_t a_dataset, hid_t a_dataspace, const void *start, ch_offset_t off, hsize_t count)
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:146
one dimensional dynamic array
Definition: Vector.H:52
int readFArrayBox(HDF5Handle &a_handle, FArrayBox &a_fab, int a_level, int a_boxNumber, const Interval &a_components, const std::string &a_dataName="data")
FArrayBox-at-a-time read function. FArrayBox gets redefined in the function. Reads data field named b...
int size() const
Definition: Interval.H:64
std::string m_group
Definition: CH_HDF5.H:438
#define mallocMT(a_a)
Definition: memtrack.H:158
void getOffsets(Vector< Vector< long long > > &offsets, const BoxLayoutData< T > &a_data, int types, const Interval &comps, const IntVect &outputGhost)
Definition: CH_HDF5.H:806
void readDataset(hid_t a_dataset, hid_t a_dataspace, void *start, ch_offset_t off, hsize_t count)
unsigned int size() const
Returns the total number of boxes in the BoxLayout.
const BoxLayout & boxLayout() const
Definition: LayoutData.H:108
DataIterator dataIterator() const
Definition: LayoutDataI.H:79
void setGroupToLevel(int a_level)
{ Group functions}
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:67
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:110
Definition: DataIterator.H:140
void linearOut(void *const a_outBuf, const CH_XDIR::OffsetBuffer &a_inputT)
int readLevel(HDF5Handle &a_handle, const int &a_level, LevelData< T > &a_data, Real &a_dx, Real &a_dt, Real &a_time, Box &a_domain, int &a_refRatio, const Interval &a_comps=Interval(), bool setGhost=false)
Definition: CH_HDF5.H:1347
Definition: CH_HDF5.H:294
std::ostream & operator<<(std::ostream &os, const HDF5HeaderData &data)
int LoadBalance(Vector< Vector< int > > &a_procAssignments, Real &a_effRatio, const Vector< Vector< Box > > &a_Grids, const Vector< Vector< long > > &a_ComputeLoads, const Vector< int > &a_RefRatios, int a_nProc=numProc())
unsigned int numProc()
number of parallel processes
int uniqueProc(const SerialTask::task &a_task)
An Iterator based on a BoxLayout object.
Definition: LayoutIterator.H:38
void createDataset(hid_t &a_dataset, hid_t &a_dataspace, HDF5Handle &handle, const std::string &name, const T *dummy, hsize_t size)
Definition: CH_HDF5.H:612
void dataTypes(Vector< hid_t > &a_types, const BaseFab< int > &dummy)
Definition: CH_HDF5.H:676
void dataSize(const BaseFab< int > &item, Vector< int > &a_sizes, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:707
Definition: CH_HDF5.H:291
Definition: EBInterface.H:45
static hid_t realvect_id
Definition: CH_HDF5.H:426
void resize(unsigned int isize)
Definition: Vector.H:323
const std::string & getGroup() const
Definition: CH_HDF5.H:293
A FArrayBox-like container for face-centered fluxes.
Definition: FluxBox.H:22
void gather(Vector< T > &a_outVec, const T &a_input, int a_dest)
Definition: SPMDI.H:194
void linearIn(CH_XDIR::OffsetBuffer &a_outputT, const void *const a_inBuf)
unsigned int index(const LayoutIndex &index) const
Definition: BoxLayout.H:690
void push_back(const T &in)
Definition: Vector.H:283
static bool initialized
Definition: CH_HDF5.H:442
#define CH_TIME(name)
Definition: CH_Timer.H:59
Structure for passing component ranges in code.
Definition: Interval.H:23
const char * name(const FArrayBox &a_dummySpecializationArg)
Definition: CH_HDF5.H:741
int linearSize(const CH_XDIR::OffsetBuffer &a_input)
Definition: BoxLayoutData.H:136
std::string m_filename
Definition: CH_HDF5.H:437
Data on a BoxLayout.
Definition: BoxLayoutData.H:91
double Real
Definition: REAL.H:33
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2166
herr_t HDF5HeaderDataattributeScan(hid_t loc_id, const char *name, void *opdata)
Definition: CH_HDF5.H:637
virtual void define(const DisjointBoxLayout &dp, int comps, const IntVect &ghost=IntVect::Zero, const DataFactory< T > &a_factory=DefaultDataFactory< T >())
Definition: LevelDataI.H:70
int pushGroup(const std::string &grp)
Vector< int > index
Definition: CH_HDF5.H:639
Definition: CH_HDF5.H:292
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
size_t size() const
Definition: Vector.H:177
void createData(hid_t &a_dataset, hid_t &a_dataspace, HDF5Handle &handle, const std::string &name, hid_t type, hsize_t size)
const IntVect & ghostVect() const
Definition: LevelData.H:157
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
int write(HDF5Handle &a_handle, const BoxLayout &a_layout, const std::string &name="boxes")
writes BoxLayout to HDF5 file.
static const IntVect Zero
Definition: IntVect.H:627
static hid_t box_id
Definition: CH_HDF5.H:424
Vector< Vector< int > > offsets
Definition: CH_HDF5.H:640
hssize_t ch_offset_t
Definition: CH_HDF5.H:566
static void Warning(const char *const a_msg=m_nullString)
Print out message to cerr and continue.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
hid_t m_fileID
Definition: CH_HDF5.H:434
hid_t H5Type(const T *dummy)
Definition: CH_HDF5.H:596
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:267
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Definition: FArrayBox.H:44
HDF5Handle()
{ constructor}
Box & grow(int i)
grow functions
Definition: Box.H:2268
int setGroup(const std::string &groupAbsPath)
void broadcast(T &a_inAndOut, int a_src)
broadcast to every process
Definition: SPMDI.H:204
int end() const
Definition: Interval.H:91
int writeLevel(HDF5Handle &a_handle, const int &a_level, const T &a_data, const Real &a_dx, const Real &a_dt, const Real &a_time, const Box &a_domain, const int &a_refRatio, const IntVect &outputGhost=IntVect::Zero, const Interval &comps=Interval())
user-friendly function to write out data on a AMR level
Definition: CH_HDF5.H:1307
const hid_t & fileID() const
LayoutIterator layoutIterator() const
Iterator that processes through ALL the boxes in a BoxLayout.
static hid_t intvect_id
Definition: CH_HDF5.H:425
int procID()
local process ID
HDF5Handle & operator=(const HDF5Handle &)
bool m_isOpen
Definition: CH_HDF5.H:436
static map< std::string, std::string > groups
Definition: CH_HDF5.H:427
void read(T &item, Vector< Vector< char > > &a_allocatedBuffers, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:47
hid_t m_currentGroupID
Definition: CH_HDF5.H:435
const hid_t & groupID() const
#define H5T_NATIVE_REAL
Definition: REAL.H:35
int m_level
Definition: CH_HDF5.H:439