src/utils is now a real library. Includable with the astaroth_utils.h header and linkable with libastaroth_utils.a. The purpose of Astaroth Utils is to function as a generic utility library in contrast to Astaroth Standalone which is essentially hardcoded only for MHD.
This commit is contained in:
@@ -1,10 +1,3 @@
|
||||
## C++ standard
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
## Compile
|
||||
find_package(OpenMP)
|
||||
## Astaroth Utils
|
||||
add_library(astaroth_utils STATIC config_loader.c memory.c verification.c modelsolver.c)
|
||||
target_link_libraries(astaroth_utils PRIVATE astaroth_core OpenMP::OpenMP_C)
|
||||
target_compile_options(astaroth_utils PRIVATE -Wall -Wextra -Werror -Wdouble-promotion -Wfloat-conversion -Wshadow)
|
||||
target_compile_options(astaroth_utils PRIVATE -mavx)
|
||||
add_dependencies(astaroth_utils dsl_headers)
|
||||
|
@@ -24,15 +24,12 @@
|
||||
* Detailed info.
|
||||
*
|
||||
*/
|
||||
#include "config_loader.h"
|
||||
#include "astaroth_utils.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h> // UINT_MAX
|
||||
#include <math.h>
|
||||
#include <stdint.h> // uint8_t, uint32_t
|
||||
#include <stdio.h> // print
|
||||
#include <string.h> // memset
|
||||
//#include "src/core/math_utils.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "errchk.h"
|
||||
|
||||
/**
|
||||
\brief Find the index of the keyword in names
|
||||
@@ -56,7 +53,7 @@ parse_config(const char* path, AcMeshInfo* config)
|
||||
fp = fopen(path, "r");
|
||||
// For knowing which .conf file will be used
|
||||
printf("Config file path: \n %s \n ", path);
|
||||
assert(fp != NULL);
|
||||
ERRCHK_ALWAYS(fp != NULL);
|
||||
|
||||
const size_t BUF_SIZE = 128;
|
||||
char keyword[BUF_SIZE];
|
||||
@@ -78,7 +75,7 @@ parse_config(const char* path, AcMeshInfo* config)
|
||||
}
|
||||
|
||||
AcResult
|
||||
acUpdateConfig(AcMeshInfo* config)
|
||||
acUpdateBuiltinParams(AcMeshInfo* config)
|
||||
{
|
||||
config->int_params[AC_mx] = config->int_params[AC_nx] + STENCIL_ORDER;
|
||||
///////////// PAD TEST
|
||||
@@ -96,7 +93,7 @@ acUpdateConfig(AcMeshInfo* config)
|
||||
config->int_params[AC_nz_max] = config->int_params[AC_nz] + STENCIL_ORDER / 2;
|
||||
|
||||
/*
|
||||
// DEPRECATED: Spacing
|
||||
// DEPRECATED: Spacing TODO
|
||||
// These do not have to be defined by empty projects any more.
|
||||
// These should be set only if stdderiv.h is included
|
||||
config->real_params[AC_inv_dsx] = (AcReal)(1.) / config->real_params[AC_dsx];
|
||||
@@ -121,14 +118,14 @@ AcResult
|
||||
acLoadConfig(const char* config_path, AcMeshInfo* config)
|
||||
{
|
||||
int retval = AC_SUCCESS;
|
||||
assert(config_path);
|
||||
ERRCHK_ALWAYS(config_path);
|
||||
|
||||
// memset reads the second parameter as a byte even though it says int in
|
||||
// the function declaration
|
||||
memset(config, (uint8_t)0xFF, sizeof(*config));
|
||||
|
||||
parse_config(config_path, config);
|
||||
acUpdateConfig(config);
|
||||
acUpdateBuiltinParams(config);
|
||||
#if VERBOSE_PRINTING // Defined in astaroth.h
|
||||
printf("###############################################################\n");
|
||||
printf("Config dimensions loaded:\n");
|
||||
@@ -137,7 +134,7 @@ acLoadConfig(const char* config_path, AcMeshInfo* config)
|
||||
#endif
|
||||
|
||||
// sizeof(config) must be a multiple of 4 bytes for this to work
|
||||
assert(sizeof(*config) % sizeof(uint32_t) == 0);
|
||||
ERRCHK_ALWAYS(sizeof(*config) % sizeof(uint32_t) == 0);
|
||||
for (size_t i = 0; i < sizeof(*config) / sizeof(uint32_t); ++i) {
|
||||
if (((uint32_t*)config)[i] == (uint32_t)0xFFFFFFFF) {
|
||||
fprintf(stderr, "Some config values may be uninitialized. "
|
||||
|
@@ -1,40 +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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* \brief Functions for loading and updating AcMeshInfo.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "astaroth.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Loads data from the config file */
|
||||
AcResult acLoadConfig(const char* config_path, AcMeshInfo* config);
|
||||
|
||||
/** Updates the built-in parameters based on nx, ny and nz */
|
||||
AcResult acUpdateConfig(AcMeshInfo* config);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
@@ -16,12 +16,9 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "memory.h"
|
||||
#include "astaroth_utils.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "src/core/errchk.h"
|
||||
#include "errchk.h"
|
||||
|
||||
AcResult
|
||||
acMeshCreate(const AcMeshInfo info, AcMesh* mesh)
|
||||
@@ -96,7 +93,7 @@ acMeshApplyPeriodicBounds(AcMesh* mesh)
|
||||
const int ny_max = info.int_params[AC_ny_max];
|
||||
const int nz_max = info.int_params[AC_nz_max];
|
||||
|
||||
#pragma omp parallel for
|
||||
// #pragma omp parallel for
|
||||
for (int k_dst = start.z; k_dst < end.z; ++k_dst) {
|
||||
for (int j_dst = start.y; j_dst < end.y; ++j_dst) {
|
||||
for (int i_dst = start.x; i_dst < end.x; ++i_dst) {
|
||||
|
@@ -1,48 +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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* \brief Brief info.
|
||||
*
|
||||
* Detailed info.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "astaroth.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
AcResult acMeshCreate(const AcMeshInfo mesh_info, AcMesh* mesh);
|
||||
|
||||
AcResult acMeshDestroy(AcMesh* mesh);
|
||||
|
||||
AcResult acMeshSet(const AcReal value, AcMesh* mesh);
|
||||
|
||||
AcResult acMeshRandomize(AcMesh* mesh);
|
||||
|
||||
AcResult acMeshApplyPeriodicBounds(AcMesh* mesh);
|
||||
|
||||
AcResult acMeshClear(AcMesh* mesh);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
@@ -24,7 +24,7 @@
|
||||
* Detailed info.
|
||||
*
|
||||
*/
|
||||
#include "modelsolver.h"
|
||||
#include "astaroth_utils.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
@@ -937,8 +937,8 @@ acModelIntegrateStep(AcMesh mesh, const AcReal dt)
|
||||
// Boundconds
|
||||
acMeshApplyPeriodicBounds(&mesh);
|
||||
|
||||
// Alpha step
|
||||
#pragma omp parallel for
|
||||
// Alpha step
|
||||
// #pragma omp parallel for
|
||||
for (int k = nz_min; k < nz_max; ++k) {
|
||||
for (int j = ny_min; j < ny_max; ++j) {
|
||||
for (int i = nx_min; i < nx_max; ++i) {
|
||||
@@ -947,8 +947,8 @@ acModelIntegrateStep(AcMesh mesh, const AcReal dt)
|
||||
}
|
||||
}
|
||||
|
||||
// Beta step
|
||||
#pragma omp parallel for
|
||||
// Beta step
|
||||
// #pragma omp parallel for
|
||||
for (int k = nz_min; k < nz_max; ++k) {
|
||||
for (int j = ny_min; j < ny_max; ++j) {
|
||||
for (int i = nx_min; i < nx_max; ++i) {
|
||||
|
@@ -1,38 +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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* \brief Brief info.
|
||||
*
|
||||
* Detailed info.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "astaroth.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
AcResult acModelIntegrateStep(AcMesh mesh, const AcReal dt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
@@ -1,63 +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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@file
|
||||
\brief High-resolution timer.
|
||||
|
||||
Usage:
|
||||
Timer t;
|
||||
timer_reset(&t);
|
||||
timer_diff_nsec(t);
|
||||
|
||||
If there are issues, try compiling with -std=gnu11 -lrt
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdio.h> // perror
|
||||
#include <time.h>
|
||||
|
||||
typedef struct timespec Timer;
|
||||
// Contains at least the following members:
|
||||
// time_t tv_sec;
|
||||
// long tv_nsec;
|
||||
|
||||
static inline int
|
||||
timer_reset(Timer* t)
|
||||
{
|
||||
const int retval = clock_gettime(CLOCK_REALTIME, t);
|
||||
if (retval == -1)
|
||||
perror("clock_gettime failure");
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static inline long
|
||||
timer_diff_nsec(const Timer start)
|
||||
{
|
||||
Timer end;
|
||||
timer_reset(&end);
|
||||
const long diff = (end.tv_sec - start.tv_sec) * 1000000000l + (end.tv_nsec - start.tv_nsec);
|
||||
return diff;
|
||||
}
|
||||
|
||||
static inline void
|
||||
timer_diff_print(const Timer t)
|
||||
{
|
||||
printf("Time elapsed: %g ms\n", timer_diff_nsec(t) / 1e6);
|
||||
}
|
@@ -1,9 +1,7 @@
|
||||
#include "verification.h"
|
||||
#include "astaroth_utils.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "astaroth.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
@@ -171,7 +169,7 @@ print_error_to_screen(const Error error)
|
||||
}
|
||||
|
||||
/** Returns true when successful, false if errors were found. */
|
||||
bool
|
||||
AcResult
|
||||
acVerifyMesh(const AcMesh model, const AcMesh candidate)
|
||||
{
|
||||
printf("Errors at the point of the maximum absolute error:\n");
|
||||
@@ -185,5 +183,8 @@ acVerifyMesh(const AcMesh model, const AcMesh candidate)
|
||||
printf("%s\n", errors_found ? "Failure. Found errors in one or more vertex buffers"
|
||||
: "Success. No errors found.");
|
||||
|
||||
return !errors_found;
|
||||
if (errors_found)
|
||||
return AC_FAILURE;
|
||||
else
|
||||
return AC_SUCCESS;
|
||||
}
|
||||
|
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "memory.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool acVerifyMesh(const AcMesh model, const AcMesh candidate);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
Reference in New Issue
Block a user