Next Article in Journal
Coordinated Volt/VAR Control in Distribution Networks Considering Demand Response via Safe Deep Reinforcement Learning
Previous Article in Journal
StegoEDCA: An Efficient Covert Channel for Smart Grids Based on IEEE 802.11e Standard
Previous Article in Special Issue
Measurement and Modeling of Self-Directed Channel (SDC) Memristors: An Extensive Study
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

DynPy—Python Library for Mechanical and Electrical Engineering: An Assessment with Coupled Electro-Mechanical Direct Current Motor Model

by
Damian Sierociński
1,*,
Bogumił Chiliński
1,
Franciszek Gawiński
2,
Amadeusz Radomski
2 and
Piotr Przybyłowicz
3
1
Department of Computer Techniques, Institute of Machine Design Fundamentals, Faculty of Automotive and Construction Machinery Engineering, Warsaw University of Technology, 02-524 Warsaw, Poland
2
Faculty of Automotive and Construction Machinery Engineering, Warsaw University of Technology, 02-524 Warsaw, Poland
3
Department of Mechanics, Institute of Machine Design Fundamentals, Faculty of Automotive and Construction Machinery Engineering, Warsaw University of Technology, 02-524 Warsaw, Poland
*
Author to whom correspondence should be addressed.
Energies 2025, 18(2), 332; https://doi.org/10.3390/en18020332
Submission received: 15 November 2024 / Revised: 4 January 2025 / Accepted: 7 January 2025 / Published: 13 January 2025

Abstract

:
DynPy is an open-source library implemented in Python (version 3.10.12) programming language which aims to provide a versatile set of functionalities for mechanical and electrical engineers. It enables the user to model, solve, simulate, and report analysis of dynamic systems with the use of a single environment. The DynPy library comes with a predefined collection of ready-to-use mechanical and electrical systems. A proprietary approach to creating new systems by combining independent elements defined as classes, such as masses, springs, dampers, resistors, capacitors, inductors, and more, allows for the quick creation of new, or the modification of existing systems. In the paper examples for obtaining analytical and numerical solutions of the systems described with ordinary differential equations were presented. The assessment of solver accuracy was conducted utilising a coupled electro-mechanical model of a direct current motor, with MATLAB/Simulink (R2022b) used as a reference tool. The model was solved in DynPy with the hybrid analytical–numerical method and fully analytically, while in MATLAB/Simulink strictly numerical simulations were run. The comparison of the results obtained from both tools not only proved the credibility of the developed library but also showed its superiority in specific conditions.

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 5 ( 4 ) ; RK23—explicit Runge–Kutta method of order 3 ( 2 ) ; 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.

2. Materials and Methods

2.1. DynPy Library—General Overview

The decision to use Python programming language for the implementation of the DynPy library was dictated by its numerous advantages. It is used by hundreds of thousands of programmers worldwide in areas such as web scripting, system programming, user interfaces, and product customisation [56,57], and the opinion is becoming widespread that it is an optimal choice for scientists and engineers seeking a high-level language for writing scientific applications [58]. As a high-level language, its syntax is more comprehensible for users, putting more focus on the task that has to be carried out rather than analysing the aspects of computing areas that naturally are not taken into consideration by nonprogrammers, such as memory management. The general purpose character of the language results in a wide variety of up-to-date libraries addressing multiple fields, such as scientific computing, data analysis, data visualisation, and more. Thanks to that, it was possible to use pre-existing modules as a foundation to implement functionalities desired functionalities, instead of writing the code from scratch. NumPy (version 2.2.1), pandas (version 2.2.3), SciPy (version 1.15.0), and SymPy (version 1.13.3) [59] are concurrently used for data processing, computations, simulations, and various mathematical operations. Pandas, in collaboration with Matplotlib (version 3.10.0), is used for presenting data and results in tabular and graphical form, while PyLaTeX (version 1.4.2) provides crucial methods required for text formatting and generating .tex and .pdf files. Therefore, Jupyter Notebook (version 7.3) is perfectly suited as a working environment with the DynPy library [60]. The ability to execute code in separate cells allows for conducting calculations in a specified order. The visualisation of operations facilitates understanding and control over the performed computations. Additionally, the option of combining code, text, and images makes the developed document readable and more accessible to other users.
In the process of selecting a programming paradigm from multiple which Python (version 3.10.12) offers, the decision was made to adopt an object-oriented programming approach, as it enables the creation of structured and modular solutions. Object-oriented code is more transparent and flexible, facilitating project management and development and providing versatility and usefulness. In the context of the project, it enables easier management of multiple modules and provides a structure that facilitates collaboration among multiple software developers.
It is worth mentioning at this point that the work on the DynPy library project follows an Agile approach, which is based on flexibility, adaptability, and continuous adjustment to changing needs. In contrast to the classical technique, which assumes planning and implementation in one cycle, the Agile methodology focuses on short-cycle stages. The goal is divided into smaller parts, and work is carried out step by step with the possibility of adapting to new conditions. This not only provides greater flexibility but also enables faster delivery of useful engineering tools [61]. The project as a whole is not presented further in this work. Instead, individual sections are presented and discussed.
The algorithms implemented in the library allow the solving and simulating of linear and nonlinear systems, both numerically and analytically. The numerical techniques inherited from SciPy provide a possibility for the analysis of linear and weakly and strongly nonlinear problems. The analytical approaches are defined in dynpy.solvers.linear and dynpy.solvers.nonlinear submodules. On top of the typical approaches utilised when working on linear ODEs, a few useful methods are defined which enable dealing with nonlinear problems. Firstly, a functionality of linearisation around an introduced point is provided, where calling the linearized method on the provided equations of motion returns a new set of formulas based on Taylor polynomial expansion of the nonlinear terms. Secondly, perturbational solvers are implemented, such as the Multiple Scales Method. The effectiveness in dealing with such problems in both numerical and analytical ways was tested in the previously referred literature, namely [7,8]. In detail, the library allows for the application of a few approaches for solving ODEs according to the class of the problem under analysis:
  • Linear: DynPy provides analytical and numerical solvers for linear systems. The scope of the application of analytical solvers is limited by the order of the equation and its parameters. The system of two second-order equations can be solved analytically in general cases (all parameters given as arbitrary symbols). For selected cases of parameter arrangement, equations of higher order are also possible to solve. All other linear cases can be efficiently solved with numerical solvers as described previously.
  • Nonlinear: This class of equations can be mostly solved by numerical solvers provided in DynPy. It results in the TimeDataFrame object (DynPy modification of pandas DataFrame object, providing data structure optimised for handling results in time and frequency domain), a uniform interface for further analysis (e.g., calculations, transformations) and manipulation (embedding the tables and graphs in the report) of results. This approach is consistent with an analytical approach, which the user can handle in a standardised way as presented before. Moreover, the selected cases are possible to solve in an analytical way if the equation is solvable from the theoretical point of view. First-order and Bernoulli equations are implemented currently.
  • Perturbational: Selected cases can be solved with the usage of the Multiple Scale Method, which is an analytical method for solving systems with weak nonlinearities or parametrical properties. The equation has to be described by the perturbational parameter (from a practical point of view—a small physical part of the system). DynPy provides several tools that allow to create a perturbational form of the equation and solve it with the same methodology and in the same environment as previously described cases.
The DynPy library is equipped with a series of dynamic models that simulate real systems, the base of which is a ComposedSystem class. An electrical circuit can be constructed by leveraging its functionalities and incorporating components provided by the dynpy.models.electric.elements module (e.g., Resistor) or by utilizing predefined systems, the availability of which continues to expand. An exemplary electrical circuit represents a Thevenin model of the lithium-ion battery, a code snippet of which is provided in Appendix A. Using such a class eliminates the need for independently designing a system while also allowing for easy analysis. Additionally, the models include graphical visualisations, as shown in Figure 1. Expanding the DynPy library with various models is an effective way to enhance its functionality. Thanks to a standardised approach to building models, adding more becomes simpler.

2.2. Solvers

