Rough wall boundary conditions by cs_user_boundary_conditions.c

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
konst
Posts: 30
Joined: Sun Sep 17, 2017 7:41 pm

Rough wall boundary conditions by cs_user_boundary_conditions.c

Post 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.
Attachments
cs_user_boundary_conditions.c
(7.87 KiB) Downloaded 196 times
Yvan Fournier
Posts: 4077
Joined: Mon Feb 20, 2012 3:25 pm

Re: Rough wall boundary conditions by cs_user_boundary_conditions.c

Post 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
konst
Posts: 30
Joined: Sun Sep 17, 2017 7:41 pm

Re: Rough wall boundary conditions by cs_user_boundary_conditions.c

Post 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
Yvan Fournier
Posts: 4077
Joined: Mon Feb 20, 2012 3:25 pm

Re: Rough wall boundary conditions by cs_user_boundary_conditions.c

Post 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
konst
Posts: 30
Joined: Sun Sep 17, 2017 7:41 pm

Re: Rough wall boundary conditions by cs_user_boundary_conditions.c

Post by konst »

Thanks for your reply, Yvan!

That approach works for me! )

Best regards,
Konstantin
Post Reply