{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Cahn-Hilliard Example\n", "\n", "This example demonstrates how to use PyMKS to solve the Cahn-Hilliard equation. The first section provides some background information about the Cahn-Hilliard equation as well as details about calibrating and validating the MKS model. The example demonstrates how to generate sample data, calibrate the influence coefficients and then pick an appropriate number of local states when state space is continuous. The MKS model and a spectral solution of the Cahn-Hilliard equation are compared on a larger test microstructure over multiple time steps." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Cahn-Hilliard Equation\n", "\n", "The Cahn-Hilliard equation is used to simulate microstructure evolution during spinodial decomposition and has the following form,\n", "\n", "$$ \\dot{\\phi} = \\nabla^2 \\left( \\phi^3 - \\phi \\right) - \\gamma \\nabla^4 \\phi $$\n", "\n", "where $\\phi$ is a conserved ordered parameter and $\\sqrt{\\gamma}$ represents the width of the interface. In this example, the Cahn-Hilliard equation is solved using a semi-implicit spectral scheme with periodic boundary conditions, see [Chang and Rutenberg](http://dx.doi.org/10.1103/PhysRevE.72.055701) for more details." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": false }, "outputs": [], "source": [ "import warnings\n", "warnings.filterwarnings('ignore')\n", "import numpy\n", "import dask.array as da\n", "import matplotlib.pyplot as plt\n", "from dask_ml.model_selection import train_test_split, GridSearchCV\n", "from distributed import Client\n", "from sklearn.pipeline import Pipeline\n", "\n", "from pymks import (\n", " solve_cahn_hilliard,\n", " plot_microstructures,\n", " PrimitiveTransformer,\n", " LocalizationRegressor,\n", " ReshapeTransformer,\n", " coeff_to_real\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n",
"Client\n", "
| \n",
"\n",
"Cluster\n", "
| \n",
"
\n",
"
| \n",
"\n", "\n", " | \n", "
\n",
"
| \n",
"\n", "\n", " | \n", "