fix: remove all source file includes

This commit is contained in:
Max Lübke 2023-09-14 11:34:41 +02:00
parent b9c4474f5a
commit ce09f0d8c8
13 changed files with 87 additions and 91 deletions

View File

@ -7,9 +7,12 @@
*
*/
#include "FTCS.cpp"
#include "Schemes.hpp"
#include "TugUtils.hpp"
#include <omp.h>
#include <tug/Boundary.hpp>
#include <tug/Grid.hpp>
#define NUM_THREADS_BTCS 10
@ -434,7 +437,7 @@ static void BTCS_2D(Grid &grid, Boundary &bc, double timestep,
}
// entry point for EigenLU solver; differentiate between 1D and 2D grid
static void BTCS_LU(Grid &grid, Boundary &bc, double timestep, int numThreads) {
void BTCS_LU(Grid &grid, Boundary &bc, double timestep, int numThreads) {
if (grid.getDim() == 1) {
BTCS_1D(grid, bc, timestep, EigenLUAlgorithm);
} else if (grid.getDim() == 2) {
@ -446,8 +449,7 @@ static void BTCS_LU(Grid &grid, Boundary &bc, double timestep, int numThreads) {
}
// entry point for Thomas algorithm solver; differentiate 1D and 2D grid
static void BTCS_Thomas(Grid &grid, Boundary &bc, double timestep,
int numThreads) {
void BTCS_Thomas(Grid &grid, Boundary &bc, double timestep, int numThreads) {
if (grid.getDim() == 1) {
BTCS_1D(grid, bc, timestep, ThomasAlgorithm);
} else if (grid.getDim() == 2) {
@ -456,4 +458,4 @@ static void BTCS_Thomas(Grid &grid, Boundary &bc, double timestep,
throw_invalid_argument(
"Error: Only 1- and 2-dimensional grids are defined!");
}
}
}

View File

@ -1,4 +1,5 @@
#include "TugUtils.cpp"
#include "TugUtils.hpp"
#include <iostream>
#include <omp.h>
#include <stdexcept>

View File

@ -1,4 +1,4 @@
add_library(tug Boundary.cpp Grid.cpp Simulation.cpp FTCS.cpp BTCSv2.cpp)
add_library(tug Boundary.cpp Grid.cpp Simulation.cpp FTCS.cpp BTCS.cpp)
target_link_libraries(tug Eigen3::Eigen)

View File

@ -5,7 +5,9 @@
*
*/
#include "TugUtils.cpp"
#include "Schemes.hpp"
#include "TugUtils.hpp"
#include <cstddef>
#include <iostream>
#include <omp.h>
@ -377,7 +379,7 @@ static void FTCS_2D(Grid &grid, Boundary &bc, double &timestep,
}
// entry point; differentiate between 1D and 2D grid
static void FTCS(Grid &grid, Boundary &bc, double &timestep, int &numThreads) {
void FTCS(Grid &grid, Boundary &bc, double &timestep, int &numThreads) {
if (grid.getDim() == 1) {
FTCS_1D(grid, bc, timestep);
} else if (grid.getDim() == 2) {

View File

@ -1,4 +1,5 @@
#include "TugUtils.cpp"
#include "TugUtils.hpp"
#include <iostream>
#include <tug/Grid.hpp>

28
src/Schemes.hpp Normal file
View File

@ -0,0 +1,28 @@
/**
* @file BTCSv2.cpp
* @brief Implementation of heterogenous BTCS (backward time-centered space)
* solution of diffusion equation in 1D and 2D space. Internally the
* alternating-direction implicit (ADI) method is used. Version 2, because
* Version 1 was an implementation for the homogeneous BTCS solution.
*
*/
#ifndef SCHEMES_H_
#define SCHEMES_H_
#include "TugUtils.hpp"
#include <tug/Boundary.hpp>
#include <tug/Grid.hpp>
// entry point; differentiate between 1D and 2D grid
extern void FTCS(Grid &grid, Boundary &bc, double &timestep, int &numThreads);
// entry point for EigenLU solver; differentiate between 1D and 2D grid
extern void BTCS_LU(Grid &grid, Boundary &bc, double timestep, int numThreads);
// entry point for Thomas algorithm solver; differentiate 1D and 2D grid
extern void BTCS_Thomas(Grid &grid, Boundary &bc, double timestep,
int numThreads);
#endif // SCHEMES_H_

View File

@ -1,20 +1,18 @@
#include <cmath>
#include <cstddef>
#include <filesystem>
#include <fstream>
#include <omp.h>
#include <stdexcept>
#include <string>
#include <tug/Simulation.hpp>
#include <fstream>
#include "TugUtils.hpp"
#ifndef SIMULATION_H_
#define SIMULATION_H_
#include "BTCSv2.cpp"
using namespace std;
Simulation::Simulation(Grid &grid, Boundary &bc, APPROACH approach)
: grid(grid), bc(bc) {

View File

@ -1,39 +0,0 @@
#include <chrono>
#include <fstream>
#include <stdexcept>
#include <string>
using namespace std;
// used for throwing an invalid argument message
#define throw_invalid_argument(msg) \
throw std::invalid_argument(std::string(__FILE__) + ":" + \
std::to_string(__LINE__) + ":" + \
std::string(msg))
// used for throwing an out of range message
#define throw_out_of_range(msg) \
throw std::out_of_range(std::string(__FILE__) + ":" + \
std::to_string(__LINE__) + ":" + std::string(msg))
// get current time
#define time_marker() std::chrono::high_resolution_clock::now()
// calculates difference between two time points
#define diff_time(start, end) \
({ \
std::chrono::duration<double> duration = \
std::chrono::duration_cast<std::chrono::duration<double>>(end - \
start); \
duration.count(); \
})
// calculates arithmetic or harmonic mean of alpha between two cells
static double calcAlphaIntercell(const double &alpha1, const double &alpha2,
bool useHarmonic = true) {
if (useHarmonic) {
return double(2) / ((double(1) / alpha1) + (double(1) / alpha2));
} else {
return 0.5 * (alpha1 + alpha2);
}
}

View File

@ -1,35 +1,36 @@
// #ifndef BTCSUTILS_H_
// #define BTCSUTILS_H_
#ifndef TUGUTILS_H_
#define TUGUTILS_H_
// #include <chrono>
// #include <stdexcept>
// #include <string>
#include <chrono>
#include <stdexcept>
#include <string>
// #define throw_invalid_argument(msg) \
// throw std::invalid_argument(std::string(__FILE__) + ":" + \
// std::to_string(__LINE__) + ":" + \
// std::string(msg))
#define throw_invalid_argument(msg) \
throw std::invalid_argument(std::string(__FILE__) + ":" + \
std::to_string(__LINE__) + ":" + \
std::string(msg))
// #define throw_out_of_range(msg) \
// throw std::out_of_range(std::string(__FILE__) + ":" + \
// std::to_string(__LINE__) + ":" + std::string(msg))
#define throw_out_of_range(msg) \
throw std::out_of_range(std::string(__FILE__) + ":" + \
std::to_string(__LINE__) + ":" + std::string(msg))
// #define time_marker() std::chrono::high_resolution_clock::now()
#define time_marker() std::chrono::high_resolution_clock::now()
// #define diff_time(start, end) \
// ({ \
// std::chrono::duration<double> duration = \
// std::chrono::duration_cast<std::chrono::duration<double>>(end - \
// start); \
// duration.count(); \
// })
// #endif // BTCSUTILS_H_
#define diff_time(start, end) \
({ \
std::chrono::duration<double> duration = \
std::chrono::duration_cast<std::chrono::duration<double>>(end - \
start); \
duration.count(); \
})
// // calculates arithmetic or harmonic mean of alpha between two cells
// static double calcAlphaIntercell(double &alpha1, double &alpha2, bool useHarmonic = true) {
// if (useHarmonic) {
// return double(2) / ((double(1)/alpha1) + (double(1)/alpha2));
// } else {
// return 0.5 * (alpha1 + alpha2);
// }
// }
// calculates arithmetic or harmonic mean of alpha between two cells
constexpr double calcAlphaIntercell(double alpha1, double alpha2,
bool useHarmonic = true) {
if (useHarmonic) {
return double(2) / ((double(1) / alpha1) + (double(1) / alpha2));
} else {
return 0.5 * (alpha1 + alpha2);
}
}
#endif // TUGUTILS_H_

View File

@ -19,7 +19,7 @@ get_filename_component(testSimulationCSV "FTCS_11_11_7000.csv" REALPATH CACHE)
# set relative path in header file
configure_file(testSimulation.hpp.in testSimulation.hpp)
# include test directory with generated header file from above
target_include_directories(testTug PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
target_include_directories(testTug PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/src")
add_custom_target(
check

View File

@ -9,7 +9,7 @@
using namespace std;
using namespace Eigen;
MatrixXd CSV2Eigen(string file2Convert) {
inline MatrixXd CSV2Eigen(string file2Convert) {
vector<double> matrixEntries;
@ -37,13 +37,13 @@ MatrixXd CSV2Eigen(string file2Convert) {
matrixEntries.size() / matrixRowNumber);
}
bool checkSimilarity(MatrixXd a, MatrixXd b, double precision = 1e-5) {
inline bool checkSimilarity(MatrixXd a, MatrixXd b, double precision = 1e-5) {
return a.isApprox(b, precision);
}
bool checkSimilarityV2(MatrixXd a, MatrixXd b, double maxDiff) {
inline bool checkSimilarityV2(MatrixXd a, MatrixXd b, double maxDiff) {
MatrixXd diff = a - b;
double maxCoeff = diff.maxCoeff();
return abs(maxCoeff) < maxDiff;
}
}

View File

@ -1,4 +1,5 @@
#include <../src/FTCS.cpp>
#include <TugUtils.hpp>
#include <doctest/doctest.h>
#include <limits>
@ -16,4 +17,4 @@ TEST_CASE("Maths") {
CHECK_EQ(calcAlphaIntercell(alpha1, alpha2), harmonicMean);
CHECK_EQ(calcAlphaIntercell(alpha1, alpha2, false), average);
}
}
}

View File

@ -1,4 +1,5 @@
#include "TestUtils.cpp"
#include "TestUtils.hpp"
#include <doctest/doctest.h>
#include <stdio.h>
#include <string>