Page 1 of 1

Calculate gradient on user-created vector field

Posted: Mon Feb 22, 2016 5:03 pm
by philippks
Hi,

I am using CS 4.0.4 and I would like to calculate the gradient of a vector field I have created in uspisu and initialized with cs_user_initialization, according to the given examples in the files. I tried field_gradient_vector on my created field in cs_user_extra_operations:

Code: Select all

call field_gradient_vector(id_vel_user, 0 , imrgra , 1, gradv)
however, it returns an error as some field information (var_cal_opt) is missing:

Code: Select all

../.././../code_saturne-4.0.4/src/base/cs_field.c:3025: Fatal error.

Field "vel_user" with type flag 9
has no value associated with key 25 ("var_cal_opt").


Call stack:
   1: 0x7f205261af9c <cs_field_get_key_struct+0xec>   (libsaturne.so.0)
   2: 0x7f2052abb1a5 <__cs_c_bindings_MOD_field_get_key_struct_var_cal_opt+0x49> (libsaturne.so.0)
   3: 0x40387a     <cs_f_user_extra_operations_+0x6a9> (cs_solver)
   4: 0x7f20525c9df0 <caltri_+0x31b0>                 (libsaturne.so.0)
   5: 0x7f20525a1cae <cs_run+0x3fe>                   (libsaturne.so.0)
   6: 0x7f20525a17a2 <main+0x112>                     (libsaturne.so.0)
   7: 0x7f2051e7fec5 <__libc_start_main+0xf5>         (libc.so.6)
   8: 0x402ac9     <>                               (cs_solver)
End of stack
Do I need to run any other subroutines in advance? In fldini.f90, I found the function field_set_key_struct_var_cal_opt, but I am not sure if this is intended to use for custom fields. Maybe you can give me an advice on this issue.

Thank you in advance,
Philipp

Re: Calculate gradient on user-created vector field

Posted: Mon Feb 22, 2016 9:50 pm
by Yvan Fournier
Hello,

You probably hit upon a current limitation of the high-level field gradient operations:

those are currently defined only for "variable" type fields. It would probably be a good idea to enable those for all fields, using default (Neumann) boundary conditions.

You currenty have 2 options:

- define you field as a variable, possibly setting iconv and idiff to 0, to avoid both convection and diffusion (so basically not solving anything, but defining boundary conditions usable with gradients)

- use the low-level gradient operators (gradient_s, gradient_v, ... defined in src/base/cs_c_bindings.f90, described under the Doxygen documentation).

Regards,

Yvan

Re: Calculate gradient on user-created vector field

Posted: Mon Feb 29, 2016 4:31 pm
by philippks
Hi Yvan,

Again thank you for the fast reply. I worked around this issue, which originally came up in because I was coupling two code_saturne simulations (hybrid RANS/LES): The subroutine grdvec was called within cscpce, and it was described in grdvec that ivar = 0 would allow to calculate the gradient of the field if it isn't a velocity or stress tensor field. So I used ivar = 0 and it seems to work fine now.
Philipp