XDMFFile << MeshFunction('size_t', ...) gives error in python - swig problem?

Asked by Chris Richardson on 2013-02-21

I can't get XDMFFile to accept MeshFunctions, unless they are of type double.

e.g.

M=UnitSquareMesh(10,10)
F=XDMFFile("a.xdmf")
MF = MeshFunction('size_t', M, 0)
F << MF

gives:
TypeError: in method 'XDMFFile___lshift__', argument 2 of type 'dolfin::MeshFunction< double > const &'

Something to do with SWIG and overloading?

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
2013-02-21
Last query:
2013-02-21
Last reply:
2013-02-21
Johan Hake (johan-hake) said : #1

On 02/21/2013 03:35 PM, Chris Richardson wrote:
> New question #222488 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/222488
>
>
> I can't get XDMFFile to accept MeshFunctions, unless they are of type
> double.
>
> e.g.
>

Try:

M=UnitSquareMesh(10,10)
F=File("b.xdmf")
MF = MeshFunction('size_t', M, 0)
F << MF

Johan

>
> gives: TypeError: in method 'XDMFFile___lshift__', argument 2 of type
> 'dolfin::MeshFunction< double > const &'
>
> Something to do with SWIG and overloading?
>
>

Chris Richardson (chris-bpi) said : #2

Yes, that works, but I want to be able to set some of the parameters of the XDMFFile, using e.g.

XDMF.parameters["flush_output"] = True

Best Johan Hake (johan-hake) said : #3

Ok, then we need to expose some of these Functions. Now we instantiate
the templated method for the <</>> operator in dolfin::File. I think we
should do it in GenericFile.

Consider it a bug. I can have a look at it.

Johan

On 02/21/2013 04:56 PM, Chris Richardson wrote:
> Question #222488 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/222488
>
> Status: Answered => Open
>
> Chris Richardson is still having a problem:
>
> Yes, that works, but I want to be able to set some of the parameters of the XDMFFile, using e.g.
>
> XDMF.parameters["flush_output"] = True
>

Chris Richardson (chris-bpi) said : #4

Thanks Johan Hake, that solved my question.

Johan Hake (johan-hake) said : #5

Should be fixed in trunk now. I had to change the file interface for
unsigned long int to std::size_t. Why were the unsigned long int there
in the first place?

Johan

On 02/21/2013 05:31 PM, Johan Hake wrote:
> Question #222488 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/222488
>
> Status: Open => Answered
>
> Johan Hake proposed the following answer:
> Ok, then we need to expose some of these Functions. Now we instantiate
> the templated method for the <</>> operator in dolfin::File. I think we
> should do it in GenericFile.
>
> Consider it a bug. I can have a look at it.
>
> Johan
>
> On 02/21/2013 04:56 PM, Chris Richardson wrote:
>> Question #222488 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/222488
>>
>> Status: Answered => Open
>>
>> Chris Richardson is still having a problem:
>>
>> Yes, that works, but I want to be able to set some of the parameters of the XDMFFile, using e.g.
>>
>> XDMF.parameters["flush_output"] = True
>>
>

Chris Richardson (chris-bpi) said : #6

On 21/02/13 20:26, Johan Hake wrote:
> Your question #222488 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/222488
>
> Johan Hake posted a new comment:
> Should be fixed in trunk now. I had to change the file interface for
> unsigned long int to std::size_t. Why were the unsigned long int there
> in the first place?
>

It is possibly related to the native datatypes of HDF5 - it may
cause problems on 32-bit systems, perhaps, as the
type is hard wired in - "grep NATIVE dolfin/io/HDF5Interface.h"

Chris