Python script of writing field data

Hi there,

I am trying to write a field data into the MED mesh. The data are the constant through all time points. But I constantly get the error message from salome that:

return _MEDLoader.MEDCouplingFieldDouble_setTime(self, val, iteration, order)
MEDLoader.InterpKernelException: MEDCouplingNoTimeLabel::setTime : no time info attached.

Here is my code:

mesh=MEDLoader.ReadUMeshFromFile(file,"Mesh_Cube",0)
fieldOnNodes=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME)


fieldOnNodes.setMesh(mesh)
fieldOnNodes.setName("ScalarFieldOnNode")

array=DataArrayDouble()
array.alloc(fieldOnNodes.getMesh().getNumberOfNodes(),1)
array.fillWithValue(7.)
fieldOnNodes.setArray(array)

MEDLoader.WriteField(Path+"//wFile1.med",fieldOnNodes,True)

I do not really see any logical issues behind the code, not sure what is wrong with the code. Any suggestions are appreciated!

Regards
ywan459

Hello,

I receive the same error (SALOME-9.8.0 and SALOME-9.7.0).

I have experienced this in the past and have temporarily circumvented this by setting the NO_TIME to ONE_TIME. But I guess this is not efficient, since then we have copies of the same data for each time-step and it changes the steps of writing the fields a bit.

Best regards,
Gregor

Hi Gregor,

Thank you very much! I think your approach is reasonable.

I am wondering whether this could affect the computation. Eventually I will load the mesh into code_saturne for CFD modelling, the field variables will become the source term. I guess I have to write the field data into all time points layer which enables the code_saturne to read out during the solution. What-if I only write the field data into first couple time points layers, but not the rest time points layers, will code_saturne be read out nothing from the defined field?

Regards
ywan459

Hello Yikun,

this is indeed a smart way to go over this problem. Although this is still, I assume, a bug in SALOME. In other words the python example for “no time derived” field fails with an error.

Your solution makes sense, I think you can have fields defined only on certain time steps (haven’t checked) so in this case as you said you write the constant data only in one field at one time slice and that’s it.

Best regards,
Gregor

Hi Yikun,
the issue was discussed with one MEDCOUPLING core developer, who confirmed that fields without temporal information (NO_TIME) cannot be made persistent and exported to med file. Thus why you get the exception.

Hi Nabil,

I am very new to Salome. I did not know the issue has been discussed. Sorry about the repeated questions here. And I have no other further questions regarding to the topic.

Regards
ywan459