← Back to team overview

dolfin team mailing list archive

Re: [Question #95695]: Dimension-Independence (C++)

 

Question #95695 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/95695

Anders Logg proposed the following answer:
On Wed, Dec 30, 2009 at 07:58:15PM -0000, Pietro Maximoff wrote:
> New question #95695 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/95695
>
> Hello all
>
> Is there a way to program dimension-independence.
>
> I'm able to select a UnitInterval, etc based on the value of a variable 'dim' in main.cpp but the major problem is how to select the right shape for the element, i.e. triangle, tetrahedron, etc via the form (ufl) file based on the dimension.
>
> Is this feasible?
>
> Best wishes
>
> Pietro

No, the generated code is always for a specific form on a specific
element shape and specific finite element function space. So you need
to do something like this in your C++ program:

  FunctionSpace* V = 0;
  Form* form = 0;
  switch (d)
  {
  case 1:
    V    = new Poisson1D::FunctionSpace(mesh);
    form = new Poisson1D::BilinearForm(*V, *V);
    break;
  case 2:
    V    = new Poisson2D::FunctionSpace(mesh);
    form = new Poisson2D::BilinearForm(*V, *V);
    break;
  case 3:
    V    = new Poisson3D::FunctionSpace(mesh);
    form = new Poisson3D::BilinearForm(*V, *V);
    break;
  default:
    error("Illegal mesh dimension %d.", d);
  };

But as Andy points out, you can get around this by using the Python
interface which will generate code for either 1D, 2D or 3D if you set
it up that way.

--
Anders

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.