Editing Fem-fenics
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
Package for solving Partial Differential Equations based on Fenics. | Package for solving Partial Differential Equations based on Fenics. | ||
== Tutorials == | == Tutorials == | ||
=== Poisson Equation === | === Poisson Equation === | ||
Here is a first example for the solution of the Poisson equation. | Here is a first example for the solution of the Poisson equation. | ||
The equation being solved is | The equation being solved is | ||
<div style="width: 100%;"> | <div style="width: 100%;"> | ||
<div style="float:left; width: 48%"> | <div style="float:left; width: 48%"> | ||
{{Code|Define Poisson problem | {{Code|Define Poisson problem|<syntaxhighlight lang="octave" style="font-size:13px"> | ||
pkg load fem-fenics msh | pkg load fem-fenics msh | ||
import_ufl_Problem ('Poisson') | |||
# Create mesh and define function space | # Create mesh and define function space | ||
Line 50: | Line 16: | ||
mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4)); | mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4)); | ||
# File Poisson.ufl | |||
# element = FiniteElement("Lagrange", triangle, 1) | |||
V = FunctionSpace('Poisson', mesh); | V = FunctionSpace('Poisson', mesh); | ||
Line 61: | Line 29: | ||
# Define variational problem | # Define variational problem | ||
# | # File Poisson.ufl | ||
# u = TrialFunction(element) | # u = TrialFunction(element) | ||
# v = TestFunction(element) | # v = TestFunction(element) | ||
Line 71: | Line 39: | ||
g = Expression ('g', @(x,y) sin (5.0 * x)); | g = Expression ('g', @(x,y) sin (5.0 * x)); | ||
# | # File Poisson.ufl | ||
# a = inner(grad(u), grad(v))*dx | # a = inner(grad(u), grad(v))*dx | ||
# L = f*v*dx + g*v*ds | # L = f*v*dx + g*v*ds | ||
a = BilinearForm ('Poisson' | a = BilinearForm ('Poisson', V); | ||
L = | L = Poisson_LinearForm ('Poisson', V, f, g); | ||
# Compute solution | # Compute solution | ||
Line 86: | Line 54: | ||
# Save solution in VTK format | # Save solution in VTK format | ||
save (u | save (u) | ||
# Plot solution | # Plot solution | ||
Line 95: | Line 63: | ||
</div> | </div> | ||
<div style="float:right; width: 48%"> | <div style="float:right; width: 48%"> | ||
{{Code|Define Poisson problem | {{Code|Define Poisson problem|<syntaxhighlight lang="python" style="font-size:13px"> | ||
from dolfin import * | from dolfin import * | ||
# Create mesh and define function space | |||
mesh = UnitSquareMesh(32, 32) | |||
V = FunctionSpace(mesh, "Lagrange", 1) | V = FunctionSpace(mesh, "Lagrange", 1) | ||
Line 131: | Line 90: | ||
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + | f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)") | ||
g = Expression("sin(5*x[0])") | g = Expression("sin(5*x[0])") | ||
Line 154: | Line 113: | ||
# Plot solution | # Plot solution | ||
plot(u, interactive=True) | plot(u, interactive=True) | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
</div> | </div> | ||
Line 766: | Line 118: | ||
<div style="clear:both"></div> | <div style="clear:both"></div> | ||
[[Category:OctaveForge]] | |||
[[Category:Packages]] | |||
[[Category: |