Skip to content
Snippets Groups Projects
Commit f9afa8e6 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

use C-API for reading particles

parent 54752916
Branches
Tags
No related merge requests found
...@@ -327,7 +327,7 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base): ...@@ -327,7 +327,7 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base):
'ps{1}->dt = dt;\n' + 'ps{1}->dt = dt;\n' +
'ps{1}->iteration = iteration;\n' + 'ps{1}->iteration = iteration;\n' +
update_field + update_field +
'ps{1}->read(data_file);\n').format(self.C_dtype, self.particle_species) 'ps{1}->read(parameter_file);\n').format(self.C_dtype, self.particle_species)
self.particle_loop += ((update_field + self.particle_loop += ((update_field +
'ps{0}->step();\n' + 'ps{0}->step();\n' +
'if (ps{0}->iteration % niter_part == 0)\n' + 'if (ps{0}->iteration % niter_part == 0)\n' +
......
...@@ -92,7 +92,11 @@ class code(base): ...@@ -92,7 +92,11 @@ class code(base):
} }
read_parameters(parameter_file); read_parameters(parameter_file);
H5Fclose(parameter_file); H5Fclose(parameter_file);
if (myrank == 0) data_file = new H5::H5File(std::string(simname) + std::string(".h5"), H5F_ACC_RDWR); if (myrank == 0)
{
data_file = new H5::H5File(std::string(simname) + std::string(".h5"), H5F_ACC_RDWR);
parameter_file = data_file->getId();
}
//endcpp //endcpp
""" """
for ostream in ['cout', 'cerr']: for ostream in ['cout', 'cerr']:
......
...@@ -600,66 +600,54 @@ void slab_field_particles<rnumber>::linear_interpolation(rnumber *field, int *xg ...@@ -600,66 +600,54 @@ void slab_field_particles<rnumber>::linear_interpolation(rnumber *field, int *xg
} }
template <class rnumber> template <class rnumber>
void slab_field_particles<rnumber>::read(H5::H5File *dfile) void slab_field_particles<rnumber>::read(hid_t data_file_id)
{ {
DEBUG_MSG("aloha\n");
if (this->fs->rd->myrank == 0) if (this->fs->rd->myrank == 0)
{
if (dfile == NULL)
{
char full_name[512];
sprintf(full_name, "%s_state_i%.5x", this->name, this->iteration);
FILE *ifile;
ifile = fopen(full_name, "rb");
fread((void*)this->state, sizeof(double), this->array_size, ifile);
fclose(ifile);
// if we're not at iteration 0, we should read rhs as well
if (this->iteration > 0)
{
sprintf(full_name, "%s_rhs_i%.5x", this->name, this->iteration);
ifile = fopen(full_name, "rb");
for (int i=0; i<this->integration_steps; i++)
fread((void*)this->rhs[i], sizeof(double), this->array_size, ifile);
fclose(ifile);
}
}
else
{ {
std::string temp_string = (std::string("/particles/") + std::string temp_string = (std::string("/particles/") +
std::string(this->name) + std::string(this->name) +
std::string("/state")); std::string("/state"));
H5::DataSet dset = dfile->openDataSet(temp_string); DEBUG_MSG("about to open dataset\n");
H5::DataSpace memspace, readspace; hid_t Cdset = H5Dopen(data_file_id, temp_string.c_str(), H5P_DEFAULT);
DEBUG_MSG("opened dataset\n");
hid_t mspace, rspace;
hsize_t count[4], offset[4]; hsize_t count[4], offset[4];
readspace = dset.getSpace(); rspace = H5Dget_space(Cdset);
readspace.getSimpleExtentDims(count); H5Sget_simple_extent_dims(rspace, count, NULL);
count[0] = 1; count[0] = 1;
offset[0] = this->iteration / this->traj_skip; offset[0] = this->iteration / this->traj_skip;
offset[1] = 0; offset[1] = 0;
offset[2] = 0; offset[2] = 0;
memspace = H5::DataSpace(3, count); mspace = H5Screate_simple(3, count, NULL);
readspace.selectHyperslab(H5S_SELECT_SET, count, offset); H5Sselect_hyperslab(rspace, H5S_SELECT_SET, offset, NULL, count, NULL);
dset.read(this->state, H5::PredType::NATIVE_DOUBLE, memspace, readspace); H5Dread(Cdset, H5T_NATIVE_DOUBLE, mspace, rspace, H5P_DEFAULT, this->state);
H5Sclose(mspace);
H5Sclose(rspace);
H5Dclose(Cdset);
if (this->iteration > 0) if (this->iteration > 0)
{ {
temp_string = (std::string("/particles/") + temp_string = (std::string("/particles/") +
std::string(this->name) + std::string(this->name) +
std::string("/rhs")); std::string("/rhs"));
dset = dfile->openDataSet(temp_string); Cdset = H5Dopen(data_file_id, temp_string.c_str(), H5P_DEFAULT);
readspace = dset.getSpace(); rspace = H5Dget_space(Cdset);
readspace.getSimpleExtentDims(count); H5Sget_simple_extent_dims(rspace, count, NULL);
//reading from last available position //reading from last available position
offset[0] = count[0] - 1; offset[0] = count[0] - 1;
offset[3] = 0; offset[3] = 0;
count[0] = 1; count[0] = 1;
count[1] = 1; count[1] = 1;
memspace = H5::DataSpace(4, count); mspace = H5Screate_simple(4, count, NULL);
for (int i=0; i<this->integration_steps; i++) for (int i=0; i<this->integration_steps; i++)
{ {
offset[1] = i; offset[1] = i;
readspace.selectHyperslab(H5S_SELECT_SET, count, offset); H5Sselect_hyperslab(rspace, H5S_SELECT_SET, offset, NULL, count, NULL);
dset.read(this->rhs[i], H5::PredType::NATIVE_DOUBLE, memspace, readspace); H5Dread(Cdset, H5T_NATIVE_DOUBLE, mspace, rspace, H5P_DEFAULT, this->rhs[i]);
}
} }
H5Sclose(mspace);
H5Sclose(rspace);
H5Dclose(Cdset);
} }
} }
MPI_Bcast( MPI_Bcast(
......
...@@ -139,7 +139,7 @@ class slab_field_particles ...@@ -139,7 +139,7 @@ class slab_field_particles
void rFFTW_to_buffered(rnumber *src, rnumber *dst); void rFFTW_to_buffered(rnumber *src, rnumber *dst);
/* generic methods, should work for all children of this class */ /* generic methods, should work for all children of this class */
void read(H5::H5File *dfile = NULL); void read(hid_t data_file_id);
void write(H5::H5File *dfile = NULL, bool write_rhs = true); void write(H5::H5File *dfile = NULL, bool write_rhs = true);
/* solver stuff */ /* solver stuff */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment