Added an example for creating arbitrary projects, see acc/test_solver and src/exampleproject. Note: make sure that dt is calculated adequately and that all parameters are defined properly (see src/exampleproject/simulation.cc)

This commit is contained in:
jpekkila
2019-10-01 15:33:26 +03:00
parent 5a45fe11a8
commit 19b16eecc8
5 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#include "stencil_definition.sdh"
//JP NOTE IMPORTANT/////////////////////////////////////////////////////////////////////////////////
// These functions are defined here temporarily.
//
// Currently the built-in functions (derx, derxx etc) are defined in CUDA in integrate.cuh.
// This is bad. Instead the built-in functions should be defined in the DSL, and be "includable"
// as a standard DSL library, analogous to f.ex. stdlib.h in C.
////////////////////////////////////////////////////////////////////////////////////////////////////
Preprocessed Scalar
value(in ScalarField vertex)
{
return vertex[vertexIdx];
}
Preprocessed Vector
gradient(in ScalarField vertex)
{
return (Vector){derx(vertexIdx, vertex), dery(vertexIdx, vertex), derz(vertexIdx, vertex)};
}
Preprocessed Matrix
hessian(in ScalarField vertex)
{
Matrix hessian;
hessian.row[0] = (Vector){derxx(vertexIdx, vertex), derxy(vertexIdx, vertex),
derxz(vertexIdx, vertex)};
hessian.row[1] = (Vector){hessian.row[0].y, deryy(vertexIdx, vertex), deryz(vertexIdx, vertex)};
hessian.row[2] = (Vector){hessian.row[0].z, hessian.row[1].z, derzz(vertexIdx, vertex)};
return hessian;
}

View File

@@ -0,0 +1,18 @@
//JP NOTE IMPORTANT/////////////////////////////////////////////////////////////////////////////////
// AC_dsx etc are defined here temporarily (otherwise does not compile).
//
// These should ultimately be defined in the standard DSL libraries.
// See test_solver/stencil_assembly.sas for more info.
////////////////////////////////////////////////////////////////////////////////////////////////////
uniform Scalar AC_dsx;// TODO include these from the std lib
uniform Scalar AC_dsy;
uniform Scalar AC_dsz;
uniform Scalar AC_inv_dsx;
uniform Scalar AC_inv_dsy;
uniform Scalar AC_inv_dsz;
uniform Scalar AC_dt;
uniform ScalarField VTXBUF_A;
uniform ScalarField VTXBUF_B;
uniform ScalarField VTXBUF_C;

View File

@@ -0,0 +1,18 @@
#include "stencil_definition.sdh"
Vector
value(in VectorField uu)
{
return (Vector){value(uu.x), value(uu.y), value(uu.z)};
}
in VectorField uu(VTXBUF_A, VTXBUF_B, VTXBUF_C);
out VectorField out_uu(VTXBUF_A, VTXBUF_B, VTXBUF_C);
Kernel void
solve()
{
Scalar dt = AC_dt;
Vector rate_of_change = (Vector){1, 2, 3};
out_uu = rk3(out_uu, uu, rate_of_change, dt);
}

View File

@@ -0,0 +1,11 @@
## C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## Compilation flags
add_compile_options(-Wall -Wextra -Werror -Wdouble-promotion -Wfloat-conversion -Wshadow)
## Compile and link
add_executable(ac_simulate simulation.cc)
target_link_libraries(ac_simulate PRIVATE astaroth_core astaroth_utils)
add_definitions(-DAC_DEFAULT_CONFIG="${CMAKE_SOURCE_DIR}/config/astaroth.conf")

View File

@@ -0,0 +1,77 @@
/*
Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
This file is part of Astaroth.
Astaroth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Astaroth is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
*/
#include "src/utils/config_loader.h"
#include "src/utils/memory.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
int
run_simulation(const char* config_path)
{
AcMeshInfo info;
acLoadConfig(config_path, &info);
AcMesh mesh;
acMeshCreate(info, &mesh);
acMeshClear(&mesh);
acInit(info);
acLoad(mesh);
const size_t num_steps = 10;
for (size_t i = 0; i < num_steps; ++i) {
const AcReal dt = 1; // JP: TODO! Set timestep here!
// JP: TODO! Make sure that AcMeshInfo parameters are properly initialized before calling
// acIntegrate()
// NANs indicate that either dt is too large or something was uninitalized
acIntegrate(dt);
}
for (int i = 0; i < NUM_VTXBUF_HANDLES; ++i) {
printf("%s:\n", vtxbuf_names[i]);
printf("\tmax: %g\n", (double)acReduceScal(RTYPE_MAX, VertexBufferHandle(i)));
printf("\tmin: %g\n", (double)acReduceScal(RTYPE_MIN, VertexBufferHandle(i)));
printf("\trms: %g\n", (double)acReduceScal(RTYPE_RMS, VertexBufferHandle(i)));
printf("\texp rms: %g\n", (double)acReduceScal(RTYPE_RMS_EXP, VertexBufferHandle(i)));
}
acStore(&mesh);
acQuit();
acMeshDestroy(&mesh);
return EXIT_SUCCESS;
}
int
main(int argc, char* argv[])
{
printf("Args: \n");
for (int i = 0; i < argc; ++i)
printf("%d: %s\n", i, argv[i]);
char* config_path;
(argc == 3) ? config_path = strdup(argv[2]) : config_path = strdup(AC_DEFAULT_CONFIG);
printf("Config path: %s\n", config_path);
assert(config_path);
run_simulation(config_path);
free(config_path);
return EXIT_SUCCESS;
}