Merge branch 'master' into sink_20190723
Conflicts: acc/mhd_solver/stencil_defines.h src/standalone/simulation.cc
This commit is contained in:
@@ -29,13 +29,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "config_loader.h"
|
||||
#include "src/core/math_utils.h"
|
||||
#include "model/host_forcing.h"
|
||||
#include "model/host_memory.h"
|
||||
#include "model/host_timestep.h"
|
||||
#include "model/model_boundconds.h"
|
||||
#include "model/model_reduce.h"
|
||||
#include "model/model_rk3.h"
|
||||
#include "src/core/math_utils.h"
|
||||
|
||||
#include "src/core/errchk.h"
|
||||
|
||||
@@ -431,8 +431,9 @@ check_rk3(const AcMeshInfo& mesh_info)
|
||||
acIntegrate(dt);
|
||||
|
||||
model_rk3(dt, model_mesh);
|
||||
boundconds(model_mesh->info, model_mesh);
|
||||
}
|
||||
boundconds(model_mesh->info, model_mesh);
|
||||
acBoundcondStep();
|
||||
acStore(gpu_mesh);
|
||||
|
||||
bool is_acceptable = verify_meshes(*model_mesh, *gpu_mesh);
|
||||
@@ -726,6 +727,7 @@ run_autotest(void)
|
||||
|
||||
// Device integration step
|
||||
acIntegrate(dt);
|
||||
acBoundcondStep();
|
||||
acStore(candidate_mesh);
|
||||
|
||||
// Check fields
|
||||
|
||||
@@ -197,7 +197,6 @@ run_benchmark(void)
|
||||
double(results[int(NTH_PERCENTILE * NUM_ITERS)]), int(NTH_PERCENTILE * 100),
|
||||
mesh_info.int_params[AC_nx]);
|
||||
|
||||
acStore(mesh);
|
||||
acQuit();
|
||||
acmesh_destroy(mesh);
|
||||
}
|
||||
@@ -269,7 +268,6 @@ run_benchmark(void)
|
||||
write_result_to_file(wallclock * 1e3f / steps);
|
||||
#endif
|
||||
|
||||
acStore(mesh);
|
||||
acQuit();
|
||||
acmesh_destroy(mesh);
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ typedef struct {
|
||||
ModelScalar value;
|
||||
ModelVector gradient;
|
||||
ModelMatrix hessian;
|
||||
#if LUPWD
|
||||
ModelVector upwind;
|
||||
#endif
|
||||
} ModelScalarData;
|
||||
|
||||
typedef struct {
|
||||
@@ -273,6 +276,53 @@ derzz(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
return second_derivative(pencil, get(AC_inv_dsz));
|
||||
}
|
||||
|
||||
#if LUPWD
|
||||
static inline ModelScalar
|
||||
der6x_upwd(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
{
|
||||
ModelScalar inv_ds = get(AC_inv_dsx);
|
||||
|
||||
return ModelScalar(1.0/60.0)*inv_ds* (
|
||||
-ModelScalar( 20.0)* arr[IDX(i, j, k)]
|
||||
+ModelScalar( 15.0)*(arr[IDX(i+1, j, k)]
|
||||
+ arr[IDX(i-1, j, k)])
|
||||
-ModelScalar( 6.0)*(arr[IDX(i+2, j, k)]
|
||||
+ arr[IDX(i-2, j, k)])
|
||||
+ arr[IDX(i+3, j, k)]
|
||||
+ arr[IDX(i-3, j, k)]);
|
||||
}
|
||||
|
||||
static inline ModelScalar
|
||||
der6y_upwd(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
{
|
||||
ModelScalar inv_ds = get(AC_inv_dsy);
|
||||
|
||||
return ModelScalar(1.0/60.0)*inv_ds* (
|
||||
-ModelScalar( 20.0)* arr[IDX(i, j, k)]
|
||||
+ModelScalar( 15.0)*(arr[IDX(i, j+1, k)]
|
||||
+ arr[IDX(i, j-1, k)])
|
||||
-ModelScalar( 6.0)*(arr[IDX(i, j+2, k)]
|
||||
+ arr[IDX(i, j-2, k)])
|
||||
+ arr[IDX(i, j+3, k)]
|
||||
+ arr[IDX(i, j-3, k)]);
|
||||
}
|
||||
|
||||
static inline ModelScalar
|
||||
der6z_upwd(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
{
|
||||
ModelScalar inv_ds = get(AC_inv_dsz);
|
||||
|
||||
return ModelScalar(1.0/60.0)*inv_ds* (
|
||||
-ModelScalar( 20.0)* arr[IDX(i, j, k )]
|
||||
+ModelScalar( 15.0)*(arr[IDX(i, j, k+1)]
|
||||
+ arr[IDX(i, j, k-1)])
|
||||
-ModelScalar( 6.0)*(arr[IDX(i, j, k+2)]
|
||||
+ arr[IDX(i, j, k-2)])
|
||||
+ arr[IDX(i, j, k+3)]
|
||||
+ arr[IDX(i, j, k-3)]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline ModelScalar
|
||||
compute_value(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
{
|
||||
@@ -285,6 +335,14 @@ compute_gradient(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
return (ModelVector){derx(i, j, k, arr), dery(i, j, k, arr), derz(i, j, k, arr)};
|
||||
}
|
||||
|
||||
#if LUPWD
|
||||
static inline ModelVector
|
||||
compute_upwind(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
{
|
||||
return (ModelVector){der6x_upwd(i, j, k, arr), der6y_upwd(i, j, k, arr), der6z_upwd(i, j, k, arr)};
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline ModelMatrix
|
||||
compute_hessian(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
{
|
||||
@@ -309,6 +367,10 @@ read_data(const int i, const int j, const int k, ModelScalar* buf[], const int h
|
||||
// diagonals with all arrays
|
||||
data.hessian = compute_hessian(i, j, k, buf[handle]);
|
||||
|
||||
#if LUPWD
|
||||
data.upwind = compute_upwind(i, j, k, buf[handle]);
|
||||
#endif
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -354,6 +416,8 @@ gradients(const ModelVectorData& data)
|
||||
return (ModelMatrix){gradient(data.x), gradient(data.y), gradient(data.z)};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* =============================================================================
|
||||
* Level 0.3 (Built-in functions available during the Stencil Processing Stage)
|
||||
@@ -502,10 +566,27 @@ contract(const ModelMatrix& mat)
|
||||
* Stencil Processing Stage (equations)
|
||||
* =============================================================================
|
||||
*/
|
||||
|
||||
#if LUPWD
|
||||
ModelScalar
|
||||
upwd_der6(const ModelVectorData& uu, const ModelScalarData& lnrho)
|
||||
{
|
||||
ModelScalar uux = fabs(value(uu).x);
|
||||
ModelScalar uuy = fabs(value(uu).y);
|
||||
ModelScalar uuz = fabs(value(uu).z);
|
||||
return uux*lnrho.upwind.x + uuy*lnrho.upwind.y + uuz*lnrho.upwind.z;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline ModelScalar
|
||||
continuity(const ModelVectorData& uu, const ModelScalarData& lnrho)
|
||||
{
|
||||
return -dot(value(uu), gradient(lnrho)) - divergence(uu);
|
||||
return -dot(value(uu), gradient(lnrho))
|
||||
#if LUPWD
|
||||
//This is a corrective hyperdiffusion term for upwinding.
|
||||
+ upwd_der6(uu, lnrho)
|
||||
#endif
|
||||
- divergence(uu);
|
||||
}
|
||||
|
||||
static inline ModelScalar
|
||||
@@ -679,23 +760,24 @@ helical_forcing(ModelScalar magnitude, ModelVector k_force, ModelVector xx, Mode
|
||||
ModelVector ff_im, ModelScalar phi)
|
||||
{
|
||||
(void)magnitude; // WARNING: unused
|
||||
xx.x = xx.x * (2.0l * M_PI / (get(AC_dsx) * (get(AC_ny_max) - get(AC_ny_min))));
|
||||
xx.y = xx.y * (2.0l * M_PI / (get(AC_dsy) * (get(AC_ny_max) - get(AC_ny_min))));
|
||||
xx.z = xx.z * (2.0l * M_PI / (get(AC_dsz) * (get(AC_ny_max) - get(AC_ny_min))));
|
||||
xx.x = xx.x*(2.0*M_PI/(get(AC_dsx)*get(AC_nx)));
|
||||
xx.y = xx.y*(2.0*M_PI/(get(AC_dsy)*get(AC_ny)));
|
||||
xx.z = xx.z*(2.0*M_PI/(get(AC_dsz)*get(AC_nz)));
|
||||
|
||||
ModelScalar cosl_phi = cosl(phi);
|
||||
ModelScalar sinl_phi = sinl(phi);
|
||||
ModelScalar cosl_k_dox_x = cosl(dot(k_force, xx));
|
||||
ModelScalar sinl_k_dox_x = sinl(dot(k_force, xx));
|
||||
ModelScalar cos_phi = cosl(phi);
|
||||
ModelScalar sin_phi = sinl(phi);
|
||||
ModelScalar cos_k_dot_x = cosl(dot(k_force, xx));
|
||||
ModelScalar sin_k_dot_x = sinl(dot(k_force, xx));
|
||||
// Phase affect only the x-component
|
||||
// ModelScalar real_comp = cosl_k_dox_x;
|
||||
// ModelScalar imag_comp = sinl_k_dox_x;
|
||||
ModelScalar real_comp_phase = cosl_k_dox_x * cosl_phi - sinl_k_dox_x * sinl_phi;
|
||||
ModelScalar imag_comp_phase = cosl_k_dox_x * sinl_phi + sinl_k_dox_x * cosl_phi;
|
||||
//Scalar real_comp = cos_k_dot_x;
|
||||
//Scalar imag_comp = sin_k_dot_x;
|
||||
ModelScalar real_comp_phase = cos_k_dot_x*cos_phi - sin_k_dot_x*sin_phi;
|
||||
ModelScalar imag_comp_phase = cos_k_dot_x*sin_phi + sin_k_dot_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};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
#include <string.h> // memcpy
|
||||
|
||||
#include "config_loader.h"
|
||||
#include "src/core/errchk.h"
|
||||
#include "src/core/math_utils.h"
|
||||
#include "model/host_forcing.h"
|
||||
#include "model/host_memory.h"
|
||||
#include "model/host_timestep.h"
|
||||
#include "model/model_reduce.h"
|
||||
#include "model/model_rk3.h"
|
||||
#include "src/core/errchk.h"
|
||||
#include "src/core/math_utils.h"
|
||||
#include "timer_hires.h"
|
||||
|
||||
// Window
|
||||
@@ -106,6 +106,7 @@ renderer_init(const int& mx, const int& my)
|
||||
// Setup window
|
||||
window = SDL_CreateWindow("Astaroth", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
window_width, window_height, SDL_WINDOW_SHOWN);
|
||||
ERRCHK_ALWAYS(window);
|
||||
|
||||
// Setup SDL renderer
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
@@ -409,9 +410,10 @@ run_renderer(void)
|
||||
/* Render */
|
||||
const float timer_diff_sec = timer_diff_nsec(frame_timer) / 1e9f;
|
||||
if (timer_diff_sec >= desired_frame_time) {
|
||||
// acStore(mesh);
|
||||
const int num_vertices = mesh->info.int_params[AC_mxy];
|
||||
const int3 dst = (int3){0, 0, k_slice};
|
||||
acBoundcondStep();
|
||||
// acStore(mesh);
|
||||
acStoreWithOffset(dst, num_vertices, mesh);
|
||||
acSynchronizeStream(STREAM_ALL);
|
||||
renderer_draw(*mesh); // Bottleneck is here
|
||||
@@ -421,7 +423,6 @@ run_renderer(void)
|
||||
}
|
||||
printf("Wallclock time %f s\n", double(timer_diff_nsec(wallclock) / 1e9f));
|
||||
|
||||
acStore(mesh);
|
||||
acQuit();
|
||||
acmesh_destroy(mesh);
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
#include "run.h"
|
||||
|
||||
#include "config_loader.h"
|
||||
#include "src/core/errchk.h"
|
||||
#include "src/core/math_utils.h"
|
||||
#include "model/host_forcing.h"
|
||||
#include "model/host_memory.h"
|
||||
#include "model/host_timestep.h"
|
||||
#include "model/model_reduce.h"
|
||||
#include "model/model_rk3.h"
|
||||
#include "src/core/errchk.h"
|
||||
#include "src/core/math_utils.h"
|
||||
#include "timer_hires.h"
|
||||
|
||||
#include <string.h>
|
||||
@@ -216,6 +216,7 @@ run_simulation(void)
|
||||
write_mesh_info(&mesh_info);
|
||||
print_diagnostics(0, AcReal(.0), t_step, diag_file);
|
||||
|
||||
acBoundcondStep();
|
||||
acStore(mesh);
|
||||
save_mesh(*mesh, 0, t_step);
|
||||
|
||||
@@ -229,13 +230,13 @@ run_simulation(void)
|
||||
/* initialize random seed: */
|
||||
srand(312256655);
|
||||
|
||||
//TODO_SINK. init_sink_particle()
|
||||
// TODO_SINK. init_sink_particle()
|
||||
// Initialize the basic variables of the sink particle to a suitable initial value.
|
||||
// 1. Location of the particle
|
||||
// 2. Mass of the particle
|
||||
// (3. Velocity of the particle)
|
||||
// This at the level of Host in this case.
|
||||
// acUpdate_sink_particle() will do the similar trick to the device.
|
||||
// This at the level of Host in this case.
|
||||
// acUpdate_sink_particle() will do the similar trick to the device.
|
||||
|
||||
/* Step the simulation */
|
||||
for (int i = 1; i < max_steps; ++i) {
|
||||
@@ -247,28 +248,28 @@ run_simulation(void)
|
||||
loadForcingParamsToDevice(forcing_params);
|
||||
#endif
|
||||
|
||||
|
||||
//TODO_SINK acUpdate_sink_particle()
|
||||
// Update properties of the sing particle for acIntegrate(). Essentially:
|
||||
// 1. Location of the particle
|
||||
// 2. Mass of the particle
|
||||
// (3. Velocity of the particle)
|
||||
// 3. Velocity of the particle)
|
||||
// These can be used for calculating he gravitational field.
|
||||
// This is my first comment! by Jack
|
||||
// This is my second comment! by Jack
|
||||
|
||||
acIntegrate(dt);
|
||||
//TODO_SINK acAdvect_sink_particle()
|
||||
// THIS IS OPTIONAL. We will start from unmoving particle.
|
||||
// 1. Calculate the equation of motion for the sink particle.
|
||||
// NOTE: Might require embedding with acIntegrate(dt).
|
||||
// TODO_SINK acAdvect_sink_particle()
|
||||
// THIS IS OPTIONAL. We will start from unmoving particle.
|
||||
// 1. Calculate the equation of motion for the sink particle.
|
||||
// NOTE: Might require embedding with acIntegrate(dt).
|
||||
|
||||
//TODO_SINK acAccrete_sink_particle()
|
||||
// Calculate accretion of the sink particle from the surrounding medium
|
||||
// 1. Transfer density into sink particle mass
|
||||
// 2. Transfer momentum into sink particle
|
||||
// (OPTIONAL: Affection the motion of the particle)
|
||||
// NOTE: Might require embedding with acIntegrate(dt).
|
||||
// This is the hardest part. Please see Lee et al. ApJ 783 (2014) for reference.
|
||||
// TODO_SINK acAccrete_sink_particle()
|
||||
// Calculate accretion of the sink particle from the surrounding medium
|
||||
// 1. Transfer density into sink particle mass
|
||||
// 2. Transfer momentum into sink particle
|
||||
// (OPTIONAL: Affection the motion of the particle)
|
||||
// NOTE: Might require embedding with acIntegrate(dt).
|
||||
// This is the hardest part. Please see Lee et al. ApJ 783 (2014) for reference.
|
||||
|
||||
t_step += dt;
|
||||
|
||||
@@ -311,9 +312,10 @@ run_simulation(void)
|
||||
assumed to be asynchronous, so the meshes must be also synchronized
|
||||
before transferring the data to the CPU. Like so:
|
||||
|
||||
acSynchronize();
|
||||
acBoundcondStep();
|
||||
acStore(mesh);
|
||||
*/
|
||||
acBoundcondStep();
|
||||
acStore(mesh);
|
||||
|
||||
save_mesh(*mesh, i, t_step);
|
||||
|
||||
Reference in New Issue
Block a user