Fixed on/off switch for forcing and accretion, now forcing only happens for first 1000 steps (currently hard-coded), and accretion only happen after 1000 steps.
This commit is contained in:
@@ -82,6 +82,7 @@
|
||||
FUNC(AC_M_sink_Msun),\
|
||||
FUNC(AC_soft),\
|
||||
FUNC(AC_accretion_range),\
|
||||
FUNC(AC_switch_accretion),\
|
||||
/* Run params */\
|
||||
FUNC(AC_cdt), \
|
||||
FUNC(AC_cdtv), \
|
||||
|
@@ -68,7 +68,6 @@ sink_gravity(int3 globalVertexIdx){
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if LSINK
|
||||
// Give Truelove density
|
||||
Scalar
|
||||
@@ -93,9 +92,11 @@ sink_accretion(int3 globalVertexIdx, in ScalarField lnrho, Scalar dt){
|
||||
DCONST_REAL(AC_sink_pos_z)};
|
||||
const Scalar profile_range = DCONST_REAL(AC_accretion_range);
|
||||
const Scalar accretion_distance = length(grid_pos - sink_pos);
|
||||
int accretion_switch = DCONST_INT(AC_switch_accretion);
|
||||
Scalar accretion_density;
|
||||
|
||||
Scalar weight;
|
||||
|
||||
if (accretion_switch == 1){
|
||||
// const Scalar weight = exp(-(accretion_distance/profile_range));
|
||||
// Step function weighting
|
||||
if ((accretion_distance) <= profile_range){
|
||||
@@ -117,9 +118,13 @@ sink_accretion(int3 globalVertexIdx, in ScalarField lnrho, Scalar dt){
|
||||
rate = Scalar(0.0);
|
||||
}
|
||||
accretion_density = weight * rate ;
|
||||
} else {
|
||||
accretion_density = 0;
|
||||
}
|
||||
return accretion_density;
|
||||
}
|
||||
|
||||
|
||||
Vector
|
||||
sink_accretion_velocity(int3 globalVertexIdx, in VectorField uu, Scalar dt) {
|
||||
const Vector grid_pos = (Vector){(globalVertexIdx.x - nx_min) * dsx,
|
||||
@@ -130,9 +135,10 @@ sink_accretion_velocity(int3 globalVertexIdx, in VectorField uu, Scalar dt) {
|
||||
DCONST_REAL(AC_sink_pos_z)};
|
||||
const Scalar profile_range = DCONST_REAL(AC_accretion_range);
|
||||
const Scalar accretion_distance = length(grid_pos - sink_pos);
|
||||
|
||||
int accretion_switch = DCONST_INT(AC_switch_accretion);
|
||||
Vector accretion_velocity;
|
||||
|
||||
if (accretion_switch == 1){
|
||||
Scalar weight;
|
||||
// Step function weighting
|
||||
if ((accretion_distance) <= profile_range){
|
||||
@@ -148,6 +154,9 @@ sink_accretion_velocity(int3 globalVertexIdx, in VectorField uu, Scalar dt) {
|
||||
rate = (Vector){0.0, 0.0, 0.0};
|
||||
}
|
||||
accretion_velocity = weight * rate ;
|
||||
} else {
|
||||
accretion_velocity = (Vector){0.0, 0.0, 0.0};
|
||||
}
|
||||
return accretion_velocity;
|
||||
}
|
||||
#endif
|
||||
@@ -326,22 +335,35 @@ heat_transfer(in VectorField uu, in ScalarField lnrho, in ScalarField tt)
|
||||
|
||||
#if LFORCING
|
||||
Vector
|
||||
simple_vortex_forcing(Vector a, Vector b, Scalar magnitude)
|
||||
{
|
||||
simple_vortex_forcing(Vector a, Vector b, Scalar magnitude){
|
||||
int accretion_switch = DCONST_INT(AC_switch_accretion);
|
||||
|
||||
if (accretion_switch == 0){
|
||||
return magnitude * cross(normalized(b - a), (Vector){ 0, 0, 1}); // Vortex
|
||||
} else {
|
||||
return (Vector){0,0,0};
|
||||
}
|
||||
}
|
||||
Vector
|
||||
simple_outward_flow_forcing(Vector a, Vector b, Scalar magnitude){
|
||||
int accretion_switch = DCONST_INT(AC_switch_accretion);
|
||||
if (accretion_switch == 0){
|
||||
return magnitude * (1 / length(b - a)) * normalized(b - a); // Outward flow
|
||||
} else {
|
||||
return (Vector){0,0,0};
|
||||
}
|
||||
}
|
||||
|
||||
Vector
|
||||
simple_outward_flow_forcing(Vector a, Vector b, Scalar 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
|
||||
Vector
|
||||
helical_forcing(Scalar magnitude, Vector k_force, Vector xx, Vector ff_re, Vector ff_im, Scalar phi)
|
||||
{
|
||||
int accretion_switch = DCONST_INT(AC_switch_accretion);
|
||||
if (accretion_switch == 0){
|
||||
|
||||
|
||||
// JP: This looks wrong:
|
||||
// 1) Should it be dsx * nx instead of dsx * ny?
|
||||
// 2) Should you also use globalGrid.n instead of the local n?
|
||||
@@ -371,12 +393,19 @@ helical_forcing(Scalar magnitude, Vector k_force, Vector xx, Vector ff_re, Vecto
|
||||
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;
|
||||
} else {
|
||||
return (Vector){0,0,0};
|
||||
}
|
||||
}
|
||||
|
||||
Vector
|
||||
forcing(int3 globalVertexIdx, Scalar dt)
|
||||
{
|
||||
int accretion_switch = DCONST_INT(AC_switch_accretion);
|
||||
if (accretion_switch == 0){
|
||||
|
||||
Vector a = Scalar(.5) * (Vector){globalGridN.x * dsx,
|
||||
globalGridN.y * dsy,
|
||||
globalGridN.z * dsz}; // source (origin)
|
||||
@@ -408,6 +437,9 @@ forcing(int3 globalVertexIdx, Scalar dt)
|
||||
|
||||
if (is_valid(force)) { return force; }
|
||||
else { return (Vector){0, 0, 0}; }
|
||||
} else {
|
||||
return (Vector){0,0,0};
|
||||
}
|
||||
}
|
||||
#endif // LFORCING
|
||||
|
||||
|
@@ -252,11 +252,11 @@ run_simulation(void)
|
||||
#if LSINK
|
||||
|
||||
const AcReal sum_mass = acReduceScal(RTYPE_MAX, VTXBUF_ACCRETION);
|
||||
if (i > 1000) {
|
||||
// if (i > 1000) {
|
||||
accreted_mass = accreted_mass + sum_mass;
|
||||
} else {
|
||||
accreted_mass = 0.0;
|
||||
}
|
||||
// } else {
|
||||
// accreted_mass = 0.0;
|
||||
// }
|
||||
AcReal sink_mass = 0.0;
|
||||
//if (i > 1000 ) {
|
||||
sink_mass = mesh_info.real_params[AC_M_sink_init] + accreted_mass;
|
||||
@@ -265,14 +265,19 @@ run_simulation(void)
|
||||
printf("accreted mass is: %e \n", accreted_mass);
|
||||
acLoadDeviceConstant(AC_M_sink, sink_mass);
|
||||
vertex_buffer_set(VTXBUF_ACCRETION, 0.0, mesh);
|
||||
|
||||
int on_off_switch;
|
||||
if (i < 1000) {
|
||||
on_off_switch = 0; //accretion is off till 1000 steps.
|
||||
} else {
|
||||
on_off_switch = 1;
|
||||
}
|
||||
acLoadDeviceConstant(AC_switch_accretion, on_off_switch);
|
||||
#endif
|
||||
|
||||
#if LFORCING
|
||||
const ForcingParams forcing_params = generateForcingParams(mesh_info);
|
||||
if (i > 1000) {
|
||||
loadForcingParamsToDevice(forcing_params);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user