switch dump yaml/netcdf thermo output to use new caching API. remove old API.

This commit is contained in:
Axel Kohlmeyer
2023-06-06 22:40:13 -04:00
parent 14acb3e0ca
commit b81b1f5ecc
6 changed files with 87 additions and 93 deletions

View File

@ -220,7 +220,7 @@ void DumpNetCDFMPIIO::openfile()
if (thermo && !singlefile_opened) {
delete[] thermovar;
thermovar = new int[output->thermo->nfield];
thermovar = new int[output->thermo->get_keywords().size()];
}
// now the computes and fixes have been initialized, so we can query
@ -318,9 +318,10 @@ void DumpNetCDFMPIIO::openfile()
// perframe variables
if (thermo) {
Thermo *th = output->thermo;
for (int i = 0; i < th->nfield; i++) {
NCERRX( ncmpi_inq_varid(ncid, th->keyword[i].c_str(), &thermovar[i]), th->keyword[i].c_str() );
auto keywords = output->thermo->get_keywords();
int nfield = keywords.size();
for (int i = 0; i < nfield; i++) {
NCERRX( ncmpi_inq_varid(ncid, keywords[i].c_str(), &thermovar[i]), keywords[i].c_str() );
}
}
@ -422,18 +423,16 @@ void DumpNetCDFMPIIO::openfile()
// perframe variables
if (thermo) {
Thermo *th = output->thermo;
for (int i = 0; i < th->nfield; i++) {
if (th->vtype[i] == Thermo::FLOAT) {
NCERRX( ncmpi_def_var(ncid, th->keyword[i].c_str(), type_nc_real, 1, dims, &thermovar[i]), th->keyword[i].c_str() );
} else if (th->vtype[i] == Thermo::INT) {
NCERRX( ncmpi_def_var(ncid, th->keyword[i].c_str(), NC_INT, 1, dims, &thermovar[i]), th->keyword[i].c_str() );
} else if (th->vtype[i] == Thermo::BIGINT) {
#if defined(LAMMPS_SMALLBIG) || defined(LAMMPS_BIGBIG)
NCERRX( ncmpi_def_var(ncid, th->keyword[i].c_str(), NC_INT64, 1, dims, &thermovar[i]), th->keyword[i].c_str() );
#else
NCERRX( ncmpi_def_var(ncid, th->keyword[i].c_str(), NC_LONG, 1, dims, &thermovar[i]), th->keyword[i].c_str() );
#endif
auto fields = output->thermo->get_fields();
auto keywords = output->thermo->get_keywords();
int nfield = fields.size();
for (int i = 0; i < nfield; i++) {
if (fields[i].type == multitype::DOUBLE) {
NCERRX( ncmpi_def_var(ncid, keywords[i].c_str(), type_nc_real, 1, dims, &thermovar[i]), keywords[i].c_str() );
} else if (fields[i].type == multitype::INT) {
NCERRX( ncmpi_def_var(ncid, keywords[i].c_str(), NC_INT, 1, dims, &thermovar[i]), keywords[i].c_str() );
} else if (fields[i].type == multitype::BIGINT) {
NCERRX( ncmpi_def_var(ncid, keywords[i].c_str(), NC_INT64, 1, dims, &thermovar[i]), keywords[i].c_str() );
}
}
}
@ -594,20 +593,17 @@ void DumpNetCDFMPIIO::write()
NCERR( ncmpi_begin_indep_data(ncid) );
if (thermo) {
Thermo *th = output->thermo;
for (int i = 0; i < th->nfield; i++) {
th->call_vfunc(i);
auto keywords = output->thermo->get_keywords();
auto fields = output->thermo->get_fields();
int nfield = fields.size();
for (int i = 0; i < nfield; i++) {
if (filewriter) {
if (th->vtype[i] == Thermo::FLOAT) {
NCERRX( ncmpi_put_var1_double(ncid, thermovar[i], start,
&th->dvalue),
th->keyword[i].c_str() );
} else if (th->vtype[i] == Thermo::INT) {
NCERRX( ncmpi_put_var1_int(ncid, thermovar[i], start, &th->ivalue),
th->keyword[i].c_str() );
} else if (th->vtype[i] == Thermo::BIGINT) {
NCERRX( ncmpi_put_var1_bigint(ncid, thermovar[i], start, &th->bivalue),
th->keyword[i].c_str() );
if (fields[i].type == multitype::DOUBLE) {
NCERRX( ncmpi_put_var1_double(ncid, thermovar[i], start, &fields[i].data.d), keywords[i].c_str() );
} else if (fields[i].type == multitype::INT) {
NCERRX( ncmpi_put_var1_int(ncid, thermovar[i], start, &fields[i].data.i), keywords[i].c_str() );
} else if (fields[i].type == multitype::BIGINT) {
NCERRX( ncmpi_put_var1_bigint(ncid, thermovar[i], start, &fields[i].data.b), keywords[i].c_str() );
}
}
}