The core of the simulational capabilities of the DynPy library lies in its dynpy.solvers module. Technically, the most important class of all defined in its submodules is ODESystem, which serves as a template for creating objects in the form of differential equations. In the scope of the class body, there is an example demonstrating its use to create a differential equation and subsequently solve it symbolically and numerically using the tools provided by the library, which can be displayed by calling the help(ODESystem) command in the interpreter.
Preparation of the defined model for simulations in the DynPy environment starts with the creation of ODESystem class instance. To satisfy its necessary arguments, equations of motion of the system have to be introduced, as well as dependent variables and the degree of the differential equation. The ODEs can be introduced in two different ways, either by directly defining them as an input argument or by creating a dynamic system class and using its _eoms property defined in the parent class ComposedSystem. The latter method is presented, as it shows DynPy’s functionalities in a wider aspect. A code snippet of such a constructed DCMotor class is presented in Appendix B. Such a class can be defined directly in the interpreter or (preferably) in the proper module. In the case of providing the definition in a module, it is necessary to import it into an interpreter. Next, creating a noncalled instance is suggested, so it gives access to inherited and internally defined objects. A properly constructed class enables the return of equations of motion, which can be directly introduced as an argument to ODESystem. With a similar approach, a matrix of dependent variables can be formulated. The last step is the provision of an ODE order. As a result, a complete representation of the ODESystem type object is obtained. A graphical representation of the described steps and generated output is shown in Figure 2.
The prepared object allows for solving the system of equations analytically using the solution method (Figure 3). By default, a matrix equation is returned, where the left-hand side represents dependent variables and the right-hand side represents a complete solution. An additional as_eq_list method was developed, which converts the original output into a list of equations of motion as Sympy’s Eq class type, so they can be easily reported in the Energies 18 00332 i019 document. For clarity of view, a display command, being a part of the IPython module, was utilised to produce output, including an asterisk to unpack the list elements. The symbolic solution is very extensive, but substituting numerical values provides simplification (Figure 4).
To generate a dataset of numerical values for a chosen time span, three additional methods are called on the solution. Firstly, with_ics, which takes a list of initial conditions (ICs) as an argument. Based on the provided ICs, integration constants are evaluated and substituted. Secondly, by utilizing the subs method, the system’s symbolical parameters are replaced with numbers provided by a user in the form of a dictionary. Lastly, compute_solution is called on the predefined time span. Executed code results in a table of analytical solutions and their derivatives calculated for subsequent time stamps (Figure 5).
An approach to obtain a strictly numerical solution is presented in Figure 6. The substitution of parameter values is provided on equations of motion derived from the DCMotor class instance. Later, the resulting object is treated with a numerised method, which prepares the model for numerical computations. In the same line, with_ics is utilised to input initial conditions, and compute_solution with a defined time span solves the system, returning a dataset of results.
The presented methodology is well suited for analysing a system with a single set of chosen parameter values. The more sophisticated way of conducting simulations, which enables the possibility of analysing the changes in the system’s behaviour for multiple values of a single parameter is provided by NumericalAnalysisDataFrame class. It includes the from_model method, which takes as arguments an object of ODESystem type, analysed parameter (symbol) and a list of its values, reference parameters values (a dictionary, excluding the parameter under investigation), and a list of dependent variables and an index of DataFrame to be generated (where time_span is a set of time stamps, and dcmotor.ivar is a symbolic definition of time as an independent variable derived from DCMotor class, with ivar being independent variable). Due to the necessity of providing multiple sets of initial conditions to properly initiate a DataFrame, the additional method insert_ics was developed so that a simple list of values can be introduced. Such a setup directly outputs a result of numerical simulations (Figure 7) after executing perform_simulations command. To obtain numerical values calculated for the analytical solution, slight modifications have to be performed, as described in Figure 8. For all of the presented approaches, plots are easily generated by adding .plot() after compute_solution or perform_simulations, which can be additionally formatted to show chosen results with pandas library options (as a visible droplevel command, for example).

3. Theory and Calculation

3.1. DC Motor—Tested System

The accuracy and effectiveness of the developed DynPy library in the aspect of solving systems of ODEs and conducting simulations were investigated with a model of a direct current electric motor described by a system of two differential equations.
Based on the equivalent circuit (Figure 9) and Kirchhoff’s second law, the electrical equation of the motor was derived:
U z = E + U L w + U R w
where:
  • U L w —voltage related to the rotor inductance;
  • E—electro-motive force of induction;
  • U z —voltage supplying the rotor;
  • U R w —voltage across the rotor winding resistance.
The voltage across the resistance of the rotor windings is proportional to the current flowing through them:
U R w = R w i w
where the following are used:
  • i w —rotor winding current;
  • R w —equivalent resistance of the rotor windings.
The voltage across the rotor winding inductance is proportional to the rate of change in the current flowing through it (magnetic circuit losses are neglected):
U L w = L w i ˙ w
where the following are used:
  • L w —equivalent inductance of the rotor windings;
  • i ˙ w —rotor winding current rate of change.
When the rotor rotates, a counter-electro-motive force (EMF) is induced in its windings, the value of which is proportional to the angular velocity of the rotor:
E = k e ω s
where the following are used:
  • ω s —angular velocity of the rotor;
  • k e —back electro-motive force constant.
By substituting each component into Equation (1), we obtain
U z = L w i ˙ w + R w i w + k e ω s
The rotor torque has to overcome torques opposing the movement and is proportional to the current flowing through it. Assuming that the magnetic flux of the stator remains constant, two formulas were derived:
M s = M a + M l + M r
M s = k m i w
where the following are used:
  • M s —rotor torque;
  • M l —engine load torque;
  • k m —torque constant;
  • M r —rotor motion resistance torque;
  • M a —rotor angular acceleration torque.
The torque values associated with the angular acceleration and the rotor’s motion can be expressed as
M a = J ω ˙ s
M r = B ω s
where the following are used:
  • B—coefficient of viscous friction reduced to the rotor shaft;
  • J—moment of inertia reduced to the rotor shaft;
  • ω ˙ s —angular acceleration of the rotor.
Substituting the individual components described in Formulas (8) and (9) into Equation (6) we obtain
k m i w = M l + B ω s + J ω ˙ s
As a result of the performed steps, equations of motion of the system were obtained:
U z + L w i ˙ w + R w i w + k e ω s = 0
M l + B ω s + J ω ˙ s k m i w = 0
The proposed model was solved with two techniques—with a hybrid approach, which utilises both analytical and numerical solutions at once (HAN), and strictly analytically, with forcing input as the Heaviside function. The HAN solution was completed in two steps. The system was first solved analytically for constant external forcing with the use of DynPy library (the solution was not calculated manually). Later, the obtained solution was updated numerically by alternately introducing dictionaries with parameter values filled in such a manner, so a step character of forcing could be imitated. As input functions in the model, the rotor supply voltage ( U z ) and the motor load torque ( M l ) were considered:
U z ( t ) = 10 for t = { ( 0 , 2 ) ( 4 , 6 ) ( 8 , 10 ) } 0 for t = { ( 2 , 4 ) ( 6 , 8 ) }
M l ( t ) = 0.2 for t = { ( 1 , 3 ) ( 5 , 7 ) ( 9 , 10 ) } 0 for t = { ( 0 , 1 ) ( 3 , 5 ) ( 7 , 9 ) }
Both are represented by step functions described in Equations (13) and (14), with graphical interpretation shown in the plots (Figure 10 and Figure 11). A detailed view of selected mathematical dependencies of the analysed system derived from the DCMotor class, and the full form of the analytical solution are defined in Appendix C.
The equations of motion for a system with Heaviside step function forcing have the following form:
L w i ˙ w + R w i w + k e ω s U z θ sin 2 π t T = 0
B ω s + J ω ˙ s + M l θ cos 2 π t T k m i w = 0
where the following are used:
  • θ —Heaviside function;
  • T—cycle length.
The step function takes a sinewave as an argument, to which additional conditions were provided for proper representation of a demanded character of input voltage and motor load. The analytical solution of Equations (15) and (16) is provided in Appendix C, while the code snippet with the implementation of the HAN method is in Appendix D.

3.2. DC Motor—Conducting Simulations Using the DynPy Library

The parameter values of the model were selected and presented in Table 1. Results of simulations for armature current and rotor angular velocity obtained with the HAN method are provided in Figure 12 and Figure 13, while plots presented in Figure 14 and Figure 15 apply to the fully analytical solution.
In Figure 16 and Figure 17, corresponding plots were juxtaposed. The fully analytical solution is visibly smoother in areas where rapid changes in analysed values occur (selected time stamps of 1 s interval are presented in Table 2). The main reason behind this might be identified as a much bigger number of samples utilised to generate a plot (one thousand time stamps), but the aspect of a fully analytical solution being more accurate than HAN, in general, cannot be omitted and will be analysed in future works. Nonetheless, it is safe to assume that even if the HAN approach with reduced step size would result in results indistinguishable from the analytical solution, it will still require more preparation, resulting in higher overall time cost. Since the HAN solution provides the possibility to compare the behaviour of the numerical solution regarding changes in step size and a comparison with commercial software in this aspect, it was selected for further consideration in the study. The integration step is 0.1   s , and selected time stamps of 1 s interval are presented in Table 3.

3.3. DC Motor—Conducting Simulations Using MATLAB/Simulink

MATLAB/Simulink, as a powerful tool for the simulation and modelling of dynamic systems, has found wide application in various engineering fields. In the context of this paper, it was used as a reference tool for comparison with the results obtained from the DynPy library, since its widespread use in the fields of control systems, drive systems, automation, and many other areas of engineering makes conducted simulations a reliable reference point.
Reference simulations were carried out using both variable and fixed step solvers. This approach enables a detailed analysis of the impact of different integration strategies on simulation results and allows for a direct comparison with the Python implementation, as the DynPy library HAN solution utilises a fixed step approach. The designed model of the DC motor used for conducting simulations in the MATLAB/Simulink environment is depicted in Figure 18.
The results obtained using the variable integration step are presented in Table 4 (Figure 19 and Figure 20), while those with a fixed step set to be the same as in the simulations using the DynPy library ( 0.1   s ) are in in Table 5 (Figure 21 and Figure 22).
After initial analysis of the simulation results obtained with variable and constant integration steps, significant differences were noticeable both in the achieved values and in the shape of the current intensity in the rotor windings and the rotor angular velocity. Therefore, a decision was made to reduce the constant integration step to a value of 0.01   s and conduct further simulations. In Figure 23 and Figure 24 are the results obtained after implementing this modification. Values of selected time stamps are listed in Table 6.

