← Back to team overview

ffc team mailing list archive

Re: including a file in .form

 

There are two ways to do this:

1. Create three files as you suggest and import the file
ConvectionDiffusion.form in both ConvectionDiffusion_2D.form and
ConvectionDiffusion_3D.form as follows:

    ConvectionDiffusion.form
    ------------------------
    u = BasisFunction(scalar)
    ...
    a = ...
    L = ...

    ConvectionDiffusion_2D.form
    ---------------------------
    scalar = FiniteElement("Lagrange", "triangle", 1)
    ...
    import "ConvectionDiffusion.form"

    ConvectionDiffusion_3D.form
    ---------------------------
    scalar = FiniteElement("Lagrange", "tetrahedron", 1)
    ...
    import "ConvectionDiffusion.form"

2. Use the Python interface to FFC and create one file named
ConvectionDiffusion.py and then do

    python ConvectionDiffusion.py

to compile. The contents could be something like

    from ffc import *

    def forms(scalar, vector):
        u = BasisFunction(scalar)
        ...
        a = ...
        L = ...
        return (a, L)

    scalar = FiniteElement("Lagrange", "triangle", 1)
    vector = FiniteElement("Vector Lagrange", "triangle", 1)
    (a, L) = forms(scalar, vector)
    compile([a, L], "ConvectionDiffusion_2D")

    scalar = FiniteElement("Lagrange", "tetrahedron", 1)
    vector = FiniteElement("Vector Lagrange", "tetrahedron", 1)
    (a, L) = forms(scalar, vector)
    compile([a, L], "ConvectionDiffusion_3D")

We could add some built-in support to the parser/command-line
interface to handle both 2D and 3D problems, but one could also argue
that we should keep it as simple as possible, since all the
flexibility you need is available anyway through the Python interface.

/Anders


On Fri, Dec 30, 2005 at 10:57:59AM +0100, Garth N. Wells wrote:
> Is it to "include" a .form (or .py) file in a .form file? If not, could
> this be done easily in the FFC parser?
> 
> I'm setting up the convection-diffusion solver in DOLFIN for both 2D and
> 3D, and the only difference in the FFC .form files is the definition of
> the finite elements at the top (3 lines in the case of
> convection-diffusion). I'd like to have something like
> 
> ConvectionDiffusion.form:
>   u = BasisFunction(scalar)
>   .
>   .
>   a = . . .
>   L = ...
> 
> ConvectionDiffusion_3D.form:
>   scalar = FiniteElement("Lagrange", "tetrahedron", 1)
>   .
>   include ConvectionDiffusion.form
> 
> ConvectionDiffusion_2D.form:
>   scalar = FiniteElement("Lagrange", "triangle", 1)
>   .
>   include ConvectionDiffusion.form
> 
> Since "ConvectionDiffusion.form" is incomplete, a better name might be
> "ConvectionDiffusion.pde".
> 
> This would be useful for developing 2D and 3D versions of a particular
> PDE, as well as different order elements. 
> 
> Garth
> 
> 
> _______________________________________________
> FFC-dev mailing list
> FFC-dev@xxxxxxxxxx
> http://www.fenics.org/cgi-bin/mailman/listinfo/ffc-dev
> 

-- 
Anders Logg
Research Assistant Professor
Toyota Technological Institute at Chicago
http://www.tti-c.org/logg/



Follow ups

References