├── .github └── workflows │ └── build-deploy-book.yml ├── .gitignore ├── AUTHORS ├── Makefile ├── README.md ├── _config.yml ├── _toc.yml ├── chapter0 ├── bezier-curves.md ├── bezier.md ├── bsplines-curves.md ├── bsplines-operations.md ├── bsplines-surfaces.md ├── bsplines.md ├── bsplines_utilities.py ├── cad.md ├── data-structure.md ├── fem.md ├── howto.md ├── iga.md ├── images │ ├── algorithms │ │ ├── contribution_arity1_1d_ex1.png │ │ ├── contribution_arity1_1d_ex2.png │ │ ├── contribution_arity1_2d_ex1.png │ │ ├── contribution_arity1_2d_ex2.png │ │ ├── contribution_arity2_1d_ex1.png │ │ ├── contribution_arity2_1d_ex2.png │ │ ├── contribution_arity2_2d_ex1.png │ │ ├── contribution_arity2_2d_ex2.png │ │ ├── eval_field_1d.png │ │ ├── eval_field_2d.png │ │ ├── kernel_arity1_1d.png │ │ ├── kernel_arity1_2d.png │ │ ├── kernel_arity2_1d.png │ │ └── kernel_arity2_2d.png │ ├── bezier │ │ ├── output_16_0.png │ │ ├── output_17_0.png │ │ ├── output_18_0.png │ │ ├── output_19_0.png │ │ ├── output_20_0.png │ │ ├── output_22_0.png │ │ └── output_25_0.png │ ├── bsplines-curves │ │ ├── output_10_0.png │ │ ├── output_11_0.png │ │ ├── output_15_0.png │ │ ├── output_17_0.png │ │ ├── output_19_0.png │ │ ├── output_21_0.png │ │ ├── output_23_0.png │ │ ├── output_5_0.png │ │ ├── output_6_0.png │ │ ├── output_7_0.png │ │ ├── output_8_0.png │ │ └── output_9_0.png │ ├── bsplines-operations │ │ ├── output_10_0.png │ │ ├── output_11_0.png │ │ ├── output_13_0.png │ │ ├── output_14_0.png │ │ ├── output_18_0.png │ │ ├── output_21_0.png │ │ ├── output_22_0.png │ │ ├── output_23_0.png │ │ ├── output_24_0.png │ │ ├── output_27_0.png │ │ ├── output_30_0.png │ │ ├── output_33_0.png │ │ └── output_9_0.png │ ├── bsplines-surfaces │ │ ├── output_12_0.png │ │ ├── output_5_0.png │ │ └── output_9_0.png │ ├── bsplines │ │ ├── output_11_1.png │ │ ├── output_13_1.png │ │ ├── output_15_1.png │ │ ├── output_17_1.png │ │ ├── output_19_1.png │ │ ├── output_21_1.png │ │ ├── output_30_0.png │ │ ├── output_31_0.png │ │ ├── output_33_0.png │ │ ├── output_34_0.png │ │ ├── output_36_0.png │ │ ├── output_37_0.png │ │ ├── output_39_0.png │ │ ├── output_40_0.png │ │ ├── output_5_1.png │ │ ├── output_7_1.png │ │ └── output_9_1.png │ ├── data-structure │ │ └── output_24_1.png │ ├── poisson-1d │ │ ├── output_20_0.png │ │ └── output_23_1.png │ └── poisson-2d │ │ └── output_20_1.png ├── performance-acceleration.md ├── poisson-1d.md └── poisson-2d.md ├── chapter1 ├── analytical-mapping.md ├── boundary-conditions.md ├── discrete-mapping.md ├── geometry.md ├── images │ ├── boundary-conditions │ │ ├── line-boundaries.png │ │ └── square-boundaries.png │ ├── ch1-jupyter-poisson-1.png │ ├── ch1-jupyter-poisson-2.png │ ├── ch1-jupyter-root.png │ └── geometry │ │ └── element.png ├── install.md ├── poisson.ipynb ├── rules.md ├── space.md ├── sympde.md └── topology.md ├── chapter2 ├── advection-diffusion-stabilized.ipynb ├── advection-diffusion.ipynb ├── biharmonic.ipynb ├── elliptic-curl.ipynb ├── elliptic-div.ipynb ├── elliptic-general-form.ipynb ├── linear-elasticity.ipynb ├── poisson-mixed-v1.ipynb ├── poisson-mixed-v2.ipynb ├── poisson-mixed.ipynb ├── poisson-nitsche.ipynb ├── poisson.ipynb ├── stokes-v1.ipynb ├── stokes-v2.ipynb ├── stokes.ipynb └── vector-poisson.ipynb ├── chapter3 ├── burgers.md ├── navier-stokes-steady-streamfunction-velocity.md ├── navier-stokes-steady.md └── poisson.md ├── chapter4 ├── poisson-multi-subdomains-nitsche.ipynb ├── poisson-two-subdomains-nitsche.ipynb └── subdomains.md ├── chapter5 ├── cfd.md ├── cfd │ ├── bingham_plastic_flow_in_a_pipe.ipynb │ ├── buoyancy-driven_natural_convection.ipynb │ ├── casson_fluid_flow_in_a_channel.ipynb │ ├── compressible_flow_in_a_nozzle.ipynb │ ├── convection-diffusion_equation_in_a_channel.ipynb │ ├── cross_power_law_fluid_flow_in_a_channel.ipynb │ ├── free_surface_flow.ipynb │ ├── heat_conduction_in_a_solid.ipynb │ ├── herschel-bulkley_fluid_flow_in_a_pipe.ipynb │ ├── incompressible_flow_past_a_cylinder.ipynb │ ├── magnetohydrodynamics_flow.ipynb │ ├── non-newtonian-fluids.md │ ├── oldroyd-b_fluid_flow_in_a_channel.ipynb │ ├── papanastasiou_fluid_flow_in_a_channel.ipynb │ ├── particle-laden_flow.ipynb │ ├── power_law_fluid_flow_in_a_channel.ipynb │ ├── stokes_flow_in_a_lid-driven_cavity.ipynb │ └── two-phase_flow.ipynb ├── electromagnetics.md ├── fsi.md ├── fsi │ ├── fluid-structure_interaction_in_a_flexible_channel.ipynb │ ├── flutter_analysis_of_a_flexible_wing_in_fluid_flow.ipynb │ └── two-way_fluid-structure_interaction_in_a_tube.ipynb ├── material-science.md ├── material-science │ ├── additive-manifacturing.md │ ├── composite-materials-analysis.md │ ├── composite-materials.md │ ├── composite_beam_analysis.ipynb │ ├── composite_materials_with_piezoelectric_fibers.ipynb │ ├── composite_materials_with_thermal_expansion.ipynb │ ├── composite_pressure_vessel_analysis.ipynb │ ├── composite_shaft_analysis.ipynb │ ├── composite_shell_structures.ipynb │ ├── creep_in_viscoelastic_materials.ipynb │ ├── diffusion_and_reaction_in_porous_media.ipynb │ ├── elasticity_with_thermal_expansion.ipynb │ ├── fiber-reinforced_composite_materials.ipynb │ ├── fluid_flow_simulation_in_directed_energy_deposition.ipynb │ ├── heat_conduction_with_phase_change.ipynb │ ├── homogenization_of_composite_structures.ipynb │ ├── laminate_plate_bending.ipynb │ ├── multi-material_simulation_in_material_jetting.ipynb │ ├── piezoelectric_material.ipynb │ ├── residual_stress_simulation_in_selective_laser_melting.ipynb │ ├── structural_simulation_in_fused_filament_fabrication.ipynb │ ├── thermal_conductivity_of_composite_materials.ipynb │ └── thermal_simulation_in_powder_bed_fusion.ipynb ├── mhd.md ├── mhd │ ├── astrophysical_dynamo_in_a_stellar_interior.ipynb │ ├── ferrofluid_damper_in_mechanical_system.ipynb │ ├── ferrofluid_flow_in_a_microfluidic_device.ipynb │ ├── magnetic_fluid_actuator_in_valve_control.ipynb │ ├── magnetic_targeting_in_a_blood_vessel.ipynb │ ├── magnetic_targeting_in_the_eye_for_retinal_diseases.ipynb │ ├── magnetic_targeting_in_tumor_tissue.ipynb │ ├── mhd-astrophysics.md │ ├── mhd-drug-targeting.md │ ├── mhd-dynamo.md │ ├── mhd-fluid-dynamics.md │ ├── mhd-fusion.md │ ├── mhd-heat-transfer.md │ ├── mhd-material-processing.md │ ├── mhd-stability-analysis.md │ ├── mhd-turbulence.md │ ├── mhd_accretion_disk_in_binary_star_system.ipynb │ ├── mhd_aluminum_electromagnetic_stirring.ipynb │ ├── mhd_continuous_casting_of_steel.ipynb │ ├── mhd_dynamo_in_a_rotating_sphere.ipynb │ ├── mhd_heat_transfer_in_a_cylindrical_fusion_reactor.ipynb │ ├── mhd_heat_transfer_in_a_magma_convection_model.ipynb │ ├── mhd_heat_transfer_in_a_rectangular_domain.ipynb │ ├── mhd_kelvin-helmholtz_instability_in_magnetized_flows.ipynb │ ├── mhd_metal_solidification_in_magnetic_field.ipynb │ ├── mhd_rayleigh-taylor_instability_in_a_conducting_fluid.ipynb │ ├── mhd_solar_wind_simulation.ipynb │ ├── mhd_stability_of_a_current-carrying_plasma_column.ipynb │ ├── mhd_star_formation_in_a_protostellar_cloud.ipynb │ ├── mhd_turbulence_in_accretion_disks.ipynb │ ├── mhd_turbulence_in_laboratory_plasmas.ipynb │ ├── mhd_turbulence_in_solar_winds.ipynb │ └── simple_kinematic_dynamo_model.ipynb └── multiphysics.md ├── intro.md ├── logo.png ├── references.bib ├── requirements.txt └── requirements_ntbk.txt /.github/workflows/build-deploy-book.yml: -------------------------------------------------------------------------------- 1 | name: Jupyter book 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ${{ matrix.os }} 12 | strategy: 13 | fail-fast: true 14 | matrix: 15 | include: 16 | - os: ubuntu-24.04 17 | python-version: '3.12' 18 | - os: macos-15 19 | python-version: '3.12' 20 | name: build / ${{ matrix.os }} / python${{ matrix.python-version }} 21 | env: 22 | FC: gfortran-14 23 | 24 | steps: 25 | - uses: actions/checkout@v4 26 | 27 | - name: Set up Python ${{ matrix.python-version }} 28 | uses: actions/setup-python@v5 29 | with: 30 | python-version: ${{ matrix.python-version }} 31 | cache: 'pip' 32 | cache-dependency-path: requirements.txt 33 | 34 | - name: Install non-Python dependencies on Ubuntu 35 | if: startsWith(matrix.os, 'ubuntu') 36 | uses: awalsh128/cache-apt-pkgs-action@latest 37 | with: 38 | packages: gfortran openmpi-bin libopenmpi-dev libhdf5-openmpi-dev 39 | version: 1.0 40 | execute_install_scripts: true 41 | 42 | # When loading cached apt packages, the default MPI compiler isn't set. 43 | # Workaround is to 'reinstall' openmpi-bin, which doesn't actually perform 44 | # installation (since openmpi-bin already exists), but instead reruns 45 | # `update-alternatives` which fixes the symlinks to mpicc/mpif90. 46 | - name: Reconfigure non-Python dependencies on Ubuntu 47 | if: startsWith(matrix.os, 'ubuntu') 48 | run: | 49 | sudo apt-get update 50 | sudo apt-get install --reinstall openmpi-bin libhdf5-openmpi-dev 51 | 52 | - name: Install non-Python dependencies on macOS 53 | if: startsWith(matrix.os, 'macos') 54 | run: | 55 | brew install open-mpi hdf5-mpi libomp 56 | 57 | - name: Check gfortran version 58 | run: | 59 | if [[ "${{ matrix.os }}" == *"macos"* ]]; then 60 | # pyccel searches for a Fortran compiler exactly named 'gfortran' 61 | # which the macos runner doesn't have. A simple workaround is to 62 | # create a symlink named 'gfortran'. 63 | FC_path=$(which $FC) 64 | FC_dir=$(dirname ${FC_path}) 65 | ln -sv ${FC_path} ${FC_dir}/gfortran 66 | fi 67 | gfortran --version 68 | 69 | - name: Install Jupyter Book and Psydac 70 | run: | 71 | pip install --upgrade pip 72 | pip install -r requirements.txt 73 | 74 | - name: Get list of changed Python notebooks 75 | id: changed-ipynb-files 76 | uses: tj-actions/changed-files@v45 77 | with: 78 | files: | 79 | **.ipynb 80 | 81 | - name: Check for dirty Python notebooks 82 | if: steps.changed-ipynb-files.outputs.any_changed == 'true' 83 | env: 84 | ALL_CHANGED_FILES: ${{ steps.changed-ipynb-files.outputs.all_changed_files }} 85 | run: | 86 | # Check if there are dirty notebooks 87 | dirty_ipynb=() 88 | for file in ${ALL_CHANGED_FILES[*]}; do 89 | echo "Checking $file..." 90 | if ! nb-clean check $file >/dev/null 2>&1; then 91 | dirty_ipynb+=($file) 92 | fi 93 | done 94 | 95 | # Trigger failure if dirty notebooks were found 96 | if [[ ! -z "${dirty_ipynb[@]}" ]]; then 97 | echo "ERROR: Found dirty Python notebooks. Please clean the notebooks by running" 98 | echo "" 99 | echo "nb-clean clean --remove-empty-cells --remove-all-notebook-metadata ${dirty_ipynb[*]}" 100 | echo "" 101 | exit 1 102 | else 103 | echo "SUCCESS: All changed notebooks are clean." 104 | fi 105 | 106 | - name: Build Jupyter Book 107 | run: make docs 108 | 109 | - name: Upload artifact 110 | id: deployment 111 | uses: actions/upload-pages-artifact@v3 112 | with: 113 | path: _build/html 114 | name: github-pages_${{ matrix.os }}_python${{ matrix.python-version }} 115 | 116 | deploy: 117 | if: github.event_name != 'pull_request' 118 | needs: build 119 | runs-on: ubuntu-24.04 120 | environment: 121 | name: github-pages 122 | url: ${{ steps.deployment.outputs.page_url }} 123 | 124 | # Grant GITHUB_TOKEN the permissions required to make a Pages deployment 125 | permissions: 126 | pages: write # to deploy to Pages 127 | id-token: write # to verify the deployment originates from an appropriate source 128 | 129 | steps: 130 | - name: Deploy to GitHub Pages 131 | id: deployment 132 | uses: actions/deploy-pages@v4 133 | with: 134 | artifact_name: github-pages_ubuntu-24.04_python3.12 135 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.pyo 3 | .ipynb_checkpoints 4 | *.so 5 | *__pycache__* 6 | *__pyccel__* 7 | *__psydac__* 8 | 9 | build 10 | *build* 11 | *egg* 12 | *dist* 13 | usr 14 | *cache* 15 | 16 | *.swp 17 | *.log 18 | 19 | .env 20 | .iga-python 21 | *_autosummary* 22 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Ahmed Ratnani 2 | Mohamed Jalal Maaouni 3 | Paul Rigor 4 | Yaman Güçlü 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BUILD_DIR = ./_build 2 | SRC_DIR = . 3 | 4 | .PHONY: docs docs-strict clean clean-notebooks 5 | 6 | docs: 7 | @echo "Building IGA-Python docs..." 8 | @jupyter-book build . 9 | @echo "Done." 10 | 11 | docs-strict: 12 | @echo "Building IGA-Python docs with strict rules on..." 13 | @jupyter-book build --warningiserror --nitpick --keep-going . 14 | @echo "Done." 15 | 16 | clean: 17 | @echo "Removing previous IGA-Python build artifacts..." 18 | @jupyter-book clean . 19 | @echo "Done." 20 | 21 | clean-notebooks: 22 | @echo "Running 'nb-clean --remove-empty-cells --remove-all-notebook-metadata' on all '*.ipynb' files..." 23 | @find . -type f -iname '*.ipynb' -exec nb-clean clean --remove-empty-cells --remove-all-notebook-metadata {} \+ 24 | @echo "Done." 25 | 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome to IGA-Python 2 | 3 | This project provides a tutorial for isogeometric analysis (IGA) using Python and the Psydac library (pyccel/psydac). The numerical examples can be consulted online at [pyccel.github.io/IGA-Python](https://pyccel.github.io/IGA-Python), or run with Jupyter Notebook on a personal computer. 4 | 5 | ## Editing and building IGA-Python locally 6 | 7 | 1. Clone this repository and then install the required dependencies. 8 | 9 | ```bash 10 | git clone https://github.com/pyccel/IGA-Python.git 11 | cd IGA-Python 12 | IGA_PYTHON_DIR=$(pwd) 13 | 14 | # Install dependencies on a virtual environment 15 | python3 -m venv iga-python-env 16 | source iga-python-env/bin/activate 17 | pip3 install -r requirements_ntbk.txt 18 | ``` 19 | 20 | 2. Install Psydac. Skip this step if Psydac is already installed. 21 | 22 | ```bash 23 | # Modify these variables if you're using your own psydac fork/branch 24 | PSYDAC_REMOTE="https://github.com/pyccel/psydac.git" 25 | BRANCH="devel" 26 | 27 | # Install psydac 28 | pip install git+${PSYDAC_REMOTE}@${BRANCH} 29 | ``` 30 | 31 | 3. Run or modify the desired Python notebooks (`*.ipynb`) and Markdown files (`*.md`). Check the [MyST syntax cheat sheet](https://jupyterbook.org/en/stable/reference/cheatsheet.html) for reference. 32 | 33 | > [!NOTE] 34 | > Before committing changes to git, the notebooks have to be cleaned first. See ["Committing your changes to git"](#committing-your-changes-to-git) for more information. 35 | 36 | 4. Build the docs by running `make` under the IGA-Python folder. This involves running all `*.ipynb` files in the background to make sure they are functional. 37 | 38 | ```bash 39 | cd ${IGA_PYTHON_DIR} 40 | make 41 | ``` 42 | 43 | 5. View your changes on the browser. 44 | 45 | ```bash 46 | open ${IGA_PYTHON_DIR}/_build/html/index.html 47 | ``` 48 | 49 | ## Committing your changes to git 50 | 51 | Running the Python notebooks embeds extra information like the name of virtual environment, Python version used, cell outputs, etc. The notebooks should be free of system- and runtime-specific information before committing them to source control. We suggest the following commit workflow: 52 | 53 | 1. Run [`nb-clean`](https://github.com/srstevenson/nb-clean) on the modified notebook/s. There are different ways to run this command: 54 | 55 | ```bash 56 | # Clean a single notebook 57 | nb-clean clean --remove-empty-cells --remove-all-notebook-metadata chapter1/poisson.ipynb 58 | 59 | # Clean all '.ipynb' files under IGA-Python 60 | make clean-notebooks 61 | 62 | # Automatically run nb-clean on `git add`-ed *.ipynb files 63 | nb-clean add-filter --remove-empty-cells --remove-all-notebook-metadata 64 | 65 | # Undo previous command 66 | nb-clean remove-filter 67 | ``` 68 | 69 | 2. Create a branch for your local changes, e.g. `git checkout -b my-local-fixes`. 70 | 3. Stage the modified files with `git add`. Then run `git diff` to check if the changed `*.ipynb` notebooks doesn't include unnecessary diffs (e.g. notebook metadata). 71 | 4. `git commit` your changes. 72 | 5. *OPTIONAL*. Share your changes to this repo via a [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). 73 | 74 | ## Contributing 75 | 76 | There are several ways to contribute to this project. 77 | If you find a problem, please check if this is already discussed in one of [our issues](https://github.com/pyccel/IGA-Python/issues) and feel free to add your opinion; if not, please create a [new issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/creating-an-issue). 78 | If you want to fix an issue, improve our notebooks, or add a new example, please [fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) our Git repository, make and commit your changes, and create a [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) (PRs). 79 | 80 | All PRs are reviewed by the project maintainers. 81 | During the PR review, GitHub workflows are triggered on various platforms. 82 | These workflows build the notebooks and prepare them to be deployed as a static HTML website to [pyccel.github.io/IGA-Python](https://pyccel.github.io/IGA-Python). 83 | Deploy does not happen before the final merge of the PR, but the HTML files can be downloaded as a zip file from GitHub, and opened with any browser for inspection. 84 | To download the zip file, select the workflow run of interest from the `Actions` tab, click on `Summary`, and look under `Artifacts`. -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | # Book settings 2 | # Learn more at https://jupyterbook.org/customize/config.html 3 | 4 | title: IGA-Python 5 | author: Ahmed Ratnani 6 | logo: logo.png 7 | 8 | # Force re-execution of notebooks on each build. 9 | # See https://jupyterbook.org/content/execute.html 10 | execute: 11 | execute_notebooks: force 12 | 13 | # Define the name of the latex output file for PDF builds 14 | latex: 15 | latex_documents: 16 | targetname: book.tex 17 | 18 | # Add a bibtex file so that we can create citations 19 | bibtex_bibfiles: 20 | - references.bib 21 | 22 | launch_buttons: 23 | notebook_interface: "jupyterlab" 24 | binderhub_url: "https://mybinder.org" 25 | 26 | # Information about where the book exists on the web 27 | repository: 28 | url: https://github.com/pyccel/IGA-Python # Online location of your book 29 | path_to_book: . # Optional path to your book, relative to the repository root 30 | branch: master # Which branch of the repository should be used when creating links (optional) 31 | 32 | # Add GitHub buttons to your book 33 | # See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository 34 | html: 35 | use_issues_button: true 36 | use_repository_button: true 37 | 38 | sphinx: 39 | extra_extensions: 40 | - sphinx_proof 41 | - sphinx.ext.autodoc 42 | - sphinx.ext.autosummary 43 | config: 44 | autosummary_generate: True 45 | 46 | exclude_patterns: [README.md, .iga-python] 47 | -------------------------------------------------------------------------------- /chapter0/bezier.md: -------------------------------------------------------------------------------- 1 | # Bernstein polynomials 2 | 3 | 4 | Without loss of generality, we restrict to the case of the unit interval, namely $a=0$ and $b=1$. 5 | In figure (Fig. \ref{fig:bernstein-polynomials}), we plot the first sixth Bernstein polynomials. 6 | 7 | 8 | ````{prf:definition} 9 | 10 | Fro $n \in \mathbb{N}$, the $n$-th degree Bernstein polynomials $B_{j,n}\,:\, [0,1] \longrightarrow \mathbb{R}$ are defined by 11 | 12 | $$ 13 | B_{j,n}(x)=\frac{n!}{(n-j)!j!} x^j (1-x)^{n-j}, \quad x \in [0,1], \quad j=0, \ldots,n. 14 | $$ 15 | ```` 16 | 17 | Bernstein polynomials exhibit interesting properties highlighted in the following proposition, 18 | 19 | ```python 20 | # needed imports 21 | import numpy as np 22 | import matplotlib.pyplot as plt 23 | ``` 24 | 25 | We first consider the evaluation of the Bernstein polynomials. 26 | 27 | ## Evaluation of Bernstein polynomials 28 | 29 | The following function evaluates all Bernstein polynomials of degree $n$ at $x$ 30 | 31 | ```python 32 | def all_bernstein(n, x): 33 | b = np.zeros(n+1) 34 | b[0] = 1. 35 | x1 = 1.-x 36 | for j in range(1, n+1): 37 | saved = 0. 38 | for i in range(0, j): 39 | tmp = b[i] 40 | b[i] = saved + x1*tmp 41 | saved = x*tmp 42 | b[j] = saved 43 | return b 44 | ``` 45 | 46 | ## Bernstein polynomials properties 47 | 48 | ````{prf:proposition} 49 | 50 | We have the following properties of Bernstein Polynomials, 51 | 52 | - Positivity: $B_{j,n}(x) \ge 0$, for all $x \in \left[ 0, 1 \right]$ and $0 \leq j \leq n$. 53 | - Partition of unity: $\sum_{j=0}^n B_{j,n}(x) = 1$, for all $x \in \left[ 0, 1 \right]$. 54 | - $B_{0,n}(0) = B_{n,n}(1) = 1$. 55 | - $B_{j,n}$ has exactly one maximum on the interval $\left[ 0, 1 \right]$, at $\frac{j}{n}$. 56 | - Symmetry: $B_{j,n}$ is symmetric with respect to $x = \frac{1}{2}$ for $j=0,\ldots,n$. 57 | - Bernstein polynomials can be defined recursively using the formula 58 | 59 | $$ 60 | \begin{align} 61 | B_{j,n}(x) = (1-x) B_{j,n-1}(x) + x B_{k-1,n-1}(x), 62 | \end{align} 63 | $$ 64 | 65 | where we assume $B_{j,n}(x) = 0$ if $j < 0$ or $j > n$. 66 | 67 | - Bernstein derivatives can be computed using the formulae 68 | 69 | $$ 70 | \begin{align} 71 | {B_{j,n}}^\prime(x) = n \left(B_{j-1,n-1}(x) - B_{j,n-1}(x) \right). 72 | \end{align} 73 | $$ 74 | using the same assumption as before. 75 | ```` 76 | -------------------------------------------------------------------------------- /chapter0/cad.md: -------------------------------------------------------------------------------- 1 | # Computer Aided Design 2 | 3 | 4 | TODO 5 | -------------------------------------------------------------------------------- /chapter0/data-structure.md: -------------------------------------------------------------------------------- 1 | # Data Structure 2 | 3 | 4 | In the sequel, we shall use **StencilMatrix** and **StencilVector** from the **psydac** library. 5 | 6 | For the moment, we are only interested about having an appropriate data structure to store our computations. 7 | Once the assembly is done, we will convert the matrix into a scipy sparse matrix, while the vector will be converted to numpy array. 8 | 9 | We will see later how one can impose boundary conditions. 10 | 11 | # 1D Case 12 | 13 | 14 | ```python 15 | import numpy as np 16 | 17 | from psydac.fem.splines import SplineSpace 18 | from psydac.fem.tensor import TensorFemSpace 19 | from psydac.linalg.stencil import StencilMatrix 20 | from psydac.linalg.stencil import StencilVector 21 | from psydac.ddm.cart import DomainDecomposition 22 | ``` 23 | 24 | 25 | ```python 26 | from gallery_section_03 import assemble_stiffness_1d 27 | from gallery_section_03 import assemble_vector_1d 28 | ``` 29 | 30 | 31 | ```python 32 | xmin = 0. ; xmax = 1. 33 | nelements = 8 34 | degree = 3 35 | grid = np.linspace( xmin, xmax, num=nelements+1 ) 36 | V = SplineSpace(degree=degree, grid=grid) 37 | dd = DomainDecomposition(ncells=[V.ncells], periods=[False]) 38 | V = TensorFemSpace(dd, V) 39 | ``` 40 | 41 | 42 | ```python 43 | stiffness = StencilMatrix(V.vector_space, V.vector_space) 44 | ``` 45 | 46 | 47 | ```python 48 | stiffness = assemble_stiffness_1d( V, matrix=stiffness ) 49 | ``` 50 | 51 | 52 | ```python 53 | stiffness = stiffness.tosparse() 54 | ``` 55 | 56 | 57 | ```python 58 | f = lambda x: 2. 59 | ``` 60 | 61 | 62 | ```python 63 | rhs = StencilVector(V.vector_space) 64 | ``` 65 | 66 | 67 | ```python 68 | rhs = assemble_vector_1d( f, V, rhs=rhs ) 69 | ``` 70 | 71 | 72 | ```python 73 | rhs = rhs.toarray() 74 | ``` 75 | 76 | ## 2D Case 77 | 78 | 79 | ```python 80 | from gallery_section_03 import assemble_stiffness_2d 81 | from gallery_section_03 import assemble_vector_2d 82 | ``` 83 | 84 | 85 | ```python 86 | x1min = 0. ; x1max = 1. 87 | x2min = 0. ; x2max = 1. 88 | nelements1 = 8 89 | nelements2 = 8 90 | degree1 = 3 91 | degree2 = 3 92 | grid1 = np.linspace( x1min, x1max, num=nelements1+1 ) 93 | grid2 = np.linspace( x2min, x2max, num=nelements2+1 ) 94 | 95 | V1 = SplineSpace(degree=degree1, grid=grid1) 96 | V2 = SplineSpace(degree=degree2, grid=grid2) 97 | 98 | dd = DomainDecomposition(ncells=[V1.ncells, V2.ncells], periods=[False, False]) 99 | V = TensorFemSpace(dd, V1, V2) 100 | ``` 101 | 102 | 103 | ```python 104 | stiffness = StencilMatrix(V.vector_space, V.vector_space) 105 | ``` 106 | 107 | 108 | ```python 109 | stiffness = assemble_stiffness_2d( V, matrix=stiffness ) 110 | ``` 111 | 112 | 113 | ```python 114 | stiffness = stiffness.tosparse() 115 | ``` 116 | 117 | 118 | ```python 119 | # convert the sparse matrix to dense 120 | stiffness = stiffness.toarray() 121 | ``` 122 | 123 | 124 | ```python 125 | f = lambda x,y: 2. 126 | ``` 127 | 128 | 129 | ```python 130 | rhs = StencilVector(V.vector_space) 131 | ``` 132 | 133 | 134 | ```python 135 | rhs = assemble_vector_2d( f, V, rhs=rhs ) 136 | ``` 137 | 138 | ### Matrix profile 139 | 140 | 141 | ```python 142 | import matplotlib.pyplot as plt 143 | 144 | plt.spy(stiffness) 145 | ``` 146 | 147 | ![png](images/data-structure/output_24_1.png) 148 | -------------------------------------------------------------------------------- /chapter0/howto.md: -------------------------------------------------------------------------------- 1 | # What to expect from IGA-Python 2 | 3 | -------------------------------------------------------------------------------- /chapter0/iga.md: -------------------------------------------------------------------------------- 1 | # Isogeometric Analysis 2 | 3 | 4 | TODO 5 | -------------------------------------------------------------------------------- /chapter0/images/algorithms/contribution_arity1_1d_ex1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/contribution_arity1_1d_ex1.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/contribution_arity1_1d_ex2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/contribution_arity1_1d_ex2.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/contribution_arity1_2d_ex1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/contribution_arity1_2d_ex1.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/contribution_arity1_2d_ex2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/contribution_arity1_2d_ex2.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/contribution_arity2_1d_ex1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/contribution_arity2_1d_ex1.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/contribution_arity2_1d_ex2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/contribution_arity2_1d_ex2.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/contribution_arity2_2d_ex1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/contribution_arity2_2d_ex1.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/contribution_arity2_2d_ex2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/contribution_arity2_2d_ex2.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/eval_field_1d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/eval_field_1d.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/eval_field_2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/eval_field_2d.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/kernel_arity1_1d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/kernel_arity1_1d.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/kernel_arity1_2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/kernel_arity1_2d.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/kernel_arity2_1d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/kernel_arity2_1d.png -------------------------------------------------------------------------------- /chapter0/images/algorithms/kernel_arity2_2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/algorithms/kernel_arity2_2d.png -------------------------------------------------------------------------------- /chapter0/images/bezier/output_16_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bezier/output_16_0.png -------------------------------------------------------------------------------- /chapter0/images/bezier/output_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bezier/output_17_0.png -------------------------------------------------------------------------------- /chapter0/images/bezier/output_18_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bezier/output_18_0.png -------------------------------------------------------------------------------- /chapter0/images/bezier/output_19_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bezier/output_19_0.png -------------------------------------------------------------------------------- /chapter0/images/bezier/output_20_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bezier/output_20_0.png -------------------------------------------------------------------------------- /chapter0/images/bezier/output_22_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bezier/output_22_0.png -------------------------------------------------------------------------------- /chapter0/images/bezier/output_25_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bezier/output_25_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_10_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_10_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_11_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_11_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_15_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_15_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_17_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_19_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_19_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_21_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_21_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_23_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_23_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_5_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_5_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_6_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_6_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_7_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_7_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_8_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_8_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-curves/output_9_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-curves/output_9_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_10_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_10_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_11_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_11_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_13_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_13_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_14_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_14_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_18_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_18_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_21_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_21_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_22_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_22_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_23_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_23_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_24_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_24_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_27_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_27_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_30_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_30_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_33_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_33_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-operations/output_9_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-operations/output_9_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-surfaces/output_12_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-surfaces/output_12_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-surfaces/output_5_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-surfaces/output_5_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines-surfaces/output_9_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines-surfaces/output_9_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_11_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_11_1.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_13_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_13_1.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_15_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_15_1.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_17_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_17_1.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_19_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_19_1.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_21_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_21_1.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_30_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_30_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_31_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_31_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_33_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_33_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_34_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_34_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_36_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_36_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_37_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_37_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_39_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_39_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_40_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_40_0.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_5_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_5_1.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_7_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_7_1.png -------------------------------------------------------------------------------- /chapter0/images/bsplines/output_9_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/bsplines/output_9_1.png -------------------------------------------------------------------------------- /chapter0/images/data-structure/output_24_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/data-structure/output_24_1.png -------------------------------------------------------------------------------- /chapter0/images/poisson-1d/output_20_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/poisson-1d/output_20_0.png -------------------------------------------------------------------------------- /chapter0/images/poisson-1d/output_23_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/poisson-1d/output_23_1.png -------------------------------------------------------------------------------- /chapter0/images/poisson-2d/output_20_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter0/images/poisson-2d/output_20_1.png -------------------------------------------------------------------------------- /chapter0/poisson-2d.md: -------------------------------------------------------------------------------- 1 | # B-splines FEM solver for Poisson equation (2D) 2 | 3 | 4 | In this section, we show hoa to use **simplines** to solve a 2D Poisson problem with homogeneous boundary conditions 5 | $$ 6 | - \nabla^2 u = f, \Omega, 7 | \\ 8 | u = 0, \partial \Omega 9 | $$ 10 | where the computation domain $\Omega$ is the unit square. 11 | 12 | 13 | ```python 14 | # needed imports 15 | from numpy import zeros, ones, linspace, zeros_like, asarray 16 | import numpy as np 17 | from matplotlib.pyplot import plot, show 18 | import matplotlib.pyplot as plt 19 | 20 | %matplotlib inline 21 | ``` 22 | 23 | 24 | ```python 25 | from psydac.fem.splines import SplineSpace 26 | from psydac.fem.tensor import TensorFemSpace 27 | from psydac.linalg.stencil import StencilMatrix 28 | from psydac.linalg.stencil import StencilVector 29 | from psydac.ddm.cart import DomainDecomposition 30 | ``` 31 | 32 | 33 | ```python 34 | from gallery_section_04 import assemble_stiffness_2d 35 | from gallery_section_04 import assemble_vector_2d 36 | ``` 37 | 38 | ## Create the Finite Elements Space 39 | 40 | In 2D, our Spline function space is defined as 41 | 42 | $$ 43 | \mathcal{V}_h := \texttt{span}\{ B_{i_1}^{p_1} B_{i_2}^{p_1}, ~ 1 \le i_1 \le n_1, ~ 1 \le i_2 \le n_2\} 44 | $$ 45 | 46 | which is basicaly 47 | $$ 48 | \mathcal{V}_h = \mathcal{V}_h^1 \otimes \mathcal{V}_h^2 49 | $$ 50 | where 51 | $$ 52 | \mathcal{V}_h^1 := \texttt{span}\{ B_{i_1}^{p_1}, ~ 1 \le i_1 \le n_1\} 53 | $$ 54 | and 55 | $$ 56 | \mathcal{V}_h^2 := \texttt{span}\{ B_{i_2}^{p_2}, ~ 1 \le i_2 \le n_2\} 57 | $$ 58 | 59 | ```python 60 | # create the spline space for each direction 61 | x1min = 0. ; x1max = 1. 62 | nelements1 = 1 63 | degree1 = 2 64 | grid1 = np.linspace( x1min, x1max, num=nelements1+1 ) 65 | V1 = SplineSpace(degree=degree1, grid=grid1) 66 | 67 | x2min = 0. ; x2max = 1. 68 | nelements2 = 1 69 | degree2 = 2 70 | grid2 = np.linspace( x2min, x2max, num=nelements2+1 ) 71 | V2 = SplineSpace(degree=degree2, grid=grid2) 72 | ``` 73 | 74 | ```python 75 | dd = DomainDecomposition(ncells=[V1.ncells, V2.ncells], periods=[False, False]) 76 | # create the tensor space 77 | V = TensorFemSpace(dd, V1, V2) 78 | ``` 79 | 80 | ## Assemble the Stiffness Matrix 81 | 82 | The stiffness matrix entries are defined as 83 | 84 | $$ 85 | M_{\textbf{i}, \textbf{j}} := \int_{\Omega} \nabla B_{\textbf{i}} \cdot \nabla B_{\textbf{j}} 86 | $$ 87 | 88 | where 89 | $$ 90 | B_{\textbf{i}}(x_1,x_2) := B_{i_1}(x_1)B_{i_2}(x_2), \quad \textbf{i} := (i_1,i_2) 91 | $$ 92 | and 93 | $$ 94 | B_{\textbf{j}}(x_1,x_2) := B_{j_1}(x_1)B_{j_2}(x_2), \quad \textbf{j} := (j_1,j_2) 95 | $$ 96 | 97 | 98 | ```python 99 | stiffness = StencilMatrix(V.vector_space, V.vector_space) 100 | stiffness = assemble_stiffness_2d( V, matrix=stiffness ) 101 | ``` 102 | 103 | ## Assemble the rhs 104 | 105 | The right hand side entries are defined as 106 | 107 | $$ 108 | F_{\textbf{i}} := \int_{\Omega} f B_{\textbf{i}} ~d\Omega 109 | $$ 110 | 111 | 112 | ```python 113 | rhs = StencilVector(V.vector_space) 114 | 115 | f = lambda x,y: 2*x*(1 - x) + 2*y*(1 - y) 116 | rhs = assemble_vector_2d( f, V, rhs=rhs ) 117 | ``` 118 | 119 | ## Imposing boundary conditions 120 | 121 | 122 | ```python 123 | s1, s2 = V.vector_space.starts 124 | e1, e2 = V.vector_space.ends 125 | 126 | # ... needed for iterative solvers 127 | # left bc at x=0. 128 | stiffness[s1,:,:,:] = 0. 129 | rhs[s1,:] = 0. 130 | # right bc at x=1. 131 | stiffness[e1,:,:,:] = 0. 132 | rhs[e1,:] = 0. 133 | # lower bc at y=0. 134 | stiffness[:,s2,:,:] = 0. 135 | rhs[:,s2] = 0. 136 | # upper bc at y=1. 137 | stiffness[:,e2,:,:] = 0. 138 | rhs[:,e2] = 0. 139 | # ... 140 | 141 | # ... needed for direct solvers 142 | # boundary x = 0 143 | #stiffness[s1,:,0,:] = 1. 144 | # boundary x = 1 145 | #stiffness[e1,:,0,:] = 1. 146 | # boundary y = 0 147 | #stiffness[:,s2,:,0] = 1. 148 | # boundary y = 1 149 | #stiffness[:,e2,:,0] = 1. 150 | # ... 151 | ``` 152 | 153 | From now on, you can use the function **apply_dirichlet** to set the dirichlet boundary conditions for both the matrix and rhs. 154 | 155 | ```python 156 | # convert the stencil matrix to scipy sparse 157 | stiffness = stiffness.tosparse() 158 | 159 | 160 | ```python 161 | # convert the stencil vector to a nd_array 162 | rhs = rhs.toarray() 163 | ``` 164 | 165 | ```python 166 | #from scipy.sparse import csc_matrix, linalg as sla 167 | 168 | #lu = sla.splu(csc_matrix(stiffness)) 169 | #x = lu.solve(rhs) 170 | ``` 171 | 172 | ```python 173 | from scipy.sparse.linalg import cg 174 | x, info = cg( stiffness, rhs, rtol=1e-7, maxiter=100 ) 175 | ``` 176 | 177 | ```python 178 | from utilities.plot import plot_field_2d 179 | nbasis = [W.nbasis for W in V.spaces] 180 | knots = [W.knots for W in V.spaces] 181 | degrees = [W.degree for W in V.spaces] 182 | u = x.reshape(nbasis) 183 | plot_field_2d(knots, degrees, u) ; plt.colorbar() 184 | ``` 185 | 186 | ![png](images/poisson-2d/output_20_1.png) 187 | -------------------------------------------------------------------------------- /chapter1/analytical-mapping.md: -------------------------------------------------------------------------------- 1 | # Analytical Mapping 2 | 3 | 4 | Analytical Mappings are provided as symbolic expressions, which allow us to compute automatically their jacobian matrices and all related geometrical information. 5 | 6 | ## Available mappings 7 | 8 | | SymPDE objects | Physical Dimension | Logical Dimension | Description | 9 | | -------------- | ----------------- | ---------------- | ----------- | 10 | | `IdentityMapping` | 1D, 2D, 3D | 1D, 2D, 3D | Identity Mapping object
$\begin{cases} x&=x_1, \\ y&=x_2, \\ z &= x_3 \end{cases} $ | 11 | | `AffineMapping` | 1D, 2D, 3D | 1D, 2D, 3D | Affine Mapping object
$\begin{cases} x &= c_1 + a_{11} x_1 + a_{12} x_2 + a_{13} x_3, \\ y &= c_2 + a_{21} x_1 + a_{22} x_2 + a_{23} x_3, \\ z &= c_3 + a_{31} x_1 + a_{32} x_2 + a_{33} x_3 \end{cases}$| 12 | | `PolarMapping` | 2D | 2D | Polar Mapping object (Annulus)
$ \begin{cases} x &= c_1 + (r_{min} (1-x_1)+r_{max} x_1) \cos(x_2), \\ y &= c_2 + (r_{min} (1-x_1)+r_{max} x_1) \sin(x_2) \end{cases} $ | 13 | | `TargetMapping` | 2D | 2D | Target Mapping object
$\begin{cases} x &= c_1 + (1-k) x_1 \cos(x_2) - D x_1^2, \\ y &= c_2 + (1+k) x_1 \sin(x_2) \end{cases}$| 14 | | `CzarnyMapping` | 2D | 2D | Czarny Mapping object
$\begin{cases} x &= \frac{1}{\epsilon}(1 - \sqrt{ 1 + \epsilon (\epsilon + 2 x_1 \cos(x_2)) }), \\ y &= c_2 + \frac{b}{\sqrt{1-\epsilon^2/4}} \frac{ x_1 \sin(x_2)}{2 - \sqrt{ 1 + \epsilon (\epsilon + 2 x_1 \cos(x_2)) }} \end{cases}$| 15 | | `CollelaMapping2D` | 2D | 2D | Collela Mapping object
$\begin{cases} x &= 2 (x_1 + \epsilon \sin(2 \pi k_1 x_1) \sin(2 \pi k_2 x_2)) - 1, \\ y &= 2 (x_2 + \epsilon \sin(2 \pi k_1 x_1) \sin(2 \pi k_2 x_2)) - 1 \end{cases}$| 16 | | `TorusMapping` | 3D | 3D | Parametrization of a torus (or a portion of it)
$\begin{cases} x &= (R_0 + x_1 \cos(x_2)) \cos(x_3), \\ y &= (R_0 + x_1 \cos(x_2)) \sin(x_3), \\ z &= x_1 \sin(x_2) \end{cases}$| 17 | | `TorusSurfaceMapping` | 3D | 2D | surface obtained by "slicing" the torus above at r = a
$\begin{cases} x &= (R_0 + a \cos(x_1)) \cos(x_2), \\ y &= (R_0 + a \cos(x_1)) \sin(x_2), \\ z &= a \sin(x_1) \end{cases}$| 18 | | `TwistedTargetSurfaceMapping` | 3D | 2D | surface obtained by "twisting" the `TargetMapping` out of the (x, y) plane
$\begin{cases} x &= c_1 + (1-k) x_1 \cos(x_2) - D x_1^2 \\ y &= c_2 + (1+k) x_1 \sin(x_2) \\ z &= c_3 + x_1^2 \sin(2 x_2) \end{cases}$| 19 | | `TwistedTargetMapping` | 3D | 3D | volume obtained by "extruding" the `TwistedTargetSurfaceMapping` along z
$\begin{cases} x &= c_1 + (1-k) x_1 \cos(x_2) - D x_1^2, \\ y &= c_2 + (1+k) x_1 \sin(x_2), \\ z &= c_3 + x_3 x_1^2 \sin(2 x_2) \end{cases}$| 20 | | `SphericalMapping` | 3D | 3D | Parametrization of a sphere (or a portion of it)
$\begin{cases} x &= x_1 \sin(x_2) \cos(x_3), \\ y &= x_1 \sin(x_2) \sin(x_3), \\ z &= x_1 \cos(x_2) \end{cases}$| 21 | 22 | ## Examples 23 | 24 | 25 | ```python 26 | from sympde.topology import Square 27 | from sympde.topology import PolarMapping 28 | 29 | ldomain = Square('A',bounds1=(0., 1.), bounds2=(0, np.pi)) 30 | mapping = PolarMapping('M1',2, c1= 0., c2= 0., rmin = 0., rmax=1.) 31 | 32 | domain = mapping(ldomain) 33 | 34 | x,y = domain.coordinates 35 | ``` 36 | 37 | 38 | ```python 39 | mapping_1 = IdentityMapping('M1', 2) 40 | mapping_2 = PolarMapping ('M2', 2, c1 = 0., c2 = 0.5, rmin = 0., rmax=1.) 41 | mapping_3 = AffineMapping ('M3', 2, c1 = 0., c2 = np.pi, a11 = -1, a22 = -1, a21 = 0, a12 = 0) 42 | 43 | A = Square('A',bounds1=(0.5, 1.), bounds2=(-1., 0.5)) 44 | B = Square('B',bounds1=(0.5, 1.), bounds2=(0, np.pi)) 45 | C = Square('C',bounds1=(0.5, 1.), bounds2=(np.pi-0.5, np.pi + 1)) 46 | 47 | D1 = mapping_1(A) 48 | D2 = mapping_2(B) 49 | D3 = mapping_3(C) 50 | 51 | connectivity = [((0,1,1),(1,1,-1)), ((1,1,1),(2,1,-1))] 52 | patches = [D1, D2, D3] 53 | domain = Domain.join(patches, connectivity, 'domain') 54 | ``` 55 | 56 | ```python 57 | A = Square('A',bounds1=(0.2, 0.6), bounds2=(0, np.pi)) 58 | B = Square('B',bounds1=(0.2, 0.6), bounds2=(np.pi, 2*np.pi)) 59 | C = Square('C',bounds1=(0.6, 1.), bounds2=(0, np.pi)) 60 | D = Square('D',bounds1=(0.6, 1.), bounds2=(np.pi, 2*np.pi)) 61 | 62 | mapping_1 = PolarMapping('M1',2, c1= 0., c2= 0., rmin = 0., rmax=1.) 63 | mapping_2 = PolarMapping('M2',2, c1= 0., c2= 0., rmin = 0., rmax=1.) 64 | mapping_3 = PolarMapping('M3',2, c1= 0., c2= 0., rmin = 0., rmax=1.) 65 | mapping_4 = PolarMapping('M4',2, c1= 0., c2= 0., rmin = 0., rmax=1.) 66 | 67 | D1 = mapping_1(A) 68 | D2 = mapping_2(B) 69 | D3 = mapping_3(C) 70 | D4 = mapping_4(D) 71 | 72 | connectivity = [((0,1,1),(1,1,-1)), ((2,1,1),(3,1,-1)), ((0,0,1),(2,0,-1)),((1,0,1),(3,0,-1))] 73 | patches = [D1, D2, D3, D4] 74 | domain = Domain.join(patches, connectivity, 'domain') 75 | ``` 76 | -------------------------------------------------------------------------------- /chapter1/boundary-conditions.md: -------------------------------------------------------------------------------- 1 | # Boundary Conditions 2 | 3 | 4 | SymPDE & Psydac allows you to use both strong and weak boundary conditions. 5 | We start first by explaining how to identify a boundary in **NCube** domains, such as **Line**, **Square** and a **Cube**. 6 | 7 | ## Identifying a boundary in **NCube** domains 8 | 9 | Since we're dealing with **NCube** domains, the best way to identify a boundary is to use the couple **(axis, extremity)**. The axis is usually defined as perpendicular to the boundary, while the **extremity** gives the lower or upper bound of the interval associated to the **axis**. 10 | 11 | Let's see it through the following examples; 12 | 13 | For a **Line**, the following figure gives the value to access a boundary. 14 | 15 | ![png](images/boundary-conditions/line-boundaries.png) 16 | 17 | For a **Square**, we have, 18 | 19 | ![png](images/boundary-conditions/square-boundaries.png) 20 | 21 | For a **Cube**, it is similar and would not be helpful to visualize it here. 22 | 23 | ## Essential boundary conditions 24 | 25 | Essential boundary conditions are usually treated in two ways, either in the strong or weak form. The latter can be achieved through the use of Nitsche's method. You can check the associated examples in the sequel. 26 | 27 | For the essential boundary conditions, usually, one needs one of the following expressions; 28 | 29 | $$ 30 | \begin{align} 31 | u &= 0, \quad \text{(homogeneous case)}, \\ 32 | u &= f, \quad \text{(inhomogeneous case)}, \\ 33 | \mathbf{v} &= 0, \quad \text{(homogeneous case)}, \\ 34 | \mathbf{v} &= \mathbf{g}, \quad \text{(homogeneous case)}, 35 | \end{align} 36 | $$ 37 | 38 | where $u$ and $f$ are scalar functions while $\mathbf{v}$ and $\mathbf{g}$ denote vector functions. 39 | 40 | 41 | Let `Gamma` denotes the boundary $\Gamma$. 42 | The normal derivative is an available operator in SymPDE, it is provided as `Dn` operator. Alternatively, you can also define it manually, 43 | 44 | ```python 45 | nn = NormalVector('nn') 46 | dn = lambda a: dot(grad(a), nn) 47 | ``` 48 | 49 | 50 | we have the following equivalences, 51 | 52 | | Mathematical Expression | SymPDE Expression | Example | 53 | | --------------------------------------------------------- | ------------------------------ | ---------------------------------- | 54 | | $u = 0$ on $\Gamma$ | `EssentialBC(u, 0, Gamma)` | | 55 | | $u = f$ on $\Gamma$ | `EssentialBC(u, f, Gamma)` | | 56 | | $\partial_n u = 0$ on $\Gamma$ | `EssentialBC(dn(u), 0, Gamma)` | | 57 | | $\partial_n u = f$ on $\Gamma$ | `EssentialBC(dn(u), f, Gamma)` | | 58 | | $\mathbf{v} = 0$ on $\Gamma$ | `EssentialBC(v, 0, Gamma)` | | 59 | | $\mathbf{v} = \mathbf{g}$ on $\Gamma$ | `EssentialBC(v, g, Gamma)` | | 60 | | $\mathbf{v} \cdot \mathbf{n} = 0$ on $\Gamma$ | ? | | 61 | | $\mathbf{v} \times \mathbf{n} = 0$ on $\Gamma$ | ? | | 62 | | $\mathbf{v} \cdot \mathbf{n} = f,\mathbf{g}$ on $\Gamma$ | ? | | 63 | | $\mathbf{v} \times \mathbf{n} = f,\mathbf{g}$ on $\Gamma$ | ? | | 64 | 65 | -------------------------------------------------------------------------------- /chapter1/discrete-mapping.md: -------------------------------------------------------------------------------- 1 | # Discrete Mapping 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /chapter1/geometry.md: -------------------------------------------------------------------------------- 1 | # Geometry 2 | 3 | 4 | The IGA concept relies on the fact that the geometry (domain) is divided into subdomains, and each of these subdomains is the image of a **Line**, **Square** or a **Cube** by a geometric transformation (also called a **mapping**), that we shall call a **patch** or **logical domain**. 5 | 6 | The following example shows a domain (half of annulus) that is the image of a logical domain using the mapping **F**. Each element (or cell) $Q$ of the logical domain is then mapped into an element $K$ of our domain, *i.e.* $K = \mathbf{F}(Q)$. 7 | 8 | ![png](images/geometry/element.png) 9 | 10 | Coordinates in the logical domain are defined by the variables $\left( x_1, x_2, x_3 \right)$ while the physical coordinates are denoted by $\left( x,y,z \right)$. 11 | 12 | ## How to define a geometry? 13 | 14 | Depending on your problem, you can be in one of the following situations; 15 | - your geometry is trivial, *i.e.* it is a **Line**, **Square** or a **Cube**. In this case, just use the **SymPDE** adhoc constructors, for which you'll define the bounds. 16 | - your geometry can be defined using an **Analytical Mapping**. See the next section. 17 | - your geometry can be defined using a **Discrete Mapping**. See the next sections. 18 | 19 | -------------------------------------------------------------------------------- /chapter1/images/boundary-conditions/line-boundaries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter1/images/boundary-conditions/line-boundaries.png -------------------------------------------------------------------------------- /chapter1/images/boundary-conditions/square-boundaries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter1/images/boundary-conditions/square-boundaries.png -------------------------------------------------------------------------------- /chapter1/images/ch1-jupyter-poisson-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter1/images/ch1-jupyter-poisson-1.png -------------------------------------------------------------------------------- /chapter1/images/ch1-jupyter-poisson-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter1/images/ch1-jupyter-poisson-2.png -------------------------------------------------------------------------------- /chapter1/images/ch1-jupyter-root.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter1/images/ch1-jupyter-root.png -------------------------------------------------------------------------------- /chapter1/images/geometry/element.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/chapter1/images/geometry/element.png -------------------------------------------------------------------------------- /chapter1/install.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | To run the examples in this guide, we recommend to follow these steps: 4 | 5 | 1. Download the [IGA-Python] repository and then install its dependencies. 6 | 7 | ```bash 8 | # Download IGA-Python 9 | git clone https://github.com/pyccel/IGA-Python.git 10 | cd IGA-Python 11 | 12 | # Install required Python packages 13 | python3 -m venv iga-python-env 14 | source iga-python-env/bin/activate 15 | pip3 install -r requirements_ntbk.txt 16 | ``` 17 | 18 | 2. Install Psydac. Skip this step if Psydac is already installed on your system. 19 | 20 | ```bash 21 | # Modify these variables if you're using your own psydac fork/branch 22 | PSYDAC_REMOTE="https://github.com/pyccel/psydac.git" 23 | BRANCH="devel" 24 | 25 | # Install psydac 26 | pip install git+${PSYDAC_REMOTE}@${BRANCH} 27 | ``` 28 | 29 | 3. Access [IGA-Python] examples through Jupyter notebook. 30 | 31 | ```shell 32 | # Run this command under IGA-Python folder 33 | jupyter notebook 34 | ``` 35 | 36 | Running `jupyter notebook` should automatically launch your web browser and show you the files in the current directory—in this case the [IGA-Python] files: 37 | 38 | ![png](images/ch1-jupyter-root.png) 39 | 40 | Try opening a sample notebook, e.g. `chapter1/poisson.ipynb`: 41 | 42 | ![png](images/ch1-jupyter-poisson-1.png) 43 | 44 | 45 | Open `poisson.ipynb` and verify that you can successfully run all cells in this notebook. 46 | 47 | ![png](images/ch1-jupyter-poisson-2.png) 48 | 49 | 50 | 3. When you close Jupyter and would like to run the [IGA-Python] examples, just open your Terminal/Console app and run these commands: 51 | 52 | ```shell 53 | cd /full/path/to/your/IGA-Python # Change this to where your IGA-Python folder is located 54 | source iga-python-env/bin/activate 55 | jupyter notebook 56 | ``` 57 | 58 | **Congratulations!** You can now head over to the [Poisson example problem](poisson.ipynb) to get started. 59 | 60 | [IGA-Python]: https://github.com/pyccel/IGA-Python.git 61 | -------------------------------------------------------------------------------- /chapter1/rules.md: -------------------------------------------------------------------------------- 1 | # Algebraic and differential operators evalution rules 2 | 3 | 4 | ## Evaluation of the $\mathrm{grad}$ operator 5 | 6 | Rule ID | symbolic expression | evaluation 7 | --- | --- | --- 8 | `[OG1]` | $\mathrm{grad}(f+g)$ | $\mathrm{grad}(f) + \mathrm{grad}(g)$ 9 | `[OG2]` | $\mathrm{grad}(\alpha ~ f)$ | $\alpha~\mathrm{grad}(f)$ 10 | `[OG3]` | $\mathrm{grad}(f ~ g)$ | $f~\mathrm{grad}(g) + g~\mathrm{grad}(f)$ 11 | `[OG4]` | $\mathrm{grad}(\frac{f}{g})$ | $-\frac{f}{g^2}\mathrm{grad}(g) + \frac{1}{g}\mathrm{grad}(f)$ 12 | `[OG5]` | $\mathrm{grad}(F+G)$ | $\mathrm{grad}(F) + \mathrm{grad}(G)$ 13 | `[OG6]` | $\mathrm{grad}(\alpha ~ F)$ | $\alpha~\mathrm{grad}(F)$ 14 | `[OG7]` | $\mathrm{grad}(\mathrm{dot}(F, G))$ | $\mathrm{convect}(F, G) + \mathrm{convect}(G, F) + \mathrm{cross}(F, \mathrm{curl}(G)) - \mathrm{cross}(\mathrm{curl}(F), G)$ 15 | 16 | ## Evaluation of $\mathrm{curl}$ and $\mathrm{rot}$ operators in 2D 17 | 18 | Rule ID | symbolic expression | evaluation 19 | --- | --- | --- 20 | `[OC1a]` | $\mathrm{curl}(f+g)$ | $\mathrm{curl}(f) + \mathrm{curl}(g)$ 21 | `[OC2a]` | $\mathrm{curl}(\alpha ~ f)$ | $\alpha~\mathrm{curl}(f)$ 22 | `[OC1b]` | $\mathrm{rot}(F+G)$ | $\mathrm{rot}(F) + \mathrm{rot}(G)$ 23 | `[OC2b]` | $\mathrm{rot}(\alpha ~ F)$ | $\alpha~\mathrm{rot}(F)$ 24 | 25 | 26 | ## Evaluation of $\mathrm{curl}$ operator in 3D 27 | 28 | Rule ID | symbolic expression | evaluation 29 | --- | --- | --- 30 | `[OC1]` | $\mathrm{curl}(F+G)$ | $\mathrm{curl}(F) + \mathrm{curl}(G)$ 31 | `[OC2]` | $\mathrm{curl}(\alpha ~ F)$ | $\alpha~\mathrm{curl}(F)$ 32 | `[OC3]` | $\mathrm{curl}(f ~ F)$ | $f~\mathrm{curl}(F) + \mathrm{cross}(\mathrm{grad}(f), F)$ 33 | `[OC4]` | $\mathrm{curl}(\mathrm{cross}(F, G))$ | $\mathrm{div}(G)~F - \mathrm{div}(F)~G - \mathrm{convect}(F, G) +\mathrm{convect}(G, F)$ 34 | 35 | ## Evaluation of $\mathrm{div}$ operator 36 | 37 | Rule ID | symbolic expression | evaluation 38 | --- | --- | --- 39 | `[OD1]` | $\mathrm{div}(F+G)$ | $\mathrm{div}(F) + \mathrm{div}(G)$ 40 | `[OD2]` | $\mathrm{div}(\alpha ~ F)$ | $\alpha~\mathrm{div}(F)$ 41 | `[OD3]` | $\mathrm{div}(f ~ G)$ | $f~\mathrm{div}(G) + \mathrm{dot}(G, \mathrm{grad}(f))$ 42 | `[OD4]` | $\mathrm{div}(\mathrm{cross}(F, G))$ | $-\mathrm{dot}(F, \mathrm{curl}(G)) + \mathrm{dot}(G, \mathrm{curl}(F))$ 43 | 44 | ## Evaluation of $\mathrm{laplace}$ operator 45 | 46 | Rule ID | symbolic expression | evaluation 47 | --- | --- | --- 48 | `[OL1]` | $\mathrm{laplace}(f+g)$ | $\mathrm{laplace}(f) + \mathrm{laplace}(g)$ 49 | `[OL2]` | $\mathrm{laplace}(\alpha ~ f)$ | $\alpha~\mathrm{laplace}(f)$ 50 | `[OL3]` | $\mathrm{laplace}(f~g)$ | $f ~ \mathrm{laplace}(g) + g ~ \mathrm{laplace}(f) + 2 \mathrm{dot}(\mathrm{grad}(f), \mathrm{grad}(g))$ 51 | 52 | ## Evaluation of specific combination of operators 53 | 54 | Rule ID | symbolic expression | evaluation 55 | --- | --- | --- 56 | `[OS1]` | $\mathrm{curl}(\mathrm{grad}(f))$ | $0$ 57 | `[OS2]` | $\mathrm{div}(\mathrm{curl}(F))$ | $0$ 58 | `[OS3]` | $\mathrm{div}(\mathrm{cross}(\mathrm{grad}(F), \mathrm{grad}(G)))$ | $0$ 59 | `[OS4]` | $\mathrm{curl}(\mathrm{curl}(F))$ | $\mathrm{grad}(\mathrm{div}(F)) - \mathrm{laplace}(F)$ 60 | `[OS5]` | $\mathrm{curl}(f~\mathrm{grad}(g))$ | $\mathrm{cross}(\mathrm{grad}(f), \mathrm{grad}(g))$ 61 | 62 | -------------------------------------------------------------------------------- /chapter1/space.md: -------------------------------------------------------------------------------- 1 | # Function Space concepts 2 | 3 | 4 | SymPDE provides two Python classes to describe scalar and vector function spaces, respectively. There is no notion of a discrete representation; for example, we do not need to mention that a space is a Brezzi-Douglas-Marini (BDM) space. In fact, these kind of function spaces can be seen as parametric types having as a basic type **ScalarFunctionSpace** or **VectorFunctionSpace**. SymPDE only needs to know if an element of the space can be indexed or not. A BDM space would then be identified by an annotation added by a third party library to uniquely define a function space at the discrete level. 5 | 6 | ## BasicFunctionSpace 7 | 8 | This represents the base class of all our function spaces. It does not reflect a continuous space, but it is more a **type** at the formal/abstract level. 9 | 10 | ## ScalarFunctionSpace 11 | 12 | ```python 13 | >>> domain = Domain('Omega', dim=2) 14 | >>> V1 = ScalarFunctionSpace('V1', domain) 15 | ``` 16 | 17 | ## VectorFunctionSpace 18 | 19 | ```python 20 | >>> domain = Domain('Omega', dim=2) 21 | >>> W1 = VectorFunctionSpace('W1', domain) 22 | ``` 23 | 24 | ## Typed Spaces 25 | ```python 26 | >>> domain = Domain('Omega', dim=2) 27 | >>> H1 = ScalarFunctionSpace('V0', domain, kind='H1') 28 | >>> Hcurl = VectorFunctionSpace('V1', domain, kind='Hcurl') 29 | >>> Hdiv = VectorFunctionSpace('V2', domain, kind='Hdiv') 30 | >>> L2 = ScalarFunctionSpace('V3', domain, kind='L2') 31 | >>> assert(H1.kind == H1Space) 32 | >>> assert(Hcurl.kind == HcurlSpace) 33 | >>> assert(Hdiv.kind == HdivSpace) 34 | >>> assert(L2.kind == L2Space) 35 | >>> assert(V.kind == UndefinedSpace) 36 | >>> assert(W.kind == UndefinedSpace) 37 | >>> assert(H1.regularity > L2.regularity) 38 | >>> assert(H1.regularity > Hcurl.regularity) 39 | >>> assert(Hcurl.regularity > L2.regularity) 40 | ``` 41 | 42 | ## ProductSpace 43 | 44 | ```python 45 | >>> domain = Domain('Omega', dim=2) 46 | >>> V1 = ScalarFunctionSpace('V1', domain) 47 | >>> V2 = ScalarFunctionSpace('V2', domain) 48 | >>> W1 = VectorFunctionSpace('W1', domain) 49 | >>> X = V1 * V2 * W1 50 | >>> # or 51 | >>> X = ProductSpace(V1, V2, W1) 52 | ``` 53 | 54 | ## Derham 55 | 56 | ## Functions 57 | 58 | ### ScalarFunction 59 | A scalar function is necessary an element of the **ScalarFunctionSpace**. 60 | 61 | ### IndexedVectorFunction 62 | ### VectorFunction 63 | A vector function is necessary an element of the **VectorFunctionSpace**. It is an extension of the **IndexedVectorFunction**, which means that one can access to its components. 64 | 65 | ## Trace 66 | 67 | ### trace_0 68 | ### trace_1 69 | 70 | ## Utilities 71 | ### element_of and elements_of 72 | 73 | ## Projection (Experimental) 74 | 75 | ## Projector (Experimental) 76 | 77 | 78 | -------------------------------------------------------------------------------- /chapter2/poisson-mixed.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1a4e2078", 6 | "metadata": {}, 7 | "source": [ 8 | "# Mixed FEM for the Poisson problem\n", 9 | "\n", 10 | "Let $\\Omega \\subset \\mathbb{R}^3$ and consider the Poisson problem\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align}\n", 14 | " \\left\\{ \n", 15 | " \\begin{array}{clr}\n", 16 | " -\\Delta p & =f & ,~\\Omega \\\\\n", 17 | " p & =0 & ,~\\partial \\Omega\n", 18 | " \\end{array} \\right.\n", 19 | "\\end{align}\n", 20 | "$$\n", 21 | "\n", 22 | "Using that $\\Delta p = \\nabla\\cdot\\nabla p$, we set $ \\mathbf{u}=\\nabla p$, then the Poisson equation can be written equivalently\n", 23 | "\n", 24 | "$$ \\mathbf{u}=-\\nabla p, ~~~ \\nabla\\cdot \\mathbf{u}= f.$$" 25 | ] 26 | } 27 | ], 28 | "metadata": {}, 29 | "nbformat": 4, 30 | "nbformat_minor": 5 31 | } 32 | -------------------------------------------------------------------------------- /chapter2/poisson-nitsche.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "119eb328", 6 | "metadata": {}, 7 | "source": [ 8 | "# The Poisson equation with weak imposition of Dirichlet conditions\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "3a5e01a2", 14 | "metadata": {}, 15 | "source": [ 16 | "In this example, we consider the following Poisson problem\n", 17 | "\n", 18 | "$$\n", 19 | "\\begin{align}\n", 20 | " - \\nabla^2 u = f \\quad \\text{in $\\Omega$}, \\quad \\quad \n", 21 | " u = g \\quad \\text{on $\\partial \\Omega$}.\n", 22 | "\\end{align}\n", 23 | "$$" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "id": "505861ef", 29 | "metadata": {}, 30 | "source": [ 31 | "## The variational formulation\n", 32 | "\n", 33 | "$$\n", 34 | "\\begin{align}\n", 35 | " \\text{find $u \\in V$ such that} \\quad a(u,v) = l(v) \\quad \\forall v \\in V,\n", 36 | "\\end{align}\n", 37 | "$$\n", 38 | "\n", 39 | "where \n", 40 | "\n", 41 | "- $V \\subset H^1(\\Omega)$, \n", 42 | "- $a(u,v) := \\int_{\\Omega} \\nabla u \\cdot \\nabla v ~ d\\Omega + \\int_{\\partial \\Omega} \\left( \\kappa u v - u \\partial_n v - v \\partial_n u \\right)~d\\partial\\Omega $,\n", 43 | "- $l(v) := \\int_{\\Omega} f v ~ d\\Omega + \\int_{\\partial\\Omega} \\left( \\kappa g v - g \\partial_n v \\right) ~ d\\Gamma$.\n" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "id": "d4f55f53", 49 | "metadata": {}, 50 | "source": [ 51 | "## Formal Model" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "id": "ecd1330a", 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "from sympde.expr import BilinearForm, LinearForm, integral, Norm\n", 62 | "from sympde.expr import find, EssentialBC\n", 63 | "from sympde.topology import ScalarFunctionSpace, Square, element_of\n", 64 | "from sympde.calculus import grad, dot, Dn\n", 65 | "from sympde.core import Constant\n", 66 | "\n", 67 | "from psydac.api.discretization import discretize\n", 68 | "\n", 69 | "from sympy import pi, sin\n", 70 | "\n", 71 | "kappa = Constant('kappa', is_real=True)\n", 72 | "\n", 73 | "domain = Square()\n", 74 | "\n", 75 | "V = ScalarFunctionSpace('V', domain)\n", 76 | "\n", 77 | "x,y = domain.coordinates\n", 78 | "\n", 79 | "u,v = [element_of(V, name=i) for i in ['u', 'v']]\n", 80 | "\n", 81 | "# bilinear form\n", 82 | "a = BilinearForm((u,v), integral(domain, dot(grad(v), grad(u))))\n", 83 | "an = BilinearForm((u,v), integral(domain.boundary, kappa*u*v - u*Dn(v) - v*Dn(u)))\n", 84 | "\n", 85 | "# linear form\n", 86 | "ue = sin(pi*x)*sin(pi*y)\n", 87 | "g = ue\n", 88 | "f = 2*pi**2*sin(pi*x)*sin(pi*y)\n", 89 | "\n", 90 | "l = LinearForm(v, integral(domain, f*v))\n", 91 | "ln = LinearForm(v, integral(domain.boundary, kappa*g*v - g*Dn(v)))\n", 92 | "\n", 93 | "# Variational problem\n", 94 | "equation = find(u, forall=v, lhs=a(u,v) + an(u,v), rhs=l(v) + ln(v))" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "id": "11ed2bc5", 100 | "metadata": {}, 101 | "source": [ 102 | "## Discretization" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "id": "3d86674b", 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "degree = [2,2]\n", 113 | "ncells = [8,8]" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "id": "94c83267", 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "# Create computational domain from topological domain\n", 124 | "domain_h = discretize(domain, ncells=ncells, comm=None)\n", 125 | "\n", 126 | "# Create discrete spline space\n", 127 | "Vh = discretize(V, domain_h, degree=degree)\n", 128 | "\n", 129 | "# Discretize equation\n", 130 | "equation_h = discretize(equation, domain_h, [Vh, Vh])" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "id": "85318e35", 136 | "metadata": {}, 137 | "source": [ 138 | "### Solving the PDE" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": null, 144 | "id": "8f1b2d68", 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "equation_h.set_solver('gmres', info=False, tol=1e-8)" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "id": "e96f321c", 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "uh = equation_h.solve(kappa=1e3)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "markdown", 163 | "id": "d87fd79f", 164 | "metadata": {}, 165 | "source": [ 166 | "## Computing the error norm" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "id": "08ee5cac", 172 | "metadata": {}, 173 | "source": [ 174 | "### Computing the $L^2$ norm" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "id": "068bdb95", 181 | "metadata": {}, 182 | "outputs": [], 183 | "source": [ 184 | "u = element_of(V, name='u')\n", 185 | "\n", 186 | "# create the formal Norm object\n", 187 | "l2norm = Norm(u - ue, domain, kind='l2')\n", 188 | "\n", 189 | "# discretize the norm\n", 190 | "l2norm_h = discretize(l2norm, domain_h, Vh)\n", 191 | "\n", 192 | "# assemble the norm\n", 193 | "l2_error = l2norm_h.assemble(u=uh)\n", 194 | "\n", 195 | "# print the result\n", 196 | "print(l2_error)" 197 | ] 198 | } 199 | ], 200 | "metadata": {}, 201 | "nbformat": 4, 202 | "nbformat_minor": 5 203 | } 204 | -------------------------------------------------------------------------------- /chapter2/stokes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9f28f9af", 6 | "metadata": {}, 7 | "source": [ 8 | "# Mixed FEM for the Stokes problem \n", 9 | "\n", 10 | "We consider now the Stokes problem for the steady-state modelling of an incompressible fluid\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align}\n", 14 | " \\left\\{\n", 15 | " \\begin{array}{rl}\n", 16 | " - \\nabla^2 \\mathbf{u} + \\nabla p = \\mathbf{f} & \\mbox{in} ~ \\Omega, \\\\\n", 17 | " \\nabla \\cdot \\mathbf{u} = 0 & \\mbox{in} ~ \\Omega, \\\\\n", 18 | " \\mathbf{u} = 0 & \\mbox{on} ~ \\partial \\Omega,\n", 19 | " \\end{array}\n", 20 | " \\right.\n", 21 | "\\end{align}\n", 22 | "$$" 23 | ] 24 | } 25 | ], 26 | "metadata": {}, 27 | "nbformat": 4, 28 | "nbformat_minor": 5 29 | } 30 | -------------------------------------------------------------------------------- /chapter3/burgers.md: -------------------------------------------------------------------------------- 1 | # 1D Burgers equation 2 | 3 | 4 | We consider the 1d Burgers equation 5 | 6 | $$ 7 | \partial_t u + u \partial_x u = \nu \frac{\partial ^2u}{\partial x^2} 8 | $$ 9 | 10 | $u_0(x) := u(x,t)$ denotes the initial condition. 11 | We choose homogeneous neumann boundary conditions in this example, i.e. 12 | $$\partial_n u = 0, \partial \Omega$$ with $\Omega = (0,1)$ 13 | 14 | ## Time scheme 15 | We shall use a $\theta$-scheme in this case and consider the following problem 16 | 17 | $$ 18 | \begin{align} 19 | \frac{u^{n+1}-u^n}{\Delta t} + 20 | \theta~ u^{n+1} \partial_x u^{n+1} + (1-\theta)~ u^n \partial_x u^n = \theta~\nu \frac{\partial ^2u^{n+1}}{\partial x^2} + (1-\theta)~\nu \frac{\partial ^2u^{n}}{\partial x^2} 21 | \end{align} 22 | $$ 23 | 24 | hence 25 | 26 | $$ 27 | \begin{align} 28 | u^{n+1} + \Delta t ~ \theta~ u^{n+1} \partial_x u^{n+1} - \Delta t ~ \theta~\nu \frac{\partial ^2u^{n+1}}{\partial x^2} = 29 | u^{n} - \Delta t ~ (1-\theta)~ u^{n} \partial_x u^{n} + \Delta t ~ (1-\theta)~\nu \frac{\partial ^2u^{n}}{\partial x^2} 30 | \end{align} 31 | $$ 32 | 33 | from now on, we shall denote by $f^n$ the right hand side of the previous equation 34 | 35 | $$f^n := u^{n} - \Delta t ~ (1-\theta)~ u^{n} \partial_x u^{n} + \Delta t ~ (1-\theta)~\nu \frac{\partial ^2u^{n}}{\partial x^2}$$ 36 | 37 | ## Weak formulation 38 | 39 | Let $v \in \mathcal{V}$ be a function test, we have by integrating by parts the highest order term: 40 | 41 | $$ 42 | \begin{align} 43 | \langle v, u^{n+1} \rangle + \Delta t ~ \theta~ \langle v, u^{n+1} \partial_x u^{n+1} \rangle + \Delta t ~ \theta~\nu \langle \frac{\partial v}{\partial x}, \frac{\partial u^{n+1}}{\partial x} \rangle = \langle v, f^n \rangle 44 | \end{align} 45 | $$ 46 | 47 | The previous weak formulation is still nonlinear with respect to $u^{n+1}$. We shall then follow the same strategy as for the previous chapter on nonlinear Poisson problem. 48 | 49 | The strategy is to define the left hand side as a **LinearForm** with respect to $v$, then linearize it around $u^{n+1}$. We therefor can use either Picard or Newton method to treat the nonlinearity. 50 | 51 | We consider the following linear form 52 | 53 | $$ 54 | \begin{align} 55 | G(v;u,w) := \langle v, u \rangle + \Delta t ~ \theta~ \langle v, w \partial_x u \rangle + \Delta t ~ \theta~\nu \langle \frac{\partial v}{\partial x}, \frac{\partial u}{\partial x} \rangle , \quad \forall u,v,w \in \mathcal{V} 56 | \end{align} 57 | $$ 58 | 59 | Our problem is then 60 | 61 | $$ 62 | \begin{align} 63 | \mbox{Find } u^{n+1} \in \mathcal{V}, \mbox{such that}\\ 64 | G(v;u^{n+1},u^{n+1}) = l(v), \quad \forall v \in \mathcal{V} 65 | \end{align} 66 | $$ 67 | 68 | where 69 | 70 | $$ 71 | l(v) := \int_{\Omega} f^n v ~d\Omega, \quad \forall v \in \mathcal{V} 72 | $$ 73 | 74 | ## SymPDE code 75 | 76 | ```python 77 | domain = Line() 78 | 79 | V = ScalarFunctionSpace('V', domain) 80 | u = element_of(V, name='u') 81 | v = element_of(V, name='v') 82 | w = element_of(V, name='w') 83 | un = element_of(V, name='un') # time iteration 84 | uk = element_of(V, name='uk') # nonlinear solver iteration 85 | 86 | x = domain.coordinates 87 | 88 | nu = Constant('nu') 89 | theta = Constant('theta') 90 | dt = Constant('dt') 91 | ``` 92 | 93 | ### Defining the Linear form $G$ 94 | 95 | ```python 96 | # Linear form g: V --> R 97 | expr = v * u + dt*theta*v*w*dx(u) + dt*theta*nu*dx(v)*dx(u) 98 | g = LinearForm(v, integral(domain, expr)) 99 | ``` 100 | 101 | ### Defining the Linear form $l$ 102 | 103 | ```python 104 | # Linear form l: V --> R 105 | expr = v * un - dt*theta*v*un*dx(un) - dt*theta*nu*dx(v)*dx(un) 106 | l = LinearForm(v, integral(domain, expr)) 107 | ``` 108 | 109 | 110 | ### Picard Method 111 | 112 | $$ 113 | \begin{align} 114 | \mbox{Find } u_{n+1} \in \mathcal{V}\_h, \mbox{such that}\\ 115 | G(v;u_{n+1},u_n) = l(v), \quad \forall v \in \mathcal{V}\_h 116 | \end{align} 117 | $$ 118 | 119 | #### Picard iteration 120 | 121 | ```python 122 | # Variational problem 123 | picard = find(u, forall=v, lhs=g(v, u=u,w=uk), rhs=l(v)) 124 | ``` 125 | 126 | ### Newton Method 127 | 128 | Let's define 129 | 130 | $$ 131 | F(v;u) := G(v;u,u) -l(v), \quad \forall v \in \mathcal{V} 132 | $$ 133 | 134 | Newton method writes 135 | 136 | $$ 137 | \begin{align} 138 | \mbox{Find } u_{n+1} \in \mathcal{V}\_h, \mbox{such that}\\ 139 | F^{\prime}(\delta u,v; u_n) = - F(v;u_n), \quad \forall v \in \mathcal{V} \\ 140 | u_{n+1} := u_{n} + \delta u, \quad \delta u \in \mathcal{V} 141 | \end{align} 142 | $$ 143 | 144 | #### Newton iteration 145 | 146 | ```python 147 | F = LinearForm(v, g(v,w=u)-l(v)) 148 | du = element_of(V, name='du') 149 | 150 | Fprime = linearize(F, u, trials=du) 151 | 152 | # Variational problem 153 | newton = find(du, forall=v, lhs=Fprime(du, v,u=uk), rhs=-F(v,u=uk)) 154 | ``` 155 | 156 | -------------------------------------------------------------------------------- /chapter3/navier-stokes-steady-streamfunction-velocity.md: -------------------------------------------------------------------------------- 1 | # The streamfunction-velocity formulation of the steady-state Navier-Stokes equations for incompressible fluids 2 | 3 | 4 | When $\Omega$ is a simply connected 2D domain, there exists a unique function $\psi$ such that $\mathbf{u} = \boldsymbol{\nabla} \times \psi:= \left( \partial_y \psi, - \partial_x \psi \right)$; 5 | substituting this expression for $\mathbf{u}$ into \eqref{eq:steady-navier-stokes} leads to the so-called ``streamfunction-velocity formulation'' of the steady-state Navier-Stokes equations for an incompressible fluid. 6 | For more details we refer the reader to \cite{TAGLIABUE2014277}. 7 | The variational formulation is then given by: 8 | 9 | $$ 10 | \begin{align} 11 | \text{find $\psi \in V$ such that} \quad 12 | a(\psi,\phi) + b(\psi,\phi;\psi) = l(\phi) 13 | \quad \forall \phi \in V, 14 | \end{align} 15 | $$ 16 | 17 | where $V \subset H^2(\Omega)$ and 18 | 19 | $$ 20 | \begin{align*} 21 | a(\psi, \phi) := \int_{\Omega} D\left( \boldsymbol{\nabla} \times \psi \right) : D\left(\boldsymbol{\nabla} \times \phi \right) ~d\Omega, 22 | \quad 23 | b(\psi, \phi; \xi) := \int_{\Omega} \left( \left(\boldsymbol{\nabla} \times \xi \cdot \nabla \right) \boldsymbol{\nabla} \times \psi \right) \cdot \boldsymbol{\nabla} \times \phi ~d\Omega, 24 | \quad 25 | l(\phi) := \int_{\Omega} \mathbf{f} \cdot \boldsymbol{\nabla} \times \phi ~d\Omega. 26 | \end{align*} 27 | $$ 28 | 29 | %As in the previous example, one can use a Picard method, by considering $\xi$ as a \texttt{Field} in Eq. \ref{eq:steady-streamfunction-velocity-vf-a}, which will lead to the Python code described in \ref{code:steady-streamfunction-velocity-picard}. %, or consider $a$ as a \texttt{LinearForm} where $\xi = \psi$ are \texttt{Field} objects, and use the \texttt{NewtonIteration} constructor to get a \texttt{BilinearForm}, as described in the Python code \ref{code:steady-streamfunction-velocity-newton}. 30 | 31 | 32 | ## Linearization of the streamfunction-velocity linear form 33 | 34 | In the sequel, we use SymPDE to linearize the streamfunction-velocity formulation, starting from a \texttt{LinearForm}. 35 | As presented in the previous example, we shall write our weak formulation as a linear form where the velocity $\mathbf{u}$ (\textit{i.e.} \texttt{u}) is considered as a \textit{field}, which is implemented in Python code \ref{code:steady-navier-stokes-nl}. 36 | Using the function \texttt{linearize} allows us to construct the bilinear form associated to the linearization of the given linear form, around the field \texttt{psi}, see Python code \ref{code:steady-streamfunction-velocity-lin}. 37 | To get an \texttt{Equation}, the user can add the left-hand-side for the Navier-Stokes equation to the linear form, the appropriate essential boundary conditions, then use the \texttt{NewtonIteration} as presented in the previous example. 38 | -------------------------------------------------------------------------------- /chapter3/navier-stokes-steady.md: -------------------------------------------------------------------------------- 1 | # the steady-state Navier-Stokes equations for incompressible fluids 2 | 3 | 4 | The steady-state Navier Stokes problem for an incompressible fluid, with homogeneous Dirichlet boundary conditions (``no slip'' condition), is defined as 5 | 6 | $$ 7 | \begin{equation} 8 | \left\{ 9 | \begin{aligned} 10 | \left( \mathbf{u} \cdot \nabla \right) \mathbf{u} + \nabla p - 2 \nabla \cdot \left( \frac{1}{R_e} D\left( \mathbf{u} \right) \right) &= \mathbf{f} && \text{in $\Omega$}, 11 | \\ 12 | \nabla \cdot \mathbf{u} &= 0 && \text{in $\Omega$}, 13 | \\ 14 | \mathbf{u} &= 0 && \text{on $\partial\Omega$}, 15 | \end{aligned} 16 | \right. 17 | \end{equation} 18 | $$ 19 | 20 | where $R_e$ is the Reynolds number and $D\left( \mathbf{u} \right) := \frac{1}{2}\left( \nabla \mathbf{u} + \nabla \mathbf{u}^T \right)$ is the strain rate tensor. 21 | The weak formulation reads 22 | 23 | $$ 24 | \begin{align} 25 | \text{find $\mathbf{u} \in W$ such that} \quad 26 | a(\mathbf{u},\mathbf{v}) + b(\mathbf{u},\mathbf{v};\mathbf{u}) = l(\mathbf{v}) \quad 27 | \forall \mathbf{v} \in W 28 | \end{align} 29 | $$ 30 | 31 | where $W \subset \{ \mathbf{v} \in \mathbf{H}_0^1(\Omega): \nabla \cdot \mathbf{v} = 0 \}$ and 32 | 33 | $$ 34 | \begin{align*} 35 | a(\mathbf{u}, \mathbf{v}) := \frac{2}{R_e} \int_{\Omega} D\left( \mathbf{u} \right) : D\left(\mathbf{v} \right) ~d\Omega, 36 | \quad 37 | b(\mathbf{u}, \mathbf{v}; \mathbf{w}) := \int_{\Omega} \left( \left( \mathbf{w} \cdot \nabla \right) \mathbf{u} \right) \cdot \mathbf{v} ~d\Omega, 38 | \quad 39 | l(\mathbf{v}) := \int_{\Omega} \mathbf{f} \cdot \mathbf{v} ~d\Omega. 40 | \end{align*} 41 | $$ 42 | 43 | -------------------------------------------------------------------------------- /chapter3/poisson.md: -------------------------------------------------------------------------------- 1 | # Nonlinear Poisson in 2D 2 | 3 | 4 | In this section, we consider the non-linear Poisson problem: 5 | 6 | $$ 7 | \begin{align} 8 | -\nabla \cdot \left( (1+u^2) \nabla u \right) &= f, \Omega 9 | \\ 10 | u &= 0, \partial \Omega 11 | \end{align} 12 | $$ 13 | 14 | where $\Omega$ denotes the unit square. 15 | 16 | For testing, we shall take a function $u$ that fulfills the boundary condition, the compute $f$ as 17 | 18 | $$ 19 | f(x,y) = -\nabla^2 u - F(u) 20 | $$ 21 | 22 | The weak formulation is 23 | 24 | $$ 25 | \int_{\Omega} (1+u^2) \nabla u \cdot \nabla v ~ d\Omega = \int_{\Omega} f v ~d\Omega, \quad \forall v \in \mathcal{V} 26 | $$ 27 | 28 | For the sack of generality, we shall consider the linear form 29 | 30 | $$ 31 | G(v;u,w) := \int_{\Omega} (1+w^2) \nabla u \cdot \nabla v ~ d\Omega, \quad \forall u,v,w \in \mathcal{V} 32 | $$ 33 | 34 | Our problem is then 35 | 36 | $$ 37 | \begin{align} 38 | \mbox{Find } u \in \mathcal{V}, \mbox{such that}\\ 39 | G(v;u,u) = l(v), \quad \forall v \in \mathcal{V} 40 | \end{align} 41 | $$ 42 | 43 | where 44 | 45 | $$ 46 | l(v) := \int_{\Omega} f v ~d\Omega, \quad \forall v \in \mathcal{V} 47 | $$ 48 | 49 | As usual, we'll follow the classical steps, 50 | 51 | 1. Create a domain 52 | 2. Create the Function space 53 | 3. Define the different linear/bilinear forms 54 | 4. Define the Picard/Newton iteration 55 | 56 | ## 1. The topological domain 57 | ```python 58 | domain = Square() 59 | B_dirichlet_0 = domain.boundary 60 | ``` 61 | ## 2. Function space 62 | ```python 63 | V = ScalarFunctionSpace('V', domain) 64 | ``` 65 | ## 3.1. Define the Linear form $G$ 66 | ```python 67 | u = element_of(V, name='u') 68 | v = element_of(V, name='v') 69 | w = element_of(V, name='w') 70 | 71 | # Linear form g: V --> R 72 | g = LinearForm(v, integral(domain, (1+w**2)*dot(grad(u), grad(v)))) 73 | ``` 74 | ## 3.2. Define the linear form $L$ 75 | ```python 76 | solution = sin(pi*x)*sin(pi*y) 77 | f = 2*pi**2*(sin(pi*x)**2*sin(pi*y)**2 + 1)*sin(pi*x)*sin(pi*y) - 2*pi**2*sin(pi*x)**3*sin(pi*y)*cos(pi*y)**2 - 2*pi**2*sin(pi*x)*sin(pi*y)**3*cos(pi*x)**2 78 | 79 | # Linear form l: V --> R 80 | l = LinearForm(v, integral(domain, f * v)) 81 | ``` 82 | ## 4.1. Picard iteration 83 | 84 | $$ 85 | \begin{align} 86 | \mbox{Find } u_{n+1} \in \mathcal{V}\_h, \mbox{such that}\\ 87 | G(v;u_{n+1},u_n) = l(v), \quad \forall v \in \mathcal{V}\_h 88 | \end{align} 89 | $$ 90 | 91 | The Picard iteration for our problem can be created this way 92 | 93 | ```python 94 | un = element_of(V, name='un') 95 | 96 | # Bilinear form a: V x V --> R 97 | a = BilinearForm((u, v), g(v, u=u,w=un)) 98 | 99 | # Dirichlet boundary conditions 100 | bc = [EssentialBC(u, 0, B_dirichlet_0)] 101 | 102 | # Variational problem 103 | equation = find(u, forall=v, lhs=a(u, v), rhs=l(v), bc=bc) 104 | 105 | # Error norms 106 | error = u - solution 107 | l2norm = Norm(error, domain, kind='l2') 108 | ``` 109 | ## 4.2. Newton iteration 110 | Let's define 111 | 112 | $$ 113 | F(v;u) := G(v;u,u) -l(v), \quad \forall v \in \mathcal{V} 114 | $$ 115 | 116 | Newton method writes 117 | 118 | $$ 119 | \begin{align} 120 | \mbox{Find } u_{n+1} \in \mathcal{V}\_h, \mbox{such that} \\ 121 | F^{\prime}(\delta u,v; u_n) = - F(v;u_n), \quad \forall v \in \mathcal{V}, \\ 122 | u_{n+1} := u_{n} + \delta u, \quad \delta u \in \mathcal{V} 123 | \end{align} 124 | $$ 125 | 126 | ### Computing $F^{\prime}$ the derivative of $F$ 127 | 128 | **SymPDE** allows you to linearize a linear form and get a bilinear form, using the function **linearize** 129 | 130 | ```python 131 | F = LinearForm(v, g(v,w=u)-l(v)) 132 | du = element_of(V, name='du') 133 | 134 | Fprime = linearize(F, u, trials=du) 135 | ``` 136 | 137 | The Newton iteration is then defined as follows, 138 | 139 | ```python 140 | # Dirichlet boundary conditions 141 | bc = [EssentialBC(du, 0, B_dirichlet_0)] 142 | 143 | # Variational problem 144 | equation = find(du, forall=v, lhs=Fprime(du, v,u=un), rhs=-F(v,u=un), bc=bc) 145 | ``` 146 | 147 | -------------------------------------------------------------------------------- /chapter4/poisson-multi-subdomains-nitsche.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "cd976573", 6 | "metadata": {}, 7 | "source": [ 8 | "# The Poisson problem using Nitsche method on multiple subdomains\n", 9 | "\n", 10 | "We consider a 2D domain $\\Omega$, that is subdivided into a grid of small squares, using the **meshgrid** function.\n", 11 | "Each subdomain has the form $(x_{i}, x_{i+1}) \\times (y_{j}, y_{j+1})$, where $x_1, ..., x_{n_x}$ and $y_1, ..., y_{n_y}$ are subdivisions in each axis.\n" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "5b1e68da", 17 | "metadata": {}, 18 | "source": [ 19 | "## Formal Model" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "id": "2ae922ff", 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "from sympde.expr import BilinearForm, LinearForm, integral, Norm\n", 30 | "from sympde.expr import find, EssentialBC\n", 31 | "from sympde.topology import ScalarFunctionSpace, Square, Domain, element_of\n", 32 | "from sympde.calculus import grad, dot\n", 33 | "from sympde.calculus import jump, avg, minus, plus, Dn\n", 34 | "from sympde.core import Constant\n", 35 | "from sympde.topology import meshgrid\n", 36 | "\n", 37 | "from sympy import pi, sin\n", 38 | "\n", 39 | "from psydac.api.discretization import discretize\n", 40 | "\n", 41 | "# ... create a domain as meshgrid of a square\n", 42 | "import numpy as np\n", 43 | "\n", 44 | "x1 = np.linspace(0., 1., 3)\n", 45 | "x2 = np.linspace(0., 1., 4)\n", 46 | "\n", 47 | "domain = meshgrid(x1, x2)\n", 48 | "# ...\n", 49 | "\n", 50 | "# one sided approximation of the normal flux on the interface\n", 51 | "Dn_I = lambda u: 0.5*(plus(Dn(u)) + minus(Dn(u)))\n", 52 | "\n", 53 | "# internal interafaces of the domain\n", 54 | "I = domain.interfaces\n", 55 | "\n", 56 | "kappa = Constant('kappa', is_real=True)\n", 57 | "\n", 58 | "V = ScalarFunctionSpace('V', domain)\n", 59 | "\n", 60 | "x,y = domain.coordinates\n", 61 | "\n", 62 | "u,v = [element_of(V, name=i) for i in ['u', 'v']]\n", 63 | "\n", 64 | "# bilinear form\n", 65 | "a = BilinearForm((u,v),\n", 66 | " integral(domain, dot(grad(u),grad(v))) \n", 67 | " + integral(I, kappa * jump(u)*jump(v) - Dn_I(u)*jump(v) - jump(u)*Dn_I(v))\n", 68 | " )\n", 69 | "\n", 70 | "# linear form\n", 71 | "f = 2*pi**2*sin(pi*x)*sin(pi*y)\n", 72 | "l = LinearForm(v, integral(domain, f*v))\n", 73 | "\n", 74 | "# Dirichlet boundary conditions\n", 75 | "bc = [EssentialBC(u, 0, domain.boundary)]\n", 76 | "\n", 77 | "# Variational problem\n", 78 | "equation = find(u, forall=v, lhs=a(u, v), rhs=l(v), bc=bc)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "id": "48bafde7", 84 | "metadata": {}, 85 | "source": [ 86 | "## Discretization" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "id": "dba29398", 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "degree = [2,2]\n", 97 | "ncells = [8,8]" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "id": "4c341883", 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "# Create computational domain from topological domain\n", 108 | "domain_h = discretize(domain, ncells=ncells, comm=None)\n", 109 | "\n", 110 | "# Create discrete spline space\n", 111 | "Vh = discretize(V, domain_h, degree=degree)\n", 112 | "\n", 113 | "# Discretize equation\n", 114 | "equation_h = discretize(equation, domain_h, [Vh, Vh])" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "id": "75f6b2cf", 120 | "metadata": {}, 121 | "source": [ 122 | "## Solving the PDE" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "id": "b6ad348a", 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "equation_h.set_solver('gmres', info=False, tol=1e-8)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "id": "11c1b23b", 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "uh = equation_h.solve(kappa=1e3)" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "id": "3d67feb3", 148 | "metadata": {}, 149 | "source": [ 150 | "## Computing the Error Norm" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "id": "50b4bf80", 156 | "metadata": {}, 157 | "source": [ 158 | "### Computing the $L^2$ norm" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "id": "e295fb37", 165 | "metadata": {}, 166 | "outputs": [], 167 | "source": [ 168 | "ue = sin(pi*x)*sin(pi*y)\n", 169 | "\n", 170 | "u = element_of(V, name='u')\n", 171 | "\n", 172 | "# create the formal Norm object\n", 173 | "l2norm = Norm(u - ue, domain, kind='l2')\n", 174 | "\n", 175 | "# discretize the norm\n", 176 | "l2norm_h = discretize(l2norm, domain_h, Vh)\n", 177 | "\n", 178 | "# assemble the norm\n", 179 | "l2_error = l2norm_h.assemble(u=uh)\n", 180 | "\n", 181 | "# print the result\n", 182 | "print(l2_error)" 183 | ] 184 | } 185 | ], 186 | "metadata": {}, 187 | "nbformat": 4, 188 | "nbformat_minor": 5 189 | } 190 | -------------------------------------------------------------------------------- /chapter4/subdomains.md: -------------------------------------------------------------------------------- 1 | # Subdomains 2 | 3 | 4 | In this section, we consider a domain $\Omega$ which a union of multiple subdomain, *i.e.* 5 | 6 | $$ 7 | \Omega := \bigcup_{i=1}^n \Omega_i, \quad \Omega_i \bigcap \Omega_j = \emptyset, ~ i \neq j 8 | $$ 9 | 10 | We shall denote by $\mathcal{I}$ the set of all internal interfaces of $\Omega$. 11 | 12 | We shall also need the following operators 13 | 14 | - The jump of the function $u$, defined as $[\![ u ]\!] := u|\_{\Omega_{i_1}} - u|\_{\Omega_{i_2}}$ for two adjacent subdomains $\Omega_{i_1}$ and $\Omega_{i_2}$ 15 | - The average of the function $u$, defined as $\{u\} := \frac{1}{2} \left( u|\_{\Omega_{i_1}} + u|\_{\Omega_{i_2}} \right)$ for two adjacent subdomains $\Omega_{i_1}$ and $\Omega_{i_2}$ 16 | 17 | In general, these operators are defined based on the considered variational formulation. We shall see in the following examples how to define them. 18 | -------------------------------------------------------------------------------- /chapter5/cfd.md: -------------------------------------------------------------------------------- 1 | # Computational Fluid Dynamics 2 | -------------------------------------------------------------------------------- /chapter5/cfd/bingham_plastic_flow_in_a_pipe.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1f0b7959", 6 | "metadata": {}, 7 | "source": [ 8 | "# Bingham Plastic Flow in a Pipe\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the Bingham plastic model for non-Newtonian fluids with yield stress:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\frac{\\partial u}{\\partial t} + u\\frac{\\partial u}{\\partial x} &= -\\frac{1}{\\rho}\\frac{\\partial p}{\\partial x} + \\frac{\\tau_0}{\\rho}\\frac{\\partial^2 u}{\\partial y^2} \\\\\n", 17 | "\\frac{\\partial^2 u}{\\partial y^2} &\\geq 0 \\quad \\text{(Yield stress condition)}\n", 18 | "\\end{align}\n", 19 | "$$\n", 20 | "\n", 21 | "where $u$ is the velocity, $p$ is the pressure, $\\rho$ is the density, $\\tau_0$ is the yield stress, and $y$ is the radial coordinate.\n", 22 | "\n", 23 | "### Boundary Conditions\n", 24 | "\n", 25 | "- Inlet: Specify velocity or pressure conditions.\n", 26 | "- Outlet: Specify outflow conditions.\n", 27 | "- Pipe walls: No-slip conditions.\n", 28 | "\n", 29 | "### Initial Conditions\n", 30 | "\n", 31 | "Specify initial conditions for velocity and pressure.\n", 32 | "\n", 33 | "## Weak Formulation\n", 34 | "\n", 35 | "Find $u \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 36 | "\n", 37 | "$$\n", 38 | "\\begin{align}\n", 39 | "&\\int_{\\Omega} \\frac{\\partial u}{\\partial t}v \\, d\\Omega + \\int_{\\Omega} u\\frac{\\partial u}{\\partial x}v \\, d\\Omega + \\int_{\\Omega} \\frac{1}{\\rho}\\frac{\\partial p}{\\partial x}v \\, d\\Omega \\\\\n", 40 | "&+ \\int_{\\Omega} \\frac{\\tau_0}{\\rho}\\frac{\\partial^2 u}{\\partial y^2}\\frac{\\partial v}{\\partial y} \\, d\\Omega \\\\\n", 41 | "&= 0\n", 42 | "\\end{align}\n", 43 | "$$\n", 44 | "\n", 45 | "for all test functions $v \\in H_0^1(\\Omega)$." 46 | ] 47 | } 48 | ], 49 | "metadata": {}, 50 | "nbformat": 4, 51 | "nbformat_minor": 5 52 | } 53 | -------------------------------------------------------------------------------- /chapter5/cfd/buoyancy-driven_natural_convection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "315d2f4f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Buoyancy-Driven Natural Convection\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the Boussinesq approximation for buoyancy-driven natural convection:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\frac{\\partial \\mathbf{v}}{\\partial t} + (\\mathbf{v} \\cdot \\nabla)\\mathbf{v} &= -\\frac{1}{\\rho_0}\\nabla p + \\nu \\nabla^2 \\mathbf{v} + \\beta g (T - T_0)\\mathbf{k} \\\\\n", 17 | "\\frac{\\partial T}{\\partial t} + \\mathbf{v} \\cdot \\nabla T &= \\alpha \\nabla^2 T\n", 18 | "\\end{align}\n", 19 | "$$\n", 20 | "\n", 21 | "### Boundary Conditions\n", 22 | "\n", 23 | "- Vertical walls: $\\mathbf{v} \\cdot \\mathbf{t} = 0$ and $\\frac{\\partial T}{\\partial n} = 0$.\n", 24 | "\n", 25 | "- Inlet and outlet: Specify velocity or temperature conditions.\n", 26 | "\n", 27 | "- Top and bottom: No-slip and adiabatic conditions.\n", 28 | "\n", 29 | "### Initial Conditions\n", 30 | "\n", 31 | "Start with an initial velocity and temperature distribution.\n", 32 | "\n", 33 | "## Weak Formulation\n", 34 | "\n", 35 | "Find $\\mathbf{v} \\in H_0^1(\\Omega)$ and $T \\in H^1(\\Omega)$ such that:\n", 36 | "\n", 37 | "$$\n", 38 | "\\begin{align}\n", 39 | "&\\int_{\\Omega} \\left(\\frac{\\partial \\mathbf{v}}{\\partial t} + (\\mathbf{v} \\cdot \\nabla)\\mathbf{v}\\right) \\cdot \\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\frac{1}{\\rho_0}\\nabla p \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 40 | "&+ \\int_{\\Omega} \\nu \\nabla \\mathbf{v} : \\nabla \\mathbf{w} \\, d\\Omega - \\beta g (T - T_0)\\mathbf{k} \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 41 | "&+ \\int_{\\Omega} \\left(\\frac{\\partial T}{\\partial t} + \\mathbf{v} \\cdot \\nabla T - \\alpha \\nabla^2 T\\right) \\psi \\, d\\Omega \\\\\n", 42 | "&= 0\n", 43 | "\\end{align}\n", 44 | "$$\n", 45 | "\n", 46 | "for all test functions $\\mathbf{w}, \\psi \\in H_0^1(\\Omega)$.\n", 47 | "\n", 48 | "\n" 49 | ] 50 | } 51 | ], 52 | "metadata": {}, 53 | "nbformat": 4, 54 | "nbformat_minor": 5 55 | } 56 | -------------------------------------------------------------------------------- /chapter5/cfd/casson_fluid_flow_in_a_channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e9f1cb0e", 6 | "metadata": {}, 7 | "source": [ 8 | "# Casson Fluid Flow in a Channel\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the Casson model for non-Newtonian fluids:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\sigma_{ij} &= -p\\delta_{ij} + \\sqrt{\\frac{\\tau_0}{\\rho}}\\sqrt{\\frac{\\tau_0}{\\rho} + \\frac{1}{2}\\rho\\left(\\frac{\\partial u_i}{\\partial x_j} + \\frac{\\partial u_j}{\\partial x_i}\\right)^2} \\\\\n", 17 | "\\end{align}\n", 18 | "$$\n", 19 | "\n", 20 | "where $\\sigma_{ij}$ is the stress tensor, $p$ is the pressure, $\\rho$ is the density, $u_i$ is the velocity, and $\\tau_0$ is the yield stress.\n", 21 | "\n", 22 | "### Boundary Conditions\n", 23 | "\n", 24 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 25 | "- Channel walls: No-slip conditions.\n", 26 | "\n", 27 | "### Initial Conditions\n", 28 | "Start with an initial guess for velocity and pressure.\n", 29 | "\n", 30 | "## Weak Formulation\n", 31 | "\n", 32 | "Find $u_i \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 33 | "\n", 34 | "$$\n", 35 | "\\begin{align}\n", 36 | "&\\int_{\\Omega} \\sigma_{ij} \\left(\\frac{\\partial u_i}{\\partial x_j} + \\frac{\\partial u_j}{\\partial x_i}\\right) \\, d\\Omega + \\int_{\\Omega} \\frac{\\partial p}{\\partial x_i}u_i \\, d\\Omega \\\\\n", 37 | "&= 0\n", 38 | "\\end{align}\n", 39 | "$$\n", 40 | "\n", 41 | "for all test functions $u_i \\in H_0^1(\\Omega)$." 42 | ] 43 | } 44 | ], 45 | "metadata": {}, 46 | "nbformat": 4, 47 | "nbformat_minor": 5 48 | } 49 | -------------------------------------------------------------------------------- /chapter5/cfd/compressible_flow_in_a_nozzle.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "896cf22a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Compressible Flow in a Nozzle\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the compressible Euler equations for flow in a converging-diverging nozzle:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v}) &= 0 \\\\\n", 17 | "\\frac{\\partial (\\rho \\mathbf{v})}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v} \\otimes \\mathbf{v} + p\\mathbf{I}) &= 0 \\\\\n", 18 | "\\frac{\\partial E}{\\partial t} + \\nabla \\cdot \\left[(E + p) \\mathbf{v}\\right] &= 0\n", 19 | "\\end{align}\n", 20 | "$$\n", 21 | "\n", 22 | "### Boundary Conditions\n", 23 | "\n", 24 | "- Inlet: Specify inflow conditions ($\\rho$, $\\mathbf{v}$, $p$).\n", 25 | "\n", 26 | "- Outlet: Specify outflow conditions or use characteristic-based boundary conditions.\n", 27 | "\n", 28 | "- Nozzle walls: $\\mathbf{v} \\cdot \\mathbf{n} = 0$ (no penetration).\n", 29 | "\n", 30 | "### Initial Conditions\n", 31 | "\n", 32 | "Specify initial conditions for density, velocity, and pressure.\n", 33 | "\n", 34 | "## Weak Formulation\n", 35 | "\n", 36 | "Find $\\rho, \\mathbf{v}, p \\in H^1(\\Omega)$ such that:\n", 37 | "\n", 38 | "$$\n", 39 | "\\begin{align}\n", 40 | "&\\int_{\\Omega} \\left(\\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v})\\right) \\phi \\, d\\Omega \\\\\n", 41 | "&+ \\int_{\\Omega} \\left(\\frac{\\partial (\\rho \\mathbf{v})}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v} \\otimes \\mathbf{v} + p\\mathbf{I})\\right) \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 42 | "&+ \\int_{\\Omega} \\left(\\frac{\\partial E}{\\partial t} + \\nabla \\cdot \\left[(E + p) \\mathbf{v}\\right]\\right) \\psi \\, d\\Omega \\\\\n", 43 | "&= 0\n", 44 | "\\end{align}\n", 45 | "$$\n", 46 | "\n", 47 | "for all test functions $\\phi, \\mathbf{w}, \\psi \\in H^1(\\Omega)$." 48 | ] 49 | } 50 | ], 51 | "metadata": {}, 52 | "nbformat": 4, 53 | "nbformat_minor": 5 54 | } 55 | -------------------------------------------------------------------------------- /chapter5/cfd/convection-diffusion_equation_in_a_channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "6889a63e", 6 | "metadata": {}, 7 | "source": [ 8 | "# Convection-Diffusion Equation in a Channel\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the 2D convection-diffusion equation in a channel:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\rho u \\frac{\\partial c}{\\partial x} + \\rho v \\frac{\\partial c}{\\partial y} - \\nabla \\cdot (D \\nabla c) = f\n", 17 | "\\end{align}\n", 18 | "$$\n", 19 | "\n", 20 | "### Boundary Conditions\n", 21 | "\n", 22 | "- Inlet: $c = c_{\\text{inlet}}$ with \\$\\mathbf{v} \\cdot \\mathbf{n} < 0$ (inward flow).\n", 23 | "\n", 24 | "- Outlet: $\\frac{\\partial c}{\\partial x} = \\frac{\\partial c}{\\partial y} = 0$ (zero gradient).\n", 25 | "\n", 26 | "- Lateral faces: $-D \\nabla c \\cdot \\mathbf{n} = 0$ (insulated).\n", 27 | "\n", 28 | "### Initial Conditions\n", 29 | "\n", 30 | "Assume an initial concentration distribution $c_0(x, y)$ at $t = 0$.\n", 31 | "\n", 32 | "## Weak Formulation\n", 33 | "\n", 34 | "Find $c \\in H_0^1(\\Omega)$ such that:\n", 35 | "\n", 36 | "$$\n", 37 | "\\begin{align}\n", 38 | "&\\int_{\\Omega} \\left(\\rho u \\frac{\\partial c}{\\partial x} + \\rho v \\frac{\\partial c}{\\partial y}\\right) \\phi \\, d\\Omega - \\int_{\\Omega} D \\nabla c \\cdot \\nabla \\phi \\, d\\Omega \\\\\n", 39 | "&= \\int_{\\Omega} f \\phi \\, d\\Omega\n", 40 | "\\end{align}\n", 41 | "$$\n", 42 | "\n", 43 | "for all test functions $\\phi \\in H_0^1(\\Omega)$.\n", 44 | "\n", 45 | "\n" 46 | ] 47 | } 48 | ], 49 | "metadata": {}, 50 | "nbformat": 4, 51 | "nbformat_minor": 5 52 | } 53 | -------------------------------------------------------------------------------- /chapter5/cfd/cross_power_law_fluid_flow_in_a_channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "45606393", 6 | "metadata": {}, 7 | "source": [ 8 | "# Cross Power Law Fluid Flow in a Channel\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the cross power-law model for non-Newtonian fluids:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\sigma_{ij} &= -p\\delta_{ij} + \\lambda \\varepsilon_{kk}\\delta_{ij} + 2\\mu\\left(\\varepsilon_{ij} + \\alpha\\varepsilon_{ij}^2\\right) \\\\\n", 17 | "\\varepsilon_{ij} &= \\frac{1}{2}\\left(\\frac{\\partial v_i}{\\partial x_j} + \\frac{\\partial v_j}{\\partial x_i}\\right) \\\\\n", 18 | "\\end{align}\n", 19 | "$$\n", 20 | "\n", 21 | "where $\\sigma_{ij}$ is the stress tensor, $p$ is the pressure, $\\lambda$ and $\\mu$ are material constants, $v_i$ is the velocity, $\\varepsilon_{ij}$ is the strain rate, and $\\alpha$ is a power-law index.\n", 22 | "\n", 23 | "### Boundary Conditions\n", 24 | "\n", 25 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 26 | "\n", 27 | "- Channel walls: No-slip conditions.\n", 28 | "\n", 29 | "### Initial Conditions\n", 30 | "\n", 31 | "Start with an initial guess for velocity and pressure.\n", 32 | "\n", 33 | "## Weak Formulation\n", 34 | "\n", 35 | "Find $v_i \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 36 | "\n", 37 | "$$\n", 38 | "\\begin{align}\n", 39 | "&\\int_{\\Omega} \\sigma_{ij} \\varepsilon_{ij} \\, d\\Omega + \\int_{\\Omega} \\frac{\\partial p}{\\partial x_i}v_i \\, d\\Omega \\\\\n", 40 | "&= 0\n", 41 | "\\end{align}\n", 42 | "$$\n", 43 | "\n", 44 | "for all test functions $v_i \\in H_0^1(\\Omega)$." 45 | ] 46 | } 47 | ], 48 | "metadata": {}, 49 | "nbformat": 4, 50 | "nbformat_minor": 5 51 | } 52 | -------------------------------------------------------------------------------- /chapter5/cfd/free_surface_flow.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "fea980ee", 6 | "metadata": {}, 7 | "source": [ 8 | "# Free Surface Flow (Navier-Stokes with Free Surface)\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the Navier-Stokes equations coupled with a level set or volume-of-fluid method for tracking a free surface:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\rho \\frac{\\partial \\mathbf{v}}{\\partial t} + \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} &= -\\nabla p + \\mu \\nabla^2 \\mathbf{v} + \\rho \\mathbf{g} \\\\\n", 17 | "\\nabla \\cdot \\mathbf{v} &= 0 \\\\\n", 18 | "\\frac{\\partial \\phi}{\\partial t} + \\mathbf{v} \\cdot \\nabla \\phi &= 0\n", 19 | "\\end{align}\n", 20 | "$$\n", 21 | "\n", 22 | "where $\\phi$ is the level set or volume fraction representing the free surface.\n", 23 | "\n", 24 | "### Boundary Conditions\n", 25 | "\n", 26 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 27 | "- No-slip conditions on solid boundaries.\n", 28 | "- Implement the level set or volume fraction boundary conditions.\n", 29 | "\n", 30 | "### Initial Conditions\n", 31 | "\n", 32 | "Specify initial conditions for velocity, pressure, and the level set or volume fraction.\n", 33 | "\n", 34 | "## Weak Formulation\n", 35 | "\n", 36 | "Find $\\mathbf{v} \\in H_0^1(\\Omega)$, $p \\in L^2(\\Omega)$, and $\\phi \\in H^1(\\Omega)$ such that:\n", 37 | "\n", 38 | "$$\n", 39 | "\\begin{align}\n", 40 | "&\\int_{\\Omega} \\rho \\frac{\\partial \\mathbf{v}}{\\partial t} \\cdot \\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 41 | "&+ \\int_{\\Omega} \\mu \\nabla \\mathbf{v} : \\nabla \\mathbf{w} \\, d\\Omega - \\int_{\\Omega} p \\nabla \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 42 | "&+ \\int_{\\Omega} \\nabla \\cdot \\mathbf{v} q \\, d\\Omega + \\int_{\\Omega} \\frac{\\partial \\phi}{\\partial t} q \\, d\\Omega + \\int_{\\Omega} \\mathbf{v} \\cdot \\nabla \\phi q \\, d\\Omega \\\\\n", 43 | "&= 0\n", 44 | "\\end{align}\n", 45 | "$$\n", 46 | "\n", 47 | "for all test functions $\\mathbf{w} \\in H_0^1(\\Omega)$, $q \\in L^2(\\Omega)$, and $r \\in H^1(\\Omega)$." 48 | ] 49 | } 50 | ], 51 | "metadata": {}, 52 | "nbformat": 4, 53 | "nbformat_minor": 5 54 | } 55 | -------------------------------------------------------------------------------- /chapter5/cfd/heat_conduction_in_a_solid.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b3466488", 6 | "metadata": {}, 7 | "source": [ 8 | "# Heat Conduction in a Solid\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the heat conduction equation in a solid domain \\(\\Omega\\):\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\rho C_p \\frac{\\partial T}{\\partial t} - \\nabla \\cdot (k \\nabla T) = Q\n", 17 | "\\end{align}\n", 18 | "$$\n", 19 | "\n", 20 | "### Boundary Conditions\n", 21 | "\n", 22 | "- Dirichlet: $T = T_{\\text{inlet}}$ on the inlet face.\n", 23 | "- Neumann: $-k \\frac{\\partial T}{\\partial n} = 0$ on the outlet face.\n", 24 | "- Insulated: $-k \\frac{\\partial T}{\\partial n} = 0$ on the lateral faces.\n", 25 | "\n", 26 | "### Initial Conditions\n", 27 | "\n", 28 | "Assume an initial temperature distribution $T_0(x, y, z)$ at $t = 0$.\n", 29 | "\n", 30 | "## Weak Formulation\n", 31 | "\n", 32 | "Find $T \\in L^2(\\Omega)$ such that:\n", 33 | "\n", 34 | "$$\n", 35 | "\\begin{align}\n", 36 | "\\int_{\\Omega} \\rho C_p \\frac{\\partial T}{\\partial t} \\phi \\, d\\Omega + \\int_{\\Omega} k \\nabla T \\cdot \\nabla \\phi \\, d\\Omega = \\int_{\\Omega} Q \\phi \\, d\\Omega\n", 37 | "\\end{align}\n", 38 | "$$\n", 39 | "\n", 40 | "for all test functions $\\phi \\in H_0^1(\\Omega)$.\n", 41 | "\n" 42 | ] 43 | } 44 | ], 45 | "metadata": {}, 46 | "nbformat": 4, 47 | "nbformat_minor": 5 48 | } 49 | -------------------------------------------------------------------------------- /chapter5/cfd/herschel-bulkley_fluid_flow_in_a_pipe.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a0c1f909", 6 | "metadata": {}, 7 | "source": [ 8 | "# Herschel-Bulkley Fluid Flow in a Pipe\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the Herschel-Bulkley model for non-Newtonian fluids with yield stress:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\frac{\\partial u}{\\partial t} + u\\frac{\\partial u}{\\partial x} &= -\\frac{1}{\\rho}\\frac{\\partial p}{\\partial x} + \\frac{\\tau_0}{\\rho}\\left(\\frac{\\partial u}{\\partial x}\\right)^{n-1} \\\\\n", 17 | "\\end{align}\n", 18 | "$$\n", 19 | "\n", 20 | "where $u$ is the velocity, $p$ is the pressure, $\\rho$ is the density, $\\tau_0$ is the yield stress, and $n$ is the flow behavior index.\n", 21 | "\n", 22 | "### Boundary Conditions\n", 23 | "\n", 24 | "- Inlet: Specify velocity or pressure conditions.\n", 25 | "\n", 26 | "- Outlet: Specify outflow conditions.\n", 27 | "\n", 28 | "- Pipe walls: No-slip conditions.\n", 29 | "\n", 30 | "### Initial Conditions\n", 31 | "\n", 32 | "Specify initial conditions for velocity and pressure.\n", 33 | "\n", 34 | "## Weak Formulation\n", 35 | "\n", 36 | "Find $u \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 37 | "\n", 38 | "$$\n", 39 | "\\begin{align}\n", 40 | "&\\int_{\\Omega} \\frac{\\partial u}{\\partial t}v \\, d\\Omega + \\int_{\\Omega} u\\frac{\\partial u}{\\partial x}v \\, d\\Omega + \\int_{\\Omega} \\frac{1}{\\rho}\\frac{\\partial p}{\\partial x}v \\, d\\Omega \\\\\n", 41 | "&+ \\int_{\\Omega} \\frac{\\tau_0}{\\rho}\\left(\\frac{\\partial u}{\\partial x}\\right)^{n-1}v \\, d\\Omega \\\\\n", 42 | "&= 0\n", 43 | "\\end{align}\n", 44 | "$$\n", 45 | "\n", 46 | "for all test functions $v \\in H_0^1(\\Omega)$." 47 | ] 48 | } 49 | ], 50 | "metadata": {}, 51 | "nbformat": 4, 52 | "nbformat_minor": 5 53 | } 54 | -------------------------------------------------------------------------------- /chapter5/cfd/incompressible_flow_past_a_cylinder.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "0b948ce3", 6 | "metadata": {}, 7 | "source": [ 8 | "# Incompressible Flow Past a Cylinder\n", 9 | "\n", 10 | "## Mathematical Model:\n", 11 | "\n", 12 | "Consider the steady, incompressible Navier-Stokes equations for fluid flow around a cylinder:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} &= -\\nabla p + \\mu \\nabla^2 \\mathbf{v} + \\rho \\mathbf{g} \\\\\n", 17 | "\\nabla \\cdot \\mathbf{v} &= 0\n", 18 | "\\end{align}\n", 19 | "$$\n", 20 | "\n", 21 | "### Boundary Conditions\n", 22 | "\n", 23 | "- Inlet: $\\mathbf{v} = (U, 0)$ (uniform velocity).\n", 24 | "- Outlet: $\\frac{\\partial \\mathbf{v}}{\\partial x} = 0$ (zero gradient).\n", 25 | "- Cylinder surface: $\\mathbf{v} \\cdot \\mathbf{n} = 0$ (no-slip condition).\n", 26 | "\n", 27 | "### Initial Conditions\n", 28 | "\n", 29 | "Assume a quiescent fluid, i.e., $\\mathbf{v} = (0, 0)$ at $t = 0$.\n", 30 | "\n", 31 | "### Weak Formulation\n", 32 | "\n", 33 | "Find $\\mathbf{v} \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 34 | "\n", 35 | "$$\n", 36 | "\\begin{align}\n", 37 | "\\int_{\\Omega} \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} \\cdot \\mathbf{w} \\, d\\Omega & = -\\int_{\\Omega} p \\nabla \\cdot \\mathbf{w} \\, d\\Omega + \\mu \\int_{\\Omega} \\nabla \\mathbf{v} : \\nabla \\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\rho \\mathbf{g} \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 38 | "\\int_{\\Omega} \\nabla \\cdot \\mathbf{v} q \\, d\\Omega & = 0\n", 39 | "\\end{align}\n", 40 | "$$\n", 41 | "\n", 42 | "where $\\mathbf{w} \\in H_0^1(\\Omega)$ and $q \\in L^2(\\Omega)$." 43 | ] 44 | } 45 | ], 46 | "metadata": {}, 47 | "nbformat": 4, 48 | "nbformat_minor": 5 49 | } 50 | -------------------------------------------------------------------------------- /chapter5/cfd/magnetohydrodynamics_flow.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "6c15c8b4", 6 | "metadata": {}, 7 | "source": [ 8 | "# Magnetohydrodynamics (MHD) Flow\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the MHD equations coupling the Navier-Stokes equations with Maxwell's equations:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\rho \\frac{\\partial \\mathbf{v}}{\\partial t} + \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} &= -\\nabla p + \\mu \\nabla^2 \\mathbf{v} + \\mathbf{J} \\times \\mathbf{B} \\\\\n", 17 | "\\frac{\\partial \\mathbf{B}}{\\partial t} &= \\nabla \\times (\\mathbf{v} \\times \\mathbf{B} - \\eta \\nabla \\times \\mathbf{B}) \\\\\n", 18 | "\\nabla \\cdot \\mathbf{v} &= 0 \\\\\n", 19 | "\\nabla \\cdot \\mathbf{B} &= 0\n", 20 | "\\end{align}\n", 21 | "$$\n", 22 | "\n", 23 | "where $\\mathbf{J} = \\nabla \\times \\mathbf{B}$ is the current density.\n", 24 | "\n", 25 | "### Boundary Conditions\n", 26 | "\n", 27 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 28 | "- Magnetic field conditions depending on the problem.\n", 29 | "\n", 30 | "### Initial Conditions\n", 31 | "\n", 32 | "Specify initial conditions for velocity, pressure, and the magnetic field.\n", 33 | "\n", 34 | "## Weak Formulation\n", 35 | "\n", 36 | "Find $\\mathbf{v} \\in H_0^1(\\Omega)$, $p \\in L^2(\\Omega)$, and $\\mathbf{B} \\in H(\\text{curl}; \\Omega)$ such that:\n", 37 | "\n", 38 | "$$\n", 39 | "\\begin{align}\n", 40 | "&\\int_{\\Omega} \\rho \\frac{\\partial \\mathbf{v}}{\\partial t} \\cdot \\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 41 | "&+ \\int_{\\Omega} \\mu \\nabla \\mathbf{v} : \\nabla \\mathbf{w} \\, d\\Omega - \\int_{\\Omega} p \\nabla \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 42 | "&+ \\int_{\\Omega} \\frac{\\partial \\mathbf{B}}{\\partial t} \\cdot \\boldsymbol{\\psi} \\, d\\Omega - \\int_{\\Omega} \\nabla \\times (\\mathbf{v} \\times \\mathbf{B} - \\eta \\nabla \\times \\mathbf{B}) \\cdot \\boldsymbol{\\psi} \\, d\\Omega \\\\\n", 43 | "&+ \\int_{\\Omega} \\nabla \\cdot \\mathbf{v} q \\, d\\Omega + \\int_{\\Omega} \\nabla \\cdot \\mathbf{B} r \\, d\\Omega \\\\\n", 44 | "&= 0\n", 45 | "\\end{align}\n", 46 | "$$\n", 47 | "\n", 48 | "for all test functions $\\mathbf{w} \\in H_0^1(\\Omega)$, $q \\in L^2(\\Omega)$, $\\boldsymbol{\\psi} \\in H(\\text{curl}; \\Omega)$, and $r \\in L^2(\\Omega)$." 49 | ] 50 | } 51 | ], 52 | "metadata": {}, 53 | "nbformat": 4, 54 | "nbformat_minor": 5 55 | } 56 | -------------------------------------------------------------------------------- /chapter5/cfd/non-newtonian-fluids.md: -------------------------------------------------------------------------------- 1 | # Non-Newtonian Fluids 2 | -------------------------------------------------------------------------------- /chapter5/cfd/oldroyd-b_fluid_flow_in_a_channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "aea3782b", 6 | "metadata": {}, 7 | "source": [ 8 | "# Oldroyd-B Fluid Flow in a Channel\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the Oldroyd-B model for viscoelastic fluids:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\frac{\\partial \\mathbf{u}}{\\partial t} + \\mathbf{u}\\cdot\\nabla\\mathbf{u} &= -\\frac{1}{\\rho}\\nabla p + \\nabla\\cdot\\boldsymbol{\\tau} \\\\\n", 17 | "\\frac{\\partial \\boldsymbol{\\tau}}{\\partial t} + \\mathbf{u}\\cdot\\nabla\\boldsymbol{\\tau} &= \\boldsymbol{\\tau}\\cdot\\nabla\\mathbf{u} - \\frac{\\boldsymbol{\\tau}}{\\lambda} + 2\\mu\\left(\\nabla\\mathbf{u} - \\frac{\\boldsymbol{\\tau}}{\\lambda}\\right) \\\\\n", 18 | "\\end{align}\n", 19 | "$$\n", 20 | "\n", 21 | "where $\\mathbf{u}$ is the velocity, $p$ is the pressure, $\\rho$ is the density, $\\boldsymbol{\\tau}$ is the extra stress tensor, $\\lambda$ is the relaxation time, and $\\mu$ is the viscosity.\n", 22 | "\n", 23 | "### Boundary Conditions\n", 24 | "\n", 25 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 26 | "- Channel walls: No-slip conditions.\n", 27 | "\n", 28 | "### Initial Conditions\n", 29 | "\n", 30 | "Specify initial conditions for velocity and pressure.\n", 31 | "\n", 32 | "## Weak Formulation\n", 33 | "\n", 34 | "Find $\\mathbf{u} \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 35 | "\n", 36 | "$$\n", 37 | "\\begin{align}\n", 38 | "&\\int_{\\Omega} \\frac{\\partial \\mathbf{u}}{\\partial t}\\cdot\\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\mathbf{u}\\cdot\\nabla\\mathbf{u}\\cdot\\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\frac{1}{\\rho}\\nabla p\\cdot\\mathbf{w} \\, d\\Omega \\\\\n", 39 | "&+ \\int_{\\Omega} \\frac{\\partial \\boldsymbol{\\tau}}{\\partial t}:\\mathbf{v} \\, d\\Omega + \\int_{\\Omega} \\mathbf{u}\\cdot\\nabla\\boldsymbol{\\tau}:\\mathbf{v} \\, d\\Omega \\\\\n", 40 | "&- \\int_{\\Omega} \\boldsymbol{\\tau}\\cdot\\nabla\\mathbf{u}:\\mathbf{v} \\, d\\Omega + \\int_{\\Omega} \\frac{\\boldsymbol{\\tau}}{\\lambda}:\\mathbf{v} \\, d\\Omega \\\\\n", 41 | "&+ \\int_{\\Omega} 2\\mu\\left(\\nabla\\mathbf{u} - \\frac{\\boldsymbol{\\tau}}{\\lambda}\\right):\\nabla\\mathbf{w} \\, d\\Omega \\\\\n", 42 | "&= 0\n", 43 | "\\end{align}\n", 44 | "$$\n", 45 | "\n", 46 | "for all test functions $\\mathbf{w} \\in H_0^1(\\Omega)$." 47 | ] 48 | } 49 | ], 50 | "metadata": {}, 51 | "nbformat": 4, 52 | "nbformat_minor": 5 53 | } 54 | -------------------------------------------------------------------------------- /chapter5/cfd/papanastasiou_fluid_flow_in_a_channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "d8b8b5bd", 6 | "metadata": {}, 7 | "source": [ 8 | "# Papanastasiou Fluid Flow in a Channel\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the Papanastasiou model for non-Newtonian fluids:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\sigma_{ij} &= -p\\delta_{ij} + 2\\mu\\left(\\varepsilon_{ij} + \\frac{\\tau_0}{2\\mu}\\right)\\left(\\frac{\\partial u_i}{\\partial x_j} + \\frac{\\partial u_j}{\\partial x_i}\\right) \\\\\n", 17 | "\\varepsilon_{ij} &= \\frac{1}{2}\\left(\\frac{\\partial u_i}{\\partial x_j} + \\frac{\\partial u_j}{\\partial x_i}\\right) \\\\\n", 18 | "\\end{align}\n", 19 | "$$\n", 20 | "\n", 21 | "where $\\sigma_{ij}$ is the stress tensor, $p$ is the pressure, $\\mu$ is the viscosity, $u_i$ is the velocity, $\\varepsilon_{ij}$ is the strain rate, and $\\tau_0$ is the yield stress.\n", 22 | "\n", 23 | "### Boundary Conditions\n", 24 | "\n", 25 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 26 | "- Channel walls: No-slip conditions.\n", 27 | "\n", 28 | "### Initial Conditions\n", 29 | "\n", 30 | "Start with an initial guess for velocity and pressure.\n", 31 | "\n", 32 | "## Weak Formulation\n", 33 | "\n", 34 | "Find $u_i \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 35 | "\n", 36 | "$$\n", 37 | "\\begin{align}\n", 38 | "&\\int_{\\Omega} \\sigma_{ij} \\left(\\frac{\\partial u_i}{\\partial x_j} + \\frac{\\partial u_j}{\\partial x_i}\\right) \\, d\\Omega + \\int_{\\Omega} \\frac{\\partial p}{\\partial x_i}u_i \\, d\\Omega \\\\\n", 39 | "&= 0\n", 40 | "\\end{align}\n", 41 | "$$\n", 42 | "\n", 43 | "for all test functions $u_i \\in H_0^1(\\Omega)$." 44 | ] 45 | } 46 | ], 47 | "metadata": {}, 48 | "nbformat": 4, 49 | "nbformat_minor": 5 50 | } 51 | -------------------------------------------------------------------------------- /chapter5/cfd/particle-laden_flow.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b4a03bc4", 6 | "metadata": {}, 7 | "source": [ 8 | "# Particle-Laden Flow (Lagrangian-Eulerian Approach)\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the incompressible Navier-Stokes equations coupled with the Lagrangian motion of particles:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\rho \\frac{\\partial \\mathbf{v}}{\\partial t} + \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} &= -\\nabla p + \\mu \\nabla^2 \\mathbf{v} + \\mathbf{F}_{\\text{drag}} \\\\\n", 17 | "\\nabla \\cdot \\mathbf{v} &= 0 \\\\\n", 18 | "\\frac{d \\mathbf{x}}{dt} &= \\mathbf{v}\n", 19 | "\\end{align}\n", 20 | "$$\n", 21 | "\n", 22 | "where $\\mathbf{F}_{\\text{drag}}$ represents the drag force on the particles.\n", 23 | "\n", 24 | "### Boundary Conditions\n", 25 | "\n", 26 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 27 | "- Solid particle boundaries: Implement no-slip conditions.\n", 28 | "\n", 29 | "### Initial Conditions\n", 30 | "\n", 31 | "Specify initial conditions for velocity, pressure, and particle positions.\n", 32 | "\n", 33 | "## Weak Formulation\n", 34 | "\n", 35 | "Find $\\mathbf{v} \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 36 | "\n", 37 | "$$\n", 38 | "\\begin{align}\n", 39 | "&\\int_{\\Omega} \\rho \\frac{\\partial \\mathbf{v}}{\\partial t} \\cdot \\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 40 | "&+ \\int_{\\Omega} \\mu \\nabla \\mathbf{v} : \\nabla \\mathbf{w} \\, d\\Omega - \\int_{\\Omega} p \\nabla \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 41 | "&+ \\int_{\\Omega} \\nabla \\cdot \\mathbf{v} q \\, d\\Omega \\\\\n", 42 | "&= -\\int_{\\Omega} \\mathbf{F}_{\\text{drag}} \\cdot \\mathbf{w} \\, d\\Omega\n", 43 | "\\end{align}\n", 44 | "$$\n", 45 | "\n", 46 | "for all test functions $\\mathbf{w} \\in H_0^1(\\Omega)$ and $q \\in L^2(\\Omega)$." 47 | ] 48 | } 49 | ], 50 | "metadata": {}, 51 | "nbformat": 4, 52 | "nbformat_minor": 5 53 | } 54 | -------------------------------------------------------------------------------- /chapter5/cfd/power_law_fluid_flow_in_a_channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "33aa7908", 6 | "metadata": {}, 7 | "source": [ 8 | "# Power Law Fluid Flow in a Channel\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the steady-state power-law fluid model for non-Newtonian fluids:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\sigma_{ij} &= -p\\delta_{ij} + \\lambda \\varepsilon_{kk}\\delta_{ij} + 2\\mu \\varepsilon_{ij} \\\\\n", 17 | "\\varepsilon_{ij} &= \\frac{1}{2}\\left(\\frac{\\partial v_i}{\\partial x_j} + \\frac{\\partial v_j}{\\partial x_i}\\right) \\\\\n", 18 | "\\end{align}\n", 19 | "$$\n", 20 | "\n", 21 | "where $\\sigma_{ij}$ is the stress tensor, $p$ is the pressure, $\\lambda$ and $\\mu$ are material constants, $v_i$ is the velocity, and $\\varepsilon_{ij}$ is the strain rate.\n", 22 | "\n", 23 | "### Boundary Conditions:\n", 24 | "\n", 25 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 26 | "- Channel walls: No-slip conditions.\n", 27 | "\n", 28 | "### Initial Conditions\n", 29 | "\n", 30 | "Start with an initial guess for velocity and pressure.\n", 31 | "\n", 32 | "## Weak Formulation\n", 33 | "\n", 34 | "Find $v_i \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 35 | "\n", 36 | "$$\n", 37 | "\\begin{align}\n", 38 | "&\\int_{\\Omega} \\sigma_{ij} \\varepsilon_{ij} \\, d\\Omega + \\int_{\\Omega} \\frac{\\partial p}{\\partial x_i}v_i \\, d\\Omega \\\\\n", 39 | "&= 0\n", 40 | "\\end{align}\n", 41 | "$$\n", 42 | "\n", 43 | "for all test functions $v_i \\in H_0^1(\\Omega)$." 44 | ] 45 | } 46 | ], 47 | "metadata": {}, 48 | "nbformat": 4, 49 | "nbformat_minor": 5 50 | } 51 | -------------------------------------------------------------------------------- /chapter5/cfd/stokes_flow_in_a_lid-driven_cavity.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "fbe877e5", 6 | "metadata": {}, 7 | "source": [ 8 | "# Stokes Flow in a Lid-Driven Cavity\n", 9 | "*Author: Ahmed Ratnani*\n", 10 | "\n", 11 | "## Mathematical Model\n", 12 | "\n", 13 | "Consider the steady-state Stokes equations for flow in a 2D lid-driven cavity:\n", 14 | "\n", 15 | "$$\n", 16 | "\\begin{align}\n", 17 | "- \\nabla p + \\mu \\nabla^2 \\mathbf{v} &= 0 \\\\\n", 18 | "\\nabla \\cdot \\mathbf{v} &= 0\n", 19 | "\\end{align}\n", 20 | "$$\n", 21 | "\n", 22 | "### Boundary Conditions\n", 23 | "\n", 24 | "- Lid: $\\mathbf{v} = (1, 0)$ (lid-driven at constant velocity).\n", 25 | "\n", 26 | "- Other boundaries: $\\mathbf{v} = (0, 0)$ (no-slip condition).\n", 27 | "\n", 28 | "- Outlet: $\\frac{\\partial p}{\\partial n} = 0$ (zero-pressure gradient).\n", 29 | "\n", 30 | "### Initial Conditions\n", 31 | "\n", 32 | "Start with an initial guess for velocity and pressure.\n", 33 | "\n", 34 | "## Weak Formulation\n", 35 | "\n", 36 | "Find $\\mathbf{v} \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 37 | "\n", 38 | "$$\n", 39 | "\\begin{align}\n", 40 | "&\\int_{\\Omega} \\mu \\nabla \\mathbf{v} : \\nabla \\mathbf{w} \\, d\\Omega - \\int_{\\Omega} p \\nabla \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 41 | "&= 0\n", 42 | "\\end{align}\n", 43 | "$$\n", 44 | "\n", 45 | "for all test functions $\\mathbf{w} \\in H_0^1(\\Omega)$.\n", 46 | "\n" 47 | ] 48 | } 49 | ], 50 | "metadata": {}, 51 | "nbformat": 4, 52 | "nbformat_minor": 5 53 | } 54 | -------------------------------------------------------------------------------- /chapter5/cfd/two-phase_flow.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "94e72217", 6 | "metadata": {}, 7 | "source": [ 8 | "# Two-Phase Flow (Immersed Boundary Method)\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the incompressible Navier-Stokes equations with the Immersed Boundary Method for simulating two-phase flows:\n", 13 | "\n", 14 | "$$\n", 15 | "\\begin{align}\n", 16 | "\\rho \\frac{\\partial \\mathbf{v}}{\\partial t} + \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} &= -\\nabla p + \\mu \\nabla^2 \\mathbf{v} + \\mathbf{f}_{\\text{IB}} \\\\\n", 17 | "\\nabla \\cdot \\mathbf{v} &= 0\n", 18 | "\\end{align}\n", 19 | "$$\n", 20 | "\n", 21 | "where $\\mathbf{f}_{\\text{IB}}$ is the immersed boundary force.\n", 22 | "\n", 23 | "### Boundary Conditions\n", 24 | "\n", 25 | "- Inlet and outlet: Specify velocity or pressure conditions.\n", 26 | "- Immersed boundary conditions to model the interface.\n", 27 | "\n", 28 | "### Initial Conditions\n", 29 | "\n", 30 | "Specify initial conditions for velocity, pressure, and the immersed boundary.\n", 31 | "\n", 32 | "## Weak Formulation\n", 33 | "\n", 34 | "Find $\\mathbf{v} \\in H_0^1(\\Omega)$ and $p \\in L^2(\\Omega)$ such that:\n", 35 | "\n", 36 | "$$\n", 37 | "\\begin{align}\n", 38 | "&\\int_{\\Omega} \\rho \\frac{\\partial \\mathbf{v}}{\\partial t} \\cdot \\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\rho (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 39 | "&+ \\int_{\\Omega} \\mu \\nabla \\mathbf{v} : \\nabla \\mathbf{w} \\, d\\Omega - \\int_{\\Omega} p \\nabla \\cdot \\mathbf{w} \\, d\\Omega + \\int_{\\Omega} \\mathbf{f}_{\\text{IB}} \\cdot \\mathbf{w} \\, d\\Omega \\\\\n", 40 | "&+ \\int_{\\Omega} \\nabla \\cdot \\mathbf{v} q \\, d\\Omega \\\\\n", 41 | "&= 0\n", 42 | "\\end{align}\n", 43 | "$$\n", 44 | "\n", 45 | "for all test functions $\\mathbf{w} \\in H_0^1(\\Omega)$ and $q \\in L^2(\\Omega)$." 46 | ] 47 | } 48 | ], 49 | "metadata": {}, 50 | "nbformat": 4, 51 | "nbformat_minor": 5 52 | } 53 | -------------------------------------------------------------------------------- /chapter5/electromagnetics.md: -------------------------------------------------------------------------------- 1 | # Electromagnetics 2 | 3 | 4 | Electromagnetic problems are commonly described by Maxwell's equations, which govern the behavior of electric and magnetic fields. The Finite Element Method (FEM) provides a powerful numerical approach for solving these equations in complex geometries. This section provides a concise overview of the mathematical formulation for electromagnetic problems using finite elements. 5 | 6 | ## Maxwell's Equations 7 | 8 | The time-harmonic Maxwell's equations in free space are given by: 9 | 10 | $$ 11 | \begin{align} 12 | \nabla \times \mathbf{E} &= -j\omega \mu \mathbf{H}, \label{eq:maxwell1} \\ 13 | \nabla \times \mathbf{H} &= j\omega \varepsilon \mathbf{E}, \label{eq:maxwell2} \\ 14 | \nabla \cdot \mathbf{B} &= 0, \label{eq:maxwell3} \\ 15 | \nabla \cdot \mathbf{D} &= 0, \label{eq:maxwell4} 16 | \end{align} 17 | $$ 18 | 19 | where $\mathbf{E}$ is the electric field, $\mathbf{H}$ is the magnetic field, $\mathbf{B}$ is the magnetic flux density, $\mathbf{D}$ is the electric displacement field, $\omega$ is the angular frequency, $\mu$ is the permeability, and $\varepsilon$ is the permittivity. 20 | 21 | ## Weak Formulation 22 | 23 | The weak form of Maxwell's equations is obtained by multiplying each equation with suitable test functions and integrating over the domain $\Omega$. For the electric field $\mathbf{E}$, the weak form is given by: 24 | 25 | $$ 26 | \begin{equation} 27 | \int_{\Omega} \nabla \times \mathbf{E} \cdot \nabla \times \mathbf{v} \, d\Omega + \omega^2 \mu \varepsilon \mathbf{E} \cdot \mathbf{v} \, d\Omega = 0, 28 | \end{equation} 29 | $$ 30 | 31 | where $\mathbf{v}$ is a test function belonging to the function space $H(\text{curl}; \Omega)$. 32 | 33 | Similarly, for the magnetic field $\mathbf{H}$, the weak form is given by: 34 | 35 | $$ 36 | \begin{equation} 37 | \int_{\Omega} \nabla \times \mathbf{H} \cdot \nabla \times \mathbf{u} \, d\Omega - \omega^2 \mu \varepsilon \mathbf{H} \cdot \mathbf{u} \, d\Omega = 0, 38 | \end{equation} 39 | $$ 40 | 41 | where $\mathbf{u}$ is a test function belonging to the function space $H(\text{curl}; \Omega)$. 42 | 43 | ## Finite Element Discretization 44 | 45 | To apply the finite element method, the domain $\Omega$ is discretized into elements, and the electromagnetic fields are approximated using piecewise basis functions. The discretized weak form leads to a system of linear equations, which can be solved numerically to obtain the finite element solution. 46 | 47 | ## References 48 | 49 | The following references provide in-depth coverage of the mathematical background for electromagnetism using finite elements: {cite}`jin2015finite` {cite}`bossavit1998whitney` {cite}`monk2003finite` 50 | 51 | -------------------------------------------------------------------------------- /chapter5/fsi.md: -------------------------------------------------------------------------------- 1 | # Fluid-Structure Interaction 2 | 3 | 4 | Fluid-Structure Interaction (FSI) involves the coupled interaction between a fluid and a structure, where the motion of one influences the behavior of the other. The Finite Element Method (FEM) is a powerful tool for simulating FSI problems. This section provides an overview of the mathematical formulation for fluid-structure interaction using finite elements. 5 | 6 | ## Coupled Fluid-Structure Equations 7 | 8 | The governing equations for fluid-structure interaction involve the Navier-Stokes equations for the fluid and the equations of motion for the structure. In a partitioned approach, the coupled system is given by: 9 | 10 | $$ 11 | \begin{align} 12 | \text{Fluid Domain:} \quad \rho_f \left(\frac{\partial \mathbf{u}_f}{\partial t} + (\mathbf{u}_f \cdot \nabla)\mathbf{u}_f\right) &= -\nabla p_f + \mu_f \nabla^2 \mathbf{u}_f + \mathbf{f}_f + \mathbf{F}_s, \label{eq:fsi_fluid_momentum} \\ 13 | \nabla \cdot \mathbf{u}_f &= 0, \label{eq:fsi_fluid_continuity} \\ 14 | \text{Structure Domain:} \quad \rho_s \frac{\partial^2 \mathbf{u}_s}{\partial t^2} &= \nabla \cdot \mathbf{P}_s + \mathbf{f}_s, \label{eq:fsi_structure_motion} 15 | \end{align} 16 | $$ 17 | 18 | where: 19 | 20 | - $\mathbf{u}_f$ is the fluid velocity, 21 | - $p_f$ is the fluid pressure, 22 | - $\rho_f$ is the fluid density, 23 | - $\mu_f$ is the fluid dynamic viscosity, 24 | - $\mathbf{f}_f$ is the fluid body force, 25 | - $\mathbf{F}_s$ is the fluid-structure interaction force on the fluid by the structure, 26 | - $\mathbf{u}_s$ is the structure displacement, 27 | - $\rho_s$ is the structure density, 28 | - $\mathbf{P}_s$ is the structure internal force, 29 | - $\mathbf{f}_s$ is the structure external force. 30 | 31 | ## Coupling Conditions 32 | 33 | For a fluid-structure interaction problem, coupling conditions at the fluid-structure interface are essential. These conditions ensure continuity of velocities, pressures, and forces between the fluid and structure. A common approach is to enforce kinematic and dynamic conditions: 34 | 35 | $$ 36 | \begin{align} 37 | \text{Kinematic Condition:} \quad \mathbf{u}_f &= \mathbf{u}_s, \label{eq:fsi_kinematic_condition} \\ 38 | \text{Dynamic Condition:} \quad \mathbf{P}_f \cdot \mathbf{n} &= \mathbf{P}_s \cdot \mathbf{n}, \label{eq:fsi_dynamic_condition} 39 | \end{align} 40 | $$ 41 | 42 | where $\mathbf{n}$ is the unit outward normal vector at the fluid-structure interface, and $\mathbf{P}_f$ and $\mathbf{P}_s$ are the fluid and structure stresses, respectively. 43 | 44 | ## Weak Formulation 45 | 46 | The weak form of the coupled fluid-structure problem involves the variational formulation of the fluid and structure equations, incorporating the coupling conditions. For the fluid domain, the weak form is given by: 47 | 48 | $$ 49 | \begin{equation} 50 | \int_{\Omega_f} \rho_f \left(\frac{\partial \mathbf{u}_f}{\partial t} + (\mathbf{u}_f \cdot \nabla)\mathbf{u}_f\right) \cdot \mathbf{v}_f \, d\Omega_f + \int_{\Omega_f} \mu_f \nabla \mathbf{u}_f : \nabla \mathbf{v}_f \, d\Omega_f = \int_{\Omega_f} (\mathbf{f}_f + \mathbf{F}_s) \cdot \mathbf{v}_f \, d\Omega_f, 51 | \end{equation} 52 | $$ 53 | 54 | where $\mathbf{v}_f$ is a test function belonging to the function space $H^1(\Omega_f)$, and $\Omega_f$ is the fluid domain. 55 | 56 | For the structure domain, the weak form is given by: 57 | 58 | $$ 59 | \begin{equation} 60 | \int_{\Omega_s} \rho_s \frac{\partial^2 \mathbf{u}_s}{\partial t^2} \cdot \mathbf{v}_s \, d\Omega_s + \int_{\Omega_s} \nabla \cdot \mathbf{P}_s \cdot \mathbf{v}_s \, d\Omega_s = \int_{\Omega_s} \mathbf{f}_s \cdot \mathbf{v}_s \, d\Omega_s, 61 | \end{equation} 62 | $$ 63 | 64 | where $\mathbf{v}_s$ is a test function belonging to the function space $H^1(\Omega_s)$, and $\Omega_s$ is the structure domain. 65 | 66 | The coupling conditions, such as \eqref{eq:fsi_kinematic_condition} and \eqref{eq:fsi_dynamic_condition}, should be enforced during the assembly of the global matrices. 67 | 68 | ## References 69 | 70 | The following references provide comprehensive coverage of the mathematical background for fluid-structure interaction using finite elements: {cite}`hron2006fluid` {cite}`bathe2014finite` {cite}`quarteroni2017fluid` 71 | -------------------------------------------------------------------------------- /chapter5/fsi/fluid-structure_interaction_in_a_flexible_channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c06958bc", 6 | "metadata": {}, 7 | "source": [ 8 | "# Fluid-Structure Interaction in a Flexible Channel\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the FSI of a flexible channel with fluid flow. The fluid velocity $\\mathbf{v}$ and structural displacement $u$ are coupled through the FSI problem.\n", 13 | "\n", 14 | "- Structural Equation:\n", 15 | "\n", 16 | "$$\n", 17 | "\\begin{align*}\n", 18 | "\\rho_s A_s \\frac{\\partial^2 u}{\\partial t^2} - \\nabla \\cdot \\sigma(u) &= 0 \\quad \\text{in } \\Omega_s \\times (0, T) \\\\\n", 19 | "u &= 0 \\quad \\text{on } \\Gamma_{\\text{fixed}} \\times (0, T) \\\\\n", 20 | "\\sigma(u) \\cdot \\mathbf{n} &= \\mathbf{t} \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T)\n", 21 | "\\end{align*}\n", 22 | "$$\n", 23 | "\n", 24 | "- Fluid Equation:\n", 25 | "\n", 26 | "$$\n", 27 | "\\begin{align*}\n", 28 | "\\rho_f \\frac{\\partial \\mathbf{v}}{\\partial t} + \\rho_f (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} - \\nabla \\cdot \\sigma(\\mathbf{v}) &= 0 \\quad \\text{in } \\Omega_f \\times (0, T) \\\\\n", 29 | "\\mathbf{v} &= \\mathbf{0} \\quad \\text{on } \\Gamma_{\\text{inlet}} \\times (0, T) \\\\\n", 30 | "\\sigma(\\mathbf{v}) \\cdot \\mathbf{n} &= p \\cdot \\mathbf{n} \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T)\n", 31 | "\\end{align*}\n", 32 | "$$\n", 33 | "\n", 34 | "- Coupling Conditions:\n", 35 | "\n", 36 | "$$\n", 37 | "\\begin{align*}\n", 38 | "\\mathbf{v}(\\mathbf{x}, t) &= \\mathbf{v}_f(\\mathbf{x}, t) \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T) \\\\\n", 39 | "\\sigma(u) \\cdot \\mathbf{n} &= \\sigma(\\mathbf{v}) \\cdot \\mathbf{n} \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T)\n", 40 | "\\end{align*}\n", 41 | "$$\n", 42 | "\n", 43 | "## Weak Formulation\n", 44 | "\n", 45 | "Find $u \\in V_s$ and $\\mathbf{v} \\in V_f$ such that\n", 46 | "\n", 47 | "$$\n", 48 | "\\begin{align*}\n", 49 | "\\int_{\\Omega_s} \\rho_s A_s \\frac{\\partial^2 u}{\\partial t^2} \\phi_s \\, d\\Omega &- \\int_{\\Omega_s} \\nabla \\cdot \\sigma(u) \\cdot \\nabla \\phi_s \\, d\\Omega = 0 \\\\\n", 50 | "\\int_{\\Omega_f} \\rho_f \\frac{\\partial \\mathbf{v}}{\\partial t} \\cdot \\mathbf{\\phi}_f \\, d\\Omega &+ \\int_{\\Omega_f} \\rho_f (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} \\cdot \\mathbf{\\phi}_f \\, d\\Omega - \\int_{\\Omega_f} \\nabla \\cdot \\sigma(\\mathbf{v}) \\cdot \\nabla \\mathbf{\\phi}_f \\, d\\Omega = 0\n", 51 | "\\end{align*}\n", 52 | "$$\n", 53 | "\n", 54 | "for all $\\phi_s \\in V_s$ and $\\mathbf{\\phi}_f \\in V_f$.\n", 55 | "\n", 56 | "\n", 57 | "\n", 58 | "\n", 59 | "\n", 60 | "\n", 61 | "\n" 62 | ] 63 | } 64 | ], 65 | "metadata": {}, 66 | "nbformat": 4, 67 | "nbformat_minor": 5 68 | } 69 | -------------------------------------------------------------------------------- /chapter5/fsi/flutter_analysis_of_a_flexible_wing_in_fluid_flow.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "37cc9bbf", 6 | "metadata": {}, 7 | "source": [ 8 | "# Flutter Analysis of a Flexible Wing in Fluid Flow\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the fluid-structure interaction of a flexible wing in a steady airflow. The structural displacement \\(u\\) and fluid velocity \\(\\mathbf{v}\\) are coupled through the FSI problem.\n", 13 | "\n", 14 | "- Structural Equation:\n", 15 | "\n", 16 | "$$\n", 17 | "\\begin{align*}\n", 18 | "\\rho_s A_s \\frac{\\partial^2 u}{\\partial t^2} + c_s \\frac{\\partial u}{\\partial t} - \\nabla \\cdot (\\sigma(u)) &= 0 \\quad \\text{in } \\Omega_s \\times (0, T) \\\\\n", 19 | "u &= 0 \\quad \\text{on } \\Gamma_{\\text{fixed}} \\times (0, T) \\\\\n", 20 | "\\sigma(u) \\cdot \\mathbf{n} &= p \\cdot \\mathbf{n} \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T)\n", 21 | "\\end{align*}\n", 22 | "$$\n", 23 | "\n", 24 | "- Fluid Equation:\n", 25 | "\n", 26 | "$$\n", 27 | "\\begin{align*}\n", 28 | "\\rho_f \\frac{\\partial \\mathbf{v}}{\\partial t} + \\rho_f (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} - \\nabla \\cdot \\sigma(\\mathbf{v}) &= 0 \\quad \\text{in } \\Omega_f \\times (0, T) \\\\\n", 29 | "\\mathbf{v} &= \\mathbf{0} \\quad \\text{on } \\Gamma_{\\text{inlet}} \\times (0, T) \\\\\n", 30 | "\\sigma(\\mathbf{v}) \\cdot \\mathbf{n} &= \\mathbf{t} \\quad \\text{on } \\Gamma_{\\text{wing}} \\times (0, T) \\\\\n", 31 | "\\end{align*}\n", 32 | "$$\n", 33 | "\n", 34 | "- Coupling Conditions:\n", 35 | "\n", 36 | "$$\n", 37 | "\\begin{align*}\n", 38 | "\\mathbf{v}(\\mathbf{x}, t) &= \\mathbf{v}_f(\\mathbf{x}, t) \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T) \\\\\n", 39 | "\\sigma(u) \\cdot \\mathbf{n} &= \\sigma(\\mathbf{v}) \\cdot \\mathbf{n} \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T)\n", 40 | "\\end{align*}\n", 41 | "$$\n", 42 | "\n", 43 | "## Weak Formulation\n", 44 | "\n", 45 | "Find $u \\in V_s$ and $\\mathbf{v} \\in V_f$ such that\n", 46 | "\n", 47 | "$$\n", 48 | "\\begin{align*}\n", 49 | "\\int_{\\Omega_s} \\rho_s A_s \\frac{\\partial^2 u}{\\partial t^2} \\phi_s \\, d\\Omega &+ \\int_{\\Omega_s} c_s \\frac{\\partial u}{\\partial t} \\phi_s \\, d\\Omega - \\int_{\\Omega_s} \\nabla \\cdot \\sigma(u) \\cdot \\nabla \\phi_s \\, d\\Omega = 0 \\\\\n", 50 | "\\int_{\\Omega_f} \\rho_f \\frac{\\partial \\mathbf{v}}{\\partial t} \\cdot \\mathbf{\\phi}_f \\, d\\Omega &+ \\int_{\\Omega_f} \\rho_f (\\mathbf{v} \\cdot \\nabla) \\mathbf{v} \\cdot \\mathbf{\\phi}_f \\, d\\Omega - \\int_{\\Omega_f} \\nabla \\cdot \\sigma(\\mathbf{v}) \\cdot \\nabla \\mathbf{\\phi}_f \\, d\\Omega = 0\n", 51 | "\\end{align*}\n", 52 | "$$\n", 53 | "\n", 54 | "for all $\\phi_s \\in V_s$ and $\\mathbf{\\phi}_f \\in V_f$.\n", 55 | "\n" 56 | ] 57 | } 58 | ], 59 | "metadata": {}, 60 | "nbformat": 4, 61 | "nbformat_minor": 5 62 | } 63 | -------------------------------------------------------------------------------- /chapter5/fsi/two-way_fluid-structure_interaction_in_a_tube.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9e78f53f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Two-Way Fluid-Structure Interaction in a Tube\n", 9 | "\n", 10 | "## Mathematical Model\n", 11 | "\n", 12 | "Consider the two-way FSI of a flexible tube conveying fluid. The fluid pressure \\(p\\) and structural displacement \\(u\\) are coupled through the FSI problem.\n", 13 | "\n", 14 | "- Structural Equation:\n", 15 | "\n", 16 | "$$\n", 17 | "\\begin{align*}\n", 18 | "\\rho_s A_s \\frac{\\partial^2 u}{\\partial t^2} - \\nabla \\cdot \\sigma(u) &= 0 \\quad \\text{in } \\Omega_s \\times (0, T) \\\\\n", 19 | "u &= 0 \\quad \\text{on } \\Gamma_{\\text{fixed}} \\times (0, T) \\\\\n", 20 | "\\sigma(u) \\cdot \\mathbf{n} &= p \\cdot \\mathbf{n} \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T)\n", 21 | "\\end{align*}\n", 22 | "$$\n", 23 | "\n", 24 | "- Fluid Equation:\n", 25 | "\n", 26 | "$$\n", 27 | "\\begin{align*}\n", 28 | "\\rho_f \\frac{\\partial^2 p}{\\partial t^2} - \\nabla \\cdot \\sigma(p) &= 0 \\quad \\text{in } \\Omega_f \\times (0, T) \\\\\n", 29 | "p &= 0 \\quad \\text{on } \\Gamma_{\\text{inlet}} \\times (0, T) \\\\\n", 30 | "\\sigma(p) \\cdot \\mathbf{n} &= \\sigma(u) \\cdot \\mathbf{n} \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T)\n", 31 | "\\end{align*}\n", 32 | "$$\n", 33 | "\n", 34 | "- Coupling Conditions:\n", 35 | "\n", 36 | "$$\n", 37 | "\\begin{align*}\n", 38 | "\\sigma(u) \\cdot \\mathbf{n} &= \\sigma(p) \\cdot \\mathbf{n} \\quad \\text{on } \\Gamma_{\\text{interface}} \\times (0, T)\n", 39 | "\\end{align*}\n", 40 | "$$\n", 41 | "\n", 42 | "## Weak Formulation\n", 43 | "\n", 44 | "Find $u \\in V_s$ and $p \\in V_f$ such that\n", 45 | "\n", 46 | "$$\n", 47 | "\\begin{align*}\n", 48 | "\\int_{\\Omega_s} \\rho_s A_s \\frac{\\partial^2 u}{\\partial t^2} \\phi_s \\, d\\Omega &- \\int_{\\Omega_s} \\nabla \\cdot \\sigma(u) \\cdot \\nabla \\phi_s \\, d\\Omega = 0 \\\\\n", 49 | "\\int_{\\Omega_f} \\rho_f \\frac{\\partial^2 p}{\\partial t^2} \\phi_f \\, d\\Omega &- \\int_{\\Omega_f} \\nabla \\cdot \\sigma(p) \\cdot \\nabla \\phi_f \\, d\\Omega = 0\n", 50 | "\\end{align*}\n", 51 | "$$\n", 52 | "\n", 53 | "for all $\\phi_s \\in V_s$ and $\\phi_f \\in V_f$.\n", 54 | "\n" 55 | ] 56 | } 57 | ], 58 | "metadata": {}, 59 | "nbformat": 4, 60 | "nbformat_minor": 5 61 | } 62 | -------------------------------------------------------------------------------- /chapter5/material-science.md: -------------------------------------------------------------------------------- 1 | # Material Science 2 | 3 | 4 | These examples cover a variety of materials science scenarios, including heat conduction with phase change, elasticity with thermal expansion, creep in viscoelastic materials, diffusion and reaction in porous media, and piezoelectric materials. The weak formulations are presented in a variational form suitable for finite element methods. Adjustments can be made based on specific material properties and numerical considerations. 5 | 6 | -------------------------------------------------------------------------------- /chapter5/material-science/additive-manifacturing.md: -------------------------------------------------------------------------------- 1 | # Additive Manifacturing Process Simulations 2 | 3 | 4 | These examples cover various scenarios in additive manufacturing process simulations, including thermal simulation in powder bed fusion (PBF), fluid flow simulation in directed energy deposition (DED), structural simulation in fused filament fabrication (FFF), multi-material simulation in material jetting, and residual stress simulation in selective laser melting (SLM). The weak formulations are presented in a variational form suitable for finite element methods. Adjustments can be made based on specific process parameters and numerical considerations. 5 | -------------------------------------------------------------------------------- /chapter5/material-science/composite-materials-analysis.md: -------------------------------------------------------------------------------- 1 | # Composite Materials Analysis 2 | 3 | 4 | These examples cover various scenarios in composite materials analysis, including laminate plate bending, composite shell structures, composite beam analysis, composite shaft analysis, and composite pressure vessel analysis. The weak formulations are presented in a variational form suitable for finite element methods. Adjustments can be made based on specific composite properties and numerical considerations. 5 | -------------------------------------------------------------------------------- /chapter5/material-science/composite-materials.md: -------------------------------------------------------------------------------- 1 | # Composite Materials 2 | 3 | 4 | These examples cover various scenarios in composite materials, including homogenization, thermal conductivity, fiber-reinforced composites, composite materials with piezoelectric fibers, and composite materials with thermal expansion. The weak formulations are presented in a variational form suitable for finite element methods. Adjustments can be made based on specific composite properties and numerical considerations. 5 | -------------------------------------------------------------------------------- /chapter5/material-science/composite_beam_analysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c3ea1dcd", 6 | "metadata": {}, 7 | "source": [ 8 | "# Composite Beam Analysis\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Equilibrium:} \\quad \\nabla \\cdot \\boldsymbol{\\sigma} + \\mathbf{b} = \\mathbf{0} \\\\\n", 15 | "&\\text{Constitutive Relation:} \\quad \\boldsymbol{\\sigma} = \\mathbf{D} : \\boldsymbol{\\varepsilon} \\\\\n", 16 | "&\\text{Kinematics:} \\quad \\boldsymbol{\\varepsilon} = \\frac{1}{2}\\left(\\nabla \\mathbf{u} + (\\nabla \\mathbf{u})^T\\right) \\\\\n", 17 | "&\\text{Compatibility:} \\quad \\nabla \\times \\nabla \\times \\mathbf{u} = \\mathbf{0}\n", 18 | "\\end{align*}\n", 19 | "$$\n", 20 | "\n", 21 | "Weak Formulation:\n", 22 | "\n", 23 | "$$\n", 24 | "\\begin{align*}\n", 25 | "&\\int_{\\Omega} \\left(\\boldsymbol{\\sigma} : \\boldsymbol{\\varepsilon} + \\mathbf{b} \\cdot \\mathbf{u}\\right) \\,d\\Omega = 0\n", 26 | "\\end{align*}\n", 27 | "$$\n" 28 | ] 29 | } 30 | ], 31 | "metadata": {}, 32 | "nbformat": 4, 33 | "nbformat_minor": 5 34 | } 35 | -------------------------------------------------------------------------------- /chapter5/material-science/composite_materials_with_piezoelectric_fibers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "90dd019d", 6 | "metadata": {}, 7 | "source": [ 8 | "# Composite Materials with Piezoelectric Fibers\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Mechanical Deformation:} \\quad \\nabla \\cdot \\boldsymbol{\\sigma} = \\mathbf{0} \\\\\n", 15 | "&\\text{Piezoelectricity:} \\quad \\nabla \\cdot \\mathbf{D} = \\rho_e, \\quad \\frac{\\partial \\mathbf{D}}{\\partial t} = \\mathbf{d} \\frac{\\partial \\mathbf{u}}{\\partial t}\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Mechanical Deformation:} \\quad \\int_{\\Omega} \\nabla \\cdot \\boldsymbol{\\sigma} : \\boldsymbol{\\varepsilon} \\,d\\Omega = 0 \\\\\n", 24 | "&\\text{Piezoelectricity:} \\quad \\int_{\\Omega} \\nabla \\cdot \\mathbf{D} \\cdot \\boldsymbol{\\phi} \\,d\\Omega = \\int_{\\Omega} \\rho_e \\boldsymbol{\\phi} \\,d\\Omega, \\quad \\int_{\\Omega} \\frac{\\partial \\mathbf{D}}{\\partial t} \\cdot \\boldsymbol{\\psi} \\,d\\Omega \\\\\n", 25 | "&\\quad = \\int_{\\Omega} \\mathbf{d} \\frac{\\partial \\mathbf{u}}{\\partial t} \\cdot \\boldsymbol{\\psi} \\,d\\Omega\n", 26 | "\\end{align*}\n", 27 | "$$\n" 28 | ] 29 | } 30 | ], 31 | "metadata": {}, 32 | "nbformat": 4, 33 | "nbformat_minor": 5 34 | } 35 | -------------------------------------------------------------------------------- /chapter5/material-science/composite_materials_with_thermal_expansion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "17887d82", 6 | "metadata": {}, 7 | "source": [ 8 | "# Composite Materials with Thermal Expansion\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Matrix Phase:} \\quad \\alpha_{\\text{matrix}} \\frac{\\partial T_{\\text{matrix}}}{\\partial t} - \\nabla \\cdot (\\beta_{\\text{matrix}} T_{\\text{matrix}} \\mathbf{I}) = \\mathbf{0} \\\\\n", 15 | "&\\text{Fiber Phase:} \\quad \\alpha_{\\text{fiber}} \\frac{\\partial T_{\\text{fiber}}}{\\partial t} - \\nabla \\cdot (\\beta_{\\text{fiber}} T_{\\text{fiber}} \\mathbf{I}) = \\mathbf{0}\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Matrix Phase:} \\quad \\int_{\\Omega_{\\text{matrix}}} \\alpha_{\\text{matrix}} \\frac{\\partial T_{\\text{matrix}}}{\\partial t} \\phi_{\\text{matrix}} \\,d\\Omega_{\\text{matrix}} - \\int_{\\Omega_{\\text{matrix}}} \\nabla \\cdot (\\beta_{\\text{matrix}} T_{\\text{matrix}} \\mathbf{I}) \\cdot \\phi_{\\text{matrix}} \\,d\\Omega_{\\text{matrix}} = 0 \\\\\n", 24 | "&\\text{Fiber Phase:} \\quad \\int_{\\Omega_{\\text{fiber}}} \\alpha_{\\text{fiber}} \\frac{\\partial T_{\\text{fiber}}}{\\partial t} \\phi_{\\text{fiber}} \\,d\\Omega_{\\text{fiber}} - \\int_{\\Omega_{\\text{fiber}}} \\nabla \\cdot (\\beta_{\\text{fiber}} T_{\\text{fiber}} \\mathbf{I}) \\cdot \\phi_{\\text{fiber}} \\,d\\Omega_{\\text{fiber}} = 0\n", 25 | "\\end{align*}\n", 26 | "$$\n" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/composite_pressure_vessel_analysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "31c27ea5", 6 | "metadata": {}, 7 | "source": [ 8 | "# Composite Pressure Vessel Analysis\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Equilibrium:} \\quad \\nabla \\cdot \\boldsymbol{\\sigma} + \\mathbf{b} = \\mathbf{0} \\\\\n", 15 | "&\\text{Constitutive Relation:} \\quad \\boldsymbol{\\sigma} = \\mathbf{D} : \\boldsymbol{\\varepsilon} \\\\\n", 16 | "&\\text{Kinematics:} \\quad \\boldsymbol{\\varepsilon} = \\frac{1}{2}\\left(\\nabla \\mathbf{u} + (\\nabla \\mathbf{u})^T\\right) \\\\\n", 17 | "&\\text{Compatibility:} \\quad \\nabla \\times \\nabla \\times \\mathbf{u} = \\mathbf{0}\n", 18 | "\\end{align*}\n", 19 | "$$\n", 20 | "\n", 21 | "Weak Formulation:\n", 22 | "\n", 23 | "$$\n", 24 | "\\begin{align*}\n", 25 | "&\\int_{\\Omega} \\left(\\boldsymbol{\\sigma} : \\boldsymbol{\\varepsilon} + \\mathbf{b} \\cdot \\mathbf{u}\\right) \\,d\\Omega = 0\n", 26 | "\\end{align*}\n", 27 | "$$\n", 28 | "\n" 29 | ] 30 | } 31 | ], 32 | "metadata": {}, 33 | "nbformat": 4, 34 | "nbformat_minor": 5 35 | } 36 | -------------------------------------------------------------------------------- /chapter5/material-science/composite_shaft_analysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1135bb05", 6 | "metadata": {}, 7 | "source": [ 8 | "# Composite Shaft Analysis\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Equilibrium:} \\quad \\nabla \\cdot \\boldsymbol{\\sigma} + \\mathbf{b} = \\mathbf{0} \\\\\n", 15 | "&\\text{Constitutive Relation:} \\quad \\boldsymbol{\\sigma} = \\mathbf{D} : \\boldsymbol{\\varepsilon} \\\\\n", 16 | "&\\text{Kinematics:} \\quad \\boldsymbol{\\varepsilon} = \\frac{1}{2}\\left(\\nabla \\mathbf{u} + (\\nabla \\mathbf{u})^T\\right) \\\\\n", 17 | "&\\text{Compatibility:} \\quad \\nabla \\times \\nabla \\times \\mathbf{u} = \\mathbf{0}\n", 18 | "\\end{align*}\n", 19 | "$$\n", 20 | "\n", 21 | "Weak Formulation:\n", 22 | "\n", 23 | "$$\n", 24 | "\\begin{align*}\n", 25 | "&\\int_{\\Omega} \\left(\\boldsymbol{\\sigma} : \\boldsymbol{\\varepsilon} + \\mathbf{b} \\cdot \\mathbf{u}\\right) \\,d\\Omega = 0\n", 26 | "\\end{align*}\n", 27 | "$$" 28 | ] 29 | } 30 | ], 31 | "metadata": {}, 32 | "nbformat": 4, 33 | "nbformat_minor": 5 34 | } 35 | -------------------------------------------------------------------------------- /chapter5/material-science/composite_shell_structures.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3f9f26ab", 6 | "metadata": {}, 7 | "source": [ 8 | "# Composite Shell Structures\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Equilibrium:} \\quad \\nabla \\cdot \\boldsymbol{\\sigma} + \\mathbf{b} = \\mathbf{0} \\\\\n", 15 | "&\\text{Constitutive Relation:} \\quad \\boldsymbol{\\sigma} = \\mathbf{D} : \\boldsymbol{\\varepsilon} \\\\\n", 16 | "&\\text{Kinematics:} \\quad \\boldsymbol{\\varepsilon} = \\frac{1}{2}\\left(\\nabla \\mathbf{u} + (\\nabla \\mathbf{u})^T\\right) \\\\\n", 17 | "&\\text{Compatibility:} \\quad \\nabla \\times \\nabla \\times \\mathbf{u} = \\mathbf{0}\n", 18 | "\\end{align*}\n", 19 | "$$\n", 20 | "\n", 21 | "Weak Formulation:\n", 22 | "\n", 23 | "$$\n", 24 | "\\begin{align*}\n", 25 | "&\\int_{\\Omega} \\left(\\boldsymbol{\\sigma} : \\boldsymbol{\\varepsilon} + \\mathbf{b} \\cdot \\mathbf{u}\\right) \\,d\\Omega = 0\n", 26 | "\\end{align*}\n", 27 | "$$\n" 28 | ] 29 | } 30 | ], 31 | "metadata": {}, 32 | "nbformat": 4, 33 | "nbformat_minor": 5 34 | } 35 | -------------------------------------------------------------------------------- /chapter5/material-science/creep_in_viscoelastic_materials.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c317aa5a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Creep in Viscoelastic Materials\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Mechanical Deformation:} \\quad \\nabla \\cdot \\mathbf{u} = 0, \\quad \\rho \\frac{\\partial^2 \\mathbf{u}}{\\partial t^2} - \\nabla \\cdot (\\boldsymbol{\\sigma}) = \\mathbf{0} \\\\\n", 15 | "&\\text{Creep:} \\quad \\frac{\\partial \\boldsymbol{\\varepsilon}}{\\partial t} - \\boldsymbol{\\varepsilon} : \\nabla \\mathbf{u} = 0\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Mechanical Deformation:} \\quad \\int_{\\Omega} \\nabla \\cdot \\mathbf{u} \\phi \\,d\\Omega = 0, \\quad \\int_{\\Omega} \\rho \\frac{\\partial^2 \\mathbf{u}}{\\partial t^2} \\cdot \\mathbf{v} \\,d\\Omega - \\int_{\\Omega} \\nabla \\cdot (\\boldsymbol{\\sigma}) \\cdot \\mathbf{v} \\,d\\Omega = 0 \\\\\n", 24 | "&\\text{Creep:} \\quad \\int_{\\Omega} \\frac{\\partial \\boldsymbol{\\varepsilon}}{\\partial t} : \\boldsymbol{\\phi} \\,d\\Omega - \\int_{\\Omega} \\boldsymbol{\\varepsilon} : \\nabla \\mathbf{u} \\cdot \\boldsymbol{\\phi} \\,d\\Omega = 0\n", 25 | "\\end{align*}\n", 26 | "$$\n" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/diffusion_and_reaction_in_porous_media.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "086f355d", 6 | "metadata": {}, 7 | "source": [ 8 | "# Diffusion and Reaction in Porous Media\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Diffusion:} \\quad \\frac{\\partial c}{\\partial t} - \\nabla \\cdot (D \\nabla c) = 0 \\\\\n", 15 | "&\\text{Reaction:} \\quad \\frac{\\partial \\rho_r}{\\partial t} = k c\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Diffusion:} \\quad \\int_{\\Omega} \\frac{\\partial c}{\\partial t} \\phi \\,d\\Omega + \\int_{\\Omega} D \\nabla c \\cdot \\nabla \\phi \\,d\\Omega = 0 \\\\\n", 24 | "&\\text{Reaction:} \\quad \\int_{\\Omega} \\frac{\\partial \\rho_r}{\\partial t} \\psi \\,d\\Omega - \\int_{\\Omega} k c \\psi \\,d\\Omega = 0\n", 25 | "\\end{align*}\n", 26 | "$$" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/elasticity_with_thermal_expansion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "d8f79629", 6 | "metadata": {}, 7 | "source": [ 8 | "# Elasticity with Thermal Expansion\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Elasticity:} \\quad \\nabla \\cdot \\boldsymbol{\\sigma} = \\mathbf{0} \\\\\n", 15 | "&\\text{Thermal Expansion:} \\quad \\alpha \\frac{\\partial T}{\\partial t} - \\nabla \\cdot (\\beta T \\mathbf{I}) = \\mathbf{0}\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Elasticity:} \\quad \\int_{\\Omega} \\boldsymbol{\\sigma} : \\boldsymbol{\\varepsilon} \\,d\\Omega = 0 \\\\\n", 24 | "&\\text{Thermal Expansion:} \\quad \\int_{\\Omega} \\alpha \\frac{\\partial T}{\\partial t} \\phi \\,d\\Omega - \\int_{\\Omega} \\nabla \\cdot (\\beta T \\mathbf{I}) \\cdot \\phi \\,d\\Omega = 0\n", 25 | "\\end{align*}\n", 26 | "$$\n" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/fiber-reinforced_composite_materials.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "23406716", 6 | "metadata": {}, 7 | "source": [ 8 | "# Fiber-Reinforced Composite Materials\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Matrix Phase:} \\quad \\nabla \\cdot (\\mathbf{C}_{\\text{matrix}} : \\boldsymbol{\\varepsilon}_{\\text{matrix}}) = 0 \\\\\n", 15 | "&\\text{Fiber Phase:} \\quad \\nabla \\cdot (\\mathbf{C}_{\\text{fiber}} : \\boldsymbol{\\varepsilon}_{\\text{fiber}}) = 0\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Matrix Phase:} \\quad \\int_{\\Omega_{\\text{matrix}}} \\nabla \\cdot (\\mathbf{C}_{\\text{matrix}} : \\boldsymbol{\\varepsilon}_{\\text{matrix}}) \\cdot \\boldsymbol{\\phi}_{\\text{matrix}} \\,d\\Omega_{\\text{matrix}} = 0 \\\\\n", 24 | "&\\text{Fiber Phase:} \\quad \\int_{\\Omega_{\\text{fiber}}} \\nabla \\cdot (\\mathbf{C}_{\\text{fiber}} : \\boldsymbol{\\varepsilon}_{\\text{fiber}}) \\cdot \\boldsymbol{\\phi}_{\\text{fiber}} \\,d\\Omega_{\\text{fiber}} = 0\n", 25 | "\\end{align*}\n", 26 | "$$\n" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/fluid_flow_simulation_in_directed_energy_deposition.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1ea6c66f", 6 | "metadata": {}, 7 | "source": [ 8 | "# Fluid Flow Simulation in Directed Energy Deposition (DED)\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Navier-Stokes Equations:} \\quad \\rho \\frac{\\partial \\mathbf{v}}{\\partial t} + \\rho(\\mathbf{v} \\cdot \\nabla)\\mathbf{v} = -\\nabla p + \\mu \\nabla^2 \\mathbf{v} + \\mathbf{f} \\\\\n", 15 | "&\\text{Heat Transfer:} \\quad \\rho c \\frac{\\partial T}{\\partial t} + \\rho(\\mathbf{v} \\cdot \\nabla)T = k \\nabla^2 T\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\int_{\\Omega} \\left(\\rho \\frac{\\partial \\mathbf{v}}{\\partial t} \\cdot \\boldsymbol{\\psi} + \\rho(\\mathbf{v} \\cdot \\nabla)\\mathbf{v} \\cdot \\boldsymbol{\\psi} + \\nabla p \\cdot \\boldsymbol{\\psi} - \\mu \\nabla^2 \\mathbf{v} \\cdot \\boldsymbol{\\psi} - \\mathbf{f} \\cdot \\boldsymbol{\\psi}\\right) \\,d\\Omega = 0 \\\\\n", 24 | "&\\int_{\\Omega} \\left(\\rho c \\frac{\\partial T}{\\partial t} \\phi + \\rho(\\mathbf{v} \\cdot \\nabla)T \\phi - k \\nabla^2 T \\phi\\right) \\,d\\Omega = 0\n", 25 | "\\end{align*}\n", 26 | "$$" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/heat_conduction_with_phase_change.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b0d9bc7d", 6 | "metadata": {}, 7 | "source": [ 8 | "# Heat Conduction with Phase Change\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Heat Conduction:} \\quad \\rho c \\frac{\\partial T}{\\partial t} - \\nabla \\cdot (k \\nabla T) = Q \\\\\n", 15 | "&\\text{Phase Change:} \\quad \\frac{\\partial \\phi}{\\partial t} = M \\nabla^2 T\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Heat Conduction:} \\quad \\int_{\\Omega} \\rho c \\frac{\\partial T}{\\partial t} \\phi \\,d\\Omega + \\int_{\\Omega} k \\nabla T \\cdot \\nabla \\phi \\,d\\Omega = \\int_{\\Omega} Q \\phi \\,d\\Omega \\\\\n", 24 | "&\\text{Phase Change:} \\quad \\int_{\\Omega} \\frac{\\partial \\phi}{\\partial t} \\psi \\,d\\Omega = \\int_{\\Omega} M \\nabla^2 T \\psi \\,d\\Omega\n", 25 | "\\end{align*}\n", 26 | "$$\n" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/homogenization_of_composite_structures.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "d79107b5", 6 | "metadata": {}, 7 | "source": [ 8 | "# Homogenization of Composite Structures\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Microstructural Behavior:} \\quad \\nabla \\cdot (\\mathbf{C}_{\\text{micro}} : \\boldsymbol{\\varepsilon}_{\\text{micro}}) = \\mathbf{0} \\\\\n", 15 | "&\\text{Homogenized Behavior:} \\quad \\nabla \\cdot (\\mathbf{C}_{\\text{eff}} : \\boldsymbol{\\varepsilon}_{\\text{eff}}) = \\mathbf{0}\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Microstructural Behavior:} \\quad \\int_{\\Omega_{\\text{micro}}} \\nabla \\cdot (\\mathbf{C}_{\\text{micro}} : \\boldsymbol{\\varepsilon}_{\\text{micro}}) \\cdot \\boldsymbol{\\phi}_{\\text{micro}} \\,d\\Omega_{\\text{micro}} = 0 \\\\\n", 24 | "&\\text{Homogenized Behavior:} \\quad \\int_{\\Omega_{\\text{eff}}} \\nabla \\cdot (\\mathbf{C}_{\\text{eff}} : \\boldsymbol{\\varepsilon}_{\\text{eff}}) \\cdot \\boldsymbol{\\phi}_{\\text{eff}} \\,d\\Omega_{\\text{eff}} = 0\n", 25 | "\\end{align*}\n", 26 | "$$" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/laminate_plate_bending.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "01cea6e9", 6 | "metadata": {}, 7 | "source": [ 8 | "# Laminate Plate Bending\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Equilibrium:} \\quad \\nabla \\cdot \\boldsymbol{\\sigma} + \\mathbf{b} = \\mathbf{0} \\\\\n", 15 | "&\\text{Constitutive Relation:} \\quad \\boldsymbol{\\sigma} = \\mathbf{D} : \\boldsymbol{\\varepsilon} \\\\\n", 16 | "&\\text{Kinematics:} \\quad \\boldsymbol{\\varepsilon} = \\frac{1}{2}\\left(\\nabla \\mathbf{u} + (\\nabla \\mathbf{u})^T\\right) \\\\\n", 17 | "&\\text{Compatibility:} \\quad \\nabla \\times \\nabla \\times \\mathbf{u} = \\mathbf{0}\n", 18 | "\\end{align*}\n", 19 | "$$\n", 20 | "\n", 21 | "Weak Formulation:\n", 22 | "\n", 23 | "$$\n", 24 | "\\begin{align*}\n", 25 | "&\\int_{\\Omega} \\left(\\boldsymbol{\\sigma} : \\boldsymbol{\\varepsilon} + \\mathbf{b} \\cdot \\mathbf{u}\\right) \\,d\\Omega = 0\n", 26 | "\\end{align*}\n", 27 | "$$\n" 28 | ] 29 | } 30 | ], 31 | "metadata": {}, 32 | "nbformat": 4, 33 | "nbformat_minor": 5 34 | } 35 | -------------------------------------------------------------------------------- /chapter5/material-science/multi-material_simulation_in_material_jetting.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "92c94e77", 6 | "metadata": {}, 7 | "source": [ 8 | "# Multi-Material Simulation in Material Jetting\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Mass Transport:} \\quad \\frac{\\partial c_i}{\\partial t} + \\nabla \\cdot (\\mathbf{v} c_i) = 0 \\\\\n", 15 | "&\\text{Thermal Simulation:} \\quad \\rho c \\frac{\\partial T}{\\partial t} - \\nabla \\cdot (k \\nabla T) = Q\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\int_{\\Omega} \\left(\\frac{\\partial c_i}{\\partial t} \\phi_i + \\nabla \\cdot (\\mathbf{v} c_i) \\phi_i\\right) \\,d\\Omega = 0 \\\\\n", 24 | "&\\int_{\\Omega} \\left(\\rho c \\frac{\\partial T}{\\partial t} \\phi + k \\nabla T \\cdot \\nabla \\phi - Q \\phi\\right) \\,d\\Omega = 0\n", 25 | "\\end{align*}\n", 26 | "$$" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/piezoelectric_material.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b9324442", 6 | "metadata": {}, 7 | "source": [ 8 | "# Piezoelectric Material\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Mechanical Deformation:} \\quad \\rho \\frac{\\partial^2 \\mathbf{u}}{\\partial t^2} - \\nabla \\cdot (\\boldsymbol{\\sigma}) = \\mathbf{0} \\\\\n", 15 | "&\\text{Piezoelectricity:} \\quad \\nabla \\cdot \\mathbf{D} = \\rho_e, \\quad \\frac{\\partial \\mathbf{D}}{\\partial t} = \\mathbf{d} \\frac{\\partial T}{\\partial t}\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Mechanical Deformation:} \\quad \\int_{\\Omega} \\rho \\frac{\\partial^2 \\mathbf{u}}{\\partial t^2} \\cdot \\mathbf{v} \\,d\\Omega - \\int_{\\Omega} \\nabla \\cdot (\\boldsymbol{\\sigma}) \\cdot \\mathbf{v} \\,d\\Omega = 0 \\\\\n", 24 | "&\\text{Piezoelectricity:} \\quad \\int_{\\Omega} \\nabla \\cdot \\mathbf{D} \\phi \\,d\\Omega = \\int_{\\Omega} \\rho_e \\phi \\,d\\Omega, \\quad \\int_{\\Omega} \\frac{\\partial \\mathbf{D}}{\\partial t} \\cdot \\boldsymbol{\\psi} \\,d\\Omega \\\\\n", 25 | "&\\quad = \\int_{\\Omega} \\mathbf{d} \\frac{\\partial T}{\\partial t} \\cdot \\boldsymbol{\\psi} \\,d\\Omega\n", 26 | "\\end{align*}\n", 27 | "$$\n" 28 | ] 29 | } 30 | ], 31 | "metadata": {}, 32 | "nbformat": 4, 33 | "nbformat_minor": 5 34 | } 35 | -------------------------------------------------------------------------------- /chapter5/material-science/residual_stress_simulation_in_selective_laser_melting.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "0490d903", 6 | "metadata": {}, 7 | "source": [ 8 | "# Residual Stress Simulation in Selective Laser Melting (SLM)\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Mechanical Deformation:} \\quad \\nabla \\cdot \\boldsymbol{\\sigma} = \\mathbf{0} \\\\\n", 15 | "&\\text{Thermal Simulation:} \\quad \\rho c \\frac{\\partial T}{\\partial t} - \\nabla \\cdot (k \\nabla T) = Q\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\int_{\\Omega} \\left(\\nabla \\cdot \\boldsymbol{\\sigma} \\cdot \\boldsymbol{\\varepsilon} + \\nabla \\cdot (k \\nabla T) \\phi - Q \\phi\\right) \\,d\\Omega = 0\n", 24 | "\\end{align*}\n", 25 | "$$" 26 | ] 27 | } 28 | ], 29 | "metadata": {}, 30 | "nbformat": 4, 31 | "nbformat_minor": 5 32 | } 33 | -------------------------------------------------------------------------------- /chapter5/material-science/structural_simulation_in_fused_filament_fabrication.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9a8a67a1", 6 | "metadata": {}, 7 | "source": [ 8 | "# Structural Simulation in Fused Filament Fabrication (FFF)\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Mechanical Deformation:} \\quad \\rho \\frac{\\partial^2 \\mathbf{u}}{\\partial t^2} - \\nabla \\cdot (\\boldsymbol{\\sigma}) = \\mathbf{0} \\\\\n", 15 | "&\\text{Constitutive Relation:} \\quad \\boldsymbol{\\sigma} = \\mathbf{D} : \\boldsymbol{\\varepsilon}\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\int_{\\Omega} \\left(\\rho \\frac{\\partial^2 \\mathbf{u}}{\\partial t^2} \\cdot \\mathbf{v} - \\nabla \\cdot (\\boldsymbol{\\sigma}) \\cdot \\mathbf{v}\\right) \\,d\\Omega = 0\n", 24 | "\\end{align*}\n", 25 | "$$" 26 | ] 27 | } 28 | ], 29 | "metadata": {}, 30 | "nbformat": 4, 31 | "nbformat_minor": 5 32 | } 33 | -------------------------------------------------------------------------------- /chapter5/material-science/thermal_conductivity_of_composite_materials.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "2822050c", 6 | "metadata": {}, 7 | "source": [ 8 | "# Thermal Conductivity of Composite Materials\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Microstructural Behavior:} \\quad \\nabla \\cdot (\\mathbf{k}_{\\text{micro}} \\nabla T_{\\text{micro}}) = 0 \\\\\n", 15 | "&\\text{Homogenized Behavior:} \\quad \\nabla \\cdot (\\mathbf{k}_{\\text{eff}} \\nabla T_{\\text{eff}}) = 0\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\text{Microstructural Behavior:} \\quad \\int_{\\Omega_{\\text{micro}}} \\nabla \\cdot (\\mathbf{k}_{\\text{micro}} \\nabla T_{\\text{micro}}) \\phi_{\\text{micro}} \\,d\\Omega_{\\text{micro}} = 0 \\\\\n", 24 | "&\\text{Homogenized Behavior:} \\quad \\int_{\\Omega_{\\text{eff}}} \\nabla \\cdot (\\mathbf{k}_{\\text{eff}} \\nabla T_{\\text{eff}}) \\phi_{\\text{eff}} \\,d\\Omega_{\\text{eff}} = 0\n", 25 | "\\end{align*}\n", 26 | "$$\n" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/material-science/thermal_simulation_in_powder_bed_fusion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "5e7f6e9e", 6 | "metadata": {}, 7 | "source": [ 8 | "# Thermal Simulation in Powder Bed Fusion (PBF)\n", 9 | "\n", 10 | "Mathematical Model:\n", 11 | "\n", 12 | "$$\n", 13 | "\\begin{align*}\n", 14 | "&\\text{Heat Conduction:} \\quad \\rho c \\frac{\\partial T}{\\partial t} - \\nabla \\cdot (k \\nabla T) = Q \\\\\n", 15 | "&\\text{Melting and Solidification:} \\quad \\rho_l L \\frac{\\partial \\phi}{\\partial t} = H \\nabla \\cdot \\left(\\frac{\\nabla T}{\\lVert \\nabla T \\rVert}\\right)\n", 16 | "\\end{align*}\n", 17 | "$$\n", 18 | "\n", 19 | "Weak Formulation:\n", 20 | "\n", 21 | "$$\n", 22 | "\\begin{align*}\n", 23 | "&\\int_{\\Omega} \\left(\\rho c \\frac{\\partial T}{\\partial t} \\phi + k \\nabla T \\cdot \\nabla \\phi - Q \\phi\\right) \\,d\\Omega = 0 \\\\\n", 24 | "&\\int_{\\Omega} \\left(\\rho_l L \\frac{\\partial \\phi}{\\partial t} - H \\nabla \\cdot \\left(\\frac{\\nabla T}{\\lVert \\nabla T \\rVert}\\right) \\phi\\right) \\,d\\Omega = 0\n", 25 | "\\end{align*}\n", 26 | "$$" 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 5 33 | } 34 | -------------------------------------------------------------------------------- /chapter5/mhd.md: -------------------------------------------------------------------------------- 1 | # MHD 2 | 3 | 4 | In magnetohydrodynamics (MHD), finite element analysis can be applied to solve a variety of problems related to the behavior of electrically conducting fluids (plasmas or liquid metals) in the presence of magnetic fields. Here are some common problems in magnetohydrodynamics that can be addressed using finite element methods. 5 | 6 | Finite element analysis provides a powerful and flexible framework for addressing these complex problems in magnetohydrodynamics by discretizing the governing equations and solving them numerically. The specific application will determine the details of the problem setup and the required numerical techniques. 7 | 8 | ## MHD Equations 9 | 10 | Magnetohydrodynamics (MHD) is a branch of physics and fluid dynamics that studies the magnetic properties and behavior of electrically conducting fluids, such as plasmas, liquid metals, and saltwater. The MHD equations describe the coupled interactions between the magnetic field, fluid flow, and electric current. Here are the mathematical models for the MHD equations: 11 | 12 | 1. MHD Continuity Equation: 13 | $ 14 | \frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \mathbf{v}) = 0 15 | $ 16 | where: 17 | - $\rho$ is the fluid density, 18 | - $\mathbf{v}$ is the fluid velocity. 19 | 20 | 2. MHD Momentum Equation: 21 | $ 22 | \rho \frac{D\mathbf{v}}{Dt} = -\nabla p + \rho \mathbf{g} + \nabla \cdot \boldsymbol{\tau} + \mathbf{J} \times \mathbf{B} 23 | $ 24 | where: 25 | - $\frac{D\mathbf{v}}{Dt}$ is the material derivative of velocity, 26 | - $p$ is the pressure, 27 | - $\mathbf{g}$ is the gravitational acceleration, 28 | - $\boldsymbol{\tau}$ is the stress tensor, 29 | - $\mathbf{J}$ is the current density, 30 | - $\mathbf{B}$ is the magnetic field. 31 | 32 | 3. MHD Induction Equation: 33 | $ 34 | \frac{\partial \mathbf{B}}{\partial t} = \nabla \times (\mathbf{v} \times \mathbf{B} - \eta \nabla \times \mathbf{B}) 35 | $ 36 | where: 37 | - $\eta$ is the magnetic diffusivity. 38 | 39 | 4. MHD Ohm's Law: 40 | $ 41 | \mathbf{J} = \sigma (\mathbf{E} + \mathbf{v} \times \mathbf{B}) 42 | $ 43 | where: 44 | - $\sigma$ is the electrical conductivity, 45 | - $\mathbf{E}$ is the electric field. 46 | 47 | 5. MHD Energy Equation: 48 | $ 49 | \rho C_p \frac{DT}{Dt} = -p \nabla \cdot \mathbf{v} + \nabla \cdot (k \nabla T) + \frac{1}{\sigma}(\mathbf{J} \cdot \mathbf{E}) 50 | $ 51 | where: 52 | - $C_p$ is the specific heat at constant pressure, 53 | - $T$ is the temperature, 54 | - $k$ is the thermal conductivity. 55 | 56 | These equations, when solved together with appropriate boundary conditions, describe the behavior of magnetized fluids in the presence of electric and magnetic fields. Keep in mind that the specific form of these equations may vary based on the assumptions made and the type of fluid being considered (e.g., ideal MHD vs. resistive MHD). 57 | -------------------------------------------------------------------------------- /chapter5/mhd/astrophysical_dynamo_in_a_stellar_interior.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "cef04089", 6 | "metadata": {}, 7 | "source": [ 8 | "# Astrophysical Dynamo in a Stellar Interior\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a portion of the interior of a star.\n", 12 | "\n", 13 | "Boundary Conditions:\n", 14 | "- Insulated boundaries.\n", 15 | "\n", 16 | "Initial Conditions:\n", 17 | "- Seed magnetic field and temperature distribution.\n", 18 | "\n", 19 | "Dynamo Term:\n", 20 | "- Consider the combined effects of convection and rotation.\n", 21 | "\n", 22 | "These test cases provide a starting point for simulating MHD Dynamo Theory. Actual applications may involve more complex geometries, additional physical effects, and tailored boundary conditions based on specific scenarios. Dynamo theory often involves studying the evolution of magnetic fields over time and understanding the mechanisms that amplify and sustain magnetic fields in astrophysical and laboratory plasmas.\n", 23 | "\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "metadata": {}, 29 | "nbformat": 4, 30 | "nbformat_minor": 5 31 | } 32 | -------------------------------------------------------------------------------- /chapter5/mhd/ferrofluid_damper_in_mechanical_system.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9b8755c0", 6 | "metadata": {}, 7 | "source": [ 8 | "# Ferrofluid Damper in Mechanical System\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a mechanical system with a rotating component and a ferrofluid damper.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a simplified mesh representing the mechanical system.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Simulate the rotation of the mechanical component.\n", 18 | "- Introduce ferrofluid within the damper.\n", 19 | "- Apply an external magnetic field to control the damping effect.\n", 20 | "\n", 21 | "Initial Conditions:\n", 22 | "- Specify the initial position and velocity of the rotating component.\n", 23 | "- Initialize the distribution of ferrofluid within the damper.\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "metadata": {}, 29 | "nbformat": 4, 30 | "nbformat_minor": 5 31 | } 32 | -------------------------------------------------------------------------------- /chapter5/mhd/ferrofluid_flow_in_a_microfluidic_device.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ad0161b9", 6 | "metadata": {}, 7 | "source": [ 8 | "# Ferrofluid Flow in a Microfluidic Device\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a microfluidic channel filled with a ferrofluid.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a mesh representing the microchannel geometry.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Simulate fluid flow driven by pressure or electrokinetic forces.\n", 18 | "- Apply an external magnetic field to control ferrofluid motion.\n", 19 | "- Implement no-slip conditions at the channel walls.\n", 20 | "\n", 21 | "Initial Conditions:\n", 22 | "- Introduce a specified initial distribution of ferrofluid within the channel.\n", 23 | "\n" 24 | ] 25 | } 26 | ], 27 | "metadata": {}, 28 | "nbformat": 4, 29 | "nbformat_minor": 5 30 | } 31 | -------------------------------------------------------------------------------- /chapter5/mhd/magnetic_fluid_actuator_in_valve_control.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "95b4b8a4", 6 | "metadata": {}, 7 | "source": [ 8 | "# Magnetic Fluid Actuator in Valve Control\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a fluid control system with a valve actuated by a magnetic fluid.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a mesh representing the fluid channels and the magnetic fluid chamber.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Simulate fluid flow through the control system.\n", 18 | "- Model the actuation of the valve using a magnetic fluid.\n", 19 | "- Apply external magnetic fields to control the valve opening/closing.\n", 20 | "\n", 21 | "Initial Conditions:\n", 22 | "- Specify the initial fluid pressure and flow conditions.\n", 23 | "- Initialize the distribution of magnetic fluid within the actuator.\n", 24 | "\n", 25 | "These test cases provide a starting point for simulating Magnetic Fluid Dynamics in engineering using the Finite Element Method. Considerations include the interaction between fluid dynamics, magnetic fields, and the unique properties of ferrofluids in various engineering applications.\n", 26 | "\n", 27 | "\n", 28 | "\n", 29 | "\n" 30 | ] 31 | } 32 | ], 33 | "metadata": {}, 34 | "nbformat": 4, 35 | "nbformat_minor": 5 36 | } 37 | -------------------------------------------------------------------------------- /chapter5/mhd/magnetic_targeting_in_a_blood_vessel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "49fb7a4a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Magnetic Targeting in a Blood Vessel\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a section of a blood vessel.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a realistic vascular geometry mesh or a simplified representation.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Simulate blood flow using MHD principles.\n", 18 | "- Introduce drug-carrying particles with specified initial conditions.\n", 19 | "- Apply external magnetic fields to guide particles.\n", 20 | "\n", 21 | "Initial Conditions:\n", 22 | "- Set up an initial blood flow profile.\n", 23 | "- Inject drug-carrying particles into the bloodstream.\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "metadata": {}, 29 | "nbformat": 4, 30 | "nbformat_minor": 5 31 | } 32 | -------------------------------------------------------------------------------- /chapter5/mhd/magnetic_targeting_in_the_eye_for_retinal_diseases.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "022ed831", 6 | "metadata": {}, 7 | "source": [ 8 | "# Magnetic Targeting in the Eye for Retinal Diseases\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model the vitreous humor in the eye.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a mesh representing the vitreous humor.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Simulate fluid dynamics within the vitreous humor.\n", 18 | "- Release drug-carrying particles near the retina.\n", 19 | "- Apply external magnetic fields for precise targeting.\n", 20 | "\n", 21 | "Initial Conditions:\n", 22 | "- Set up initial conditions for the vitreous humor.\n", 23 | "- Release drug-carrying particles from a specific location.\n", 24 | "\n", 25 | "These test cases provide a starting point for simulating Magnetic Drug Targeting using the Finite Element Method. Considerations include the choice of mesh, fluid dynamics simulation, and the incorporation of magnetic fields for guiding drug-carrying particles to specific targets within the body. The models should be adapted based on the specific characteristics of the targeted tissue and the drug delivery system.\n", 26 | "\n", 27 | "\n", 28 | "\n", 29 | "\n" 30 | ] 31 | } 32 | ], 33 | "metadata": {}, 34 | "nbformat": 4, 35 | "nbformat_minor": 5 36 | } 37 | -------------------------------------------------------------------------------- /chapter5/mhd/magnetic_targeting_in_tumor_tissue.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "75638d63", 6 | "metadata": {}, 7 | "source": [ 8 | "# Magnetic Targeting in Tumor Tissue\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a tumor tissue environment.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a mesh representing the tumor and surrounding tissue.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Simulate interstitial fluid flow within the tumor.\n", 18 | "- Release drug-carrying particles within the tumor.\n", 19 | "- Apply external magnetic fields for targeting.\n", 20 | "\n", 21 | "Initial Conditions:\n", 22 | "- Establish initial conditions for the tumor environment.\n", 23 | "- Release drug-carrying particles from a source point.\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "metadata": {}, 29 | "nbformat": 4, 30 | "nbformat_minor": 5 31 | } 32 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd-astrophysics.md: -------------------------------------------------------------------------------- 1 | # MHD Astrophysics 2 | 3 | ## Mathematical Models 4 | 5 | 1. MHD Continuity Equation: 6 | $$ 7 | \frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \mathbf{v}) = 0 8 | $$ 9 | where $\rho$ is the fluid density, and $\mathbf{v}$ is the fluid velocity. 10 | 11 | 2. MHD Momentum Equation: 12 | $$ 13 | \rho \frac{D\mathbf{v}}{Dt} = -\nabla p + \rho \mathbf{g} + \nabla \cdot \boldsymbol{\tau} + \mathbf{J} \times \mathbf{B} + \nu \nabla^2 \mathbf{v} 14 | $$ 15 | incorporating the viscous term ($\nu \nabla^2 \mathbf{v}$) for fluid viscosity. 16 | 17 | 3. MHD Induction Equation: 18 | $$ 19 | \frac{\partial \mathbf{B}}{\partial t} = \nabla \times (\mathbf{v} \times \mathbf{B} - \eta \nabla \times \mathbf{B}) 20 | $$ 21 | where $\eta$ is the magnetic diffusivity. 22 | 23 | 4. MHD Ohm's Law: 24 | $$ 25 | \mathbf{J} = \sigma (\mathbf{E} + \mathbf{v} \times \mathbf{B}) 26 | $$ 27 | with $\sigma$ as the electrical conductivity and $\mathbf{E}$ as the electric field. 28 | 29 | 5. MHD Energy Equation: 30 | $$ 31 | \rho C_p \frac{DT}{Dt} = -p \nabla \cdot \mathbf{v} + \nabla \cdot (k \nabla T) + \frac{1}{\sigma}(\mathbf{J} \cdot \mathbf{E}) 32 | $$ 33 | including heat conduction ($k \nabla T$) and Joule heating ($\frac{1}{\sigma}(\mathbf{J} \cdot \mathbf{E})$) terms. 34 | 35 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd-drug-targeting.md: -------------------------------------------------------------------------------- 1 | # Magnetic Drug Targeting 2 | 3 | Magnetic Drug Targeting involves the use of magnetic fields to guide drug-carrying particles to a specific target within the body. This application combines principles of magnetohydrodynamics (MHD) with drug delivery. Below are the mathematical models and example test cases for Magnetic Drug Targeting: 4 | 5 | ## Mathematical Models 6 | 7 | 1. MHD Continuity Equation: 8 | $$ 9 | \frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \mathbf{v}) = 0 10 | $$ 11 | where $\rho$ is the fluid density, and $\mathbf{v}$ is the fluid velocity. 12 | 13 | 2. MHD Momentum Equation: 14 | $$ 15 | \rho \frac{D\mathbf{v}}{Dt} = -\nabla p + \rho \mathbf{g} + \nabla \cdot \boldsymbol{\tau} + \mathbf{J} \times \mathbf{B} + \nu \nabla^2 \mathbf{v} 16 | $$ 17 | incorporating the viscous term ($\nu \nabla^2 \mathbf{v}$) for fluid viscosity. 18 | 19 | 3. Magnetic Particle Motion Equation: 20 | $$ 21 | m_p \frac{d\mathbf{u}_p}{dt} = \mathbf{F}_p + \mathbf{F}_{\text{magnetic}} 22 | $$ 23 | where $m_p$ is the particle mass, $\mathbf{u}_p$ is the particle velocity, $\mathbf{F}_p$ is the sum of external forces, and $\mathbf{F}_{\text{magnetic}}$ is the magnetic force. 24 | 25 | 4. Magnetic Force Equation: 26 | $$ 27 | \mathbf{F}_{\text{magnetic}} = \nabla (\mathbf{m} \cdot \mathbf{B}) 28 | $$ 29 | where $\mathbf{m}$ is the magnetic moment of the drug-carrying particle. 30 | 31 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd-dynamo.md: -------------------------------------------------------------------------------- 1 | # MHD Dynamo Theory 2 | 3 | ## Mathematical Models 4 | 5 | 1. MHD Continuity Equation: 6 | $$ 7 | \frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \mathbf{v}) = 0 8 | $$ 9 | where $\rho$ is the fluid density, and $\mathbf{v}$ is the fluid velocity. 10 | 11 | 2. MHD Momentum Equation: 12 | $$ 13 | \rho \frac{D\mathbf{v}}{Dt} = -\nabla p + \rho \mathbf{g} + \nabla \cdot \boldsymbol{\tau} + \mathbf{J} \times \mathbf{B} + \nu \nabla^2 \mathbf{v} 14 | $$ 15 | incorporating the viscous term ($\nu \nabla^2 \mathbf{v}$) for fluid viscosity. 16 | 17 | 3. MHD Induction Equation: 18 | $$ 19 | \frac{\partial \mathbf{B}}{\partial t} = \nabla \times (\mathbf{v} \times \mathbf{B} - \eta \nabla \times \mathbf{B}) 20 | $$ 21 | where $\eta$ is the magnetic diffusivity. 22 | 23 | 4. MHD Ohm's Law: 24 | $$ 25 | \mathbf{J} = \sigma (\mathbf{E} + \mathbf{v} \times \mathbf{B}) 26 | $$ 27 | with $\sigma$ as the electrical conductivity and $\mathbf{E}$ as the electric field. 28 | 29 | 5. MHD Dynamo Equation: 30 | $$ 31 | \frac{\partial \mathbf{B}}{\partial t} = \nabla \times (\mathbf{v} \times \mathbf{B} - \eta \nabla \times \mathbf{B} + \alpha \mathbf{B}) 32 | $$ 33 | introducing the dynamo term ($\alpha \mathbf{B}$) representing the generation of magnetic field. 34 | 35 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd-fluid-dynamics.md: -------------------------------------------------------------------------------- 1 | # Magnetic Fluid Dynamics in Engineering 2 | 3 | Magnetic Fluid Dynamics (MFD) in engineering involves the study of the behavior of ferrofluids or magnetizable fluids under the influence of magnetic fields. These fluids are colloidal suspensions of ferromagnetic or superparamagnetic nanoparticles in a carrier liquid. The behavior of such fluids is influenced by both fluid dynamics and magnetic interactions. Below are the mathematical models and example test cases for Magnetic Fluid Dynamics in engineering: 4 | 5 | ## Mathematical Models 6 | 7 | 1. MHD Continuity Equation: 8 | $$ 9 | \frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \mathbf{v}) = 0 10 | $$ 11 | where $\rho$ is the fluid density, and $\mathbf{v}$ is the fluid velocity. 12 | 13 | 2. MHD Momentum Equation: 14 | $$ 15 | \rho \frac{D\mathbf{v}}{Dt} = -\nabla p + \rho \mathbf{g} + \nabla \cdot \boldsymbol{\tau} + \mathbf{J} \times \mathbf{B} + \nu \nabla^2 \mathbf{v} 16 | $$ 17 | incorporating the viscous term ($\nu \nabla^2 \mathbf{v}$) for fluid viscosity. 18 | 19 | 3. Magnetic Induction Equation: 20 | $$ 21 | \frac{\partial \mathbf{B}}{\partial t} = \nabla \times (\mathbf{v} \times \mathbf{B} - \eta \nabla \times \mathbf{B}) 22 | $$ 23 | where $\mathbf{B}$ is the magnetic field, and $\eta$ is the magnetic diffusivity. 24 | 25 | 4. Magnetic Force Equation: 26 | $$ 27 | \mathbf{F}_{\text{magnetic}} = \nabla (\mathbf{m} \cdot \mathbf{B}) 28 | $$ 29 | where $\mathbf{m}$ is the magnetic moment of the ferrofluid. 30 | 31 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd-fusion.md: -------------------------------------------------------------------------------- 1 | # MHD in Nuclear Fusion -------------------------------------------------------------------------------- /chapter5/mhd/mhd-heat-transfer.md: -------------------------------------------------------------------------------- 1 | # MHD Heat Transfer 2 | 3 | Magnetohydrodynamics (MHD) Heat Transfer involves the study of thermal phenomena in electrically conducting fluids in the presence of magnetic fields. This interdisciplinary field finds applications in various scenarios, from astrophysical environments to industrial processes. In MHD heat transfer, the interaction between fluid flow, magnetic fields, and heat transfer processes is considered. Below are the mathematical models governing MHD heat transfer, along with a brief description. 4 | 5 | ## MHD Heat Transfer Equations 6 | 7 | The MHD heat transfer equations are an extension of the Magnetohydrodynamics equations, incorporating heat transfer terms. The fundamental equations are as follows: 8 | 9 | 1. MHD Continuity Equation: 10 | $$ 11 | \frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \mathbf{v}) = 0 12 | $$ 13 | where $\rho$ is the fluid density, and $\mathbf{v}$ is the fluid velocity. 14 | 15 | 2. MHD Momentum Equation: 16 | $$ 17 | \rho \frac{D\mathbf{v}}{Dt} = -\nabla p + \rho \mathbf{g} + \nabla \cdot \boldsymbol{\tau} + \mathbf{J} \times \mathbf{B} + \nu \nabla^2 \mathbf{v} 18 | $$ 19 | incorporating the viscous term ($\nu \nabla^2 \mathbf{v}$) for fluid viscosity. 20 | 21 | 3. MHD Induction Equation: 22 | $$ 23 | \frac{\partial \mathbf{B}}{\partial t} = \nabla \times (\mathbf{v} \times \mathbf{B} - \eta \nabla \times \mathbf{B}) 24 | $$ 25 | where $\eta$ is the magnetic diffusivity. 26 | 27 | 4. MHD Ohm's Law: 28 | $$ 29 | \mathbf{J} = \sigma (\mathbf{E} + \mathbf{v} \times \mathbf{B}) 30 | $$ 31 | with $\sigma$ as the electrical conductivity and $\mathbf{E}$ as the electric field. 32 | 33 | 5. MHD Energy Equation: 34 | $$ 35 | \rho C_p \frac{DT}{Dt} = -p \nabla \cdot \mathbf{v} + \nabla \cdot (k \nabla T) + \frac{1}{\sigma}(\mathbf{J} \cdot \mathbf{E}) 36 | $$ 37 | including heat conduction ($k \nabla T$) and Joule heating ($\frac{1}{\sigma}(\mathbf{J} \cdot \mathbf{E})$) terms. 38 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd-material-processing.md: -------------------------------------------------------------------------------- 1 | # MHD Material Processing 2 | 3 | ## Mathematical Models 4 | 5 | 1. MHD Continuity Equation: 6 | $$ 7 | \frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \mathbf{v}) = 0 8 | $$ 9 | where $\rho$ is the fluid density, and $\mathbf{v}$ is the fluid velocity. 10 | 11 | 2. MHD Momentum Equation: 12 | $$ 13 | \rho \frac{D\mathbf{v}}{Dt} = -\nabla p + \rho \mathbf{g} + \nabla \cdot \boldsymbol{\tau} + \mathbf{J} \times \mathbf{B} + \nu \nabla^2 \mathbf{v} 14 | $$ 15 | incorporating the viscous term ($\nu \nabla^2 \mathbf{v}$) for fluid viscosity. 16 | 17 | 3. MHD Induction Equation: 18 | $$ 19 | \frac{\partial \mathbf{B}}{\partial t} = \nabla \times (\mathbf{v} \times \mathbf{B} - \eta \nabla \times \mathbf{B}) 20 | $$ 21 | where $\eta$ is the magnetic diffusivity. 22 | 23 | 4. MHD Ohm's Law: 24 | $$ 25 | \mathbf{J} = \sigma (\mathbf{E} + \mathbf{v} \times \mathbf{B}) 26 | $$ 27 | with $\sigma$ as the electrical conductivity and $\mathbf{E}$ as the electric field. 28 | 29 | 5. MHD Energy Equation: 30 | $$ 31 | \rho C_p \frac{DT}{Dt} = -p \nabla \cdot \mathbf{v} + \nabla \cdot (k \nabla T) + \frac{1}{\sigma}(\mathbf{J} \cdot \mathbf{E}) 32 | $$ 33 | including heat conduction ($k \nabla T$) and Joule heating ($\frac{1}{\sigma}(\mathbf{J} \cdot \mathbf{E})$) terms. 34 | 35 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd-stability-analysis.md: -------------------------------------------------------------------------------- 1 | # MHD Stability Analysis -------------------------------------------------------------------------------- /chapter5/mhd/mhd-turbulence.md: -------------------------------------------------------------------------------- 1 | # MHD Turbulence -------------------------------------------------------------------------------- /chapter5/mhd/mhd_accretion_disk_in_binary_star_system.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9832118d", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Accretion Disk in Binary Star System\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a 2D accretion disk in a binary star system.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a structured mesh for the 2D disk geometry.\n", 15 | "\n", 16 | "Boundary\n", 17 | "\n", 18 | "Conditions:\n", 19 | "- Inflow conditions representing accretion from the companion star.\n", 20 | "- Outflow conditions at the inner and outer disk boundaries.\n", 21 | "\n", 22 | "Initial Conditions:\n", 23 | "- Establish an initial density and temperature profile for the accretion disk.\n", 24 | "- Include a magnetic field configuration consistent with accretion processes.\n", 25 | "\n", 26 | "These test cases provide a starting point for simulating MHD Astrophysical phenomena using the Finite Element Method. The choice of mesh type and refinement, numerical methods, and solver settings will depend on the specific requirements and complexities of the astrophysical scenario being modeled. It's also important to consider adaptive mesh refinement strategies for capturing dynamic and localized features accurately.\n", 27 | "\n", 28 | "\n", 29 | "\n", 30 | "\n", 31 | "\n" 32 | ] 33 | } 34 | ], 35 | "metadata": {}, 36 | "nbformat": 4, 37 | "nbformat_minor": 5 38 | } 39 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_aluminum_electromagnetic_stirring.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e02cd3fb", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Aluminum Electromagnetic Stirring\n", 9 | "\n", 10 | "Domain:\n", 11 | "Consider a crucible containing molten aluminum.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a tetrahedral or hexahedral mesh for the 3D domain.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Apply electromagnetic stirring at the bottom of the crucible.\n", 18 | "- Specify heat extraction at the top surface.\n", 19 | "- Insulated conditions on the side walls.\n", 20 | "\n", 21 | "Initial Conditions:\n", 22 | "- Set up an initial temperature distribution for the molten aluminum.\n", 23 | "- Include initial magnetic field conditions.\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "metadata": {}, 29 | "nbformat": 4, 30 | "nbformat_minor": 5 31 | } 32 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_continuous_casting_of_steel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "cff635d2", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Continuous Casting of Steel\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a continuous casting process for steel.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a structured mesh for the 2D or 3D casting geometry.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Apply electromagnetic fields to control fluid flow during casting.\n", 18 | "- Implement heat extraction at the mold surface.\n", 19 | "- Consider insulated conditions on the sides.\n", 20 | "\n", 21 | "Initial Conditions:\n", 22 | "- Establish an initial temperature profile for the molten steel.\n", 23 | "- Include initial magnetic field conditions.\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "metadata": {}, 29 | "nbformat": 4, 30 | "nbformat_minor": 5 31 | } 32 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_dynamo_in_a_rotating_sphere.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "4d7906a1", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Dynamo in a Rotating Sphere\n", 9 | "\n", 10 | "Domain:\n", 11 | "Represent a rotating spherical fluid domain.\n", 12 | "\n", 13 | "Boundary Conditions:\n", 14 | "- No-slip conditions at the sphere's surface.\n", 15 | "- Allow for radial outflow.\n", 16 | "\n", 17 | "Initial Conditions:\n", 18 | "- Seed magnetic field and fluid velocity.\n", 19 | "\n", 20 | "Dynamo Term:\n", 21 | "- Incorporate a rotation-induced dynamo term.\n", 22 | "\n" 23 | ] 24 | } 25 | ], 26 | "metadata": {}, 27 | "nbformat": 4, 28 | "nbformat_minor": 5 29 | } 30 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_heat_transfer_in_a_cylindrical_fusion_reactor.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "95a8c391", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Heat Transfer in a Cylindrical Fusion Reactor\n", 9 | "\n", 10 | "Domain:\n", 11 | "Consider a cylindrical domain representing a fusion reactor.\n", 12 | "\n", 13 | "Boundary Conditions:\n", 14 | "- Inlet: Plasma injection with temperature $T = T_{\\text{inlet}}$.\n", 15 | "- Outlet: Outflow conditions.\n", 16 | "- Plasma-Metal Wall Interface: Insulated conditions for heat transfer, no-slip conditions for velocity, and conservation of magnetic field.\n", 17 | "\n", 18 | "Initial Conditions:\n", 19 | "- Initial plasma temperature and velocity distribution.\n", 20 | "\n" 21 | ] 22 | } 23 | ], 24 | "metadata": {}, 25 | "nbformat": 4, 26 | "nbformat_minor": 5 27 | } 28 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_heat_transfer_in_a_magma_convection_model.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a1b2face", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Heat Transfer in a Magma Convection Model\n", 9 | "\n", 10 | "Domain:\n", 11 | "A 2D representation of the Earth's mantle.\n", 12 | "\n", 13 | "Boundary Conditions:\n", 14 | "- Top Surface: Heat flux condition.\n", 15 | "- Bottom Surface: Insulated conditions.\n", 16 | "- Side Boundaries: No-slip conditions for velocity.\n", 17 | "\n", 18 | "Initial Conditions:\n", 19 | "- Initial temperature distribution representing the initial state of the mantle.\n", 20 | "\n", 21 | "These test cases provide a starting point for simulating MHD Heat Transfer. Actual applications may involve more complex geometries, additional physical effects, and tailored boundary conditions based on specific scenarios.\n", 22 | "\n", 23 | "\n", 24 | "\n" 25 | ] 26 | } 27 | ], 28 | "metadata": {}, 29 | "nbformat": 4, 30 | "nbformat_minor": 5 31 | } 32 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_heat_transfer_in_a_rectangular_domain.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a0477f2f", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Heat Transfer in a Rectangular Domain\n", 9 | "\n", 10 | "Domain:\n", 11 | "Consider a rectangular domain $[0, L_x] \\times [0, L_y]$.\n", 12 | "\n", 13 | "Boundary Conditions:\n", 14 | "- Inlet ($x=0$): Velocity $\\mathbf{v} = [V_0, 0]$, Magnetic field $\\mathbf{B} = [B_0, 0]$, Temperature $T = T_0$.\n", 15 | "- Outlet ($x=L_x$): Outflow conditions.\n", 16 | "- Top and Bottom: No-slip conditions for velocity, insulated conditions for heat transfer.\n", 17 | "- Magnetic Insulation: $\\frac{\\partial \\mathbf{B}}{\\partial n} = 0$ (normal component of magnetic field is conserved).\n", 18 | "\n", 19 | "Initial Conditions:\n", 20 | "- Initial fluid velocity $\\mathbf{v} = [0, 0]$, magnetic field $\\mathbf{B} = [B_0, 0]$, and uniform temperature $T = T_0$.\n", 21 | "\n" 22 | ] 23 | } 24 | ], 25 | "metadata": {}, 26 | "nbformat": 4, 27 | "nbformat_minor": 5 28 | } 29 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_kelvin-helmholtz_instability_in_magnetized_flows.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9a9297cd", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Kelvin-Helmholtz Instability in Magnetized Flows\n", 9 | "\n", 10 | "Study the stability of two fluid layers with different velocities and magnetic fields, leading to the development of the Kelvin-Helmholtz instability.\n", 11 | "\n", 12 | "## Mathematical Model\n", 13 | "\n", 14 | "1. MHD Equations:\n", 15 | "\n", 16 | "$$\n", 17 | " \\begin{align*}\n", 18 | " \\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v}) &= 0 \\\\\n", 19 | " \\rho \\frac{D\\mathbf{v}}{Dt} &= -\\nabla p + \\rho \\mathbf{g} + \\nabla \\cdot \\boldsymbol{\\tau} + \\mathbf{J} \\times \\mathbf{B} \\\\\n", 20 | " \\frac{\\partial \\mathbf{B}}{\\partial t} &= \\nabla \\times (\\mathbf{v} \\times \\mathbf{B} - \\eta \\nabla \\times \\mathbf{B}) \\\\\n", 21 | " \\mathbf{J} &= \\sigma (\\mathbf{E} + \\mathbf{v} \\times \\mathbf{B}) \\\\\n", 22 | " \\rho C_p \\frac{DT}{Dt} &= -p \\nabla \\cdot \\mathbf{v} + \\nabla \\cdot (k \\nabla T) + \\frac{1}{\\sigma}(\\mathbf{J} \\cdot \\mathbf{E})\n", 23 | " \\end{align*}\n", 24 | "$$\n", 25 | "\n", 26 | "2. Initial and Boundary Conditions:\n", 27 | "\n", 28 | "- Initial condition: $\\rho(\\mathbf{x},0) = \\rho_0, \\mathbf{v}(\\mathbf{x},0) = \\mathbf{v}_0, \\mathbf{B}(\\mathbf{x},0) = \\mathbf{B}_0, T(\\mathbf{x},0) = T_0$\n", 29 | "- Boundary conditions: Appropriate conditions on $\\mathbf{v}, \\mathbf{B}, T$ at the interfaces.\n", 30 | "\n" 31 | ] 32 | } 33 | ], 34 | "metadata": {}, 35 | "nbformat": 4, 36 | "nbformat_minor": 5 37 | } 38 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_metal_solidification_in_magnetic_field.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "4e4dd5f5", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Metal Solidification in Magnetic Field\n", 9 | "\n", 10 | "Domain:\n", 11 | "Consider a metal solidification process under the influence of a magnetic field.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a structured or unstructured mesh depending on the geometry.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Apply a magnetic field during solidification.\n", 18 | "- Specify heat extraction at the boundaries.\n", 19 | "\n", 20 | "Initial Conditions:\n", 21 | "- Set up initial temperature distribution for the molten metal.\n", 22 | "- Include initial magnetic field conditions.\n", 23 | "\n", 24 | "These test cases offer a starting point for simulating MHD Material Processing using the Finite Element Method. The specific choice of mesh, numerical methods, and solver settings will depend on the characteristics of the material processing scenario being modeled.\n", 25 | "\n", 26 | "\n", 27 | "\n", 28 | "\n" 29 | ] 30 | } 31 | ], 32 | "metadata": {}, 33 | "nbformat": 4, 34 | "nbformat_minor": 5 35 | } 36 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_rayleigh-taylor_instability_in_a_conducting_fluid.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f6345c71", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Rayleigh-Taylor Instability in a Conducting Fluid\n", 9 | "\n", 10 | "Investigate the stability of a conducting fluid layer subjected to a magnetic field, where the gravitational force acts opposite to the magnetic force, leading to the Rayleigh-Taylor instability.\n", 11 | "\n", 12 | "## Mathematical Model\n", 13 | "\n", 14 | "1. MHD Equations:\n", 15 | "\n", 16 | "$$\n", 17 | " \\begin{align*}\n", 18 | " \\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v}) &= 0 \\\\\n", 19 | " \\rho \\frac{D\\mathbf{v}}{Dt} &= -\\nabla p + \\rho \\mathbf{g} + \\nabla \\cdot \\boldsymbol{\\tau} + \\mathbf{J} \\times \\mathbf{B} \\\\\n", 20 | " \\frac{\\partial \\mathbf{B}}{\\partial t} &= \\nabla \\times (\\mathbf{v} \\times \\mathbf{B} - \\eta \\nabla \\times \\mathbf{B}) \\\\\n", 21 | " \\mathbf{J} &= \\sigma (\\mathbf{E} + \\mathbf{v} \\times \\mathbf{B}) \\\\\n", 22 | " \\rho C_p \\frac{DT}{Dt} &= -p \\nabla \\cdot \\mathbf{v} + \\nabla \\cdot (k \\nabla T) + \\frac{1}{\\sigma}(\\mathbf{J} \\cdot \\mathbf{E})\n", 23 | " \\end{align*}\n", 24 | "$$\n", 25 | "\n", 26 | "2. Initial and Boundary Conditions:\n", 27 | "\n", 28 | "- Initial condition: $\\rho(\\mathbf{x},0) = \\rho_0, \\mathbf{v}(\\mathbf{x},0) = \\mathbf{0}, \\mathbf{B}(\\mathbf{x},0) = \\mathbf{B}_0, T(\\mathbf{x},0) = T_0$\n", 29 | "- Boundary conditions: Appropriate conditions on $\\mathbf{v}, \\mathbf{B}, T$ at the fluid interfaces.\n", 30 | "\n" 31 | ] 32 | } 33 | ], 34 | "metadata": {}, 35 | "nbformat": 4, 36 | "nbformat_minor": 5 37 | } 38 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_solar_wind_simulation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "66f5b0d6", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Solar Wind Simulation\n", 9 | "\n", 10 | "Domain:\n", 11 | "Model a portion of the solar corona and solar wind.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a structured or unstructured mesh depending on the complexity of the geometry.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Inflow conditions at the base of the solar wind region.\n", 18 | "- Outflow conditions at the outer boundary.\n", 19 | "\n", 20 | "Initial Conditions:\n", 21 | "- Include initial solar magnetic field conditions.\n", 22 | "- Set up initial plasma parameters.\n", 23 | "\n" 24 | ] 25 | } 26 | ], 27 | "metadata": {}, 28 | "nbformat": 4, 29 | "nbformat_minor": 5 30 | } 31 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_stability_of_a_current-carrying_plasma_column.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "77efa5a1", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Stability of a Current-Carrying Plasma Column\n", 9 | "\n", 10 | "Examine the stability of a cylindrical plasma column carrying an electric current, interacting with an axial magnetic field, to understand the stability conditions for fusion confinement.\n", 11 | "\n", 12 | "## Mathematical Model\n", 13 | "\n", 14 | "1. MHD Equations:\n", 15 | "\n", 16 | "$$\n", 17 | " \\begin{align*}\n", 18 | " \\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v}) &= 0 \\\\\n", 19 | " \\rho \\frac{D\\mathbf{v}}{Dt} &= -\\nabla p + \\rho \\mathbf{g} + \\nabla \\cdot \\boldsymbol{\\tau} + \\mathbf{J} \\times \\mathbf{B} \\\\\n", 20 | " \\frac{\\partial \\mathbf{B}}{\\partial t} &= \\nabla \\times (\\mathbf{v} \\times \\mathbf{B} - \\eta \\nabla \\times \\mathbf{B}) \\\\\n", 21 | " \\mathbf{J} &= \\sigma (\\mathbf{E} + \\mathbf{v} \\times \\mathbf{B}) \\\\\n", 22 | " \\rho C_p \\frac{DT}{Dt} &= -p \\nabla \\cdot \\mathbf{v} + \\nabla \\cdot (k \\nabla T) + \\frac{1}{\\sigma}(\\mathbf{J} \\cdot \\mathbf{E})\n", 23 | " \\end{align*}\n", 24 | "$$\n", 25 | "\n", 26 | "2. Initial and Boundary Conditions:\n", 27 | "\n", 28 | "- Initial condition: $\\rho(\\mathbf{x},0) = \\rho_0, \\mathbf{v}(\\mathbf{x},0) = \\mathbf{0}, \\mathbf{B}(\\mathbf{x},0) = \\mathbf{B}_0, T(\\mathbf{x},0) = T_0$\n", 29 | "- Boundary conditions: Appropriate conditions on $\\mathbf{v}, \\mathbf{B}, T$ at the plasma boundary.\n", 30 | "\n", 31 | "\n", 32 | "\n", 33 | "\n" 34 | ] 35 | } 36 | ], 37 | "metadata": {}, 38 | "nbformat": 4, 39 | "nbformat_minor": 5 40 | } 41 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_star_formation_in_a_protostellar_cloud.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "8e089287", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Star Formation in a Protostellar Cloud\n", 9 | "\n", 10 | "Domain:\n", 11 | "Consider a 3D computational domain representing a protostellar cloud.\n", 12 | "\n", 13 | "Finite Element Mesh:\n", 14 | "Use a tetrahedral or hexahedral mesh for the 3D domain.\n", 15 | "\n", 16 | "Boundary Conditions:\n", 17 | "- Inflow boundary conditions representing the infall of material.\n", 18 | "- Outflow conditions at the outer boundary.\n", 19 | "\n", 20 | "Initial Conditions:\n", 21 | "- Set up an initial density and temperature distribution.\n", 22 | "- Include a small seed magnetic field perturbation.\n", 23 | "\n" 24 | ] 25 | } 26 | ], 27 | "metadata": {}, 28 | "nbformat": 4, 29 | "nbformat_minor": 5 30 | } 31 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_turbulence_in_accretion_disks.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "571e6c81", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Turbulence in Accretion Disks\n", 9 | "\n", 10 | "Study MHD turbulence in accretion disks around astrophysical objects, where magnetized flows lead to complex dynamics influencing mass accretion onto central objects.\n", 11 | "\n", 12 | "## Mathematical Model\n", 13 | "\n", 14 | "1. MHD Equations:\n", 15 | "\n", 16 | "$$\n", 17 | " \\begin{align*}\n", 18 | " \\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v}) &= 0 \\\\\n", 19 | " \\rho \\frac{D\\mathbf{v}}{Dt} &= -\\nabla p + \\rho \\mathbf{g} + \\nabla \\cdot \\boldsymbol{\\tau} + \\mathbf{J} \\times \\mathbf{B} + \\nu \\nabla^2 \\mathbf{v} \\\\\n", 20 | " \\frac{\\partial \\mathbf{B}}{\\partial t} &= \\nabla \\times (\\mathbf{v} \\times \\mathbf{B} - \\eta \\nabla \\times \\mathbf{B}) \\\\\n", 21 | " \\mathbf{J} &= \\sigma (\\mathbf{E} + \\mathbf{v} \\times \\mathbf{B}) \\\\\n", 22 | " \\rho C_p \\frac{DT}{Dt} &= -p \\nabla \\cdot \\mathbf{v} + \\nabla \\cdot (k \\nabla T) + \\frac{1}{\\sigma}(\\mathbf{J} \\cdot \\mathbf{E})\n", 23 | " \\end{align*}\n", 24 | "$$\n", 25 | "\n", 26 | "2. Initial and Boundary Conditions:\n", 27 | "- Initial condition: Conditions representing the initial state of the accretion disk.\n", 28 | "- Boundary conditions: Specify conditions at the inner and outer edges of the accretion disk." 29 | ] 30 | } 31 | ], 32 | "metadata": {}, 33 | "nbformat": 4, 34 | "nbformat_minor": 5 35 | } 36 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_turbulence_in_laboratory_plasmas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "fe34d34b", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Turbulence in Laboratory Plasmas\n", 9 | "\n", 10 | "Investigate turbulence in laboratory plasmas, where MHD interactions occur within controlled magnetic confinement devices such as tokamaks or stellarators.\n", 11 | "\n", 12 | "## Mathematical Model\n", 13 | "\n", 14 | "1. MHD Equations:\n", 15 | "\n", 16 | "$$\n", 17 | " \\begin{align*}\n", 18 | " \\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v}) &= 0 \\\\\n", 19 | " \\rho \\frac{D\\mathbf{v}}{Dt} &= -\\nabla p + \\rho \\mathbf{g} + \\nabla \\cdot \\boldsymbol{\\tau} + \\mathbf{J} \\times \\mathbf{B} + \\nu \\nabla^2 \\mathbf{v} \\\\\n", 20 | " \\frac{\\partial \\mathbf{B}}{\\partial t} &= \\nabla \\times (\\mathbf{v} \\times \\mathbf{B} - \\eta \\nabla \\times \\mathbf{B}) \\\\\n", 21 | " \\mathbf{J} &= \\sigma (\\mathbf{E} + \\mathbf{v} \\times \\mathbf{B}) \\\\\n", 22 | " \\rho C_p \\frac{DT}{Dt} &= -p \\nabla \\cdot \\mathbf{v} + \\nabla \\cdot (k \\nabla T) + \\frac{1}{\\sigma}(\\mathbf{J} \\cdot \\mathbf{E})\n", 23 | " \\end{align*}\n", 24 | "$$\n", 25 | "\n", 26 | "2. Initial and Boundary Conditions:\n", 27 | "\n", 28 | "- Initial condition: Conditions reflecting the initial state of the plasma.\n", 29 | "- Boundary conditions: Set appropriate conditions for the plasma confinement device.\n", 30 | "\n" 31 | ] 32 | } 33 | ], 34 | "metadata": {}, 35 | "nbformat": 4, 36 | "nbformat_minor": 5 37 | } 38 | -------------------------------------------------------------------------------- /chapter5/mhd/mhd_turbulence_in_solar_winds.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b3737827", 6 | "metadata": {}, 7 | "source": [ 8 | "# MHD Turbulence in Solar Winds\n", 9 | "\n", 10 | "Explore the turbulence in the solar wind, where the interaction between the solar magnetic field and the flow of charged particles leads to complex MHD turbulence phenomena.\n", 11 | "\n", 12 | "## Mathematical Model\n", 13 | "\n", 14 | "1. MHD Equations:\n", 15 | "\n", 16 | "$$\n", 17 | " \\begin{align*}\n", 18 | " \\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\mathbf{v}) &= 0 \\\\\n", 19 | " \\rho \\frac{D\\mathbf{v}}{Dt} &= -\\nabla p + \\rho \\mathbf{g} + \\nabla \\cdot \\boldsymbol{\\tau} + \\mathbf{J} \\times \\mathbf{B} + \\nu \\nabla^2 \\mathbf{v} \\\\\n", 20 | " \\frac{\\partial \\mathbf{B}}{\\partial t} &= \\nabla \\times (\\mathbf{v} \\times \\mathbf{B} - \\eta \\nabla \\times \\mathbf{B}) \\\\\n", 21 | " \\mathbf{J} &= \\sigma (\\mathbf{E} + \\mathbf{v} \\times \\mathbf{B}) \\\\\n", 22 | " \\rho C_p \\frac{DT}{Dt} &= -p \\nabla \\cdot \\mathbf{v} + \\nabla \\cdot (k \\nabla T) + \\frac{1}{\\sigma}(\\mathbf{J} \\cdot \\mathbf{E})\n", 23 | " \\end{align*}\n", 24 | "$$\n", 25 | "\n", 26 | "2. Initial and Boundary Conditions:\n", 27 | "- Initial condition: Appropriate conditions for solar wind parameters.\n", 28 | "- Boundary conditions: Consider inflow conditions at the solar corona and outflow conditions at the outer boundary." 29 | ] 30 | } 31 | ], 32 | "metadata": {}, 33 | "nbformat": 4, 34 | "nbformat_minor": 5 35 | } 36 | -------------------------------------------------------------------------------- /chapter5/mhd/simple_kinematic_dynamo_model.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7862dd84", 6 | "metadata": {}, 7 | "source": [ 8 | "# Simple Kinematic Dynamo Model\n", 9 | "\n", 10 | "Domain:\n", 11 | "Consider a 2D or 3D periodic domain.\n", 12 | "\n", 13 | "Boundary Conditions:\n", 14 | "- Periodic boundaries.\n", 15 | "\n", 16 | "Initial Conditions:\n", 17 | "- Small seed magnetic field perturbation.\n", 18 | "- Initially stationary fluid.\n", 19 | "\n", 20 | "Dynamo Term:\n", 21 | "- Choose a constant $\\alpha$ to represent the dynamo term.\n", 22 | "\n" 23 | ] 24 | } 25 | ], 26 | "metadata": {}, 27 | "nbformat": 4, 28 | "nbformat_minor": 5 29 | } 30 | -------------------------------------------------------------------------------- /chapter5/multiphysics.md: -------------------------------------------------------------------------------- 1 | # Multiphysics 2 | -------------------------------------------------------------------------------- /intro.md: -------------------------------------------------------------------------------- 1 | # Home 2 | 3 | *Author: Ahmed Ratnani* [^authors] 4 | 5 | Welcome to IGA-Python, a tutorial for Isogeometric Analysis using Python. 6 | 7 | ## TODO 8 | 9 | - Geometry and Meshes 10 | - More models 11 | - Visualization 12 | - GLT 13 | - Documentation using docstrings from gelato 14 | 15 | ```{tableofcontents} 16 | ``` 17 | 18 | [^authors]: Complete list of authors can be found here: https://github.com/pyccel/IGA-Python/blob/master/AUTHORS 19 | 20 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyccel/IGA-Python/148975c1a3e17c2cc8d3bac34a7b83966fcdbd5c/logo.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | wheel 2 | numpy 3 | jupyter-book 4 | sphinx-proof 5 | matplotlib 6 | pyccel 7 | ipykernel 8 | notebook 9 | nb-clean 10 | psydac @ git+https://github.com/pyccel/psydac.git@devel#egg=psydac 11 | 12 | -------------------------------------------------------------------------------- /requirements_ntbk.txt: -------------------------------------------------------------------------------- 1 | wheel 2 | numpy 3 | jupyter-book 4 | sphinx-proof 5 | matplotlib 6 | ipykernel 7 | notebook 8 | nb-clean 9 | myst_parser 10 | 11 | --------------------------------------------------------------------------------