Fem-fenics: Difference between revisions

Jump to navigation Jump to search
32 bytes removed ,  11 April 2015
→‎Obstacles in the Domain: Rearrange the example in order to put corresponding instructions next to each other
(→‎Tutorials: Add obstacle example)
(→‎Obstacles in the Domain: Rearrange the example in order to put corresponding instructions next to each other)
Line 1,091: Line 1,091:
pkg load fem-fenics msh
pkg load fem-fenics msh


# Create mesh
x = y = linspace (0, 1, 65);
[msh, facets] = Mesh (msh2m_structured_mesh (x, y, 0, 4:-1:1));




Line 1,114: Line 1,117:




# Create mesh
x = y = linspace (0, 1, 65);
[msh, facets] = Mesh (msh2m_structured_mesh (x, y, 0, 4:-1:1));




Line 1,156: Line 1,151:


# Define subdomains
# Define subdomains


domains = MeshFunction ("dx", msh, 2, 0);
domains = MeshFunction ("dx", msh, 2, 0);
obstacle = SubDomain (@(x,y) (y >= 0.5) && (y <= 0.7) && ...
obstacle = SubDomain (@(x,y) (y >= 0.5) && (y <= 0.7) && ...
                       (x >= 0.2) && (x <= 1.0), false);
                       (x >= 0.2) && (x <= 1.0), false);
Line 1,196: Line 1,196:
from dolfin import *
from dolfin import *


# Create classes for defining parts of the boundaries and the interior
# Define mesh
# of the domain
 
mesh = UnitSquareMesh(64, 64)
 
# Create classes for defining parts of the boundaries
class Left(SubDomain):
class Left(SubDomain):
   def inside(self, x, on_boundary):
   def inside(self, x, on_boundary):
Line 1,213: Line 1,216:
   def inside(self, x, on_boundary):
   def inside(self, x, on_boundary):
     return near(x[1], 1.0)
     return near(x[1], 1.0)
class Obstacle(SubDomain):
  def inside(self, x, on_boundary):
    return (between(x[1], (0.5, 0.7)) and between(x[0], (0.2, 1.0)))


# Initialize sub-domain instances
# Initialize sub-domain instances
Line 1,223: Line 1,222:
right = Right()
right = Right()
bottom = Bottom()
bottom = Bottom()
# Define mesh
mesh = UnitSquareMesh(64, 64)


# Initialize mesh function for boundary domains
# Initialize mesh function for boundary domains
Line 1,261: Line 1,256:


# Initialize mesh function for interior domains
# Initialize mesh function for interior domains
class Obstacle(SubDomain):
  def inside(self, x, on_boundary):
    return (between(x[1], (0.5, 0.7)) and between(x[0], (0.2, 1.0)))
obstacle = Obstacle()
obstacle = Obstacle()
domains = CellFunction("size_t", mesh)
domains = CellFunction("size_t", mesh)
domains.set_all(0)
domains.set_all(0)


obstacle.mark(domains, 1)
obstacle.mark(domains, 1)
22

edits

Navigation menu