Giter VIP home page Giter VIP logo

laneemden's Introduction

Lane-Emden

All Contributors

Operating Systems License Pulls Top Language Version Commits Size

Lane-Emden is a simple C++ program that solves the Lane-Emden differential equation

Lane-Emden_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.

Table of contents

Requirements

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.

Installation

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.

Usage

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 of n 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)).

Options and output for euler and rungekutta

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:

i xi theta thetap g_csi f_csi h_csi alpha_csi
0 0.0001 1 0 1 -0 0 0
1 0.0011 1 -0.000175084 1 2.11852e-10 -0.477502 6.54207e+06
2 0.0021 0.999999 -0.000643578 1 2.83818e-09 -0.919396 1.15978e+06
3 0.0031 0.999998 -0.00100734 1 9.68052e-09 -0.974843 511844
4 0.0041 0.999997 -0.0013518 1 2.27237e-08 -0.989119 289790
... ... ... ... ... ... ... ...

Here we rememeber the definition of g_csi, f_csi, h_csi e alpha_csi:

g_csi f_csi
h_csi alpha_csi

Options for zero

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 than 1e-5, because the algorithm becomes more and more unstable for certain values of n when the numerical solution approaches to zero.

Options and output for zerosfunc

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 index n 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 than 1e-5, because the algorithm becomes more and more unstable for certain values of n 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:

i n xi_n theta_n thetap_n g_n f_n h_n alpha_n
2449 0 2.4491 0.000318203 -0.816367 1 4.89664 -1 0.
2454 0.01 2.4541 0.000631585 -0.807695 0.928976 4.86443 -0.987362 0.80179
2459 0.02 2.4591 0.000958193 -0.799185 0.87022 4.83281 -0.974972 0.797389
2465 0.03 2.4651 0.00050677 -0.790996 0.796424 4.80666 -0.962633 0.792508
2470 0.04 2.4701 0.000867039 -0.782751 0.754261 4.77587 -0.950671 0.788258
... ... ... ... ... ... ... ... ...

Here we rememeber the definition of g_n, f_n, h_n e alpha_n:

g_n f_n
h_n alpha_n

Visualization of the data

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 of n;
  • Lane-Emden-zerosfunc.ipynb, where the zeros for a subset of n values inside [0, 5) are plotted and analysed;
  • Lane-Emden_confronto_vari_esponenti.ipynb, where solutions for various n 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.

Mathematical treatment

The original equation can be rewrited in this simple system:

LE_system

So, with the basic treatment of the differential equation numerical solutions:

LE_system

License

Lane-Emden is free software, and it is released under version 3 of the GNU General Public License.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Matteo Zeccoli Marazzini

🤔 🔧

This project follows the all-contributors specification. Contributions of any kind welcome!

laneemden's People

Contributors

foglienimatteo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.