Skip to content

Commit

Permalink
Make variable naming consistent with text
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Oct 13, 2024
1 parent d0d5720 commit e10ad16
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions docs/modules/ude.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ derivatives to mass flow are not zero.
.. code-block:: python
>>> def my_ude_deriv(ude):
... c0 = ude.conns[0]
... c1 = ude.conns[1]
... if c0.m.is_var:
... ude.jacobian[c0.m.J_col] = 1
... c1 = ude.conns[0]
... c2 = ude.conns[1]
... if c1.m.is_var:
... ude.jacobian[c1.m.J_col] = -2 * ude.conns[1].m.val_SI
... ude.jacobian[c1.m.J_col] = 1
... if c2.m.is_var:
... ude.jacobian[c2.m.J_col] = -2 * ude.conns[1].m.val_SI
Now we can create our instance of the :code:`UserDefinedEquation` and add it to
the network. The class requires four mandatory arguments to be passed:
Expand Down Expand Up @@ -184,21 +184,21 @@ respectively to calculate the partial derivatives.
>>> from tespy.tools.fluid_properties import dT_mix_pdh
>>> def my_ude_deriv(ude):
... c0 = ude.conns[0]
... c1 = ude.conns[1]
... if c0.m.is_var:
... ude.jacobian[c0.m.J_col] = 1 / ude.conns[0].m.val_SI
... if c0.p.is_var:
... ude.jacobian[c0.p.J_col] = - 2 / ude.conns[0].p.val_SI
... T = c1.calc_T()
... c1 = ude.conns[0]
... c2 = ude.conns[1]
... if c1.m.is_var:
... ude.jacobian[c1.m.J_col] = 1 / ude.conns[0].m.val_SI
... if c1.p.is_var:
... ude.jacobian[c1.p.J_col] = (
... dT_mix_dph(c1.p.val_SI, c1.h.val_SI, c1.fluid_data, c1.mixing_rule)
... ude.jacobian[c1.p.J_col] = - 2 / ude.conns[0].p.val_SI
... T = c2.calc_T()
... if c2.p.is_var:
... ude.jacobian[c2.p.J_col] = (
... dT_mix_dph(c2.p.val_SI, c2.h.val_SI, c2.fluid_data, c2.mixing_rule)
... * 0.5 / (T ** 0.5)
... )
... if c1.h.is_var:
... ude.jacobian[c1.h.J_col] = (
... dT_mix_pdh(c1.p.val_SI, c1.h.val_SI, c1.fluid_data, c1.mixing_rule)
... if c2.h.is_var:
... ude.jacobian[c2.h.J_col] = (
... dT_mix_pdh(c2.p.val_SI, c2.h.val_SI, c2.fluid_data, c2.mixing_rule)
... * 0.5 / (T ** 0.5)
... )
Expand All @@ -212,16 +212,16 @@ for the above derivatives would therefore look like this:
.. code-block:: python
>>> def my_ude_deriv(ude):
... c0 = ude.conns[0]
... c1 = ude.conns[1]
... if c0.m.is_var:
... ude.jacobian[c0.m.J_col] = ude.numeric_deriv('m', c0)
... if c0.p.is_var:
... ude.jacobian[c0.p.J_col] = ude.numeric_deriv('p', c0)
... c1 = ude.conns[0]
... c2 = ude.conns[1]
... if c1.m.is_var:
... ude.jacobian[c1.m.J_col] = ude.numeric_deriv('m', c1)
... if c1.p.is_var:
... ude.jacobian[c1.p.J_col] = ude.numeric_deriv('p', c1)
... if c1.h.is_var:
... ude.jacobian[c1.h.J_col] = ude.numeric_deriv('h', c1)
... if c2.p.is_var:
... ude.jacobian[c2.p.J_col] = ude.numeric_deriv('p', c2)
... if c2.h.is_var:
... ude.jacobian[c2.h.J_col] = ude.numeric_deriv('h', c2)
>>> ude = UserDefinedEquation('ude numerical', my_ude, my_ude_deriv, [c1, c2])
>>> nw.add_ude(ude)
Expand Down Expand Up @@ -266,24 +266,24 @@ instance must therefore be changed as below.
>>> def my_ude(ude):
... a = ude.params['a']
... b = ude.params['b']
... c0 = ude.conns[0]
... c1 = ude.conns[1]
... c1 = ude.conns[0]
... c2 = ude.conns[1]
... return (
... a * (c1.h.val_SI - c0.h.val_SI) -
... (c1.h.val_SI - h_mix_pQ(c0.p.val_SI, b, c0.fluid_data))
... a * (c2.h.val_SI - c1.h.val_SI) -
... (c2.h.val_SI - h_mix_pQ(c1.p.val_SI, b, c1.fluid_data))
... )
>>> def my_ude_deriv(ude):
... a = ude.params['a']
... b = ude.params['b']
... c0 = ude.conns[0]
... c1 = ude.conns[1]
... if c0.p.is_var:
... ude.jacobian[c0.p.J_col] = dh_mix_dpQ(c0.p.val_SI, b, c0.fluid_data)
... if c0.h.is_var:
... ude.jacobian[c0.h.J_col] = -a
... c1 = ude.conns[0]
... c2 = ude.conns[1]
... if c1.p.is_var:
... ude.jacobian[c1.p.J_col] = a - 1
... ude.jacobian[c1.p.J_col] = dh_mix_dpQ(c1.p.val_SI, b, c1.fluid_data)
... if c1.h.is_var:
... ude.jacobian[c1.h.J_col] = -a
... if c2.p.is_var:
... ude.jacobian[c2.p.J_col] = a - 1
>>> ude = UserDefinedEquation(
... 'my ude', my_ude, my_ude_deriv, [c1, c2], params={'a': 0.5, 'b': 1}
Expand Down

0 comments on commit e10ad16

Please sign in to comment.