3.4. Application of DynPy for Electrical Circuits

DynPy library enables to modelling of electric circuits in a similar way as it handles electro-mechanical and mechanical systems. Electrical modelling was performed based on a serial DC RLC circuit (Figure 25). A single-degree-of-freedom, second-order system was introduced, in which the Heaviside function provides the variable value of the resistance. Such a definition of equations of motion introduces a more challenging problem, as the nonconstant parameter directly affects the behaviour of the first derivative of the dependent variable, while in the case of the DC motor system, the forcing vector was subjected to periodic changes:
U + L q ¨ + R m i n q ˙ + q C + R θ sin 2 π t T q ˙ = 0
where the following are used:
  • R—amplitude of the variable part of the resistance;
  • R m i n —constant value of the resistance;
  • L—inductance;
  • C—capacitance;
  • U—source voltage;
  • q—electric charge;
  • q ˙ —current;
  • q ¨ —current rate of change.
The simulational model adopts the parameters for modulation control of the current in a power circuit. Values of the system’s parameters are provided in Table 7. Parameters were selected in a way that allows for presenting analysed phenomena in an understandable form. The period was selected arbitrarily, then other parameters were calculated to ensure decay times lower than the period. Under these conditions, the circuit can operate as a current control system that can be utilised to simulate electronic commutation processes or polarisation changes in direct current machines. The resistance signal is shown in Figure 26 and described with the following formula:
R ( t ) = 0.1 for t = ( 0 , 2 ) ( 4 , 6 ) ( 8 , 10 ) 20 for t = ( 2 , 4 ) ( 6 , 8 )
To solve the equation, the HAN method was utilised in a similar way as in the case of the DC motor. First, the solution (19) and its first derivative representing current (20) for a system with stationary resistance was returned from an instance of ODEs system class:
q = C 1 e t R 2 L C R 2 4 L 2 C L + C 2 e t R 2 L + C R 2 4 L 2 C L 2 C L U C R C R 2 4 L + C R 2 4 L + 2 C L U C R C R 2 4 L C R 2 + 4 L
q ˙ = C 1 R 2 L C R 2 4 L 2 C L e t R 2 L C R 2 4 L 2 C L + C 2 R 2 L + C R 2 4 L 2 C L e t R 2 L + C R 2 4 L 2 C L + C R U C R C R 2 4 L + C R 2 4 L + C U C R 2 4 L C R C R 2 4 L + C R 2 4 L + C U C R 2 4 L C R C R 2 4 L C R 2 + 4 L C R U C R C R 2 4 L C R 2 + 4 L
Formulas (19) and (20) were later introduced into a slightly modified (inputted system, data dictionaries, and number of time stamps) han_solution_loop function, presented in Appendix D. The HAN method was used twice to obtain results for 0.1   s and 0.01   s time steps. Simultaneously, the system was created in the MATLAB/Simulink environment (Figure 27) and solved there separately with variable, 0.1   s , and 0.01   s step sizes.
The considered case underwent the entire process of electrical circuit modelling and its further analysis. The MATLAB/Simulink environment was used again as a reference tool for the assessment of the performance of the demonstrated library. A detailed view of the comparison between RLC circuit results generated with DynPy and MATLAB/Simulink is provided in Section 4.2. The results presented there confirm the outcomes obtained previously with the analysis of the DC motor.

4. Results and Discussion

4.1. DC Motor

The results of computer simulations were subjected to comparative analysis to assess the effectiveness of the developed library. The listed plots and tables show a comparison of the armature current and rotor angular velocity of the DC motor obtained using DynPy (with a constant integration step size of 0.1   s ) and the following:
The simulation results obtained using the DynPy library with a constant integration step size of 0.1   s and in MATLAB/Simulink using a variable integration step size confirm the agreement between the results outputted from both tools. To present the compatibility of the results more clearly, the characteristics of both simulations are overlaid in (Figure 28). Only minor differences are noticeable in the rotor current plots in areas of dynamic changes in characteristics. The results of the simulation conducted in MATLAB/Simulink are more precise, and the curve representing them is smoother. These differences result from the use of a variable integration step size in the simulation using MATLAB/Simulink. This approach allows for adjusting the integration step size depending on the rate of change in the function, resulting in better accuracy of results in areas of dynamic changes. In the case of rotor angular velocity characteristics, there are no significant differences—the plots are almost identical.
Next, the simulation results were compared, where in both software, a constant integration step of 0.1   s was specified (Figure 29). Significant differences in the characteristics of rotor current intensity are visible. In MATLAB/Simulink, the waveform of the rotor current intensity undergoes oscillations in regions of rapid changes in its value, while the corresponding plot generated using the DynPy library remains stable. In the same intervals as the rotor current intensity, there are discrepancies in the characteristics of angular velocity. However, they are less noticeable, and their differences are acceptable. The disagreement in the results may stem from various factors such as the numerical implementation of the algorithm in both environments or the handling of numerical errors.
Due to discrepancies in the simulation results with the specified constant integration step of 0.1   s , it was decided to reduce its value to 0.01   s in the case of MATLAB/Simulink software and conduct further simulations. The juxtaposed characteristics confirm the consistency of the simulation results, and for better presentation, the characteristics are overlaid (Figure 30). The graph is very similar to the plot in Figure 28, with only minor, negligible differences in the values of rotor current intensity and rotor angular velocity in the areas of rapid changes.

4.2. RLC Circuit

Similarly, the comparison was prepared for the RLC circuit:
  • With both solvers utilizing constant step of 0.1   s (Figure 31, Table 11);
  • With both solvers utilizing constant step of 0.01   s (Figure 32, Table 12);
  • With a variable integration step size in MATLAB/Simulink, 0.1   s and 0.01   s step size in DynPy (Figure 33, Table 13).
When considering the comparison of simulations for a 0.1   s step size, both qualitative and quantitative discrepancies are clearly visible (Figure 31). Above all, the curve generated in MATLAB/Simulink is smooth, while in the case of HAN, sudden changes in current value appear in the second, third, sixth, and seventh second. These changes have a periodic character and are directly related to the implementation of the method. The switch of datasets is realised every second, so to ensure the continuity of the solution, new initial values are introduced to its consecutive parts. As these initial conditions are obtained directly from the previous part of the solution for the same time stamp at which the next part of the solution starts, vertical shifts appear in the plot. A similar situation is expected to take place at every dataset change, yet might not be visible due to the different slopes of the plot at other time stamps. On the other hand, the maximum amperage in the fourth and eighth seconds is higher in MATLAB/Simulink. The fact that the HAN method predominantly utilises an analytical approach lets us conclude that in this aspect, DynPy is more reliable.
The plot in Figure 32 compares the results from both environments with the step size set to 0.01   s . In this scenario, only qualitative difference is exposed—both graphs are equally smooth and generally take the same shape. As previously, maximum current values at the fourth and eighth second are smaller in comparison with MATLAB/Simulink.
Finally, Figure 33 shows the comparison between both constant step size HAN solutions and variable step size output from MATLAB/Simulink. The graph obtained from MATLAB/Simulink performs marginally better qualitatively than the 0.1   s HAN curve. In both cases, small, general waviness appears, as well as sudden rises in amperage at the third and seventh seconds (which also happen at the second and sixth seconds in the case of the 0.1   s step size HAN solution). The 0.01   s step size HAN method utilised in DynPy performs the best from the compared approaches, ensuring the highest smoothness and reliability of results.
Regardless of the selected step size, from a quantitative point of view, the hybrid analytical–numerical method utilised with the DynPy library showed better performance than the strictly numerical approach. When considering the step size, when selected properly, it also ensures high smoothness, resulting in an overall high quality of the obtained results.

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 0.01   s in MATLAB/Simulink, the obtained results are consistent with the results obtained using the DynPy library with the specified constant step of 0.1   s . This confirms the correctness of the implementation in the developed library. However, in the case of a constant step of 0.1   s 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 0.01   s 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.   

Author Contributions

D.S., data curation, formal analysis, software, supervision, validation, and writing—original draft; B.C., conceptualisation, formal analysis, software, supervision, and writing—review and editing; F.G., data curation, investigation, methodology, software, validation, and writing—original draft; P.P., formal analysis, supervision, and writing—review and editing; A.R., software and writing—original draft. All authors have read and agreed to the published version of the manuscript.

Funding

This research did not receive any specific grant from funding agencies in the public, commercial, or not-for-profit sectors.

Data Availability Statement

The data presented in this study are openly available in GitHub, at https://github.com/bogumilchilinski/dynpy (accessed on 14 November 2024).

Conflicts of Interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Appendix A. BatteryCell Class Code

