Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusgh committed Oct 2, 2024
1 parent 691ef05 commit 4f670e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 52 deletions.
5 changes: 1 addition & 4 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ Examples
--------

.. nbgallery::
examples/reproduce_article
examples/material_parameters
examples/truncate_ntfa_modes
examples/paper_plots
examples/generate_inputs
examples/generate_plots
examples/NTFA_thermo_paper
examples/thermoNTFA_example
63 changes: 28 additions & 35 deletions examples/truncate_ntfa_modes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@
}
],
"source": [
"fname = os.path.join(\n",
" data_path, \"validation\", \"simple_3d_rve_B1-B6_16x16x16_10samples_fix.h5\"\n",
")\n",
"fname = os.path.join(data_path, \"ntfa_raw\", \"rve_thermoplastic_6loadings_10samples.h5\")\n",
"basename = \"/ms_9p/dset0_ntfa/\"\n",
"\n",
"F = h5py.File(fname, \"r\")\n",
Expand Down Expand Up @@ -215,12 +213,6 @@
"print(XX)"
]
},
{
"cell_type": "markdown",
"id": "1644aa44",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 9,
Expand Down Expand Up @@ -268,12 +260,6 @@
"print(C_bar[0, :, :])"
]
},
{
"cell_type": "markdown",
"id": "8840c9e8",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 11,
Expand Down Expand Up @@ -302,38 +288,37 @@
"print(\"error:\", xx / np.linalg.norm(x))"
]
},
{
"cell_type": "markdown",
"id": "89aa604a",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 12,
"id": "260bb68a",
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] Unable to synchronously create file (unable to open file: name = 'data_new/ms9p_fix_ntfa16_B1-6_10s_N24.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 242)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[12], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# print((C_bar[0,:,:]), tau_theta[0,:])\u001b[39;00m\n\u001b[1;32m 2\u001b[0m fname \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdata_new/ms9p_fix_ntfa16_B1-6_10s_N\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mNmax\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.h5\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 3\u001b[0m F \u001b[38;5;241m=\u001b[39m \u001b[43mh5py\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mFile\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mw\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4\u001b[0m F\u001b[38;5;241m.\u001b[39mcreate_dataset(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSIG_phases\u001b[39m\u001b[38;5;124m\"\u001b[39m, data\u001b[38;5;241m=\u001b[39msig_ph)\n\u001b[1;32m 5\u001b[0m F\u001b[38;5;241m.\u001b[39mcreate_dataset(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mC_phases\u001b[39m\u001b[38;5;124m\"\u001b[39m, data\u001b[38;5;241m=\u001b[39mC_ph)\n",
"File \u001b[0;32m~/Documents/ThermoNTFA/venv/lib/python3.11/site-packages/h5py/_hl/files.py:562\u001b[0m, in \u001b[0;36mFile.__init__\u001b[0;34m(self, name, mode, driver, libver, userblock_size, swmr, rdcc_nslots, rdcc_nbytes, rdcc_w0, track_order, fs_strategy, fs_persist, fs_threshold, fs_page_size, page_buf_size, min_meta_keep, min_raw_keep, locking, alignment_threshold, alignment_interval, meta_block_size, **kwds)\u001b[0m\n\u001b[1;32m 553\u001b[0m fapl \u001b[38;5;241m=\u001b[39m make_fapl(driver, libver, rdcc_nslots, rdcc_nbytes, rdcc_w0,\n\u001b[1;32m 554\u001b[0m locking, page_buf_size, min_meta_keep, min_raw_keep,\n\u001b[1;32m 555\u001b[0m alignment_threshold\u001b[38;5;241m=\u001b[39malignment_threshold,\n\u001b[1;32m 556\u001b[0m alignment_interval\u001b[38;5;241m=\u001b[39malignment_interval,\n\u001b[1;32m 557\u001b[0m meta_block_size\u001b[38;5;241m=\u001b[39mmeta_block_size,\n\u001b[1;32m 558\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds)\n\u001b[1;32m 559\u001b[0m fcpl \u001b[38;5;241m=\u001b[39m make_fcpl(track_order\u001b[38;5;241m=\u001b[39mtrack_order, fs_strategy\u001b[38;5;241m=\u001b[39mfs_strategy,\n\u001b[1;32m 560\u001b[0m fs_persist\u001b[38;5;241m=\u001b[39mfs_persist, fs_threshold\u001b[38;5;241m=\u001b[39mfs_threshold,\n\u001b[1;32m 561\u001b[0m fs_page_size\u001b[38;5;241m=\u001b[39mfs_page_size)\n\u001b[0;32m--> 562\u001b[0m fid \u001b[38;5;241m=\u001b[39m \u001b[43mmake_fid\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muserblock_size\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfapl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfcpl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mswmr\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mswmr\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 564\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(libver, \u001b[38;5;28mtuple\u001b[39m):\n\u001b[1;32m 565\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_libver \u001b[38;5;241m=\u001b[39m libver\n",
"File \u001b[0;32m~/Documents/ThermoNTFA/venv/lib/python3.11/site-packages/h5py/_hl/files.py:241\u001b[0m, in \u001b[0;36mmake_fid\u001b[0;34m(name, mode, userblock_size, fapl, fcpl, swmr)\u001b[0m\n\u001b[1;32m 239\u001b[0m fid \u001b[38;5;241m=\u001b[39m h5f\u001b[38;5;241m.\u001b[39mcreate(name, h5f\u001b[38;5;241m.\u001b[39mACC_EXCL, fapl\u001b[38;5;241m=\u001b[39mfapl, fcpl\u001b[38;5;241m=\u001b[39mfcpl)\n\u001b[1;32m 240\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mw\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m--> 241\u001b[0m fid \u001b[38;5;241m=\u001b[39m \u001b[43mh5f\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mh5f\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mACC_TRUNC\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfapl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfapl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfcpl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfcpl\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 242\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 243\u001b[0m \u001b[38;5;66;03m# Open in append mode (read/write).\u001b[39;00m\n\u001b[1;32m 244\u001b[0m \u001b[38;5;66;03m# If that fails, create a new file only if it won't clobber an\u001b[39;00m\n\u001b[1;32m 245\u001b[0m \u001b[38;5;66;03m# existing one (ACC_EXCL)\u001b[39;00m\n\u001b[1;32m 246\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
"File \u001b[0;32mh5py/_objects.pyx:54\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32mh5py/_objects.pyx:55\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32mh5py/h5f.pyx:122\u001b[0m, in \u001b[0;36mh5py.h5f.create\u001b[0;34m()\u001b[0m\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] Unable to synchronously create file (unable to open file: name = 'data_new/ms9p_fix_ntfa16_B1-6_10s_N24.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 242)"
"name": "stdout",
"output_type": "stream",
"text": [
"[-2.91058179e-04 -2.91058179e-04 -2.91058179e-04 7.56424908e-07\n",
" 7.56424908e-07 7.56424908e-07]\n",
"[[-4.09384219e+04 -4.09384219e+04 -4.09384219e+04 5.84757940e+00\n",
" 5.84757940e+00 5.84757940e+00]\n",
" [-4.67906106e+04 -4.67906106e+04 -4.67906106e+04 6.68330174e+00\n",
" 6.68330174e+00 6.68330174e+00]\n",
" [-5.26422371e+04 -5.26422371e+04 -5.26422371e+04 7.51886249e+00\n",
" 7.51886249e+00 7.51886249e+00]\n",
" ...\n",
" [-4.58740710e+05 -4.58740710e+05 -4.58740712e+05 -1.14949438e+03\n",
" -1.14949447e+03 -1.14949439e+03]\n",
" [-4.43545699e+05 -4.43545699e+05 -4.43545699e+05 -1.12134182e+03\n",
" -1.12134185e+03 -1.12134183e+03]\n",
" [-4.28268141e+05 -4.28268141e+05 -4.28268141e+05 -1.09241643e+03\n",
" -1.09241643e+03 -1.09241643e+03]]\n"
]
}
],
"source": [
"# print((C_bar[0,:,:]), tau_theta[0,:])\n",
"fname = f\"data_new/ms9p_fix_ntfa16_B1-6_10s_N{Nmax}.h5\"\n",
"fname = os.path.join(data_path, \"ntfa\", f\"ntfa_6loadings_10samples_N{Nmax}.h5\")\n",
"F = h5py.File(fname, \"w\")\n",
"F.create_dataset(\"SIG_phases\", data=sig_ph)\n",
"F.create_dataset(\"C_phases\", data=C_ph)\n",
Expand All @@ -351,6 +336,14 @@
"print(eps_th_500)\n",
"print(tau_theta)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "206024f5-ec26-4c00-8a35-02ebb7a4e6aa",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
17 changes: 4 additions & 13 deletions examples/truncate_ntfa_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
data_path = "../data"

# %%
fname = os.path.join(
data_path, "validation", "simple_3d_rve_B1-B6_16x16x16_10samples_fix.h5"
)
fname = os.path.join(data_path, "ntfa_raw", "rve_thermoplastic_6loadings_10samples.h5")
basename = "/ms_9p/dset0_ntfa/"

F = h5py.File(fname, "r")
Expand Down Expand Up @@ -103,9 +101,6 @@
XX = A.T @ np.linalg.pinv(A @ A.T) @ A
print(XX)

# %% [markdown]
#

# %%
# print(( vol_frac[1]*A1[0,:,:7]+vol_frac[0]*A0[0,:,:7]) )
x = C_bar[0, :, :].flatten()
Expand All @@ -119,20 +114,14 @@
print("c_Bar:")
print(C_bar[0, :, :])

# %% [markdown]
#

# %%
xx = alpha * x0 + (1 - alpha) * x1
# print(xx.reshape((6,6))-C_bar[0,:,:])
print("error:", xx / np.linalg.norm(x))

# %% [markdown]
#

# %%
# print((C_bar[0,:,:]), tau_theta[0,:])
fname = f"data_new/ms9p_fix_ntfa16_B1-6_10s_N{Nmax}.h5"
fname = os.path.join(data_path, "ntfa", f"ntfa_6loadings_10samples_N{Nmax}.h5")
F = h5py.File(fname, "w")
F.create_dataset("SIG_phases", data=sig_ph)
F.create_dataset("C_phases", data=C_ph)
Expand All @@ -149,3 +138,5 @@
eps_th_500 = np.linalg.solve(C_bar[20, :, :], tau_theta[20, :])
print(eps_th_500)
print(tau_theta)

# %%

0 comments on commit 4f670e7

Please sign in to comment.