1 /*============================================================================
2 * This function is called each time step to define physical properties
3 *============================================================================*/
4
5 /* VERS */
6
7 /*
8 This file is part of Code_Saturne, a general-purpose CFD tool.
9
10 Copyright (C) 1998-2021 EDF S.A.
11
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 2 of the License, or (at your option) any later
15 version.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
24 Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26
27 /*----------------------------------------------------------------------------*/
28
29 #include "cs_defs.h"
30
31 /*----------------------------------------------------------------------------
32 * Standard C library headers
33 *----------------------------------------------------------------------------*/
34
35 #include <assert.h>
36 #include <math.h>
37
38 /*----------------------------------------------------------------------------
39 * PLE library headers
40 *----------------------------------------------------------------------------*/
41
42 #include <ple_coupling.h>
43
44 /*----------------------------------------------------------------------------
45 * Local headers
46 *----------------------------------------------------------------------------*/
47
48 #include "cs_headers.h"
49
50 /*----------------------------------------------------------------------------*/
51
52 BEGIN_C_DECLS
53
54 /*----------------------------------------------------------------------------*/
55 /*!
56 * \file cs_user_source_terms-momentum.c
57 *
58 * \brief Base examples for additional right-hand side source terms for
59 * momentum equations.
60 *
61 * See the reference \ref cs_user_source_terms.c for documentation.
62 */
63 /*----------------------------------------------------------------------------*/
64
65 /*============================================================================
66 * User function definitions
67 *============================================================================*/
68
69 /*----------------------------------------------------------------------------*/
70 /*!
71 * \brief Function called at each time step to define source terms.
72 *
73 * \param[in, out] domain pointer to a cs_domain_t structure
74 * \param[in] f_id field id of the variable
75 * \param[out] st_exp explicit source term
76 * \param[out] st_imp implicit part of the source term
77 */
78 /*----------------------------------------------------------------------------*/
79
80 void
cs_user_source_terms(cs_domain_t * domain,int f_id,cs_real_t * st_exp,cs_real_t * st_imp)81 cs_user_source_terms(cs_domain_t *domain,
82 int f_id,
83 cs_real_t *st_exp,
84 cs_real_t *st_imp)
85 {
86 CS_NO_WARN_IF_UNUSED(domain);
87
88 /*! [st_meta] */
89 /* field structure */
90 const cs_field_t *f = cs_field_by_id(f_id);
91
92 /* mesh quantities */
93 const cs_lnum_t n_cells = cs_glob_mesh->n_cells;
94 const cs_real_t *cell_f_vol = cs_glob_mesh_quantities->cell_vol;
95
96 /* density */
97 const cs_real_t *cpro_rom = CS_F_(rho)->val;
98 /*! [st_meta] */
99
100 /* Example of arbitrary source term for component u:
101 *
102 * S = A * u + B
103 *
104 * appearing in the equation under the form
105 *
106 * rho*du/dt = S (+ standard Navier-Stokes terms)
107 *
108 * In the following example:
109 * A = - rho * CKP
110 * B = XMMT
111 *
112 * with:
113 * CKP = 1.0 [1/s] (return term on velocity)
114 * MMT = 100.0 [kg/m2/s2] (momentum production by volume and time unit)
115 *
116 * which yields:
117 * st_imp[i][0][0] = cell_f_vol[i] * A = - cell_f_vol[i]*(rho*CKP)
118 * st_exp[i][0] = cell_f_vol[i] * B = cell_f_vol[i]*(XMMT)
119 */
120
121 /*! [st_momentum_e_1] */
122 if (f == CS_F_(vel)) { /* velocity */
123
124 /* cast to 3D vectors for readability */
125 cs_real_3_t *_st_exp = (cs_real_3_t *)st_exp;
126 cs_real_33_t *_st_imp = (cs_real_33_t *)st_imp;
127
128 /* Density */
129
130 const cs_real_t ckp = 10.0;
131 const cs_real_t xmmt = 100.0;
132
133 for (cs_lnum_t i = 0; i < n_cells; i++) {
134 _st_imp[i][0][0] = - cell_f_vol[i] * cpro_rom[i] * ckp;
135 _st_exp[i][0] = cell_f_vol[i] * cpro_rom[i] * xmmt;
136 }
137
138 }
139 /*! [st_momentum_e_1] */
140
141 /* Example of boussinesq source term. */
142
143 /*! [boussinesq_st] */
144 if (f == CS_F_(vel) && CS_F_(t) != NULL) { /* velocity and temperature */
145
146 /* expansion coefficient and reference density */
147
148 const cs_real_t beta = 1.;
149 const cs_real_t ro0 = cs_glob_fluid_properties->ro0;
150 const cs_real_t t0 = cs_glob_fluid_properties->t0;
151
152 /* get temperature */
153
154 const cs_real_t *cvar_temperature = CS_F_(t)->val;
155
156 /* source term (in z direction here) */
157
158 cs_real_3_t *_st_exp = (cs_real_3_t *)st_exp;
159
160 for (cs_lnum_t i = 0; i < n_cells; i++) {
161 _st_exp[i][2] = cell_f_vol[i] * ro0 * beta * (cvar_temperature[i]-t0);
162 }
163
164 }
165 /*! [boussinesq_st] */
166 }
167
168 /*----------------------------------------------------------------------------*/
169
170 END_C_DECLS
171