Merged master to acc_parameter_overhaul
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2014-2018, Johannes Pekkilae, Miikka Vaeisalae.
|
||||
Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
|
||||
|
||||
This file is part of Astaroth.
|
||||
|
||||
@@ -553,11 +553,6 @@ normalized(const ModelVector& vec)
|
||||
return inv_len * vec;
|
||||
}
|
||||
|
||||
// Note: LNT0 and LNRHO0 must be set very carefully: if the magnitude is different that other values
|
||||
// in the mesh, then we will inherently lose precision
|
||||
#define LNT0 (ModelScalar(0.0))
|
||||
#define LNRHO0 (ModelScalar(0.0))
|
||||
|
||||
#define H_CONST (ModelScalar(0.0))
|
||||
#define C_CONST (ModelScalar(0.0))
|
||||
|
||||
@@ -571,9 +566,10 @@ momentum(const ModelVectorData& uu, const ModelScalarData& lnrho
|
||||
{
|
||||
#if LENTROPY
|
||||
const ModelMatrix S = stress_tensor(uu);
|
||||
const ModelScalar cs2 = get(AC_cs2_sound) * expl(get(AC_gamma) * value(ss) / get(AC_cp_sound) +
|
||||
(get(AC_gamma) - 1) * (value(lnrho) - LNRHO0));
|
||||
const ModelVector j = (ModelScalar(1.) / get(AC_mu0)) *
|
||||
const ModelScalar cs2 = get(AC_cs2_sound) *
|
||||
expl(get(AC_gamma) * value(ss) / get(AC_cp_sound) +
|
||||
(get(AC_gamma) - 1) * (value(lnrho) - get(AC_lnrho0)));
|
||||
const ModelVector j = (ModelScalar(1.) / get(AC_mu0)) *
|
||||
(gradient_of_divergence(aa) - laplace_vec(aa)); // Current density
|
||||
const ModelVector B = curl(aa);
|
||||
const ModelScalar inv_rho = ModelScalar(1.) / expl(value(lnrho));
|
||||
@@ -591,7 +587,8 @@ momentum(const ModelVectorData& uu, const ModelScalarData& lnrho
|
||||
// !!!!!!!!!!!!!!!!%JP: NOTE TODO IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// NOT CHECKED FOR CORRECTNESS: USE AT YOUR OWN RISK
|
||||
const ModelMatrix S = stress_tensor(uu);
|
||||
const ModelScalar cs2 = get(AC_cs2_sound) * expl((get(AC_gamma) - 1) * (value(lnrho) - LNRHO0));
|
||||
const ModelScalar cs2 = get(AC_cs2_sound) *
|
||||
expl((get(AC_gamma) - 1) * (value(lnrho) - get(AC_lnrho0)));
|
||||
|
||||
const ModelVector mom = -mul(gradients(uu), value(uu)) - cs2 * gradient(lnrho) +
|
||||
get(AC_nu_visc) * (laplace_vec(uu) +
|
||||
@@ -623,8 +620,8 @@ induction(const ModelVectorData& uu, const ModelVectorData& aa)
|
||||
static inline ModelScalar
|
||||
lnT(const ModelScalarData& ss, const ModelScalarData& lnrho)
|
||||
{
|
||||
const ModelScalar lnT = LNT0 + get(AC_gamma) * value(ss) / get(AC_cp_sound) +
|
||||
(get(AC_gamma) - ModelScalar(1.)) * (value(lnrho) - LNRHO0);
|
||||
const ModelScalar lnT = get(AC_lnT0) + get(AC_gamma) * value(ss) / get(AC_cp_sound) +
|
||||
(get(AC_gamma) - ModelScalar(1.)) * (value(lnrho) - get(AC_lnrho0));
|
||||
return lnT;
|
||||
}
|
||||
|
||||
@@ -678,41 +675,96 @@ entropy(const ModelScalarData& ss, const ModelVectorData& uu, const ModelScalarD
|
||||
*/
|
||||
}
|
||||
|
||||
static bool
|
||||
static inline bool
|
||||
is_valid(const ModelScalar a)
|
||||
{
|
||||
return !isnan(a) && !isinf(a);
|
||||
}
|
||||
|
||||
static bool
|
||||
static inline bool
|
||||
is_valid(const ModelVector& a)
|
||||
{
|
||||
return is_valid(a.x) && is_valid(a.y) && is_valid(a.z);
|
||||
}
|
||||
|
||||
static inline ModelVector
|
||||
forcing(int3 globalVertexIdx)
|
||||
{
|
||||
// source (origin)
|
||||
ModelVector a = ModelScalar(.5) * (ModelVector){get(AC_nx) * get(AC_dsx),
|
||||
get(AC_ny) * get(AC_dsy),
|
||||
get(AC_nz) * get(AC_dsz)};
|
||||
// sink (current index)
|
||||
ModelVector b = (ModelVector){(globalVertexIdx.x - get(AC_nx_min)) * get(AC_dsx),
|
||||
(globalVertexIdx.y - get(AC_ny_min)) * get(AC_dsy),
|
||||
(globalVertexIdx.z - get(AC_nz_min)) * get(AC_dsz)};
|
||||
#if 0
|
||||
//FORCING NOT SUPPORTED FOR AUTOTEST
|
||||
|
||||
ModelScalar magnitude = 0.05;
|
||||
// Vector c = magnitude * (1 / length(b - a)) * normalized(b - a); // Outward flow
|
||||
ModelVector c = magnitude * cross(normalized(b - a), (ModelVector){0, 0, 1}); // Vortex
|
||||
if (is_valid(c)) {
|
||||
return c;
|
||||
}
|
||||
else {
|
||||
return (ModelVector){0, 0, 0};
|
||||
}
|
||||
static inline ModelVector
|
||||
simple_vortex_forcing(ModelVector a, ModelVector b, ModelScalar magnitude)
|
||||
{
|
||||
return magnitude * cross(normalized(b - a), (ModelVector){0, 0, 1}); // Vortex
|
||||
}
|
||||
|
||||
static inline ModelVector
|
||||
simple_outward_flow_forcing(ModelVector a, ModelVector b, ModelScalar magnitude)
|
||||
{
|
||||
return magnitude * (1 / length(b - a)) * normalized(b - a); // Outward flow
|
||||
}
|
||||
|
||||
|
||||
// The Pencil Code forcing_hel_noshear(), manual Eq. 222, inspired forcing function with adjustable helicity
|
||||
static inline ModelVector
|
||||
helical_forcing(ModelScalar magnitude, ModelVector k_force, ModelVector xx, ModelVector ff_re, ModelVector ff_im, ModelScalar phi)
|
||||
{
|
||||
|
||||
xx.x = xx.x*(2.0*M_PI/(get(AC_dsx)*(get(AC_ny_max) - get(AC_ny_min))));
|
||||
xx.y = xx.y*(2.0*M_PI/(get(AC_dsy)*(get(AC_ny_max) - get(AC_ny_min))));
|
||||
xx.z = xx.z*(2.0*M_PI/(get(AC_dsz)*(get(AC_ny_max) - get(AC_ny_min))));
|
||||
|
||||
ModelScalar cos_phi = cos(phi);
|
||||
ModelScalar sin_phi = sin(phi);
|
||||
ModelScalar cos_k_dox_x = cos(dot(k_force, xx));
|
||||
ModelScalar sin_k_dox_x = sin(dot(k_force, xx));
|
||||
// Phase affect only the x-component
|
||||
ModelScalar real_comp_phase = cos_k_dox_x*cos_phi - sin_k_dox_x*sin_phi;
|
||||
ModelScalar imag_comp_phase = cos_k_dox_x*sin_phi + sin_k_dox_x*cos_phi;
|
||||
|
||||
|
||||
ModelVector force = (ModelVector){ ff_re.x*real_comp_phase - ff_im.x*imag_comp_phase,
|
||||
ff_re.y*real_comp_phase - ff_im.y*imag_comp_phase,
|
||||
ff_re.z*real_comp_phase - ff_im.z*imag_comp_phase};
|
||||
|
||||
return force;
|
||||
}
|
||||
|
||||
static inline ModelVector
|
||||
forcing(int3 globalVertexIdx, ModelScalar dt)
|
||||
{
|
||||
ModelVector a = ModelScalar(.5) * (ModelVector){ get(AC_nx) * get(AC_dsx),
|
||||
get(AC_ny) * get(AC_dsy),
|
||||
get(AC_nz) * get(AC_dsz)}; // source (origin)
|
||||
ModelVector xx = (ModelVector){(globalVertexIdx.x - get(AC_nx_min)) * get(AC_dsx),
|
||||
(globalVertexIdx.y - get(AC_ny_min) * get(AC_dsy)),
|
||||
(globalVertexIdx.z - get(AC_nz_min) * get(AC_dsz))}; // sink (current index)
|
||||
const ModelScalar cs2 = get(AC_cs2_sound);
|
||||
const ModelScalar cs = sqrt(cs2);
|
||||
|
||||
//Placeholders until determined properly
|
||||
ModelScalar magnitude = get(AC_forcing_magnitude);
|
||||
ModelScalar phase = get(AC_forcing_phase);
|
||||
ModelVector k_force = (ModelVector){ get(AC_k_forcex), get(AC_k_forcey), get(AC_k_forcez)};
|
||||
ModelVector ff_re = (ModelVector){get(AC_ff_hel_rex), get(AC_ff_hel_rey), get(AC_ff_hel_rez)};
|
||||
ModelVector ff_im = (ModelVector){get(AC_ff_hel_imx), get(AC_ff_hel_imy), get(AC_ff_hel_imz)};
|
||||
|
||||
|
||||
//Determine that forcing funtion type at this point.
|
||||
//ModelVector force = simple_vortex_forcing(a, xx, magnitude);
|
||||
//ModelVector force = simple_outward_flow_forcing(a, xx, magnitude);
|
||||
ModelVector force = helical_forcing(magnitude, k_force, xx, ff_re,ff_im, phase);
|
||||
|
||||
//Scaling N = magnitude*cs*sqrt(k*cs/dt) * dt
|
||||
const ModelScalar NN = cs*sqrt(get(AC_kaver)*cs);
|
||||
//MV: Like in the Pencil Code. I don't understandf the logic here.
|
||||
force.x = sqrt(dt)*NN*force.x;
|
||||
force.y = sqrt(dt)*NN*force.y;
|
||||
force.z = sqrt(dt)*NN*force.z;
|
||||
|
||||
if (is_valid(force)) { return force; }
|
||||
else { return (ModelVector){0, 0, 0}; }
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
solve_alpha_step(const int step_number, const ModelScalar dt, const int i, const int j, const int k,
|
||||
ModelMesh& in, ModelMesh* out)
|
||||
@@ -774,12 +826,13 @@ solve_beta_step(const int step_number, const ModelScalar dt, const int i, const
|
||||
for (int w = 0; w < NUM_VTXBUF_HANDLES; ++w)
|
||||
out->vertex_buffer[w][idx] += beta[step_number] * in.vertex_buffer[w][idx];
|
||||
|
||||
(void)dt; // Suppress unused variable warning if forcing not used
|
||||
#if LFORCING
|
||||
if (step_number == 2) {
|
||||
ModelVector force = forcing((int3){i, j, k});
|
||||
out->vertex_buffer[VTXBUF_UUX][idx] += force.x * dt;
|
||||
out->vertex_buffer[VTXBUF_UUY][idx] += force.y * dt;
|
||||
out->vertex_buffer[VTXBUF_UUZ][idx] += force.z * dt;
|
||||
ModelVector force = forcing((int3){i, j, k}, dt);
|
||||
out->vertex_buffer[VTXBUF_UUX][idx] += force.x;
|
||||
out->vertex_buffer[VTXBUF_UUY][idx] += force.y;
|
||||
out->vertex_buffer[VTXBUF_UUZ][idx] += force.z;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user