sdocutils.nodesdocument)}( rawsourcechildren](htarget)}(h.. _dda-rationale:h]
attributes}(ids]classes]names]dupnames]backrefs]refid
dda-rationaleutagnameh lineKparenthhhsourceB/builds/software/pyanalog-mirror-from-github/doc/dda/rationale.rstubhsection)}(hhh](htitle)}(hA rationale about DDAh]hTextA rationale about DDA}(hh+hh)hhh NhNubah}(h]h]h]h]h]uhh'hh$hhh h!hKubh paragraph)}(hXThe following text is an introduction into the *DDA* concepts. It is envisaged for readers
who want to trace the connections between analog computing and it's digital simulation.
If you only want to work with `PyDDA` but do not care about the fundamentals, you can
skip this text.h](h./The following text is an introduction into the }(h/The following text is an introduction into the hh;hhh NhNubhemphasis)}(h*DDA*h]h.DDA}(hhhhFubah}(h]h]h]h]h]uhhDhh;ubh. concepts. It is envisaged for readers
who want to trace the connections between analog computing and it’s digital simulation.
If you only want to work with }(h concepts. It is envisaged for readers
who want to trace the connections between analog computing and it's digital simulation.
If you only want to work with hh;hhh NhNubhtitle_reference)}(h`PyDDA`h]h.PyDDA}(hhhh[ubah}(h]h]h]h]h]uhhYhh;ubh.@ but do not care about the fundamentals, you can
skip this text.}(h@ but do not care about the fundamentals, you can
skip this text.hh;hhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhh$hhubh#)}(hhh](h()}(hThe digital number flow machineh]h.The digital number flow machine}(hhyhhwhhh NhNubah}(h]h]h]h]h]uhh'hhthhh h!hK
ubh:)}(hX_DDA is short for *digital differential analyzer*. This term describes a certain way of
building an algorithmic-logical unit which is programmed with a dataflow paradigm. It
can be imagined as an analog computer but with digital computing elements in place of
analog computing elements. Such a DDA machine could feature *n* bit integer adders
(for instance a ripple-carry adder), binary multipliers, and even discrete integrators
for adding integers (i.e. a stateful computing element). In general, it is straightforward
to design such a machine for some fixed width binary number representation. It is worth
emphasizing that such a machine neither features continous time nor continous number
representation as a real analog computer would have. Nevertheless, it is an interesting
computing architecture as it is half-way between an analog and a digital computer.h](h.DDA is short for }(hDDA is short for hhhhh NhNubhE)}(h*digital differential analyzer*h]h.digital differential analyzer}(hhhhubah}(h]h]h]h]h]uhhDhhubh.X. This term describes a certain way of
building an algorithmic-logical unit which is programmed with a dataflow paradigm. It
can be imagined as an analog computer but with digital computing elements in place of
analog computing elements. Such a DDA machine could feature }(hX. This term describes a certain way of
building an algorithmic-logical unit which is programmed with a dataflow paradigm. It
can be imagined as an analog computer but with digital computing elements in place of
analog computing elements. Such a DDA machine could feature hhhhh NhNubhE)}(h*n*h]h.n}(hhhhubah}(h]h]h]h]h]uhhDhhubh.X bit integer adders
(for instance a ripple-carry adder), binary multipliers, and even discrete integrators
for adding integers (i.e. a stateful computing element). In general, it is straightforward
to design such a machine for some fixed width binary number representation. It is worth
emphasizing that such a machine neither features continous time nor continous number
representation as a real analog computer would have. Nevertheless, it is an interesting
computing architecture as it is half-way between an analog and a digital computer.}(hX bit integer adders
(for instance a ripple-carry adder), binary multipliers, and even discrete integrators
for adding integers (i.e. a stateful computing element). In general, it is straightforward
to design such a machine for some fixed width binary number representation. It is worth
emphasizing that such a machine neither features continous time nor continous number
representation as a real analog computer would have. Nevertheless, it is an interesting
computing architecture as it is half-way between an analog and a digital computer.hhhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhhthhubh:)}(hX~In the age of FPGAs (field programmable gate arrays), it is straightforward to generate
digital computing circuits by software descriptions. Furthermore, being a digital
computer, the DDA architecture can be simulated by any Turing machine. This makes it
straightforward to write a simulator for contemporary register machines (that is,
regular and widespread computers/processors).h]h.X~In the age of FPGAs (field programmable gate arrays), it is straightforward to generate
digital computing circuits by software descriptions. Furthermore, being a digital
computer, the DDA architecture can be simulated by any Turing machine. This makes it
straightforward to write a simulator for contemporary register machines (that is,
regular and widespread computers/processors).}(hhhhhhh NhNubah}(h]h]h]h]h]uhh9h h!hKhhthhubeh}(h]the-digital-number-flow-machineah]h]the digital number flow machineah]h]uhh"hh$hhh h!hK
ubh#)}(hhh](h()}(h'Describing and simulating a DDA machineh]h.'Describing and simulating a DDA machine}(hhhhhhh NhNubah}(h]h]h]h]h]uhh'hhhhh h!hK!ubh:)}(hAThe DDA code proposed in this document consists of several parts:h]h.AThe DDA code proposed in this document consists of several parts:}(hhhhhhh NhNubah}(h]h]h]h]h]uhh9h h!hK#hhhhubhbullet_list)}(hhh](h list_item)}(hDAn easy description language for the computational network (circuit)h]h:)}(hhh]h.DAn easy description language for the computational network (circuit)}(hhhhubah}(h]h]h]h]h]uhh9h h!hK%hhubah}(h]h]h]h]h]uhhhhhhh h!hNubh)}(hFA compiler from that language to an iterative imperative code (Perl/C)h]h:)}(hjh]h.FA compiler from that language to an iterative imperative code (Perl/C)}(hjhjubah}(h]h]h]h]h]uhh9h h!hK&hj
ubah}(h]h]h]h]h]uhhhhhhh h!hNubh)}(h9Tools for running such a code and evaluating the results
h]h:)}(h8Tools for running such a code and evaluating the resultsh]h.8Tools for running such a code and evaluating the results}(hj*hj(ubah}(h]h]h]h]h]uhh9h h!hK'hj$ubah}(h]h]h]h]h]uhhhhhhh h!hNubeh}(h]h]h]h]h]bullet*uhhh h!hK%hhhhubh:)}(huLoosely speaking, this translation works as follows: A circuit file is an ASCII
line based text file which looks likeh]h.uLoosely speaking, this translation works as follows: A circuit file is an ASCII
line based text file which looks like}(hjFhjDhhh NhNubah}(h]h]h]h]h]uhh9h h!hK)hhhhubh
literal_block)}(hdt = const(0.0005)
t = int(1, dt)
y0 = const(-1)
minus_dy0 = const(-1)
minus_dy = int(y, dt, minus_dy0)
y = int(minus_dy, dt, y0)h]h.dt = const(0.0005)
t = int(1, dt)
y0 = const(-1)
minus_dy0 = const(-1)
minus_dy = int(y, dt, minus_dy0)
y = int(minus_dy, dt, y0)}(hhhjTubah}(h]h]h]h]h] xml:spacepreserveforcelanguagepythonhighlight_args}uhjRh h!hK,hhhhubh:)}(hXThat is, each line is an assignment of some variable to some expression, which is either
a constant (``const``) or a compound expression of computing elements. These expressions
are written in some standard C-like notation ``f(x,y,...)`` where ``f`` is the identifier for
the function and ``x,y,...`` are comma seperated arguments. The following *basic arithmetic*
(from the perspective of an analog computer) computing elements are defined:h](h.eThat is, each line is an assignment of some variable to some expression, which is either
a constant (}(heThat is, each line is an assignment of some variable to some expression, which is either
a constant (hjihhh NhNubhliteral)}(h ``const``h]h.const}(hhhjtubah}(h]h]h]h]h]uhjrhjiubh.q) or a compound expression of computing elements. These expressions
are written in some standard C-like notation }(hq) or a compound expression of computing elements. These expressions
are written in some standard C-like notation hjihhh NhNubjs)}(h``f(x,y,...)``h]h.
f(x,y,...)}(hhhjubah}(h]h]h]h]h]uhjrhjiubh. where }(h where hjihhh NhNubjs)}(h``f``h]h.f}(hhhjubah}(h]h]h]h]h]uhjrhjiubh.( is the identifier for
the function and }(h( is the identifier for
the function and hjihhh NhNubjs)}(h``x,y,...``h]h.x,y,...}(hhhjubah}(h]h]h]h]h]uhjrhjiubh.. are comma seperated arguments. The following }(h. are comma seperated arguments. The following hjihhh NhNubhE)}(h*basic arithmetic*h]h.basic arithmetic}(hhhjubah}(h]h]h]h]h]uhhDhjiubh.M
(from the perspective of an analog computer) computing elements are defined:}(hM
(from the perspective of an analog computer) computing elements are defined:hjihhh NhNubeh}(h]h]h]h]h]uhh9h h!hK6hhhhubh)}(hhh](h)}(h :math:`neg(x) = -x`, the inverseh]h:)}(hjh](hmath)}(h:math:`neg(x) = -x`h]h.neg(x) = -x}(hhhjubah}(h]h]h]h]h]uhjhjubh.
, the inverse}(h
, the inversehjubeh}(h]h]h]h]h]uhh9h h!hKhj*ubah}(h]h]h]h]h]uhhhjhhh h!hNubh)}(hl:math:`sum(a_0, a_1, \dots) = - \sum_i a_i`, the summation in analog-computer typical
*negating* convention.h]h:)}(hl:math:`sum(a_0, a_1, \dots) = - \sum_i a_i`, the summation in analog-computer typical
*negating* convention.h](j)}(h+:math:`sum(a_0, a_1, \dots) = - \sum_i a_i`h]h.#sum(a_0, a_1, \dots) = - \sum_i a_i}(hhhjXubah}(h]h]h]h]h]uhjhjTubh.+, the summation in analog-computer typical
}(h+, the summation in analog-computer typical
hjTubhE)}(h
*negating*h]h.negating}(hhhjkubah}(h]h]h]h]h]uhhDhjTubh. convention.}(h convention.hjTubeh}(h]h]h]h]h]uhh9h h!hK?hjPubah}(h]h]h]h]h]uhhhjhhh h!hNubh)}(h:math:`int(a_0, a_1, \dots, \Delta t, I_0) \approx - \int \sum_i a_i \, \Delta t + I_0`,
the time integration (again in analog-computer typical negating convention).
The digital integrator is discussed in detail in the following text.
h]h:)}(h:math:`int(a_0, a_1, \dots, \Delta t, I_0) \approx - \int \sum_i a_i \, \Delta t + I_0`,
the time integration (again in analog-computer typical negating convention).
The digital integrator is discussed in detail in the following text.h](j)}(hW:math:`int(a_0, a_1, \dots, \Delta t, I_0) \approx - \int \sum_i a_i \, \Delta t + I_0`h]h.Oint(a_0, a_1, \dots, \Delta t, I_0) \approx - \int \sum_i a_i \, \Delta t + I_0}(hhhjubah}(h]h]h]h]h]uhjhjubh.,
the time integration (again in analog-computer typical negating convention).
The digital integrator is discussed in detail in the following text.}(h,
the time integration (again in analog-computer typical negating convention).
The digital integrator is discussed in detail in the following text.hjubeh}(h]h]h]h]h]uhh9h h!hKAhjubah}(h]h]h]h]h]uhhhjhhh h!hNubeh}(h]h]h]h]h]jBjCuhhh h!hKb) ? (a-b) : 0 = lt(b,a,a-b,0)``h]h:)}(hjh]js)}(hjh]h.3dead_upper(a,b) = (a>b) ? (a-b) : 0 = lt(b,a,a-b,0)}(hhhjubah}(h]h]h]h]h]uhjrhjubah}(h]h]h]h]h]uhh9h h!hKMhjubah}(h]h]h]h]h]uhhhjhhh h!hNubh)}(h*``min(a,b) = (a**b) ? a : b = gt(a,b,a,b)``h]h:)}(hjh]js)}(hjh]h.&max(a,b) = (a>b) ? a : b = gt(a,b,a,b)}(hhhjubah}(h]h]h]h]h]uhjrhjubah}(h]h]h]h]h]uhh9h h!hKOhjubah}(h]h]h]h]h]uhhhjhhh h!hNubh)}(h+``abs(a) = (a<0) ? -a : a = lt(a,0,-a,a)``h]h:)}(hjh]js)}(hjh]h.'abs(a) = (a<0) ? -a : a = lt(a,0,-a,a)}(hhhjubah}(h]h]h]h]h]uhjrhjubah}(h]h]h]h]h]uhh9h h!hKPhjubah}(h]h]h]h]h]uhhhjhhh h!hNubh)}(h?``floor(a) = (int)a`` rounds ``a`` to the next lower integer.
h]h:)}(h>``floor(a) = (int)a`` rounds ``a`` to the next lower integer.h](js)}(h``floor(a) = (int)a``h]h.floor(a) = (int)a}(hhhjubah}(h]h]h]h]h]uhjrhjubh. rounds }(h rounds hjubjs)}(h``a``h]h.a}(hhhj*ubah}(h]h]h]h]h]uhjrhjubh. to the next lower integer.}(h to the next lower integer.hjubeh}(h]h]h]h]h]uhh9h h!hKQhjubah}(h]h]h]h]h]uhhhjhhh h!hNubeh}(h]h]h]h]h]jBjCuhhh h!hKHhhhhubh:)}(hNote that this is only a subset of the overall computing elements defined. It is easy
to introduce new computing elements, they are defined in the :mod:`dda.computing_elements`.h](h.Note that this is only a subset of the overall computing elements defined. It is easy
to introduce new computing elements, they are defined in the }(hNote that this is only a subset of the overall computing elements defined. It is easy
to introduce new computing elements, they are defined in the hjOhhh NhNubsphinx.addnodespending_xref)}(h:mod:`dda.computing_elements`h]js)}(hj]h]h.dda.computing_elements}(hhhj_ubah}(h]h](xrefpypy-modeh]h]h]uhjrhj[ubah}(h]h]h]h]h]refdoc
dda/rationale refdomainjjreftypemodrefexplicitrefwarn py:moduleNpy:classN reftargetdda.computing_elementsuhjYh h!hKShjOubh..}(hjhjOhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKShhhhubeh}(h]'describing-and-simulating-a-dda-machineah]h]'describing and simulating a dda machineah]h]uhh"hh$hhh h!hK!ubh#)}(hhh](h()}(hLinearization of a circuith]h.Linearization of a circuit}(hjhjhhh NhNubah}(h]h]h]h]h]uhh'hjhhh h!hKWubh:)}(hX=The ``dda2c.pl`` Perl script translates a DDA circuit file to a valid *C* program. To do
so, all quantities are treated as *real valued* and are associated with the *double*
floating point data type. As C is a strongly typed language, all defined quantities are
collected and introduced as stack variables before use.h](h.The }(hThe hjhhh NhNubjs)}(h``dda2c.pl``h]h.dda2c.pl}(hhhjubah}(h]h]h]h]h]uhjrhjubh.6 Perl script translates a DDA circuit file to a valid }(h6 Perl script translates a DDA circuit file to a valid hjhhh NhNubhE)}(h*C*h]h.C}(hhhjubah}(h]h]h]h]h]uhhDhjubh.2 program. To do
so, all quantities are treated as }(h2 program. To do
so, all quantities are treated as hjhhh NhNubhE)}(h
*real valued*h]h.real valued}(hhhjubah}(h]h]h]h]h]uhhDhjubh. and are associated with the }(h and are associated with the hjhhh NhNubhE)}(h*double*h]h.double}(hhhjubah}(h]h]h]h]h]uhhDhjubh.
floating point data type. As C is a strongly typed language, all defined quantities are
collected and introduced as stack variables before use.}(h
floating point data type. As C is a strongly typed language, all defined quantities are
collected and introduced as stack variables before use.hjhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKYhjhhubh:)}(hX$The actual imperative program then just takes the DDA circuit line-by-line. This introduces
a bias, as the computing network by itself is executed *synchronously* while a simulation
with a single arithmetic logical unit (ALU) on an ordinary processor can only execute one
operation at a time.h](h.The actual imperative program then just takes the DDA circuit line-by-line. This introduces
a bias, as the computing network by itself is executed }(hThe actual imperative program then just takes the DDA circuit line-by-line. This introduces
a bias, as the computing network by itself is executed hjhhh NhNubhE)}(h*synchronously*h]h.
synchronously}(hhhjubah}(h]h]h]h]h]uhhDhjubh. while a simulation
with a single arithmetic logical unit (ALU) on an ordinary processor can only execute one
operation at a time.}(h while a simulation
with a single arithmetic logical unit (ALU) on an ordinary processor can only execute one
operation at a time.hjhhh NhNubeh}(h]h]h]h]h]uhh9h h!hK^hjhhubhnote)}(hIt would be interesting to think a bit whether we could not write an DDA-level exact
simulator, since the DDA machine is clocked. We should be able to correctly simulate
this clock.h]h:)}(hIt would be interesting to think a bit whether we could not write an DDA-level exact
simulator, since the DDA machine is clocked. We should be able to correctly simulate
this clock.h]h.It would be interesting to think a bit whether we could not write an DDA-level exact
simulator, since the DDA machine is clocked. We should be able to correctly simulate
this clock.}(hj(hj&ubah}(h]h]h]h]h]uhh9h h!hKehj"ubah}(h]h]h]h]h]uhj hjhhh h!hNubh:)}(hXSince the DDA is subject to a discrete computing cycle, a register machine can simulate
the DDA architecture cycle by cycle, computing the value of each computing element
input and output. For the sake of extraordinary introspection and debugging facilities,
the DDA to C compiler dismantles compound expressions ``f(g(x))`` or ``f(a,b(c),d(e))``
and entitles all intermediate expressions such as ``gx=g(x)`` in ``f(gx)`` or
``g=b(c)`` and ``h=d(e)`` in ``f(a,g,h)``. This is especially handy when the DDA is seen
as an approximation of the analog computer, as it allows for checking the boundness
(correct scaling) of all variables during the cycles (time evolution).h](h.X9Since the DDA is subject to a discrete computing cycle, a register machine can simulate
the DDA architecture cycle by cycle, computing the value of each computing element
input and output. For the sake of extraordinary introspection and debugging facilities,
the DDA to C compiler dismantles compound expressions }(hX9Since the DDA is subject to a discrete computing cycle, a register machine can simulate
the DDA architecture cycle by cycle, computing the value of each computing element
input and output. For the sake of extraordinary introspection and debugging facilities,
the DDA to C compiler dismantles compound expressions hj:hhh NhNubjs)}(h``f(g(x))``h]h.f(g(x))}(hhhjCubah}(h]h]h]h]h]uhjrhj:ubh. or }(h or hj:hhh NhNubjs)}(h``f(a,b(c),d(e))``h]h.f(a,b(c),d(e))}(hhhjVubah}(h]h]h]h]h]uhjrhj:ubh.3
and entitles all intermediate expressions such as }(h3
and entitles all intermediate expressions such as hj:hhh NhNubjs)}(h``gx=g(x)``h]h.gx=g(x)}(hhhjiubah}(h]h]h]h]h]uhjrhj:ubh. in }(h in hj:hhh NhNubjs)}(h ``f(gx)``h]h.f(gx)}(hhhj|ubah}(h]h]h]h]h]uhjrhj:ubh. or
}(h or
hj:hhh NhNubjs)}(h
``g=b(c)``h]h.g=b(c)}(hhhjubah}(h]h]h]h]h]uhjrhj:ubh. and }(h and hj:hhh NhNubjs)}(h
``h=d(e)``h]h.h=d(e)}(hhhjubah}(h]h]h]h]h]uhjrhj:ubh. in }(hj{hj:ubjs)}(h``f(a,g,h)``h]h.f(a,g,h)}(hhhjubah}(h]h]h]h]h]uhjrhj:ubh.. This is especially handy when the DDA is seen
as an approximation of the analog computer, as it allows for checking the boundness
(correct scaling) of all variables during the cycles (time evolution).}(h. This is especially handy when the DDA is seen
as an approximation of the analog computer, as it allows for checking the boundness
(correct scaling) of all variables during the cycles (time evolution).hj:hhh NhNubeh}(h]h]h]h]h]uhh9h h!hKihjhhubh:)}(hXuHaving said that, the DDA simulator allows for simulating a DDA circuit iteration by
iteration and dumping (outputting) values every ``n`` iterations. Therefore, while
the input of a circuit is always fixed by the constants (``const`` statements, no
focus has given to the point of interfacing other codes, which is left as an exercise
for the reader), the output is always a time series for a given set of quantities. We
refer to theses quantities as *observables*, which are *queried* for at code generation
time. One can thus understand the output as a fully discrete table of numbers, where
the columns hold the time series for a given variable and the each row stands for one
time iteration (or some average or surrogate for a larger number of iterations, if
requested). These numbers are represented as ASCII column seperated values (CSV) in the
output of the compiled C program.h](h.Having said that, the DDA simulator allows for simulating a DDA circuit iteration by
iteration and dumping (outputting) values every }(hHaving said that, the DDA simulator allows for simulating a DDA circuit iteration by
iteration and dumping (outputting) values every hjhhh NhNubjs)}(h``n``h]h.n}(hhhjubah}(h]h]h]h]h]uhjrhjubh.W iterations. Therefore, while
the input of a circuit is always fixed by the constants (}(hW iterations. Therefore, while
the input of a circuit is always fixed by the constants (hjhhh NhNubjs)}(h ``const``h]h.const}(hhhjubah}(h]h]h]h]h]uhjrhjubh. statements, no
focus has given to the point of interfacing other codes, which is left as an exercise
for the reader), the output is always a time series for a given set of quantities. We
refer to theses quantities as }(h statements, no
focus has given to the point of interfacing other codes, which is left as an exercise
for the reader), the output is always a time series for a given set of quantities. We
refer to theses quantities as hjhhh NhNubhE)}(h
*observables*h]h.observables}(hhhjubah}(h]h]h]h]h]uhhDhjubh., which are }(h, which are hjhhh NhNubhE)}(h *queried*h]h.queried}(hhhjubah}(h]h]h]h]h]uhhDhjubh.X for at code generation
time. One can thus understand the output as a fully discrete table of numbers, where
the columns hold the time series for a given variable and the each row stands for one
time iteration (or some average or surrogate for a larger number of iterations, if
requested). These numbers are represented as ASCII column seperated values (CSV) in the
output of the compiled C program.}(hX for at code generation
time. One can thus understand the output as a fully discrete table of numbers, where
the columns hold the time series for a given variable and the each row stands for one
time iteration (or some average or surrogate for a larger number of iterations, if
requested). These numbers are represented as ASCII column seperated values (CSV) in the
output of the compiled C program.hjhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKrhjhhubeh}(h]linearization-of-a-circuitah]h]linearization of a circuitah]h]uhh"hh$hhh h!hKWubh#)}(hhh](h()}(h0Applicability for solving differential equationsh]h.0Applicability for solving differential equations}(hj5hj3hhh NhNubah}(h]h]h]h]h]uhh'hj0hhh h!hKubh:)}(hX_The usability for this software-based DDA implemenetation for solving ordinary differential
equations highly depends on the internals of the integrator component. From all computing
elements described above, the integrator is the only one with an *internal state*. That
is, it has to remember from iteration to iteration the current integration value.h](h.The usability for this software-based DDA implemenetation for solving ordinary differential
equations highly depends on the internals of the integrator component. From all computing
elements described above, the integrator is the only one with an }(hThe usability for this software-based DDA implemenetation for solving ordinary differential
equations highly depends on the internals of the integrator component. From all computing
elements described above, the integrator is the only one with an hjAhhh NhNubhE)}(h*internal state*h]h.internal state}(hhhjJubah}(h]h]h]h]h]uhhDhjAubh.X. That
is, it has to remember from iteration to iteration the current integration value.}(hX. That
is, it has to remember from iteration to iteration the current integration value.hjAhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhj0hhubh:)}(haThe most easy integrator component will internally look like the following imperative
dummy code:h]h.aThe most easy integrator component will internally look like the following imperative
dummy code:}(hjehjchhh NhNubah}(h]h]h]h]h]uhh9h h!hKhj0hhubjS)}(hdouble integrate(double integrand, double dx, double initial_value) {
static double internal_state = initial_value;
internal_state += integrand * dx;
return internal_state;
}h]h.double integrate(double integrand, double dx, double initial_value) {
static double internal_state = initial_value;
internal_state += integrand * dx;
return internal_state;
}}(hhhjqubah}(h]h]h]h]h]jbjcjdjecjg}uhjRh h!hKhj0hhubh:)}(hXHere, the ``internal_state`` is declared as a *static* variable, which you can think of a
global variable (with a lifetime longer then the function evaluation) if you don't know C.
In fact, this dummy code comes quite close to the actual implementation of the integrator
in the DDA C code. We refer to the above numerical scheme as the *Euler time integration*,
since it approximates the time-continous integral by it's Riemann sum.h](h.
Here, the }(h
Here, the hjhhh NhNubjs)}(h``internal_state``h]h.internal_state}(hhhjubah}(h]h]h]h]h]uhjrhjubh. is declared as a }(h is declared as a hjhhh NhNubhE)}(h*static*h]h.static}(hhhjubah}(h]h]h]h]h]uhhDhjubh.X variable, which you can think of a
global variable (with a lifetime longer then the function evaluation) if you don’t know C.
In fact, this dummy code comes quite close to the actual implementation of the integrator
in the DDA C code. We refer to the above numerical scheme as the }(hX variable, which you can think of a
global variable (with a lifetime longer then the function evaluation) if you don't know C.
In fact, this dummy code comes quite close to the actual implementation of the integrator
in the DDA C code. We refer to the above numerical scheme as the hjhhh NhNubhE)}(h*Euler time integration*h]h.Euler time integration}(hhhjubah}(h]h]h]h]h]uhhDhjubh.J,
since it approximates the time-continous integral by it’s Riemann sum.}(hH,
since it approximates the time-continous integral by it's Riemann sum.hjhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhj0hhubh:)}(hX}Within the DDA code, higher order explicit integration schemes can be chosen, such as
Runge-Kutta. However, given the nature of the problem description in a circuit, implicit
methods can not be applied by the compiler without an actual analysis of the differential
equation. Howver, on can imagine a DDA circuit which itself describes a numerical scheme
on a digital-circuit level.h]h.X}Within the DDA code, higher order explicit integration schemes can be chosen, such as
Runge-Kutta. However, given the nature of the problem description in a circuit, implicit
methods can not be applied by the compiler without an actual analysis of the differential
equation. Howver, on can imagine a DDA circuit which itself describes a numerical scheme
on a digital-circuit level.}(hjhjhhh NhNubah}(h]h]h]h]h]uhh9h h!hKhj0hhubeh}(h]0applicability-for-solving-differential-equationsah]h]0applicability for solving differential equationsah]h]uhh"hh$hhh h!hKubh#)}(hhh](h()}(h,On PyDDA, the successor of the DDA Perl codeh]h.,On PyDDA, the successor of the DDA Perl code}(hjhjhhh NhNubah}(h]h]h]h]h]uhh'hjhhh h!hKubh:)}(hThe first DDA code was written by Bernd. It's job was to simulate circuits, and this was
performed by a small Perl script which threw a few regexes onto the DDA file to convert it
to an executable C numeric simulation.h]h.The first DDA code was written by Bernd. It’s job was to simulate circuits, and this was
performed by a small Perl script which threw a few regexes onto the DDA file to convert it
to an executable C numeric simulation.}(hjhjhhh NhNubah}(h]h]h]h]h]uhh9h h!hKhjhhubh:)}(hAs described above, we found out that even with slightly more challenging circuits (kind of *border
cases*, such as the depicted one above) the simple ideology of looping over numeric
equations breaks down.h](h.\As described above, we found out that even with slightly more challenging circuits (kind of }(h\As described above, we found out that even with slightly more challenging circuits (kind of hjhhh NhNubhE)}(h*border
cases*h]h.border
cases}(hhhjubah}(h]h]h]h]h]uhhDhjubh.d, such as the depicted one above) the simple ideology of looping over numeric
equations breaks down.}(hd, such as the depicted one above) the simple ideology of looping over numeric
equations breaks down.hjhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhjhhubeh}(h]+on-pydda-the-successor-of-the-dda-perl-codeah]h],on pydda, the successor of the dda perl codeah]h]uhh"hh$hhh h!hKubh#)}(hhh](h()}(h(Lexical sorting of variable dependenciesh]h.(Lexical sorting of variable dependencies}(hj-hj+hhh NhNubah}(h]h]h]h]h]uhh'hj(hhh h!hKubh:)}(hXInstead, was has to be applied for a stable integration of an electric circuit, i.e. an
ordinary differential equaiton, is the correct sorting of equation ordering. To do so,
we must study the dependencies of equations. This requires a memory representation of
equations, and there we enter the domain of *computer algebra systems* (CAS). Their central
piece of information are algebraic equations, which are typically represented as
(abstract) *syntax trees*.h](h.X1Instead, was has to be applied for a stable integration of an electric circuit, i.e. an
ordinary differential equaiton, is the correct sorting of equation ordering. To do so,
we must study the dependencies of equations. This requires a memory representation of
equations, and there we enter the domain of }(hX1Instead, was has to be applied for a stable integration of an electric circuit, i.e. an
ordinary differential equaiton, is the correct sorting of equation ordering. To do so,
we must study the dependencies of equations. This requires a memory representation of
equations, and there we enter the domain of hj9hhh NhNubhE)}(h*computer algebra systems*h]h.computer algebra systems}(hhhjBubah}(h]h]h]h]h]uhhDhj9ubh.r (CAS). Their central
piece of information are algebraic equations, which are typically represented as
(abstract) }(hr (CAS). Their central
piece of information are algebraic equations, which are typically represented as
(abstract) hj9hhh NhNubhE)}(h*syntax trees*h]h.syntax trees}(hhhjUubah}(h]h]h]h]h]uhhDhj9ubh..}(hjhj9hhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhj(hhubh:)}(hPyDDA was an effort to rewrite the Perl-based DDA with a minimal amount of work.
Exploiting that DDA looks almost like Python, the idea was to bring a number of
archivements with a single code:h]h.PyDDA was an effort to rewrite the Perl-based DDA with a minimal amount of work.
Exploiting that DDA looks almost like Python, the idea was to bring a number of
archivements with a single code:}(hjohjmhhh NhNubah}(h]h]h]h]h]uhh9h h!hKhj(hhubh)}(hhh](h)}(h`Allow to write high-level DDA codes, which probably involve indexing, n-dimensional
arrays, etc.h]h:)}(h`Allow to write high-level DDA codes, which probably involve indexing, n-dimensional
arrays, etc.h]h.`Allow to write high-level DDA codes, which probably involve indexing, n-dimensional
arrays, etc.}(hjhjubah}(h]h]h]h]h]uhh9h h!hKhj~ubah}(h]h]h]h]h]uhhhj{hhh h!hNubh)}(hAllow for easy interoperation with various codes and tools, such as other CAS,
(evventually generated) numerical simulation codes or reprogrammable analog computers.h]h:)}(hAllow for easy interoperation with various codes and tools, such as other CAS,
(evventually generated) numerical simulation codes or reprogrammable analog computers.h]h.Allow for easy interoperation with various codes and tools, such as other CAS,
(evventually generated) numerical simulation codes or reprogrammable analog computers.}(hjhjubah}(h]h]h]h]h]uhh9h h!hKhjubah}(h]h]h]h]h]uhhhj{hhh h!hNubh)}(hjEnable the user for a Read-eval-print loop interface (REPL) in order to encourage
explorative programming.h]h:)}(hjEnable the user for a Read-eval-print loop interface (REPL) in order to encourage
explorative programming.h]h.jEnable the user for a Read-eval-print loop interface (REPL) in order to encourage
explorative programming.}(hjhjubah}(h]h]h]h]h]uhh9h h!hKhjubah}(h]h]h]h]h]uhhhj{hhh h!hNubh)}(hlMeshing literate programming, generation of documentation and reports out of the
equations without much workh]h:)}(hlMeshing literate programming, generation of documentation and reports out of the
equations without much workh]h.lMeshing literate programming, generation of documentation and reports out of the
equations without much work}(hjhjubah}(h]h]h]h]h]uhh9h h!hKhjubah}(h]h]h]h]h]uhhhj{hhh h!hNubh)}(hPicking the community where it is: Scientific Python is a thing, and so we choose
python. Thus we also can stick to python when it comes to simulation analysis and
postprocessing.h]h:)}(hPicking the community where it is: Scientific Python is a thing, and so we choose
python. Thus we also can stick to python when it comes to simulation analysis and
postprocessing.h]h.Picking the community where it is: Scientific Python is a thing, and so we choose
python. Thus we also can stick to python when it comes to simulation analysis and
postprocessing.}(hjhjubah}(h]h]h]h]h]uhh9h h!hKhjubah}(h]h]h]h]h]uhhhj{hhh h!hNubh)}(hAvoid dependencies if not neccessary. Don't reinvent the wheel, but try out how
far we can get without employing a large computer algebra system.
h]h:)}(hAvoid dependencies if not neccessary. Don't reinvent the wheel, but try out how
far we can get without employing a large computer algebra system.h]h.Avoid dependencies if not neccessary. Don’t reinvent the wheel, but try out how
far we can get without employing a large computer algebra system.}(hjhjubah}(h]h]h]h]h]uhh9h h!hKhjubah}(h]h]h]h]h]uhhhj{hhh h!hNubeh}(h]h]h]h]h]jB-uhhh h!hKhj(hhubeh}(h](lexical-sorting-of-variable-dependenciesah]h](lexical sorting of variable dependenciesah]h]uhh"hh$hhh h!hKubh#)}(hhh](h()}(hEI want to simulate electronics or solve an ODE. Do I really need DDA?h]h.EI want to simulate electronics or solve an ODE. Do I really need DDA?}(hj"hj hhh NhNubah}(h]h]h]h]h]uhh'hjhhh h!hKubh:)}(hXDDA is great if you want to learn about and work with analog computers.
Expressing your equations in terms of this domain specific hardware
description language (which includes all the "quirks" such as *negating*
operational amplifiers used for summation/integration) can be helpful
when it comes to implementing it on real analog computers. PyDDA is
also a helpful tool if you want to learn about numerical vs. analog
computing, or experiment with more challenging systems such as
partial differential equations.h](h.DDA is great if you want to learn about and work with analog computers.
Expressing your equations in terms of this domain specific hardware
description language (which includes all the “quirks” such as }(hDDA is great if you want to learn about and work with analog computers.
Expressing your equations in terms of this domain specific hardware
description language (which includes all the "quirks" such as hj.hhh NhNubhE)}(h
*negating*h]h.negating}(hhhj7ubah}(h]h]h]h]h]uhhDhj.ubh.X-
operational amplifiers used for summation/integration) can be helpful
when it comes to implementing it on real analog computers. PyDDA is
also a helpful tool if you want to learn about numerical vs. analog
computing, or experiment with more challenging systems such as
partial differential equations.}(hX-
operational amplifiers used for summation/integration) can be helpful
when it comes to implementing it on real analog computers. PyDDA is
also a helpful tool if you want to learn about numerical vs. analog
computing, or experiment with more challenging systems such as
partial differential equations.hj.hhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhjhhubh:)}(hIf your goal is to simulate electronics on an advanced level, you might
want to look into the `SPICE class `_
of tools, such as `ngspice `_.h](h.^If your goal is to simulate electronics on an advanced level, you might
want to look into the }(h^If your goal is to simulate electronics on an advanced level, you might
want to look into the hjPhhh NhNubh reference)}(h4`SPICE class `_h]h.SPICE class}(hSPICE classhj[ubah}(h]h]h]h]h]nameSPICE classrefuri#https://en.wikipedia.org/wiki/SPICEuhjYhjPubh
)}(h& h]h}(h]spice-classah]h]spice classah]h]refurijmuhh
referencedKhjPubh.
of tools, such as }(h
of tools, such as hjPhhh NhNubjZ)}(h,`ngspice `_h]h.ngspice}(hngspicehjubah}(h]h]h]h]h]namejjlhttp://ngspice.sourceforge.net/uhjYhjPubh
)}(h" h]h}(h]ngspiceah]h]ngspiceah]h]refurijuhh j{KhjPubh..}(hjhjPhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhjhhubh:)}(hX}If your goal is to solve a differential equation or
to study a small system of interest, you better do so by using
tools particularly made for doing this job very well, such as
Matlab, GNU Octave or some computer algebra system. These are typically
mature systems with decades of development, while PyAnalog is a small
research code developed by a single person over a single year.h]h.X}If your goal is to solve a differential equation or
to study a small system of interest, you better do so by using
tools particularly made for doing this job very well, such as
Matlab, GNU Octave or some computer algebra system. These are typically
mature systems with decades of development, while PyAnalog is a small
research code developed by a single person over a single year.}(hjhjhhh NhNubah}(h]h]h]h]h]uhh9h h!hKhjhhubh:)}(hXlEspecially small systems with only a few
unknowns, it is rather straightforward to transform them into analog
circuits once required, and you can safely postpone this task up to
when it gets relevant. The only thing to keep in mind is that when
developing your applications within another (assumably numerical)
toolkit, be careful about implementing your own algorithmic features.
Ideally, you straightforwardly implement a closed set of mathematical
equations in order to maintain the option to implement this system
on an analog computer, without touching the solution vector with
algorithms during the time evolution.h]h.XlEspecially small systems with only a few
unknowns, it is rather straightforward to transform them into analog
circuits once required, and you can safely postpone this task up to
when it gets relevant. The only thing to keep in mind is that when
developing your applications within another (assumably numerical)
toolkit, be careful about implementing your own algorithmic features.
Ideally, you straightforwardly implement a closed set of mathematical
equations in order to maintain the option to implement this system
on an analog computer, without touching the solution vector with
algorithms during the time evolution.}(hjhjhhh NhNubah}(h]h]h]h]h]uhh9h h!hKhjhhubh:)}(hX1In fact, you even can do a scaling study without PyAnalog. Most
time evolution codes solve some ODE equation :math:`\dot y = f(y)`
by allowing the user to implement the function ``f(y)`` freely.
You could easily implement any checks on scaling within ``f(y)``
in your favourite programming language/tool
.h](h.mIn fact, you even can do a scaling study without PyAnalog. Most
time evolution codes solve some ODE equation }(hmIn fact, you even can do a scaling study without PyAnalog. Most
time evolution codes solve some ODE equation hjhhh NhNubj)}(h:math:`\dot y = f(y)`h]h.
\dot y = f(y)}(hhhjubah}(h]h]h]h]h]uhjhjubh.0
by allowing the user to implement the function }(h0
by allowing the user to implement the function hjhhh NhNubjs)}(h``f(y)``h]h.f(y)}(hhhjubah}(h]h]h]h]h]uhjrhjubh.A freely.
You could easily implement any checks on scaling within }(hA freely.
You could easily implement any checks on scaling within hjhhh NhNubjs)}(h``f(y)``h]h.f(y)}(hhhjubah}(h]h]h]h]h]uhjrhjubh..
in your favourite programming language/tool
.}(h.
in your favourite programming language/tool
.hjhhh NhNubeh}(h]h]h]h]h]uhh9h h!hKhjhhubeh}(h]Ci-want-to-simulate-electronics-or-solve-an-ode-do-i-really-need-ddaah]h]Ei want to simulate electronics or solve an ode. do i really need dda?ah]h]uhh"hh$hhh h!hKubeh}(h](a-rationale-about-ddaheh]h](a rationale about dda
dda-rationaleeh]h]uhh"hhhhh h!hKexpect_referenced_by_name}j hsexpect_referenced_by_id}hhsubeh}(h]h]h]h]h]sourceh!uhhcurrent_sourceNcurrent_lineNsettingsdocutils.frontendValues)}(h'N generatorN datestampNsource_linkN
source_urlN
toc_backlinksentryfootnote_backlinksK
sectnum_xformKstrip_commentsNstrip_elements_with_classesN
strip_classesNreport_levelK
halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjE error_encodingutf-8error_encoding_error_handlerbackslashreplace
language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid
dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh!_destinationN
_config_files]pep_referencesNpep_base_url https://www.python.org/dev/peps/pep_file_url_templatepep-%04drfc_referencesNrfc_base_urlhttps://tools.ietf.org/html/ tab_widthKtrim_footnote_reference_spacefile_insertion_enabledraw_enabledKsyntax_highlightlongsmart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform
docinfo_xformKsectsubtitle_xformembed_stylesheetcloak_email_addressesenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}h]hasnameids}(j hj j hhjjj-j*jjj%j"jjj j jwjtjju nametypes}(j j NhNjNj-NjNj%NjNj Njwjuh}(hh$j h$hhtjhj*jjj0j"jjj(j jjtjnjju
footnote_refs}
citation_refs}
autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK
id_countercollectionsCounter}Rparse_messages]transform_messages]hsystem_message)}(hhh]h:)}(hhh]h.3Hyperlink target "dda-rationale" is not referenced.}(hhhj ubah}(h]h]h]h]h]uhh9hj ubah}(h]h]h]h]h]levelKtypeINFOsourceh!lineKuhj ubatransformerN
decorationNhhub.**