From f41b15d484f847e4563477f11ca63733562f3823 Mon Sep 17 00:00:00 2001
From: Ian Bell <ian.bell@nist.gov>
Date: Sat, 5 Nov 2022 10:33:01 -0400
Subject: [PATCH] Docs for make_model

---
 doc/source/models/make_model.ipynb | 113 +++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)
 create mode 100644 doc/source/models/make_model.ipynb

diff --git a/doc/source/models/make_model.ipynb b/doc/source/models/make_model.ipynb
new file mode 100644
index 0000000..419ea17
--- /dev/null
+++ b/doc/source/models/make_model.ipynb
@@ -0,0 +1,113 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "id": "0f7ef656",
+   "metadata": {},
+   "source": [
+    "# Constructing Models\n",
+    "\n",
+    "With a few exceptions, most models are constructed by describing the model in JSON format, and passing the JSON-formatted information to the ``make_model`` function.  There are some convenience functions exposed for backwards compatibility, but as of version 0.14.0, all model construction should go via this route.\n",
+    "\n",
+    "At the C++ level, the returned value from the ``make_model`` function is a ``shared_ptr`` that wraps a pointer to an ``AbstractModel`` class.  The ``AbstractModel`` class is an abstract class which defines the public C++ interface.\n",
+    "\n",
+    "In Python, construction is in two parts. First, the model is constructed, which only includes the common methods.  Then, the model-specific attributes and methods are attached with the ``attach_model_specific_methods`` method.\n",
+    "\n",
+    "The JSON structure is of two parts, the ``kind`` field is a case-sensitive string defining which model kind is being constructed, and the ``model`` field contains all the information needed to build the model. In the case of hard-coded models, nothing is provided in the ``model`` field, but it must still be provided.\n",
+    "\n",
+    "Also, the argument to ``make_model`` must be valid JSON. So if you are working with numpy array datatypes, make sure to convert them to a list (which is convertible to JSON). Example below."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "d3ab9d9c",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import teqp, numpy as np\n",
+    "teqp.__version__"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "39bd96e0",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "teqp.make_model({'kind': 'vdW1', 'model': {'a': 1, 'b': 2}})"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "45d41b7f",
+   "metadata": {
+    "tags": [
+     "raises-exception"
+    ]
+   },
+   "outputs": [],
+   "source": [
+    "# Fields are case-sensitive\n",
+    "teqp.make_model({'kind': 'vdW1', 'model': {'a': 1, 'B': 2}})"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "907f3619",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# A hard-coded model\n",
+    "teqp.make_model({\n",
+    "    'kind': 'AmmoniaWaterTillnerRoth', \n",
+    "    'model': {}\n",
+    "})"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "800b86f4",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Show what to do with numpy array\n",
+    "Tc_K = np.array([100,200])\n",
+    "pc_Pa = np.array([3e6, 4e6])\n",
+    "teqp.make_model({\n",
+    "    \"kind\": \"vdW\", \n",
+    "    \"model\": {\n",
+    "        \"Tcrit / K\": Tc_K.tolist(), \n",
+    "        \"pcrit / Pa\": pc_Pa.tolist()\n",
+    "    }\n",
+    "})"
+   ]
+  }
+ ],
+ "metadata": {
+  "celltoolbar": "Tags",
+  "kernelspec": {
+   "display_name": "Python 3 (ipykernel)",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.10.6"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
-- 
GitLab