1. Introduction
Simulations are an essential part of modern science, as they provide a multitude of benefits. Starting with the possibility of analysing very complicated processes, impossible or barely impossible to be conducted in real-life conditions, to ‘what if’ scenarios, hypotheses evaluation, understanding of processes, and optimisations, ending with designing and testing new technologies and solutions. The goal of this article is to present the abilities of the independent,
Python-programming-language-based
DynPy (‘DynamicPython’) [
1] library and compare the results obtained from simulations of a dynamic system conducted with well-known, field-tested commercial software. A growing demand for clean energy and transportation introduces new challenges to multiple engineering branches [
2,
3,
4,
5]. As a result, a continuous seeking for more reliable, durable, safe, and effective hardware design is seen. This usually means a necessity for analysing yet more complicated phenomena [
6], for which nontrivial approaches are needed, most likely to be investigated with the use of some software.
DynPy is an open-source project aimed at providing an engineering tool that allows, among other functionalities: performing symbolic computations, conducting numerical simulations, and creating comprehensive reports of conducted calculations. It supports a few useful and suitable typesetting systems for reporting engineering and scientific activities, e.g.,
Markdown and LaTeX. Another advantage of the developed library is the significant number of dynamic components it provides. This allows for quickly simulating the behaviour of systems described by mathematical dependencies characterizing their dynamic states.
DynPy is conceptualised, developed, and maintained by the authors and other developers. Throughout the years it has been utilized by various researchers in the field of mechanical engineering. Due to the constantly growing capabilities of the developed tool, its use in research could be categorized regarding the formerly available set of functionalities. In [
7], the proprietary methodology for creating dynamic systems, as well as numerical and analytical solving algorithms, were utilised. Further, in [
8,
9], chosen elements of a text editing submodule were additionally used for adding formulas and other minor typesetting activities. Finally, the article in [
10] was the first one to be created as a whole strictly with
DynPy’s functionalities—from model creation, through simulations, to manuscript generation. The authors are not aware of any other examples but do not exclude such a possibility, as the library is available in a public
GitHub (version 2.34.1) repository. Such circumstances are the effect of the current article being the first one explicitly about
DynPy, as the state of development allows for presentation to the broader public.
In the case of electrical systems, the description of their dynamics most often takes the form of ordinary differential equations (further referred to as ODE). Due to the complexity of the formulas, solutions can be found in analytical forms or with the use of numerical algorithms. The biggest advantage of the analytical approach lies in the provision of exact solutions for the whole domain, which ensures high repeatability and, thus, reliability of achieved results. Even though it is not always possible to directly obtain closed-form formulas, the stated aspects push scientists to find different mathematical tools, which lead to overwork of hitherto numerically analysed phenomena with analytical methods also in the case of electrical circuits [
11,
12,
13,
14]. Although, in the current state, the
DynPy library does not provide as specialised functionalities as presented in the cited literature, it is crucial to note its ability in this aspect. Firstly, a broad spectrum of typical electrical elements is predefined with the possibility of further enlargement. Secondly, basic analytical and numerical solvers are implemented. Thanks to the utilisation of an object-oriented paradigm and open-source code, more sophisticated approaches can be introduced on the user’s demand.
As noted earlier, the ability to achieve analytical solutions is case-specific and highly depends on the type of equations describing the system. Numerical simulations became such a powerful tool due to the provision of approximated results to problems, which could not be worked out by traditional means [
15,
16,
17]. Multiple types of numerical solving methods have been introduced throughout the years [
18]. In the case of ODE, three main families of algorithms can be recognised: explicit single-step, explicit multistep, and their implicit analogues dedicated to stiff systems of differential equations [
19]. Typical single-step methods for ODE may be divided into the Runge–Kutta (RK, fixed step size) and Runge–Kutta–Fehlberg (RKF, variable step size) approaches. Examples of their utilisation in analyses of electrical circuits in both nonstiff and stiff ODEs can be found in [
20,
21,
22,
23,
24,
25,
26,
27,
28]. Moving on to multistep algorithms, again two main groups could be highlighted, known as Adams and predictor–corrector methods. The Adams family methods in analyses of electrical circuits were presented in [
29,
30,
31,
32,
33,
34,
35]. Predictor–corrector (PC) algorithms include both explicit and implicit algorithms at once, which results in obtaining a set of properties connecting their benefits. The sequence of operations is as follows: prediction (explicit, P), evaluation (E), correction (implicit, C), evaluation (E) [
36,
37]. The described rule is outright applicable to predictor–corrector algorithms based on Adams–Bashforth and Adams–Moulton methods, but constant research on the effects of numerical approximations in the development of different approaches including explicit–explicit or implicit–implicit PC algorithms [
38,
39,
40,
41,
42,
43,
44,
45]. The
DynPy environment in its current state provides six types of numerical solving techniques, inherited from the
SciPy (version 1.15.0) [
46] module:
RK45—explicit Runge–Kutta method of order
;
RK23—explicit Runge–Kutta method of order
;
DOP853—explicit Runge–Kutta method of order 8;
Radau—implicit Runge-Kutta method of the Radau IIA family of order 5;
BDF—implicit multistep variable-order (1 to 5) method based on a backward differentiation formula for the derivative approximation; and the
LSODA —Adams/BDF method with automatic stiffness detection and switching. Simultaneously with other development and maintenance works, actions are taken to create
DynPy-embedded, standalone versions of these and other useful algorithms, so a package can become more versatile and less susceptible to third-party changes in the code, possibly due to the previously stated inheritance.
Solving and simulating electrical circuit behaviour can be performed with the use of multiple software tools available on the market. While some of them strictly require the user to formulate code instructions, others have more advanced
Graphical User Interfaces which provide the possibility to create a representation of analysed problems by block diagrams or 3D models. Vendors such as
MathWorks (Natick, MA, USA) or
Wolfram (Champaign, IL, USA) offer platforms of both types [
47,
48,
49,
50]. Each of them uses individual language, mutual between different developed environments. The mentioned programs serve a multipurpose function, being used by engineers of imaginably all branches. Throughout the years, many additional packages and add-ins were introduced, so the functionalities of interest for specific sectors of the industry could be grouped and state better fitment to the consumers [
51,
52]. When such universal tools are not found as a suitable solution for any reason, more task-oriented software is accessible, such as
TINA, whose scope is restricted to electrical/electronic circuit modelling and simulations [
53]. All of the highlighted examples, despite their undeniable advantages, share one undisputable drawback—to obtain a full experience of their abilities, whether in general or in exact context, a license has to be acquired, which often does not include additional toolboxes or add-ins offered independently at different prices. Although it is possible to find free and open-source alternatives, such as
Scilab [
54] or
CircuitLab [
55], they are not flawless—less developed or completely lack predefined electrical elements, one-off types of interfaces, and a smaller group of users effects in worse community support (what becomes a serious problem when diving into analyses of more complex phenomena, which, may even outcome as too complicated for the utilised software), and so on.
5. Conclusions
This paper presents a general investigation of the DynPy library and its application for scientific and engineering activities. An overview of the developed tool was presented, with deeper insight into its modules and functionalities responsible for the provision of analytical and numerical solutions to systems described with linear and nonlinear ordinary differential equations. Nonlinear (more realistic representation of physical systems) and linear (idealised for theoretical or simplified analysis) models can be adopted and solved in an efficient way.
The solution for a model under consideration obtained with the DynPy library was presented in hybrid analytical–numerical (HAN) and fully analytical forms, where in the case of the latter, Heaviside forcing inputs were included. The HAN methodology, which enables the possibility of setting the integration step size, was chosen for comparison with MATLAB/Simulink results. The results obtained from the HAN method were compared with numerical simulations conducted in MATLAB/Simulink environment.
The analysis of results for the DC motor case leads to the conclusion that for cases with a variable integration step and a constant step of in MATLAB/Simulink, the obtained results are consistent with the results obtained using the DynPy library with the specified constant step of . This confirms the correctness of the implementation in the developed library. However, in the case of a constant step of in MATLAB/Simulink, significant quantitative and qualitative discrepancies were observed between the results—both in terms of values and waveform shapes. Deviating values indicate that under specific conditions, the DynPy library may respond better to changes in system dynamics than the MATLAB/Simulink tool. Specifically, the hybrid analytical–numerical method not only proved to return proper results in opposition to simulation with the same step size in MATLAB/Simulink but also presented high accuracy with step simulations in the stated reference environment.
Summarizing the simulations of the RLC circuit, the main conclusion is that regardless of the selected step size, thanks to the solution being based on an analytical approach, the results are quantitatively better than the strictly numerical ones obtained from each analysed MATLAB/Simulink case. Qualitative discrepancies are different between approaches subjected to comparison. It is clearly visible that the DynPy HAN solution with a properly set step size provides smoother curves than MATLAB/Simulink with variable steps. Hence, the analytical solution updated numerically with appropriate frequency provides the most reliable results.
The comparisons of simulation results indicate that the numerical algorithms in the DynPy library have been implemented correctly, and the results obtained are accurate. The paper itself was generated strictly with the use of DynPy’s functionalities—all steps from building the model, through finding an analytical solution, conducting the simulations and their visualisation, to generating editable .tex files were carried out in the same environment. Thus, not only the accuracy and reliability of the tool were proven but its versatility and usefulness as well. Conclusions drawn from this study will enable further optimisation and development of the library for various engineering applications. Some of the future research directions include the development of a more user-friendly interface for hybrid analytical–numerical methods, the expansion of built-in analytical solvers with more types of step functions, and general refining and maintenance. It is worth mentioning that the library undergoes constant development, and numerous new features and fixes were added during and after the writing of this article.
By no means do the authors of this article imply the overall superiority of the DynPy library over well-known and field-tested software, but the main advantages have to be pointed out for comparison. Firstly, it is written in the Python programming language. Although it requires the user to obtain at least a basic knowledge of its structure and syntax, it also assures the fact that insight into developed algorithms and their working principles is possible, as well as local editing, in contrast to previously described software. Moreover, a large user community of the language, in general, ensures additional support on top of the one possible to obtain from DynPy’s built-in guides and functioning help methods. Thanks to the utilisation of the object-oriented paradigm, a unique way to build dynamic systems was implemented. Said paradigm also enables the user to create self-defined basic elements, without the need of downloading additional toolboxes or add-ins. Such an approach results in a low level of initial theoretical, mathematical, and modelling knowledge needed to use the tool. At no point when building the system, manual definition of equations of motion or governing equations is necessary (but still possible if needed), since they are derived directly from the user-provided composition of the model. Of course, verification of the obtained results is necessary, as with any other tool. Another advantage lies in the scope of solving possibilities. The same model can be solved both analytically (if possible from the mathematical point of view) and numerically in the same environment. Lastly, DynPy also works as a text editing tool. Thanks to the implementation of self-written and PyLaTeX inherited functionalities, fully formatted papers like this one are possible to generate without the need for workspace change, so the model preparation, solution finding, simulations, and reporting are all in one place.