Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outstart, so far only for constant dt #494

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The development team consists of (in alphabetic order):
Sylwester Arabas
(core code, library design, OOP-formulae concepts [4],
concurrency, gnuplot output)
Piotr Dziekan
Dorota Jarecka
(shallow-water systems, OOP-formulae concepts [4])
Anna Jaruga
Expand Down
11 changes: 8 additions & 3 deletions libmpdata++/output/detail/output_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace libmpdataxx

int do_record_cnt = 0;
typename parent_t::real_t record_time;
const typename parent_t::advance_arg_t outfreq;
const typename parent_t::advance_arg_t outfreq, outstart;
const int outwindow;
const std::string outdir;

Expand Down Expand Up @@ -158,7 +158,7 @@ namespace libmpdataxx
record_time = this->time;
for (int t = 0; t < outwindow; ++t)
{
if ((this->timestep - t) % static_cast<int>(outfreq) == 0) record_all();
if ((this->timestep - t) % static_cast<int>(outfreq) == 0 && this->timestep >= static_cast<int>(outstart)) record_all();
}
}
}
Expand All @@ -170,7 +170,8 @@ namespace libmpdataxx

struct rt_params_t : parent_t::rt_params_t
{
typename parent_t::advance_arg_t outfreq = 1;
typename parent_t::advance_arg_t outfreq = 1,
outstart = 0; // TODO: make it work for var_dt
int outwindow = 1;
std::map<int, info_t> outvars;
std::string outdir;
Expand All @@ -184,11 +185,15 @@ namespace libmpdataxx
) :
parent_t(args, p),
outfreq(p.outfreq),
outstart(p.outstart),
outwindow(p.outwindow),
outvars(p.outvars),
outdir(p.outdir),
intrp_vars(args.mem->tmp[__FILE__][0])
{
assert(int(outstart) % int(outfreq) == 0);
assert(int(outstart)==0 || this->var_dt==0);

// default value for outvars
if (this->outvars.size() == 0 && parent_t::n_eqns == 1)
outvars = {{0, {"", ""}}};
Expand Down
1 change: 1 addition & 0 deletions libmpdata++/output/gnuplot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace libmpdataxx

for (int t = 0; t <= nt; t+=p.outfreq)
{
if(t > 0 && t < p.outstart) continue;
for (const auto &v : this->outvars)
{
*gp << ", '-'";
Expand Down
47 changes: 43 additions & 4 deletions libmpdata++/output/hdf5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,21 @@ namespace libmpdataxx

// T
{
const hsize_t
nt_out = nt / this->outfreq + 1; // incl. t=0
// incl. t=0 and t=outstart
const hsize_t nt_out = this->outstart == 0 ?
(nt - this->outstart) / this->outfreq + 1 :
(nt - this->outstart) / this->outfreq + 2; // for outstart>0 we still want to store t=0

float dt = this->dt;

blitz::Array<typename solver_t::real_t, 1> coord(nt_out);
coord = (this->var_dt ? this->outfreq : this->outfreq * this->dt) * blitz::firstIndex();
if(this->outstart == 0)
coord(blitz::Range(0,nt_out-1)) = (this->var_dt ? this->outfreq : this->outfreq * this->dt) * (blitz::firstIndex() + this->outstart/this->outfreq);
else
{
coord(blitz::Range(1,nt_out-1)) = (this->var_dt ? this->outfreq : this->outfreq * this->dt) * (blitz::firstIndex() + this->outstart/this->outfreq);
coord(0)=0;
}

auto curr_dim = (*hdfp).createDataSet("T", flttype_output, H5::DataSpace(1, &nt_out));

Expand Down Expand Up @@ -365,6 +374,22 @@ namespace libmpdataxx
aux.write(data, flttype_solver, H5::DataSpace(parent_t::n_dims, shape.data()), space, dxpl_id);
}

// for 1-D arrays
void record_aux_hlpr(const std::string &name, typename solver_t::real_t *data, hsize_t size, H5::H5File hdf)
{
assert(this->rank == 0);

auto aux = hdf.createDataSet(
name,
flttype_output,
H5::DataSpace(1, &size)
);

auto space = aux.getSpace();
space.selectHyperslab(H5S_SELECT_SET, &size, &zero);
aux.write(data, flttype_solver, H5::DataSpace(1, &size), space, dxpl_id);
}

// for discontiguous array with halos
void record_aux_dsc_hlpr(const std::string &name, const typename solver_t::arr_t &arr, H5::H5File hdf, bool srfc = false)
{
Expand Down Expand Up @@ -516,10 +541,24 @@ namespace libmpdataxx
// has to be called after const file was created (i.e. after start())
void record_aux_const(const std::string &name, typename solver_t::real_t *data)
{
H5::H5File hdfcp(const_file, H5F_ACC_RDWR); // reopen the const file
H5::H5File hdfcp(const_file, H5F_ACC_RDWR
#if defined(USE_MPI)
, H5P_DEFAULT, fapl_id
#endif
); // reopen the const file
record_aux_hlpr(name, data, hdfcp);
}

void record_aux_const(const std::string &name, typename solver_t::real_t *data, const int &size)
{
H5::H5File hdfcp(const_file, H5F_ACC_RDWR
#if defined(USE_MPI)
, H5P_DEFAULT, fapl_id
#endif
); // reopen the const file
record_aux_hlpr(name, data, size, hdfcp);
}

void record_aux_const(const std::string &name, const std::string &group_name, typename solver_t::real_t data)
{
H5::H5File hdfcp(const_file, H5F_ACC_RDWR
Expand Down
Loading