Page 1 of 1

Cannot access user defined field

Posted: Wed Feb 08, 2017 1:57 pm
by CTrinca
Hello everybody,

In the model I am developing I make use of several custom property fields. Currently I am experiencing problems with one I added lately: when I try to initialize it in one of my subroutines, I get the following error:

Code: Select all

Fortran runtime error: Index '1' of dimension 1 of array 'filter_cell_volume' above upper bound of 0
Running the calculation through gdb, I found out that before the failure, cs_user_model is executed and cs_parameters_add_property is called on that field, but, after I try to retrieve it in my subroutine by calling field_get_val_s_by_name, the pointer I pass remains "<not associated>".
The errors occurs a few lines below when I try to assign a value to the first element of the vector.

My subroutine is called during the first run of cs_user_head_losses. When I wrote it, I had a similar problem when trying to fill the porosity field, which I solved storing the calculated values in a temporary vector. When I initialize other custom fields, in subroutines called at later stages, all is fine. Can it be that I am trying to access the field "too early"?

Thanks in advance to anyone answering.
Regards,

Cosimo

Re: Cannot access user defined field

Posted: Wed Feb 08, 2017 6:14 pm
by Yvan Fournier
Hello,

Yes, this is the case. Most fields are defined very early in the initialization (before the mesh is read), so you can access their associated keywords, but the associated value arrays are allocated later (between the first and second calls to cs_user_head_losses), just before the time stepping loop.

In version 5.0, a new method for defining head losses allows defining zones, and specifying zones either by selection criteria (in which case they are fixed) or by a user function (in which case they may even be declared as time-varying). The previous cs_user_head_losses is still usable, though it will be removed in later versions. Not sure if this might be of interest to you...

Regards,

Yvan

Re: Cannot access user defined field

Posted: Wed Feb 08, 2017 7:22 pm
by CTrinca
Hello Yvan,

Thanks for your answer, that probably means I will need to use a similar workaround as I did for the porosity.
Best regards,

Cosimo