/usr/share/code_saturne/user_examples/cs_user_parameters-time_moments.c is in code-saturne-data 4.2.0+repack-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | /*============================================================================
* User subroutines for input of calculation parameters.
*============================================================================*/
/* Code_Saturne version 4.2.0 */
/*
This file is part of Code_Saturne, a general-purpose CFD tool.
Copyright (C) 1998-2015 EDF S.A.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*----------------------------------------------------------------------------*/
#include "cs_defs.h"
/*----------------------------------------------------------------------------
* Standard C library headers
*----------------------------------------------------------------------------*/
#include <assert.h>
#include <math.h>
#if defined(HAVE_MPI)
#include <mpi.h>
#endif
/*----------------------------------------------------------------------------
* PLE library headers
*----------------------------------------------------------------------------*/
#include <ple_coupling.h>
/*----------------------------------------------------------------------------
* Local headers
*----------------------------------------------------------------------------*/
#include "bft_mem.h"
#include "bft_error.h"
#include "bft_printf.h"
#include "fvm_writer.h"
#include "cs_base.h"
#include "cs_field.h"
#include "cs_gui_util.h"
#include "cs_field_pointer.h"
#include "cs_field_operator.h"
#include "cs_math.h"
#include "cs_mesh.h"
#include "cs_mesh_location.h"
#include "cs_mesh_quantities.h"
#include "cs_halo.h"
#include "cs_halo_perio.h"
#include "cs_log.h"
#include "cs_parameters.h"
#include "cs_physical_constants.h"
#include "cs_prototypes.h"
#include "cs_rotation.h"
#include "cs_time_moment.h"
#include "cs_time_step.h"
#include "cs_turbomachinery.h"
#include "cs_selector.h"
#include "cs_post.h"
/*----------------------------------------------------------------------------
* Header for the current file
*----------------------------------------------------------------------------*/
#include "cs_prototypes.h"
/*----------------------------------------------------------------------------*/
BEGIN_C_DECLS
/*============================================================================
* User function definitions
*============================================================================*/
/*----------------------------------------------------------------------------
* User function example with simple data computation.
*
* This function computes a sum of 2 specific user scalars defined on cells.
*
* parameters:
* input <-- pointer to simple data array (here, containing a single
* character ket)
* vals --> pointer to values (size: n_local elements*dimension)
* radial velocity for input 0, tangential for input 1, and
* axial for input 2
*----------------------------------------------------------------------------*/
/*! [tmom_simple_sum_data] */
static void
_simple_data_sum(const void *input,
cs_real_t *vals)
{
const int location_id = CS_MESH_LOCATION_CELLS;
const cs_lnum_t n_elts = cs_mesh_location_get_n_elts(location_id)[0];
const cs_real_t *s1 = cs_field_by_name("species_1")->val;
const cs_real_t *s2 = cs_field_by_name("species_2")->val;
for (cs_lnum_t i = 0; i < n_elts; i++) {
vals[i] = s1[i] + s2[i];
}
}
/*! [tmom_simple_sum_data] */
/*----------------------------------------------------------------------------
* User function for velocity values for moments computation.
*
* With a rotating frame of reference, the velocity is separated into
* radial, tangential, and axial components.
*
* parameters:
* input <-- pointer to simple data array (here, containing a single
* character ket)
* vals --> pointer to values (size: n_local elements*dimension)
* radial velocity for input 0, tangential for input 1, and
* axial for input 2
*----------------------------------------------------------------------------*/
/*! [tmom_velocity_rotation_data] */
static void
_velocity_moment_data(const void *input,
cs_real_t *vals)
{
const char key = *((const char *)input);
const int location_id = CS_MESH_LOCATION_CELLS;
const cs_lnum_t n_elts = cs_mesh_location_get_n_elts(location_id)[0];
const cs_real_3_t *vel = (const cs_real_3_t *)(CS_F_(u)->val);
const cs_real_3_t *restrict cell_cen
= (const cs_real_3_t *restrict)cs_glob_mesh_quantities->cell_cen;
const cs_rotation_t *rot = cs_glob_rotation;
double omgnrm = fabs(rot->omega);
/* Axial, tangential and radial unit vectors */
cs_real_3_t e_ax = {rot->axis[0], rot->axis[1], rot->axis[2]};
for (cs_lnum_t i = 0; i < n_elts; i++) {
cs_real_3_t e_th;
cs_rotation_velocity(rot, cell_cen[i], e_th);
double xnrm = sqrt(cs_math_3_square_norm(e_th));
e_th[0] /= xnrm;
e_th[1] /= xnrm;
e_th[2] /= xnrm;
cs_real_3_t e_r;
cs_rotation_coriolis_v(rot, -1., e_th, e_r);
xnrm = sqrt(cs_math_3_square_norm(e_r));
e_r[0] /= xnrm;
e_r[1] /= xnrm;
e_r[2] /= xnrm;
/* Radius */
cs_real_t xr = cs_math_3_dot_product(cell_cen[i], e_r);
/* Axial, tangential and radial components of velocity */
cs_real_t xva = vel[i][0]*e_ax[0] + vel[i][1]*e_ax[1] + vel[i][2]*e_ax[2];
cs_real_t xvt = vel[i][0]*e_th[0] + vel[i][1]*e_th[1] + vel[i][2]*e_th[2];
cs_real_t xvr = vel[i][0]*e_r[0] + vel[i][1]*e_r[1] + vel[i][2]*e_r[2];
/* Entrainment velocity is removed */
xvt -= omgnrm*xr;
/* Store value */
if (key == 'r')
vals[i] = xvr;
else if (key == 't')
vals[i] = xvt;
else if (key == 'a')
vals[i] = xva;
}
}
/*! [tmom_velocity_rotation_data] */
/*----------------------------------------------------------------------------*/
/*!
* \brief Define time moments.
*
* This function is called at the setup stage, once user and most model-based
* fields are defined, and before fine control of field output options
* is defined.
*/
/*----------------------------------------------------------------------------*/
void
cs_user_time_moments(void)
{
/*
* We compute temporal means of the type <f1*f2*f3*...*fn>
* The fi's are variables defined by fields of a same location
* (usually cells or boundary faces)
* The parameters for time_moment_define_by_field_ids are:
* name <-- name of associated moment
* n_fields <-- number of associated fields
* field_id <-- ids of associated fields
* component_id <-- ids of matching field components (-1 for all)
* type <-- moment type (CS_TIME_MOMENT_MEAN
* or CS_TIME_MOMENT_VARIANCE)
* nt_start <-- starting time step (or -1 to use t_start)
* t_start <-- starting time
* restart_mode <-- behavior in case or restart:
* CS_TIME_MOMENT_RESTART_RESET,
* CS_TIME_MOMENT_RESTART_AUTO, or
* CS_TIME_MOMENT_RESTART_EXACT
* restart_name <-- name in previous run, NULL for default
*/
{
/* Moment <U> calculated starting from time step 1000. */
/*! [tmom_u] */
int moment_f_id[] = {CS_F_(u)->id};
int moment_c_id[] = {-1};
int n_fields = 1;
cs_time_moment_define_by_field_ids("U_mean",
n_fields,
moment_f_id,
moment_c_id,
CS_TIME_MOMENT_MEAN,
1000, /* nt_start */
-1, /* t_start */
CS_TIME_MOMENT_RESTART_AUTO,
NULL);
/*! [tmom_u] */
}
/*! [tmom_rho_u] */
{
/* Moment <U> calculated starting from time step 1000. */
int moment_f_id[] = {CS_F_(rho)->id, CS_F_(u)->id};
int moment_c_id[] = {-1, -1};
int n_fields = 2;
cs_time_moment_define_by_field_ids("U_mean",
n_fields,
moment_f_id,
moment_c_id,
CS_TIME_MOMENT_MEAN,
1000, /* nt_start */
-1, /* t_start */
CS_TIME_MOMENT_RESTART_AUTO,
NULL);
}
/*! [tmom_rho_u] */
{
/* Moment <u v> is calculated from physical time 20 s
(reinitialized at each restart). */
/*! [tmom_rho_u_v] */
int moment_f_id[] = {CS_F_(rho)->id, CS_F_(u)->id, CS_F_(u)->id};
int moment_c_id[] = {-1, 0, 1};
int n_fields = 3;
cs_time_moment_define_by_field_ids("rho_u_v_mean",
n_fields,
moment_f_id,
moment_c_id,
CS_TIME_MOMENT_MEAN,
-1, /* nt_start */
20.0, /* t_start */
CS_TIME_MOMENT_RESTART_RESET,
NULL);
/*! [tmom_rho_u_v] */
}
/* Moments for sum of user scalars "species_1" and "species_2". */
{
/*! [tmom_simple_sum] */
const char *sum_comp_name[] = {"species_sum_mean", "species_sum_variance"};
cs_time_moment_type_t m_type[] = {CS_TIME_MOMENT_MEAN,
CS_TIME_MOMENT_VARIANCE};
for (int i = 0; i < 2; i++) {
cs_time_moment_define_by_func(sum_comp_name[i],
CS_MESH_LOCATION_CELLS,
1, /* field dimension */
_simple_data_sum, /* data_func */
NULL, /* data_input */
NULL, /* w_data_func */
NULL, /* w_data_input */
m_type[i],
1000, /* nt_start */
-1, /* t_start */
CS_TIME_MOMENT_RESTART_AUTO,
NULL);
}
/*! [tmom_simple_sum] */
}
/* Moments for radial, tangential, and axial velocity components
require extracting those components first, so a more advanced
function is needed. */
{
/*! [tmom_velocity_rotation] */
const char *vel_comp_name[] = {"Wr_moy", "Wt,moy", "Wa_moy"};
/* Data input must be "static" so it can be used in later calls */
static char vel_comp_input[3] = {'r', 't', 'a'};
for (int comp_id = 0; comp_id < 3; comp_id++) {
cs_time_moment_define_by_func(vel_comp_name[comp_id],
CS_MESH_LOCATION_CELLS,
1,
_velocity_moment_data, /* data_func */
&(vel_comp_input[comp_id]), /* data_input */
NULL, /* w_data_func */
NULL, /* w_data_input */
CS_TIME_MOMENT_MEAN,
74000, /* nt_start */
-1, /* t_start */
CS_TIME_MOMENT_RESTART_AUTO,
NULL);
}
/*! [tmom_velocity_rotation] */
}
}
/*----------------------------------------------------------------------------*/
END_C_DECLS
|