Energies 18 00332 i001Energies 18 00332 i002Energies 18 00332 i003Energies 18 00332 i004

Appendix B. DCMotor Class Code

Energies 18 00332 i005Energies 18 00332 i006Energies 18 00332 i007

Appendix C. Detailed View of DCMotor Class Dependencies and Equations of Motion Solutions

The structure of the DCMotor class, which is inherited from the parent class ComposedSystem, enables the user to display crucial mathematical information about the analysed system. To obtain the equations of motion, Lagrange’s equations of a second kind are utilised, which are built based on the type and number of components of which the system is made. As such, the kinetic energy, potential energy, and dissipative potential of the DC motor can be displayed by the following commands: Energies 18 00332 i008The resulting output, provided in (A1)–(A3), requires some clarification. Referenced formulas are created by another functionality of the DynPy library intended for generating .tex and .pdf documents and SympyFormula objects by directly introducing properties described previously as arguments: Energies 18 00332 i009
J ω s 2 2 L w i w 2 2
 
B ω s 2 2 R w i w 2 2
In general, these properties do not return equations but simply symbolic descriptions of the quantities of interest. Since the potential energy of the analysed system is equal to zero, nothing appeared in (A2), and on top of that, (A1) and (A3) lack the equality signs; hence, no actual right- and left-hand sides can be determined. This does not affect the usability of the interpreter and can be easily improved for cases of reporting by introducing additional symbols and Eq class, as in the following example: Energies 18 00332 i010This slight modification results in the following formulas:
T = J φ ˙ 2 2 L w q ˙ 2 2
V = 0
D = B φ ˙ 2 2 R w q ˙ 2 2
Further in this appendix, to avoid ambiguities, all of the quantities and relations generated from class built-in methods are presented in proper mathematical representation. Another feature of the system that is possible to obtain is its Lagrangian, called by Energies 18 00332 i011
L = J φ ˙ 2 2 L w q ˙ 2 2
Also, inertia, stiffness, damping, and external forces matrices are available. To show them in the form of equations, MatrixSymbol objects have to be defined, which include the size of the matrices as an argument: Energies 18 00332 i012
M = L w 0 0 J
K = 0 0 0 0
C = R w k e k m B
F = U z M l
The equations of motion are accessible through Energies 18 00332 i013A single matrix of equations is returned; hence, to obtain separate formulas, they need to be extracted and introduced into Eq class with right-hand sides equal to zero (or with the as_eq_list method, as in the main part of this article): Energies 18 00332 i014
U z L w i ˙ w R w i w k e ω s = 0
M l + k m i w B ω s J ω ˙ s = 0
Several more quantities are obtainable, such as natural frequencies or frequency response functions, which are not further described. A full form of the solution for the ODESystem object of DCMotor is presented in Equations (A14) and (A17), as well as their derivatives (A16) and (A17):
ω s = U z k m B R w + k e k m M l R w B R w + k e k m + C 1 e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w + C 2 e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w
i w = B U z B R w + k e k m + M l k e B R w + k e k m + B C 1 e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 k m + B C 2 e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 k m + C 2 B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w k m C 1 B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w k m C 1 J R w e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w k m C 2 J R w e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w k m
ω ˙ s = B C 1 e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 J C 1 R w e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w B C 2 e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 J C 2 R w e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w + C 2 B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 J L w C 1 B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 J L w
i ˙ w = C 1 k e e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w L w C 2 k e e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w L w + C 1 J R w 2 e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w 2 k m + C 1 R w B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w 2 k m + C 2 J R w 2 e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w 2 k m B C 1 R w e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w k m B C 2 R w e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w k m C 2 R w B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m e B t 2 J e R w t 2 L w e t B 2 L w 2 2 B J L w R w + J 2 R w 2 4 J L w k e k m 2 J L w 2 L w 2 k m
Similarly, a solution of equations of motion including Heaviside forcing based on sinewave and their derivatives are presented subsequently in (A18)–(A19) and (A20)–(A21). For clarity of view (very long components of the equations disabled proper line breaking), their dimensionless versions are provided, where τ is dimensionless time, i is the imaginary unit, κ is the dimensionless coupling coefficient, μ is the torque reduced to the shaft rotation angle, υ is the voltage reduced to armature current, and N is the number of Heaviside function cycles.
i w τ = C 1 e τ i κ 1 + C 2 e τ i κ 1 + κ μ κ 2 1 e μ e τ i κ 1 2 κ e i κ + 2 i e i κ e μ e i κ e τ i κ 1 2 κ 2 i θ cos 2 π τ T + n = N N i υ e T 2 e T n e τ i κ 1 2 κ e i T κ 2 e i T κ n + 2 i e i T κ 2 e i T κ n + υ κ 2 1 i υ e T 2 e T n e τ i κ 1 e i T κ 2 e i T κ n 2 κ 2 i θ T n T 2 + τ + n = N N i υ e T n e τ i κ 1 2 κ e i T κ n + 2 i e i T κ n υ κ 2 1 + i υ e T n e τ i κ 1 e i T κ n 2 κ 2 i θ T n + τ
ω s τ = e i μ e τ i κ 1 2 κ e i κ + 2 i e i κ μ κ 2 + 1 e i μ e i κ e τ i κ 1 2 κ 2 i θ cos 2 π τ T + i C 1 e τ i κ 1 i C 2 e τ i κ 1 + n = N N κ υ κ 2 + 1 υ e T n e τ i κ 1 2 κ e i T κ n + 2 i e i T κ n υ e T n e τ i κ 1 e i T κ n 2 κ 2 i θ T n + τ + n = N N κ υ κ 2 + 1 + υ e T 2 e T n e τ i κ 1 2 κ e i T κ 2 e i T κ n + 2 i e i T κ 2 e i T κ n + υ e T 2 e T n e τ i κ 1 e i T κ 2 e i T κ n 2 κ 2 i θ T n T 2 + τ
d d τ i w τ = C 1 e τ e i κ τ C 2 e τ e i κ τ + e μ e i κ θ cos 2 π τ T 2 κ e τ e i κ τ 2 i e τ e i κ τ + e μ e i κ τ θ cos 2 π τ T 2 κ e τ e i κ + 2 i e τ e i κ i C 2 κ e τ e i κ τ i C 1 κ e τ e i κ τ 2 π κ μ sin 2 π τ T δ cos 2 π τ T T κ 2 T e i κ μ e i κ θ cos 2 π τ T 2 κ e τ e i κ τ 2 i e τ e i κ τ e i κ μ e i κ τ θ cos 2 π τ T 2 κ e τ e i κ + 2 i e τ e i κ 2 e π μ e i κ sin 2 π τ T δ cos 2 π τ T 2 T κ e τ e i κ τ 2 i T e τ e i κ τ 2 e π μ e i κ τ sin 2 π τ T δ cos 2 π τ T 2 T κ e τ e i κ + 2 i T e τ e i κ + n = N N υ δ T n T 2 + τ κ 2 1 + n = N N υ δ T n + τ κ 2 1 + n = N N i υ e T n e i T κ n δ T n + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N i υ e T n e i κ τ θ T n + τ 2 κ e τ e i T κ n + 2 i e τ e i T κ n + n = N N κ υ e T n e i T κ n θ T n + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N κ υ e T n e i κ τ θ T n + τ 2 κ e τ e i T κ n + 2 i e τ e i T κ n + n = N N i υ e T n e i T κ n θ T n + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N i υ e T n e i κ τ δ T n + τ 2 κ e τ e i T κ n + 2 i e τ e i T κ n + n = N N i υ e T 2 e T n e i κ τ δ T n T 2 + τ 2 κ e τ e i T κ 2 e i T κ n + 2 i e τ e i T κ 2 e i T κ n + n = N N i υ e T 2 e T n e i κ τ θ T n T 2 + τ 2 κ e τ e i T κ 2 e i T κ n + 2 i e τ e i T κ 2 e i T κ n + n = N N κ υ e T 2 e T n e i κ τ θ T n T 2 + τ 2 κ e τ e i T κ 2 e i T κ n + 2 i e τ e i T κ 2 e i T κ n + n = N N i υ e T 2 e T n e i T κ 2 e i T κ n θ T n T 2 + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N i υ e T 2 e T n e i T κ 2 e i T κ n δ T n T 2 + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N κ υ e T 2 e T n e i T κ 2 e i T κ n θ T n T 2 + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ
d d τ ω s τ = i C 2 e τ e i κ τ C 1 κ e τ e i κ τ C 2 κ e τ e i κ τ i C 1 e τ e i κ τ 2 π μ sin 2 π τ T δ cos 2 π τ T T κ 2 + T + e i μ e i κ θ cos 2 π τ T 2 κ e τ e i κ τ 2 i e τ e i κ τ e i μ e i κ τ θ cos 2 π τ T 2 κ e τ e i κ + 2 i e τ e i κ e κ μ e i κ θ cos 2 π τ T 2 κ e τ e i κ τ 2 i e τ e i κ τ e κ μ e i κ τ θ cos 2 π τ T 2 κ e τ e i κ + 2 i e τ e i κ 2 e i π μ e i κ sin 2 π τ T δ cos 2 π τ T 2 T κ e τ e i κ τ 2 i T e τ e i κ τ + 2 e i π μ e i κ τ sin 2 π τ T δ cos 2 π τ T 2 T κ e τ e i κ + 2 i T e τ e i κ + n = N N κ υ δ T n + τ κ 2 + 1 + n = N N κ υ δ T n T 2 + τ κ 2 + 1 + n = N N υ e T n e i T κ n θ T n + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N υ e T n e i κ τ θ T n + τ 2 κ e τ e i T κ n + 2 i e τ e i T κ n + n = N N υ e T n e i T κ n δ T n + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N υ e T n e i κ τ δ T n + τ 2 κ e τ e i T κ n + 2 i e τ e i T κ n + n = N N υ e T 2 e T n e i κ τ δ T n T 2 + τ 2 κ e τ e i T κ 2 e i T κ n + 2 i e τ e i T κ 2 e i T κ n + n = N N υ e T 2 e T n e i κ τ θ T n T 2 + τ 2 κ e τ e i T κ 2 e i T κ n + 2 i e τ e i T κ 2 e i T κ n + n = N N i κ υ e T n e i T κ n θ T n + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N υ e T 2 e T n e i T κ 2 e i T κ n δ T n T 2 + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N i κ υ e T n e i κ τ θ T n + τ 2 κ e τ e i T κ n + 2 i e τ e i T κ n + n = N N υ e T 2 e T n e i T κ 2 e i T κ n θ T n T 2 + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ + n = N N i κ υ e T 2 e T n e i κ τ θ T n T 2 + τ 2 κ e τ e i T κ 2 e i T κ n + 2 i e τ e i T κ 2 e i T κ n + n = N N i κ υ e T 2 e T n e i T κ 2 e i T κ n θ T n T 2 + τ 2 κ e τ e i κ τ 2 i e τ e i κ τ

