Merge branch 'master' into sink_20190723
Conflicts: acc/mhd_solver/stencil_process.sps I've mannaully resolved the conflict, only that I'm leaving int3 globalVertexIdx as is, as instructed by Miikka.
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
// #include "astaroth_defines.h"
|
||||
#include "astaroth.h"
|
||||
|
||||
#include "errchk.h"
|
||||
#include "math_utils.h" // int3 + int3
|
||||
|
||||
#define AC_GEN_STR(X) #X
|
||||
const char* intparam_names[] = {AC_FOR_BUILTIN_INT_PARAM_TYPES(AC_GEN_STR) //
|
||||
AC_FOR_USER_INT_PARAM_TYPES(AC_GEN_STR)};
|
||||
@@ -33,10 +36,13 @@ const char* vtxbuf_names[] = {AC_FOR_VTXBUF_HANDLES(AC_GEN_STR)};
|
||||
|
||||
static const int num_nodes = 1;
|
||||
static Node nodes[num_nodes];
|
||||
static int3 grid_n;
|
||||
|
||||
AcResult
|
||||
acInit(const AcMeshInfo mesh_info)
|
||||
{
|
||||
grid_n = (int3){mesh_info.int_params[AC_nx], mesh_info.int_params[AC_ny],
|
||||
mesh_info.int_params[AC_nz]};
|
||||
return acNodeCreate(0, mesh_info, &nodes[0]);
|
||||
}
|
||||
|
||||
@@ -46,6 +52,23 @@ acQuit(void)
|
||||
return acNodeDestroy(nodes[0]);
|
||||
}
|
||||
|
||||
AcResult
|
||||
acCheckDeviceAvailability(void)
|
||||
{
|
||||
int device_count; // Separate from num_devices to avoid side effects
|
||||
ERRCHK_CUDA_ALWAYS(cudaGetDeviceCount(&device_count));
|
||||
if (device_count > 0)
|
||||
return AC_SUCCESS;
|
||||
else
|
||||
return AC_FAILURE;
|
||||
}
|
||||
|
||||
AcResult
|
||||
acSynchronize(void)
|
||||
{
|
||||
return acNodeSynchronizeStream(nodes[0], STREAM_ALL);
|
||||
}
|
||||
|
||||
AcResult
|
||||
acSynchronizeStream(const Stream stream)
|
||||
{
|
||||
@@ -80,6 +103,20 @@ acIntegrate(const AcReal dt)
|
||||
return acNodeIntegrate(nodes[0], dt);
|
||||
}
|
||||
|
||||
AcResult
|
||||
acIntegrateStep(const int isubstep, const AcReal dt)
|
||||
{
|
||||
const int3 start = (int3){NGHOST, NGHOST, NGHOST};
|
||||
const int3 end = start + grid_n;
|
||||
return acNodeIntegrateSubstep(nodes[0], STREAM_DEFAULT, isubstep, start, end, dt);
|
||||
}
|
||||
|
||||
AcResult
|
||||
acIntegrateStepWithOffset(const int isubstep, const AcReal dt, const int3 start, const int3 end)
|
||||
{
|
||||
return acNodeIntegrateSubstep(nodes[0], STREAM_DEFAULT, isubstep, start, end, dt);
|
||||
}
|
||||
|
||||
AcResult
|
||||
acBoundcondStep(void)
|
||||
{
|
||||
@@ -108,3 +145,9 @@ acStoreWithOffset(const int3 dst, const size_t num_vertices, AcMesh* host_mesh)
|
||||
{
|
||||
return acNodeStoreMeshWithOffset(nodes[0], STREAM_DEFAULT, dst, dst, num_vertices, host_mesh);
|
||||
}
|
||||
|
||||
AcResult
|
||||
acLoadWithOffset(const AcMesh host_mesh, const int3 src, const int num_vertices)
|
||||
{
|
||||
return acNodeLoadMeshWithOffset(nodes[0], STREAM_DEFAULT, host_mesh, src, src, num_vertices);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ IDX(const int3 idx)
|
||||
return DEVICE_VTXBUF_IDX(idx.x, idx.y, idx.z);
|
||||
}
|
||||
|
||||
#define make_int3(a, b, c) \
|
||||
(int3) { (int)a, (int)b, (int)c }
|
||||
|
||||
static __forceinline__ AcMatrix
|
||||
create_rotz(const AcReal radians)
|
||||
{
|
||||
|
||||
@@ -282,14 +282,11 @@ 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)]);
|
||||
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
|
||||
@@ -297,14 +294,11 @@ 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)]);
|
||||
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
|
||||
@@ -312,14 +306,11 @@ 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)]);
|
||||
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
|
||||
|
||||
@@ -339,7 +330,8 @@ compute_gradient(const int i, const int j, const int k, const ModelScalar* arr)
|
||||
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)};
|
||||
return (ModelVector){der6x_upwd(i, j, k, arr), der6y_upwd(i, j, k, arr),
|
||||
der6z_upwd(i, j, k, arr)};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -368,7 +360,7 @@ read_data(const int i, const int j, const int k, ModelScalar* buf[], const int h
|
||||
data.hessian = compute_hessian(i, j, k, buf[handle]);
|
||||
|
||||
#if LUPWD
|
||||
data.upwind = compute_upwind(i, j, k, buf[handle]);
|
||||
data.upwind = compute_upwind(i, j, k, buf[handle]);
|
||||
#endif
|
||||
|
||||
return data;
|
||||
@@ -416,8 +408,6 @@ 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)
|
||||
@@ -571,10 +561,10 @@ contract(const ModelMatrix& mat)
|
||||
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;
|
||||
ModelScalar uux = fabsl(value(uu).x);
|
||||
ModelScalar uuy = fabsl(value(uu).y);
|
||||
ModelScalar uuz = fabsl(value(uu).z);
|
||||
return uux * lnrho.upwind.x + uuy * lnrho.upwind.y + uuz * lnrho.upwind.z;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -583,7 +573,7 @@ continuity(const ModelVectorData& uu, const ModelScalarData& lnrho)
|
||||
{
|
||||
return -dot(value(uu), gradient(lnrho))
|
||||
#if LUPWD
|
||||
//This is a corrective hyperdiffusion term for upwinding.
|
||||
// This is a corrective hyperdiffusion term for upwinding.
|
||||
+ upwd_der6(uu, lnrho)
|
||||
#endif
|
||||
- divergence(uu);
|
||||
@@ -760,24 +750,23 @@ helical_forcing(ModelScalar magnitude, ModelVector k_force, ModelVector xx, Mode
|
||||
ModelVector ff_im, ModelScalar phi)
|
||||
{
|
||||
(void)magnitude; // WARNING: unused
|
||||
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)));
|
||||
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 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));
|
||||
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
|
||||
//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;
|
||||
// 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user