Skip to content

Instantly share code, notes, and snippets.

@aavogt
aavogt / stream.py
Last active April 3, 2025 14:00
paraview.simple purge gas mixing
# install cfdof
# make the geometry where the gases mix such that inlets with z>0 are Ar, z<0 are Air
# adjust rx,ry,rz below
# the normal speed-weighted average composition of a rectangle specified below is calculated
#
# TODO:
# - [ ] diffusion: reconstructPar -latestTime, then use the output velocity field with another openfoam solver for the transport equation
# - [ ] composition from boundary names, instead of the ad-hoc plane split based on the location of the farthest upstream point in the streamline
# - [ ] surrogate model (tgp?) for geometry/flow/model parameter sweeps
from typing import cast
@aavogt
aavogt / pun.R
Created March 13, 2025 01:39
alternative R function argument matching
#' Get the name of a symbol or function call
#'
#' @param expr An expression to extract the name from.
#' @return A character string representing the name of the symbol or function call, or NULL if unsupported.
#' @examples
#' get_pun_name(quote(x)) # returns "x"
#' get_pun_name(quote(f(x))) # returns "f"
get_pun_name <- function(expr) {
if (is.symbol(expr)) {
return(as.character(expr))
@aavogt
aavogt / applyN.mac
Created March 9, 2025 21:19
maxima CAS library for simplifying list of equations
/* put this in the same directory as the wx maxima file (.wxmx)
load("applyN.mac");
then use applyN as below
*/
/* applyN eliminates variables from a set of equations,
* while maintaining expressions for the eliminated variables.
*
* For example:
*
* r : applyN([v1 + v2 = v4^2], [v1])
@aavogt
aavogt / CSG.hs
Last active February 21, 2025 21:19
attempted geometry as functions
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE PatternSynonyms #-}
-- |
--
-- Constructive solid geometry. Not quite FRep or signed distance function.
module CSG where
@aavogt
aavogt / 4bar2.jl
Created January 27, 2025 17:17
4 bar linkage filament cutter
# %%
using BSplineKit, LinearAlgebra, Optimization
using Plots
using RCall
using SplitApplyCombine
using Symbolics
@rlibrary ggplot2
import OptimizationOptimisers, DataFrames
@aavogt
aavogt / fc2stl.py
Last active January 30, 2025 02:01
freecad export stls (on save)
#!/usr/bin/env -S freecad --console
import os
import sys
import textwrap
import FreeCAD
import PartDesign
import Part
import tempfile
import shutil
@aavogt
aavogt / Defun.hs
Last active December 1, 2024 06:31
Defun
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# HLINT ignore "Functor law" #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
@aavogt
aavogt / bmp_tptp.rs
Created November 25, 2024 19:40
esp-rs bme280
fn bmp_tptp(
i2c_ref: Arc<Mutex<I2C0>>,
sda: AnyIOPin,
scl: AnyIOPin,
config: Config,
) -> anyhow::Result<[f32; 4]> {
use bme280::i2c::BME280;
let i2c = i2c_ref.lock().unwrap();
let i2c = RefCell::new(I2cDriver::new(i2c, sda, scl, &config)?);
@aavogt
aavogt / string_vs_list.R
Created November 17, 2024 21:09
benchmarking ghc (`elem` "{([") vs. (\c -> c `elem` "{([") vs. ...
library(pacman)
p_load(tidyverse, tictoc, glue, e1071, directlabels, cache)
split <- function(x) unlist(strsplit(x, ""))
sample(c(letters, split("{}[]()")), 10^5, replace = TRUE) %>% as.list() %>% do.call(str_c, .) %>% writeLines("input0.txt")
# map_chr(commands, function(command) readLines(paste0(command, ".hs"))) %>% setNames(commands) %>% deparse %>% writeLines
mains <- c(
@aavogt
aavogt / VVariable.hs
Created November 11, 2024 18:13
ghc parser plugin to assign IORefs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
module VVariable where
import Control.Monad
import Control.Monad.Trans.Writer