The accompanying Jupyter notebook can be obtained here 3_expressions
Expressions
In FEniCS, an Expression is a flexible and convenient way to define mathematical functions or expressions within the domain of interest. Expressions are often used to specify boundary conditions, source terms, initial conditions, or any other function needed in the formulation of the PDE problem.
The beauty of using Expressions lies in their simplicity and directness. Users can define an Expression using a concise mathematical expression, incorporating spatial coordinates and/or time variables. Additionally, FEniCS supports the use of elementary mathematical functions, mathematical constants, and custom-defined functions within Expressions.
Please visit the official documentation link provided to learn how to modify expressions. After familiarizing yourself with the process, return here to implement the changes and visualize the updated results.
https://hplgit.github.io/fenics-tutorial/pub/sphinx1/._ftut1003.html#index-28
Change this portion of the code to: 1. Make a 2D unit square mesh.
U = FunctionSpace(mesh, "CG", 1)
u_D = Constant(0.0)
boundary = CompiledSubDomain("on_boundary")
bc = DirichletBC(U, u_D, boundary)
u, v = TrialFunction(U), TestFunction(U)
a = inner(grad(u), grad(v)) * dx
Change this portion of the code to: 1. Change the forcing function to \(f(x) = x\) 2. Change the forcing function to \(f(x,y) = sin(\pi x)sin(\pi y)\)