Creating a new field variable

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
AndrewH
Posts: 47
Joined: Thu Oct 02, 2014 11:03 am

Creating a new field variable

Post by AndrewH »

Hello,

Through the user subroutines, is it possible to create a new field variable?

In cs_user_parameters I added the following lines:

itycat = FIELD_INTENSIVE + FIELD_PROPERTY
ityloc = 3
idim1 = 3
ilved = .true.
inoprv = .false.

call field_create('var1', itycat, ityloc, idim1, ilved, inoprv, f_id)
call field_set_key_int(f_id, keyvis, 1)
call field_set_key_int(f_id, keylog, 1)

In the setup.log and in the listing file for each time iteration, my new field variable var1 is present. In cs_user_extra_operations.f90, I use field_get_val_v(var1, p_var1) to call the variable and assign it a value. However, in the listing file and results file, the value is zero. To double check that my routine in cs_user_extra_operations.f90 works, I output my results directly and obtain what I was expecting.

Is there something fundamentally wrong with this approach? I surmise that the field variable is not being saved when it is called in cs_user_extra_operations, but I can't come up with an explanation why.

Thank you,
Andrew
Yvan Fournier
Posts: 4208
Joined: Mon Feb 20, 2012 3:25 pm

Re: Creating a new field variable

Post by Yvan Fournier »

Hello,

In version 4.0, you can also use a higher level function to tell the code you are creating a property field (which manages a few additional setting). Check cs_user_parameters.c examples.

The approach should work so far as I can think of.

But in cs_user_extra_operations.f90, are you using :

Code: Select all

field_get_val_v(var1, p_var1)
as you post seems to indicate (unless you have a typo), or:

Code: Select all

f_id = field_get_id('var1')
field_get_val_v(f_id, p_var1)
The first variant should not compile with all compilers, but if it does, it might be accessing
the wrong variable (possibly the velocity).

Regards,

Yvan
AndrewH
Posts: 47
Joined: Thu Oct 02, 2014 11:03 am

Re: Creating a new field variable

Post by AndrewH »

Hi Yvan,

Yes, it was a typo. In cs_user_extra_operations, I used the following lines to call the field:

call field_get_id_try('var1',id_name)
call field_get_val_v(ivarfl(isca(id_name)), p_var)

I checked my compile log and there was no errors, and the routine computes the value correctly. But, the computed value isn't stored in the field. Is there any benefits in declaring my field in cs_user_parameters.c?



Also, is there any examples of cs_field_gradient_vector being implemented in c? My overall goal is obtain the time average of my field and I rewrote my routine in cs_user_parameters to be called as the cs_user_time_moment is being run. But, I ran into a different problem. When the routine is called, I get the following error. I assume something wrong when I call cs_field_gradient_vector, but I can't see any errors with it. My compile log shows no warnings or errors either.

SIGSEGV signal (forbidden memory area access) intercepted!

Call stack:
1: 0x7ff443026f72 <+0x2a3f72> (libsaturne.so.0)
2: 0x7ff44302d441 <cs_gradient_vector+0x231> (libsaturne.so.0)
3: 0x7ff442e5e533 <cs_field_gradient_vector+0xb3> (libsaturne.so.0)
4: 0x400bc6 <> (cs_solver)
5: 0x7ff442eab6a6 <cs_time_moment_update_all+0x786> (libsaturne.so.0)
6: 0x7ff442e063ab <caltri_+0x30cb> (libsaturne.so.0)
7: 0x7ff442de7365 <cs_run+0x3e5> (libsaturne.so.0)
8: 0x7ff442de6e92 <main+0x112> (libsaturne.so.0)
9: 0x7ff44255d76d <__libc_start_main+0xed> (libc.so.6)
10: 0x400a59 <> (cs_solver)
End of stack

I attached my cs_user_parameters.c file.

Thank you,
Andrew
Attachments
cs_user_parameters.c
(9.71 KiB) Downloaded 230 times
Yvan Fournier
Posts: 4208
Joined: Mon Feb 20, 2012 3:25 pm

Re: Creating a new field variable

Post by Yvan Fournier »

Hello,

The "isca" numbering is a specific indirection, which is only used for scalars, and ivarfl to map resolved variable to field ids.

The "low-level" field functions use a "flat" numbering, so you should not use:

Code: Select all

call field_get_id_try('var1',id_name)
call field_get_val_v(ivarfl(isca(id_name)), p_var)
but simply:

Code: Select all

call field_get_id_try('var1',id_name)
call field_get_val_v(id_name, p_var)
Regards,

Yvan
AndrewH
Posts: 47
Joined: Thu Oct 02, 2014 11:03 am

Re: Creating a new field variable

Post by AndrewH »

Okay, I changed that and caught another mistake in my routine, and appears to be working now. Thank you!

In regards to cs_user_time_moment, is it possible to use cs_field_gradient_vector to calculate the velocity gradient?


Thank you,
Andrew
Post Reply