Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FESTIM 1.3 update #56

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ dependencies:
- numpy==1.24
- pip>=20.1
- ipykernel
- nbconvert
- pip:
- festim==1.2
- festim==1.3
- pyparsing
- h-transport-materials==0.12.7
- nbconvert
- h-transport-materials==0.12.7
135 changes: 53 additions & 82 deletions tasks/task01.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.2.2.dev242+gb884fdf\n"
]
}
],
"source": [
"import festim as F"
"import festim as F\n",
"\n",
"print(F.__version__)"
]
},
{
Expand Down Expand Up @@ -64,7 +74,7 @@
"FESTIM simulations need a mesh. FESTIM provides support for simple 1D meshes. More complicated meshes can be imported from external software (see [Task 7](https://github.com/festim-dev/FESTIM-workshop/blob/main/tasks/task07.ipynb)).\n",
"\n",
"The most straightforward mesh is `MeshFromVertices`, which takes a `vertices` argument.\n",
"Here's a simple mesh with 4 cells:"
"Here's a simple mesh with a few vertices:"
]
},
{
Expand All @@ -75,7 +85,7 @@
{
"data": {
"text/plain": [
"<festim.meshing.mesh_from_vertices.MeshFromVertices at 0x7f1cacb55810>"
"<festim.meshing.mesh_from_vertices.MeshFromVertices at 0x7f07d47bc4d0>"
]
},
"execution_count": 3,
Expand All @@ -92,7 +102,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Numpy can be used to generate heavier meshes. Here we create a mesh containing 1000 cells over a [0, 7e-6] domain (7 $\\mu m$).\n",
"Numpy can be used to generate heavier meshes. Here we create a mesh containing 1000 cells over a [0, 7e-6] domain (7 microns).\n",
"\n",
"This mesh is assigned to the simulation by setting the `.mesh` attribute of `my_model`."
]
Expand All @@ -105,9 +115,7 @@
"source": [
"import numpy as np\n",
"\n",
"my_model.mesh = F.MeshFromVertices(\n",
" vertices=np.linspace(0, 7e-6, num=1001)\n",
")"
"my_model.mesh = F.MeshFromVertices(vertices=np.linspace(0, 7e-6, num=1001))"
]
},
{
Expand Down Expand Up @@ -194,11 +202,7 @@
"outputs": [],
"source": [
"my_model.boundary_conditions = [\n",
" F.DirichletBC(\n",
" surfaces=[1,2],\n",
" value=1e15, # H/m3/s\n",
" field=0\n",
" )\n",
" F.DirichletBC(surfaces=[1, 2], value=1e15, field=0) # H/m3/s\n",
"]\n",
"\n",
"\n",
Expand Down Expand Up @@ -234,25 +238,28 @@
"outputs": [],
"source": [
"my_model.settings = F.Settings(\n",
" absolute_tolerance=1e10,\n",
" relative_tolerance=1e-10,\n",
" final_time=2 # s\n",
" )"
" absolute_tolerance=1e10, relative_tolerance=1e-10, final_time=2 # s\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Stepsize\n",
"## 6. Exports\n",
"\n",
"Since we are solving a transient problem, we need to set a ``Stepsize``.\n",
"Here, the value of the stepsize is fixed at 0.1.\n",
"Finally, we want to be able to visualise the concentration field.\n",
"To do so, we add an `XDMFExport` object which will export the concentration field at each timestep to an XDMF file.\n",
"This XDMF file can then be read in [Paraview](https://www.paraview.org/).\n",
"\n",
"- `field`: the field we want to export. Here, `\"solute\"` stands for the mobile concentration of hydrogen. It could be ``\"retention\"``, ``\"1\"`` (trap 1), ``\"T\"`` (temperature)\n",
"\n",
"- `filename`: the path to the exported file\n",
"\n",
"> Note:\n",
">\n",
"> Transient simulations can be accelerated with adaptive stepsize. See [Task 2](https://github.com/festim-dev/FESTIM-workshop/blob/main/tasks/task02.ipynb)"
"> For 1D fields, the `checkpoint` attribute needs to be set to ``False`` to be visualised in Paraview. Refer to [this issue](https://github.com/festim-dev/FESTIM/issues/134). "
]
},
{
Expand All @@ -261,27 +268,36 @@
"metadata": {},
"outputs": [],
"source": [
"my_model.dt = F.Stepsize(0.05) # s"
"results_folder = \"task01\"\n",
"my_model.exports = [\n",
" F.XDMFExport(\n",
" field=\"solute\",\n",
" filename=results_folder + \"/hydrogen_concentration.xdmf\",\n",
" checkpoint=False, # needed in 1D\n",
" ),\n",
" F.TXTExport(\n",
" field=\"solute\",\n",
" times=[0.1, 0.2, 0.5, 1],\n",
" filename=results_folder + \"/mobile_concentration.txt\",\n",
" ),\n",
"]"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. Exports\n",
"## 7. Stepsize\n",
"\n",
"Finally, we want to be able to visualise the concentration field.\n",
"To do so, we add an `XDMFExport` object which will export the concentration field at each timestep to an XDMF file.\n",
"This XDMF file can then be read in [Paraview](https://www.paraview.org/).\n",
"\n",
"- `field`: the field we want to export. Here, `\"solute\"` stands for the mobile concentration of hydrogen. It could be ``\"retention\"``, ``\"1\"`` (trap 1), ``\"T\"`` (temperature)\n",
"Since we are solving a transient problem, we need to set a ``Stepsize``.\n",
"Here, the value of the stepsize is fixed at 0.05.\n",
"\n",
"- `filename`: the path to the exported file\n",
"We also add ``milestones`` to ensure the simulation passes by specific times.\n",
"\n",
"> Note:\n",
">\n",
"> For 1D fields, the `checkpoint` attribute needs to be set to ``False`` to be visualised in Paraview. Refer to [this issue](https://github.com/festim-dev/FESTIM/issues/134). "
"> Transient simulations can be accelerated with adaptive stepsize. See [Task 2](https://github.com/festim-dev/FESTIM-workshop/blob/main/tasks/task02.ipynb)"
]
},
{
Expand All @@ -290,15 +306,7 @@
"metadata": {},
"outputs": [],
"source": [
"results_folder = \"task01\"\n",
"my_model.exports = [\n",
" F.XDMFExport(\n",
" field=\"solute\",\n",
" filename=results_folder + \"/hydrogen_concentration.xdmf\",\n",
" checkpoint=False # needed in 1D\n",
" ),\n",
" F.TXTExport(field=\"solute\", times=[0.1, 0.2, 0.5, 1], filename=results_folder+\"/mobile_concentration.txt\")\n",
"]"
"my_model.dt = F.Stepsize(0.05, milestones=[0.1, 0.2, 0.5, 1]) # s"
]
},
{
Expand All @@ -320,44 +328,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Defining initial values\n",
"Defining variational problem\n",
"Defining source terms\n",
"Defining boundary conditions\n",
"Time stepping...\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/remidm/miniconda3/envs/festim-workshop/lib/python3.11/site-packages/festim/generic_simulation.py:334: UserWarning: To ensure that TXTExport exports data at the desired times TXTExport.times are added to milestones\n",
" warnings.warn(msg)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"100.0 % 2.0e+00 s Ellapsed time so far: 3.4 s\n"
"100.0 % 2.0e+00 s Elapsed time so far: 0.2 s\n"
]
}
],
Expand Down Expand Up @@ -407,6 +383,7 @@
"plt.plot(data[:, 0], data[:, 3], label=\"0.5 s\")\n",
"plt.plot(data[:, 0], data[:, 2], label=\"0.2 s\")\n",
"plt.plot(data[:, 0], data[:, 1], label=\"0.1 s\")\n",
"\n",
"plt.xlabel(\"x (m)\")\n",
"plt.ylabel(\"Mobile concentration (H/m3)\")\n",
"plt.legend()\n",
Expand All @@ -431,7 +408,9 @@
"my_model.dt = None\n",
"\n",
"my_model.exports = [\n",
" F.TXTExport(field=\"solute\", filename=results_folder+\"/mobile_concentration_steady.txt\")\n",
" F.TXTExport(\n",
" field=\"solute\", filename=results_folder + \"/mobile_concentration_steady.txt\"\n",
" )\n",
"]"
]
},
Expand All @@ -449,15 +428,7 @@
"Defining source terms\n",
"Defining boundary conditions\n",
"Solving steady state problem...\n",
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calling FFC just-in-time (JIT) compiler, this may take some time.\n",
"Solved problem in 0.50 s\n"
"Solved problem in 0.00 s\n"
]
}
],
Expand Down
18 changes: 2 additions & 16 deletions tasks/task02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
"derived_quantities = F.DerivedQuantities(\n",
" list_of_derived_quantities,\n",
" # filename=\"tds/derived_quantities.csv\" # optional set a filename to export the data to csv\n",
" show_units=True,\n",
")\n",
"\n",
"\n",
Expand All @@ -330,22 +331,7 @@
"Defining source terms\n",
"Defining boundary conditions\n",
"Time stepping...\n",
"1.1 % 5.7e+00 s Ellapsed time so far: 0.2 s\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/remidm/miniconda3/envs/festim-workshop/lib/python3.11/site-packages/festim/exports/derived_quantities/derived_quantities.py:49: DeprecationWarning: The derived_quantities attribute will be deprecated in a future release, please use festim.DerivedQuantities as a list instead\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"100.0 % 5.0e+02 s Ellapsed time so far: 3.3 s\n"
"100.0 % 5.0e+02 s Elapsed time so far: 3.1 s\n"
]
}
],
Expand Down
32 changes: 4 additions & 28 deletions tasks/task03.ipynb

