Fem-fenics: Difference between revisions

Jump to navigation Jump to search
361 bytes removed ,  28 May 2014
Undo revision 4907 by Eg123 (talk)
(→‎Mixed Formulation for Poisson Equation: Adapt the example to the ufl paradigm)
(Undo revision 4907 by Eg123 (talk))
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 Discontinuos elements 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 Dicontinuos element 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 available 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 avilable 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 199: Line 183:
mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4));
mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4));


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


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


# Define variational form
# Define variational form
# ufl snippet above
# File MixedPoisson.ufl
#  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 261: Line 245:
{{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 293: Line 260:
(sigma, u) = TrialFunctions(W)
(sigma, u) = TrialFunctions(W)
(tau, v) = TestFunctions(W)
(tau, v) = TestFunctions(W)




22

edits

Navigation menu