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.
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, I don't expect a change here. The issue might be due to the fact that the mean and instant velocities are not stored in the same file (auxiliary vs. main) checkpoint. I'll need to check in more detail.

In the meantime, the simplest solution is probably to use the cs_user_initialize user function to overwrite the values of the instant velocity with those of the average velocity. But you should also avoid reading (or remove) the auxiliary restart, to make sure the instant mass flux is not also used.

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,

Thnak you for your help.

Is there a exmaple to overwrite the initial value by mean_velocity?
I only found it overwrited by constant single here:
https://www.code-saturne.org/cms/sites/ ... _base.html

Can it be overwited by a usual script manner of Fortran?

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,

Compared to the C example, copying values from one field to another instead of copying from a constant should be relatively straightforward.

and yes, you can also do it the usual way in Fortran.

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,

As you said, I want to try to initilizing a field by mean_velocity field, which is calculate by a previous simulation.
However, is mean_velocity value (also pressure) stored in main or auxiliary file?

As far as I understand, I have thiese information

Code: Select all

Write final restart files
   checkpoint at iteration       6000, Physical time    0.12000E+04


   ** Writing the main restart file
      -----------------------------

 Start writing
  Wrote field names and types to checkpoint at iteration 6000: checkpoint/main
   End writing the options                              
  Wrote main variables to checkpoint: checkpoint/main
 End writing

   ** Writing the auxiliary restart file
      ----------------------------------

 Start writing
   End writing the dimensions and options               
   End writing the physical properties                  
   End writing the time step                            
  Wrote boundary condition coefficients to checkpoint: checkpoint/auxiliary
 End writing
and the mean_variable values are stored in "checkpoint/auxiliary" file.
Now what I want to know is that how to open "auxiliary"?
Can we output the auxiliary file by some kind od readable extension (at the moment, I cannot read the auxiliary file and get mean values because it is binary file)?
By default, extension of auxiliary is csc? If so, can we change it or can we get the mean values in it?


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,

In this case, it may be simpler to keep the auxilairy.csm file, and read it normally, keeping time averages active in the restart (.i.e. keeping the default behavior for everything), so that the time averages are read automatically, and you can then simply access the values from the average field.

But again, unless running the development branch, in which it is now possible to activate time averages for the mass flux, the mass flux used for convection will probably still be that of the last time step...

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,

OK, I understand...

So now, ideal thing for me is that the pressure driven flow simulation can be done only with tetra mesh in steady simulation (not unsteady simulation) in Ver.7.
If this is possible, we can directly get average values without additional postprocessings. And after that, I will carry out simulation for scalar in code_saturne or another software.

If possible, would you test the pressure driven simulation in Ver.7?
You can use the mesh, which I gave before in another post, and I will give you SRC script if you will do this.

Best regards,
Tsubasa
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,

Let me check something finally.
Even in new version of Code_saturne (e.g. ver.7), is it impossible to get data of average mass flux from the auxilairy file?

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,

Yes, it is impossible in v7.0, or at least not guaranteed : you might be able to declare a time average for the mass flux if you add the call to cs_time_moment_define_by_field_ids not in cs_user_time_moments, but in cs_user_finalize_setup (both in cs_user_parameters.c). Not sure it will work, but there might be a chance.

In v7.1, you will be able to add the definition in the usual place (i.e. cs_user_time_moments).

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 »

Dear Yvan,

OK, Thank you for your tips.
As a final option for this problem, I will try what you said.

But I am not sure how to do what you said.
Are there exmaples of what you said (adding calls to cs_time_moment_define_by_field_ids in cs_user_finalize_setup for a time average for some variables)?
If so, would you show me some examples, if you have?

Should I just edit this from a example of time moment?

Code: Select all

 {
    /* Moment <U> calculated starting from time step 1000. */
    /* resulting field is a vector */
    int moment_f_id[] = {CS_F_(vel)->id};
    int moment_c_id[] = {-1};
    int n_fields = 1;
    cs_time_moment_define_by_field_ids("U_mean",
                                       n_fields,
                                       moment_f_id,
                                       moment_c_id,
                                       CS_TIME_MOMENT_MEAN,
                                       1000, /* nt_start */
                                       -1,   /* t_start */
                                       CS_TIME_MOMENT_RESTART_AUTO,
                                       NULL);
Thank you for your kindness.
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,

Your piece of code seems good for the mean velocity (but you could actually also do the same thing using the graphical interface).

In v7.1, you may also add a similar piece of code for the mas fluxes. I have no example code, but you can check in the setup.log for the name of the matching field name, and use cs_field_by_name() instead of CS_F_() to get the matching field id.

Once you have the field averages output correctly, we can go to the second stage (reading those fields instead of the default ones when restarting).

Best regards,

YVan
Post Reply