Updated samples to have consistent naming

This commit is contained in:
jpekkila
2020-01-15 16:56:02 +02:00
parent efa95147f3
commit 65d9274eaa
7 changed files with 74 additions and 82 deletions

3
samples/CMakeLists.txt Normal file
View File

@@ -0,0 +1,3 @@
add_subdirectory(ctest)
add_subdirectory(cpptest)
add_subdirectory(mpitest)

View File

@@ -6,6 +6,5 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
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")
add_executable(cpptest main.cc)
target_link_libraries(cpptest PRIVATE astaroth_core astaroth_utils)

58
samples/cpptest/main.cc Normal file
View File

@@ -0,0 +1,58 @@
/*
Copyright (C) 2014-2020, Johannes Pekkila, Miikka Vaisala.
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 <assert.h>
#include <stdio.h>
#include <string.h>
#include "astaroth.h"
// From Astaroth Utils
#include "src/utils/config_loader.h"
#include "src/utils/memory.h"
#include "src/utils/verification.h"
int
main(void)
{
AcMeshInfo info;
acLoadConfig(AC_DEFAULT_CONFIG, &info);
// Alloc
AcMesh model, candidate;
acMeshCreate(info, &model);
acMeshCreate(info, &candidate);
// Init
acMeshRandomize(&model);
acMeshApplyPeriodicBounds(&model);
////////////////////////////////////////////////////////////////////////////////////////////////
acInit(info);
acLoad(model);
acStore(&candidate);
acQuit();
////////////////////////////////////////////////////////////////////////////////////////////////
// Verify and destroy
acVerifyMesh(model, candidate);
acMeshDestroy(&model);
acMeshDestroy(&candidate);
return EXIT_SUCCESS;
}

View File

@@ -1,77 +0,0 @@
/*
Copyright (C) 2014-2020, Johannes Pekkila, Miikka Vaisala.
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;
}

View File

@@ -41,7 +41,6 @@ main(void)
acMeshRandomize(&model);
acMeshApplyPeriodicBounds(&model);
// TODO load to candidate
////////////////////////////////////////////////////////////////////////////////////////////////
acInit(info);
acLoad(model);

View File

@@ -6,4 +6,4 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(mpitest main.cc)
target_link_libraries(mpitest astaroth_core)
target_link_libraries(mpitest astaroth_core astaroth_utils)

View File

@@ -1 +1,11 @@
This directory is used to test MPI with Astaroth.
Building (in the base astaroth directory):
cmake -DBUILD_SAMPLES=ON -DMPI_ENABLED=ON -DCMAKE_CXX_COMPILER=$(which mpicxx) .. && make -j
Running:
mpirun -np <nprocs> ./mpitest
or
srun <options> ./mpitest # With slurm
or
a batch script of your choice