Page 5 of 6

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

Posted: Sun Sep 05, 2021 3:01 pm
by Tsubasa
Hello Yvan,

Yes, your code works very well, at least for velocity field.
Probably you just mistyped "ve" instead of "vel" in

Code: Select all

cs_lnum_t n_vals = cs_glob_mesh->n_cells * ve->dim
Let me check one aspect in;

Code: Select all

cs_glob_mesh->n_cells * ve->dim
This "*" is not pointer, is it?
Does it mean just "multiplication"?
So the code means "the number of cells *(time) 3", doesn't it?
___________________________________________________________________________


In next step, I will do it for "mass flux".
SInce the dimention of mass flux is 1 dimension,
I guess the previsou code should work, but there is an error message when compilng.
Should I also change something for mass flux?

Code: Select all

void
cs_user_initialization(cs_domain_t     *domain)
{
  cs_field_t *vel = cs_field_by_name("velocity");
  cs_field_t *vel_m = cs_field_by_name("meanVel");

  cs_field_t *inner_mass_flux = cs_field_by_name("inner_mass_flux");
  cs_field_t *inner_mass_flux_m = cs_field_by_name("inner_mass_flux_mean");

  cs_field_t *boundary_mass_flux = cs_field_by_name("boundary_mass_flux");
  cs_field_t *boundary_mass_flux_m = cs_field_by_name("boundary_mass_flux_mean");

  cs_lnum_t n_vals = cs_glob_mesh->n_cells * vel->dim;  // n_cells * 3 for vector field
  for (cs_lnum_t i = 0; i < n_vals; i++) {
  vel->val[i] = vel_m->val[i];
 }
  for (cs_lnum_t i = 0; i < cs_glob_mesh->n_cells; i++) {
  inner_mass_flux->val[i] = inner_mass_flux_m->val[i];
  boundary_mass_flux->val[i] = boundary_mass_flux_m->val[i];
 }
}
I think the problem comes from

Code: Select all

boundary_mass_flux->val[i] = boundary_mass_flux_m->val[i];
becasue the code workd without this line.

I think, the number of cell for boundary mass flux is not same to inner mass flux and velocities.
For boundary mass flux, we should code "cs_glob_mesh->n_b_cells" instead "cs_glob_mesh->n_cells", right?
At least now, this code works.
___________________________________________________________________________

Also I want to check one thing.
For inner mass flux, is the number of cells "cs_glob_mesh->n_cells"?
I am worrying that there is a symbol for "the numbre of inner cell"? (e.g. n_b_cells for boundary mass flux)

Best regares,
Tsubasa

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

Posted: Mon Sep 06, 2021 12:14 pm
by Tsubasa
Hello Yvan,

I would like to let you know that,
to overrite instant fields to average fields,
I finally used this code, which I think it is correct,

Code: Select all

void
cs_user_initialization(cs_domain_t     *domain)
{
  // for velocity
  cs_field_t *vel = cs_field_by_name("velocity");
  cs_field_t *vel_m = cs_field_by_name("meanVel");
  cs_lnum_t n_vals = cs_glob_mesh->n_cells * vel->dim;  // n_cells * 3 for vector field
  for (cs_lnum_t i = 0; i < n_vals; i++) {
  vel->val[i] = vel_m->val[i];
 }

  // for pressure 
  cs_field_t *pressure = cs_field_by_name("pressure");
  cs_field_t *pressure_m = cs_field_by_name("meanPre");
  for (cs_lnum_t i = 0; i < cs_glob_mesh->n_cells; i++) {
  pressure->val[i] = pressure_m->val[i];
 }

  // for innar mass flux
  cs_field_t *inner_mass_flux = cs_field_by_name("inner_mass_flux");
  cs_field_t *inner_mass_flux_m = cs_field_by_name("inner_mass_flux_mean");
  for (cs_lnum_t i = 0; i < cs_glob_mesh->n_cells; i++) {
  inner_mass_flux->val[i] = inner_mass_flux_m->val[i];
 }

  // for boundary mass flux
  cs_field_t *boundary_mass_flux = cs_field_by_name("boundary_mass_flux");
  cs_field_t *boundary_mass_flux_m = cs_field_by_name("boundary_mass_flux_mean");
  for (cs_lnum_t i = 0; i < cs_glob_mesh->n_b_cells; i++) {
  boundary_mass_flux->val[i] = boundary_mass_flux_m->val[i];
 }
}
This code works, and it was succeeded to overwrite them.
However, strange things happned.
When I check the scalar transport, the scalar does not flow along with the average flow.
It goes along with the instant field at last time step before our code was applied.
a.png
b.png
c.png
As you can see, the instant velocity field is replaced with average flow,
but the scalr transport goes to different direction.
And finally the scalar magnitude become divergence like 1.0e10 and -1.0e10 in almost all over the cells as can be seen in next post.

For scalar transport, I did
1st: noram simulation to calculate average flow without scalar
2nd: simulation with frozen velocity field without scalar just in case to make sure overrwiting
3rd: simulation wirh frozen velocity field with scalar transport.
Would you give me tips?

