My Project
programmer's documentation
Define user laws for physical properties

Introduction

This page provides examples of code blocks that may be used to define physical variable laws.

Warning

It is forbidden to modify turbulent viscosity visct here (a specific subroutine is dedicated to that: usvist)

  • icp = 1 must have been specified in usipsu if we wish to define a variable specific heat cpro_cp (otherwise: memory overwrite).
  • the kivisl field integer key (diffusivity_id) must have been specified in usipsu if we wish to define a variable viscosity viscls.
Remarks
  • This routine is called at the beginning of each time step Thus, AT THE FIRST TIME STEP (non-restart case), the only values initialized before this call are those defined
  • We may define here variation laws for cell properties, for:
    • density: rom kg/m3
    • density at boundary faces: romb kg/m3)
    • molecular viscosity: cpro_viscl kg/(m s)
    • specific heat: cpro_cp J/(kg degrees)
    • diffusivities associated with scalars: cpro_vscalt kg/(m s)
Warning
: if the scalar is the temperature, cpro_vscalt corresponds to its conductivity (Lambda) in W/(m K)

The types of boundary faces at the previous time step are available (except at the first time step, where arrays itypfb and itrifb have not been initialized yet)

It is recommended to keep only the minimum necessary in this file (i.e. remove all unused example code)

Molecular viscosity varying with temperature

The values of the molecular viscosity are provided as a function of the temperature. All variables are evaluated at the cell centers.

Here is the corresponding code:

! To refer to the user-defined scalar number 2 instead, for example, use
! ivart = isca(2)
ivart = isca(itempk)
call field_get_val_s(ivarfl(ivart), cvar_scalt)
! --- Molecular dynamic viscosity 'cpro_viscl'
! (physical properties at the cell centers)
call field_get_val_s(iviscl, cpro_viscl)
! --- User-defined coefficients for the selected law.
! The values hereafter are provided as a mere example. They
! are physically meaningless.
varam = -3.4016d-9
varbm = 6.2332d-7
varcm = -4.5577d-5
vardm = 1.6935d-3
! --- Molecular dynamic viscosity mu at the cell centers, kg/(m s)
! In this example, mu is provided as a function of the temperature T:
! mu(T) = T *( T *( am * T + bm )+ cm )+ dm
! that is:
! cpro_viscl(iel) = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm
do iel = 1, ncel
xvart = cvar_scalt(iel)
cpro_viscl(iel) = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm
enddo

Molecular volumetric viscosity varying with temperature

The values of the molecular volumetric viscosity are provided as a function of the temperature. All variables are evaluated at the cell centers.

Here is the corresponding code:

ivart = isca(itempk)
call field_get_val_s(ivarfl(ivart), cvar_scalt)
! --- Molecular volumetric viscosity
if (iviscv.ge.0) then
call field_get_val_s(iviscv, cpro_viscv)
else
cpro_viscv => null()
endif
! --- Stop if the volumetric viscosity has not been defined as variable
if (iviscv.lt.0) then
write(nfecra,2000) iviscv
call csexit (1)
endif
! --- User-defined coefficients for the selected law.
! The values provided hereafter are provided as a mere example. They
! are physically meaningless.
varam = -3.4016d-9
varbm = 6.2332d-7
varcm = -4.5577d-5
vardm = 1.6935d-3
! --- Molecular dynamic volumetric viscosity kappa at the cell centers, kg/(m s)
! In this example, kappa is provided as a function of the temperature T:
! kappa(T) = T *( T *( am * T + bm )+ cm )+ dm
! that is:
! cpro_viscv(iel) = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm
do iel = 1, ncel
xvart = cvar_scalt(iel)
cpro_viscv(iel) = xvart*(xvart*(varam*xvart+varbm)+varcm)+vardm
enddo

Isobaric specific heat varying with temperature

The values of the isobaric specific heat values are provided as a function of the temperature. All variables are evaluated at the cell centers.

Warning
: do not discard the call to the subroutine 'usthht' at the end of this example: its purpose is to calculate the isochoric specific heat. Indeed, this variable needs to be computed from the isobaric specific heat using the thermodynamics laws.

Here is the corresponding code:

ivart = isca(itempk)
call field_get_val_s(ivarfl(ivart), cvar_scalt)
! --- Isobaric specific heat
if (icp.ge.0) call field_get_val_s(icp, cpro_cp)
! --- Stop if the isobaric or isochoric specific heat (cpro_cp or cpro_cv) has not
! been defined as variable
if (icp.lt.0) then
write(nfecra,1000) icp
call csexit (1)
endif
if (icv.lt.0) then
write(nfecra,1001) icv
call csexit (1)
endif
! --- User-defined coefficients for the selected law.
! The values provided hereafter are provided as a mere example. They
! are physically meaningless.
varac = 0.00001d0
varbc = 1000.0d0
! --- Isobaric specific heat cpro_cp at the cell centers, J/(kg degree)
! In this example, cpro_cp is provided as a function of the temperature T:
! cpro_cp(T) = ac * T + ab
! that is:
! cpro_cp(iel) = varac*xvart+varbc
do iel = 1, ncel
xvart = cvar_scalt(iel)
cpro_cp(iel) = varac*xvart + varbc
enddo
! --- The isochoric specific heat is deduced from the isobaric specific heat
call field_get_val_s(icv, cpro_cv)
call field_get_val_s(igmxml, mix_mol_mas)
call cs_cf_thermo_cv(cpro_cp, mix_mol_mas, cpro_cv, ncel)

Molecular thermal conductivity varying with temperature

The values of the molecular thermal conductivity are provided as a function of the temperature. All variables are evaluated at the cell centers.

Here is the corresponding code:

ivart = isca(itempk)
call field_get_val_s(ivarfl(ivart), cvar_scalt)
! --- Molecular thermal conductivity
call field_get_key_int(ivarfl(isca(itempk)), kivisl, ifcvsl)
if (ifcvsl.ge.0) then
call field_get_val_s(ifcvsl, cpro_vtmpk)
else
cpro_vtmpk => null()
endif
! --- Stop if the molecular thermal conductivity has not
! been defined as variable
if (ifcvsl.lt.0) then
write(nfecra,1010) itempk
call csexit (1)
endif
! --- User-defined coefficients for the selected law.
! The values provided hereafter are provided as a mere example. They
! are physically meaningless.
varal = -3.3283d-7
varbl = 3.6021d-5
varcl = 1.2527d-4
vardl = 0.58923d0
! --- Molecular thermal conductivity lambda at the cell centers, W/(m degree)
! In this example, lambda is provided as a function of the temperature T:
! lambda(T) = T *( T *( al * T + bl )+ cl )+ dl
! that is:
! cpro_vtmpk(iel) = xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl
do iel = 1, ncel
xvart = cvar_scalt(iel)
cpro_vtmpk(iel) = (xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl)
enddo

Molecular diffusivity of user-defined scalars varying with temperature

The molecular diffusivity can be set for all the user-defined scalars except:

  • temperature and enthalpy (already dealt with above: for these variables, the 'diffusivity' is the thermal conductivity)
  • variances of the fluctuations of another scalar variable (the diffusivity is assumed to be equal to that of the associated scalar) The values of the molecular diffusivity are provided as a function of the temperature. All variables are evaluated at the cell centers.

Here is the corresponding code:

! --- Loop on the scalars
do iscal = 1, nscaus
! --- If the scalar is the temperature, it is marked by ith = 1
! so that it will be skipped.
ith = 0
if (iscal.eq.itempk) ith = 1
! --- If the variable represents the variance of the fluctuations of
! another scalar variable (iscavr <= 0), it is simply skipped.
if (ith.eq.0.and.iscavr(iscal).le.0) then
! --- Here, iscal points to any scalar variable except the temperature,
! the enthalpy and the variance of the fluctuations of another
! scalar variable.
ivart = isca(itempk)
call field_get_val_s(ivarfl(ivart), cvar_scalt)
! --- Molecular diffusivity of the current scalar iscal
call field_get_key_int(ivarfl(isca(iscal)), kivisl, ifcvsl)
if (ifcvsl.ge.0) then
call field_get_val_s(ifcvsl, cpro_vscal)
else
cpro_vscal => null()
endif
! --- Stop if the molecular diffusivity has not been defined as variable
if (ifcvsl.lt.0) then
write(nfecra,1010) iscal
call csexit (1)
endif
! --- User-defined coefficients for the selected law.
! The values provided hereafter are provided as a mere example. They
! are physically meaningless.
varal = -3.3283d-7
varbl = 3.6021d-5
varcl = 1.2527d-4
vardl = 0.58923d0
! --- Molecular diffusivity lambda at the cell centers, kg/(m s)
! In this example, lambda is provided as a function of the temperature T:
! lambda(T) = T *( T *( al * T + bl )+ cl )+ dl
! that is:
! cpro_vscal(iel) = xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl
do iel = 1, ncel
xvart = cvar_scalt(iel)
cpro_vscal(iel) = (xvart*(xvart*(varal*xvart+varbl)+varcl)+vardl)
enddo
endif
! --- End of the tests on ith and iscavr
enddo
! --- End of the loop on the scalars
cs_cf_thermo_cv
void cs_cf_thermo_cv(cs_real_t *cp, cs_real_t *xmasml, cs_real_t *cv, cs_lnum_t l_size)
Compute the isochoric specific heat:
Definition: cs_cf_thermo.c:847