Appendix D. Hybrid Analytical–Numerical Solution Code

Code snippet of the hybrid analytical–numerical solution:
Energies 18 00332 i015Energies 18 00332 i016
Main procedure implemented in a loop:
Energies 18 00332 i017Energies 18 00332 i018

References

  1. GitHub. Bogumilchilinski/Dynpy. Available online: https://github.com/bogumilchilinski/dynpy (accessed on 4 May 2024).
  2. Guo, Y.; Liu, L.; Ba, X.; Lu, H.; Lei, G.; Yin, W.; Zhu, J. Designing High-Power-Density Electric Motors for Electric Vehicles with Advanced Magnetic Materials. World Electr. Veh. J. 2023, 14, 114. [Google Scholar] [CrossRef]
  3. Martinez, S.S.; Samaras, C. Electrification of Transit Buses in the United States Reduces Greenhouse Gas Emissions. Environ. Sci. Technol. 2024, 58, 4137–4144. [Google Scholar] [CrossRef] [PubMed]
  4. Siddhartha, P.; Sujeeth, T.; Shiva, B.; Ramprabhakar, J. Integration Of Renewable Energy Sources With Power Management Strategy For Effective Bidirectional Vehicle To Grid Power Transfer. Procedia Comput. Sci. 2023, 218, 9–23. [Google Scholar] [CrossRef]
  5. Kebede, A.A.; Kalogiannis, T.; Mierlo, J.V.; Berecibar, M. A comprehensive review of stationary energy storage devices for large scale renewable energy sources grid integration. Renew. Sustain. Energy Rev. 2022, 159, 112213. [Google Scholar] [CrossRef]
  6. Mathew, M.S.; Kolhe, M.L.; Kandukuri, S.T.; Omlin, C.W. Data driven approach for the management of wind and solar energy integrated electrical distribution network with high penetration of electric vehicles. J. Clean. Prod. 2023, 421, 138467. [Google Scholar] [CrossRef]
  7. Mackojć, A.; Chiliński, B. Preliminary modelling methodology of a coupled payload-vessel system for offshore lifts of light and heavyweight objects. Bull. Pol. Acad. Sci. Tech. Sci. 2021, 70, 139003. [Google Scholar] [CrossRef]
  8. Chilinski, B.; Mackojc, A.; Mackojc, K. Analytical solution of parametrically induced payload nonlinear pendulation in offshore lifting. Ocean. Eng. 2022, 259, 111835. [Google Scholar] [CrossRef]
  9. Mackojc, A.; Chilinski, B.; Zalewski, R. Preliminary research of a symmetrical controllable granular damper prototype. Bull. Pol. Acad. Sci. Tech. Sci. 2022, 70, 141002. [Google Scholar] [CrossRef]
  10. Radomski, A.P.; Sierociński, D.J.; Chiliński, B.D. Proposition of a structural health monitoring model for a concept of an innovative variable mass pendular tuned mass damper. Diagnostyka 2024, 25, 1–10. [Google Scholar] [CrossRef]
  11. Hassan, M.S.; Safwat, I.M.; Abounemra, A.M.E.; Ahmed, H.N. A generalized closed-form analytic design technique for solid-state Marx generators. Int. J. Circuit Theory Appl. 2024, 52, 4026–4039. [Google Scholar] [CrossRef]
  12. Wang, B.; Zhang, C.; Xia, Y.; Zhang, F. Analytical solution of serial ferroresonance triggered by circuit breaker operation in solidly grounded power grids. Int. J. Electr. Power Energy Syst. 2023, 154, 109447. [Google Scholar] [CrossRef]
  13. Fevzi Çakmak, Z.A.; Tür, M.R. Analysis of Open Circuit Voltage MPPT Method with Analytical Analysis with Perturb and Observe (P&O) MPPT Method in PV Systems. Electr. Power Compon. Syst. 2023, 52, 1528–1542. [Google Scholar] [CrossRef]
  14. Alqhtani, M.; Saad, K.M.; Shah, R.; Hamanah, W.M. Discovering novel soliton solutions for (3+1)-modified fractional Zakharov–Kuznetsov equation in electrical engineering through an analytical approach. Opt. Quantum Electron. 2023, 55, 1149. [Google Scholar] [CrossRef]
  15. Valbuena Godoy, J.; Negri, S.; Oliva, F.; Antoniazzi, A.; Faranda, R.S. Innovative Fault Current Evaluation Method for Active DC Grids. Electronics 2024, 13, 847. [Google Scholar] [CrossRef]
  16. Zhou, P.; Ghabeli, A.; Ainslie, M.; Grilli, F. Characterization of flux pump-charging of high-temperature superconducting coils using coupled numerical models. Supercond. Sci. Technol. 2023, 36, 115002. [Google Scholar] [CrossRef]
  17. Du, Y.; Qiao, J.; Wu, J.; Xu, Y.; Nan, T.; Dong, S.; Hu, Z.; Liu, M. Performance analysis of acoustically actuated magnetoelectric antennas via equivalent circuit method. J. Appl. Phys. 2024, 135, 114101. [Google Scholar] [CrossRef]
  18. Arnold, M. Numerical methods for simulation in applied dynamics. In Simulation Techniques for Applied Dynamics; Arnold, M., Schiehlen, W., Eds.; Springer: Vienna, Austria, 2009; pp. 191–246. [Google Scholar] [CrossRef]
  19. Tatjewski, P. Numerical Methods, 1st ed.; Oficyna Wydawnicza Politechniki Warszawskiej: Warsaw, Poland, 2015. [Google Scholar]
  20. Wang, Y.; Zhao, G. A comparative study of fractional-order models for lithium-ion batteries using Runge Kutta optimizer and electrochemical impedance spectroscopy. Control. Eng. Pract. 2023, 133, 105451. [Google Scholar] [CrossRef]
  21. Baron, B.; Kolanska-Płuska, J.; Łukaniszyn, M.; Spałek, D.; Kraszewski, T. Solution of nonlinear stiff differential equations for a three-phase no-load transformer using a Runge-Kutta implicit method. Arch. Electr. Eng. (Online) 2022, 71, 1081–1106. [Google Scholar]
  22. Yousri, D.; Mudhsh, M.; Shaker, Y.O.; Abualigah, L.; Tag-Eldin, E.; Abd Elaziz, M.; Allam, D. Modified Interactive Algorithm Based on Runge Kutta Optimizer for Photovoltaic Modeling: Justification Under Partial Shading and Varied Temperature Conditions. IEEE Access 2022, 10, 20793–20815. [Google Scholar] [CrossRef]
  23. Malarvizhi, M.; Karunanithi, S. Study of electrical circuits using Runge Kutta method of order 4. J. Comput. Math. 2021, 5, 109–120. [Google Scholar]
  24. Teoh, A.K. Transient Analysis of Electrical Circuits Using Runge-Kutta Method. 2017. Available online: https://api.semanticscholar.org/CorpusID:86832491 (accessed on 10 October 2024).
  25. Maffezzoni, P.; Codecasa, L.; D’Amore, D. Time-Domain Simulation of Nonlinear Circuits Through Implicit Runge–Kutta Methods. IEEE Trans. Circuits Syst. I Regul. Pap. 2007, 54, 391–400. [Google Scholar] [CrossRef]
  26. Suhag, A. Transient analysis of electrical circuits using Runge-Kutta method and its application. Int. J. Sci. Res. Publ. 2013, 3, 486–490. [Google Scholar]
  27. Patil, M.B.; Hari, V.V.S.P.K. Circuit simulation using explicit methods. arXiv 2023, arXiv:2301.04595. [Google Scholar]
  28. Fadnavis, S. Round off Error propagation in simulation of RC circuit Subtitle: Simulation of RC circuit. In Proceedings of the nternational Conference on Advances in Computing and Information Technology–ACIT 2014, Bangkok, Thailand, 4–5 January 2014. [Google Scholar]
  29. Kazmierski, T.J.; Wang, L.; Al-Hashimi, B.M.; Merrett, G.V. An Explicit Linearized State-Space Technique for Accelerated Simulation of Electromagnetic Vibration Energy Harvesters. IEEE Trans.-Comput.-Aided Des. Integr. Circuits Syst. 2012, 31, 522–531. [Google Scholar] [CrossRef]
  30. MOHAMAD ZAKI, F.A.; Isa, S. Numerical Solutions of Applications in Ordinary Differential Equation by Implicit Multistep Method. Enhanc. Knowl. Sci. Technol. 2022, 2, 500–507. [Google Scholar]
  31. Kuznyetsov, O. Modeling of electromechanical systems based on induction machine using method of average voltage on the integration step length. Sci. Bull. Ser. C Electr. Eng. Comput. Sci. 2017, 79, 169–180. [Google Scholar]
  32. Adeniran, O. Numerical solution of some selected RLC circuits. Sospoly J. Sci. Agric. 2017, 2, 1–11. [Google Scholar]
  33. Tural-Polat, S.N.; Dincel, A.T. Wavelet methods for fractional electrical circuit equations. Phys. Scr. 2023, 98, 115203. [Google Scholar] [CrossRef]
  34. Avci, I. Spectral collocation with generalized Laguerre operational matrix for numerical solutions of fractional electrical circuit models. Math. Model. Numer. Simul. Appl. 2024, 4, 110–132. [Google Scholar] [CrossRef]
  35. Doménech-Asensi, G.; Kazmierski, T.J. Generation of new power processing structures exploiting genetic programming. In Proceedings of the 2017 IEEE 26th International Symposium on Industrial Electronics (ISIE), Edinburgh, UK, 19–21 June 2017; pp. 729–732. [Google Scholar] [CrossRef]
  36. Sels, T.; Craenenbroeck, T.V.; Hameyer, K.; Mertens, R.; Declercq, J. Comparison of a Combined Time-Harmonic—Transient Finite Element Analysis of Fast Transient Oscillations with Laboratory Measurements. 2000. Available online: https://api.semanticscholar.org/CorpusID:125250908 (accessed on 7 October 2024).
  37. Condon, M.; Dautbegovic, E.; Brazil, T. An Efficient Numerical Algorithm for the Transient Analysis of High-Frequency Non-Linear Circuits. In Proceedings of the 2002 32nd European Microwave Conference, Milan, Italy, 23–26 September 2002. [Google Scholar] [CrossRef]
  38. Cai, Y.; Zhang, J.; Yu, W. A Predictor-Corrector Method for Power System Variable Step Numerical Simulation. IEEE Trans. Power Syst. 2019, 34, 3283–3285. [Google Scholar] [CrossRef]
  39. Kurobe, H.; Sekine, T.; Asai, H. Predictor-corrector latency insertion method for fast transient analysis of ill-constructed circuits. In Proceedings of the 17th Asia and South Pacific Design Automation Conference, Sydney, Australia, 30 January–2 February 2012; pp. 365–370. [Google Scholar]
  40. Noda, T.; Yamamoto, K.; Nagaoka, N.; Ametani, A. A predictor-corrector scheme for solving a nonlinear circuit. In Proceedings of the IPST 1997, Seattle, WA, USA, 22–26 June 2016; Volume 95, pp. 5–10. [Google Scholar]
  41. Tripodi, E.; Musolino, A.; Rizzo, R.; Raugi, M. A new predictor–corrector approach for the numerical integration of coupled electromechanical equations. Int. J. Numer. Methods Eng. 2016, 105, 261–285. [Google Scholar] [CrossRef]
  42. Aadithya, K.; Keiter, E.; Mei, T. Predictor/Corrector Newton-Raphson (PCNR): A Simple, Flexible, Scalable, Modular, and Consistent Replacement for Limiting in Circuit Simulation. In Scientific Computing in Electrical Engineering; Springer: Cham, Switzerland, 2020; pp. 201–208. [Google Scholar] [CrossRef]
  43. Abdulsalam, S.; Xu, W.; Dinavahi, V. Modelling and simulation of three-phase transformers for inrush current studies. Gener. Transm. Distrib. 2005, 152, 328–333. [Google Scholar] [CrossRef]
  44. Bayrak, M.A.; Can, E. Numerical Solution of Fuzzy Differential Equations by Milne’S Predictor-Corrector Method. Math. Sci. Appl. E-Notes 2015, 3, 137–153. [Google Scholar] [CrossRef]
  45. Sowa, M. A subinterval-based method for circuits with fractional order elements. Bull. Pol. Acad. Sci. Tech. Sci. 2014, 62, 449–454. [Google Scholar] [CrossRef]
  46. Virtanen, P.; Gommers, R.; Oliphant, T.E.; Haberland, M.; Reddy, T.; Cournapeau, D.; Burovski, E.; Peterson, P.; Weckesser, W.; Bright, J.; et al. SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python. Nat. Methods 2020, 17, 261–272. [Google Scholar] [CrossRef]
  47. Semenova, M.; Kazazaeva, D.; Sabychikova, A. Simulation and analysis of transition processes in linear electrical circuits using MatLab software package. E3s Web Conf. 2023, 389, 1045. [Google Scholar] [CrossRef]
  48. Khanahmedova, S. Investigation of Some Electrical Circuits Using Simulation in Matlab/Simulink. Available online: https://cyberleninka.ru/article/n/investigation-of-some-electrical-circuits-using-simulation-in-matlab-simulink/viewer (accessed on 8 October 2024).
  49. Mladenović, V.M.; Porrat, D.; Lutovac, M.D. Simulation of OFDM transmitters and post processing with SchematicSolver and Mathematica as a computer algebra system. In Proceedings of the Papers 5th European Conference on Circuits and Systems for Communications (ECCSC’10), Belgrade, Serbia, 23–25 November 2010; pp. 278–281. [Google Scholar]
  50. Yadir, S.; Aazou, S.; Maouhoub, N.; Rais, K.; Benhmida, M.; Assaid, E. Illuminated solar cell physical parameters extraction using mathematica. In Proceedings of the 2009 IEEE/ACS International Conference on Computer Systems and Applications, Rabat, Morocco, 10–13 May 2009; pp. 63–64. [Google Scholar]
  51. MATLAB. Specialized Power Systems. Available online: https://www.mathworks.com/help/sps/specialized-power-systems.html?s_tid=CRUX_lftnav (accessed on 3 May 2024).
  52. Modeler, W.S. Modelica: Electrical. Available online: https://reference.wolfram.com/system-modeler/libraries/Modelica/Modelica.Electrical.html (accessed on 3 May 2024).
  53. Asadi, F. Electric and Electronic Circuit Simulation using TINA-TI. In Electric and Electronic Circuit Simulation Using TINA-TI; River Publishers: Aalborg, Denmark, 2022. [Google Scholar]
  54. Pérez Martínez, M.; Ramos Guardarrama, J.; Santos Baranda, J.; Silvério Freire, R.C. Use of Scilab software as a didactic tool in electrical circuits laboratory practices. Ing. Energética 2022, 43, 71–79. [Google Scholar]
  55. CircuitLab. Online Circuit Simulator & Schematic Editor. Available online: https://www.circuitlab.com/ (accessed on 3 May 2024).
  56. Boys, B.; Dodwell, T.; Hobbs, M.; Girolami, M. PeriPy—A high performance OpenCL peridynamics package. Comput. Methods Appl. Mech. Eng. 2021, 386, 114085. [Google Scholar] [CrossRef]
  57. Lutz, M. Programming Python; O’Reilly Media, Inc.: Sebastopol, CA, USA, 2001. [Google Scholar]
  58. Oliphant, T. Python for Scientific Computing. Comput. Sci. Eng. 2007, 9, 10–20. [Google Scholar] [CrossRef]
  59. Meurer, A.; Smith, C.P.; Paprocki, M.; Čertík, O.; Kirpichev, S.B.; Rocklin, M.; Kumar, A.; Ivanov, S.; Moore, J.K.; Singh, S.; et al. SymPy: Symbolic computing in Python. PeerJ Comput. Sci. 2017, 3, e103. [Google Scholar] [CrossRef]
  60. Kluyver, T.; Ragan-Kelley, B.; Pérez, F.; Granger, B.; Bussonnier, M.; Frederic, J.; Kelley, K.; Hamrick, J.; Grout, J.; Corlay, S.; et al. Jupyter Notebooks—A publishing format for reproducible computational workflows. In Positioning and Power in Academic Publishing: Players, Agents and Agendas; Loizides, F., Schmidt, B., Eds.; IOS Press: Amsterdam, The Netherlands, 2016; pp. 87–90. [Google Scholar]
  61. Dyba, T.; Dingsoyr, T. What Do We Know about Agile Software Development? IEEE Softw. 2009, 26, 6–9. [Google Scholar] [CrossRef]
