Skip to content

Instantly share code, notes, and snippets.

@robinknowles
robinknowles / FOAM fuzzy finder.md
Created November 17, 2023 14:26
Using fzf to fuzzy-find OpenFOAM features

Fuzzy finding 'FOAM features

Accompanies OnCFD Newsletter #173

A couple of code snippets that use fzf to mine your install & extract the answers to everyday OpenFOAM questions, like...

  • How do I use a particular feature?
  • What does so-and-so dictionary look like?
  • Does this need a semi-colon? 🤦‍♂️
@robinknowles
robinknowles / OpenFOAM VS Code Tasks.md
Last active November 17, 2023 14:13
Using VS Code tasks to run OpenFOAM scripts

Running OpenFOAM with VS Code Tasks

Accompanies OnCFD Newsletter #171

Attached is an example tasks.json file for running your Allrun & Allclean OpenFOAM scripts in VS Code via Tasks.

In VS Code, use cmd/ctrl + shift + p to bring up the command palette & type Tasks: Open User Tasks

Choose the Others option & it will create a tasks.json file in your user area & pop it open in the editor.

@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.

@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 / 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()

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 / 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 👋

@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 / 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 / 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