Skip to content

Instantly share code, notes, and snippets.

@reox
reox / doubletensorproduct.py
Last active February 10, 2025 08:18
double tensorial product for stiffness tensor from Lamé constants
import numpy as np
# 2nd order identity tensor
I = np.eye(3)
# Lamé Constants
lam_0 = 456
mu_0 = 123
print(f"G = {mu_0}")
@reox
reox / build.sh
Created January 7, 2025 20:28
Build dovecot-fts-xapian nightly debian package
# Recommended to run in a clean environment
export EMAIL="builder@localhost"
apt update
apt dist-upgrade -y
apt install -y git git-buildpackage --no-install-recommends
git config --global user.name "Bob the Builder"
git config --global user.email "$EMAIL"
@reox
reox / pfilter.py
Created May 3, 2022 09:49
Paraview: Programmable Filter to display the CellType of unstructured grids
# This programmable filter can be used on an unstructured grid to display the
# numerical value of the cell type (i.e., tet, hex, wedge, ...)
output.CellData.append(inputs[0].CellTypes, 'Cell_type')
@reox
reox / stiffness.py
Last active March 22, 2022 13:50
Fun with stiffness matrices: Voigt-Reuss-Hill averages and plotting Young's modulus
"""
Fun with stiffness matrices!
The plotting routine is inspired by https://github.com/coudertlab/elate
The Voigt-Reuss-Hill Averaging was directly copied from there.
Note the following relationships of stresses and strains:
sigma_ij ... stress tensor
epsilon_ij ... strain tensor
@reox
reox / savefig_tiff_lzw.py
Created March 17, 2022 10:40
Save a figure as tiff with lzw compression
import matplotlib.pyplot as plt
# do plotting:
#plt.dosomething(...)
# pil_kwargs can be used to pass things to PIL.
# the save function has **params which then passes the kwargs to the file format save function, for example:
# See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#saving-tiff-images
# LZW compression is called tiff_lzw in pil...
plt.savefig('foobaz.tiff', pad_inches=0.05, bbox_inches='tight', pil_kwargs=dict(compression='tiff_lzw'))
@reox
reox / faces_of_array.py
Created May 20, 2021 12:41
Query the faces of a cubical image in numpy
import numpy as np
# Numpy array is xyz
img = np.zeros((10,20,30))
a = slice(None) # all items, same as ':'
faces = {
'top': (-1, a, a),
'bottom': (0, a, a),
@reox
reox / eigen.py
Created August 5, 2020 08:34
Eigenvalues and -vectors of matrix and getting matrix back in numpy
import numpy as np
A = np.array([[2,1,2.5], [1,3,1], [2.5,1,4]])
# Eigenvalues and -vectors have the property such that: Ax = lx
# x ... Eigenvectors
# l ... Eigenvalues
l, x = np.linalg.eig(A)
# it follows:
[
{
"ColorSpace": "RGB",
"DefaultMap": true,
"Name": "Turbo",
"RGBPoints": [
0.0,
0.18823529411764706,
0.07058823529411765,
0.23137254901960785,
@reox
reox / divide by value.py
Created November 29, 2017 16:34
divide by a value, decide with a flag
# What you would normaly do:
def some_divison():
flag = True
val = 23
divisor = 42
if flag:
return val / divisor
@reox
reox / freecad_daily_build.sh
Last active March 19, 2019 01:41
Build a debian package from FreeCAD yourself.
#!/bin/bash
set -e
#################################
# NOTE:
# This assumes you have a user `builder` and a folder `/home/builder/packages`.
# it will clone FreeCAD there and start pbuilder using pdebuild.
# For me this works using debian sid. (stretch/buster will probably not work!)
#
# After the build has finished, it will import the packes into a reprepro
# which is setup at /srv/repo