Skip to content

Instantly share code, notes, and snippets.

@robinknowles
robinknowles / Dockerfile
Created May 9, 2019 13:40
Simple OpenFOAM Dockerfile
# Start from the official Ubuntu Bionic (18.04 LTS) image
FROM ubuntu:bionic
# Install any extra things we might need
RUN apt-get update \
&& apt-get install -y \
vim \
ssh \
sudo \
wget \
@robinknowles
robinknowles / foamDictionary-cheat-sheet.md
Created February 4, 2022 09:46
A cheat sheet of foamDictionary commands for making quick command-line edits to OpenFOAM dictionaries

foamDictionary Cheat Sheet

Accompanies OnCFD Newsletter #082: Quick edits with foamDictionary

Retrieve entries

# Print the top-level keywords present in this dictionary
foamDictionary system/snappyHexMeshDict -keywords

# Print the addLayersControls sub-dictionary
foamDictionary system/snappyHexMeshDict -entry addLayersControls
@robinknowles
robinknowles / sample
Last active February 25, 2022 20:46
An example of using sampledSurfaces to export patches from OpenFOAM
// OpenFOAM v2112 function using sampledSurfaces for patch/surface export
// Includes:
// - multiple file formats;
// - point-data export;
// - near-wall interpolation;
//
// Can be tested on motorBike tutorial data, using:
// postProcess -func sample -latestTime
sample
@robinknowles
robinknowles / forceCoeffs
Created August 12, 2022 15:27
An example of using binField to create a force x-ray
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
// Calculate lift force coefficient acting on the motorbike patch group
// Then "bin" that data along the X & Y axes to create a force x-ray
@robinknowles
robinknowles / rename-a-patch-with-createPatch.md
Created April 28, 2023 08:34
How to rename a patch in OpenFOAM using createPatch

How to rename a patch in OpenFOAM using createPatch

Accompanies OnCFD Newsletter #144: How to change a patch name

Outline

Need to rename a patch in a meshed & decomposed case? Do the following...

  • Copy the dictionary below & save it as /system/createPatchDict
  • Edit the name & patches entries to the required names
  • Run createPatch -overwrite in parallel to make the change
@robinknowles
robinknowles / building-an-open-source-mesh-wrapper.md
Created May 18, 2023 13:19
Building triangle_alpha_wrap from the CGAL examples

Shrink-wrapping triangle meshes using CGAL

Accompanies OnCFD Newsletter #147: "It's a(n open-source) wrap"

Here are my "high-level" notes on building a command-line, mesh shrinkwrapper using Alpha Wrap 3 from CGAL.

I did this in an Ubuntu container on a Mac, but you could do similar in Windows Subsystem for Linux or native Ubuntu (or anywhere else that you can grab all of the dependecies).

See the accompanying article for more background 👋

Divergence detection in OpenFOAM using runTimeControls

Accompanies OnCFD Newsletter #148: "Divergence Detector"

Here's the copy-paste-able version of the function I use to detect (& end) simulations that are slowly diverging & taking up valuable cluster time.

minMaxU
{
    type        fieldMinMax;
@robinknowles
robinknowles / ParaView_State_ExplodingAssembly.py
Last active July 13, 2023 12:52
A semi-automatic way to explode assemblies in ParaView & create simple plots that reveal the hidden parts in your models.
# state file generated using paraview version 5.11.1
import paraview
paraview.compatibility.major = 5
paraview.compatibility.minor = 11
#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
@robinknowles
robinknowles / ParaView Run Receipts.md
Created August 4, 2023 14:21
A scriptable method for producing run summary receipts for sharing in Slack/Teams/Whatsapp

Run Receipts in ParaView

Accompanies OnCFD Newsletter #158

Attached is an example ParaView script to create a "run receipt" summary of your results like this 👇

Straight from the command-line & ready to post into Slack/Teams/WhatsApp

@robinknowles
robinknowles / OpenFOAM checkpoint for AWS Spot.md
Created September 21, 2023 11:00
Detecting an AWS spot instance interruption during an OpenFOAM simulation & saving your data

Detecting AWS spot instance interruptions in OpenFOAM

Accompanies OnCFD Newsletter #165

Here's a quick OpenFOAM function that makes running on AWS spot instances a whole lot nicer.

It uses two standard function objects (plus curl) to check whether your instance has recieved a termination notice.

If it has, it stops your simulation & writes your current data.