Dimension-Independence (C++)
Hello all
Is there a way to program dimension-
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
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Anders Logg
- Solved:
- 2009-12-31
- Last query:
- 2009-12-31
- Last reply:
- 2009-12-30
Andy R Terrel (andy-terrel) said : | #1 |
The easiest thing to do is just create multiple .ufl files. See dolfin/
But it is also possible to just do a switch inside the ufl file since ffc just wraps the ufl file as a python script. The problem with this approach is making sure you have the right dimensions everywhere. For simple things (like stokes) this is trivial, but as you add more complexity to your algorithms it begins to become a real pain.
Another option is to just use the python interface to dolfin, then every thing gets generated as necessary and can have a larger amount of flexibility for less code (that you write anyways).
|
#2 |
On Wed, Dec 30, 2009 at 07:58:15PM -0000, Pietro Maximoff wrote:
> New question #95695 on DOLFIN:
> https:/
>
> Hello all
>
> Is there a way to program dimension-
>
> 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:
form = new Poisson1D:
break;
case 2:
V = new Poisson2D:
form = new Poisson2D:
break;
case 3:
V = new Poisson3D:
form = new Poisson3D:
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
Pietro Maximoff (segment-x) said : | #3 |
Thanks, Anders. That was quite helpful.
Yes, you're quite right, I can actually do this via the Python interface but ultimately, I'll need the raw power of C++ for the simulations I perform.
Pietro Maximoff (segment-x) said : | #4 |
Thanks Anders Logg, that solved my question.