Non-diffusion volume heat source settings

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
Steven Tang
Posts: 3
Joined: Thu May 12, 2022 6:38 am

Non-diffusion volume heat source settings

Post by Steven Tang »

Dear all,

I am a newbie to code-saturne,recently,I'm learning how to set the non-diffusion volume heat source.

For example, I define a temp source terms zone(1<x<2,1<z<2) on the GUI page, and name it "cooler". In the "cs_user_source_terms-base .c" file, I did the following . However,this volumetric heat source is diffuse,which could affect the temperature of the area around it. I want this volume heat source to remain in the area I defined, and it will not affect the temperature of the surrounding area. Only when the fluid passes through the area, the effect of the volume heat source will be reflected, which will change the fluid temperature passing through the area.
Can anyone give me some code modification suggestions if it is convenient?
Besides,If it is convenient, can you tell me how to call the current time step, such as using "ttcabs" in Fortran, and how to express it in C language.
Thank you very much for any ideas on this matter
Kind regards


#include "cs_defs.h"
#include <assert.h>
#include <math.h>
#include <ple_coupling.h>
#include "cs_headers.h"
cs_user_source_terms(cs_domain_t *domain,
int f_id,
cs_real_t *st_exp,
cs_real_t *st_imp)
const cs_field_t *f = cs_field_by_id(f_id);
const cs_lnum_t n_cells = cs_glob_mesh->n_cells;
const cs_real_t *cell_f_vol = cs_glob_mesh_quantities->cell_vol;
int var_f_id = cs_field_get_key_int(f, cs_field_key_id("first_moment_id"));
const cs_real_t *cpro_rom = CS_F_(rho)->val;
if (f == CS_F_(t)) {
const cs_var_cal_opt_t *var_cal_opt
= cs_field_get_key_struct_const_ptr(f,
if (var_cal_opt->iwarni >= 1)
bft_printf(" User source terms for variable %s\n",

// main code here!!!!!!!!!!!!!!!!!!!!!!!!

const cs_zone_t *z1 = cs_volume_zone_by_name_try("cooler");
if (z1 != NULL) {

for (cs_lnum_t i = 0; i < z1->n_elts; i++) {
cs_lnum_t c_id = z1->elt_ids;
st_imp[c_id] = -100;

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

Re: Non-diffusion volume heat source settings

Post by Yvan Fournier »


There is no option to cut diffusion for the source term only. So in your case, you would need to set the diffusion (and the turbulent diffusion) to zero on one layer of cells just upstream of the source term zone (doing it at the faces would be better, but I do not think thee is a user option for that, so it would require modifying the code).

Laminar diffusivity may be defined using either the GUI or user-defined functions, but to change the turbulent viscosity, you need to use a user-defined function.

Best regards,

Post Reply