My Project
programmer's documentation
Scaling parameters definition for electric model (cs_user_electric_scaling.c)

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_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_3_t *surfac = (const cs_real_3_t *) mesh_quantities->b_face_normal;
const cs_real_3_t *cdgfac = (const cs_real_3_t *) 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.;
double *w1;
BFT_MALLOC(w1, ncelet, double);
int diff_id = cs_field_get_key_int(CS_FI_(curre, 0), kivisl);
cs_field_t *c_prop = NULL;
c_prop = cs_field_by_id(diff_id);
for (int iel = 0; iel < ncel; iel++) {
double xelec = CS_FI_(curre, 0)->val[iel] / c_prop->val[iel];
double yelec = CS_FI_(curre, 1)->val[iel] / c_prop->val[iel];
double zelec = CS_FI_(curre, 2)->val[iel] / c_prop->val[iel];
w1[iel] = pow(xelec * xelec + yelec * yelec + zelec * zelec, 0.5);
amex = CS_MIN(amex, w1[iel]);
aiex = CS_MAX(amex, w1[iel]);
}
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[3 * iel ];
xyzmax[1] = xyzcen[3 * iel + 1];
xyzmax[2] = xyzcen[3 * 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]);
}
BFT_FREE(w1);
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[3 * iel + 2] > z1 && xyzcen[3 * iel + 2] < z2) {
double rayo = elec_opt->restrike_point[0] * xyzcen[3 * iel ]
- elec_opt->restrike_point[1] * xyzcen[3 * 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[3 * iel + 2] - elec_opt->restrike_point[2]
* xyzcen[3 * iel + 2] - elec_opt->restrike_point[2]);
rayo = pow(rayo, 0.5);
double posi = elec_opt->restrike_point[0] * xyzcen[3 * iel];
if (rayo < 5.e-4 && posi <= 0.)
CS_F_(h)->val[iel] = 8.e7;
}
}
}
else {
elec_opt->irestrike = 0;
}
double somje = 0.;
for (int iel = 0; iel < ncel; iel++) {
somje += CS_F_(joulp)->val[iel] * volume[iel];
}
cs_parall_sum(1, CS_DOUBLE, &somje);
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(surfac[ifac][0]) < 1.e-8 && fabs(surfac[ifac][1]) < 1.e-8 &&
cdgfac[ifac][2] > 0.05e-2 && cdgfac[ifac][2] < 0.08e-2) {
int iel = mesh->i_face_cells[ifac][0];
elcou += CS_FI_(curre, 2)->val[iel] * surfac[ifac][2];
}
}
if (fabs(elcou) > 1.e-6)
elcou = fabs(elcou);
else
elcou = 0.;
if (fabs(elcou) > 1.e20)
coepot = coepoa;
double dtj = 1.e15;
double dtjm = dtj;
double delhsh = 0.;
double cdtj = 20.;
for (int iel = 0; iel < ncel; iel++) {
if (fabs(CS_F_(rho)->val[iel]) > 1.e-20)
delhsh = CS_F_(joulp)->val[iel] * dt[iel]
/ CS_F_(rho)->val[iel];
if (fabs(delhsh) > 1.e-20)
dtjm = CS_F_(h)->val[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) */
for (int iel = 0; iel < ncel; iel++)
CS_F_(potr)->val[iel] *= coepot;
/* current density */
if (ielarc > 0)
for (int i = 0; i < 3 ; i++)
for (int iel = 0; iel < 3 ; iel++)
CS_FI_(curre, i)->val[iel] *= coepot;
/* joule effect */
for (int iel = 0; iel < 3 ; iel++)
CS_F_(joulp)->val[iel] *= coepot * coepot;
}
optcal::elcou
real(c_double), pointer, save elcou
elcou : current
Definition: optcal.f90:1282
cs_elec_option_t::restrike_point
cs_real_t restrike_point[3]
Definition: cs_elec_model.h:100
rho
Definition: cs_field_pointer.h:103
mesh::nfac
integer, save nfac
Definition: mesh.f90:54
cs_real_3_t
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:315
cs_elec_option_t::irestrike
int irestrike
Definition: cs_elec_model.h:99
ppincl::ielarc
integer ielarc
pointer to specify Electric arcs module (Joule effect and Laplace forces) with indicator ippmod(ielar...
Definition: ppincl.f90:175
CS_FI_
#define CS_FI_(e, i)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:53
cs_elec_option_t::couimp
cs_real_t couimp
Definition: cs_elec_model.h:106
potr
Definition: cs_field_pointer.h:165
cs_time_step_t::nt_cur
int nt_cur
Definition: cs_time_step.h:61
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
ifac
void const cs_lnum_t *const ifac
Definition: cs_wall_functions.h:1147
cs_glob_physical_model_flag
int cs_glob_physical_model_flag[CS_N_PHYSICAL_MODEL_TYPES]
Definition: cs_physical_model.c:109
cs_parall_sum
static void cs_parall_sum(int n, cs_datatype_t datatype, void *val)
Sum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:147
mesh
Definition: mesh.f90:26
CS_DOUBLE
Definition: cs_defs.h:265
CS_ELECTRIC_ARCS
Definition: cs_physical_model.h:70
cs_field_t::val
cs_real_t * val
Definition: cs_field.h:145
ncel
void const cs_int_t * ncel
Definition: cs_prototypes.h:122
CS_MIN
#define CS_MIN(a, b)
Definition: cs_defs.h:430
cs_parall_max_loc_vals
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.c:747
mesh::ncelet
integer, save ncelet
Definition: mesh.f90:46
cs_math_epzero
const cs_real_t cs_math_epzero
cs_field_get_key_int
int cs_field_get_key_int(const cs_field_t *f, int key_id)
Return a integer value for a given key associated with a field.
Definition: cs_field.c:2976
BFT_MALLOC
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62
BFT_FREE
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101
CS_F_
#define CS_F_(e)
Macro used to return a field pointer by its enumerated value.
Definition: cs_field_pointer.h:51
cs_elec_option_t
option for electric model
Definition: cs_elec_model.h:96
cs_elec_option_t::pot_diff
cs_real_t pot_diff
Definition: cs_elec_model.h:107
curre
Definition: cs_field_pointer.h:172
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_field_by_id
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.c:2307
cs_time_step_t::nt_prev
int nt_prev
Definition: cs_time_step.h:59
mesh::cdgfac
double precision, dimension(:,:), pointer cdgfac
Definition: mesh.f90:140
mesh::surfac
double precision, dimension(:,:), pointer surfac
Definition: mesh.f90:115
cs_parall_min
static void cs_parall_min(int n, cs_datatype_t datatype, void *val)
Minimum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:217
joulp
Definition: cs_field_pointer.h:169
xyzcen
void const cs_int_t const cs_real_t * xyzcen
Definition: cs_prototypes.h:122
cs_parall_max
static void cs_parall_max(int n, cs_datatype_t datatype, void *val)
Maximum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:182
cs_elec_option_t::ntdcla
int ntdcla
Definition: cs_elec_model.h:98
cs_get_glob_elec_option
cs_elec_option_t * cs_get_glob_elec_option(void)
Definition: cs_elec_model.c:552
cs_field_key_id
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.c:2490
numvar::kivisl
integer, save kivisl
variable diffusivity field id key for scalars
Definition: numvar.f90:193
dt
Definition: cs_field_pointer.h:65
cs_glob_elec_option
const cs_elec_option_t * cs_glob_elec_option
CS_MAX
#define CS_MAX(a, b)
Definition: cs_defs.h:431
mesh::volume
double precision, dimension(:), pointer volume
Definition: mesh.f90:152
cs_glob_time_step
const cs_time_step_t * cs_glob_time_step
h
Definition: cs_field_pointer.h:97
cs_field_t
Field descriptor.
Definition: cs_field.h:124
bft_printf
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.c:140