@@ -434,23 +434,8 @@ label{nonlin:exer:1D:1pu2:fem:pde}
434434\end{equation}
435435!et
436436
437- % if FEM_BOOK:
438- !bsubex
439- Discretize (ref{nonlin:exer:1D:1pu2:fem:pde}) by a centered
440- finite difference method on a uniform mesh.
441- !esubex
442-
443- !bsubex
444- Discretize (ref{nonlin:exer:1D:1pu2:fem:pde}) by a finite
445- element method with P1 elements of equal length.
446- Use the Trapezoidal method to compute all integrals.
447- Set up the resulting matrix system in symbolic form such that the
448- equations can be compared with those in a).
449- !esubex
450- % else:
451437Discretize (ref{nonlin:exer:1D:1pu2:fem:pde}) by a centered
452438finite difference method on a uniform mesh.
453- % endif
454439
455440===== Problem: Linearize a 1D problem with a nonlinear coefficient =====
456441label{nonlin:exer:1D:1pu2:PicardNewton}
@@ -550,117 +535,6 @@ in each iteration, where $u$ is solution in the current iteration and
550535$u^{-}$ is the solution in the previous iteration.
551536!esubex
552537
553- % if FEM_BOOK:
554- ===== Problem: Integrate functions of finite element expansions =====
555- label{nonlin:exer:fu:fem:int}
556- file=fu_fem_int
557-
558- idx{`latex.codecogs.com` web site}
559- idx{online rendering of LaTeX formulas}
560-
561- We shall investigate integrals on the form
562-
563- !bt
564- \begin{equation}
565- \int_0^L f(\sum_ku_k\basphi_k(x))\basphi_i(x)\dx,
566- label{nonlin:exer:fu:fem:int:global}
567- \end{equation}
568- !et
569- where $\basphi_i(x)$ are P1 finite element basis functions and $u_k$
570- are unknown coefficients, more precisely the values of the unknown
571- function $u$ at nodes $\xno{k}$. We introduce a node numbering that
572- goes from left to right and also that all cells have
573- the same length $h$. Given $i$, the integral
574- only gets contributions from $[\xno{i-1},\xno{i+1}]$. On this
575- interval $\basphi_k(x)=0$ for $k<i-1$ and $k>i+1$, so only three
576- basis functions will contribute:
577-
578- !bt
579- \[
580- \sum_k u_k\basphi_k(x) = u_{i-1}\basphi_{i-1}(x) +
581- u_{i}\basphi_{i}(x) + u_{i+1}\basphi_{i+1}(x)\tp
582- \]
583- !et
584- The integral (ref{nonlin:exer:fu:fem:int:global}) now takes the
585- simplified form
586-
587- !bt
588- \[
589- \int_{\xno{i-1}}^{\xno{i+1}}
590- f(u_{i-1}\basphi_{i-1}(x) +
591- u_{i}\basphi_{i}(x) + u_{i+1}\basphi_{i+1}(x))\basphi_i(x)\dx\tp
592- \]
593- !et
594- Split this integral in two integrals over cell L (left),
595- $[\xno{i-1},\xno{i}]$, and cell R (right), $[\xno{i},\xno{i+1}]$. Over
596- cell L, $u$ simplifies to $u_{i-1}\basphi_{i-1} + u_{i}\basphi_{i}$
597- (since $\basphi_{i+1}=0$ on this cell), and over cell R, $u$
598- simplifies to $u_{i}\basphi_{i} + u_{i+1}\basphi_{i+1}$. Make a
599- `sympy` program that can compute the integral and write it out as a
600- difference equation. Give the $f(u)$ formula on the command line.
601- Try out $f(u)=u^2, \sin u, \exp u$.
602-
603- !bhint
604- Introduce symbols `u_i`, `u_im1`, and `u_ip1` for $u_i$, $u_{i-1}$,
605- and $u_{i+1}$, respectively, and similar symbols for $x_i$, $x_{i-1}$,
606- and $x_{i+1}$. Find formulas for the basis functions on each of the
607- two cells, make expressions for $u$ on the two cells, integrate over
608- each cell, expand the answer and simplify. You can ask `sympy` for
609- LaTeX code and render it either by creating a LaTeX document and
610- compiling it to a PDF document or by using
611- URL: "http://latex.codecogs.com" to display LaTeX formulas in a web
612- page. Here are some appropriate Python statements
613- for the latter purpose:
614-
615- !bc pycod
616- from sympy import *
617- ...
618- # expr_i holdes the integral as a sympy expression
619- latex_code = latex(expr_i, mode='plain')
620- # Replace u_im1 sympy symbol name by latex symbol u_{i-1}
621- latex_code = latex_code.replace('im1', '{i-1}')
622- # Replace u_ip1 sympy symbol name by latex symbol u_{i+1}
623- latex_code = latex_code.replace('ip1', '{i+1}')
624- # Escape (quote) latex_code so it can be sent as HTML text
625- import cgi
626- html_code = cgi.escape(latex_code)
627- # Make a file with HTML code for displaying the LaTeX formula
628- f = open('tmp.html', 'w')
629- # Include an image that can be clicked on to yield a new
630- # page with an interactive editor and display area where the
631- # formula can be further edited
632- text = """
633- <a href="http://www.codecogs.com/eqnedit.php?latex=%(html_code)s"
634- target="_blank">
635- <img src="http://latex.codecogs.com/gif.latex?%(html_code)s"
636- title="%(latex_code)s"/>
637- </a>
638- """ % vars()
639- f.write(text)
640- f.close()
641- !ec
642- The formula is displayed by loading `tmp.html` into a web browser.
643- !ehint
644-
645- ===== Problem: Finite elements for the 1D Bratu problem =====
646- label{nonlin:exer:1D:fu:discretize:fe}
647- file=nonlin_1D_Bratu_fe
648-
649- We address the same 1D Bratu problem as described in
650- Problem ref{nonlin:exer:1D:fu:discretize:fd}.
651-
652- !bsubex
653- Discretize (ref{nonlin:exer:1D:fu:discretize:fe}) by a finite element
654- method using a uniform mesh with P1 elements. Use a group
655- finite element method for the $e^u$ term.
656- !esubex
657-
658- !bsubex
659- Set up the nonlinear equations $F_i(u_0,u_1,\ldots,u_{N_x})=0$
660- from a). Calculate the associated Jacobian.
661- !esubex
662- % endif
663-
664538
665539===== Problem: Discretize a nonlinear 1D heat conduction PDE by finite differences =====
666540label{nonlin:exer:1D:heat:nonlinear:fdm}
@@ -709,78 +583,6 @@ Derive the matrix and right-hand side of a Newton method applied
709583to the discretized PDE in d).
710584!esubex
711585
712- % if FEM_BOOK:
713- ===== Exercise: Use different symbols for different approximations of the solution =====
714- label{nonlin:exer:dD:nonlinear:usymbols}
715- file=nonlin_heat_FE_usymbols
716-
717- The symbol $u$ has several meanings, depending on the context, as
718- briefly mentioned in Section ref{nonlin:alglevel:dD:fe}.
719- Go through the derivation of the Picard iteration method in
720- that section and use different symbols for all the different
721- approximations of $u$:
722-
723- * $\uex(\x,t)$ for the exact solution of the PDE problem
724- * $\uex(\x)^n$ for the exact solution after time discretization
725- * $u^n(\x)$ for the spatially discrete solution $\sum_jc_j\baspsi_j$
726- * $u^{n,k}$ for approximation in Picard/Newton iteration no $k$
727- to $u^n(\x)$
728-
729- ===== Exercise: Derive Picard and Newton systems from a variational form =====
730- label{nonlin:exer:dD:heat:nonlinear:c:a}
731- file=nonlin_heat_FE
732-
733- We study the multi-dimensional heat conduction PDE
734-
735- !bt
736- \[ \varrho c(T) T_t = \nabla\cdot (k(T)\nabla T)\]
737- !et
738- in a spatial domain $\Omega$, with a nonlinear Robin boundary condition
739-
740- !bt
741- \[ -k(T)\frac{\partial T}{\partial n} = h(T)(T-T_s(t)),\]
742- !et
743- at the boundary $\partial\Omega$.
744- The primary unknown is the temperature $T$, $\varrho$ is the density
745- of the solid material, $c(T)$ is the heat capacity, $k(T)$ is
746- the heat conduction, $h(T)$ is a heat transfer coefficient, and
747- $T_s(T)$ is a possibly time-dependent temperature of the surroundings.
748-
749- !bsubex
750- Use a Backward Euler or Crank-Nicolson time discretization and
751- derive the variational form for the spatial problem to be solved
752- at each time level.
753- !esubex
754-
755- !bsubex
756- Define a Picard iteration method from the variational form at
757- a time level.
758- !esubex
759-
760- !bsubex
761- Derive expressions for the matrix and the right-hand side of the
762- equation system that arises from applying Newton's method to
763- the variational form at a time level.
764- !esubex
765-
766- !bsubex
767- Apply the Backward Euler or Crank-Nicolson scheme in time first.
768- Derive a Newton method at the PDE level. Make a variational
769- form of the resulting PDE at a time level.
770- !esubex
771-
772- ===== Exercise: Derive algebraic equations for nonlinear 1D heat conduction =====
773- label{nonlin:exer:1D:heat:nonlinear:c:a}
774- file=nonlin_1D_heat_FE
775-
776- We consider the same problem as in Exercise ref{nonlin:exer:dD:heat:nonlinear:c:a}, but restricted to one space dimension: $\Omega = [0,L]$.
777- Simplify the boundary condition to $T_x=0$ (i.e., $h(T)=0$).
778- Use a uniform finite element mesh of P1 elements, the group
779- finite element method, and the Trapezoidal
780- rule for integration at the nodes to derive symbolic expressions for
781- the algebraic equations arising from this diffusion problem.
782- % endif
783-
784586===== Problem: Differentiate a highly nonlinear term =====
785587label{nonlin:exer:grad:pow:term}
786588file=nonlin_differentiate
0 commit comments