Skip to content

Commit

Permalink
[1D] Improve docstrings and minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Feb 24, 2020
1 parent b283b75 commit 613d5c5
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions interfaces/cython/cantera/onedim.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class FlameBase(Sim1D):
""" Base class for flames with a single flow domain """
__slots__ = ('gas',)
_extra = ()
_extra = () # extra columns used for saving/restoring of simulation data

def __init__(self, domains, gas, grid=None):
"""
Expand Down Expand Up @@ -301,52 +301,51 @@ def write_csv(self, filename, species='X', quiet=True):
print("Solution saved to '{0}'.".format(filename))

def to_solution_array(self):
"""Return the solution vector as a Cantera SolutionArray object.
"""
Return the solution vector as a Cantera `SolutionArray` object.
The SolutionArray has the following ``extra`` entries:
* `grid`: grid point positions along the flame [m]
* `velocity`: normal velocity [m/s]
* `gradient`: tangential velocity gradient [1/s] (if applicable)
* `lambda`: radial pressure gradient [N/m^4] (if applicable)
* `eField`: electric field strength (if applicable)
The `SolutionArray` has the following ``extra`` entries:
* ``grid``: grid point positions along the flame [m]
* ``velocity``: normal velocity [m/s]
* ``gradient``: tangential velocity gradient [1/s] (if applicable)
* ``lambda``: radial pressure gradient [N/m^4] (if applicable)
* ``eField``: electric field strength (if applicable)
"""
# create extra columns
dom = self.domains[1]
extra = {}
for e in self._extra:
if e == 'grid':
extra[e] = self.grid
elif e == 'velocity':
extra[e] = self.profile(dom, 'u')
extra[e] = self.profile(self.flame, 'u')
elif e == 'gradient':
extra[e] = self.profile(dom, 'V')
extra[e] = self.profile(self.flame, 'V')
else:
extra[e] = self.profile(dom, e)
extra[e] = self.profile(self.flame, e)

# create solution array object
arr = SolutionArray(self.gas, self.flame.n_points, extra=extra)

# retrieve species concentrations and set states
X = []
for n in range(self.flame.n_points):
self.set_gas_state(n)
X.append(self.gas.X)
arr.TPX = self.T, self.gas.P, np.vstack(X)
arr[n].TPY = self.gas.T, self.gas.P, self.gas.Y

return arr

def from_solution_array(self, arr):
"""Restore the solution vector from a Cantera SolutionArray object.
"""
Restore the solution vector from a Cantera `SolutionArray` object.
The SolutionArray requires the following ``extra`` entries:
* `grid`: grid point positions along the flame [m]
* `velocity`: normal velocity [m/s]
* `gradient`: tangential velocity gradient [1/s] (if applicable)
* `lambda`: radial pressure gradient [N/m^4] (if applicable)
* `eField`: electric field strength (if applicable)
The `SolutionArray` requires the following ``extra`` entries:
* ``grid``: grid point positions along the flame [m]
* ``velocity``: normal velocity [m/s]
* ``gradient``: tangential velocity gradient [1/s] (if applicable)
* ``lambda``: radial pressure gradient [N/m^4] (if applicable)
* ``eField``: electric field strength (if applicable)
"""
# restore grid
self.domains[1].grid = arr.grid
self.flame.grid = arr.grid
self._get_initial_solution()
xi = (arr.grid - arr.grid[0]) / (arr.grid[-1] - arr.grid[0])

Expand All @@ -370,7 +369,8 @@ def from_solution_array(self, arr):
self.P = arr.P[0]

def to_pandas(self):
"""Return the solution vector as a pandas DataFrame.
"""
Return the solution vector as a `pandas.DataFrame`.
This method uses `to_solution_array` and requires a working pandas
installation. Use pip or conda to install `pandas` to enable this
Expand All @@ -380,7 +380,8 @@ def to_pandas(self):
return self.to_solution_array().to_pandas(cols=cols)

def from_pandas(self, df):
"""Return the solution vector as a pandas DataFrame.
"""
Return the solution vector as a `pandas.DataFrame`.
This method is intendend for loading of data that were previously
exported by `to_pandas`. The method uses `from_solution_array` and
Expand Down

0 comments on commit 613d5c5

Please sign in to comment.