Large diffs are not rendered by default.

31 changes: 4 additions & 27 deletions tasks/task04.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"source": [
"folder = 'task04'\n",
"\n",
"derived_quantities_with_barrier = F.DerivedQuantities([F.HydrogenFlux(surface=2)])\n",
"derived_quantities_with_barrier = F.DerivedQuantities([F.HydrogenFlux(surface=2)], show_units=True)\n",
"\n",
"txt_export = F.TXTExport(\n",
" field='solute',\n",
Expand Down Expand Up @@ -236,22 +236,7 @@
"Defining source terms\n",
"Defining boundary conditions\n",
"Time stepping...\n",
"0.2 % 1.9e+03 s Ellapsed time so far: 0.2 s\r"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/remidm/miniconda3/envs/festim-workshop/lib/python3.11/site-packages/festim/exports/derived_quantities/derived_quantities.py:49: DeprecationWarning: The derived_quantities attribute will be deprecated in a future release, please use festim.DerivedQuantities as a list instead\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"100.0 % 8.0e+05 s Ellapsed time so far: 0.6 s\n"
"100.0 % 8.0e+05 s Elapsed time so far: 0.6 s\n"
]
}
],
Expand Down Expand Up @@ -340,15 +325,7 @@
"Defining source terms\n",
"Defining boundary conditions\n",
"Time stepping...\n",
"100.0 % 8.0e+05 s Ellapsed time so far: 0.2 s\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/remidm/miniconda3/envs/festim-workshop/lib/python3.11/site-packages/festim/exports/derived_quantities/derived_quantities.py:49: DeprecationWarning: The derived_quantities attribute will be deprecated in a future release, please use festim.DerivedQuantities as a list instead\n",
" warnings.warn(\n"
"100.0 % 8.0e+05 s Elapsed time so far: 0.2 s\n"
]
}
],
Expand All @@ -374,7 +351,7 @@
"\n",
"model_no_barrier.dt = model_barrier.dt\n",
"\n",
"derived_quantities_without_barrier = F.DerivedQuantities([F.HydrogenFlux(surface=2)])\n",
"derived_quantities_without_barrier = F.DerivedQuantities([F.HydrogenFlux(surface=2)], show_units=True)\n",
"\n",
"model_no_barrier.exports = [derived_quantities_without_barrier]\n",
"\n",
Expand Down
Loading
Loading