Lane-Emden is a simple C++ program that solves the Lane-Emden differential equation
for an arbitrary input value of the index n
with two possible algorithms: Euler and classic Runge-Kutta. The output file Lane-Emden_Eulero_n=<index>.dat
/Lane-Emden_RK_n=<index>.dat
contains also the values of the first derivate θ'(ξ)
, concentration parameter g_0
and f_0
.
This data may be easily visualize thanks to the Jupyter Notebook files:
Lane-Emden.ipynb
, which analyses deeply a given input dataset;Lane-Emden_confronti_vari_esponenti.ipynb
, which compares various datasets with different index values;Lane-Emden_confronto_Eulero-RK.ipynb
, which compares a dataset obtained with Euler algorithm with another obtained with Runge-Kutta one.
In order to build the software from the source code here provided, you will need:
cmake
(version >= 3.12);- A
C++17
compiler;
This project uses the header-only Argh!
library, which is already included in this repository in include/argh.h
;therefore, you do not need to install it on your system.
First of all, copy the source code provided in this repository on your OS. You may clone the repository where it is built in, running in the command line
git clone https://github.com/foglienimatteo/LaneEmden
or download the source code from the webpage https://github.com/foglienimatteo/LaneEmden.
Hereafter, run the following shell commands from the project directory:
mkdir build
cd build
cmake ..
make
The executable file Lane_Emden
is generated in the build
directory.
In order to execute the Lane_Emden
file (inside the build
directory), the syntax is the standar one:
./Lane_Emden {euler|rungekutta|zero|zerosfunc} [options]
euler
solve the differential equation with the Euler method;rungekutta
solve the differential equation with the classic Runge-Kutta method;zero
solve the differential equation with the classic Runge-Kutta method (not other methods avaiable for this command) and print to the standard output the resulting values ofξ
,θ'(ξ)
, ... in the zero of the numerical solution obtained; no output files are produced;zerosfunc
solve the differential equation with the classic Runge-Kutta method (not other methods avaiable for this command) and creates an output file with the resulting values ofξ
,θ'(ξ)
, ... in the zero of the numerical solution for a subset ofn
values inside[0,5)
.
You must specify the index n
of the Lane-Emden equation to be resolved (throughout the option -n <index>
or --index=<index>
) for the commands euler
-rungekutta
-zero
(because they operate on THAT SPECIFIC Lane-Emden equation), but not for zerosfunc
(because it operates on the interval n \in [0, 5)
).
The actual available options, for euler
and rungekutta
commands, are the following:
-h, --help
: print the help message;-n <index>, --index=<index>
REQUIRED: set the index of the Lane-Emden equation to be resolved;-s <step>, --step=<step>
: set the step measure to be used solving the differential equation;-b <begin>, --begin=<begin>
: set the beginning value ofξ
, where the algothims starts;-e <end>, --end=<end>
: set the ending value ofξ
, where the algorithm ends;
Depending on the algorithm choosen, the output file (saved in the build
directory) will be Lane-Emden_Eulero_n=<index>.dat
or Lane-Emden_RK_n=<index>.dat
.
For each of these files, the output data are organized in 8 columns; from left to right, they are:
- the iteration index of the algorithm
i=0,1,2,...
; - the corresponding
ξ
value; - the function value in that point, i.e.
θ(ξ)
; - the first function derivate in that point, i.e.
θ'(ξ)
; - the concentration parameter
g(ξ)
; - the parameter
f(ξ)
; - the parameter
h(ξ)
; - the parameter
α(ξ)
;
In a table form, the data are disposed like this:
Here we rememeber the definition of g_csi
, f_csi
, h_csi
e alpha_csi
:
The actual available options, for the zero
command, are the following:
-h, --help
: print the help message;-n <index>, --index=<index>
REQUIRED: set the index of the Lane-Emden equation to be resolved;-s <step>, --step=<step>
: set the step measure to be used solving the differential equation;-b <begin>, --begin=<begin>
: set the beginning value ofξ
, where the algothims starts;-e <end>, --end=<end>
: set the ending value ofξ
, where the algorithm ends;-m <min>, --min=<min>
: value of theta considered sufficiently close to zero (from up) where the algorithm must stop; it's better to set values not less than1e-5
, because the algorithm becomes more and more unstable for certain values ofn
when the numerical solution approaches to zero.
The actual available options, for the zerosfunc
command, are the following:
-h, --help
: print the help message;-s <step>, --step=<step>
: set the step measure to be used solving the differential equation;-b <begin>, --begin=<begin>
: set the beginning value ofξ
, where the algothims starts;-e <end>, --end=<end>
: set the ending value ofξ
, where the algorithm ends;-sn <index_step>, --index_step=<index_step>
: set the step which will be used to sample the indexn
of the Lane-Emden equation;-m <min>, --min=<min>
: value of theta considered sufficiently close to zero (from up) where the algorithm must stop; it's better to set values not less than1e-5
, because the algorithm becomes more and more unstable for certain values ofn
when the numerical solution approaches to zero.
The output file (saved in the build
directory) will be Lane-Emden_Eulero_zerosfunc.dat
.
The output data are organized in 9 columns; from left to right, they are:
- the iteration index of the algorithm
i
where the zero is placed; - the value of the index
n
; - the corresponding
ξ_n
value; - the function value in that point, i.e.
θ(ξ_n)
; - the first function derivate in that point, i.e.
θ'(ξ_n)
; - the concentration parameter
g_n = g(ξ_n)
; - the parameter
f_n = f(ξ_n)
; - the parameter
h_n = h(ξ_n)
; - the parameter
α_n = α(ξ_n)
;
In a table form, the data are disposed like this:
Here we rememeber the definition of g_n
, f_n
, h_n
e alpha_n
:
In the main directory, there are 4 JupyterLab Notebooks:
Lane-Emden.ipynb
, where the skeleton of the data plotting and analysis is provided, for an arbitrary value ofn
;Lane-Emden-zerosfunc.ipynb
, where the zeros for a subset ofn
values inside[0, 5)
are plotted and analysed;Lane-Emden_confronto_vari_esponenti.ipynb
, where solutions for variousn
values are compared;Lane-Emden_confronto_Eulero-RK.ipynb
, where are compared Euler and Runge-Kutta methods.
Unfortunately, the notous curl in the p_0/p_s
vs (R_0/R_s)^3
does not appear clearly, probably for a computational mistake somewhere in the source code.
The original equation can be rewrited in this simple system:
So, with the basic treatment of the differential equation numerical solutions:
Lane-Emden is free software, and it is released under version 3 of the GNU General Public License.
Thanks goes to these wonderful people (emoji key):
Matteo Zeccoli Marazzini 🤔 🔧 |
This project follows the all-contributors specification. Contributions of any kind welcome!