generated from feelpp/feelpp-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploying to gh-pages from @ 87e8a6b 🚀
- Loading branch information
Showing
3 changed files
with
18 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells":[{"cell_type":"markdown","source":["# {project_name} Notebook\n\n","This is a Jupyter notebook for the {project_name} project.\n\n","## Introduction\n\n","You write your notebook in AsciiDoc including LaTeX math and thanks to the `:page-jupyter: true` attribute, the notebook is converted to a Jupyter notebook when the book is built.\n","## Code cells\n\n","You can include code cells in your notebook using the `[source,python]` block macro.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import sys, os\n","print(\"Hello, world!\")\n"]},{"cell_type":"markdown","source":["## {feelpp} Code cells\n\n","You can include {feelpp} code cells in your notebook using the `[source,python]` block macro.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import feelpp\n","app = feelpp.Environment([\"myapp\"],config=feelpp.globalRepository(\"myapp\"))\n","\n","geo=feelpp.download( \"github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}\", worldComm=app.worldCommPtr() )[0]\n","print(\"geo file: {}\".format(geo))\n","mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), geo, 0.1)\n","\n","Xh=feelpp.functionSpace(mesh=mesh, space=\"Pchv\")\n","f = Xh.element()\n","f.on(range=feelpp.elements(mesh),expr=feelpp.expr(\"{sin(pi*x)*sin(pi*y),cos(pi*x)*cos(pi*y)}:x:y\",row=2,col=1))\n","e= feelpp.exporter(mesh=mesh)\n","e.add(\"f\",f)\n","e.save()\n"]},{"cell_type":"markdown","source":["You can then visualize the result using the `pyvista` package as follows:\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["from xvfbwrapper import Xvfb\n","vdisplay = Xvfb()\n","vdisplay.start()\n","\n","import pyvista as pv\n","pv.set_jupyter_backend('panel')\n","reader = pv.get_reader(\"exports/ensightgold/Exporter/Exporter.case\")\n","mesh = reader.read()\n","mesh.plot(scalars=\"f\",show_edges=True)\n"]}],"metadata":{"language_info":{"name":"python","version":"3.9.1"}},"nbformat":4,"nbformat_minor":4} | ||
{"cells":[{"cell_type":"markdown","source":["# {project_name} Notebook\n\n","This is a Jupyter notebook for the {project_name} project.\n\n","## Introduction\n\n","You write your notebook in AsciiDoc including LaTeX math and thanks to the `:page-jupyter: true` attribute, the notebook is converted to a Jupyter notebook when the book is built.\n","## Code cells\n\n","You can include code cells in your notebook using the `[source,python]` block macro.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import sys, os\n","print(\"Hello, world!\")\n"]},{"cell_type":"markdown","source":["## {feelpp} Code cells\n\n","You can include {feelpp} code cells in your notebook using the `[source,python]` block macro.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import feelpp\n","app = feelpp.Environment([\"myapp\"],config=feelpp.globalRepository(\"myapp\"))\n","\n","geo=feelpp.download( \"github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}\", worldComm=app.worldCommPtr() )[0]\n","print(\"geo file: {}\".format(geo))\n","mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), geo, 0.1)\n","\n","Xh=feelpp.functionSpace(mesh=mesh, space=\"Pchv\")\n","f = Xh.element()\n","f.on(range=feelpp.elements(mesh),expr=feelpp.expr(\"{sin(pi*x)*sin(pi*y),cos(pi*x)*cos(pi*y)}:x:y\",row=2,col=1))\n","e= feelpp.exporter(mesh=mesh)\n","e.add(\"f\",f)\n","e.save()\n"]},{"cell_type":"markdown","source":["You can then visualize the result using the `pyvista` package as follows:\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["from xvfbwrapper import Xvfb\n","vdisplay = Xvfb()\n","vdisplay.start()\n","\n","import pyvista as pv\n","pv.set_jupyter_backend('panel')\n","reader = pv.get_reader(\"exports/ensightgold/Exporter/Exporter.case\")\n","mesh = reader.read()\n","mesh.plot(scalars=\"f\",show_edges=True)\n"]}],"metadata":{"language_info":{"name":"python","version":"3.9.1"},"kernelspec":{"name":"python3","language":"python"}},"nbformat":4,"nbformat_minor":4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells":[{"cell_type":"markdown","source":["# Thermal fin\n\n","## Problem statement\n\n","We consider the problem of designing a thermal fin to effectively remove heat from a surface. The two-dimensional fin, shown in Figure below, consists of a vertical central post and four horizontal subfins; the fin conducts heat from a prescribed uniform flux source at the root, $\\Gamma_{\\text {root }}$, through the large-surface-area subfins to surrounding flowing air. The fin is characterized by a five-component parameter vector, or input, $\\mu_{=}\\left(\\mu_1, \\mu_2, \\ldots, \\mu_5\\right)$, where $\\mu_i=k^i, i=1, \\ldots, 4$, and $\\mu_5=\\mathrm{Bi} ; \\mu$ may take on any value in a specified design set $D \\subset \\mathbb{R}^5$.\n","\n","![ROOT:fin2d 4 mesh](ROOT:fin2d-4-mesh.png)\n","\n","Here $k^i$ is the thermal conductivity of the ith subfin (normalized relative to the post conductivity $k^0 \\equiv 1$ ); and $\\mathrm{Bi}$ is the Biot number, a nondimensional heat transfer coefficient reflecting convective transport to the air at the fin surfaces (larger $\\mathrm{Bi}$ means better heat transfer). For example, suppose we choose a thermal fin with $k^1=0.4, k^2=0.6, k^3=0.8, k^4=1.2$, and $\\mathrm{Bi}=0.1$; for this particular configuration $\\mu=\\{0.4,0.6,0.8,1.2,0.1\\}$, which corresponds to a single point in the set of all possible configurations D (the parameter or design set). The post is of width unity and height four; the subfins are of fixed thickness $t=0.25$ and length $L=2.5$.\n","We are interested in the design of this thermal fin, and we thus need to look at certain outputs or cost-functionals of the temperature as a function of $\\mu$. We choose for our output $T_{\\text {root }}$, the average steady-state temperature of the fin root normalized by the prescribed heat flux into the fin root. The particular output chosen relates directly to the cooling efficiency of the fin lower values of $T_{\\text {root }}$ imply better thermal performance. The steadystate temperature distribution within the fin, $u(\\mu)$, is governed by the elliptic partial differential equation\n","\n$$\n\\rho_i C_i \\frac{\\partial u^i}{\\partial t} -k^i \\Delta u^i=0 \\text { in } \\Omega^i, i=0, \\ldots, 4,\n$$\n","where $\\Delta$ is the Laplacian operator, and $u_i$ refers to the restriction of $u$ to $\\Omega^i$.\n","Here $\\Omega^i$ is the region of the fin with conductivity $k^i, i=0, \\ldots, 4$ and volumetric heat capacity $(\\rho C)_i, i=0, \\cdots, 4$: $\\Omega^0$ is thus the central post, and $\\Omega^i, i=1, \\ldots, 4$, corresponds to the four subfins.\n","The entire fin domain is denoted $\\Omega\\left(\\bar{\\Omega}=\\cup_{i=0}^4 \\bar{\\Omega}^i\\right)$; the boundary $\\Omega$ is denoted $\\Gamma$. We must also ensure continuity of temperature and heat flux at the conductivity discontinuity interfaces $\\Gamma_{\\text {int }}^i \\equiv \\partial \\Omega^0 \\cap \\partial \\Omega^i, i=1, \\ldots, 4$, where $\\partial \\Omega^i$ denotes the boundary of $\\Omega^i$, we have on $\\Gamma_{\\text {int }}^i i=1, \\ldots, 4$ :\n","\n$$\n\\begin{aligned}\nu^0 & =u^i \\\\\n-\\left(\\nabla u^0 \\cdot n^i\\right) & =-k^i\\left(\\nabla u^i \\cdot n^i\\right)\n\\end{aligned}\n$$\n","here $n^i$ is the outward normal on $\\partial \\Omega^i$. Finally, we introduce a Neumann flux boundary condition on the fin root\n","\n$$\n-\\left(\\nabla u^0 \\cdot n^0\\right)=-1 \\text { on } \\Gamma_{\\text {root }},\n$$\n","which models the heat source; and a Robin boundary condition\n","\n$$\n-k^i\\left(\\nabla u^i \\cdot n^i\\right)=\\operatorname{Bi} u^i \\text { on } \\Gamma_{e x t}^i, i=0, \\ldots, 4,\n$$\n","which models the convective heat losses. Here $\\Gamma_{\\text {ext }}^i$ is that part of the boundary of $\\Omega^i$ exposed to the flowing fluid; note that $\\cup_{i=0}^4 \\Gamma_{e x t}^i=\\Gamma \\backslash \\Gamma_{\\text {root }}$. The average temperature at the root, $T_{\\text {root }}(\\mu)$, can then be expressed as $\\ell^O(u(\\mu))$, where\n","\n$$\n\\ell^O(v)=\\int_{\\Gamma_{\\text {root }}} v\n$$\n","## Implementation\n\n","First, we initialize the {feelpp} environment and set the working directory.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import feelpp\n","from feelpp_project import laplacian\n","import json\n","import os\n","\n","d = os.getcwd()\n","print(f\"directory={d}\")\n","e = feelpp.Environment(['fin'], config=feelpp.localRepository(\".\"))\n"]},{"cell_type":"markdown","source":["Next, we set the configuration file for the simulation and load the specifications from a JSON file.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["feelpp.Environment.setConfigFile(f\"{d}/src/cases/laplacian/fin/fin1/fin2d.cfg\")\n","# Reading the JSON file\n","data = laplacian.loadSpecs(f\"{d}/src/cases/laplacian/fin/fin2d.json\")\n","print(data)\n"]},{"cell_type":"markdown","source":["Now, we create a Laplacian object, set the specifications, and run the simulation.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["lap = laplacian.get(dim=2, order=1)\n","lap.setSpecs(data)\n","lap.run()\n","meas=lap.measures()\n"]},{"cell_type":"markdown","source":["After running the simulation, we convert the results to a Pandas DataFrame and set the 'time' column as the index for easy data manipulation.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import pandas as pd\n","df = pd.DataFrame(meas)\n","df.set_index('time', inplace=True)\n","print(df.to_markdown())\n"]},{"cell_type":"markdown","source":["In the next block, we plot the mean temperature values at the fin root and the exterior using Plotly.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import plotly.graph_objects as go\n","import numpy as np\n","\n","fig = go.Figure()\n","fig.add_trace(go.Scatter(x=df.index, y=df[\"mean_Gamma_root\"], mode='lines', name='T_{Gamma Root}'))\n","fig.add_trace(go.Scatter(x=df.index, y=df[\"mean_Gamma_ext\"], mode='markers', name='T_{Gamma Ext}'))\n","fig.add_trace(go.Scatter(x=df.index, y=df[\"min\"], mode='markers', name='min T'))\n","fig.add_trace(go.Scatter(x=df.index, y=df[\"max\"], mode='markers', name='max T'))\n","fig.update_layout(title='Temperature', xaxis_title='time', yaxis_title='T')\n","fig.show()\n"]},{"cell_type":"markdown","source":["Lastly, we plot the heat flux values at the fin root and the exterior.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["fig = go.Figure()\n","fig.add_trace(go.Scatter(\n"," x=df.index, y=df[\"flux_Gamma_root\"], mode='lines', name='Flux_{Gamma Root}'))\n","fig.add_trace(go.Scatter(\n"," x=df.index, y=df[\"flux_Gamma_ext\"], mode='markers', name='Flux_{Gamma Ext}'))\n","fig.update_layout(title='Heat Flux', xaxis_title='time', yaxis_title='Flux')\n","fig.show()\n"]}],"metadata":{"language_info":{"name":"python","version":"3.9.1"}},"nbformat":4,"nbformat_minor":4} | ||
{"cells":[{"cell_type":"markdown","source":["# Thermal fin\n\n","## Problem statement\n\n","We consider the problem of designing a thermal fin to effectively remove heat from a surface. The two-dimensional fin, shown in Figure below, consists of a vertical central post and four horizontal subfins; the fin conducts heat from a prescribed uniform flux source at the root, $\\Gamma_{\\text {root }}$, through the large-surface-area subfins to surrounding flowing air. The fin is characterized by a five-component parameter vector, or input, $\\mu_{=}\\left(\\mu_1, \\mu_2, \\ldots, \\mu_5\\right)$, where $\\mu_i=k^i, i=1, \\ldots, 4$, and $\\mu_5=\\mathrm{Bi} ; \\mu$ may take on any value in a specified design set $D \\subset \\mathbb{R}^5$.\n","\n","![ROOT:fin2d 4 mesh](ROOT:fin2d-4-mesh.png)\n","\n","Here $k^i$ is the thermal conductivity of the ith subfin (normalized relative to the post conductivity $k^0 \\equiv 1$ ); and $\\mathrm{Bi}$ is the Biot number, a nondimensional heat transfer coefficient reflecting convective transport to the air at the fin surfaces (larger $\\mathrm{Bi}$ means better heat transfer). For example, suppose we choose a thermal fin with $k^1=0.4, k^2=0.6, k^3=0.8, k^4=1.2$, and $\\mathrm{Bi}=0.1$; for this particular configuration $\\mu=\\{0.4,0.6,0.8,1.2,0.1\\}$, which corresponds to a single point in the set of all possible configurations D (the parameter or design set). The post is of width unity and height four; the subfins are of fixed thickness $t=0.25$ and length $L=2.5$.\n","We are interested in the design of this thermal fin, and we thus need to look at certain outputs or cost-functionals of the temperature as a function of $\\mu$. We choose for our output $T_{\\text {root }}$, the average steady-state temperature of the fin root normalized by the prescribed heat flux into the fin root. The particular output chosen relates directly to the cooling efficiency of the fin lower values of $T_{\\text {root }}$ imply better thermal performance. The steadystate temperature distribution within the fin, $u(\\mu)$, is governed by the elliptic partial differential equation\n","\n$$\n\\rho_i C_i \\frac{\\partial u^i}{\\partial t} -k^i \\Delta u^i=0 \\text { in } \\Omega^i, i=0, \\ldots, 4,\n$$\n","where $\\Delta$ is the Laplacian operator, and $u_i$ refers to the restriction of $u$ to $\\Omega^i$.\n","Here $\\Omega^i$ is the region of the fin with conductivity $k^i, i=0, \\ldots, 4$ and volumetric heat capacity $(\\rho C)_i, i=0, \\cdots, 4$: $\\Omega^0$ is thus the central post, and $\\Omega^i, i=1, \\ldots, 4$, corresponds to the four subfins.\n","The entire fin domain is denoted $\\Omega\\left(\\bar{\\Omega}=\\cup_{i=0}^4 \\bar{\\Omega}^i\\right)$; the boundary $\\Omega$ is denoted $\\Gamma$. We must also ensure continuity of temperature and heat flux at the conductivity discontinuity interfaces $\\Gamma_{\\text {int }}^i \\equiv \\partial \\Omega^0 \\cap \\partial \\Omega^i, i=1, \\ldots, 4$, where $\\partial \\Omega^i$ denotes the boundary of $\\Omega^i$, we have on $\\Gamma_{\\text {int }}^i i=1, \\ldots, 4$ :\n","\n$$\n\\begin{aligned}\nu^0 & =u^i \\\\\n-\\left(\\nabla u^0 \\cdot n^i\\right) & =-k^i\\left(\\nabla u^i \\cdot n^i\\right)\n\\end{aligned}\n$$\n","here $n^i$ is the outward normal on $\\partial \\Omega^i$. Finally, we introduce a Neumann flux boundary condition on the fin root\n","\n$$\n-\\left(\\nabla u^0 \\cdot n^0\\right)=-1 \\text { on } \\Gamma_{\\text {root }},\n$$\n","which models the heat source; and a Robin boundary condition\n","\n$$\n-k^i\\left(\\nabla u^i \\cdot n^i\\right)=\\operatorname{Bi} u^i \\text { on } \\Gamma_{e x t}^i, i=0, \\ldots, 4,\n$$\n","which models the convective heat losses. Here $\\Gamma_{\\text {ext }}^i$ is that part of the boundary of $\\Omega^i$ exposed to the flowing fluid; note that $\\cup_{i=0}^4 \\Gamma_{e x t}^i=\\Gamma \\backslash \\Gamma_{\\text {root }}$. The average temperature at the root, $T_{\\text {root }}(\\mu)$, can then be expressed as $\\ell^O(u(\\mu))$, where\n","\n$$\n\\ell^O(v)=\\int_{\\Gamma_{\\text {root }}} v\n$$\n","## Implementation\n\n","First, we initialize the {feelpp} environment and set the working directory.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import feelpp\n","from feelpp_project import laplacian\n","import json\n","import os\n","\n","d = os.getcwd()\n","print(f\"directory={d}\")\n","e = feelpp.Environment(['fin'], config=feelpp.localRepository(\".\"))\n"]},{"cell_type":"markdown","source":["Next, we set the configuration file for the simulation and load the specifications from a JSON file.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["feelpp.Environment.setConfigFile(f\"{d}/src/cases/laplacian/fin/fin1/fin2d.cfg\")\n","# Reading the JSON file\n","data = laplacian.loadSpecs(f\"{d}/src/cases/laplacian/fin/fin2d.json\")\n","print(data)\n"]},{"cell_type":"markdown","source":["Now, we create a Laplacian object, set the specifications, and run the simulation.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["lap = laplacian.get(dim=2, order=1)\n","lap.setSpecs(data)\n","lap.run()\n","meas=lap.measures()\n"]},{"cell_type":"markdown","source":["After running the simulation, we convert the results to a Pandas DataFrame and set the 'time' column as the index for easy data manipulation.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import pandas as pd\n","df = pd.DataFrame(meas)\n","df.set_index('time', inplace=True)\n","print(df.to_markdown())\n"]},{"cell_type":"markdown","source":["In the next block, we plot the mean temperature values at the fin root and the exterior using Plotly.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["import plotly.graph_objects as go\n","import numpy as np\n","\n","fig = go.Figure()\n","fig.add_trace(go.Scatter(x=df.index, y=df[\"mean_Gamma_root\"], mode='lines', name='T_{Gamma Root}'))\n","fig.add_trace(go.Scatter(x=df.index, y=df[\"mean_Gamma_ext\"], mode='markers', name='T_{Gamma Ext}'))\n","fig.add_trace(go.Scatter(x=df.index, y=df[\"min\"], mode='markers', name='min T'))\n","fig.add_trace(go.Scatter(x=df.index, y=df[\"max\"], mode='markers', name='max T'))\n","fig.update_layout(title='Temperature', xaxis_title='time', yaxis_title='T')\n","fig.show()\n"]},{"cell_type":"markdown","source":["Lastly, we plot the heat flux values at the fin root and the exterior.\n"],"metadata":{}},{"cell_type":"code","execution_count":0,"metadata":{"slideshow":{"slide_type":"fragment"}},"outputs":[],"source":["fig = go.Figure()\n","fig.add_trace(go.Scatter(\n"," x=df.index, y=df[\"flux_Gamma_root\"], mode='lines', name='Flux_{Gamma Root}'))\n","fig.add_trace(go.Scatter(\n"," x=df.index, y=df[\"flux_Gamma_ext\"], mode='markers', name='Flux_{Gamma Ext}'))\n","fig.update_layout(title='Heat Flux', xaxis_title='time', yaxis_title='Flux')\n","fig.show()\n"]}],"metadata":{"language_info":{"name":"python","version":"3.9.1"},"kernelspec":{"name":"python3","language":"python"}},"nbformat":4,"nbformat_minor":4} |
Oops, something went wrong.