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 / cbrt_libm_example.f90
Created July 10, 2020 08:46
Port of the libm cbrt function (https://svnweb.freebsd.org/base/head/lib/msun/src/s_cbrt.c?revision=342563&view=markup) from C to Fortran. This code has not been verified. Use at your own risk!
! @(#)s_cbrt.c 5.1 93/09/24
!
! ====================================================
! Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
!
! Developed at SunPro, a Sun Microsystems, Inc. business.
! Permission to use, copy, modify, and distribute this
! software is freely granted, provided that this notice
! is preserved.
! ====================================================
@ivan-pi
ivan-pi / ensemble_kf.f90
Created July 9, 2020 16:01
Ensemble Kalman filter from Evensen, G. (2003). The ensemble Kalman filter: Theoretical formulation and practical implementation. Ocean dynamics, 53(4), 343-367.
module m_multa
implicit none
private
public :: multa
contains
subroutine multa(A,X,ndims,nrens,iblkmax)
@ivan-pi
ivan-pi / cbrt_2.f90
Created June 28, 2020 12:09
Cube root code example 2
module cbrt_mod2
implicit none
private
public :: cbrt, sp
interface cbrt
module procedure cbrt_sp_sp
module procedure cbrt_sp_csp
@ivan-pi
ivan-pi / cbrt_1.f90
Created June 28, 2020 12:07
Cube root code example 1
module cbrt_mod1
implicit none
private
public :: cbrt, sp, r
interface cbrt
module procedure cbrt_sp_sp
module procedure cbrt_csp_csp
@ivan-pi
ivan-pi / continued_fractions.py
Created June 26, 2020 12:23
Basic functions for working with continued fractions. These are handy for approximating irrational numbers as ratios of integer. A Fortran solution is available at https://fortran-lang.discourse.group/t/implmentation-of-contnued-fraction/124/2
import math
from fractions import Fraction
def continued_fraction(r,steps=10):
cf = []
for step in range(steps):
i = math.floor(r)
cf.append(i)
subroutine C_F_STRPOINTER (STRARRAY, FSTRPTR, MAXLEN)
use, intrinsic :: ISO_C_BINDING
implicit none
character, dimension(*), target, intent(in) :: STRARRAY
character(:), pointer, intent(out) :: FSTRPTR
integer, intent(in), optional :: MAXLEN
integer :: curlen
curlen = 0
@ivan-pi
ivan-pi / linspace.f90
Created December 19, 2019 18:54
Linspace in Fortran
module linspace_mod
use iso_fortran_env, only: dp => real64
implicit none
contains
!>
! Return evenly spaced numbers over a specified interval.
!
! Returns `num` evenly spaced samples, calculated over the interval `[start, stop]`.
@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
@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 / ghiav.txt
Last active August 13, 2024 13:49
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
# -------------------------------------------------------------