Skip to content

Instantly share code, notes, and snippets.

@Foadsf
Foadsf / MakeFile
Last active May 13, 2018 18:12
OpenCL: comparing the time required to add two arrays of integers on different devices
OS := $(shell uname)
OPTIONS:=
ifeq ($(OS),Darwin)
OPTIONS += -framework OpenCL
else
OPTIONS += -l OpenCL
endif
all: main.c
@Foadsf
Foadsf / compile.sh
Last active July 10, 2018 23:30
compiling Elmer fem on macOS High Sierra
#!/bin/sh -f
export CC="mpicc -fPIC"
export CXX="mpicxx"
export FC="mpif90"
export F77="mpif90"
export ELMER_INSTALL="/some/random/folder/elmerfem/install/"
export ELMER_HOME="/some/random/folder/elmerfem/install/"
export MPI_HOME="/usr/local/Cellar/open-mpi/3.1.1"
from functools import reduce
from operator import mul
import sympy as sp
import numpy as np
# Both of these function will be vectorized via np.vectorize.
# This will not speed up the computation at all (behind np.vectorize, there still are for loops)
# but this avoid nested for loop, making that easier to read (and deal with arbitrary number of dims).
def build_X(a, xs):
@Foadsf
Foadsf / PDE.ipynb
Last active August 9, 2018 12:23
power series substituting continuity equation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Foadsf
Foadsf / ndpoly.py
Last active August 11, 2018 08:15
A multivariate polynomial class
import numpy as np
from copy import deepcopy
def list_dim(a):
if not type(a) == list:
return []
return [len(a)] + list_dim(a[0])
class Monomial:
def __init__(self, coefficient, powers):
@Foadsf
Foadsf / exampleconve.ipynb
Created August 13, 2018 11:58
example for multidimensional conv
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Foadsf
Foadsf / ndconv.py
Last active August 13, 2018 13:34
Cauchy product of multivariate finite power series (polynomials) represented as discrete convolution of NumPy ndarrays
import numpy as np
def crop(A,D1,D2):
return A[tuple(slice(D1[i], D2[i]) for i in range(A.ndim))]
def sumall(A):
sum1=A
for k in range(A.ndim):
sum1 = np.sum(sum1,axis=0)
return sum1
@Foadsf
Foadsf / blockMeshDict
Created August 21, 2018 21:21
axisymmetric cylinder and piston for OpenFOAM
//following this: https://openfoamwiki.net/index.php/Main_ContribExamples/AxiSymmetric
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
@Foadsf
Foadsf / blockMeshDict
Last active August 23, 2018 10:30
axisymmetric step OpenFOAM
//following this: https://openfoamwiki.net/index.php/Main_ContribExamples/AxiSymmetric
// /cygdrive/c/Users/sojoodif/surfdrive/sync/MyPhD/simulation/OpenFOAM/20180131_2
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@Foadsf
Foadsf / blockMeshDict
Last active August 30, 2018 12:08
imports a blockMeshDict files and display it in FreeCAD draft workbench
// test blockMeshDict file
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{