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:
JackHsu
2019-08-20 23:12:42 +08:00
parent eda83e5807
commit 5b686bc659
3 changed files with 149 additions and 111 deletions

View File

@@ -82,6 +82,7 @@
FUNC(AC_M_sink_Msun),\ FUNC(AC_M_sink_Msun),\
FUNC(AC_soft),\ FUNC(AC_soft),\
FUNC(AC_accretion_range),\ FUNC(AC_accretion_range),\
FUNC(AC_switch_accretion),\
/* Run params */\ /* Run params */\
FUNC(AC_cdt), \ FUNC(AC_cdt), \
FUNC(AC_cdtv), \ FUNC(AC_cdtv), \

View File

@@ -68,7 +68,6 @@ sink_gravity(int3 globalVertexIdx){
#endif #endif
#if LSINK #if LSINK
// Give Truelove density // Give Truelove density
Scalar Scalar
@@ -93,9 +92,11 @@ sink_accretion(int3 globalVertexIdx, in ScalarField lnrho, Scalar dt){
DCONST_REAL(AC_sink_pos_z)}; DCONST_REAL(AC_sink_pos_z)};
const Scalar profile_range = DCONST_REAL(AC_accretion_range); const Scalar profile_range = DCONST_REAL(AC_accretion_range);
const Scalar accretion_distance = length(grid_pos - sink_pos); const Scalar accretion_distance = length(grid_pos - sink_pos);
int accretion_switch = DCONST_INT(AC_switch_accretion);
Scalar accretion_density; Scalar accretion_density;
Scalar weight; Scalar weight;
if (accretion_switch == 1){
// const Scalar weight = exp(-(accretion_distance/profile_range)); // const Scalar weight = exp(-(accretion_distance/profile_range));
// Step function weighting // Step function weighting
if ((accretion_distance) <= profile_range){ if ((accretion_distance) <= profile_range){
@@ -117,9 +118,13 @@ sink_accretion(int3 globalVertexIdx, in ScalarField lnrho, Scalar dt){
rate = Scalar(0.0); rate = Scalar(0.0);
} }
accretion_density = weight * rate ; accretion_density = weight * rate ;
} else {
accretion_density = 0;
}
return accretion_density; return accretion_density;
} }
Vector 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 - nx_min) * dsx, 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)}; DCONST_REAL(AC_sink_pos_z)};
const Scalar profile_range = DCONST_REAL(AC_accretion_range); const Scalar profile_range = DCONST_REAL(AC_accretion_range);
const Scalar accretion_distance = length(grid_pos - sink_pos); const Scalar accretion_distance = length(grid_pos - sink_pos);
int accretion_switch = DCONST_INT(AC_switch_accretion);
Vector accretion_velocity; Vector accretion_velocity;
if (accretion_switch == 1){
Scalar weight; Scalar weight;
// Step function weighting // Step function weighting
if ((accretion_distance) <= profile_range){ 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}; rate = (Vector){0.0, 0.0, 0.0};
} }
accretion_velocity = weight * rate ; accretion_velocity = weight * rate ;
} else {
accretion_velocity = (Vector){0.0, 0.0, 0.0};
}
return accretion_velocity; return accretion_velocity;
} }
#endif #endif
@@ -326,22 +335,35 @@ heat_transfer(in VectorField uu, in ScalarField lnrho, in ScalarField tt)
#if LFORCING #if LFORCING
Vector 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);
return magnitude * cross(normalized(b - a), (Vector){0, 0, 1}); // Vortex
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 // The Pencil Code forcing_hel_noshear(), manual Eq. 222, inspired forcing function with adjustable helicity
Vector Vector
helical_forcing(Scalar magnitude, Vector k_force, Vector xx, Vector ff_re, Vector ff_im, Scalar phi) 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: // JP: This looks wrong:
// 1) Should it be dsx * nx instead of dsx * ny? // 1) Should it be dsx * nx instead of dsx * ny?
// 2) Should you also use globalGrid.n instead of the local n? // 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.y*real_comp_phase - ff_im.y*imag_comp_phase,
ff_re.z*real_comp_phase - ff_im.z*imag_comp_phase}; ff_re.z*real_comp_phase - ff_im.z*imag_comp_phase};
return force; return force;
} else {
return (Vector){0,0,0};
}
} }
Vector Vector
forcing(int3 globalVertexIdx, Scalar dt) 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, Vector a = Scalar(.5) * (Vector){globalGridN.x * dsx,
globalGridN.y * dsy, globalGridN.y * dsy,
globalGridN.z * dsz}; // source (origin) globalGridN.z * dsz}; // source (origin)
@@ -408,6 +437,9 @@ forcing(int3 globalVertexIdx, Scalar dt)
if (is_valid(force)) { return force; } if (is_valid(force)) { return force; }
else { return (Vector){0, 0, 0}; } else { return (Vector){0, 0, 0}; }
} else {
return (Vector){0,0,0};
}
} }
#endif // LFORCING #endif // LFORCING

View File

@@ -252,11 +252,11 @@ run_simulation(void)
#if LSINK #if LSINK
const AcReal sum_mass = acReduceScal(RTYPE_MAX, VTXBUF_ACCRETION); const AcReal sum_mass = acReduceScal(RTYPE_MAX, VTXBUF_ACCRETION);
if (i > 1000) { // if (i > 1000) {
accreted_mass = accreted_mass + sum_mass; accreted_mass = accreted_mass + sum_mass;
} else { // } else {
accreted_mass = 0.0; // accreted_mass = 0.0;
} // }
AcReal sink_mass = 0.0; AcReal sink_mass = 0.0;
//if (i > 1000 ) { //if (i > 1000 ) {
sink_mass = mesh_info.real_params[AC_M_sink_init] + accreted_mass; 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); printf("accreted mass is: %e \n", accreted_mass);
acLoadDeviceConstant(AC_M_sink, sink_mass); acLoadDeviceConstant(AC_M_sink, sink_mass);
vertex_buffer_set(VTXBUF_ACCRETION, 0.0, mesh); 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 #endif
#if LFORCING #if LFORCING
const ForcingParams forcing_params = generateForcingParams(mesh_info); const ForcingParams forcing_params = generateForcingParams(mesh_info);
if (i > 1000) {
loadForcingParamsToDevice(forcing_params); loadForcingParamsToDevice(forcing_params);
}
#endif #endif