Fundamental concepts
Base units and dimensions
Base unitshave the important property that all other units derive from them.
The International System of Units (SI) consists of seven fundamental base units, each representing a specific physical quantity: meter (m) for measuring length, kilogram (kg) for mass, second (s) for time, kelvin (K) for temperature, ampere (A) for electric current, candela (cd) for luminous intensity, and mole (mol) for the amount of substance.
To effectively calculate with dimensions such as length, mass, time, and temperature, we use specific mathematical notations: length is represented as [L], mass as [M], time as [T], and temperature as [Θ] For derived units, velocity is expressed as [LT⁻¹], indicating distance (length) divided by time Additionally, the dimension of force can also be defined within this framework.
H.P Langtangen and G.K Pedersen, Scaling of Differential Equations, derived unit, is the same as the dimension of mass times acceleration, and hence the dimension of force is [MLT −2 ].
In analyzing the dimensions of the terms in equation (1.1), we find that the displacement \( u(t) \) has the dimension of length, denoted as [L] The derivative \( u'(t) \), representing the change in displacement over a time interval, has dimensions of [L] divided by [T], leading to the dimension of velocity as [LT^{-1}] This aligns with the definition of velocity, which is the ratio of distance ([L]) to time ([T]).
In the analysis of equation (1.1), interpreting u(t) as displacement reveals that the term mu, representing mass times acceleration, has the dimension [MLT −2] Consequently, the term bu must share this dimension; given that u has the dimension [LT −1], it follows that b possesses the dimension [MT −1] Additionally, the term ku also carries the dimension [MLT −2], indicating that k is a parameter with the dimension [MT −2].
The unit of a physical quantity is derived from its dimensional expression For instance, velocity, which has the dimension [LT −1], is measured in meters per second (m/s), while force, with the dimension [MLT −2], is expressed in kilograms times meters per second squared (kg m/s²) Additionally, the parameter in equation (1.1) is quantified in kilograms per second squared (kg s −2).
To understand the dimension of a derivative, it can be expressed as a finite difference For a function u(t), the derivative is approximated as du/dt ≈ (u(t + Δt) - u(t)) / Δt, where Δt represents a small time interval If u denotes velocity, its dimension is [LT]⁻¹, and the difference u(t + Δt) - u(t) shares this dimension The time interval Δt has the dimension [T], leading to the finite difference having a dimension of [LT]⁻² Therefore, the general dimension of the derivative du/dt is the dimension of u divided by the dimension of t.
Dimensions of common physical quantities
Derived quantities are measured using specific derived units, each with its own name For instance, force is quantified in Newtons (N), which is defined as kg m/s² Another example is the Pascal (Pa), the unit for pressure and stress, representing force per unit area, equivalent to N/m² or kg/ms² Below is a list of additional derived quantities along with their respective units.
Name Symbol Physical quantity Unit radian rad angle 1 hertz Hz frequency s −1 newton N force, weight kg m/s 2 pascal Pa pressure, stress N/m 2 joule J energy, work, heat Nm watt W power J/s
Some common physical quantities and their dimensions are listed next.
Quantity Relation Unit Dimension stress force/area N/m 2 = Pa [MT −2 L −1 ] pressure force/area N/m 2 = Pa MT −2 L −1 ] density mass/volume kg/m 3 [ML −3 ] strain displacement/length 1 [1]
Young’s modulus stress/strain N/m 2 = Pa [MT −2 L −1 ] Poisson’s ratio transverse strain/axial strain 1 [1]
Lame’ parameters λ and μ represent stress and strain in pascals (Pa), defined as [MT −2 L −1] The moment of a force is calculated as distance multiplied by force, measured in newton-meters (Nm) or [ML 2 T −2] Impulse is derived from force multiplied by time, resulting in newton-seconds (Ns) or [MLT −1] Linear momentum is the product of mass and velocity, expressed in kilograms per meter per second (kg m/s) or [MLT −1] Angular momentum combines distance, mass, and velocity, measured in kilogram square meters per second (kg m²/s) or [ML 2 T −1] Work and energy are both quantified as force multiplied by distance, resulting in joules (J) or [ML 2 T −2] Power is defined as work done over time, expressed in watts (W) or [ML 2 T −3] Heat is measured in joules (J), while heat flux is the heat rate per area, expressed in watts per square meter (W/m²) or [MT −3] Temperature is represented by the base unit kelvin (K) or [Θ] Heat capacity indicates heat change per temperature change in joules per kelvin (J/K) or [ML 2 T −2 Θ −1], while specific heat capacity is heat capacity per unit mass in joules per kilogram kelvin (J/kg K) or [L 2 T −2 Θ −1] Thermal conductivity measures heat flux per temperature gradient in watts per meter per kelvin (W/m K) or [MLT −3 Θ −1] Dynamic viscosity is the ratio of shear stress to velocity gradient, measured in kilograms per meter per second (kg/m s) or [ML −1 T −1], and kinematic viscosity is dynamic viscosity divided by density, expressed in square meters per second (m²/s) or [L 2 T −1] Finally, surface tension is defined as energy per area, measured in joules per square meter (J/m²) or [MT −2].
Prefixes for units Units often have prefixes 1 For example, kilo (k) is a prefix for 1000, so kg is 1000 g Similarly, GPa means giga pascal or 10 9 Pa.
The Buckingham Pi theorem
Almost all texts on scaling has a treatment of the famous Buckingham Pi the- orem, which can be used to derive physical laws based on unit compatibility
is a unit prefix that indicates a multiple or submultiple of a basic unit of measure All metric prefixes used today are decadic and each has a unique symbol that precedes the unit symbol For instance, the prefix *kilo-* signifies multiplication by one thousand, making one kilogram equal to one thousand grams The metric system, established in the 1790s, features decimal multiplicative prefixes, which have been standardized for the International System of Units (SI) by the International Bureau of Weights and Measures (BIPM) Currently, there are twenty-four SI prefixes, including the recently adopted *ronna-* and *quetta-* in 2022, which anticipate future needs in data science These prefixes are essential for creating coherent units of measure across various fields, enhancing clarity and consistency in scientific communication.
The theorem is composed of two main parts: first, when dealing with n physical parameters that include m independent unit types (like length and mass), these parameters can be combined to yield exactly n−m independent dimensionless numbers known as Pi’s Second, any relationship that is unit-free among the original n parameters can be converted into a relationship between the n−m dimensionless numbers These relationships may take the form of identities or inequalities, indicating whether certain effects are negligible Additionally, transforming a set of equations into dimensionless form allows for the expression of coefficients, as well as free and dependent variables, in terms of Pi’s.
Consider a body moving at a constant speed \( v \) The distance \( s \) traveled over time \( t \) can be expressed through the Pi theorem, resulting in the dimensionless variable \( \pi = vt/s \) This leads to the formula \( s = Cvt \), where \( C \) is an undetermined constant This outcome closely resembles the familiar physics equation \( s = vt \), derived from the differential equation \( s = v \), but includes an additional constant.
At first glance the Pi theorem may appear as bordering on the trivial.
The application of dimensional analysis can lead to significant advancements in specific scenarios, such as turbulent jets and nuclear blasts, even without extensive knowledge of mathematical or physical models For beginners, this concept may seem profound or even magical However, as problems become more complex and involve numerous parameters, the benefits of the theorem diminish, particularly when the number of Pi terms increases Additionally, these Pi terms can be recombined in various ways, highlighting the necessity for strong physical insight or information from an equation set to identify the most relevant dimensionless numbers and appropriate scaling A careful examination of the equations may also uncover that some terms can be simplified or eliminated.
In this article, we emphasize that Pi terms, derived from the Pi theorem, can be effectively excluded from complex physical problem modeling Instead of treating scaling and dimensionless numbers as separate issues, they should be integrated into the analysis of governing equations Unfortunately, many textbooks and articles inadequately address scaling within the context of these equations Our focus is to explore this often-overlooked process, while we do not intend to undermine the value of the Pi theorem, which can be essential in experimental contexts This textbook aims to provide a complementary perspective on scaling, demonstrating that when working with models based on differential equations, classical dimensional analysis may not be necessary.
Absolute errors, relative errors, and units
The choice of units in physical measurements can significantly impact the representation of errors, especially when dealing with approximations For instance, in a geophysical context, an approximate length of 12.5 km compared to an exact value of 12.52 km results in an absolute error of 0.02 km However, converting this measurement to millimeters yields an error of 20,000 mm, highlighting how absolute error is sensitive to unit selection To mitigate this issue, relative error is often used, calculated as (exact - approximate)/exact, which eliminates the influence of units In this scenario, the relative error remains consistent at 1.6 x 10^-3, regardless of whether the measurement is expressed in kilometers or millimeters.
To improve computational accuracy, it's advisable to scale problems so that the variables involved are of unit size or moderate magnitude, rather than excessively large or small The methods discussed in this article illustrate how to effectively achieve this scaling.
Units and computers
Traditional numerical computing focuses solely on numbers and necessitates the use of dimensionless mathematical expressions Typically, a simple scaling method is employed, where length, time, and mass quantities are scaled by 1 meter, 1 second, and 1 kilogram, respectively, to derive the dimensionless numbers required for calculations While this approach is widely utilized, it is rarely articulated explicitly.
Symbolic computing packages like Mathematica and Maple enable computations involving dimensional quantities Additionally, this capability is available in widely-used programming languages for numerical computing, with Python serving as a specific example.
Unit systems
Confusion often arises when physical quantities are measured in different units, such as SI units versus US or British units, leading to potential errors in unit conversion For example, density might be expressed in ounces per teaspoon, illustrating the complexity of conversions These errors are prevalent among scientists and engineers, and can have serious consequences, such as affecting aircraft fuel calculations Therefore, having reliable software tools for unit conversion is essential, as discussed in Sections 1.1.8 and 1.2 However, readers focused on mathematical scaling techniques may choose to skip this section and proceed directly to Section 2.1.
Example on challenges arising from unit systems
The study of tsunamis encompasses various fields, including geophysics, geology, fluid dynamics, and civil protection, highlighting the complexity and diversity of practices in units and scales When focusing on tsunami propagation modeling, the scaling primarily involves length and time; however, inconsistencies in physical units still pose significant challenges.
The article highlights the occasional use of non-SI units, such as inches and fathoms, which can lead to confusion A more significant concern is the inconsistency in the magnitudes of various variables and the differences in horizontal and vertical scales Surface elevations are generally measured in meters, while for far-field deep water propagation and small tsunamis, these elevations are often represented in centimeters or millimeters In contrast, the deep ocean typically has a characteristic depth of around 5000 meters, with propagation distances extending hundreds or thousands of kilometers Additionally, geographical coordinates (longitude/latitude) are commonly used to describe locations and computational grids, where one latitude minute is approximately equivalent to one nautical mile.
Tsunami wave periods typically range from a few minutes to an hour, allowing them to be distinctly separated from the semi-daily tidal cycles When traversing the Pacific Ocean, the propagation times for these waves generally span several hours to nearly a full day.
In the tsunami research community, scientists, engineers, and bureaucrats exhibit strict preferences regarding data formats and units, necessitating that tsunami modelers produce a wide range of data in various formats that may not align with their internal models Modelers must also be equipped to handle diverse input data forms, while minimizing unnecessary duplication of large data sets with differing units or scaling Furthermore, tsunami models are frequently benchmarked against experimental data, which is typically measured at a lab scale in centimeters or meters, leading to the use of different units—sometimes even volts—along with conversion information from measuring instruments.
The presence of unit particulars in multiple file formats can lead to misconceptions and errors, resulting in wasted time and effort To mitigate these issues, developers of computational tools should ensure a balance between flexibility in unit handling and a clear, consistent scaling convention This principle is equally relevant for academic tools used internally.
To optimize your computational practices, always utilize scaled differential equation models, as outlined in this guide Additionally, software users should be able to input data with specific dimensions and receive output data in the same format Implementing tools such as PhysicalQuantity and the advanced Parampool package will facilitate the handling of explicit dimensions and ensure accurate conversions when necessary.
Using tools to integrate computational software is straightforward when the software is written in Python For software developed in compiled languages like Fortran, C, or C++, the process is equally simple by creating a Python input reading module This module can capture data from a user interface and pass it to the computational software through files or function calls To facilitate this, relevant functions need to be wrapped in Python using tools such as f2py, Cython, Weave, SWIG, or Instant, as demonstrated in basic examples provided in the references.
PhysicalQuantity: a tool for computing with units
This article highlights the use of Python to demonstrate how theoretical concepts translate into practical software applications Python is chosen for its readability and versatility, supporting both MATLAB-like and class-based programming styles found in languages such as Java, C#, and C++ The rapid growth of Python's ecosystem for scientific computing has positioned it as a strong alternative to specialized tools like MATLAB, R, and IDL The coding examples provided require only a basic understanding of procedural programming in Python.
3 http://docs.scipy.org/doc/numpy-dev/f2py/
5 http://docs.scipy.org/doc/scipy/reference/tutorial/weave.html
7 https://bitbucket.org/fenics-project/instant
For readers unfamiliar with Python concepts such as variables, functions, if statements, and module imports, it is advisable to refer to resources like a brief tutorial on scientific Python, the Python Scientific Lecture Notes, or a comprehensive textbook while studying the Python code presented in these notes.
Python exists in two incompatible versions, numbered 2 and 3 The differences can be made small, and there are tools to write code that runs under both versions.
Despite Python version 2 still being prevalent in scientific computing, we choose to use version 2.7 while ensuring our code remains as compatible as possible with version 3.4 and later The primary distinction between the two versions in most of our programs lies in the print statement.
Python offers strong support for computations involving units through the PhysicalQuantity tool from the ScientificPython package created by Konrad Hinsen However, it is important to note that as of now, ScientificPython is not compatible with NumPy versions 1.9 or later.
The PhysicalQuantity object is part of the PhysicalQuantities module 11, which is publicly accessible on GitHub While there is an alternative package called Unum 12 for performing calculations with numbers that include units, this article will focus on the PhysicalQuantities module.
To illustrate the application of the PhysicalQuantity object, we will compute the equation s = vt, where v represents velocity measured in yards per minute and t denotes time in hours To understand the units utilized in PhysicalQuantities, you can execute the command pydoc PhysicalQuantities.
To access the documentation for the ScientificPython package, use the command `pydoc Scientific.Physics.PhysicalQuantities` in the terminal This documentation provides a list of unit names, including yards represented as "yd," minutes as "min," and hours as "h." With this information, we can compute the equation \( s = vt \).
8 http://hplgit.github.io/bumpy/doc/web/index.html
9 http://scipy-lectures.github.com/
10 https://bitbucket.org/khinsen/scientificpython
>>> from Scientific.Physics.PhysicalQuantities import \
>>> # With PhysicalQuantities as separate/stand-alone module:
>>> from PhysicalQuantities import PhysicalQuantity as PQ
The odd unit h*yd/min is better converted to a standard SI unit such as meter:
Note that s is a PhysicalQuantity object with a value and a unit For mathematical computations we need to extract the value as afloatobject.
We can also extract the unit as a string:
Here is an example on how to convert the odd velocity unit yards per minute to something more standard:
To convert the specific heat capacity of water from calories to joules, we start with the known value of 1 cal g⁻¹ K⁻¹ The equivalent value in the standard unit of joules is calculated as 4.184 J g⁻¹ K⁻¹, since one calorie is approximately equal to 4.184 joules.
Parampool: user interfaces with automatic unit conversion
Pool of parameters
Parampool necessitates the definition of a pool of input parameters, represented as a list of dictionaries, with each dictionary containing details about an individual parameter While input parameters can be organized in a hierarchical tree structure with subpools, our straightforward application requires only a flat structure comprising three parameters: v0, a, and t These parameters are categorized under a subpool named "Main."
The pool is created by the code
For each parameter we can define a logical name, such asinitial velocity, a default value, and a unit Additional properties are also allowed, see the
Tip: specify default values of numbers as float objects
Note that we do not just write 1, but 1.0 as default Had 1 been used,
Parampool interprets parameters as integers, leading to the conversion of inputs like 2.5 m/s to 2 m/s To ensure that a real-valued parameter is treated as a float within the pool, it is essential to set the default value as a real number, such as 1 or 1.0 This approach guarantees accurate input handling in the function definition.
’Main’, [ dict(name=’initial velocity’, default=1.0, unit=’m/s’), dict(name=’acceleration’, default=1.0, unit=’m/s**2’), dict(name=’time’, default.0, unit=’s’)
To convert a list into a Pool object, use the `listtree2Pool` function from the `parampool.pool.UI` module You can also explicitly set an input parameter using the `str2type` property, such as `str2type=float` This allows for greater flexibility in handling data types during the conversion process.
Fetching pool data for computing
We can make a little function for fetching values from the pool and computing s:
The `pool.get_value` function retrieves the numerical value of a specified parameter after converting the user's input unit to the registered unit in the pool For instance, if the user inputs the command-line argument ` time '2 h'`, the `Parampool` will convert this duration into seconds, resulting in `pool.get_value('time')` returning 7200.
Reading command-line options
To run the computations, we define the pool, load values from the command line, and calldistance:
Parameter names with whitespace must use an underscore for whitespace in the command-line option, such as in Initial_velocity We can now run
Terminal> python distance.py initial_velocity ’10 km/h’ \
Notice from the answer (s) that 10 km/h gets converted to m/s and 1 h to s.
To retrieve parameter values as PhysicalQuantity objects from the pool, define a function called `distance(pool)` Within this function, obtain the initial velocity, acceleration, and time by using `pool.get_value()` for each parameter Calculate the distance using the formula \( s = v_0 \times t + 0.5 \times a \times t^2 \) After defining the input pool with `define_input()`, utilize `set_values_from_command_line(pool)` to set the values Finally, compute the distance and print the result with `print 's=%g' % s`.
The following variant of the distance function computes with values and units:
We can then do and get output with the right unit as well.
Setting default values in a file
In large applications that require numerous input parameters, it's common to establish a comprehensive set of default values tailored to specific cases, allowing users to override select values via the command line These default values can be conveniently defined in a file using a straightforward syntax.
The unit can be given after the!symbol (and before the comment symbol
To read such files we have to add the lines before the call toset_defaults_from_command_line.
If the above commands are stored in a filedistance.dat, we give this file information to the program through the option –poolfile distance.dat.
Terminal> python distance.py poolfile distance.dat s.25 m v_0 = pool.get_value_unit(’Initial velocity’) def distance_unit(pool):
To compute the distance using the initial velocity, acceleration, and time, we utilize the formula \( s = v_0 \cdot t + 0.5 \cdot a \cdot t^2 \) The initial velocity is set to 100 yards per minute, with an acceleration of 0 meters per second squared, indicating no drop acceleration After retrieving the necessary values from the pool, the computed distance and its unit are returned and printed.
The initial velocity of 100 yards per minute is converted to 1.524 meters per second, with zero acceleration, and is then introduced into the pool system Subsequently, the function distance_unit retrieves these values from the pool, along with the default time value.
10 s The calculation is then s= 1.524ã10 + 0 = 15.24 with unit m We can override the time and/or the other two parameters on the command line:
Terminal> python distance.py poolfile distance.dat time ’2 h’ s972.8 m
The resulting calculations ares= 1.524ã7200 + 0 = 10972.8 You are encour- aged to play around with thedistance.pyprogram.
Specifying multiple values of input parameters
Parampool offers a unique feature that allows multiple values to be assigned to an input parameter, facilitating the exploration of all parameter combinations in an application To illustrate this capability, we can create a table that includes values for v0, a, t, and s In the compute function, it is essential to use pool.get_values instead of pool.get_value to retrieve a comprehensive list of specified values for the relevant parameter By implementing nested loops for each parameter, we can effectively traverse all user-defined combinations.
When a single value is specified for a parameter, the pool.get_values function returns only that value, resulting in a single iteration of the corresponding loop After loading the command-line arguments into the ourpool object, we can utilize the distance_table function to generate a well-structured table of results, rather than using distance or distance_unit.
Here is a sample run, def distance_table(pool):
The code retrieves multiple values for parameters such as initial velocity, acceleration, and time from a specified pool It calculates the distance using the formula \( s = v_0 \cdot t + 0.5 \cdot a \cdot t^2 \) and stores the results in a table The final output presents a formatted table displaying the values of initial velocity, acceleration, time, and calculated distance.
Terminal> python distance.py time ’1 h & 2 h & 3 h’ \
It is important to observe that certain multiple values may have dimensions that differ from the registered dimension for the respective parameter, and the accompanying table indicates that these values have been successfully converted to the appropriate dimension.
Generating a graphical user interface
With Param-pool, creating an engaging graphical user interface is effortless By encapsulating the distance_unit function, we can present the output in visually appealing HTML format.
In addition, we must make a filegenerate_distance_GUI.pywith the simple content def distance_unit2(pool):
The function `distance_unit(pool)` returns a formatted HTML string displaying the distance and its unit It utilizes the `generate` function from `parampool.generator.flask` and the `distance_unit2` and `define_input` methods from the `distance` module The output includes MathJax support for enhanced rendering.
The script Runninggenerate_distance_GUI.py establishes a Flask-based web interface for the distance_unit function This user-friendly GUI features text fields where users can input parameters, such as acceleration measured in yards per minute squared Additionally, hovering the mouse near the text fields reveals a tooltip displaying the registered unit for each parameter, enhancing usability.
Fig 1.1 Web GUI where parameters can be specified with units.
Readers can effectively utilize the PhysicalQuantity object and the Parampool package in their programs to ensure safe handling of units In the following sections, we will focus on the craft of scaling using standard SI units, eliminating the need for unit conversion and the use of PhysicalQuantity and Parampool.
15 You need to have Flask and additional packages installed This is easy to do with a few pip install commands, see [5] or [6].
NonCommercial 2.5 License (http://creativecommons.org/licenses/by-nc/2.5/), which permits any noncommercial use, distribution, and reproduction in any medium, provided the original author(s) and source are credited
This book contains images and third-party materials that are covered by a Creative Commons license, unless specified otherwise in the credit line If any material is not included under this license and cannot be used according to legal regulations, users must seek permission from the license holder to duplicate, adapt, or reproduce the content.
Open Access This chapter is distributed under the terms of the Creative Commons Attribution-
This chapter explores fundamental scaling techniques and reasoning methods related to scales It begins with exponential decay models, focusing on the ordinary differential equation (ODE) for exponential decay processes, expressed as u = -au, where a is a positive constant The discussion then advances to various generalizations of this ODE, encompassing nonlinear versions and systems of equations.
Second-order ordinary differential equations (ODEs) are crucial for modeling oscillatory systems, exemplified by the fundamental equation mu + ku = 0, where m and k are positive constants This article explores various extensions of this equation, incorporating damping and external force terms for a comprehensive understanding of dynamic behavior in these systems.
Exponential decay problems
Fundamental ideas of scaling
Scaling is an extremely useful technique in mathematical modeling and nu- merical simulation The purpose of the technique is three-fold:
1 Make independent and dependent variables dimensionless.
2 Make the size of independent and dependent variables about unity.
3 Reduce the number of independent physical parameters in the model.
To create a dimensionless variable ¯q from any variable q, we define it as ¯q = (q - q0) / qc, where q0 represents a reference value (commonly set to 0) and qc is a characteristic size of |q|, known as a "scale." This formulation ensures that ¯q is dimensionless, as both the numerator and denominator share the same dimension.
Ifq c is the maximum value of|q−q 0 |, we see that 00 are prescribed parameters, andu(t) is the unknown function.
For the particular model with a constant a, we can easily derive the exact solution, u(t) =Ie −at , which is helpful to have in mind during the scaling process.
Population dynamics refers to the changes in the number of individuals in a population, such as humans, animals, or cells, when resources are abundant This evolution can be mathematically represented by a specific model In this context, "N" denotes the population size, which is ideally an integer but can be approximated as a real number in large populations Additionally, the parameter "a" represents the rate of increase in population size per individual over time.
The decay of pressure with altitude is described by a simple model, which applies under certain assumptions, such as treating air as an ideal gas in equilibrium In this model, pressure is measured in Newtons per square meter (Nm−2), height is measured in meters, and the variable 'a' is defined as M/(R ∗ T), where M represents the molar mass of the gas, R is the gas constant, and T is the temperature.
Earth’s air (0.029 kg/mol),R ∗ is the universal gas constant (8.314 Nm mol K), and T is the temperature in Kelvin (K) The temperature depends on the height so we havea=a(t).
The technical steps of the scaling procedure
Step 1: Identify independent and dependent variables There is one independent variable,t, and one dependent variable,u.
Step 2: Make independent and dependent variables dimensionless.
We present a new dimensionless variable, denoted as ¯t, defined by the equation ¯t = t/t c, where t c represents a characteristic value of time In addition, we introduce another dimensionless variable, ¯u, defined as ¯u = u/u c, with u c being a constant characteristic size of u This framework allows for specific interpretations of u; for instance, if (2.1) models pressure in an atmospheric layer, u c would signify the characteristic pressure In the context of a decaying population, u c could represent a characteristic number of members, such as the initial population, I.
Step 3: Derive the model involving only dimensionless variables.
The next step involves integrating the new dimensionless variables into the governing mathematical model by substituting \( t \) with \( \bar{t} \) and \( u \) with \( \bar{u} \) in equation (2.1) The derivative with respect to \( \bar{t} \) is calculated using the chain rule, resulting in \( \frac{du}{dt} = \frac{d(\bar{u}c)}{d\bar{t}} \frac{d\bar{t}}{dt} = c \frac{d\bar{u}}{d\bar{t}} \).
The model (2.1) now becomes u c t c d¯u d¯t =−au c u,¯ u c u(0) =¯ I (2.4)
Step 4: Make each term dimensionless Equation (2.4) still has terms with dimensions To make each term dimensionless, we usually divide by the coefficient in front of the term with the highest time derivative (but dividing by any coefficient in any term will do) The result is d¯u d¯t =−at c u,¯ ¯u(0) =u −1 c I (2.5)
Step 5: Estimate the scales A characteristic quantity liket c reflects the time scale in the problem Estimating such a time scale is certainly the most challenging part of the scaling procedure There are different ways to reason. The first approach is to aim at a size of ¯uand its derivatives that is of order unity If u c is chosen such that |u¯| is of size unity, we see from (2.5) that d¯u/dt¯is of the size of ¯u(i.e., unity) if we chooset c = 1/a.
In certain cases, we can leverage analytical insights to inform our choice of scales, particularly when we have access to an exact solution for the input data For exponential decay, represented as u(t) ∼ e^(-at), the characteristic time scale, t_c, is defined as the time required for the initial value of u to decrease by a factor of 1/e, also known as the e-folding time This relationship can be expressed mathematically as e^(-at_c) = e^(-1), leading to the conclusion that t_c = 1/a While having an exact solution is not a necessity for determining scales, it can be a valuable resource in the limited instances where such solutions are available.
In this example, two common reasoning methods yield the same characteristic time, t c Instead of the e-folding time, we can utilize the half-time of exponential decay as an alternative measure of the time scale in these processes The half-time is defined as the duration required for a quantity to reduce to half its initial value, represented mathematically by the equation e −at c = 1.
In the analysis of the factor ln 2 = 0.69, it is noted that as long as this factor does not differ significantly from other critical values, it can be disregarded for the sake of simplifying formulas By utilizing the time scale t c = a −1 ln 2, a scaled differential equation u = −(ln 2)u is derived, although it is less conventional The simpler ordinary differential equation (ODE) u = −u, which emerges from the time scale t c = 1/a, is preferred for clarity Additionally, by setting the initial condition u c = I, we achieve ¯u(0) = 1, and for t > 0, the differential equation indicates that u decreases, allowing u c = I to keep ¯u within the range (0, 1] The ultimate goal of scaling the variable q to maintain |¯q| within [0, 1] is successfully accomplished, ensuring that the magnitude of |q| remains manageable.
In this context, "small" refers to a size that is moderate, falling between the extremes of 10 or 100 and 0.1 or 0.01 With the exact solution u(t) = Ie^(-at) available, we can observe that u lies within the range (0, I], indicating that when u equals I, the average value ¯u is within the interval (0, 1].
Witht c = 1/aandu c =I, we have the final dimensionless model d¯u d¯t =−u,¯ ¯u(0) = 1 (2.6)
This achievement is significant because it eliminates the need for physical parameters (a and I) in the model, allowing for a streamlined approach Unlike the original model (2.1), which requires experiments with varying a and I values for numerical investigations, the modified model (2.6) can be analyzed with a single computation Once the curve ¯u(¯t) is obtained, the solution u(t) for the original model can be derived using the equation u(t) = u c u(t/t¯ c ) = Iu(at)¯.
This particular transformation actually means stretching the ¯tand ¯uaxes in a plot of ¯u(¯t) by the factorsaandI, respectively.
It is very common to drop the bars when the scaled problem has been derived and work further with (2.6) simply written as du dt =−u, u(0) = 1.
Nevertheless, in this booklet we have decided to stick to bars for all dimen- sionless quantities.
Making software for utilizing the scaled model
Software designed to solve equation (2.1) can optimize its performance by utilizing a single simulation of equation (2.6) Once the scaled solution ¯u(¯t) is obtained, the actual output u(t) can be quickly calculated for any input data a and I using a straightforward scaling method (2.7) While computing u(t) directly from (2.1) is relatively fast in this basic model, employing (2.7) significantly enhances computational speed Overall, rescaling a solution is far more efficient than addressing a differential equation problem directly.
We can approach the computation of the dimensionless model (2.6) in two ways: by developing a new solver specifically for (2.6) or by adapting an existing solver for (2.1) with parameters I=1 and a=1 We opt for the latter method, as it allows us to utilize software that is compatible with both dimensionless and dimensional models.
(and all the original physical parameters).
Software for the original unscaled problem Assume that we have some moduledecay.pythat offers the following functions:
• solver(I, a, T, dt, theta=0.5) for returning the solution arrays u andt, over a time interval [0, T], for (2.1) solved by the so-calledθ rule.
This rule includes the Forward Euler scheme (θ= 0), the Backward Euler scheme (θ= 1), or the Crank-Nicolson (centered midpoint) scheme (θ= 1 2 ).
• read_command_line_argparse()for reading parameters in the problem from the command line and returning them:I,a,T,theta (θ), and a list
The basic statements for solving (2.1) are then
The moduledecay.pyis developed and explained in Section 5.1.7 in [3].
To solve the dimensionless problem, just fixI= 1 anda= 1, and choose
The initial two variables returned from read_command_line_argparse are I and a, which are intentionally ignored by using a dummy name, typically represented by an underscore in Python While users have the option to set –I and –a via the command line due to the decay module's functionality, the provided code serves as a reminder that these options are not intended for use Additionally, it's important to note that T and dt_values[0] specified on the command line are the key parameters for addressing the scaled problem.
To address the scaled problem, we will reuse the solver function initially designed for the unscaled problem, executing it only when essential Our code will first verify if a solution can be derived by scaling an existing solution stored in a file If a suitable solution isn't available, we will compute a new scaled solution, determine the corresponding unscaled solution for the user, and save this new scaled solution for potential future use.
The file `filedecay_scaled_v1.py` offers a straightforward solution to the issue at hand The `np.savetxt` function allows for saving a two-dimensional array, or "table," to a text file, while the `np.loadtxt` function facilitates loading this data back into the program However, an improved approach is available through the use of the `joblib` package, which will be discussed next.
Joblib is a Python package that simplifies the implementation of the solver_scaled function by providing a memoization feature When a function is executed for the first time with specific arguments, its output is saved to a file If the function is called again with the same arguments, the output is retrieved from the file instead of re-executing the function, allowing for efficient reuse of results This capability is particularly useful for optimizing performance in computational tasks.
I, a, T, theta, dt_values = read_command_line_argparse() u, t = solver(I, a, T, dt_values[0], theta) from matplotlib.pyplot import plot, show plot(t, u) show()
_, _, T, theta, dt_values = read_command_line_argparse() u, t = solver(I=1, a=1, T=T, dt=dt_values[0], theta=theta) large-scale computations with arrays that one would hesitate to recompute.
We illustrate the technique here in a very simple mathematical context.
First we make asolver_scaled function for the scaled model that just calls up asolver_unscaled(withI=a= 1) for the problem with dimensions:
Then we create some “computer memory on disk”, i.e., some disk space to store the result of a call to thesolver_scaledfunction Thereafter, we rede-
fine the namesolver_scaled to a new function, created byjoblib, which calls our original solver_scaled function if necessary and otherwise loads data from file:
The solutions are actually stored in files in the cache directorytemp.
A common scenario involves reading input values from the command line, addressing the scaled problem if needed, then unscaling the solution and visualizing it with dimensions This process utilizes the `solver` from the `decay` module, along with `numpy` for numerical operations and `matplotlib.pyplot` for visualization The function `solver_scaled(T, dt, theta)` is designed to handle these tasks effectively.
Solve u’=-u, u(0)=1 for (0,T] with step dt and theta method.
To compute the numerical solution, invoke the `solver_unscaled` function with parameters I=1, a=1, T=T, dt=dt, and theta=theta Utilize joblib to manage disk memory for caching the `solver_scaled` function The `unscale` function converts scaled values back to their original units by multiplying `u_scaled` by I and `t_scaled` by a Additionally, import the `read_command_line_argparse` function from the decay module for command-line argument handling in the main function.
# Read unscaled parameters, solve and plot
I, a, T, theta, dt_values = read_command_line_argparse() dt = dt_values[0] # use only the first dt value
In this article, we present a method for scaling time and velocity in a computational model, defined by the equations T_bar = a*T and dt_bar = a*dt The scaled values are computed using the solver_scaled function, which takes T_bar, dt_bar, and theta as inputs, resulting in u_scaled and t_scaled We visualize the scaled results by plotting u_scaled against t_scaled, labeling the axes as 'scaled time' and 'scaled velocity', and titling the graph 'Universal Solution of Scaled Problem' The figures are saved in both PNG and PDF formats Additionally, we create another plot that displays the original velocity u against the original time t.
The complete code can be found in the file decay_scaled.py The function read_command_line_argparse is designed to read parameters with specific dimensions, although we primarily address the scaled problem and unscale the solution when necessary.
Terminal> python decay_scaled.py I 8 a 0.1 dt 0.01 T 50
A plot of the scaled and unscaled solution appears in Figure 2.1.
Fig 2.1 Scaled (left) and unscaled (right) exponential decay.
The numerical solution is computed within the solver_scaled function, allowing for easy identification of when the solution is generated from scratch versus when it is retrieved from a file, followed by the unscaling process.
Terminal> python decay_scaled.py T 7 a 1 I 0.5 dt 0.2
[Memory] Calling main home-hpl solver_scaled-alias(7.0, 0.2, 0.5)
Terminal> # No change of T, dt, theta - can reuse solution in file Terminal> python decay_scaled.py T 7 a 4 I 2.5 dt 0.2
Terminal> # Change of dt, must recompute
Terminal> python decay_scaled.py T 7 a 4 I 2.0 dt 0.5
[Memory] Calling main home-hpl solver_scaled-alias(7.0, 0.5, 0.5)
Terminal> # Change of dt again, but dt=0.2 is already in a file
Terminal> python decay_scaled.py T 7 a 0.5 I 1 dt 0.2
Joblib optimizes performance by accessing all previous runs and avoids unnecessary recomputation, unlike our earlier implementation in indecay_scaled_v1.py, which relied on a single file for a single numerical case and resulted in a higher frequency of calls to solver_unscaled.
On the implementation of a simple memoize function
A memoized function enhances performance by storing previously computed results for specific arguments, effectively caching its outputs This implementation involves saving the function's arguments and their corresponding results in a dictionary, allowing for quick retrieval of results when the same arguments are encountered again.
The memoize functionality injoblib.Memoryis more sophisticated and can work very efficiently with large array data structures as arguments.
Note that the simple version above can only be used when all arguments to the function f are immutable (since the key in a dictionary has to be immutable).
Scaling a generalized problem
Now we consider an extension of the exponential decay ODE to the form u (t) =−au(t) +b, u(0) =I (2.8)
One particular model, with constant aand b, is a spherical small-sized or- ganism falling in air, u =−3πdμ b V u+g b −1
In the given model, the physical parameters include d, μ, b, V, and g, while the function u(t) denotes the vertical velocity, which is defined as positive in the upward direction This model will be utilized in subsequent analyses Additionally, the Memoize class is introduced to optimize function calls by storing results in a dictionary, allowing for efficient retrieval of previously computed values based on their arguments.
# Wrap my_compute_function(arg1, arg2, ) my_compute_function = Memoize(my_compute_function)
Exact solution It can be handy to have the exact solution for reference, in case of constantaandb: u e (t) =e −at a b(e at −1) +aI
Solving differential equations in SymPy
Using a symbolic computation tool like SymPy can greatly assist in solving differential equations In this demonstration, we will show how to utilize SymPy to find solutions by first defining the parameters of the problem as symbols and representing the function as u(t).
To define a differential equation, it can be expressed either as a symbolic expression set to equal zero or in the form of an equation Eq(lhs, rhs), where lhs and rhs represent the left-hand side and right-hand side expressions, respectively.
The differential equation can be solved by thedsolvefunction, yielding an equation of the form u(t) == expression We want to grab the expression on the right-hand side as our solution:
The solution contains the unknown integration constantC1, which must be determined by the initial condition We form the equation arising from the initial conditionu(0) =I:
The one solution that was found (stored in a list!) must then be sub- stituted back in the expressionuto yield the final solution:
>>> t, a, b, I = symbols(’t a b I’, real=True, positive=True)
>>> eq = Eq(u.subs(t, 0), I) # substitute t by 0 in u
In symbolic computing, similar to simplifying expressions in mathematics with pen and paper, we often use trial and error with SymPy's simplification functions A common initial approach involves expanding all elements and then applying simplification algorithms to achieve clearer results.
Doinglatex(u)automatically converts the expression to L A TEX syntax for inclusion in reports.
While SymPy can provide exact solutions for specific differential equations, understanding the scaling of these equations is crucial for tackling more complex scenarios In general problems, SymPy may only yield solutions for particular cases, but these solutions can guide our reasoning and analysis of scales in broader contexts.
Theory The challenges in our scaling is to find the right u c andt c scales.
From (2.8) we see that if u →0 as t→ ∞,uapproaches the constant value b/a It can be convenient to let the scaled ¯u→1 as we approach thed¯u/d¯t= 0 state This idea points to choosing u c =b a=g b −1
On the sign of the scaled velocity
In the analysis of buoyancy and gravity forces, when the buoyancy coefficient \( b < 0 \), the upward buoyancy force surpasses the downward gravitational force, causing the body to ascend with a positive terminal velocity \( u_c > 0 \) Conversely, when \( b > 0 \), the body experiences downward motion, resulting in a negative terminal velocity \( u_c < 0 \), while the scaled velocity \( u/u_c \) remains positive.
Insertingu=u c u¯=bu/a¯ and t=t c ¯tin (2.8) leads to d¯u dt¯=−t c a¯u+ t c u c b, u(0) =¯ Ia b.
To achieve a balance between the scaled variables \( \bar{u} \) and \( \frac{d\bar{u}}{dt} \), we set \( t_c = \frac{1}{a} \), leading to the scaled ordinary differential equation (ODE) \( \frac{d\bar{u}}{dt} = -\bar{u} + 1 \) with the initial condition \( \bar{u}(0) = \beta \) Here, \( \beta \) is a dimensionless parameter defined as \( \beta = \frac{I u}{c} = \frac{I a}{b} \), representing the ratio of the initial velocity to the terminal velocity as \( t \) approaches infinity Scaled equations typically yield dimensionless parameters like \( \beta \), which encapsulate the ratios of physical effects within the model The analytical solution for the scaled model is given by \( \bar{u}_e(t) = e^{-t} (e^t - 1) + \beta \).
The result (2.11) with the solution (2.13) is actually astonishing ifaand bare as in (2.9): the six parametersd,μ, b , ,V, andgare conjured to one: β=I3πdμ b V
To explore how the variable u varies with the physical input parameters in the model, we can simplify the problem significantly If the motion begins from rest (β = 0) and there are no physical parameters in the scaled model, a single simulation can be conducted to represent all physical cases through an unscaling process After computing ¯u(¯t) from the equation, we can revert to the original problem using the scaling formula u(t) = b * a * u(at) Notably, equation (2.11) can be solved by applying a solver for equation (2.8) with parameters set as a = 1, b = 1, and I = β By implementing a solver for (2.8), such as solver(I, a, b, T, dt, theta), the scaled model can be executed using solver(β, 1, 1, T, dt, theta).
In our software development, we are creating a solver for the scaled problem that utilizes joblib to cache solutions based on consistent parameters such as β, Δt, and T, while currently fixing θ at 0.5 The module decay_vc.py, detailed in Section 3.1.3 of [3], features a function named solver(I, a, b, T, dt, theta) designed to solve the equation u(t) = -a(t)u(t) + b(t) for t within the specified range.
(0, T], u(0) =I, with time step dt We reuse this function and call it with a=b= 1 andI=β to solve the scaled problem:
If we want to plot the physical solution, we need anunscalefunction,
In the study of water droplets in the air, we can manipulate certain parameters while focusing on the size parameter, d, for experimentation The function defined in the decay_vc module sets the physical parameters, calculates beta, and utilizes a solver to address the scaled problem, with joblib determining the necessity of this process Ultimately, the function generates and displays both the scaled curve ¯u(¯t) and the unscaled curve u(t).
Solve u’=-u+1, u(0)ta for (0,T] with step dt and theta method.
""" print ’Computing the numerical solution’ return solver_unscaled(
The article discusses a computational method for scaling and unscaling variables in a physical model, utilizing the joblib library for caching results to enhance performance It defines the functions 'unscale' and 'ab' to convert scaled variables back to their original values, incorporating parameters such as diameter, viscosity, and densities The gravitational constant is also considered in the calculations The main function sets a time step for the scaled problem, ensuring efficient processing of data in simulations.
T=7.5, # Final time, scaled problem d=0.001, # Diameter (unscaled problem)
# Set parameters, solve and plot rho = 0.00129E+3 # air rho_b = 1E+3 # density of water mu = 0.001 # viscosity of water
# Asumme we have list or similar for d if not isinstance(d, (list,tuple,np.ndarray)): d = [d] legends1 = [] legends2 = [] plt.figure(1) plt.figure(2) betas = [] # beta values already computed (for plot)
The most complex aspect of the code pertains to plotting; however, this section can be overlooked when focusing on how we utilize a scaled model for computations The entire program is available in the file falling_body.py.
SinceI= 0 impliesβ= 0, we can run differentdvalues without any need to recompute ¯u(¯t) as long as we assume the particle starts from rest.
The scaling analysis reveals that the critical velocity, \( u_c \), is proportional to \( b/a \sim d^{-2} \), and the critical time, \( t_c \), is inversely related to \( a \sim d^{-2} \) Consequently, when plotting \( u(t) \) across various values of \( d \), significant variations in both time and velocity scales are observed For instance, Figure 2.2 illustrates this with \( d \) values of 1, 2, and 3 mm, clearly showcasing the distinct time and velocity scales using unscaled variables It is important to note that the scaled velocity remains positive due to the sign of \( u_c \).
Fig 2.2 Velocity of falling body: scaled (left) and with dimensions (right). for d_ in d:
V = 4*pi/3*(d_/2.)**3 # volume a, b = ab(d_, mu, rho, rho_b, V) beta = I*a/b
# Restrict to 3 digits in beta beta = abs(round(beta, 3)) print ’beta=%.3f’ % beta u_scaled, t_scaled = solver_scaled(beta, T, dt)
To avoid plotting curves with the same beta value, ensure that beta is included in the betas list Begin by creating the first figure and plotting the scaled time against the scaled velocity, while holding the plot to add more data Append the beta value to the legends list for reference Next, create a second figure where you unscale the velocity and time using the specified parameters, and plot these values Again, hold the plot to allow for additional data representation and append the diameter information to the legends list Finally, label the axes of the first figure with 'scaled time' and 'scaled velocity', and include a legend at the lower right location.
Variable coefficients
When dealing with a time-varying coefficient a(t) in the equation u(t) = -a(t)u(t), it is common to perform a scaling transformation defined as ¯a(¯t) = a(t) - a₀/aₖ The objective of this scaling is to normalize ¯a to a size of unity, ensuring that |¯a| ≤ 1 To achieve this, aₖ is selected as the maximum value of |a(t) - a₀| over the interval t ∈ [0, T], which can typically be estimated since a(t) is a known function of time It is often practical to set a₀ to 0; however, choosing a₀ as the minimum value of a(t) could lead to a situation where ¯a equals 0 at some point, causing the differential equation to reduce to u = 0.
In a decaying cell culture, altering the environment at time t1—specifically the nutrition—can lead to a fivefold increase in the death rate of the cells This change can be expressed mathematically as a(t) = d for t < t1 and a(t) = 5d for t ≥ t1 The resulting model can be represented by the equation u = -a(t)u, with the initial condition u(0) = I.
Thea(t) function is scaled by letting the characteristic size bea c =dand a 0 = 0: ¯ a(¯t) 1,¯t < t 1 /t c
The natural choice of u c is I The characteristic time, previously taken as t c = 1/a, can now be chosen ast c =t 1 or t c = 1/d Witht c = 1/dwe get ¯ u (¯t) =−¯a¯u, u(0) = 1,¯ ¯a 1,¯t < γ
5,¯t≥γ (2.15) where γ=t 1 d is a dimensionless number in the problem Witht c =t 1 , we get ¯ u (¯t) =−γ¯a¯u, u(0) = 1,¯ ¯a 1,¯t >> t, k, T_m, a, w = symbols(’t k T_m a w’, real=True, positive=True)
The α quantity represents the ratio of temperature oscillation amplitudes to the distance from the initial temperature to the average temperature over extended periods In contrast, the β number compares two time scales: the oscillation frequency in T s and the inverse e-folding time of heat transfer For a clearer understanding of β, we define the period P as 2π/ω of the oscillations in T s and the e-folding time e as 1/k Consequently, β can be expressed as β = 2πe/P, indicating the relationship between the e-folding time and the oscillation period.
The original problem features five physical parameters: k, T 0 , T m , a, andω, but only two dimensionless numbers appear in the scaled model
(2.23) In fact, this is an example where application of the Pi theorem
The analysis in Section 1.1.3 reveals a limitation, as it only considers time and temperature as unit types Consequently, the theorem indicates that five parameters should yield three dimensionless numbers instead of two In contrast, scaling the differential equations demonstrates the significance of the two parameters, T and m, in the overall framework.
T 0 affect the nature of the problem only through their difference.
The implementations of the unscaled problem can be effectively reused for the scaled model by adjusting parameters: set k=1, T0=0, and Ts(t)=1+αsin(β¯t) with Tm=1, a=α, and ω=β The file osc_cooling.py includes solvers for both the unscaled and scaled problems The accompanying figure illustrates three scenarios based on varying β values: small, medium, and large.
In scenarios with a small β value, the heating and cooling processes closely align with gradual changes in surrounding temperature, resulting in minimal time lag Conversely, larger β values lead to prolonged heating and cooling durations, causing a reduction in temperature oscillations.
In analyzing the time scale relevant to heat transfer and temperature variations, we identify two critical time parameters: the decay rate of heat transfer to the surroundings, represented by k, and the oscillation frequency of the surroundings, denoted by ω The decay factor, expressed as e^(-kt), indicates that the temperature decay occurs over a time scale of t_c = 1/k, while the surrounding temperature oscillations vary with a time scale of t_c = 1/ω The challenge lies in determining which time scale is more significant for the problem at hand.
To analyze the temperature transition from T0 to the surrounding temperature Ts, we observe that it follows an exponential decay represented by e^(-kt), where tc = 1/k is the characteristic time After this initial phase, the temperature fluctuations are primarily influenced by oscillations, with sin(ωt) and cos(ωt) becoming the dominant terms For longer time periods, the appropriate time scale is tc = 1/ω, leading to the equation dT/dt = -β^(-1)(T - (1 + αsin(t))), with the initial condition T(0) = 0 Alternatively, we can consider a less effective scaling approach, where the characteristic temperature T0 - Ts incorporates a time-dependent term Ts(t), resulting in more complex mathematical expressions.
T(t) =T 0 + (T s (t)−T 0 ) ¯T , dT dt =dT s dt T¯+ (T s −T 0 )dT¯ d¯t d¯t dt.
With ¯t=t/t c =ktwe get from the differential equation dT s dt T¯+ (T s −T 0)dT¯ dt¯k=−k( ¯T−1)(T s −T 0), which after dividing byk(T s −T 0 ) results in dT¯ dt¯ =−( ¯T−1)−dT s dt
The equation describes the relationship between temperature changes over time, represented as dT¯/d¯t = −(¯T − 1) − αβ cos(β¯t) By factoring out dimensionless numbers, specifically scaling T s by T m, the last term simplifies, allowing for a clearer understanding of the dynamics involved This approach highlights the significance of the parameters in the equation, facilitating a more tractable analysis of temperature variations.
1 +αsin(β¯t)−γT ,¯ (2.25) whereα,β, andγ are dimensionless numbers characterizing the relative im- portance of parameters in the problem: α=a/T m , β=ω/k, γ=T 0 /T m (2.26)
We notice that (2.25) is not a special case of the original problem (2.16).
The original five parameters, k, T m, a, ω, and T 0, can be simplified to three dimensionless parameters; however, this scaling approach is deemed less effective By utilizing the temperature scale T 0 − T m, the software can be repurposed for the unscaled problem, resulting in a model that only requires two dimensionless parameters.
Scaling a nonlinear ODE
Exponential growth models, represented by the equation u = au, fail to accurately reflect scenarios with limited resources To address this limitation, we can modify the model by allowing the parameter 'a' to depend on 'u', resulting in a more realistic differential equation: u = a(u)u, with the initial condition u(0) = I This approach effectively captures the impact of resource constraints on growth dynamics.
The maximum value of u, represented as M, leads to the condition a(M) = 0 A straightforward function that meets this criterion is a(u) = (1−u/M) This parameter can be understood as the initial exponential growth rate under certain assumptions.
I/M1, since att= 0 the model then approximatesu =u.
The choicea(u) = (1−u/M) is known as the logistic model for population growth: u =u(1−u/M), u(0) =I (2.28)
A more complicated choice ofamay bea(u) = (1−u/M) p for some exponent p(this function also fulfillsa(M) = 0 anda≈fort= 0).
Scaling Let us scale (2.27) with a(u) = (1−u/M) p The natural scale for u is M (u c =M), since we know that 0< u≤M, and this makes the dimensionless ¯u=u/M∈(0,1] The functiona(u) is typically varying between
0 and , so it can be scaled as ¯ a(¯u) =a(u)
Time is scaled as ¯t=t/t c for some suitable characteristic timet c Inserted in (2.27), we get u c t c d¯u d¯t = ¯au c u,¯ u c u(0) =¯ I, resulting in d¯u d¯t =t c (1−u)¯ p u,¯ u(0) =¯ I
In exponential growth models, a natural choice for the time constant is \( t_c = 1 \), as this results in both sides of the equation being approximately equal to unity This choice ensures that the scaling is accurate, with \( \bar{u} \) and its derivatives maintaining an order of unity, necessitating that the coefficients also align with this order Additionally, the introduction of the dimensionless parameter \( \alpha = I \) further refines the model.
M, measuring the fraction of the initial population compared to the maximum one, we get the dimensionless model d¯u d¯t = (1−u)¯ p u,¯ u(0) =¯ α (2.29) Here, we have two dimensionless parameters: α and p A classical logistic model withp= 1 has only one dimensionless variable.
Alternative scaling We could try another scaling ofuwhere we also trans- late ¯u: ¯ u=u−I
This choice of ¯uresults in d¯u dt¯= (1ưαưu)¯ p u,¯ u(0) = 0¯ (2.30)
The key distinction between the two models lies in the ranges of ¯u, with ¯u∈[α,1] for model (2.29) and ¯u∈[0,1−α] for model (2.30) Both models incorporate the dimensionless parameters α and p A notable benefit of model (2.29) is its compatibility with existing software designed for the unscaled model, which can be adapted for the scaled model by selecting I=α and M=1.
SIR ODE system for spreading of diseases
The field of epidemiology frequently applies ODE systems to describe the spreading of diseases, such as smallpox, measles, plague, ordinary flu, swine
flu, and HIV Different models include different effects, which are reflected in dimensionless numbers Most of the effects are modeled as exponential decay or growth of the dependent variables.
The basic model categorizes individuals into three groups: susceptibles (S), who are at risk of contracting the disease; infectious (I), who are currently infected and capable of spreading the infection; and recovered (R), who have overcome the disease and developed immunity.
We introduce S(t),I(t), andR(t) as the number of people in the categories
S, I, and R, respectively The model, naturally known as the SIR model 1 , can be expressed as a system of three ODEs: dS dt =−βSI, (2.31) dI dt =βSI−νI, (2.32) dR dt =νI, (2.33) whereβandν are empirical constants The average time for recovering from the disease can be shown to be ν −1 , but β is much harder to estimate, so working with a scaled model whereβ is “scaled away” is advantageous.
Scaling It is natural to scaleS,I, andRby, e.g., S(0):
Introducing ¯t=t/t c , we arrive at the equations dS¯ d¯t =−t c S(0)βS¯I,¯ dI¯ d¯t =t c S(0)βS¯I¯−t c νI,¯ dR¯ d¯t =t c νI,¯ with initial conditions ¯S(0) = 1, ¯I(0) =I 0 /S(0) =α, and ¯R(0) =R(0)/S(0).
In this study, we define a time unit as the duration needed for recovery from the disease, leading to a scaled model represented by the equations dS¯/dt¯ = -R₀S¯I¯, dI¯/dt¯ = R₀S¯I¯ - I¯, and dR¯/dt¯ = I¯ The initial conditions are set with ¯S(0) = 1, ¯I(0) = α, and ¯R(0) = 0, where R₀ is the dimensionless number.
The basic reproduction number, R₀, is a crucial dimensionless quantity that indicates a disease's potential to spread It is defined as R₀ > 1, which implies that the initial number of susceptible individuals, S(0) = 1, must be greater than zero for the disease to propagate (dI/dt > 0) Essentially, R₀ represents the average number of new infections generated by a single infectious individual during the disease's infectious period.
Looking at (2.32), we see that to increaseIinitially, we must havedI/dt >0 att= 0, which impliesβI(0)S(0)−νI(0)>0, i.e.,R 0 >1.
Software Any implementation of the SIR model with dimensions can be reused for the scaled model by setting β =R 0 , ν= 1, S(0) = 1−α, and I(0) =α Below is a plot with two cases: R 0 = 2 and R 0 = 5, both with α= 0.02.
Alternative scaling Adding (2.31)-(2.33) shows that dS dt +dI dt +dR dt = 0 ⇒ S+I+R= const =N,
2 https://en.wikipedia.org/wiki/Basic_reproduction_number whereN is the size of the population We can therefore scaleS,I, andR by the total populationN=S(0) +I(0) +R(0):
With the same time scale, one gets the system (2.34)-(2.36), but with R 0 replaced by the dimensionless number:
The initial conditions become ¯S(0) = 1−α, ¯I(0) =α, and ¯R(0) = 0.
For the disease to spread att= 0, we must have ˜R 0 S(0)¯ >1, but ˜R 0 S(0) =¯
N β/νãS(0)/N=R 0 , so the criterion is stillR 0 >1 SinceR 0 is a more famous number than ˜R 0 , we can write the ODEs withR 0 /S(0) =R 0 /(1−α) instead of ˜R 0
Choosing t c to make the SI terms balance the time derivatives, t c (N β) −1 , moves ˜R 0 (orR 0 if we scaleS,I, andR byS(0)) to theI terms: dS¯ dt¯=−S¯I,¯ dI¯ d¯t = ¯SI¯−R˜ −1 0 I,¯ dR¯ d¯t = ˜R −1 0 I
SIRV model with finite immunity
An extension of the SIR model incorporates finite immunity, where recovered individuals eventually lose their immunity and revert to the susceptible category This transition is represented by a leakage term, μR, indicating the average time, μ−1, for immunity loss Additionally, vaccination is integrated into the model, with a fraction pS of the susceptible population being successfully vaccinated and moved to a new category, V, for vaccinated individuals The corresponding ordinary differential equations (ODEs) for this model are: dS/dt = −βSI − pS + μR, dI/dt = βSI − νI, dR/dt = νI − μR, and dV/dt = pS.
Using t c = 1/ν and scaling the unknowns byS(0), we arrive at the dimen- sionless model dS¯ d¯t =−R 0 S¯I¯−δS¯+γR,¯ (2.43) dI¯ dt¯=R 0 S¯I¯−I,¯ (2.44) dR¯ d¯t = ¯I−γR,¯ (2.45) dV¯ d¯t =δS,¯ (2.46) with two new dimensionless parameters: γ=μ ν, δ=p ν.
The quantity \( p^{-1} \) represents the average time required to successfully vaccinate a susceptible individual By defining \( \gamma = \nu^{-1} / \mu^{-1} \) and \( \delta = \nu^{-1} / p^{-1} \), we can understand \( \gamma \) as the ratio of the average recovery time to the average duration of immunity loss, while \( \delta \) indicates the ratio of the average recovery time to the average time needed for successful vaccination of a susceptible person.
In Figure 2.4, with a loss of immunity rate (γ) of 0.05, individuals lose immunity after 20 weeks post-recovery from the disease The left plot illustrates the scenario without vaccination, while the right plot depicts a vaccination campaign characterized by a vaccination efficacy (δ) of 0.5, implemented between days 7 and 15 This δ value indicates that it requires two weeks to effectively vaccinate a susceptible individual, yet the impact of the vaccination campaign remains significantly beneficial.
Michaelis-Menten kinetics for biochemical reactions
A classical reaction model in biochemistry describes how a substrate S is turned into a product P with aid of an enzyme E S and E react to form
Fig 2.4 Spreading of a disease with loss of immunity (left) and added vaccination
(right). a complex ES in the first stage of the reaction In the second stage, ES is turned into E and P Introducing the amount of S, E, ES, and P by [S], [E],
[ES], and [P], the mathematical model can be written as d[ES] dt =k + [E][S]−k v [ES]−k − [ES], (2.47) d[P] dt =k v [ES], (2.48) d[S] dt =−k +[E][S] +k − [ES], (2.49) d[E] dt =−k + [E][S] +k − [ES] +k v [ES] (2.50)
The initial conditions are [ES](0) = [P](0) = 0, and [S] =S 0 , [E] =E 0 Three rate constants are involved:k + ,k − , andk v The above mathematical model is known as Michaelis-Menten kinetics 3
The amount of substance is quantified in moles (mol), with rate constants k+ measured in s−1 mol−1, while k− and kv are expressed in s−1 To simplify calculations, it is beneficial to eliminate the mole unit, focusing instead on dimensionless quantities that rely solely on the ratios of the rate constants rather than their specific values.
Classical analysis A common assumption is that the formation of [ES] is very fast and that it quickly reaches an equilibrium state, [ES] = 0 Equation
(2.47) then reduces to the algebraic equation k + [E][S]−k v [ES]−k − [ES] = 0, which leads to
3 https://en.wikipedia.org/wiki/Michaelis-Menten_kinetics
[ES] =k − +k v k + =K, (2.51) whereKis the famous Michaelis constant - the equilibrium constant between [E][S] and [ES].
The ODE system reveals two key conservation equations derived from the addition of the ODEs: \( d[ES]/dt + d[E]/dt = 0 \) and \( d[ES]/dt + d[S]/dt + d[P]/dt = 0 \) These equations highlight the conservation principles inherent in the system.
We can use (2.54) and (2.51) to express [E] by [S]:
Now (2.49) can be developed to an equation involving [S] only: d[S] dt =−k + [E][S] +k − [ES]
We see that the parameterK is central.
From above expression for [E] and (2.54) it now follows
IfK is comparable toS 0 these indicate
K , as is used for scaling [E] andQ c , subsequently Provided we exclude the case
[S]K, we may infer that [E] will be of magnitudeE 0 , while [ES] will be of magnitudeE 0 S 0 /K.
Dimensionless ODE system Let us reason how to make the original ODE system (2.47)-(2.50) dimensionless Aiming at [S] and [E] of unit size, two obvious dimensionless unknowns are
For the other two unknowns we just introduce scales to be determined later:
With ¯t=t/t c the equations become dQ¯ d¯t =t c k + E 0 S 0
Choosing the appropriate scales is a complex task that necessitates thorough analysis of the equations to understand the solution characteristics While extensive literature exists on this topic, we will adopt a straightforward and practical approach In addition to the Michaelis constant (K), another crucial parameter must be considered.
S 0 , because most applications will involve a small We shall have K and in mind while choosing scales such that these symbols appear naturally in the scaled equations.
The K parameter is introduced in the equations when t_c is approximately equal to 1/k +, but since 1/k + lacks the required dimension of [T] −1, we must include a factor with a dimension of mol A suitable choice is t_c = k + S_0 or t_c = k + E_0 Typically, S_0 represents a short time scale while E_0 signifies a long time scale For analyses focused on the long time scale, we can simplify by setting t_c = 1.
The equations then take the form dQ¯ d¯t = S 0
The [ES] variable starts and ends at zero, and its maximum value can be roughly estimated from the equation for [ES] by setting [ES] = 0, which gives
K , where we have replaced [E][S] by E 0 S 0 as an identification of magnitude. This magnitude of [ES] at its maximum can be used as the characteristic sizeQ c :
The equation for ¯Psimplifies if we chooseP c =Q c With these assumptions one gets dQ¯ d¯t =KE 0 −1 ( ¯ES¯−Q),¯ dP¯ dt¯ = k v k + E 0 Q,¯ dS¯ d¯t =−E¯S¯+ k − k + E 0
We can now identify the dimensionless numbers α= K
E 0 , β= k v k + E 0 , γ= k − k + E 0 , where we see thatα=β+γ, so γcan be eliminated Moreover, α= k − k + E 0 +β, implying thatα > β.
We arrive at the final set of scaled differential equations: dQ¯ d¯t =α( ¯ES¯−Q),¯ (2.57) dP¯ d¯t =βQ,¯ (2.58) dS¯ d¯t =−E¯S¯+ (1−βα −1 ) ¯Q, (2.59) dE¯ d¯t =−E¯S¯+ ¯Q (2.60)
The initial conditions are ¯S= ¯E= 1 and ¯Q= ¯P= 0.
The five initial parameters (S 0 ,E 0 ,k + ,k − , andk v ) are reduced to three dimensionless constants:
• αis the dimensionless Michaelis constant, reflecting the ratio of the pro- duction of P and E (k v +k − ) versus the production of the complex (k + ), made dimensionless byE 0 ,
• is the initial fraction of enzyme relative to the substrate,
• βmeasures the relative importance of production of P (k v ) versus produc- tion of the complex (k + ), made dimensionless byE 0
Observe that software developed for solving (2.47)-(2.50) cannot be reused for solving (2.57)-(2.60) since the latter system has a slightly different structure.
Conservation equations The counterpart to the conservation equations
(2.54)-(2.55) is obtained by adding (2.57) and α times (2.60), and adding
In a simulation, it is essential to ensure that scaled quantities and original concentrations remain positive variables, while the parameters ¯E and ¯S must fall within the range of [0,1] These checks, along with the conservation of quantities, should be conducted at each time step to maintain accuracy and integrity in the simulation process.
In the analysis of the scaled system, we can simplify the equation by assuming small values, leading to E¯ = 0 and the relation ¯Q = ¯ES The conservation equation, represented as [ES] + [E] = ¯E0, can be expressed as Qc + Q¯ = 0.
E 0 E¯ =E 0 such that ¯E = 1−Q c Q/E¯ 0 = 1−QS¯ 0 /K = 1− −1 α −1 Q The¯ relation ¯Q= ¯ES¯ then becomes
Q¯= (1− −1 α −1 Q) ¯¯ S, which can be solved for ¯Q:
The equation (2.59) for ¯S becomes dS¯ d¯t =−βα −1 Q¯=− βS¯ α+ −1 S¯ (2.63)
This is a more precise analysis than the one leading to (2.56) since we now realize that the mathematical assumption for the simplification is→0.
Is (2.63) consistent with (2.56)? It is easy to make algebraic mistakes when deriving scaled equations, so it is always wise to carry out consistency checks. Introducing dimensions in (2.63) leads to t c
K+S, and hence witht −1 c =k + E 0 , dS dt =−k v E 0 S
Figure 2.5 illustrates the effects of a moderately small value (0.1), resulting in ¯Q≈0, which validates the previous simplifications The data shows that all unknown variables range between 0 and approximately 1, confirming the effectiveness of the chosen dimensionless numbers for scaling The simulations employed a time step of Δ¯t= 0.01 and utilized a 4th-order Runge-Kutta method with parameters α= 1.5 and β= 1, as outlined in the simulate_biochemical_process function within session.py.
Fig 2.5 Simulation of a biochemical process.
However, it is of interest to investigate the limit→0 Initially, the equa- tion fordE/d¯ ¯t reads dE/d¯ ¯t=− −1 , which implies a very fast reduction of
E Using¯ = 0.005 andΔ¯t= 10 −3 , simulation results show that ¯E decays to approximately zero att= 0.03 while ¯S≈1 and ¯Q≈P¯≈0 This is reasonable since with very little enzyme in comparison with the substrate (→0) very little will happen.