Best regards,
Tsubasa

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

Posted: Mon Sep 06, 2021 3:27 pm
by Tsubasa
This is a scalar transport which became divergent finally.
d.png

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

Posted: Mon Sep 06, 2021 6:41 pm
by Yvan Fournier
Hello,

You code is almost correct, but for the mass fluxes:

- The loop shoud be on n_i_faces (not n_cells) for the interior faces mass flow
- The loop shoud be on n_b_faces (not n_b_cells) for the boundary faces mass flow

Once this is corrected let's see how the code behaves.

Also, the pressure should not be important (I think), because in a frozen velocity scheme, it is not required anymore (unless you compute some specific pressure-depedent forces).

Best regards,

Yvan

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

Posted: Tue Sep 07, 2021 10:24 am
by Tsubasa
Hello Yvan,

Thanks to your help, I finally succeeded in getting scalar transport on frozen average field.
Thank you so much for your help.

I post the code just in case when someone want to do same thing;

Code: Select all

void
cs_user_initialization(cs_domain_t     *domain)
{
  // for velocity
  cs_field_t *vel = cs_field_by_name("velocity");
  cs_field_t *vel_m = cs_field_by_name("meanVel");
  cs_lnum_t n_vals = cs_glob_mesh->n_cells * vel->dim;  // n_cells * 3 for vector field
  for (cs_lnum_t i = 0; i < n_vals; i++) {
  vel->val[i] = vel_m->val[i];
 }

  // for pressure 
  //cs_field_t *pressure = cs_field_by_name("pressure");
  //cs_field_t *pressure_m = cs_field_by_name("meanPre");
  //for (cs_lnum_t i = 0; i < cs_glob_mesh->n_cells; i++) {
  //pressure->val[i] = pressure_m->val[i];
 //}

  // for innar mass flux
  cs_field_t *inner_mass_flux = cs_field_by_name("inner_mass_flux");
  cs_field_t *inner_mass_flux_m = cs_field_by_name("inner_mass_flux_mean");
  for (cs_lnum_t i = 0; i < cs_glob_mesh->n_i_faces ; i++) {
  inner_mass_flux->val[i] = inner_mass_flux_m->val[i];
 }

  // for boundary mass flux
  cs_field_t *boundary_mass_flux = cs_field_by_name("boundary_mass_flux");
  cs_field_t *boundary_mass_flux_m = cs_field_by_name("boundary_mass_flux_mean");
  for (cs_lnum_t i = 0; i < cs_glob_mesh->n_b_faces ; i++) {
  boundary_mass_flux->val[i] = boundary_mass_flux_m->val[i];
 }
}
Best regards,
Tsubasa

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

Posted: Tue Sep 21, 2021 2:13 pm
by Tsubasa
Hello Yvan,

Let me check a thing for scalar transport.

Thanks for you, I suceeded to caculate scalar transport on frozen velocity.
Now, I am littele bit confused about "Prescribed (outgoing) flux" for scalar in GUI.
b.png
In here, I want scalar to be flow out naturally, not forcibly.
So I just impose Neumann condition (0 gradient) for outlet boundary. In this case, should I put "0.0" in "flux" in GUI, shouldn't I? or Does "0.0" mean "no flux" (equal to wall condition) for outlet boudanry?

Best regards,
Tsubasa

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

Posted: Tue Nov 08, 2022 5:36 am
by Tsubasa
Hello Yvan,

Sorry for restarting from old posts.

These days I had some problems when I overwrite the velocity field with the average velocity field.
Replacing velocity with the average velocity works. No problem happened here.
However, even though it works, scalar transport cannot be solved based on the average velocity field.
Surprisingly, it looks like that scalar transport is solved based on the velocity field which has only 0 velocity magnitude.

Could you check what happened here as soon as possible?
files.zip
(112.43 KiB) Downloaded 67 times

The first picture is the velocity field, which is frozen and is already replaced with the average velocity.
The second picture is scalar transport. As you can see, the scalar is not transported with the flow.
I think some kind of errors happened when replacing velocity.
Sometimes I succeeded in calculating scalar transport in the same procedure but sometimes this problem happened.
flow.png
scalar.png
Best regards,
Hamada

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

Posted: Wed Nov 09, 2022 8:29 pm
by Yvan Fournier
Hello,

I won't have much time before a few days, but can you try:

-step 1; run overs 0 additional iterations, while reading the auxiliary restart file, so that the mean velocity is read, and saved as the instant velocity of the new computation.

- step 2, run a restart from that intermediate computation, starting from the standard velocity, and try activating/deactivating reading the auxiliary restart file (which contains the mass fluxes) to see if this has some influence.

Best regards,

Yvan

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

Posted: Tue Nov 22, 2022 6:20 pm
by Tsubasa
Hello,

I tried as you said, but unfortunately the same problem happened.

Best regards,
Hamada

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

Posted: Wed Nov 23, 2022 1:36 am
by Yvan Fournier
Hello,

Could you post the whole run directories (both the one containing the initial computation and the one containing the restart) ?

With the provided files alone, I cannot see what is wrong.

Regards,

Yvan