Commit eb42cd3d authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

move particle I/O to cpp lib

parent 07f95532
......@@ -526,40 +526,13 @@ class NavierStokes(_fluid_particle_base):
{0}->field = {1};
ps{2}->sample_vec_field({0}, acceleration);
""".format(interpolator[s], acc_name, s0 + s)
output_vel_acc += """
if (myrank == 0)
{{
//VELOCITY begin
std::string temp_string = (std::string("/") +
std::string(ps{0}->name) +
std::string("/velocity"));
hid_t Cdset = H5Dopen(particle_file, temp_string.c_str(), H5P_DEFAULT);
hid_t mspace, wspace;
int ndims;
hsize_t count[3], offset[3];
wspace = H5Dget_space(Cdset);
ndims = H5Sget_simple_extent_dims(wspace, count, NULL);
count[0] = 1;
offset[0] = ps{0}->iteration / ps{0}->traj_skip;
offset[1] = 0;
offset[2] = 0;
mspace = H5Screate_simple(ndims, count, NULL);
H5Sselect_hyperslab(wspace, H5S_SELECT_SET, offset, NULL, count, NULL);
H5Dwrite(Cdset, H5T_NATIVE_DOUBLE, mspace, wspace, H5P_DEFAULT, velocity);
H5Dclose(Cdset);
//VELOCITY end\n""".format(s0 + s)
output_vel_acc += (
'if (myrank == 0)\n' +
'{\n' +
'ps{0}->write(particle_file, "velocity", velocity);\n'.format(s0 + s))
if not type(acc_name) == type(None):
output_vel_acc += """
//ACCELERATION begin
temp_string = (std::string("/") +
std::string(ps{0}->name) +
std::string("/acceleration"));
Cdset = H5Dopen(particle_file, temp_string.c_str(), H5P_DEFAULT);
H5Dwrite(Cdset, H5T_NATIVE_DOUBLE, mspace, wspace, H5P_DEFAULT, acceleration);
H5Sclose(mspace);
H5Sclose(wspace);
H5Dclose(Cdset);
//ACCELERATION end\n""".format(s0 + s)
output_vel_acc += (
'ps{0}->write(particle_file, "acceleration", acceleration);\n'.format(s0 + s))
output_vel_acc += '}\n'
output_vel_acc += 'delete[] velocity;\n'
if not type(acc_name) == type(None):
......
......@@ -109,7 +109,8 @@ void rFFTW_particles<particle_type, rnumber, interp_neighbours>::roll_rhs()
template <int particle_type, class rnumber, int interp_neighbours>
void rFFTW_particles<particle_type, rnumber, interp_neighbours>::AdamsBashforth(int nsteps)
void rFFTW_particles<particle_type, rnumber, interp_neighbours>::AdamsBashforth(
const int nsteps)
{
ptrdiff_t ii;
this->get_rhs(this->state, this->rhs[0]);
......@@ -194,7 +195,8 @@ void rFFTW_particles<particle_type, rnumber, interp_neighbours>::step()
template <int particle_type, class rnumber, int interp_neighbours>
void rFFTW_particles<particle_type, rnumber, interp_neighbours>::read(hid_t data_file_id)
void rFFTW_particles<particle_type, rnumber, interp_neighbours>::read(
const hid_t data_file_id)
{
if (this->myrank == 0)
{
......@@ -257,42 +259,57 @@ void rFFTW_particles<particle_type, rnumber, interp_neighbours>::read(hid_t data
}
template <int particle_type, class rnumber, int interp_neighbours>
void rFFTW_particles<particle_type, rnumber, interp_neighbours>::write(hid_t data_file_id, bool write_rhs)
void rFFTW_particles<particle_type, rnumber, interp_neighbours>::write(
const hid_t data_file_id,
const char *dset_name,
const double *data)
{
std::string temp_string = (std::string(this->name) +
std::string("/") +
std::string(dset_name));
hid_t dset = H5Dopen(data_file_id, temp_string.c_str(), H5P_DEFAULT);
hid_t mspace, wspace;
hsize_t count[3], offset[3];
wspace = H5Dget_space(dset);
H5Sget_simple_extent_dims(wspace, count, NULL);
count[0] = 1;
offset[0] = this->iteration / this->traj_skip;
offset[1] = 0;
offset[2] = 0;
mspace = H5Screate_simple(3, count, NULL);
H5Sselect_hyperslab(wspace, H5S_SELECT_SET, offset, NULL, count, NULL);
H5Dwrite(dset, H5T_NATIVE_DOUBLE, mspace, wspace, H5P_DEFAULT, data);
H5Sclose(mspace);
H5Sclose(wspace);
H5Dclose(dset);
}
template <int particle_type, class rnumber, int interp_neighbours>
void rFFTW_particles<particle_type, rnumber, interp_neighbours>::write(
const hid_t data_file_id,
const bool write_rhs)
{
if (this->myrank == 0)
{
std::string temp_string = (std::string("/") +
std::string(this->name) +
std::string("/state"));
hid_t dset = H5Dopen(data_file_id, temp_string.c_str(), H5P_DEFAULT);
hid_t mspace, wspace;
hsize_t count[4], offset[4];
wspace = H5Dget_space(dset);
H5Sget_simple_extent_dims(wspace, count, NULL);
count[0] = 1;
offset[0] = this->iteration / this->traj_skip;
offset[1] = 0;
offset[2] = 0;
mspace = H5Screate_simple(3, count, NULL);
H5Sselect_hyperslab(wspace, H5S_SELECT_SET, offset, NULL, count, NULL);
H5Dwrite(dset, H5T_NATIVE_DOUBLE, mspace, wspace, H5P_DEFAULT, this->state);
H5Sclose(mspace);
H5Sclose(wspace);
H5Dclose(dset);
this->write(data_file_id, "state", this->state);
if (write_rhs)
{
temp_string = (std::string("/") +
std::string(this->name) +
std::string("/rhs"));
dset = H5Dopen(data_file_id, temp_string.c_str(), H5P_DEFAULT);
wspace = H5Dget_space(dset);
std::string temp_string = (
std::string("/") +
std::string(this->name) +
std::string("/rhs"));
hid_t dset = H5Dopen(data_file_id, temp_string.c_str(), H5P_DEFAULT);
hid_t wspace = H5Dget_space(dset);
hsize_t count[4], offset[4];
H5Sget_simple_extent_dims(wspace, count, NULL);
//writing to last available position
offset[0] = count[0] - 1;
offset[1] = 0;
offset[2] = 0;
offset[3] = 0;
count[0] = 1;
count[1] = 1;
offset[3] = 0;
mspace = H5Screate_simple(4, count, NULL);
hid_t mspace = H5Screate_simple(4, count, NULL);
for (int i=0; i<this->integration_steps; i++)
{
offset[1] = i;
......
......@@ -78,21 +78,26 @@ class rFFTW_particles
const int INTEGRATION_STEPS = 2);
~rFFTW_particles();
void get_rhs(double *__restrict__ x, double *__restrict__ rhs);
void get_rhs(
double *__restrict__ x,
double *__restrict__ rhs);
inline void sample_vec_field(rFFTW_interpolator<rnumber, interp_neighbours> *field, double *vec_values)
inline void sample_vec_field(
rFFTW_interpolator<rnumber, interp_neighbours> *field,
double *vec_values)
{
field->sample(this->nparticles, this->ncomponents, this->state, vec_values, NULL);
}
/* input/output */
void read(hid_t data_file_id);
void write(hid_t data_file_id, bool write_rhs = true);
void read(const hid_t data_file_id);
void write(const hid_t data_file_id, const char *dset_name, const double *data);
void write(const hid_t data_file_id, const bool write_rhs = true);
/* solvers */
void step();
void roll_rhs();
void AdamsBashforth(int nsteps);
void AdamsBashforth(const int nsteps);
};
#endif//RFFTW_PARTICLES
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment