|
|
|
@@ -9,7 +9,7 @@
|
|
|
|
|
#define LUPWD (1)
|
|
|
|
|
#define LSINK (0)
|
|
|
|
|
|
|
|
|
|
#define AC_THERMAL_CONDUCTIVITY (AcReal(0.001)) // TODO: make an actual config parameter
|
|
|
|
|
#define AC_THERMAL_CONDUCTIVITY (0.001) // TODO: make an actual config parameter
|
|
|
|
|
#define H_CONST (0) // TODO: make an actual config parameter
|
|
|
|
|
#define C_CONST (0) // TODO: make an actual config parameter
|
|
|
|
|
|
|
|
|
@@ -140,11 +140,11 @@ der6x_upwd(in ScalarField vertex)
|
|
|
|
|
{
|
|
|
|
|
Scalar inv_ds = AC_inv_dsx;
|
|
|
|
|
|
|
|
|
|
return (Scalar){Scalar(1.0 / 60.0) * inv_ds *
|
|
|
|
|
(-Scalar(20.0) * vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
Scalar(15.0) * (vertex[vertexIdx.x + 1, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
return (Scalar){(1.0 / 60.0) * inv_ds *
|
|
|
|
|
(-20.0 * vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
15.0 * (vertex[vertexIdx.x + 1, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
vertex[vertexIdx.x - 1, vertexIdx.y, vertexIdx.z]) -
|
|
|
|
|
Scalar(6.0) * (vertex[vertexIdx.x + 2, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
6.0 * (vertex[vertexIdx.x + 2, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
vertex[vertexIdx.x - 2, vertexIdx.y, vertexIdx.z]) +
|
|
|
|
|
vertex[vertexIdx.x + 3, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
vertex[vertexIdx.x - 3, vertexIdx.y, vertexIdx.z])};
|
|
|
|
@@ -155,11 +155,11 @@ der6y_upwd(in ScalarField vertex)
|
|
|
|
|
{
|
|
|
|
|
Scalar inv_ds = AC_inv_dsy;
|
|
|
|
|
|
|
|
|
|
return (Scalar){Scalar(1.0 / 60.0) * inv_ds *
|
|
|
|
|
(-Scalar(20.0) * vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
Scalar(15.0) * (vertex[vertexIdx.x, vertexIdx.y + 1, vertexIdx.z] +
|
|
|
|
|
return (Scalar){(1.0 / 60.0) * inv_ds *
|
|
|
|
|
(-20.0 * vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
15.0 * (vertex[vertexIdx.x, vertexIdx.y + 1, vertexIdx.z] +
|
|
|
|
|
vertex[vertexIdx.x, vertexIdx.y - 1, vertexIdx.z]) -
|
|
|
|
|
Scalar(6.0) * (vertex[vertexIdx.x, vertexIdx.y + 2, vertexIdx.z] +
|
|
|
|
|
6.0 * (vertex[vertexIdx.x, vertexIdx.y + 2, vertexIdx.z] +
|
|
|
|
|
vertex[vertexIdx.x, vertexIdx.y - 2, vertexIdx.z]) +
|
|
|
|
|
vertex[vertexIdx.x, vertexIdx.y + 3, vertexIdx.z] +
|
|
|
|
|
vertex[vertexIdx.x, vertexIdx.y - 3, vertexIdx.z])};
|
|
|
|
@@ -170,11 +170,11 @@ der6z_upwd(in ScalarField vertex)
|
|
|
|
|
{
|
|
|
|
|
Scalar inv_ds = AC_inv_dsz;
|
|
|
|
|
|
|
|
|
|
return (Scalar){Scalar(1.0 / 60.0) * inv_ds *
|
|
|
|
|
(-Scalar(20.0) * vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
Scalar(15.0) * (vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z + 1] +
|
|
|
|
|
return (Scalar){(1.0 / 60.0) * inv_ds *
|
|
|
|
|
(-20.0 * vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z] +
|
|
|
|
|
15.0 * (vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z + 1] +
|
|
|
|
|
vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z - 1]) -
|
|
|
|
|
Scalar(6.0) * (vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z + 2] +
|
|
|
|
|
6.0 * (vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z + 2] +
|
|
|
|
|
vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z - 2]) +
|
|
|
|
|
vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z + 3] +
|
|
|
|
|
vertex[vertexIdx.x, vertexIdx.y, vertexIdx.z - 3])};
|
|
|
|
@@ -182,7 +182,6 @@ der6z_upwd(in ScalarField vertex)
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if LUPWD
|
|
|
|
|
Device Scalar
|
|
|
|
|
upwd_der6(in VectorField uu, in ScalarField lnrho)
|
|
|
|
@@ -202,7 +201,8 @@ gradients(in VectorField uu)
|
|
|
|
|
|
|
|
|
|
#if LSINK
|
|
|
|
|
Device Vector
|
|
|
|
|
sink_gravity(int3 globalVertexIdx){
|
|
|
|
|
sink_gravity(int3 globalVertexIdx)
|
|
|
|
|
{
|
|
|
|
|
int accretion_switch = int(AC_switch_accretion);
|
|
|
|
|
if (accretion_switch == 1) {
|
|
|
|
|
Vector force_gravity;
|
|
|
|
@@ -210,33 +210,34 @@ sink_gravity(int3 globalVertexIdx){
|
|
|
|
|
(globalVertexIdx.y - AC_ny_min) * AC_dsy,
|
|
|
|
|
(globalVertexIdx.z - AC_nz_min) * AC_dsz};
|
|
|
|
|
const Scalar sink_mass = AC_M_sink;
|
|
|
|
|
const Vector sink_pos = (Vector){AC_sink_pos_x,
|
|
|
|
|
AC_sink_pos_y,
|
|
|
|
|
AC_sink_pos_z};
|
|
|
|
|
const Vector sink_pos = (Vector){AC_sink_pos_x, AC_sink_pos_y, AC_sink_pos_z};
|
|
|
|
|
const Scalar distance = length(grid_pos - sink_pos);
|
|
|
|
|
const Scalar soft = AC_soft;
|
|
|
|
|
//MV: The commit 083ff59 had AC_G_const defined wrong here in DSL making it exxessively strong.
|
|
|
|
|
//MV: Scalar gravity_magnitude = ... below is correct!
|
|
|
|
|
const Scalar gravity_magnitude = (AC_G_const * sink_mass) / pow(((distance * distance) + soft*soft), 1.5);
|
|
|
|
|
// MV: The commit 083ff59 had AC_G_const defined wrong here in DSL making it exxessively
|
|
|
|
|
// strong. MV: Scalar gravity_magnitude = ... below is correct!
|
|
|
|
|
const Scalar gravity_magnitude = (AC_G_const * sink_mass) /
|
|
|
|
|
pow(((distance * distance) + soft * soft), 1.5);
|
|
|
|
|
const Vector direction = (Vector){(sink_pos.x - grid_pos.x) / distance,
|
|
|
|
|
(sink_pos.y - grid_pos.y) / distance,
|
|
|
|
|
(sink_pos.z - grid_pos.z) / distance};
|
|
|
|
|
force_gravity = gravity_magnitude * direction;
|
|
|
|
|
return force_gravity;
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (Vector){0.0, 0.0, 0.0};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if LSINK
|
|
|
|
|
// Give Truelove density
|
|
|
|
|
Device Scalar
|
|
|
|
|
truelove_density(in ScalarField lnrho){
|
|
|
|
|
truelove_density(in ScalarField lnrho)
|
|
|
|
|
{
|
|
|
|
|
const Scalar rho = exp(value(lnrho));
|
|
|
|
|
const Scalar Jeans_length_squared = (M_PI * AC_cs2_sound) / (AC_G_const * rho);
|
|
|
|
|
const Scalar TJ_rho = ((M_PI) * ((AC_dsx * AC_dsx) / Jeans_length_squared) * AC_cs2_sound) / (AC_G_const * AC_dsx * AC_dsx);
|
|
|
|
|
const Scalar TJ_rho = ((M_PI) * ((AC_dsx * AC_dsx) / Jeans_length_squared) * AC_cs2_sound) /
|
|
|
|
|
(AC_G_const * AC_dsx * AC_dsx);
|
|
|
|
|
// TODO: AC_dsx will cancel out, deal with it later for optimization.
|
|
|
|
|
|
|
|
|
|
Scalar accretion_rho = TJ_rho;
|
|
|
|
@@ -246,13 +247,12 @@ truelove_density(in ScalarField lnrho){
|
|
|
|
|
|
|
|
|
|
// This controls accretion of density/mass to the sink particle.
|
|
|
|
|
Device Scalar
|
|
|
|
|
sink_accretion(int3 globalVertexIdx, in ScalarField lnrho, Scalar dt){
|
|
|
|
|
sink_accretion(int3 globalVertexIdx, in ScalarField lnrho, Scalar dt)
|
|
|
|
|
{
|
|
|
|
|
const Vector grid_pos = (Vector){(globalVertexIdx.x - AC_nx_min) * AC_dsx,
|
|
|
|
|
(globalVertexIdx.y - AC_ny_min) * AC_dsy,
|
|
|
|
|
(globalVertexIdx.z - AC_nz_min) * AC_dsz};
|
|
|
|
|
const Vector sink_pos = (Vector){AC_sink_pos_x,
|
|
|
|
|
AC_sink_pos_y,
|
|
|
|
|
AC_sink_pos_z};
|
|
|
|
|
const Vector sink_pos = (Vector){AC_sink_pos_x, AC_sink_pos_y, AC_sink_pos_z};
|
|
|
|
|
const Scalar profile_range = AC_accretion_range;
|
|
|
|
|
const Scalar accretion_distance = length(grid_pos - sink_pos);
|
|
|
|
|
int accretion_switch = AC_switch_accretion;
|
|
|
|
@@ -261,12 +261,13 @@ sink_accretion(int3 globalVertexIdx, in ScalarField lnrho, Scalar dt){
|
|
|
|
|
|
|
|
|
|
if (accretion_switch == 1) {
|
|
|
|
|
if ((accretion_distance) <= profile_range) {
|
|
|
|
|
//weight = Scalar(1.0);
|
|
|
|
|
// weight = 1.0;
|
|
|
|
|
// Hann window function
|
|
|
|
|
Scalar window_ratio = accretion_distance / profile_range;
|
|
|
|
|
weight = Scalar(0.5)*(Scalar(1.0) - cos(Scalar(2.0)*M_PI*window_ratio));
|
|
|
|
|
} else {
|
|
|
|
|
weight = Scalar(0.0);
|
|
|
|
|
weight = 0.5 * (1.0 - cos(2.0 * M_PI * window_ratio));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
weight = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Truelove criterion is used as a kind of arbitrary density floor.
|
|
|
|
@@ -274,25 +275,26 @@ sink_accretion(int3 globalVertexIdx, in ScalarField lnrho, Scalar dt){
|
|
|
|
|
Scalar rate;
|
|
|
|
|
if (value(lnrho) > lnrho_min) {
|
|
|
|
|
rate = (exp(value(lnrho)) - exp(lnrho_min)) / dt;
|
|
|
|
|
} else {
|
|
|
|
|
rate = Scalar(0.0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rate = 0.0;
|
|
|
|
|
}
|
|
|
|
|
accretion_density = weight * rate;
|
|
|
|
|
} else {
|
|
|
|
|
accretion_density = Scalar(0.0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
accretion_density = 0.0;
|
|
|
|
|
}
|
|
|
|
|
return accretion_density;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This controls accretion of velocity to the sink particle.
|
|
|
|
|
Device Vector
|
|
|
|
|
sink_accretion_velocity(int3 globalVertexIdx, in VectorField uu, Scalar dt) {
|
|
|
|
|
sink_accretion_velocity(int3 globalVertexIdx, in VectorField uu, Scalar dt)
|
|
|
|
|
{
|
|
|
|
|
const Vector grid_pos = (Vector){(globalVertexIdx.x - AC_nx_min) * AC_dsx,
|
|
|
|
|
(globalVertexIdx.y - AC_ny_min) * AC_dsy,
|
|
|
|
|
(globalVertexIdx.z - AC_nz_min) * AC_dsz};
|
|
|
|
|
const Vector sink_pos = (Vector){AC_sink_pos_x,
|
|
|
|
|
AC_sink_pos_y,
|
|
|
|
|
AC_sink_pos_z};
|
|
|
|
|
const Vector sink_pos = (Vector){AC_sink_pos_x, AC_sink_pos_y, AC_sink_pos_z};
|
|
|
|
|
const Scalar profile_range = AC_accretion_range;
|
|
|
|
|
const Scalar accretion_distance = length(grid_pos - sink_pos);
|
|
|
|
|
int accretion_switch = AC_switch_accretion;
|
|
|
|
@@ -304,32 +306,33 @@ sink_accretion_velocity(int3 globalVertexIdx, in VectorField uu, Scalar dt) {
|
|
|
|
|
// Arch of a cosine function?
|
|
|
|
|
// Cubic spline x^3 - x in range [-0.5 , 0.5]
|
|
|
|
|
if ((accretion_distance) <= profile_range) {
|
|
|
|
|
//weight = Scalar(1.0);
|
|
|
|
|
// weight = 1.0;
|
|
|
|
|
// Hann window function
|
|
|
|
|
Scalar window_ratio = accretion_distance / profile_range;
|
|
|
|
|
weight = Scalar(0.5)*(Scalar(1.0) - cos(Scalar(2.0)*M_PI*window_ratio));
|
|
|
|
|
} else {
|
|
|
|
|
weight = Scalar(0.0);
|
|
|
|
|
weight = 0.5 * (1.0 - cos(2.0 * M_PI * window_ratio));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
weight = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector rate;
|
|
|
|
|
// MV: Could we use divergence here ephasize velocitie which are compressive and
|
|
|
|
|
// MV: not absorbins stuff that would not be accreted anyway?
|
|
|
|
|
if (length(value(uu)) > Scalar(0.0)) {
|
|
|
|
|
rate = (Scalar(1.0)/dt) * value(uu);
|
|
|
|
|
} else {
|
|
|
|
|
if (length(value(uu)) > 0.0) {
|
|
|
|
|
rate = (1.0 / dt) * value(uu);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rate = (Vector){0.0, 0.0, 0.0};
|
|
|
|
|
}
|
|
|
|
|
accretion_velocity = weight * rate;
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
accretion_velocity = (Vector){0.0, 0.0, 0.0};
|
|
|
|
|
}
|
|
|
|
|
return accretion_velocity;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Device Scalar
|
|
|
|
|
continuity(int3 globalVertexIdx, in VectorField uu, in ScalarField lnrho, Scalar dt)
|
|
|
|
|
{
|
|
|
|
@@ -344,35 +347,34 @@ continuity(int3 globalVertexIdx, in VectorField uu, in ScalarField lnrho, Scalar
|
|
|
|
|
- divergence(uu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if LENTROPY
|
|
|
|
|
Device Vector
|
|
|
|
|
momentum(int3 globalVertexIdx, in VectorField uu, in ScalarField lnrho, in ScalarField ss, in VectorField aa, Scalar dt)
|
|
|
|
|
momentum(int3 globalVertexIdx, in VectorField uu, in ScalarField lnrho, in ScalarField ss,
|
|
|
|
|
in VectorField aa, Scalar dt)
|
|
|
|
|
{
|
|
|
|
|
const Matrix S = stress_tensor(uu);
|
|
|
|
|
const Scalar cs2 = AC_cs2_sound * exp(AC_gamma * value(ss) / AC_cp_sound +
|
|
|
|
|
(AC_gamma - 1) * (value(lnrho) - AC_lnrho0));
|
|
|
|
|
const Vector j = (Scalar(1.0) / AC_mu0) *
|
|
|
|
|
const Vector j = (1.0 / AC_mu0) *
|
|
|
|
|
(gradient_of_divergence(aa) - laplace_vec(aa)); // Current density
|
|
|
|
|
const Vector B = curl(aa);
|
|
|
|
|
// TODO: DOES INTHERMAL VERSTION INCLUDE THE MAGNETIC FIELD?
|
|
|
|
|
const Scalar inv_rho = Scalar(1.0) / exp(value(lnrho));
|
|
|
|
|
const Scalar inv_rho = 1.0 / exp(value(lnrho));
|
|
|
|
|
|
|
|
|
|
// Regex replace CPU constants with get\(AC_([a-zA-Z_0-9]*)\)
|
|
|
|
|
// \1
|
|
|
|
|
const Vector mom = -mul(gradients(uu), value(uu)) -
|
|
|
|
|
cs2 * ((Scalar(1.0) / AC_cp_sound) * gradient(ss) + gradient(lnrho)) +
|
|
|
|
|
cs2 * ((1.0 / AC_cp_sound) * gradient(ss) + gradient(lnrho)) +
|
|
|
|
|
inv_rho * cross(j, B) +
|
|
|
|
|
AC_nu_visc *
|
|
|
|
|
(laplace_vec(uu) + Scalar(1.0 / 3.0) * gradient_of_divergence(uu) +
|
|
|
|
|
Scalar(2.0) * mul(S, gradient(lnrho))) +
|
|
|
|
|
AC_nu_visc * (laplace_vec(uu) + (1.0 / 3.0) * gradient_of_divergence(uu) +
|
|
|
|
|
2.0 * mul(S, gradient(lnrho))) +
|
|
|
|
|
AC_zeta * gradient_of_divergence(uu)
|
|
|
|
|
#if LSINK
|
|
|
|
|
// Gravity term
|
|
|
|
|
+ sink_gravity(globalVertexIdx)
|
|
|
|
|
// Corresponding loss of momentum
|
|
|
|
|
- //(Scalar(1.0) / Scalar( (AC_dsx*AC_dsy*AC_dsz) * exp(value(lnrho)))) * // Correction factor by unit mass
|
|
|
|
|
- //(1.0 / ( (AC_dsx*AC_dsy*AC_dsz) * exp(value(lnrho)))) * //
|
|
|
|
|
// Correction factor by unit mass
|
|
|
|
|
sink_accretion_velocity(globalVertexIdx, uu, dt) // As in Lee et al.(2014)
|
|
|
|
|
;
|
|
|
|
|
#else
|
|
|
|
@@ -392,8 +394,8 @@ momentum(int3 globalVertexIdx, in VectorField uu, in ScalarField lnrho, in Scala
|
|
|
|
|
(gradient(tt) + value(tt) * gradient(lnrho));
|
|
|
|
|
|
|
|
|
|
mom = -mul(gradients(uu), value(uu)) - pressure_term +
|
|
|
|
|
AC_nu_visc * (laplace_vec(uu) + Scalar(1.0 / 3.0) * gradient_of_divergence(uu) +
|
|
|
|
|
Scalar(2.0) * mul(S, gradient(lnrho))) +
|
|
|
|
|
AC_nu_visc * (laplace_vec(uu) + (1.0 / 3.0) * gradient_of_divergence(uu) +
|
|
|
|
|
2.0 * mul(S, gradient(lnrho))) +
|
|
|
|
|
AC_zeta * gradient_of_divergence(uu)
|
|
|
|
|
#if LSINK
|
|
|
|
|
+ sink_gravity(globalVertexIdx);
|
|
|
|
@@ -417,13 +419,14 @@ momentum(int3 globalVertexIdx, in VectorField uu, in ScalarField lnrho, Scalar d
|
|
|
|
|
// Isothermal: we have constant speed of sound
|
|
|
|
|
|
|
|
|
|
mom = -mul(gradients(uu), value(uu)) - AC_cs2_sound * gradient(lnrho) +
|
|
|
|
|
AC_nu_visc * (laplace_vec(uu) + Scalar(1.0 / 3.0) * gradient_of_divergence(uu) +
|
|
|
|
|
Scalar(2.0) * mul(S, gradient(lnrho))) +
|
|
|
|
|
AC_nu_visc * (laplace_vec(uu) + (1.0 / 3.0) * gradient_of_divergence(uu) +
|
|
|
|
|
2.0 * mul(S, gradient(lnrho))) +
|
|
|
|
|
AC_zeta * gradient_of_divergence(uu)
|
|
|
|
|
#if LSINK
|
|
|
|
|
+ sink_gravity(globalVertexIdx)
|
|
|
|
|
// Corresponding loss of momentum
|
|
|
|
|
- //(Scalar(1.0) / Scalar( (AC_dsx*AC_dsy*AC_dsz) * exp(value(lnrho)))) * // Correction factor by unit mass
|
|
|
|
|
- //(1.0 / ( (AC_dsx*AC_dsy*AC_dsz) * exp(value(lnrho)))) * // Correction
|
|
|
|
|
// factor by unit mass
|
|
|
|
|
sink_accretion_velocity(globalVertexIdx, uu, dt) // As in Lee et al.(2014)
|
|
|
|
|
;
|
|
|
|
|
#else
|
|
|
|
@@ -460,21 +463,21 @@ Device Scalar
|
|
|
|
|
lnT(in ScalarField ss, in ScalarField lnrho)
|
|
|
|
|
{
|
|
|
|
|
return AC_lnT0 + AC_gamma * value(ss) / AC_cp_sound +
|
|
|
|
|
(AC_gamma - Scalar(1.0)) * (value(lnrho) - AC_lnrho0);
|
|
|
|
|
(AC_gamma - 1.0) * (value(lnrho) - AC_lnrho0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Nabla dot (K nabla T) / (rho T)
|
|
|
|
|
Device Scalar
|
|
|
|
|
heat_conduction(in ScalarField ss, in ScalarField lnrho)
|
|
|
|
|
{
|
|
|
|
|
const Scalar inv_AC_cp_sound = AcReal(1.0) / AC_cp_sound;
|
|
|
|
|
const Scalar inv_AC_cp_sound = 1.0 / AC_cp_sound;
|
|
|
|
|
|
|
|
|
|
const Vector grad_ln_chi = -gradient(lnrho);
|
|
|
|
|
|
|
|
|
|
const Scalar first_term = AC_gamma * inv_AC_cp_sound * laplace(ss) +
|
|
|
|
|
(AC_gamma - AcReal(1.0)) * laplace(lnrho);
|
|
|
|
|
(AC_gamma - 1.0) * laplace(lnrho);
|
|
|
|
|
const Vector second_term = AC_gamma * inv_AC_cp_sound * gradient(ss) +
|
|
|
|
|
(AC_gamma - AcReal(1.0)) * gradient(lnrho);
|
|
|
|
|
(AC_gamma - 1.0) * gradient(lnrho);
|
|
|
|
|
const Vector third_term = AC_gamma * (inv_AC_cp_sound * gradient(ss) + gradient(lnrho)) +
|
|
|
|
|
grad_ln_chi;
|
|
|
|
|
|
|
|
|
@@ -492,11 +495,11 @@ Device Scalar
|
|
|
|
|
entropy(in ScalarField ss, in VectorField uu, in ScalarField lnrho, in VectorField aa)
|
|
|
|
|
{
|
|
|
|
|
const Matrix S = stress_tensor(uu);
|
|
|
|
|
const Scalar inv_pT = Scalar(1.0) / (exp(value(lnrho)) * exp(lnT(ss, lnrho)));
|
|
|
|
|
const Vector j = (Scalar(1.0) / AC_mu0) *
|
|
|
|
|
const Scalar inv_pT = 1.0 / (exp(value(lnrho)) * exp(lnT(ss, lnrho)));
|
|
|
|
|
const Vector j = (1.0 / AC_mu0) *
|
|
|
|
|
(gradient_of_divergence(aa) - laplace_vec(aa)); // Current density
|
|
|
|
|
const Scalar RHS = H_CONST - C_CONST + AC_eta * (AC_mu0)*dot(j, j) +
|
|
|
|
|
Scalar(2.0) * exp(value(lnrho)) * AC_nu_visc * contract(S) +
|
|
|
|
|
2.0 * exp(value(lnrho)) * AC_nu_visc * contract(S) +
|
|
|
|
|
AC_zeta * exp(value(lnrho)) * divergence(uu) * divergence(uu);
|
|
|
|
|
|
|
|
|
|
return -dot(value(uu), gradient(ss)) + inv_pT * RHS + heat_conduction(ss, lnrho);
|
|
|
|
@@ -511,28 +514,32 @@ heat_transfer(in VectorField uu, in ScalarField lnrho, in ScalarField tt)
|
|
|
|
|
const Scalar heat_diffusivity_k = 0.0008; // 8e-4;
|
|
|
|
|
return -dot(value(uu), gradient(tt)) + heat_diffusivity_k * laplace(tt) +
|
|
|
|
|
heat_diffusivity_k * dot(gradient(lnrho), gradient(tt)) +
|
|
|
|
|
AC_nu_visc * contract(S) * (Scalar(1.0) / AC_cv_sound) -
|
|
|
|
|
AC_nu_visc * contract(S) * (1.0 / AC_cv_sound) -
|
|
|
|
|
(AC_gamma - 1) * value(tt) * divergence(uu);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if LFORCING
|
|
|
|
|
Device Vector
|
|
|
|
|
simple_vortex_forcing(Vector a, Vector b, Scalar magnitude){
|
|
|
|
|
simple_vortex_forcing(Vector a, Vector b, Scalar magnitude)
|
|
|
|
|
{
|
|
|
|
|
int accretion_switch = AC_switch_accretion;
|
|
|
|
|
|
|
|
|
|
if (accretion_switch == 0) {
|
|
|
|
|
return magnitude * cross(normalized(b - a), (Vector){0, 0, 1}); // Vortex
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (Vector){0, 0, 0};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Device Vector
|
|
|
|
|
simple_outward_flow_forcing(Vector a, Vector b, Scalar magnitude){
|
|
|
|
|
simple_outward_flow_forcing(Vector a, Vector b, Scalar magnitude)
|
|
|
|
|
{
|
|
|
|
|
int accretion_switch = AC_switch_accretion;
|
|
|
|
|
if (accretion_switch == 0) {
|
|
|
|
|
return magnitude * (1 / length(b - a)) * normalized(b - a); // Outward flow
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (Vector){0, 0, 0};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -579,8 +586,7 @@ forcing(int3 globalVertexIdx, Scalar dt)
|
|
|
|
|
int accretion_switch = AC_switch_accretion;
|
|
|
|
|
if (accretion_switch == 0) {
|
|
|
|
|
|
|
|
|
|
Vector a = Scalar(0.5) * (Vector){globalGridN.x * AC_dsx,
|
|
|
|
|
globalGridN.y * AC_dsy,
|
|
|
|
|
Vector a = 0.5 * (Vector){globalGridN.x * AC_dsx, globalGridN.y * AC_dsy,
|
|
|
|
|
globalGridN.z * AC_dsz}; // source (origin)
|
|
|
|
|
Vector xx = (Vector){(globalVertexIdx.x - AC_nx_min) * AC_dsx,
|
|
|
|
|
(globalVertexIdx.y - AC_ny_min) * AC_dsy,
|
|
|
|
@@ -595,7 +601,6 @@ forcing(int3 globalVertexIdx, Scalar dt)
|
|
|
|
|
Vector ff_re = (Vector){AC_ff_hel_rex, AC_ff_hel_rey, AC_ff_hel_rez};
|
|
|
|
|
Vector ff_im = (Vector){AC_ff_hel_imx, AC_ff_hel_imy, AC_ff_hel_imz};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Determine that forcing funtion type at this point.
|
|
|
|
|
// Vector force = simple_vortex_forcing(a, xx, magnitude);
|
|
|
|
|
// Vector force = simple_outward_flow_forcing(a, xx, magnitude);
|
|
|
|
@@ -608,9 +613,14 @@ forcing(int3 globalVertexIdx, Scalar dt)
|
|
|
|
|
force.y = sqrt(dt) * NN * force.y;
|
|
|
|
|
force.z = sqrt(dt) * NN * force.z;
|
|
|
|
|
|
|
|
|
|
if (is_valid(force)) { return force; }
|
|
|
|
|
else { return (Vector){0, 0, 0}; }
|
|
|
|
|
} else {
|
|
|
|
|
if (is_valid(force)) {
|
|
|
|
|
return force;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (Vector){0, 0, 0};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (Vector){0, 0, 0};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -671,7 +681,8 @@ solve()
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if LSINK
|
|
|
|
|
out_accretion = rk3(out_accretion, accretion, sink_accretion(globalVertexIdx, lnrho, dt), dt);// unit now is rho!
|
|
|
|
|
out_accretion = rk3(out_accretion, accretion, sink_accretion(globalVertexIdx, lnrho, dt),
|
|
|
|
|
dt); // unit now is rho!
|
|
|
|
|
|
|
|
|
|
if (step_number == 2) {
|
|
|
|
|
out_accretion = out_accretion * AC_dsx * AC_dsy * AC_dsz; // unit is now mass!
|
|
|
|
|