Skip to content

Instantly share code, notes, and snippets.

View ivan-pi's full-sized avatar

Ivan Pribec ivan-pi

View GitHub Profile
@ivan-pi
ivan-pi / kalman.f90
Last active October 24, 2018 08:19 — forked from mrocklin/kalman.f90
Kalman filter in BLAS/LAPACK Fortran; see [blogpost](http://matthewrocklin.com/blog/work/2012/11/24/Kalman-Filter) for more information
subroutine f(mu, Sigma, H, INFO, R, Sigmavar_2, data, muvar_2, k, n)
implicit none
integer, intent(in) :: k
integer, intent(in) :: n
real*8, intent(in) :: Sigma(n, n) ! Sigma
real*8, intent(in) :: H(k, n) ! H
real*8, intent(in) :: mu(n) ! mu
real*8, intent(in) :: R(k, k) ! R, H*Sigma*H' + R
real*8, intent(in) :: data(k) ! (H*Sigma*H' + R)^-1*((-1)*data + H*mu), data, (-1)* data + H*mu
@ivan-pi
ivan-pi / mkl_least_squares_example.f90
Last active December 28, 2018 23:14
Sample least squares problem using LAPACK routines from Intel MKL
! # Check out the link below for specific compile instructions for your system:
! # https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/
!
! To compile use:
! LINK="${MKLROOT}/lib/intel64/libmkl_lapack95_lp64.a -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a ${MKLROOT}/lib/intel64/libmkl_sequential.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm -ldl"
! INC="-I${MKLROOT}/include/intel64/lp64/ -I${MKLROOT}/include/"
! ifort -warn all -o example3 $INC example3.f90 $LINK
module m_least_squares
@ivan-pi
ivan-pi / test_gttrf.f90
Last active January 26, 2019 17:22
Tridiagonal linear system of equations example using gttrf from LAPACK (Intel MKL)
! LINK="${MKLROOT}/lib/intel64/libmkl_lapack95_lp64.a -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a ${MKLROOT}/lib/intel64/libmkl_sequential.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm -ldl"
! INC="-I${MKLROOT}/include/intel64/lp64/ -I${MKLROOT}/include/"
! ifort -warn all -o test_gttrf $INC test_gttrf.f90 $LINK
! ./test_gttrf > test_gttrf.out
! gnuplot
! gnuplot> Th = 1
! gnuplot> plot "test_gttrf.out" u 1:2 w p pt 7, cosh((1-x)*Th)/cosh(Th)
module rd_setup
@ivan-pi
ivan-pi / test_banded.f90
Last active November 6, 2023 10:30
Banded system of linear equations solved using "gbsv" driver from LAPACK (Intel MKL)
!LINK="${MKLROOT}/lib/intel64/libmkl_lapack95_lp64.a -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a ${MKLROOT}/lib/intel64/libmkl_sequential.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm -ldl"
!INC="-I${MKLROOT}/include/intel64/lp64/ -I${MKLROOT}/include/"
!ifort -O3 -warn all -o test_banded $INC test_banded.f90 $LINK
program test_banded
use lapack95, only: gbtrf, gbtrs, gbsv
use f95_precision, only: wp => dp
implicit none
integer, parameter :: kl = 2, ku = 1
@ivan-pi
ivan-pi / high_order_poisson_solver.f90
Created February 11, 2019 16:09
Mehrstellenverfahren for the Poisson equation
! See link below for details:
! https://scicomp.stackexchange.com/questions/6854/mehrstellenverfahren-for-poisson
!
program poisson_higher_order
implicit none
integer, parameter :: wp = kind(1.0d0)
real(wp), parameter :: pi = 4._wp*atan(0._wp)
@ivan-pi
ivan-pi / wort_cooling.py
Created February 17, 2019 18:54
Some simple calculations of wort cooling with an internal coil
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
# LMTD case
def f(t,y,params):
p2, p3, Tin = params
@ivan-pi
ivan-pi / boyd_bvp_example.f90
Created March 18, 2019 00:59
Code example from book "Chebyshev and Fourier Spectral Methods" by John P. Boyd
program boyd_bvp
dimension xi(20),aphi(20),g(20),h(20,20),ugraph(101)
common/pbasis/phi(20),phix(20),phixx(20)
common/thiele/th
pi = 4.*atan(1.0)
! specify parameters
@ivan-pi
ivan-pi / ghiav.txt
Last active October 11, 2021 15:52
Lid-driven cavity flow benchmark v-velocity values from Ghia, U. K. N. G., Ghia, K. N., & Shin, C. T. (1982), Journal of computational physics, 48(3), 387-411.
# Ghia, U. K. N. G., Ghia, K. N., & Shin, C. T. (1982).
# High-Re solutions for incompressible flow using the Navier-Stokes equations and a multigrid method.
# Journal of computational physics, 48(3), 387-411.
#
# TABLE II
# Results for $v$-Velocity along Horizontal Line through Geometric Center of Cavity
# [Note: The velocity for Re = 400 and point (x,v) = (0.9063,-0.23827) is probably wrong]
#--------------------------------------------------------------------
# Re
# -------------------------------------------------------------
@ivan-pi
ivan-pi / ghiau.txt
Created April 18, 2019 14:31
Lid-driven cavity flow benchmark u-velocity values from Ghia, U. K. N. G., Ghia, K. N., & Shin, C. T. (1982), Journal of computational physics, 48(3), 387-411.
# Ghia, U. K. N. G., Ghia, K. N., & Shin, C. T. (1982).
# High-Re solutions for incompressible flow using the Navier-Stokes equations and a multigrid method.
# Journal of computational physics, 48(3), 387-411.
#
# TABLE I
# Results for $u$-velocity along Vertical Line through Geometric Center of Cavity
#--------------------------------------------------------------------
# Re
# -------------------------------------------------------------
# y 100 400 1000 3200 5000 7500 10000
@ivan-pi
ivan-pi / gist:5554aed5157c7c84c8ec04aef612977d
Created September 8, 2019 13:26
Biperiodic weight matrix example
def biperiodic_weight_matrix(bbox,x, p, n, diffs,
coeffs=None,
phi=phs3,
order=None,
eps=1.0,
stencils=None):
'''
Returns a weight matrix which maps a functions values at `p` to an
approximation of that functions derivative at `x`. This is a convenience
function which first creates stencils and then computes the RBF-FD weights