Git Product home page Git Product logo

gha3mi / forsolver Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 3.0 907 KB

ForSolver - linear and nonlinear solvers

Home Page: https://gha3mi.github.io/forsolver/

License: BSD 3-Clause "New" or "Revised" License

Fortran 100.00%
fortran linear-system-solver newton-raphson solver fortran-package-manager nonlinear-systems complex-step-differentiation finite-difference-method newton-method quasi-newton-method

forsolver's Introduction

GitHub Version Documentation License Build

ForSolver: A Fortran library of linear and nonlinear solvers.

Usage

Linear system solver

use forsolver, only: solve

x = solve(A,b,method)

available methods (optional):

  • gesv
  • gels

Nonlinear system solver

use forsolver, only: nlsolver

call nls%set_options(&
      lin_method,&
      nl_method,&
      fdm_method,&
      fdm_tol,&
      cs_tol,&
      TolFun,&
      maxit,&
      nmp,&
      verbosity )

call nls%solve(F, dFdx, x0, x_sol)

available nl_methods:

  • newton
  • newton-modified
  • newton-quasi-fd
  • newton-quasi-fd-modified
  • newton-quasi-cs
  • newton-quasi-cs-modified

fd: finite difference method

cs: complex step method

Requirements

  • A Fortran Compiler
  • LAPACK, BLAS or MKL
  • Fortran Package Manager (fpm)

fpm Dependency

If you want to use ForSolver as a dependency in your own fpm project, you can easily include it by adding the following line to your fpm.toml file:

[dependencies]
forsolver = {git="https://github.com/gha3mi/forsolver.git"}

Runing Tests

Execute the following commands to run tests with specific compilers:

fpm @<compiler>-test

compiler: ifx, ifort, gfortran, nvfortran

Examples

Example 1: Linear System Solver

program example1

   use kinds
   use forsolver

   implicit none

   real(rk), dimension(:,:), allocatable :: A
   real(rk), dimension(:)  , allocatable :: x, b
   integer                               :: m,n, i, j

   m = 3
   n = 2

   allocate(A(m,n),b(m),x(n))

   A(1,:) = [ 1.0_rk, 5.0_rk]
   A(2,:) = [ 3.0_rk, 1.0_rk]
   A(3,:) = [-2.0_rk, 4.0_rk]

   b = [4.0_rk, -2.0_rk, 3.0_rk]

   x = solve(A, b)

end program example1

Example 2: Newton's Method for Root Finding

module my_function3
   use kinds
   implicit none
contains
   function F1(x) result(F_val)
      real(rk), intent(in) :: x
      real(rk) :: F_val
      F_val = 5.0_rk * x**3 + 8.0_rk * x - 5.0_rk
   end function F1
   function dF1dx(x) result(dFdx_val)
      real(rk), intent(in) :: x
      real(rk) :: dFdx_val
      dFdx_val = 15.0_rk * x**2 + 8.0_rk
   end function dF1dx
end module my_function3

program example2

   use forsolver
   use my_function3

   implicit none

   type(nlsolver) :: nls
   real(rk)       :: x, expected_x

   call nls%set_options(&
      nl_method   = 'newton',&
      maxit       = 100,&
      TolFun      = 1e-4_rk,&
      verbosity   = 1)

   call nls%solve(F=F1, dFdx=dF1dx, x0=10.0_rk, x_sol=x)

end program example2

API Documentation

The most up-to-date API documentation for the master branch is available here. To generate the API documentation for ForSolver using ford run the following command:

ford ford.yml

Contributing

Contributions to ForSolver are welcome! If you find any issues or would like to suggest improvements, please open an issue.

forsolver's People

Contributors

gha3mi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.