{"id":25854782,"url":"https://github.com/jchristopherson/integral","last_synced_at":"2026-03-05T19:04:35.427Z","repository":{"id":43750635,"uuid":"135277103","full_name":"jchristopherson/integral","owner":"jchristopherson","description":"The INTEGRAL library provides routines for the integration of functions of various types.  Additionally, the INTEGRAL library provides routines for the integration of systems of ordinary differential equations (ODEs).","archived":false,"fork":false,"pushed_at":"2023-04-25T17:57:26.000Z","size":2058,"stargazers_count":16,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-01-29T08:48:34.958Z","etag":null,"topics":["differential-equations","fortran","integration","odepack","ordinary-differential-equations","quadpack"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jchristopherson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-05-29T10:03:10.000Z","updated_at":"2023-10-30T06:33:11.000Z","dependencies_parsed_at":"2023-09-25T00:40:52.471Z","dependency_job_id":"7ea20943-ece7-4f29-96be-e79953d505c8","html_url":"https://github.com/jchristopherson/integral","commit_stats":{"total_commits":74,"total_committers":1,"mean_commits":74.0,"dds":0.0,"last_synced_commit":"0ac990026652bdea64e8ba03af1fb497780a7641"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Fintegral","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Fintegral/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Fintegral/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Fintegral/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jchristopherson","download_url":"https://codeload.github.com/jchristopherson/integral/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241389134,"owners_count":19955107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["differential-equations","fortran","integration","odepack","ordinary-differential-equations","quadpack"],"created_at":"2025-03-01T16:18:08.800Z","updated_at":"2026-03-05T19:04:30.378Z","avatar_url":"https://github.com/jchristopherson.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# integral\nThe INTEGRAL library provides routines for the integration of functions of various types.  Additionally, the INTEGRAL library provides routines for the integration of systems of ordinary differential equations (ODEs).\n\nThe integration routines are provided by [QUADPACK](http://www.netlib.org/quadpack/), and the ODE routines are provided by [ODEPACK](http://www.netlib.org/odepack/).\n\n## Status\n![Build Status](https://travis-ci.org/jchristopherson/integral.svg?branch=master)\n\n## Example 1\nThe following example illustrates the use of an adaptive integrator to compute the integral of an equation over a finite interval.\n```fortran\nprogram example\n    use iso_fortran_env\n    use integral_core\n    implicit none\n\n    ! Variables\n    real(real64) :: ans, y, pi, a, b\n    procedure(integrand), pointer :: fcn\n    type(adaptive_integrator) :: integrator\n\n    ! Define the integration limits\n    pi = 2.0d0 * acos(0.0d0)\n    a = pi / 6.0d0\n    b = pi / 4.0d0\n\n    ! Evaluate the integral\n    fcn =\u003e int_fcn\n    y = integrator%integrate(fcn, a, b)\n\n    ! Display the results\n    ans = 5.0d0 * pi / 12.0d0 - 2.0d0 * sqrt(2.0d0) + 4.0d0 / sqrt(3.0d0)\n    print '(AEN13.5AEN13.5A)', \"The solution is: \", ans, \u0026\n        \", the integrator computed: \", y, \".\"\n\ncontains\n    ! This example is from http://tutorial.math.lamar.edu/Classes/CalcI/ComputingDefiniteIntegrals.aspx#Int_CompDef_Ex3a\n    ! The integrand is: f(x) = 5 - 2 sec(x) tan(x).\n    ! If the integral is considered over the range [pi/6, pi/4], the solution\n    ! is 5 pi / 12 - 2 sqrt(2) + 4 / sqrt(3).\n    function int_fcn(x) result(f)\n        real(real64), intent(in) :: x\n        real(real64) :: f\n        f = 5.0d0 - 2.0d0 * tan(x) / cos(x) ! Remember, sec(x) = 1 / cos(x)\n    end function\nend program\n```\n```text\nThe solution is: 789.97089E-03, the integrator computed: 789.97089E-03.\n```\n## Example 2\nThe following example illustrates solution of the Van Der Pol equation comparing two different integrators, an implicit Runge-Kutta integrator (ODE_IRK) and an integrator that automatically switches between an Adams method and a BDF method (ODE_AUTO).\n```fortran\nprogram example\n    use iso_fortran_env\n    use integral_core\n    use fplot_core\n    implicit none\n\n    ! Local Variables\n    type(ode_helper) :: fcn\n    type(ode_irk) :: integrator1\n    type(ode_auto) :: integrator2\n    procedure(ode_fcn), pointer :: ptr\n    real(real64) :: ic(2), t(2)\n    real(real64), allocatable, dimension(:,:) :: x1, x2\n    type(plot_2d) :: plt\n    type(plot_data_2d) :: d1, d2\n    class(plot_axis), pointer :: xAxis, yAxis\n    class(legend), pointer :: lgnd\n\n    ! Set up the integrator\n    ptr =\u003e vdp\n    call fcn%define_equations(2, ptr)\n\n    ! Define the initial conditions\n    t = [0.0d0, 8.0d1]\n    ic = [2.0d0, 0.0d0]\n\n    ! Compute the solution\n    x1 = integrator1%integrate(fcn, t, ic)  ! ODE_IRK integrator\n    x2 = integrator2%integrate(fcn, t, ic)  ! ODE_AUTO integrator\n\n    ! Display the number of solution points in each\n    print '(AI0)', \"ODE_IRK Solution Point Count: \", size(x1, 1)\n    print '(AI0)', \"ODE_AUTO Solution Point Count: \", size(x2, 1)\n\n    ! ---------------------------- PLOTTING CODE ----------------------------- !\n    ! Plot the solution\n    call plt%initialize()\n    call plt%set_font_size(14)\n\n    xAxis =\u003e plt%get_x_axis()\n    call xAxis%set_title(\"t\")\n\n    yAxis =\u003e plt%get_y_axis()\n    call yAxis%set_title(\"x(t)\")\n\n    lgnd =\u003e plt%get_legend()\n    call lgnd%set_is_visible(.true.)\n    call lgnd%set_draw_border(.false.)\n    call lgnd%set_draw_inside_axes(.false.)\n\n    call d1%set_name(\"IRK\")\n    call d1%set_draw_line(.false.)\n    call d1%set_draw_markers(.true.)\n    call d1%set_marker_style(MARKER_FILLED_TRIANGLE)\n    call d1%set_marker_scaling(1.5)\n    call d1%define_data(x1(:,1), x1(:,2))\n    call plt%push(d1)\n\n    call d2%set_name(\"AUTO\")\n    call d2%set_draw_line(.false.)\n    call d2%set_draw_markers(.true.)\n    call d2%set_marker_style(MARKER_EMPTY_CIRCLE)\n    call d2%set_line_color(CLR_RED)\n    call d2%set_line_style(LINE_DASHED)\n    call d2%define_data(x2(:,1), x2(:,2))\n    call plt%push(d2)\n\n    call plt%draw()\n\n    call plt%clear_all()\n\n    call d1%define_data(x1(:,2), x1(:,3))\n    call d2%define_data(x2(:,2), x2(:,3))\n    call xAxis%set_title(\"x(t)\")\n    call yAxis%set_title(\"dx/dt\")\n    call plt%push(d1)\n    call plt%push(d2)\n    call plt%draw()\n\ncontains\n    ! Van Der Pol Equation\n    ! x\" + x - mu * (1 - x**2) * x' = 0\n    subroutine vdp(t, x, dxdt)\n        real(real64), intent(in) :: t\n        real(real64), intent(in), dimension(:) :: x\n        real(real64), intent(out), dimension(:) :: dxdt\n\n        real(real64), parameter :: mu = 20.0d0\n\n        dxdt(1) = x(2)\n        dxdt(2) = mu * (1.0d0 - x(1)**2) * x(2) - x(1)\n    end subroutine\nend program\n```\n```text\nODE_IRK Solution Point Count: 544\nODE_AUTO Solution Point Count: 1283\n```\nThese are the plots resulting from the above program.\n![](images/vanderpol_compare_example.png?raw=true)\n![](images/vanderpol_compare_example_diff.png?raw=true)\n\n## Example 3\nThe following example illustrates how to compute the solution to a system of ODEs modeling the bouncing of a ball.  The example also utilizes the [FPLOT](https://github.com/jchristopherson/fplot) library in order to plot the solution.\n```fortran\nprogram example\n    use iso_fortran_env\n    use integral_core\n    use fplot_core\n    implicit none\n\n    ! Parameters\n    real(real64), parameter :: g = 9.81d0 ! Gravitational acceleration\n    real(real64), parameter :: k = -0.8d0 ! Coefficient of restitution\n\n    ! Local Variables\n    procedure(ode_fcn), pointer :: ptr\n    procedure(ode_constraint), pointer :: cptr\n    type(ode_helper) :: fcn\n    type(ode_auto) :: integrator\n    integer(int32) :: n\n    real(real64) :: ic(2), t(2)\n    real(real64), allocatable, dimension(:,:) :: x1, x2, x3, x4\n    type(plot_2d) :: plt\n    type(plot_data_2d) :: d1, d2, d3, d4\n    class(plot_axis), pointer :: xAxis, yAxis\n    type(legend), pointer :: lgnd\n\n    ! Set up the integrator\n    ptr =\u003e ball\n    cptr =\u003e ground_constraint\n    call fcn%define_equations(2, ptr)\n    call fcn%define_constraints(1, cptr)\n    call integrator%set_max_step_size(1.0d-3)\n    call integrator%set_limit_step_size(.true.)\n\n    ! Compute the solution\n    t = [0.0d0, 1.0d1]\n    ic = [1.0d1, 5.0d0]\n    x1 = integrator%integrate(fcn, t, ic)\n\n    ! The integrator stops when the ball first makes contact.  As a result, lets\n    ! reset the time limits and initial conditions to continue the integration\n    n = size(x1, 1)\n    t(1) = x1(n,1)\n    ic = [abs(x1(n,2)), k * x1(n,3)]\n    call integrator%reset()\n    x2 = integrator%integrate(fcn, t, ic)\n\n    ! Again\n    n = size(x2, 1)\n    t(1) = x2(n,1)\n    ic = [abs(x2(n,2)), k * x2(n,3)]\n    call integrator%reset()\n    x3 = integrator%integrate(fcn, t, ic)\n\n    ! Again\n    n = size(x3, 1)\n    t(1) = x3(n,1)\n    ic = [abs(x3(n,2)), k * x3(n,3)]\n    call integrator%reset()\n    x4 = integrator%integrate(fcn, t, ic)\n\n\n    ! Plot the solution\n    call plt%initialize()\n    call plt%set_font_size(14)\n\n    lgnd =\u003e plt%get_legend()\n    call lgnd%set_is_visible(.false.)\n\n    xAxis =\u003e plt%get_x_axis()\n    call xAxis%set_title(\"t\")\n\n    yAxis =\u003e plt%get_y_axis()\n    call yAxis%set_title(\"x(t)\")\n\n    call d1%set_line_color(CLR_BLUE)\n    call d1%set_line_width(2.0)\n    call d1%define_data(x1(:,1), x1(:,2))\n\n    call d2%set_line_color(CLR_BLUE)\n    call d2%set_line_width(2.0)\n    call d2%define_data(x2(:,1), x2(:,2))\n\n    call d3%set_line_color(CLR_BLUE)\n    call d3%set_line_width(2.0)\n    call d3%define_data(x3(:,1), x3(:,2))\n\n    call d4%set_line_color(CLR_BLUE)\n    call d4%set_line_width(2.0)\n    call d4%define_data(x4(:,1), x4(:,2))\n\n    call plt%push(d1)\n    call plt%push(d2)\n    call plt%push(d3)\n    call plt%push(d4)\n    call plt%draw()\n\ncontains\n    ! A bouncing ball can be described by the following equation:\n    ! x\" = -g\n    !\n    ! Where g = gravitational acceleration\n    subroutine ball(t, x, dxdt)\n        real(real64), intent(in) :: t\n        real(real64), intent(in), dimension(:) :: x\n        real(real64), intent(out), dimension(:) :: dxdt\n        dxdt(1) = x(2)\n        dxdt(2) = -g\n    end subroutine\n\n    ! The constraint function\n    subroutine ground_constraint(t, x, f)\n        real(real64), intent(in) :: t\n        real(real64), intent(in), dimension(:) :: x\n        real(real64), intent(out), dimension(:) :: f\n        f(1) = x(1)     ! Find when x == 0\n    end subroutine\nend program\n```\nThis is the plot resulting from the above program.\n![](images/bouncing_ball_example.png?raw=true)\n\n## Documentation\nDocumentation can be found [here](http://htmlpreview.github.io/?https://github.com/jchristopherson/integral/blob/master/doc/html/index.html).\n\n## Build Instructions\nThis library utilizes [CMake](https://cmake.org/) to facilitate its build.  Using CMake is as simple as issuing the following commands.\n- cmake ...\n- make\n- make install\n\n## Dependencies\nThis library depends upon the following libraries.\n- [FERROR](https://github.com/jchristopherson/ferror)\n\nSee [Running CMake](https://cmake.org/runningcmake/) for more details on the use of CMake.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristopherson%2Fintegral","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjchristopherson%2Fintegral","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristopherson%2Fintegral/lists"}