Fem-fenics: Difference between revisions

Jump to navigation Jump to search
361 bytes added ,  27 May 2014
→‎Mixed Formulation for Poisson Equation: Adapt the example to the ufl paradigm
(→‎Poisson Equation: Edited to show the ufl.m usage)
(→‎Mixed Formulation for Poisson Equation: Adapt the example to the ufl paradigm)
Line 162: Line 162:


=== Mixed Formulation for Poisson Equation ===
=== Mixed Formulation for Poisson Equation ===
In this example the Poisson equation is solved with a '''mixed approach''': the stable FE space obtained using Brezzi-Douglas-Marini polynomial of order 1 and Dicontinuos element of order 0 is used.
In this example the Poisson equation is solved with a '''mixed approach''': the stable FE space obtained using Brezzi-Douglas-Marini polynomial of order 1 and Discontinuos elements of order 0 is used.


<math>-\mathrm{div}\ ( \mathbf{\sigma} (x, y) ) ) = f (x, y) \qquad \mbox{ in } \Omega</math>
<math>-\mathrm{div}\ ( \mathbf{\sigma} (x, y) ) ) = f (x, y) \qquad \mbox{ in } \Omega</math>
Line 172: Line 172:
<math>(\sigma (x, y) )  \cdot \mathbf{n} = \sin (5x) \qquad \mbox{ on } \Gamma_N</math>
<math>(\sigma (x, y) )  \cdot \mathbf{n} = \sin (5x) \qquad \mbox{ on } \Gamma_N</math>


A complete description of the problem is avilable on the [http://fenicsproject.org/documentation/dolfin/1.2.0/python/demo/pde/mixed-poisson/python/documentation.html Fenics website.]
A complete description of the problem is available on the [http://fenicsproject.org/documentation/dolfin/1.2.0/python/demo/pde/mixed-poisson/python/documentation.html Fenics website.]
<div style="width: 100%;">
<div style="width: 100%;">
   <div style="float:left; width: 48%">
   <div style="float:left; width: 48%">
{{Code|Define MixedPoisson problem with fem-fenics|<syntaxhighlight lang="octave" style="font-size:13px">  
{{Code|Define MixedPoisson problem with fem-fenics|<syntaxhighlight lang="octave" style="font-size:13px">  
pkg load fem-fenics msh
pkg load fem-fenics msh
import_ufl_Problem ('MixedPoisson')
 
ufl start MixedPoisson
ufl
ufl BDM = FiniteElement("BDM", triangle, 1)
ufl DG  = FiniteElement("DG", triangle, 0)
ufl W = BDM * DG
ufl
ufl (sigma, u) = TrialFunctions(W)
ufl (tau, v)  = TestFunctions(W)
ufl
ufl CG = FiniteElement("CG", triangle, 1)
ufl f = Coefficient(CG)
ufl
ufl a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx
ufl L = - f*v*dx
ufl end
delete ('MixedPoisson.ufl');


# Create mesh
# Create mesh
Line 183: Line 199:
mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4));
mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4));


# File MixedPoisson.ufl
# ufl snippet above
#  BDM = FiniteElement("BDM", triangle, 1)
#  BDM = FiniteElement("BDM", triangle, 1)
#  DG  = FiniteElement("DG", triangle, 0)
#  DG  = FiniteElement("DG", triangle, 0)
Line 190: Line 206:


# Define trial and test function
# Define trial and test function
# File MixedPoisson.ufl
# ufl snippet above
#  (sigma, u) = TrialFunctions(W)
#  (sigma, u) = TrialFunctions(W)
#  (tau, v)  = TestFunctions(W)
#  (tau, v)  = TestFunctions(W)
Line 199: Line 215:


# Define variational form
# Define variational form
# File MixedPoisson.ufl
# ufl snippet above
#  a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx
#  a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx
#  L = - f*v*dx
#  L = - f*v*dx
Line 245: Line 261:
{{Code|Define MixedPoisson problem with fenics python|<syntaxhighlight lang="python" style="font-size:13px">  
{{Code|Define MixedPoisson problem with fenics python|<syntaxhighlight lang="python" style="font-size:13px">  
from dolfin import *
from dolfin import *




# Create mesh
# Create mesh
mesh = UnitSquareMesh(32, 32)
mesh = UnitSquareMesh(32, 32)


Line 260: Line 293:
(sigma, u) = TrialFunctions(W)
(sigma, u) = TrialFunctions(W)
(tau, v) = TestFunctions(W)
(tau, v) = TestFunctions(W)




22

edits

Navigation menu