求问,为什么第三方库内定义的函数都直接pass
求问,为什么第三方库内定义的函数都直接pass,那是如何实现它的功能的呢?这个是cantera模块的一个ReactorNet类,其中类方法只有一个注释和pass,我想改变其中的step,但完全看不懂它是如何实现的
# encoding: utf-8
# module cantera._cantera
# from C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\cantera\_cantera.cp37-win_amd64.pyd
# by generator 1.145
# no doc
# imports
import builtins as __builtins__ # <module 'builtins' (built-in)>
import numpy as np # C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\numpy\__init__.py
import math as math # <module 'math' (built-in)>
import sys as sys # <module 'sys' (built-in)>
import os as os # C:\Program Files\Python37\lib\os.py
import warnings as warnings # C:\Program Files\Python37\lib\warnings.py
import weakref as weakref # C:\Program Files\Python37\lib\weakref.py
import numbers as _numbers # C:\Program Files\Python37\lib\numbers.py
import cantera.interrupts as interrupts # C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\cantera\interrupts.py
from .object import object
class ReactorNet(object):
"""
ReactorNet(reactors=())
Networks of reactors. ReactorNet objects are used to simultaneously
advance the state of one or more coupled reactors.
Example:
>>> r1 = Reactor(gas1)
>>> r2 = Reactor(gas2)
>>> <... install walls, inlets, outlets, etc...>
>>> reactor_network = ReactorNet()
>>> reactor_network.advance(time)
"""
def add_reactor(self, Reactor_r): # real signature unknown; restored from __doc__
"""
ReactorNet.add_reactor(self, Reactor r)
Add a reactor to the network.
"""
pass
def advance(self, double_t): # real signature unknown; restored from __doc__
"""
ReactorNet.advance(self, double t)
Advance the state of the reactor network in time from the current
time to time *t* , taking as many integrator timesteps as necessary.
"""
pass
def advance_to_steady_state(self, int_max_steps=10000, double_residual_threshold=0., double_atol=0., bool_return_residuals=False): # real signature unknown; restored from __doc__
"""
ReactorNet.advance_to_steady_state(self, int max_steps=10000, double residual_threshold=0., double atol=0., bool return_residuals=False)
Advance the reactor network in time until steady state is reached.
The steady state is defined by requiring that the state of the system
only changes below a certain threshold. The residual is computed using
feature scaling:
.. math:: r = \left| \frac{x(t + \Delta t) - x(t)}{\text{max}(x) + \text{atol}} \right| \cdot \frac{1}{\sqrt{n_x}}
:param max_steps:
Maximum number of steps to be taken
:param residual_threshold:
Threshold below which the feature-scaled residual r should drop such
that the network is defines as steady state. By default,
residual_threshold is 10 times the solver rtol.
:param atol:
The smallest expected value of interest. Used for feature scaling.
By default, this atol is identical to the solver atol.
:param return_residuals:
If set to `True`, this function returns the residual time series
as a vector with length `max_steps`.
"""
pass
def component_name(self, int_i): # real signature unknown; restored from __doc__
"""
ReactorNet.component_name(self, int i)
Return the name of the i-th component of the global state vector. The
name returned includes both the name of the reactor and the specific
component, e.g. `'reactor1: CH4'`.
"""
pass
def get_state(self): # real signature unknown; restored from __doc__
"""
ReactorNet.get_state(self)
Get the combined state vector of the reactor network.
The combined state vector consists of the concatenated state vectors of
all entities contained.
"""
pass
def reinitialize(self): # real signature unknown; restored from __doc__
"""
ReactorNet.reinitialize(self)
Reinitialize the integrator after making changing to the state of the
system. Changes to Reactor contents will automatically trigger
reinitialization.
"""
pass
def sensitivities(self): # real signature unknown; restored from __doc__
"""
ReactorNet.sensitivities(self)
Returns the sensitivities of all of the solution variables with respect
to all of the registered parameters. The normalized sensitivity
coefficient :math:`S_{ki}` of the solution variable :math:`y_k` with
respect to sensitivity parameter :math:`p_i` is defined as:
.. math:: S_{ki} = \frac{p_i}{y_k} \frac{\partial y_k}{\partial p_i}
For reaction sensitivities, the parameter is a multiplier on the forward
rate constant (and implicitly on the reverse rate constant for
reversible reactions).
The sensitivities are returned in an array with dimensions *(n_vars,
n_sensitivity_params)*, unless no timesteps have been taken, in which
case the shape is *(0, n_sensitivity_params)*. The order of the
variables (i.e., rows) is:
`Reactor` or `IdealGasReactor`:
- 0- mass
- 1- volume
- 2- internal energy or temperature
- 3+ - mass fractions of the species
`ConstPressureReactor` or `IdealGasConstPressureReactor`:
- 0- mass
- 1- enthalpy or temperature
- 2+ - mass fractions of the species
"""
pass
def sensitivity(self, component, int_p, int_r=0): # real signature unknown; restored from __doc__
"""
ReactorNet.sensitivity(self, component, int p, int r=0)
Returns the sensitivity of the solution variable *component* in
reactor *r* with respect to the parameter *p*. *component* can be a
string or an integer. See `component_index` and `sensitivities` to
determine the integer index for the variables and the definition of the
resulting sensitivity coefficient. If it is not given, *r* defaults to
the first reactor. Returns an empty array until the first time step is
taken.
"""
pass
def sensitivity_parameter_name(self, int_p): # real signature unknown; restored from __doc__
"""
ReactorNet.sensitivity_parameter_name(self, int p)
Name of the sensitivity parameter with index *p*.
"""
pass
def set_initial_time(self, double_t): # real signature unknown; restored from __doc__
"""
ReactorNet.set_initial_time(self, double t)
Set the initial time. Restarts integration from this time using the
current state as the initial condition. Default: 0.0 s.
"""
pass
def set_max_time_step(self, double_t): # real signature unknown; restored from __doc__
"""
ReactorNet.set_max_time_step(self, double t)
Set the maximum time step *t* that the integrator is allowed
to use.
"""
pass
def step(self): # real signature unknown; restored from __doc__
"""
ReactorNet.step(self)
Take a single internal time step. The time after taking the step is
returned.
"""
pass
def __copy__(self): # real signature unknown; restored from __doc__
""" ReactorNet.__copy__(self) """
pass
def __init__(self, reactors=()): # real signature unknown; restored from __doc__
pass
@staticmethod # known case of __new__
def __new__(*args, **kwargs): # real signature unknown
""" Create and return a new object.See help(type) for accurate signature. """
pass
def __reduce__(self): # real signature unknown; restored from __doc__
""" ReactorNet.__reduce__(self) """
pass
atol = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""
The absolute error tolerance used while integrating the reactor
equations.
"""
atol_sensitivity = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""
The absolute error tolerance for sensitivity analysis.
"""
max_err_test_fails = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""
The maximum number of error test failures permitted by the CVODES
integrator in a single time step.
"""
n_sensitivity_params = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""
The number of registered sensitivity parameters.
"""
n_vars = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""
The number of state variables in the system. This is the sum of the
number of variables for each `Reactor` and `Wall` in the system.
Equal to:
`Reactor` and `IdealGasReactor`: `n_species` + 3 (mass, volume,
internal energy or temperature).
`ConstPressureReactor` and `IdealGasConstPressureReactor`:
`n_species` + 2 (mass, enthalpy or temperature).
`Wall`: number of surface species
"""
rtol = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""
The relative error tolerance used while integrating the reactor
equations.
"""
rtol_sensitivity = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""
The relative error tolerance for sensitivity analysis.
"""
time = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""The current time ."""
verbose = property(lambda self: object(), lambda self, v: None, lambda self: None)# default
"""
If *True*, verbose debug information will be printed during
integration. The default is *False*.
"""
因为不是用python写的,懂吧 本帖最后由 hrp 于 2020-9-4 12:41 编辑
专门定义只有pass的Python空函数,是为了让用户能够在Python程序中实现对这些函数的重写以实现某执行些流程的变化。
比如一个模块中某个类有退出方法exit,这个程序是用C写的,python用户无法去重写这个方法。这个exit方法内部的实现是这样的:先调用执行python写的空函数close_event,再执行exit剩下的语句后退出。当用户程序继承这个类时,如果不重写close_event,那么执行exit后只会正常退出。如果重写了close_event比如保存某些文件,那执行exit时,程序就会先保存某些某些文件再退出,这样就实现了退出流程的自定义。
页:
[1]