← Back to team overview

dolfin team mailing list archive

Re: [Question #147820]: how to read out data array from unstructured mesh (advection-diffusion demo)

 

You should be able to use GetPointData().GetArray(). Have you looked at the
name of the variable in the vtu file? It is in ASCII format.

I attach something I did earlier.

Kent

On 4 March 2011 19:34, JJ Jiang <question147820@xxxxxxxxxxxxxxxxxxxxx>wrote:

> New question #147820 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/147820
>
> Hi all,
>  I am running into a problem. I run the advection-diffusion demo. All the
> simulated mass transport quantities u were save to a vtk PVD file with an
> unstructured mesh.
>
> My question is how to read out the u from the associated individual vtu
> files. I thought  the u is attached to either PointData or CellData so that
> I can read out the scalar u using one of the following:
> grid->GetPointData()->GetArray('name');
> or
> grid->GetCellData()->GetArray('name');
>
> But my attempts have failed. Please provide your advice. Thanks so much for
> your help!
>
> Best regards,
> --JJ
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp
>
import vtk 

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName("u3D.vtu")
reader.Update()

v0 = reader.GetOutput()
v1 = reader.GetOutput()

u0 = v0.GetPointData().GetArray("u")
u1 = v1.GetPointData().GetArray("u")

print u1 

code1 = """
void add(vtkFloatArray* x, vtkFloatArray* result){
    float* xx = x->GetPointer(0); 
    float* rresults = result->GetPointer(0); 
    int n = x->GetSize(); 
    for (int i=0; i<n; i++) { 
	rresults[i] += xx[i]; 
    }
}
"""


code2 = """
void scale(vtkFloatArray* x, double scale){
    float* xx = x->GetPointer(0); 
    int n = x->GetSize(); 
    for (int i=0; i<n; i++) { 
	xx[i] *= scale; 
    }

}
"""

from instant import inline_vtk 

add = inline_vtk(code1, cache_dir="test_vtk")
scale = inline_vtk(code2, cache_dir="test_vtk")


print u1.GetValue(137)
add(u0, u1)
print u1.GetValue(137)
scale(u1, 0.5)
print u1.GetValue(137)






Follow ups

References