Boundary definition : condition

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
SimBu
Posts: 30
Joined: Tue Sep 13, 2022 4:13 pm

Boundary definition : condition

Post by SimBu »

Dear users,

I would like to define a Neumann condition which is only activated under a temperature threshold (I was thinking of getting the temperature from a balance variable).
Let me be clearer by taking an example :
I want to define a wall that heat 100W/m² only if the average room temperature is below 30 degrees.

For now I managed to code what follow in cs_user_boundary.f90 :

Code: Select all

! From a boundary, get the mesh faces that fit
call getfbr('heating_wall', nlfac, lstfac4)
!==========
! get the number of fields
  call field_get_n_fields(n_fields)

do ilelt = 1, nlfac

  ifac = lstfac4(ilelt)
  !get the neighboor cells
  iel = ifabor(ifac)

!define the face as a wall
  itypfb(ifac) = iparoi


  ! Handle temperature
  call field_get_id("temperature", scal_id)
  call field_get_key_id("scalar_id", keysca)
  call field_get_key_int(scal_id, keysca, iscal)
  call balance_by_zone(box[], "temperature")

!MODIFYING VALUES : Neumann condition on the wall
  if (ntcabs.gt.1 .and. AVERAGE_TEMPERATURE.gt.30 .and. nscal.gt.0) then     !AVERAGE_TEMPERATURE would be the balanced_by_zone variable)
    rcodcl(ifac,iscal,3) = 0
  else if (nscal.gt.0) then
    rcodcl(ifac,iscal,3) = -100
  endif


enddo

But I didn't find in the documentation how could I call the AVERAGE_TEMPERATURE, I was thinking of

Code: Select all

call balance_by_zone(box[a,b,c,x,y,z], "temperature")
but this subroutine do not return variable...
  • How can I get a control of a field in order to impose conditions on it?
  • By the way, is it possible to impose neumann condition on an inlet, for the temperature? (As far as I know, it is not possible from the gui)
  • I have tried to implement in an user fonction, but is it possible to do it from the gui and define Neumann (user law) with some conditions on balanced variable ?
I will be glad if someone has some answer,

Regards,
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Boundary definition : condition

Post by Yvan Fournier »

Hello,

To compute the average (spatial) room temperature, you can use :

Code: Select all

cs_real_t t_mean = cs_gmean(cs_glob_mesh->n_cells, cs_glob_mesh_quantities->cell_vol, CS_F_(t)->val);
In C. In Fortran, you need to code your own sum (and not forget the parallel sum).

You may be able to impose a Neumann condition an a scalar for an inlet with user-defined routines, but that may be risky (and probably amount to prescribing the diffusive flux, and not controlling the convective flux).

Best regards,

Yvan
SimBu
Posts: 30
Joined: Tue Sep 13, 2022 4:13 pm

Re: Boundary definition : condition

Post by SimBu »

Hi Yvan,
Thank you for your answer,
I didn't find anywhere the existence of this cs_gmean function, even while doing grep 'cs_gmean' in the code_saturne source files.
In wich head file is it define, to include it in my user function ?

Ok then you are right, instead of imposing a neaumann condition on a mapped inlet, it seems a lot easier to juste "unmap" it (i will just calcul the inlet temperature with the watt I have ). But I am sorry, what mean
and not forget the parallel sum
?
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Boundary definition : condition

Post by Yvan Fournier »

Hello,

it is defined in src/alge/cs_blas.h.

It was added on November 2021, so may be in version 7.1 and 7.2, but might not be present in version 7.0... In this case, you can simply copy the definition of _cs_gmean_superblock from src/alge/cs_blas.c in v7.2 to you user-defined function and call that.

Best regards,

Yvan
SimBu
Posts: 30
Joined: Tue Sep 13, 2022 4:13 pm

Re: Boundary definition : condition

Post by SimBu »

Ok great, found it ! Ok, obviously parallel operation for multi-threading... Ok thank you I will try to manage with the C function
Post Reply