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,091: | Line 1,091: | ||
pkg load fem-fenics msh | pkg load fem-fenics msh | ||
Line 1,117: | Line 1,114: | ||
# Create mesh | |||
x = y = linspace (0, 1, 65); | |||
[msh, facets] = Mesh (msh2m_structured_mesh (x, y, 0, 4:-1:1)); | |||
Line 1,151: | Line 1,156: | ||
# 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 | |||
# of the domain | |||
# 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,216: | Line 1,213: | ||
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,222: | Line 1,223: | ||
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,256: | Line 1,261: | ||
# Initialize mesh function for interior domains | # Initialize mesh function for interior domains | ||
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) |