problem with the bc

Asked by Niraj Kumar Jha on 2013-04-30

I am facing problem while defining the bcs..
problem desp- I have a square domain which is fixed at the left side..
case I - I want to apply the external load *Neumann bc * at the node (1,1)
case- II - I want to apply the external load at the whole top boundary..
..
I have written a code after goin through manuals..but it does not work..please gv your suggestions

from dolfin import *

# Create classes for defining parts of the boundaries and the interior
# of the domain
class Left(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[0], 0.0)

class Right(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[0], 1.0)

class Bottom(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[1], 0.0)

class Top(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[1], 1.0)

class Obstacle(SubDomain):
    def inside(self, x, on_boundary):
        return ((x[1], (1.0)) and (x[0], (1.0)))

# Initialize sub-domain instances
left = Left()
top = Top()
right = Right()
bottom = Bottom()
obstacle = Obstacle()

# Create mesh and define function space
mesh = dolfin.UnitSquare(2, 2)

# Initialize mesh function for interior domains
domains = CellFunction("uint", mesh)
domains.set_all(0)
obstacle.mark(domains, 1)

# Initialize mesh function for boundary domains
boundaries = FacetFunction("uint", mesh)
boundaries.set_all(0)
left.mark(boundaries, 1)
top.mark(boundaries, 2)
right.mark(boundaries, 3)
bottom.mark(boundaries, 4)

# Define function space and basis functions

V = VectorFunctionSpace(mesh, "Lagrange", 1)
U = TrialFunction(V)
v = TestFunction(V)

# Define boundary conditions

bc = DirichletBC(V, 0.0, boundaries,1)

# Define new measures associated with the interior domains and exterior boundaries

dx = Measure("dx")[domains]
ds = Measure("ds")[boundaries]

# Define functions

v = TestFunction(V) # Test function
U = TrialFunction(V)

# Elasticity parameters
E, nu ,g_T= 10.0, 0.3, Constant("1.0")
mu, lmbda = Constant(E/(2*(1 + nu))), Constant(E*nu/((1 + nu)*(1 - 2*nu)))

def epsilon(v):return 0.5*(grad(v)+transpose(grad(v)))
def sigma(v):return 2*mu*epsilon(v)+lmbda*tr(epsilon(v))*Identity(V.cell().d)

# Define variational problem

a = inner(grad(v),sigma(U))*dx
L = - g_T*v*ds(2)

# Solve problem
U = Function(V)
solve(a == L, U, bc)

# Plot solution and mesh

# Hold plot
plot(U, interactive=True)

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
2013-04-30
Last reply:
2013-05-09

This question was reopened

Jan Blechta (blechta) said : #1

On Tue, 30 Apr 2013 12:21:15 -0000
Niraj Kumar Jha <email address hidden> wrote:
> New question #227859 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/227859
>
> I am facing problem while defining the bcs..
> problem desp- I have a square domain which is fixed at the left side..
> case I - I want to apply the external load *Neumann bc * at the node
> (1,1) case- II - I want to apply the external load at the whole top
> boundary.. ..
> I have written a code after goin through manuals..but it does not
> work..please gv your suggestions
>
> from dolfin import *
>
> # Create classes for defining parts of the boundaries and the interior
> # of the domain
> class Left(SubDomain):
> def inside(self, x, on_boundary):
> return near(x[0], 0.0)
>
> class Right(SubDomain):
> def inside(self, x, on_boundary):
> return near(x[0], 1.0)
>
> class Bottom(SubDomain):
> def inside(self, x, on_boundary):
> return near(x[1], 0.0)
>
> class Top(SubDomain):
> def inside(self, x, on_boundary):
> return near(x[1], 1.0)
>
> class Obstacle(SubDomain):
> def inside(self, x, on_boundary):
> return ((x[1], (1.0)) and (x[0], (1.0)))
>
> # Initialize sub-domain instances
> left = Left()
> top = Top()
> right = Right()
> bottom = Bottom()
> obstacle = Obstacle()
>
> # Create mesh and define function space
> mesh = dolfin.UnitSquare(2, 2)
>
> # Initialize mesh function for interior domains
> domains = CellFunction("uint", mesh)
> domains.set_all(0)
> obstacle.mark(domains, 1)
>
> # Initialize mesh function for boundary domains
> boundaries = FacetFunction("uint", mesh)
> boundaries.set_all(0)
> left.mark(boundaries, 1)
> top.mark(boundaries, 2)
> right.mark(boundaries, 3)
> bottom.mark(boundaries, 4)
>
> # Define function space and basis functions
>
> V = VectorFunctionSpace(mesh, "Lagrange", 1)
> U = TrialFunction(V)
> v = TestFunction(V)
>
> # Define boundary conditions
>
> bc = DirichletBC(V, 0.0, boundaries,1)
bc = DirichletBC(V, (0.0, 0.0), boundaries,1)
>
> # Define new measures associated with the interior domains and
> exterior boundaries
>
> dx = Measure("dx")[domains]
> ds = Measure("ds")[boundaries]
>
> # Define functions
>
> v = TestFunction(V) # Test function
> U = TrialFunction(V)
>
> # Elasticity parameters
> E, nu ,g_T= 10.0, 0.3, Constant("1.0")
E, nu ,g_T= 10.0, 0.3, Constant(("1.0", "0.0"))
> mu, lmbda = Constant(E/(2*(1 + nu))), Constant(E*nu/((1 + nu)*(1 -
> 2*nu)))
>
> def epsilon(v):return 0.5*(grad(v)+transpose(grad(v)))
> def sigma(v):return
> 2*mu*epsilon(v)+lmbda*tr(epsilon(v))*Identity(V.cell().d)
>
> # Define variational problem
>
> a = inner(grad(v),sigma(U))*dx
a = inner(grad(v),sigma(U))*dx(1)
> L = - g_T*v*ds(2)
L = - inner(g_T, v)*ds(2)
>
>
> # Solve problem
> U = Function(V)
> solve(a == L, U, bc)
>
>
> # Plot solution and mesh
>
> # Hold plot
> plot(U, interactive=True)
>
>
>
>

Niraj Kumar Jha (niraj-jha) said : #2

thnks Jan Blechta..

Niraj Kumar Jha (niraj-jha) said : #3

Thanks Jan Blechta, that solved my question.

Niraj Kumar Jha (niraj-jha) said : #4

Hi..

I am just curious to know about the load application ata particular node..can zou please guide ??

Anders Logg (logg) said : #5

FEniCS no longer uses Launchapd for Questions & Answers. Please
consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

Anders Logg (logg) said : #6

FEniCS no longer uses Launchapd for Questions & Answers. Please
consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

Chaitanya (chaitanyaraj108) said : #7

Whoever would like to follow further discussion on this problem....pls. check this link:

http://fenicsproject.org/qa/7856/linear-elasticity-2d-mesh-error?show=7894#c7894

Can you help with this problem?

Provide an answer of your own, or ask Niraj Kumar Jha for more information if necessary.

To post a message you must log in.