Modeling Oobleck in Python: Simulating Shear Thickening at Home
Build a Python oobleck simulator with a rate-dependent viscosity model and visualize shear-thickening behavior step by step.
Modeling Oobleck in Python: Simulating Shear Thickening at Home
Oobleck is one of the best classroom demos in physics because it behaves like a contradiction in a bowl: tap it quickly and it feels solid, but move it slowly and it flows like a liquid. That dramatic switching is not magic; it is rheology, the science of how matter flows and deforms under stress. In a recent Ars Technica report on oobleck’s surprising behavior, dense drops at high shear rates were described as spreading like a liquid before stiffening into a solid, a reminder that the transition depends on how fast you stress the material. In this code lab, we will build a simple but insightful Python simulation that approximates oobleck with a rate-dependent viscosity model, then visualize the switch between fluid-like and solid-like response.
This guide is designed as a practical bridge between theory and computation, much like a lab notebook you can run at home. If you have seen summaries of modern physics workflows like open-source quantum software ecosystems or evaluation frameworks for reasoning-intensive systems, the spirit is similar: define the model clearly, test assumptions, and inspect the outputs instead of trusting a black box. Here, our “black box” is a non-Newtonian fluid, and our goal is to make it transparent, reproducible, and visually intuitive.
1. What Oobleck Is, and Why It Suddenly Feels Solid
Shear thickening in plain language
Oobleck is typically a cornstarch-water suspension, and its strange behavior comes from the way particles interact under stress. At low shear rates, the mixture can rearrange and flow because water helps the particles slide past one another. At high shear rates, the particle network jams, the local viscosity rises sharply, and the mixture resists motion like a temporary solid. That rate dependence is the key: the material is not simply “thick” or “thin,” but changes with the speed and intensity of forcing.
Why this matters beyond the kitchen
Shear-thickening suspensions are not just classroom curiosities. They inform protective gear, impact-resistant materials, industrial slurries, and formulations where response under stress matters more than static properties. When scientists and engineers study these fluids, they are often trying to understand how microstructure, particle concentration, and applied forcing produce nonlinear behavior. If you want a broader computational mindset for scientific modeling, it can help to think in terms of systems and workflows, similar to how instructors map concepts in decision-engine classroom activities or how teams design robust pipelines in real-time capacity systems—the exact domains differ, but the principle of responsive modeling is the same.
What we will and will not model
To make the simulation approachable, we will not attempt a full particulate suspension calculation. A complete treatment would involve hydrodynamics, particle packing, and possibly contact mechanics, which is too heavy for a home code lab. Instead, we will approximate oobleck as a fluid with viscosity that depends on shear rate. That simplification is powerful enough to reproduce the qualitative “switching” behavior while staying accessible in Python.
2. The Physics Behind the Switching Behavior
Newtonian vs non-Newtonian fluids
A Newtonian fluid has a constant viscosity: double the shear stress, and you double the shear rate. Water and air are close to this ideal over many conditions. Oobleck is different because its viscosity is not constant; it depends on how hard and how fast you deform it. This makes it a non-Newtonian fluid, and more specifically one with shear-thickening behavior.
Viscosity as a function of shear rate
The simplest useful model is a smooth transition from low viscosity to high viscosity as shear rate increases. One popular family of approximations uses a sigmoidal or power-law-like relation. For example, you can define an effective viscosity μ(γ̇) that grows rapidly once the shear rate γ̇ crosses a threshold γ̇c. The exact formula is not unique, but it should satisfy two requirements: low-shear flow is easy, and high-shear flow becomes strongly resisted. That nonlinear transition is what gives oobleck its “switching” personality.
Rate-dependent viscosity vs viscoelasticity
It is important not to confuse shear thickening with viscoelasticity, even though the two can appear together in real suspensions. Viscoelastic materials store and release elastic energy, often showing spring-like memory effects. Oobleck’s most famous classroom behavior is dominated by a rapid viscosity increase under shear, which is a rheological response rather than a purely elastic one. In our code lab, we will focus on rate-dependent viscosity first, then note where a viscoelastic extension could be added later.
3. Building a Minimal Mathematical Model
A thresholded viscosity law
We want a model that is simple enough to code in a few lines, but expressive enough to show the transition. One practical choice is a smooth step function:
mu(gamma_dot) = mu_low + (mu_high - mu_low) / (1 + exp(-k * (gamma_dot - gamma_c)))
Here, mu_low is the low-shear viscosity, mu_high is the jammed or high-shear viscosity, gamma_c is the transition shear rate, and k controls how sharp the switch is. If k is large, the model behaves more like a sudden jump; if it is smaller, the transition is gradual. This is not a microphysical derivation, but it is an excellent computational surrogate for exploring nonlinear behavior.
Why a smooth function is useful numerically
A hard discontinuity can be awkward in numerical simulation because it may cause unstable updates or sensitivity to step size. A smooth sigmoid avoids those problems while still preserving the core physics of abrupt thickening. In practice, smooth models are also easier to visualize and can help beginners understand how thresholds emerge. This is the same reason many computational workflows use regularization instead of brittle rules, much like careful validation in metadata vetting workflows or clean handoff design in migration playbooks: smoothness helps systems behave predictably.
From viscosity to motion
To see the effect in motion, we need a simple dynamical setting. We will simulate a disk or parcel of fluid subjected to a time-varying shear rate, then use the viscosity model to compute an effective resistance. One convenient choice is to model the velocity response of a driven layer with an equation like dv/dt = (F - c(mu) v)/m, where the drag coefficient depends on viscosity. This is not a full Navier-Stokes simulation, but it captures the idea that the material becomes harder to move as it thickens.
4. Python Setup and Core Simulation Code
Choosing tools
You only need standard scientific Python packages: NumPy for numerical arrays, Matplotlib for plotting, and optionally SciPy if you want smoother integration or parameter fitting. If you have worked through other computational tutorials, you already know the value of a small, testable stack. That approach mirrors the clarity found in practical guides such as cross-platform training systems and postmortem knowledge bases: keep the structure clean before adding complexity.
Core code for the viscosity model
Start with a standalone function:
import numpy as np
def viscosity(gamma_dot, mu_low=1.0, mu_high=100.0, gamma_c=20.0, k=0.4):
return mu_low + (mu_high - mu_low) / (1.0 + np.exp(-k * (gamma_dot - gamma_c)))This function returns a viscosity that stays near mu_low for small shear rates and rises toward mu_high once the threshold is crossed. You can think of gamma_c as the “flip point” where the suspension begins to jam. Before using it in a dynamic simulation, plot the function across a range of shear rates to verify the shape and ensure that the transition is where you expect it to be.
Adding a simple motion equation
Next, define a basic time loop. Suppose a force or drive increases periodically, perhaps like a vibrating spoon or oscillating hand. Then the shear rate can be estimated from the velocity gradient or a proxy such as the drive amplitude. Use the viscosity to compute drag and update velocity with Euler’s method. The following code is intentionally simple so that the logic stays visible:
import numpy as np
import matplotlib.pyplot as plt
m = 1.0
F0 = 8.0
dt = 0.01
T = 20.0
t = np.arange(0, T, dt)
v = np.zeros_like(t)
gamma_dot = np.zeros_like(t)
mu = np.zeros_like(t)
for i in range(1, len(t)):
gamma_dot[i] = abs(v[i-1]) * 30.0
mu[i] = viscosity(gamma_dot[i])
drag = 0.5 * mu[i] * v[i-1]
F = F0 * np.sin(2 * np.pi * 0.7 * t[i])
a = (F - drag) / m
v[i] = v[i-1] + a * dtEven though this is a simplified model, it lets you see how the system responds when viscosity rises in step with shear rate. The result is nonlinear because the drag itself depends on the evolving state, which feeds back into the next step of the simulation. That feedback loop is the heart of the phenomenon.
5. Visualizing the Switching Behavior
Plotting viscosity against shear rate
The first visualization should be the simplest: plot mu versus gamma_dot. This curve is the model’s signature, and it lets you confirm that your chosen parameters create a clear transition. If the rise is too shallow, increase k. If the transition happens too early or too late, adjust gamma_c. Parameter tuning is not just cosmetic; it determines whether your simulation resembles a toy fluid or an actual shear-thickening suspension.
Plotting time series of drive, viscosity, and velocity
To interpret the dynamics, plot the applied force, the velocity, and the effective viscosity on the same time axis. When the force drives the system hard enough, viscosity should climb and velocity should flatten or lag. Under weaker forcing, the system should remain in the low-viscosity regime and respond more freely. This kind of time-series comparison is especially helpful for students because it connects abstract formulas to observable behavior.
Making the threshold obvious
A useful trick is to shade the regions where mu exceeds some threshold value, say 50% of mu_high. That makes the “solid-like” intervals visible in the plot and helps you see exactly when the system switches regimes. If you want to make the visualization more educational, add annotations like “flowing regime” and “jammed regime.” In the same way that tailored content systems or research-driven editorial planning rely on strong visual structure, your physics plots should guide the eye to the important transitions.
Pro Tip: If your curve looks almost linear, your model is too gentle to reveal shear thickening clearly. Increase the transition sharpness, raise the viscosity ratio, or drive the system with a stronger oscillatory force so the simulation crosses the critical shear rate more often.
6. A Better Numerical Workflow: Stability, Timestep, and Diagnostics
Why Euler may be enough at first
Forward Euler is the “hello world” of numerical integration. It is easy to understand and fast to code, which makes it perfect for first-pass experiments. For a model like this, Euler can be adequate if you choose a sufficiently small timestep. The important lesson is that the physics should not be hidden by the numerics; if the timestep is too large, the simulation may create fake oscillations or miss the transition entirely.
Checking timestep sensitivity
Run the simulation with dt values such as 0.05, 0.01, and 0.001. If the main features change drastically, your step size is too coarse. A trustworthy simulation should preserve the broad thickening pattern across reasonable timesteps, even if the fine details shift slightly. In computational physics, this kind of convergence check is as important as the model itself because it tells you whether you are studying the system or just the artifact of your solver.
Diagnostics to log
At minimum, log time, applied force, velocity, shear rate, and viscosity. These variables let you understand the causality chain: force drives motion, motion raises shear rate, shear rate increases viscosity, and viscosity feeds back into motion. If the response seems strange, inspect whether your threshold is too high, your force amplitude too low, or your drag law too weak. Good diagnostics play the same role as the careful monitoring patterns described in operational KPI tracking and alert design: they tell you where the system starts to drift.
7. Interpreting the Model: What It Teaches, and What It Leaves Out
What the model gets right
Even a simple viscosity law can reproduce the most recognizable macroscopic signature of oobleck: easy motion at low stress and resistance at high stress. It also teaches that the transition is not a switch in the binary sense, but a continuous change that can look abrupt when the parameter slope is steep. That is a valuable lesson for students who may assume material behavior is always linear and predictable. Nonlinear systems often look simple until you push them past a threshold.
What the model leaves out
Real oobleck has spatial structure, particle jamming, and possible hysteresis, none of which are fully captured here. We are not modeling boundary layers, particle clustering, or the dependence on concentration and temperature. In a serious research context, you would likely need a more detailed constitutive model or even a discrete particle simulation. Still, the simplified model is not a weakness; it is a pedagogical choice that exposes the mechanism without overwhelming the learner.
When to upgrade the model
If you want to go beyond a first approximation, consider adding hysteresis, where thickening depends on whether the material is being loaded or unloaded. You can also introduce a yield-stress term or a viscoelastic spring-dashpot element to mimic memory effects. Another extension is to couple the viscosity to local packing fraction, which helps connect the macroscopic behavior to microstructure. That kind of progressive refinement is similar in spirit to building a descriptive-to-prescriptive analytics stack or a topic cluster map: start simple, then add layers as the questions become sharper.
8. An Expanded Code Lab: Parameter Sweeps and Scenario Testing
Run multiple viscosities and thresholds
Once the baseline simulation works, explore how the behavior changes when you vary mu_high, gamma_c, and k. This is where the model becomes a real scientific tool rather than a static demo. For instance, a higher mu_high makes the jammed state more dramatic, while a lower gamma_c means the thickening starts earlier. You can run a grid of values and compare the resulting curves, then identify which parameters most strongly control the visual “snap” of the material.
Compare driving amplitudes
Use several force amplitudes and frequencies to see how response changes under weak, moderate, and strong forcing. Low-amplitude forcing may never cross the threshold, producing smooth flow. High-amplitude forcing may repeatedly trigger thickening and make the motion intermittent or locked. These scenarios are especially useful in teaching because they show that the same material can look ordinary or bizarre depending on how you excite it.
Use tables to summarize results
A compact comparison table helps students connect parameter values to outcomes. The goal is not only to run the code but to understand how model choices shape behavior.
| Parameter | Low value effect | High value effect | Physical interpretation |
|---|---|---|---|
mu_high | Mild stiffening | Strong jamming | How resistant the suspension becomes at high shear |
gamma_c | Early switch | Late switch | Shear rate needed before thickening begins |
k | Gradual transition | Sharp transition | How abrupt the thickening appears |
| Drive amplitude | Mostly fluid-like | Frequent thickening | How hard the system is being forced |
Timestep dt | Stable but more compute | Faster but less reliable | Numerical resolution of the dynamics |
This kind of comparison makes model behavior legible, especially for learners who are still developing intuition for nonlinear response. It is also a good reminder that computational physics is as much about experimentation as calculation. If you have ever compared product variants in battery chemistry guides or tested different workflows in fast CI rollback systems, you already know the value of controlled comparisons.
9. From Toy Model to Research Mindset
How students should think about approximation
The point of modeling oobleck in Python is not to reproduce every laboratory detail. The point is to learn how to translate a physical idea into an algorithm and then test whether the outputs make sense. That process is at the heart of computational science. You define a constitutive relation, choose a numerical method, examine the output, and revise the model if the behavior does not match the phenomenon you are trying to capture.
How teachers can use this as a code lab
This exercise works well as a classroom or self-study project because it has multiple entry points. Beginners can focus on plotting the viscosity curve, while more advanced learners can implement the time-stepping simulation and parameter sweeps. Instructors can ask students to modify the threshold function, compare different forms of nonlinearity, or add noise to mimic experimental uncertainty. That layered design is similar to building a stepped learning path in education workflow automation or a structured content series from analyst insights.
How early-career researchers can extend it
If you are preparing for research work, this kind of model is a useful rehearsal for more serious simulation tasks. You practice forming assumptions, testing sensitivity, and explaining why a parameter matters. You also learn how to communicate a model’s limits clearly, which is a core scientific skill. A good researcher knows when a simplified model is sufficient and when the question demands a more sophisticated representation.
10. Step-by-Step Implementation Checklist
Minimal reproducible workflow
Start by coding the viscosity function on its own and plotting mu(gamma_dot). Next, build the simple time evolution loop with a chosen driving force and small timestep. Then run the simulation, inspect the velocity and viscosity time series, and confirm that thickening occurs where expected. Finally, try at least three parameter sweeps to see whether the behavior is robust.
Common mistakes to avoid
One common error is choosing a viscosity contrast that is too small, making the output look nearly Newtonian. Another is setting the threshold so high that the simulation never enters the thickened regime. A third is using an overly large timestep, which can create false instability or hide the transition. Careful debugging is part of the learning process, not a sign that the model is broken.
How to document your results
Write down the parameter values, note the qualitative behavior, and save plots with clear labels. Include units if your chosen proxy variables correspond to physical quantities, and be explicit when you are using nondimensionalized values. Good documentation makes it possible to reproduce and improve the model later, whether you are sharing it in class, a notebook, or a lab report. That habit is one reason good computational practice scales so well across fields, from modular design systems to resilient infrastructure under constraints.
11. FAQ
Is oobleck really a liquid or a solid?
It is best understood as a non-Newtonian suspension whose behavior depends on forcing. Under slow deformation it flows like a liquid, while under rapid stress it can resist motion and appear solid-like. In reality, it is neither purely one nor the other.
Why use a smooth viscosity function instead of a hard switch?
A smooth function is easier to simulate and more stable numerically. It also reflects the fact that real transitions in materials are often gradual over a finite range of shear rates rather than perfectly discontinuous.
Can this model predict actual laboratory measurements?
Not precisely. It is a pedagogical approximation meant to reproduce the main qualitative behavior. For laboratory accuracy, you would need experimental data, parameter fitting, and likely a more advanced rheological model.
How is shear thickening different from shear thinning?
Shear thickening means viscosity increases with shear rate, while shear thinning means viscosity decreases with shear rate. Both are non-Newtonian behaviors, but they produce opposite responses under stress.
What would be the next step after this code lab?
A natural next step is to add spatial structure, hysteresis, or a viscoelastic element, then compare the results against experimental data. You could also switch from a toy ODE to a 1D or 2D field model if you want to study local variations in flow.
12. Conclusion: Why This Simulation Is Worth Learning
Physics intuition through code
Modeling oobleck in Python is valuable because it turns a memorable demo into a computational lesson about nonlinear response. You learn that materials can change behavior dramatically when a threshold is crossed, and that a modest mathematical model can still reveal important physics. This is the kind of problem that rewards curiosity, iteration, and visualization.
What you should take away
The essential ideas are simple: define a rate-dependent viscosity, couple it to motion, and inspect the switching behavior under different forcing conditions. Once you can do that, you have the foundation for exploring more advanced rheological models and potentially even viscoelasticity. The bigger lesson is methodological: start with a minimal model, test it carefully, and expand only when the physics demands it.
Where to go next
If you want to deepen the learning path, explore related resources on computational modeling, scientific workflows, and structured analysis. Useful next steps include designing modular computational systems, understanding spike-driven traffic patterns, and building trust through rigorous explanation. In physics, as in code, clarity wins: when your model is transparent, your conclusions become much easier to trust.
Related Reading
- Oobleck still holds some surprises - A timely look at why this classic suspension remains scientifically interesting.
- Open-Source Quantum Software Tools: Maturity, Ecosystem and Adoption Tips - A useful lens on building reliable scientific software habits.
- Choosing LLMs for Reasoning-Intensive Workflows: An Evaluation Framework - A model for evaluating systems carefully before trusting outputs.
- Trust but Verify: How Engineers Should Vet LLM-Generated Table and Column Metadata from BigQuery - A reminder that validation matters in any computational workflow.
- Building a Postmortem Knowledge Base for AI Service Outages - A strong example of structured diagnosis and reproducible learning.
Related Topics
Daniel Mercer
Senior Physics Editor
Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.
Up Next
More stories handpicked for you
Teaching in the Age of ChatGPT: What Students and Instructors Need to Understand
Can AI Peer Review Science Without Breaking It?
From Wardrobes to Wormholes: Science Fiction as a Gateway to Modern Physics
How to Build Better Physics Revision Materials with AI: A Practical Workflow for Students
What Does It Mean to Be Conscious? A Physics Perspective on Brain States and Measurement
From Our Network
Trending stories across our publication group