Page 1 of 1

Rough wall boundary conditions by cs_user_boundary_conditions.c

Posted: Mon Oct 01, 2018 2:48 pm
by konst
Hello,

I am trying to impose boundary conditions by using c-functions, but not so many examples with that. So the question is:
How to set "z0" value for rough wall? I was trying to do it similarly to a fortran code:

Code: Select all

  const int keyvar = cs_field_key_id("variable_id");
  //botom
  cs_selector_get_b_face_list("bottom", &nelts, lstelt);
  for (cs_lnum_t ilelt = 0; ilelt < nelts; ilelt++) {
    cs_lnum_t face_id = lstelt[ilelt];
    bc_type[face_id] = CS_ROUGHWALL;
    
    f = CS_F_(u);
    int ivar = cs_field_get_key_int(f, keyvar) - 1 + 0; // access to U_x 
    icodcl[ivar * n_b_faces + face_id] = 6; //3??
    rcodcl[ivar * n_b_faces + face_id] = 0.001; //roughness value z0
  }
but looks like it is a wrong way. It gives me error:

Code: Select all


First face with boundary condition definition error
  (out of 1)
  has boundary condition type 6, center (0.25, 0, 0.25)

cs_boundary_conditions.c:363: Fatal error.
Thanks for helping.

Re: Rough wall boundary conditions by cs_user_boundary_conditions.c

Posted: Tue Oct 02, 2018 1:06 am
by Yvan Fournier
Hello,

We really need to change the way we handle rough walls (using a separate field could be a good option, as it would also allow visualizing the roughness)...

In Fortran, the value for roughness for velocity is in rcodcl(ifac, iu, 3), that for scalars in rcodcl(ifac, iv, 3).

The equivalent in C would be:

Code: Select all

  const int keyvar = cs_field_key_id("variable_id");
  f = CS_F_(u);
  int ivarv = cs_field_get_key_int(f, keyvar) - 1; // access to U_x 
  //bottom
  cs_selector_get_b_face_list("bottom", &nelts, lstelt);
  for (cs_lnum_t ilelt = 0; ilelt < nelts; ilelt++) {
    cs_lnum_t face_id = lstelt[ilelt];
    bc_type[face_id] = CS_ROUGHWALL;
    rcodcl[2*n_b_faces*nvar + ivarv*n_b_faces + face_id] = 0.001; //roughness value z0
  }
Notice that I placed the access to f and computation of ivarv outside the loop (for better performance).

Best regards,

Yvan

Re: Rough wall boundary conditions by cs_user_boundary_conditions.c

Posted: Tue Oct 02, 2018 12:49 pm
by konst
Thank you for reply, Yvan!

It is still not clear to me where is the value of "nvar" come from?

Code: Select all

..
    rcodcl[2*n_b_faces*nvar + ivarv*n_b_faces + face_id] = 0.001; //roughness value z0
 ...
And I have the other question about rough wall. Maybe you can give some recommendations for first cell size in case of rough wall?

Thanks

Best regards,
Konstantin

Re: Rough wall boundary conditions by cs_user_boundary_conditions.c

Posted: Wed Oct 03, 2018 10:07 am
by Yvan Fournier
Hello,

nvar is the number of independent (in the sense of having their own boundary conditions), and intervenes here because boundary condition values are saved in a non-interleaved mode (a relic from the old Fortran indexing chosen at the beginning of the project).

As regards the recommended cell size, I'll need to check with people who used the feature, but it would make sense for the cell size to be at least a few times larger than the roughness features.

Regards,

Yvan

Re: Rough wall boundary conditions by cs_user_boundary_conditions.c

Posted: Thu Oct 04, 2018 6:18 pm
by konst
Thanks for your reply, Yvan!

That approach works for me! )

Best regards,
Konstantin