9.2
general documentation
Scaling parameters definition for electric model (cs_user_electric_scaling.cpp)

Introduction

C user function for scaling parameters definition for electric model.

Scaling parameters definition for electric model

cs_lnum_t ncel = mesh->n_cells;
cs_lnum_t ncelet = mesh->n_cells_with_ghosts;
cs_real_3_t *xyzcen = mesh_quantities->cell_cen;
cs_real_t *volume = mesh_quantities->cell_vol;
cs_lnum_t nfac = mesh->n_i_faces;
const cs_real_t *surfac = mesh_quantities->b_face_surf;
const cs_nreal_3_t *u_normal = mesh_quantities->b_face_u_normal;
const cs_real_3_t *cdgfac = mesh_quantities->i_face_cog;
const int kivisl = cs_field_key_id("diffusivity_id");
/* example of a restrike arc */
if (ielarc >= 1) {
elec_opt->couimp = 200.;
else if (cs_glob_time_step->nt_cur > 200 &&
elec_opt->couimp = 200. + 2. * (cs_glob_time_step->nt_cur - 200);
else
elec_opt->couimp = 600.;
}
if (cs_glob_time_step->nt_cur < 400 ||
elec_opt->irestrike = 0;
double econs = 1.5e5;
double coepot = 0.;
double coepoa = 1.;
double amex = 1.e30;
double aiex = -1.e30;
double emax = 0.;
int diff_id = CS_FI_(curre, 0)->get_key_int(kivisl);
auto cvar_prop = cs_field(diff_id)->get_val_s();
auto cvar_curre0 = CS_FI_(curre, 0)->get_val_s();
auto cvar_curre1 = CS_FI_(curre, 1)->get_val_s();
auto cvar_curre2 = CS_FI_(curre, 2)->get_val_s();
auto cvar_h = CS_F_(h)->get_val_s();
auto cvar_rho = CS_F_(rho)->get_val_s();
for (int iel = 0; iel < ncel; iel++) {
double xelec = cvar_curre0[iel] / cvar_prop[iel];
double yelec = cvar_curre1[iel] / cvar_prop[iel];
double zelec = cvar_curre2[iel] / cvar_prop[iel];
w1[iel] = pow(xelec * xelec + yelec * yelec + zelec * zelec, 0.5);
amex = cs::min(amex, w1[iel]);
aiex = cs::max(amex, w1[iel]);
}
cs::parall::min(amex, aiex);
bft_printf("min and max for E : %14.5E %15.4E\n", amex, aiex);
if (aiex > econs) {
elec_opt->irestrike = 1;
/* initialize restrike point coordinates */
elec_opt->restrike_point[0] = 1.e-8;
elec_opt->restrike_point[1] = 1.e-8;
elec_opt->restrike_point[2] = 1.e-8;
double diff = 0.;
double xyzmax[3] = {-1.e10, -1.e10, -1.e10};
for (int iel = 0; iel < ncel; iel++) {
diff = aiex - w1[iel];
if (diff < 1.e-6) {
emax = w1[iel];
xyzmax[0] = xyzcen[iel][0];
xyzmax[1] = xyzcen[iel][1];
xyzmax[2] = xyzcen[iel][2];
}
}
/* we can only have a single restrike point */
cs_parall_max_loc_vals(3, &emax, xyzmax);
elec_opt->restrike_point[0] = xyzmax[0];
elec_opt->restrike_point[1] = xyzmax[1];
elec_opt->restrike_point[2] = xyzmax[2];
bft_printf("restrike point : %14.5E %14.5E %14.5E\n",
elec_opt->restrike_point[0],
elec_opt->restrike_point[1],
elec_opt->restrike_point[2]);
}
if (cs_glob_time_step->nt_cur <= elec_opt->ntdcla + 30) {
double z1 = elec_opt->restrike_point[0] - 3.e-4;
double z2 = elec_opt->restrike_point[0] + 3.e-4;
if (z1 < 0.)
z1 = 0.;
if (z2 > 2.e-2)
z2 = 2.e-2;
for (int iel = 0; iel < ncel; iel++) {
if (xyzcen[iel][2] > z1 && xyzcen[iel][2] < z2) {
double rayo = elec_opt->restrike_point[0] * xyzcen[iel][0]
- elec_opt->restrike_point[1] * xyzcen[iel][1];
double denom
= pow( elec_opt->restrike_point[0] * elec_opt->restrike_point[0]
+ elec_opt->restrike_point[1] * elec_opt->restrike_point[1], 0.5);
rayo /= denom;
rayo += (xyzcen[iel][2] - elec_opt->restrike_point[2]
* xyzcen[iel][2] - elec_opt->restrike_point[2]);
rayo = pow(rayo, 0.5);
double posi = elec_opt->restrike_point[0] * xyzcen[iel][0];
if (rayo < 5.e-4 && posi <= 0.)
cvar_h[iel] = 8.e7;
}
}
}
else {
elec_opt->irestrike = 0;
}
double somje = 0.;
auto cvar_joulp = CS_F_(joulp)->get_val_s();
for (int iel = 0; iel < ncel; iel++) {
somje += cvar_joulp[iel] * volume[iel];
}
if (fabs(somje) > 1.-20)
bft_printf("imposed current %14.5E, Dpot %14.5E, Somje %14.5E\n",
somje);
double elcou = 0.;
for (int ifac = 0; ifac < nfac; ifac++) {
if (fabs(u_normal[ifac][0]) < 1.e-2 && fabs(u_normal[ifac][1]) < 1.e-2 &&
cdgfac[ifac][2] > 0.05e-2 && cdgfac[ifac][2] < 0.08e-2) {
int iel = mesh->i_face_cells[ifac][0];
elcou += cvar_curre2[iel] * u_normal[ifac][2] * surfac[ifac];
}
}
if (fabs(elcou) > 1.e-6)
elcou = fabs(elcou);
else
elcou = 0.;
if (fabs(elcou) > 1.e20)
coepoa = cs_glob_elec_option->couimp / elcou;
coepot = coepoa;
double dtj = 1.e15;
double dtjm = dtj;
double delhsh = 0.;
double cdtj = 20.;
for (int iel = 0; iel < ncel; iel++) {
if (fabs(cvar_rho[iel]) > 1.e-20)
delhsh = cvar_joulp[iel] * dt[iel]
/ cvar_rho[iel];
if (fabs(delhsh) > 1.e-20)
dtjm = cvar_h[iel] / delhsh;
else
dtjm = dtj;
dtjm = fabs(dtjm);
dtj = cs::min(dtj, dtjm);
}
double cpmx = pow(cdtj * dtj, 0.5);
coepot = cpmx;
if (coepoa > 1.05)
coepot = cpmx;
else
coepot = coepoa;
}
bft_printf(" Cpmx = %14.5E\n", cpmx);
bft_printf(" COEPOA = %14.5E\n", coepoa);
bft_printf(" COEPOT = %14.5E\n", coepot);
bft_printf(" Dpot rescaled = %14.5E\n",
/* scaling electric fields */
elec_opt->pot_diff *= coepot;
/* electric potential (for post treatment) */
auto cvar_potr = CS_F_(potr)->get_val_s();
for (int iel = 0; iel < ncel; iel++)
cvar_potr[iel] *= coepot;
/* current density */
if (ielarc > 0) {
for (int iel = 0; iel < 3 ; iel++) {
cvar_curre0[iel] *= coepot;
cvar_curre1[iel] *= coepot;
cvar_curre2[iel] *= coepot;
}
}
/* joule effect */
for (int iel = 0; iel < 3 ; iel++)
cvar_joulp[iel] *= coepot * coepot;
}
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.cpp:134
Define a templated array class (owner of data)
Definition: cs_array.h:1118
cs_span< cs_real_t > get_val_s(const int time_id=0) const
Return a 1D span view of field values. If the field is not a scalar a fatal error is provoked.
Definition: cs_field.cpp:5080
int nt_prev
Definition: cs_time_step.h:70
int nt_cur
Definition: cs_time_step.h:72
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
cs_nreal_t cs_nreal_3_t[3]
Definition: cs_defs.h:375
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:349
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_elec_option_t * cs_get_glob_elec_option(void)
Definition: cs_elec_model.cpp:643
const cs_elec_option_t * cs_glob_elec_option
cs_field_t * cs_field(int id)
Return a pointer to a field based on its id. This function requires that a field of the given id is d...
Definition: cs_field.cpp:4295
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.cpp:2728
@ curre
Definition: cs_field_pointer.h:140
@ joulp
Definition: cs_field_pointer.h:137
@ h
Definition: cs_field_pointer.h:90
@ rho
Definition: cs_field_pointer.h:96
@ potr
Definition: cs_field_pointer.h:133
@ dt
Definition: cs_field_pointer.h:61
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:47
#define CS_FI_(e, i)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:49
static constexpr cs_real_t cs_math_epzero
Definition: cs_math.h:102
void cs_parall_max_loc_vals(int n, cs_real_t *max, cs_real_t max_loc_vals[])
Maximum value of a real and the value of related array on all default communicator processes.
Definition: cs_parall.cpp:275
int cs_glob_physical_model_flag[CS_N_PHYSICAL_MODEL_TYPES]
Definition: cs_physical_model.cpp:104
@ CS_ELECTRIC_ARCS
Definition: cs_physical_model.h:60
const cs_time_step_t * cs_glob_time_step
integer, save ncelet
number of extended (real + ghost of the 'halo') cells. See Note 1: ghost cells - (halos)
Definition: mesh.f90:46
double precision, dimension(:,:), pointer xyzcen
coordinate of the cell centers
Definition: mesh.f90:61
integer, save ncel
number of real cells in the mesh
Definition: mesh.f90:50
static void min(const cs_mpi_wrapper &mpi_w, T &first, Vals &... values)
Minimum values of a given datatype on a given communicator processes.
Definition: cs_parall.h:1261
static void sum(const cs_mpi_wrapper &mpi_w, T &first, Vals &... values)
Sum values of a given datatype over a given communicator.
Definition: cs_parall.h:893
CS_F_HOST_DEVICE T max(const T a, const T b)
Definition: cs_defs.h:735
CS_F_HOST_DEVICE T min(const T a, const T b)
Definition: cs_defs.h:712
Definition: mesh.f90:26
option for electric model
Definition: cs_elec_model.h:94
cs_real_t pot_diff
Definition: cs_elec_model.h:110
int irestrike
Definition: cs_elec_model.h:98
cs_real_t restrike_point[3]
Definition: cs_elec_model.h:99
cs_real_t couimp
Definition: cs_elec_model.h:108
int ntdcla
Definition: cs_elec_model.h:97