← Back to team overview

dolfin team mailing list archive

Re: [Branch ~dolfin-core/dolfin/main] Rev 4990: Allow setting constant values for boundary conditions without using Constant.

 

On Mon, 2010-08-16 at 10:03 +0000, noreply@xxxxxxxxxxxxx wrote:
> ------------------------------------------------------------
> revno: 4990
> committer: Anders Logg <logg@xxxxxxxxx>
> branch nick: dolfin-dev
> timestamp: Mon 2010-08-16 12:00:01 +0200
> message:
>   Allow setting constant values for boundary conditions without using Constant.
>   The following are equivalent:
>   
>     c = Constant(foo)
>     bc = DirichletBC(V, c, boundary)
>   
>     bc = DirichletBC(V, foo, boundary)
> modified:
>   demo/pde/poisson/python/demo.py
>   site-packages/dolfin/fem/bcs.py
> 

I've been meaning to do this for a while on the C++ side. Shouldn't it
be implemented in DirichetBC/.h/.cpp (some extra constructors)?

Garth

> 
> --
> lp:dolfin
> https://code.launchpad.net/~dolfin-core/dolfin/main
> 
> Your team DOLFIN Core Team is subscribed to branch lp:dolfin.
> To unsubscribe from this branch go to https://code.launchpad.net/~dolfin-core/dolfin/main/+edit-subscription
> differences between files attachment (revision-diff.txt)
> === modified file 'demo/pde/poisson/python/demo.py'
> --- demo/pde/poisson/python/demo.py	2010-08-06 17:06:24 +0000
> +++ demo/pde/poisson/python/demo.py	2010-08-16 10:00:01 +0000
> @@ -28,8 +28,7 @@
>      return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS
>  
>  # Define boundary condition
> -u0 = Constant(0.0)
> -bc = DirichletBC(V, u0, boundary)
> +bc = DirichletBC(V, 0.0, boundary)
>  
>  # Define variational problem
>  v = TestFunction(V)
> 
> === modified file 'site-packages/dolfin/fem/bcs.py'
> --- site-packages/dolfin/fem/bcs.py	2010-05-16 18:08:57 +0000
> +++ site-packages/dolfin/fem/bcs.py	2010-08-16 10:00:01 +0000
> @@ -43,6 +43,11 @@
>      def __init__(self, *args):
>          "Create Dirichlet boundary condition."
>  
> +        # Special case for value specified as float, tuple or similar
> +        if len(args) >= 2 and not isinstance(args[1], cpp.GenericFunction):
> +            constant = Constant(args[1]) # let Constant handle all problems
> +            args = args[:1] + (constant,) + args[2:]
> +
>          # Special case for sub domain specified as a function
>          if len(args) >= 3 and isinstance(args[2], types.FunctionType):
>              sub_domain = AutoSubDomain(args[2])
> 





Follow ups