How to calculate scalar based on frozen average velocity?

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Tsubasa
Posts: 130
Joined: Fri Nov 20, 2020 4:09 am

How to calculate scalar based on frozen average velocity?

Post by Tsubasa »

Hello,

Now I am wondering how to solve scalar equation based on average velocityand pressure field.

In the GUI, we can select "Calculation on frozen velocity and pressure fields".
However, as far as I understand, the frozen velocity and pressure field are the field, which is obtained latest time step in previous calculation. Than's why it is instantaneous field, but not average field.

However, What I want to do now is:
Step1: calculation by URANS
Step2: get average velocity field and pressure field obtained by URANS (Time averages in GUI)
Step3: calculation scalar equation based on average velocity field and pressure field

Would someone give me tips?

Best regards,
Tsubasa
Yvan Fournier
Posts: 3498
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to calculate scalar based on frozen average velocity?

Post by Yvan Fournier »

Hello,

Although it is rarely used, you can remap a field to another when restarting.

For this, you need to edit a user-defined function, either cs_user_parameters, or cs_user_finalize_setup (both in cs_user_parameters.c).

Something such as this should work :

Code: Select all

const int kr = cs_field_key_id_try("restart_name");

cs_field_t *vel = cs_field_by_name("velocity");
cs_field_set_key_str(vel, kr, "velocity_mean");
Adapting "velocity_mean" if your mean velocity field has another name.

This should work, though again, I have not used/checked this in a while.

Best regards,

Yvan
Tsubasa
Posts: 130
Joined: Fri Nov 20, 2020 4:09 am

Re: How to calculate scalar based on frozen average velocity?

Post by Tsubasa »

Hello Yvan,

Thank you for the reply.

Should I also change the name ""restart_name"" in your example?

Best regards,
Tsubasa
Yvan Fournier
Posts: 3498
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to calculate scalar based on frozen average velocity?

Post by Yvan Fournier »

Hello,

no, "restart_name" is the name of the field keyword, so should not be changed.

Another possible issue is that the mass flux (defined at faces) stored in checkpoints is also that of the lat time step.
A minor change was done in the master branch (v7.1) to allow to also compute its mean, but this is not easily available in v7.0.

If the mass flux is not available (avoid reading or move/remove the checkpoint/auxiliary.csc file), it should be rebuilt, so if you switched to the mean velocity, that should be good in theory, but I remember that in past versions, this was not handled well, and scalars would not be convected (easy to check: if that bug is still present, no convection is present, so not much happens).

So would also recommend moving/removing the checkpoint/auxilliary.csc and post-processing to check that scalars seem convected as expected.

Best regards,

Yvan
Tsubasa
Posts: 130
Joined: Fri Nov 20, 2020 4:09 am

Re: How to calculate scalar based on frozen average velocity?

Post by Tsubasa »

Hello Yvan,

Thank you for the reply.

As you said, I edit the SRC file like this:

Code: Select all

void
cs_user_finalize_setup(cs_domain_t   *domain)
{
  const int kr = cs_field_key_id_try("restart_name");
  cs_field_t *vel = cs_field_by_name("velocity");
  cs_field_set_key_str(vel, kr, "ave_vel");
}
However, the scalar is calculated based on the velocity field of last time step, not average velocity field. Scalar seems to be convected (but this result is based on the velocity field of last time step).

Would you give me some tips?

Best regards,
Hamada
Tsubasa
Posts: 130
Joined: Fri Nov 20, 2020 4:09 am

Re: How to calculate scalar based on frozen average velocity?

Post by Tsubasa »

Hello Yvan,

Is it correct to put a name "ave_vel" written in a picture into ""cs_field_set_key_str(vel, kr, "velocity_mean")""?
Untitled.png
Best regards,
Hamada
Yvan Fournier
Posts: 3498
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to calculate scalar based on frozen average velocity?

Post by Yvan Fournier »

Hello,

Yes, if you named the field ave_velocity, you should use that instead of velocity_mean.

Best regards,

Yvan
Tsubasa
Posts: 130
Joined: Fri Nov 20, 2020 4:09 am

Re: How to calculate scalar based on frozen average velocity?

Post by Tsubasa »

Hello,

I tried your script a few time, but it did not work. Scalar transport is calclated on velocity field of last time step.

The script is here:

Code: Select all

void
cs_user_parameters(cs_domain_t   *domain)
{
  const int kr = cs_field_key_id_try("restart_name");
  cs_field_t *vel = cs_field_by_name("velocity");
  cs_field_set_key_str(vel, kr, "ave_vel");
}
on cs_user_parameters.c in SRC folder.

To check the script, can I tried "test the compilation of user function inside the SRC folder" in GUI?
When I did it, I always have this kind of message
Untitled.png
but this message can be seen when I used another script, which can be used correctly.
"test the compilation of user function inside the SRC folder" in GUI is not so important?

Best regards,
Hamada
Yvan Fournier
Posts: 3498
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to calculate scalar based on frozen average velocity?

Post by Yvan Fournier »

Hello,

This is just a warning about an unused parameter, so not a problem.

Best regards,

Yvan
Tsubasa
Posts: 130
Joined: Fri Nov 20, 2020 4:09 am

Re: How to calculate scalar based on frozen average velocity?

Post by Tsubasa »

Hello Yvan,

If your suggested script doesn't work, do you think I should I it with Ver.7.0?

Best regards,
Tsubasa
Post Reply