mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[Python] Add SolutionArray tweaks to API
This commit is contained in:
parent
4406110573
commit
30d21073cc
@ -112,8 +112,8 @@ cdef extern from "cantera/oneD/Sim1D.h":
|
||||
void refine(int) except +translate_exception
|
||||
void setRefineCriteria(size_t, double, double, double, double) except +translate_exception
|
||||
vector[double] getRefineCriteria(int) except +translate_exception
|
||||
void save(string, string, string, int, int) except +translate_exception
|
||||
CxxAnyMap restore(string, string, int) except +translate_exception
|
||||
void save(string&, string&, string&, cbool, int) except +translate_exception
|
||||
CxxAnyMap restore(string&, string&) except +translate_exception
|
||||
void writeStats(int) except +translate_exception
|
||||
void clearStats()
|
||||
void resize() except +translate_exception
|
||||
|
@ -1523,7 +1523,7 @@ cdef class Sim1D:
|
||||
return self.sim.fixedTemperatureLocation()
|
||||
|
||||
def save(self, filename='soln.yaml', name='solution', description=None,
|
||||
loglevel=1, compression=0):
|
||||
loglevel=None, overwrite=False, compression=0):
|
||||
"""
|
||||
Save the solution in YAML or HDF format.
|
||||
|
||||
@ -1533,17 +1533,24 @@ cdef class Sim1D:
|
||||
solution name within the file
|
||||
:param description:
|
||||
custom description text
|
||||
:param overwrite:
|
||||
Force overwrite if name exists; optional (default=`False`)
|
||||
:param compression:
|
||||
compression level 0..9; optional (HDF only)
|
||||
|
||||
>>> s.save(filename='save.yaml', name='energy_off',
|
||||
... description='solution with energy eqn. disabled')
|
||||
|
||||
.. versionchanged:: 3.0
|
||||
Argument loglevel is no longer supported
|
||||
"""
|
||||
if loglevel is not None:
|
||||
warnings.warn("Argument 'loglevel' is deprecated and will be ignored.",
|
||||
DeprecationWarning)
|
||||
self.sim.save(stringify(str(filename)), stringify(name),
|
||||
stringify(description), loglevel, compression)
|
||||
stringify(description), overwrite, compression)
|
||||
|
||||
def restore(self, filename='soln.yaml', name='solution', loglevel=2):
|
||||
def restore(self, filename='soln.yaml', name='solution', loglevel=None):
|
||||
"""Set the solution vector to a previously-saved solution.
|
||||
|
||||
:param filename:
|
||||
@ -1559,10 +1566,13 @@ cdef class Sim1D:
|
||||
>>> s.restore(filename='save.yaml', name='energy_off')
|
||||
|
||||
.. versionchanged:: 3.0
|
||||
Implemented return value for meta data
|
||||
Implemented return value for meta data; loglevel is no longer supported
|
||||
"""
|
||||
if loglevel is not None:
|
||||
warnings.warn("Argument 'loglevel' is deprecated and will be ignored.",
|
||||
DeprecationWarning)
|
||||
cdef CxxAnyMap header
|
||||
header = self.sim.restore(stringify(str(filename)), stringify(name), loglevel)
|
||||
header = self.sim.restore(stringify(str(filename)), stringify(name))
|
||||
self._initialized = True
|
||||
return anymap_to_dict(header)
|
||||
|
||||
|
@ -1230,7 +1230,8 @@ class SolutionArray(SolutionArrayBase):
|
||||
data_dict[label] = data[:, i]
|
||||
self.restore_data(data_dict, normalize)
|
||||
|
||||
def save(self, fname, name=None, key=None, description=None, compression=0):
|
||||
def save(self, fname, name=None, key=None, description=None,
|
||||
overwrite=False, compression=0):
|
||||
"""
|
||||
Save current `SolutionArray` and header to a container file.
|
||||
|
||||
@ -1244,14 +1245,14 @@ class SolutionArray(SolutionArrayBase):
|
||||
metadata objects. If `None`, the subgroup name default to ``data``.
|
||||
:param description:
|
||||
Custom comment describing the dataset to be stored.
|
||||
:param overwrite:
|
||||
Force overwrite if name exists; optional (default=`False`)
|
||||
:param compression:
|
||||
Compression level (0-9); optional (default=0; HDF only)
|
||||
:return:
|
||||
Group identifier used for storing HDF data.
|
||||
|
||||
.. versionadded:: 3.0
|
||||
"""
|
||||
return self._cxx_save(fname, name, key, description, compression)
|
||||
self._cxx_save(fname, name, key, description, overwrite, compression)
|
||||
|
||||
def restore(self, fname, name=None, key=None):
|
||||
"""
|
||||
@ -1352,11 +1353,13 @@ class SolutionArray(SolutionArrayBase):
|
||||
"""
|
||||
warnings.warn("Method to be removed after Cantera 3.0; use 'save' instead.\n"
|
||||
"Note that the call is redirected to 'save' in order to prevent the "
|
||||
"creation of a file with legacy HDF format.", DeprecationWarning)
|
||||
"creation of a file with legacy HDF format;\nas a consequence, "
|
||||
"some options are no longer supported.", DeprecationWarning)
|
||||
|
||||
if group is None:
|
||||
raise KeyError("Missing required parameter 'group'.")
|
||||
return self.save(filename, name=group, key=subgroup)
|
||||
self.save(filename, name=group, key=subgroup)
|
||||
return group
|
||||
|
||||
def read_hdf(self, filename, group=None, subgroup=None, force=False, normalize=True):
|
||||
"""
|
||||
|
@ -576,8 +576,7 @@ class FlameBase(Sim1D):
|
||||
"Note that the call is redirected to 'save' in order to prevent the "
|
||||
"creation of a file with deprecated HDF format.", DeprecationWarning)
|
||||
|
||||
self.save(filename, name=group, description=description,
|
||||
loglevel=int(not quiet))
|
||||
self.save(filename, name=group, description=description)
|
||||
|
||||
def read_hdf(self, filename, group=None, restore_boundaries=True, normalize=True):
|
||||
"""
|
||||
|
@ -94,7 +94,7 @@ cdef extern from "cantera/base/SolutionArray.h" namespace "Cantera":
|
||||
CxxAnyMap getAuxiliary(size_t) except +translate_exception
|
||||
void setAuxiliary(size_t, CxxAnyMap&) except +translate_exception
|
||||
void append(vector[double]&, CxxAnyMap&) except +translate_exception
|
||||
string save(string&, string&, string&, string&, int) except +translate_exception
|
||||
void save(string&, string&, string&, string&, cbool, int) except +translate_exception
|
||||
CxxAnyMap restore(string&, string&, string&) except +translate_exception
|
||||
|
||||
cdef shared_ptr[CxxSolutionArray] CxxNewSolutionArray "Cantera::SolutionArray::create" (
|
||||
|
@ -634,13 +634,11 @@ cdef class SolutionArrayBase:
|
||||
cxx_state.push_back(item)
|
||||
self.base.append(cxx_state, dict_to_anymap(extra))
|
||||
|
||||
def _cxx_save(self, filename, name, key, description, compression):
|
||||
def _cxx_save(self, filename, name, key, description, overwrite, compression):
|
||||
""" Interface `SolutionArray.save` with C++ core """
|
||||
cdef string cxx_path
|
||||
cxx_path = self.base.save(
|
||||
self.base.save(
|
||||
stringify(str(filename)), stringify(name), stringify(key),
|
||||
stringify(description), compression)
|
||||
return pystr(cxx_path)
|
||||
stringify(description), overwrite, compression)
|
||||
|
||||
def _cxx_restore(self, filename, name, key):
|
||||
""" Interface `SolutionArray.restore` with C++ core """
|
||||
|
Loading…
Reference in New Issue
Block a user