Figure 1. Graphical representation of the BatteryCell dynamic model.
Figure 1. Graphical representation of the BatteryCell dynamic model.
Energies 18 00332 g001
Figure 2. Definition and output of initialised ODESystem component.
Figure 2. Definition and output of initialised ODESystem component.
Energies 18 00332 g002
Figure 3. Preview of analytical solution generation.
Figure 3. Preview of analytical solution generation.
Energies 18 00332 g003
Figure 4. Analytical solution with substituted parameter values.
Figure 4. Analytical solution with substituted parameter values.
Energies 18 00332 g004
Figure 5. Analytical solution values calculated for subsequent time stamps.
Figure 5. Analytical solution values calculated for subsequent time stamps.
Energies 18 00332 g005
Figure 6. Numerical solution obtained by ODESystem with numerised method.
Figure 6. Numerical solution obtained by ODESystem with numerised method.
Energies 18 00332 g006
Figure 7. Numerical solutions for multiple values of analysed parameters obtained by NumericalAnalysisDataFrame.
Figure 7. Numerical solutions for multiple values of analysed parameters obtained by NumericalAnalysisDataFrame.
Energies 18 00332 g007
Figure 8. Analytical solutions for multiple values of analysed parameters obtained by NumericalAnalysisDataFrame.
Figure 8. Analytical solutions for multiple values of analysed parameters obtained by NumericalAnalysisDataFrame.
Energies 18 00332 g008
Figure 9. The equivalent circuit diagram of the analysed DC motor system.
Figure 9. The equivalent circuit diagram of the analysed DC motor system.
Energies 18 00332 g009
Figure 10. Rotor supply voltage.
Figure 10. Rotor supply voltage.
Energies 18 00332 g010
Figure 11. Motor load torque.
Figure 11. Motor load torque.
Energies 18 00332 g011
Figure 12. Armature current —simulational results obtained from DynPy library (HAN, fixed step size 0.1 s ).
Figure 12. Armature current —simulational results obtained from DynPy library (HAN, fixed step size 0.1 s ).
Energies 18 00332 g012
Figure 13. Rotor’s angular velocity—simulational results obtained from DynPy library (HAN, fixed step size 0.1 s ).
Figure 13. Rotor’s angular velocity—simulational results obtained from DynPy library (HAN, fixed step size 0.1 s ).
Energies 18 00332 g013
Figure 14. Armature current—simulational results obtained from DynPy with fully analytical solution.
Figure 14. Armature current—simulational results obtained from DynPy with fully analytical solution.
Energies 18 00332 g014
Figure 15. Rotor’s angular velocity—simulational results obtained from DynPy with fully analytical solution.
Figure 15. Rotor’s angular velocity—simulational results obtained from DynPy with fully analytical solution.
Energies 18 00332 g015
Figure 16. DynPy —comparison of results for armature current obtained with hybrid analytical–numerical and fully analytical solution.
Figure 16. DynPy —comparison of results for armature current obtained with hybrid analytical–numerical and fully analytical solution.
Energies 18 00332 g016
Figure 17. DynPy —comparison of results for angular velocity of the rotor obtained with hybrid analytical–numerical and fully analytical solution.
Figure 17. DynPy —comparison of results for angular velocity of the rotor obtained with hybrid analytical–numerical and fully analytical solution.
Energies 18 00332 g017
Figure 18. Block diagram representing a DC motor designed in MATLAB/Simulink.
Figure 18. Block diagram representing a DC motor designed in MATLAB/Simulink.
Energies 18 00332 g018
Figure 19. Armature current—simulation results in MATLAB/Simulink with variable integration step.
Figure 19. Armature current—simulation results in MATLAB/Simulink with variable integration step.
Energies 18 00332 g019
Figure 20. Angular velocity of the rotor—simulation results in MATLAB/Simulink with variable integration step.
Figure 20. Angular velocity of the rotor—simulation results in MATLAB/Simulink with variable integration step.
Energies 18 00332 g020
Figure 21. Armature current—simulation results in MATLAB/Simulink with a specified constant integration step of 0.1 s .
Figure 21. Armature current—simulation results in MATLAB/Simulink with a specified constant integration step of 0.1 s .
Energies 18 00332 g021
Figure 22. Angular velocity of the rotor—simulation results in MATLAB/Simulink with a specified constant integration step of 0.1 s .
Figure 22. Angular velocity of the rotor—simulation results in MATLAB/Simulink with a specified constant integration step of 0.1 s .
Energies 18 00332 g022
Figure 23. Armature current—simulation results in MATLAB/Simulink with a specified constant integration step of 0.01 s .
Figure 23. Armature current—simulation results in MATLAB/Simulink with a specified constant integration step of 0.01 s .
Energies 18 00332 g023
Figure 24. Angular velocity of the rotor—simulation results in MATLAB/Simulink with a specified constant integration step of 0.01 s .
Figure 24. Angular velocity of the rotor—simulation results in MATLAB/Simulink with a specified constant integration step of 0.01 s .
Energies 18 00332 g024
Figure 25. Schematic representation of the analysed RLC circuit.
Figure 25. Schematic representation of the analysed RLC circuit.
Energies 18 00332 g025
Figure 26. Resistance signal.
Figure 26. Resistance signal.
Energies 18 00332 g026
Figure 27. Block diagram representing an RLC circuit designed in extitMATLAB/Simulink.
Figure 27. Block diagram representing an RLC circuit designed in extitMATLAB/Simulink.
Energies 18 00332 g027
Figure 28. Comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.1 s and MATLAB/Simulink with a variable integration step size.
Figure 28. Comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.1 s and MATLAB/Simulink with a variable integration step size.
Energies 18 00332 g028
Figure 29. DC motor - comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.1 s and MATLAB/Simulink with a fixed integration step size of 0.1 s .
Figure 29. DC motor - comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.1 s and MATLAB/Simulink with a fixed integration step size of 0.1 s .
Energies 18 00332 g029
Figure 30. Comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.1 s and MATLAB/Simulink with a fixed integration step size of 0.01 s .
Figure 30. Comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.1 s and MATLAB/Simulink with a fixed integration step size of 0.01 s .
Energies 18 00332 g030
Figure 31. RLC circuit - comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.1 s and MATLAB/Simulink with a fixed integration step size of 0.1 s .
Figure 31. RLC circuit - comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.1 s and MATLAB/Simulink with a fixed integration step size of 0.1 s .
Energies 18 00332 g031
Figure 32. Comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.01 s and MATLAB/Simulink with a fixed integration step size of 0.01 s .
Figure 32. Comparison of simulations conducted using the DynPy library with a fixed integration step size of 0.01 s and MATLAB/Simulink with a fixed integration step size of 0.01 s .
Energies 18 00332 g032
Figure 33. Comparison of simulations conducted using the DynPy library with a fixed integration step sizes of 0.01 s and 0.1 s compared with MATLAB/Simulink variable integration step size.
Figure 33. Comparison of simulations conducted using the DynPy library with a fixed integration step sizes of 0.01 s and 0.1 s compared with MATLAB/Simulink variable integration step size.
Energies 18 00332 g033
Table 1. Parameter values adopted for calculations.
Table 1. Parameter values adopted for calculations.
ParameterUnitValue
R w Ω 2.0
L w H0.1
k e Vs rad 0.1
k m Nm A 0.1
J kgm 2 s 2 0.1
B Nms rad 0.5
Ts4
Table 2. Results of the simulation conducted using the DynPy library—fully analytical method.
Table 2. Results of the simulation conducted using the DynPy library—fully analytical method.
t [ s ] i w [ A ] ω s [ rad s ]
0.0000000.000000−0.000000
1.0000004.9510520.979779
2.0000004.7542540.596283
3.000000−0.000552−0.381824
4.0000000.384783−0.001621
5.0000004.9510410.972042
6.0000004.3845710.594716
7.000000−0.000541−0.374180
8.0000000.7399520.000653
9.0000004.9510300.964474
10.0000004.9504990.596505
Table 3. Results of the simulation conducted using the DynPy library—HAN method.
Table 3. Results of the simulation conducted using the DynPy library—HAN method.
t [ s ] i w [ A ] ω s [ rad s ]
0.000000−0.0000000.000000
1.0000004.9510550.981733
2.0000004.9701330.596505
3.0000000.019241−0.387659
4.0000000.000164−0.002446
5.0000004.9510560.981718
6.0000004.9701330.596505
7.0000000.019241−0.387659
8.0000000.000164−0.002446
9.0000004.9510560.981718
10.0000004.9701330.596505
Table 4. Results of the simulation conducted with variable integration step in MATLAB/Simulink.
Table 4. Results of the simulation conducted with variable integration step in MATLAB/Simulink.
t [ s ] i w [ A ] ω s [ rad s ]
0.0000000.0000000.000000
1.0000004.9506320.981745
2.0000004.9705010.596487
3.0000000.019819−0.387680
4.000000−0.000201−0.002427
5.0000004.9506920.981726
6.0000004.9705000.596487
7.0000000.019819−0.387680
8.000000−0.000201−0.002427
9.0000004.9506920.981726
10.0000004.9705000.596487
Table 5. Results of the simulation conducted with a constant integration step of 0.1 s in MATLAB/Simulink.
Table 5. Results of the simulation conducted with a constant integration step of 0.1 s in MATLAB/Simulink.
t [ s ] i w [ A ] ω s [ rad s ]
0.0000000.0000000.000000
1.0000004.9509630.982077
2.0000004.9701400.596408
3.0000000.019333−0.388004
4.0000000.000157−0.002349
5.0000004.9509640.982063
6.0000004.9701400.596408
7.0000000.019333−0.388004
8.0000000.000157−0.002349
9.0000004.9509640.982063
10.0000004.9701400.596408
Table 6. Results of the simulation conducted with a specified constant integration step of 0.01 s in MATLAB/Simulink.
Table 6. Results of the simulation conducted with a specified constant integration step of 0.01 s in MATLAB/Simulink.
t [ s ] i w [ A ] ω s [ rad s ]
0.0000000.0000000.000000
1.0000004.9510550.981734
2.0000004.9701330.596505
3.0000000.019241−0.387659
4.0000000.000164−0.002446
5.0000004.9510560.981718
6.0000004.9701330.596505
7.0000000.019241−0.387659
8.0000000.000164−0.002446
9.0000004.9510560.981718
10.0000004.9701330.596505
Table 7. Parameter values adopted for simulations of RLC circuit.
Table 7. Parameter values adopted for simulations of RLC circuit.
ParameterUnitValue
UV10.0
R Ω 19.9
R m i n Ω 0.1
LH1
CF100
Ts4
Table 8. DC motor: comparison of results for chosen time stamps—MATLAB/Simulink with variable step and HAN method with 0.1 s step.
Table 8. DC motor: comparison of results for chosen time stamps—MATLAB/Simulink with variable step and HAN method with 0.1 s step.
MATLAB, Δ t const DynPy HAN, Δ t = 0.1 s
t [ s ] i w [ A ] ω s [ rad s ] i w [ A ] ω s [ rad s ]
0.1000004.3032430.2463514.3174660.236242
1.1000004.9544240.8899134.9555570.827837
2.1000000.6627440.3459300.6527320.359291
3.1000000.015932−0.2955130.014739−0.233768
4.1000004.2424980.2339024.3175650.234769
5.1000004.9544490.8900174.9555580.827828
6.1000000.6627440.3459300.6527320.359291
7.1000000.015932−0.2955130.014739−0.233768
8.1000004.2424980.2339024.3175650.234769
9.1000004.9544490.8900174.9555580.827828
Table 9. DC motor: comparison of results for chosen time stamps—MATLAB/Simulink with 0.1 s step and HAN method 0.1 s step.
Table 9. DC motor: comparison of results for chosen time stamps—MATLAB/Simulink with 0.1 s step and HAN method 0.1 s step.
MATLAB, Δ t = 0.01 s DynPy HAN, Δ t = 0.1 s
t [ s ] i w [ A ] ω s [ rad s ] i w [ A ] ω s [ rad s ]
0.1000006.6500000.0833334.3174660.236242
1.1000004.9525070.8272824.9555570.827837
2.100000−1.6797970.5121350.6527320.359291
3.1000000.017789−0.2332140.014739−0.233768
4.1000006.6500940.0819244.3175650.234769
5.1000004.9525080.8272734.9555580.827828
6.100000−1.6797970.5121350.6527320.359291
7.1000000.017789−0.2332140.014739−0.233768
8.1000006.6500940.0819244.3175650.234769
9.1000004.9525080.8272734.9555580.827828
Table 10. DC motor: comparison of results for chosen time stamps—MATLAB/Simulink with 0.01 s step and HAN method with 0.1 s step.
Table 10. DC motor: comparison of results for chosen time stamps—MATLAB/Simulink with 0.01 s step and HAN method with 0.1 s step.
MATLAB, Δ t = 0.01 s DynPy HAN, Δ t = 0.1 s
t [ s ] i w [ A ] ω s [ rad s ] i w [ A ] ω s [ rad s ]
0.1000004.3179960.2362094.3174660.236242
1.1000004.9555570.8278364.9555570.827837
2.1000000.6522030.3593240.6527320.359291
3.1000000.014740−0.2337680.014739−0.233768
4.1000004.3180940.2347354.3175650.234769
5.1000004.9555570.8278274.9555580.827828
6.1000000.6522030.3593240.6527320.359291
7.1000000.014740−0.2337680.014739−0.233768
8.1000004.3180940.2347354.3175650.234769
9.1000004.9555570.8278274.9555580.827828
Table 11. RLC circuit: comparison of results for chosen time stamps—MATLAB/Simulink with 0.1 s step and HAN method with 0.1 s step.
Table 11. RLC circuit: comparison of results for chosen time stamps—MATLAB/Simulink with 0.1 s step and HAN method with 0.1 s step.
DynPy, HAN, Δ t = 0.1 s MATLAB/Simulink, Δ t = 0.1 s
t [ s ] q ˙ [A] q ˙ [A]
0.0000000.0000000.000000
1.0000000.5022980.497255
2.0000000.5020460.497013
3.0000009.49422810.368359
4.00000017.58540220.136108
5.0000000.4917540.486170
6.0000000.4915070.485625
7.0000009.29492910.130792
8.00000017.21625619.674735
9.0000000.4814310.475031
10.0000000.4811890.474498
Table 12. RLC circuit: comparison of results for chosen time stamps—MATLAB/Simulink with 0.01 s step and HAN method with 0.01 s step.
Table 12. RLC circuit: comparison of results for chosen time stamps—MATLAB/Simulink with 0.01 s step and HAN method with 0.01 s step.
DynPy, HAN, Δ t = 0.01 s MATLAB/Simulink, Δ t = 0.1 s
t [ s ] q ˙ [A] q ˙ [A]
0.0000000.0000000.000000
1.0000000.5022870.497263
2.0000000.5020340.497013
3.0000009.89828610.368359
4.00000018.31094820.136108
5.0000000.4915320.485869
6.0000000.4912850.485625
7.0000009.68634510.130792
8.00000017.91887619.674735
9.0000000.4810070.474736
10.0000000.4807650.474498
Table 13. RLC circuit: comparison of results for chosen time stamps—MATLAB/Simulink with variable step and HAN method with 0.1 s and 0.01 s step.
Table 13. RLC circuit: comparison of results for chosen time stamps—MATLAB/Simulink with variable step and HAN method with 0.1 s and 0.01 s step.
DynPy, Δ t = 0.1 s DynPy, Δ t = 0.01 s MATLAB/Simulink, Δ t const
t [ s ] q ˙ [A] q ˙ [A] q ˙ [A]
0.0000000.0000000.0000000.000000
1.0000000.5022980.5022870.497267
2.0000000.5020460.5020340.497013
3.0000009.4942289.89828610.295847
4.00000017.58540218.31094820.144906
5.0000000.4917540.4915320.485902
6.0000000.4915070.4912850.485620
7.0000009.2949299.68634510.099166
8.00000017.21625617.91887619.692078
9.0000000.4814310.4810070.474862
10.0000000.4811890.4807650.474468
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Sierociński, D.; Chiliński, B.; Gawiński, F.; Radomski, A.; Przybyłowicz, P. DynPy—Python Library for Mechanical and Electrical Engineering: An Assessment with Coupled Electro-Mechanical Direct Current Motor Model. Energies 2025, 18, 332. https://doi.org/10.3390/en18020332

AMA Style

Sierociński D, Chiliński B, Gawiński F, Radomski A, Przybyłowicz P. DynPy—Python Library for Mechanical and Electrical Engineering: An Assessment with Coupled Electro-Mechanical Direct Current Motor Model. Energies. 2025; 18(2):332. https://doi.org/10.3390/en18020332

Chicago/Turabian Style

Sierociński, Damian, Bogumił Chiliński, Franciszek Gawiński, Amadeusz Radomski, and Piotr Przybyłowicz. 2025. "DynPy—Python Library for Mechanical and Electrical Engineering: An Assessment with Coupled Electro-Mechanical Direct Current Motor Model" Energies 18, no. 2: 332. https://doi.org/10.3390/en18020332

APA Style

Sierociński, D., Chiliński, B., Gawiński, F., Radomski, A., & Przybyłowicz, P. (2025). DynPy—Python Library for Mechanical and Electrical Engineering: An Assessment with Coupled Electro-Mechanical Direct Current Motor Model. Energies, 18(2), 332. https://doi.org/10.3390/en18020332

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop