mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-15 18:38:23 +01:00
BREAKING CHANGE: Rename Simulation to Diffusion
chore: Cleanup of applications
This commit is contained in:
parent
ac693caea9
commit
16fbefa9ed
@ -1,4 +1,4 @@
|
||||
Simulation
|
||||
Diffusion
|
||||
==========
|
||||
|
||||
.. doxygenenum:: tug::APPROACH
|
||||
@ -7,4 +7,4 @@ Simulation
|
||||
.. doxygenenum:: tug::CONSOLE_OUTPUT
|
||||
.. doxygenenum:: tug::TIME_MEASURE
|
||||
|
||||
.. doxygenclass:: tug::Simulation
|
||||
.. doxygenclass:: tug::Diffusion
|
||||
@ -5,4 +5,4 @@ User API
|
||||
|
||||
Grid
|
||||
Boundary
|
||||
Simulation
|
||||
Diffusion
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// **************
|
||||
// **** GRID ****
|
||||
// **************
|
||||
|
||||
// create a linear grid with 20 cells
|
||||
int cells = 20;
|
||||
Grid64 grid(cells);
|
||||
|
||||
MatrixXd concentrations = MatrixXd::Constant(1, 20, 0);
|
||||
concentrations(0, 0) = 2000;
|
||||
// TODO add option to set concentrations with a vector in 1D case
|
||||
grid.setConcentrations(concentrations);
|
||||
|
||||
// ******************
|
||||
// **** BOUNDARY ****
|
||||
// ******************
|
||||
|
||||
// create a boundary with constant values
|
||||
Boundary bc = Boundary(grid);
|
||||
bc.setBoundarySideConstant(BC_SIDE_LEFT, 0);
|
||||
bc.setBoundarySideConstant(BC_SIDE_RIGHT, 0);
|
||||
|
||||
// ************************
|
||||
// **** SIMULATION ENV ****
|
||||
// ************************
|
||||
|
||||
// set up a simulation environment
|
||||
Simulation simulation = Simulation(grid, bc); // grid,boundary
|
||||
|
||||
// set the timestep of the simulation
|
||||
simulation.setTimestep(0.1); // timestep
|
||||
|
||||
// set the number of iterations
|
||||
simulation.setIterations(100);
|
||||
|
||||
// set kind of output [CSV_OUTPUT_OFF (default), CSV_OUTPUT_ON,
|
||||
// CSV_OUTPUT_VERBOSE]
|
||||
simulation.setOutputCSV(CSV_OUTPUT_VERBOSE);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
|
||||
// run the simulation
|
||||
simulation.run();
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <tug/Diffusion.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
@ -61,8 +61,7 @@ int main(int argc, char *argv[]) {
|
||||
// ************************
|
||||
|
||||
// set up a simulation environment
|
||||
Simulation simulation =
|
||||
Simulation(grid, bc); // grid,boundary
|
||||
Diffusion simulation(grid, bc); // grid,boundary
|
||||
|
||||
// set the timestep of the simulation
|
||||
simulation.setTimestep(0.1); // timestep
|
||||
|
||||
@ -1,20 +1,7 @@
|
||||
add_executable(FTCS_1D_proto_example FTCS_1D_proto_example.cpp)
|
||||
add_executable(FTCS_2D_proto_example FTCS_2D_proto_example.cpp)
|
||||
add_executable(BTCS_1D_proto_example BTCS_1D_proto_example.cpp)
|
||||
add_executable(BTCS_2D_proto_example BTCS_2D_proto_example.cpp)
|
||||
add_executable(CRNI_2D_proto_example CRNI_2D_proto_example.cpp)
|
||||
add_executable(reference-FTCS_2D_closed reference-FTCS_2D_closed.cpp)
|
||||
add_executable(profiling_openmp profiling_openmp.cpp)
|
||||
|
||||
target_link_libraries(FTCS_1D_proto_example tug)
|
||||
target_link_libraries(FTCS_2D_proto_example tug)
|
||||
target_link_libraries(BTCS_1D_proto_example tug)
|
||||
target_link_libraries(BTCS_2D_proto_example tug)
|
||||
target_link_libraries(CRNI_2D_proto_example tug)
|
||||
target_link_libraries(reference-FTCS_2D_closed tug)
|
||||
target_link_libraries(profiling_openmp tug)
|
||||
|
||||
add_executable(FTCS_2D_proto_example_mdl FTCS_2D_proto_example_mdl.cpp)
|
||||
add_executable(FTCS_2D_proto_closed_mdl FTCS_2D_proto_closed_mdl.cpp)
|
||||
|
||||
target_link_libraries(BTCS_2D_proto_example tug)
|
||||
target_link_libraries(FTCS_2D_proto_closed_mdl tug)
|
||||
target_link_libraries(FTCS_2D_proto_example_mdl tug)
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int row = 20;
|
||||
int col = 20;
|
||||
Grid64 grid(row, col);
|
||||
|
||||
MatrixXd concentrations = MatrixXd::Constant(row, col, 0);
|
||||
concentrations(10, 10) = 2000;
|
||||
grid.setConcentrations(concentrations);
|
||||
|
||||
Boundary bc = Boundary(grid);
|
||||
bc.setBoundarySideClosed(BC_SIDE_LEFT);
|
||||
bc.setBoundarySideClosed(BC_SIDE_RIGHT);
|
||||
bc.setBoundarySideClosed(BC_SIDE_TOP);
|
||||
bc.setBoundarySideClosed(BC_SIDE_BOTTOM);
|
||||
|
||||
Simulation simulation =
|
||||
Simulation<double, tug::CRANK_NICOLSON_APPROACH>(grid, bc);
|
||||
simulation.setTimestep(0.1);
|
||||
simulation.setIterations(50);
|
||||
simulation.setOutputCSV(CSV_OUTPUT_XTREME);
|
||||
|
||||
simulation.run();
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
#include "tug/Boundary.hpp"
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// **************
|
||||
// **** GRID ****
|
||||
// **************
|
||||
|
||||
// create a linear grid with 20 cells
|
||||
int cells = 20;
|
||||
Grid64 grid(cells);
|
||||
|
||||
MatrixXd concentrations = MatrixXd::Constant(1, 20, 20);
|
||||
grid.setConcentrations(concentrations);
|
||||
|
||||
// ******************
|
||||
// **** BOUNDARY ****
|
||||
// ******************
|
||||
|
||||
// create a boundary with constant values
|
||||
Boundary bc = Boundary(grid);
|
||||
bc.setBoundarySideConstant(BC_SIDE_LEFT, 1);
|
||||
bc.setBoundarySideConstant(BC_SIDE_RIGHT, 1);
|
||||
|
||||
// ************************
|
||||
// **** SIMULATION ENV ****
|
||||
// ************************
|
||||
|
||||
// set up a simulation environment
|
||||
Simulation simulation =
|
||||
Simulation<double, tug::FTCS_APPROACH>(grid, bc); // grid,boundary,simulation-approach
|
||||
|
||||
// (optional) set the timestep of the simulation
|
||||
simulation.setTimestep(0.1); // timestep
|
||||
|
||||
// (optional) set the number of iterations
|
||||
simulation.setIterations(100);
|
||||
|
||||
// (optional) set kind of output [CSV_OUTPUT_OFF (default), CSV_OUTPUT_ON,
|
||||
// CSV_OUTPUT_VERBOSE]
|
||||
simulation.setOutputCSV(CSV_OUTPUT_OFF);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
|
||||
// run the simulation
|
||||
simulation.run();
|
||||
}
|
||||
@ -9,7 +9,7 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <tug/Diffusion.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
@ -69,8 +69,8 @@ int main(int argc, char *argv[]) {
|
||||
// ************************
|
||||
|
||||
// set up a simulation environment
|
||||
Simulation simulation =
|
||||
Simulation<double, FTCS_APPROACH>(grid, bc); // grid,boundary,simulation-approach
|
||||
Diffusion<double, FTCS_APPROACH> simulation(
|
||||
grid, bc); // grid,boundary,simulation-approach
|
||||
|
||||
// set the timestep of the simulation
|
||||
simulation.setTimestep(10000); // timestep
|
||||
|
||||
@ -1,92 +0,0 @@
|
||||
/**
|
||||
* @file FTCS_2D_proto_example.cpp
|
||||
* @author Hannes Signer, Philipp Ungrund
|
||||
* @brief Creates a prototypical standard TUG simulation in 2D with FTCS
|
||||
* approach and constant boundary condition
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
// #include <easy/profiler.h>
|
||||
// #define EASY_PROFILER_ENABLE ::profiler::setEnabled(true);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// EASY_PROFILER_ENABLE;
|
||||
// profiler::startListen();
|
||||
// **************
|
||||
// **** GRID ****
|
||||
// **************
|
||||
// profiler::startListen();
|
||||
// create a grid with a 20 x 20 field
|
||||
int row = 20;
|
||||
int col = 20;
|
||||
Grid64 grid(row, col);
|
||||
|
||||
// (optional) set the domain, e.g.:
|
||||
// grid.setDomain(20, 20);
|
||||
|
||||
// (optional) set the concentrations, e.g.:
|
||||
// MatrixXd concentrations = MatrixXd::Constant(20,20,1000); //
|
||||
// #row,#col,value grid.setConcentrations(concentrations);
|
||||
MatrixXd concentrations = MatrixXd::Constant(row, col, 0);
|
||||
concentrations(0, 0) = 1999;
|
||||
grid.setConcentrations(concentrations);
|
||||
|
||||
// (optional) set alphas of the grid, e.g.:
|
||||
// MatrixXd alphax = MatrixXd::Constant(20,20,1); // row,col,value
|
||||
// MatrixXd alphay = MatrixXd::Constant(20,20,1); // row,col,value
|
||||
// grid.setAlpha(alphax, alphay);
|
||||
|
||||
// ******************
|
||||
// **** BOUNDARY ****
|
||||
// ******************
|
||||
|
||||
// create a boundary with constant values
|
||||
Boundary bc = Boundary(grid);
|
||||
bc.setBoundarySideConstant(BC_SIDE_LEFT, 0);
|
||||
bc.setBoundarySideConstant(BC_SIDE_RIGHT, 0);
|
||||
bc.setBoundarySideConstant(BC_SIDE_TOP, 0);
|
||||
bc.setBoundarySideConstant(BC_SIDE_BOTTOM, 0);
|
||||
|
||||
// (optional) set boundary condition values for one side, e.g.:
|
||||
// VectorXd bc_left_values = VectorXd::Constant(20,1); // length,value
|
||||
// bc.setBoundaryConditionValue(BC_SIDE_LEFT, bc_left_values); // side,values
|
||||
// VectorXd bc_zero_values = VectorXd::Constant(20,0);
|
||||
// bc.setBoundaryConditionValue(BC_SIDE_LEFT, bc_zero_values);
|
||||
// bc.setBoundaryConditionValue(BC_SIDE_RIGHT, bc_zero_values);
|
||||
// VectorXd bc_front_values = VectorXd::Constant(20,2000);
|
||||
// bc.setBoundaryConditionValue(BC_SIDE_TOP, bc_front_values);
|
||||
// bc.setBoundaryConditionValue(BC_SIDE_BOTTOM, bc_zero_values);
|
||||
|
||||
// ************************
|
||||
// **** SIMULATION ENV ****
|
||||
// ************************
|
||||
|
||||
// set up a simulation environment
|
||||
Simulation simulation =
|
||||
Simulation<double, tug::FTCS_APPROACH>(grid, bc); // grid,boundary,simulation-approach
|
||||
|
||||
// set the timestep of the simulation
|
||||
simulation.setTimestep(0.1); // timestep
|
||||
|
||||
// set the number of iterations
|
||||
simulation.setIterations(10000);
|
||||
|
||||
// set kind of output [CSV_OUTPUT_OFF (default), CSV_OUTPUT_ON,
|
||||
// CSV_OUTPUT_VERBOSE]
|
||||
simulation.setOutputCSV(CSV_OUTPUT_VERBOSE);
|
||||
|
||||
// **** RUN SIMULATION ****
|
||||
|
||||
// run the simulation
|
||||
|
||||
// EASY_BLOCK("SIMULATION")
|
||||
simulation.run();
|
||||
// EASY_END_BLOCK;
|
||||
// profiler::dumpBlocksToFile("test_profile.prof");
|
||||
// profiler::stopListen();
|
||||
}
|
||||
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <tug/Diffusion.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
@ -60,8 +60,8 @@ int main(int argc, char *argv[]) {
|
||||
// ************************
|
||||
|
||||
// set up a simulation environment
|
||||
Simulation simulation =
|
||||
Simulation<double, tug::FTCS_APPROACH>(grid, bc); // grid,boundary,simulation-approach
|
||||
Diffusion<double, tug::FTCS_APPROACH> simulation(
|
||||
grid, bc); // grid,boundary,simulation-approach
|
||||
|
||||
// (optional) set the timestep of the simulation
|
||||
simulation.setTimestep(1000); // timestep
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <tug/Simulation.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
using namespace tug;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int n[] = {2000};
|
||||
int threads[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
int iterations[1] = {1};
|
||||
int repetition = 10;
|
||||
|
||||
for (int l = 0; l < size(threads); l++) {
|
||||
// string filename = "ftcs_openmp_" + to_string(threads[l]) + ".csv";
|
||||
ofstream myfile;
|
||||
myfile.open("speedup_1000.csv", std::ios::app);
|
||||
myfile << "Number threads: " << threads[l] << endl;
|
||||
|
||||
for (int i = 0; i < size(n); i++) {
|
||||
cout << "Grid size: " << n[i] << " x " << n[i] << endl << endl;
|
||||
// myfile << "Grid size: " << n[i] << " x " << n[i] << endl << endl;
|
||||
for (int j = 0; j < size(iterations); j++) {
|
||||
cout << "Iterations: " << iterations[j] << endl;
|
||||
// myfile << "Iterations: " << iterations[j] << endl;
|
||||
for (int k = 0; k < repetition; k++) {
|
||||
cout << "Wiederholung: " << k << endl;
|
||||
Grid64 grid(n[i], n[i]);
|
||||
grid.setDomain(1, 1);
|
||||
|
||||
MatrixXd concentrations = MatrixXd::Constant(n[i], n[i], 0);
|
||||
concentrations(n[i] / 2, n[i] / 2) = 1;
|
||||
grid.setConcentrations(concentrations);
|
||||
MatrixXd alpha = MatrixXd::Constant(n[i], n[i], 0.5);
|
||||
|
||||
Boundary bc = Boundary(grid);
|
||||
|
||||
Simulation sim = Simulation(grid, bc);
|
||||
|
||||
if (argc == 2) {
|
||||
int numThreads = atoi(argv[1]);
|
||||
sim.setNumberThreads(numThreads);
|
||||
} else {
|
||||
sim.setNumberThreads(threads[l]);
|
||||
}
|
||||
|
||||
sim.setTimestep(0.01);
|
||||
sim.setIterations(iterations[j]);
|
||||
sim.setOutputCSV(CSV_OUTPUT_OFF);
|
||||
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
sim.run();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto milliseconds =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(end -
|
||||
begin);
|
||||
myfile << milliseconds.count() << endl;
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
myfile << endl;
|
||||
}
|
||||
myfile.close();
|
||||
}
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <tug/Simulation.hpp>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
using namespace tug;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int n[] = {2000};
|
||||
int threads[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
int iterations[1] = {1};
|
||||
int repetition = 10;
|
||||
|
||||
for (int l = 0; l < size(threads); l++) {
|
||||
// string filename = "ftcs_openmp_" + to_string(threads[l]) + ".csv";
|
||||
ofstream myfile;
|
||||
myfile.open("speedup_1000.csv", std::ios::app);
|
||||
myfile << "Number threads: " << threads[l] << endl;
|
||||
|
||||
for (int i = 0; i < size(n); i++) {
|
||||
cout << "Grid size: " << n[i] << " x " << n[i] << endl << endl;
|
||||
// myfile << "Grid size: " << n[i] << " x " << n[i] << endl << endl;
|
||||
for (int j = 0; j < size(iterations); j++) {
|
||||
cout << "Iterations: " << iterations[j] << endl;
|
||||
// myfile << "Iterations: " << iterations[j] << endl;
|
||||
for (int k = 0; k < repetition; k++) {
|
||||
cout << "Wiederholung: " << k << endl;
|
||||
Grid64 grid(n[i], n[i]);
|
||||
grid.setDomain(1, 1);
|
||||
|
||||
MatrixXd concentrations = MatrixXd::Constant(n[i], n[i], 0);
|
||||
concentrations(n[i] / 2, n[i] / 2) = 1;
|
||||
grid.setConcentrations(concentrations);
|
||||
MatrixXd alpha = MatrixXd::Constant(n[i], n[i], 0.5);
|
||||
|
||||
Boundary bc = Boundary(grid);
|
||||
|
||||
Simulation sim = Simulation(grid, bc);
|
||||
|
||||
if (argc == 2) {
|
||||
int numThreads = atoi(argv[1]);
|
||||
sim.setNumberThreads(numThreads);
|
||||
} else {
|
||||
sim.setNumberThreads(threads[l]);
|
||||
}
|
||||
|
||||
sim.setTimestep(0.01);
|
||||
sim.setIterations(iterations[j]);
|
||||
sim.setOutputCSV(CSV_OUTPUT_OFF);
|
||||
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
sim.run();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto milliseconds =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(end -
|
||||
begin);
|
||||
myfile << milliseconds.count() << endl;
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
myfile << endl;
|
||||
}
|
||||
myfile.close();
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
#include "Eigen/Core"
|
||||
#include <iostream>
|
||||
#include <tug/Simulation.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace Eigen;
|
||||
using namespace tug;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int row = 50;
|
||||
int col = 50;
|
||||
int domain_row = 10;
|
||||
int domain_col = 10;
|
||||
|
||||
// Grid
|
||||
Grid64 grid(row, col);
|
||||
grid.setDomain(domain_row, domain_col);
|
||||
|
||||
MatrixXd concentrations = MatrixXd::Constant(row, col, 0);
|
||||
concentrations(5, 5) = 1;
|
||||
grid.setConcentrations(concentrations);
|
||||
|
||||
MatrixXd alpha = MatrixXd::Constant(row, col, 1);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 6; j++) {
|
||||
alpha(i, j) = 0.01;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 6; j < 11; j++) {
|
||||
alpha(i, j) = 0.001;
|
||||
}
|
||||
}
|
||||
for (int i = 5; i < 11; i++) {
|
||||
for (int j = 6; j < 11; j++) {
|
||||
alpha(i, j) = 0.1;
|
||||
}
|
||||
}
|
||||
grid.setAlpha(alpha, alpha);
|
||||
|
||||
// Boundary
|
||||
Boundary bc = Boundary(grid);
|
||||
|
||||
// Simulation
|
||||
Simulation sim = Simulation<double, tug::FTCS_APPROACH>(grid, bc);
|
||||
sim.setTimestep(0.001);
|
||||
sim.setIterations(10000);
|
||||
sim.setOutputCSV(CSV_OUTPUT_OFF);
|
||||
sim.setOutputConsole(CONSOLE_OUTPUT_OFF);
|
||||
|
||||
// RUN
|
||||
sim.run();
|
||||
}
|
||||
135
include/tug/Core/BaseSimulation.hpp
Normal file
135
include/tug/Core/BaseSimulation.hpp
Normal file
@ -0,0 +1,135 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace tug {
|
||||
|
||||
/**
|
||||
* @brief Enum holding different options for .csv output.
|
||||
*
|
||||
*/
|
||||
enum CSV_OUTPUT {
|
||||
CSV_OUTPUT_OFF, /*!< do not produce csv output */
|
||||
CSV_OUTPUT_ON, /*!< produce csv output with last concentration matrix */
|
||||
CSV_OUTPUT_VERBOSE, /*!< produce csv output with all concentration matrices */
|
||||
CSV_OUTPUT_XTREME /*!< csv output like VERBOSE but additional boundary
|
||||
conditions at beginning */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enum holding different options for console output.
|
||||
*
|
||||
*/
|
||||
enum CONSOLE_OUTPUT {
|
||||
CONSOLE_OUTPUT_OFF, /*!< do not print any output to console */
|
||||
CONSOLE_OUTPUT_ON, /*!< print before and after concentrations to console */
|
||||
CONSOLE_OUTPUT_VERBOSE /*!< print all concentration matrices to console */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enum holding different options for time measurement.
|
||||
*
|
||||
*/
|
||||
enum TIME_MEASURE {
|
||||
TIME_MEASURE_OFF, /*!< do not print any time measures */
|
||||
TIME_MEASURE_ON /*!< print time measure after last iteration */
|
||||
};
|
||||
|
||||
class BaseSimulation {
|
||||
protected:
|
||||
CSV_OUTPUT csv_output{CSV_OUTPUT_OFF};
|
||||
CONSOLE_OUTPUT console_output{CONSOLE_OUTPUT_OFF};
|
||||
TIME_MEASURE time_measure{TIME_MEASURE_OFF};
|
||||
|
||||
int iterations{1};
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Set the option to output the results to a CSV file. Off by default.
|
||||
*
|
||||
*
|
||||
* @param csv_output Valid output option. The following options can be set
|
||||
* here:
|
||||
* - CSV_OUTPUT_OFF: do not produce csv output
|
||||
* - CSV_OUTPUT_ON: produce csv output with last
|
||||
* concentration matrix
|
||||
* - CSV_OUTPUT_VERBOSE: produce csv output with all
|
||||
* concentration matrices
|
||||
* - CSV_OUTPUT_XTREME: produce csv output with all
|
||||
* concentration matrices and simulation environment
|
||||
*/
|
||||
void setOutputCSV(CSV_OUTPUT csv_output) {
|
||||
if (csv_output < CSV_OUTPUT_OFF && csv_output > CSV_OUTPUT_VERBOSE) {
|
||||
throw std::invalid_argument("Invalid CSV output option given!");
|
||||
}
|
||||
|
||||
this->csv_output = csv_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the options for outputting information to the console. Off by
|
||||
* default.
|
||||
*
|
||||
* @param console_output Valid output option. The following options can be set
|
||||
* here:
|
||||
* - CONSOLE_OUTPUT_OFF: do not print any output to
|
||||
* console
|
||||
* - CONSOLE_OUTPUT_ON: print before and after
|
||||
* concentrations to console
|
||||
* - CONSOLE_OUTPUT_VERBOSE: print all concentration
|
||||
* matrices to console
|
||||
*/
|
||||
void setOutputConsole(CONSOLE_OUTPUT console_output) {
|
||||
if (console_output < CONSOLE_OUTPUT_OFF &&
|
||||
console_output > CONSOLE_OUTPUT_VERBOSE) {
|
||||
throw std::invalid_argument("Invalid console output option given!");
|
||||
}
|
||||
|
||||
this->console_output = console_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Time Measure option. Off by default.
|
||||
*
|
||||
* @param time_measure The following options are allowed:
|
||||
* - TIME_MEASURE_OFF: Time of simulation is not printed
|
||||
* to console
|
||||
* - TIME_MEASURE_ON: Time of simulation run is printed to
|
||||
* console
|
||||
*/
|
||||
void setTimeMeasure(TIME_MEASURE time_measure) {
|
||||
if (time_measure < TIME_MEASURE_OFF && time_measure > TIME_MEASURE_ON) {
|
||||
throw std::invalid_argument("Invalid time measure option given!");
|
||||
}
|
||||
|
||||
this->time_measure = time_measure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the desired iterations to be calculated. A value greater
|
||||
* than zero must be specified here. Setting iterations is required.
|
||||
*
|
||||
* @param iterations Number of iterations to be simulated.
|
||||
*/
|
||||
void setIterations(int iterations) {
|
||||
if (iterations <= 0) {
|
||||
throw std::invalid_argument(
|
||||
"Number of iterations must be greater than zero.");
|
||||
}
|
||||
this->iterations = iterations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the currently set iterations to be calculated.
|
||||
*
|
||||
* @return int Number of iterations.
|
||||
*/
|
||||
int getIterations() const { return this->iterations; }
|
||||
|
||||
/**
|
||||
* @brief Method starts the simulation process with the previously set
|
||||
* parameters.
|
||||
*/
|
||||
virtual void run() = 0;
|
||||
};
|
||||
} // namespace tug
|
||||
@ -10,8 +10,8 @@
|
||||
#ifndef BTCS_H_
|
||||
#define BTCS_H_
|
||||
|
||||
#include "Matrix.hpp"
|
||||
#include "TugUtils.hpp"
|
||||
#include "../Matrix.hpp"
|
||||
#include "../TugUtils.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <tug/Boundary.hpp>
|
||||
@ -8,10 +8,8 @@
|
||||
#ifndef FTCS_H_
|
||||
#define FTCS_H_
|
||||
|
||||
#include "TugUtils.hpp"
|
||||
#include "../TugUtils.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <tug/Boundary.hpp>
|
||||
|
||||
#ifdef _OPENMP
|
||||
@ -1,13 +1,12 @@
|
||||
/**
|
||||
* @file Simulation.hpp
|
||||
* @brief API of Simulation class, that holds all information regarding a
|
||||
* @file Diffusion.hpp
|
||||
* @brief API of Diffusion class, that holds all information regarding a
|
||||
* specific simulation run like its timestep, number of iterations and output
|
||||
* options. Simulation object also holds a predefined Grid and Boundary object.
|
||||
* options. Diffusion object also holds a predefined Grid and Boundary object.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SIMULATION_H_
|
||||
#define SIMULATION_H_
|
||||
#pragma once
|
||||
|
||||
#include "Boundary.hpp"
|
||||
#include "Grid.hpp"
|
||||
@ -19,9 +18,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Core/BTCS.hpp"
|
||||
#include "Core/FTCS.hpp"
|
||||
#include "Core/Numeric/BTCS.hpp"
|
||||
#include "Core/Numeric/FTCS.hpp"
|
||||
#include "Core/TugUtils.hpp"
|
||||
#include "tug/Core/BaseSimulation.hpp"
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
@ -51,37 +51,6 @@ enum SOLVER {
|
||||
tridiagonal matrices */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enum holding different options for .csv output.
|
||||
*
|
||||
*/
|
||||
enum CSV_OUTPUT {
|
||||
CSV_OUTPUT_OFF, /*!< do not produce csv output */
|
||||
CSV_OUTPUT_ON, /*!< produce csv output with last concentration matrix */
|
||||
CSV_OUTPUT_VERBOSE, /*!< produce csv output with all concentration matrices */
|
||||
CSV_OUTPUT_XTREME /*!< csv output like VERBOSE but additional boundary
|
||||
conditions at beginning */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enum holding different options for console output.
|
||||
*
|
||||
*/
|
||||
enum CONSOLE_OUTPUT {
|
||||
CONSOLE_OUTPUT_OFF, /*!< do not print any output to console */
|
||||
CONSOLE_OUTPUT_ON, /*!< print before and after concentrations to console */
|
||||
CONSOLE_OUTPUT_VERBOSE /*!< print all concentration matrices to console */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enum holding different options for time measurement.
|
||||
*
|
||||
*/
|
||||
enum TIME_MEASURE {
|
||||
TIME_MEASURE_OFF, /*!< do not print any time measures */
|
||||
TIME_MEASURE_ON /*!< print time measure after last iteration */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The class forms the interface for performing the diffusion simulations
|
||||
* and contains all the methods for controlling the desired parameters, such as
|
||||
@ -94,7 +63,17 @@ enum TIME_MEASURE {
|
||||
*/
|
||||
template <class T, APPROACH approach = BTCS_APPROACH,
|
||||
SOLVER solver = THOMAS_ALGORITHM_SOLVER>
|
||||
class Simulation {
|
||||
class Diffusion : public BaseSimulation {
|
||||
private:
|
||||
T timestep{-1};
|
||||
int innerIterations{1};
|
||||
int numThreads{omp_get_num_procs()};
|
||||
|
||||
Grid<T> &grid;
|
||||
Boundary<T> &bc;
|
||||
|
||||
const std::vector<std::string> approach_names = {"FTCS", "BTCS", "CRNI"};
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Set up a simulation environment. The timestep and number of
|
||||
@ -108,68 +87,7 @@ public:
|
||||
* @param bc Valid boundary condition object
|
||||
* @param approach Approach to solving the problem. Either FTCS or BTCS.
|
||||
*/
|
||||
Simulation(Grid<T> &_grid, Boundary<T> &_bc) : grid(_grid), bc(_bc){};
|
||||
|
||||
/**
|
||||
* @brief Set the option to output the results to a CSV file. Off by default.
|
||||
*
|
||||
*
|
||||
* @param csv_output Valid output option. The following options can be set
|
||||
* here:
|
||||
* - CSV_OUTPUT_OFF: do not produce csv output
|
||||
* - CSV_OUTPUT_ON: produce csv output with last
|
||||
* concentration matrix
|
||||
* - CSV_OUTPUT_VERBOSE: produce csv output with all
|
||||
* concentration matrices
|
||||
* - CSV_OUTPUT_XTREME: produce csv output with all
|
||||
* concentration matrices and simulation environment
|
||||
*/
|
||||
void setOutputCSV(CSV_OUTPUT csv_output) {
|
||||
if (csv_output < CSV_OUTPUT_OFF && csv_output > CSV_OUTPUT_VERBOSE) {
|
||||
throw std::invalid_argument("Invalid CSV output option given!");
|
||||
}
|
||||
|
||||
this->csv_output = csv_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the options for outputting information to the console. Off by
|
||||
* default.
|
||||
*
|
||||
* @param console_output Valid output option. The following options can be set
|
||||
* here:
|
||||
* - CONSOLE_OUTPUT_OFF: do not print any output to
|
||||
* console
|
||||
* - CONSOLE_OUTPUT_ON: print before and after
|
||||
* concentrations to console
|
||||
* - CONSOLE_OUTPUT_VERBOSE: print all concentration
|
||||
* matrices to console
|
||||
*/
|
||||
void setOutputConsole(CONSOLE_OUTPUT console_output) {
|
||||
if (console_output < CONSOLE_OUTPUT_OFF &&
|
||||
console_output > CONSOLE_OUTPUT_VERBOSE) {
|
||||
throw std::invalid_argument("Invalid console output option given!");
|
||||
}
|
||||
|
||||
this->console_output = console_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Time Measure option. Off by default.
|
||||
*
|
||||
* @param time_measure The following options are allowed:
|
||||
* - TIME_MEASURE_OFF: Time of simulation is not printed
|
||||
* to console
|
||||
* - TIME_MEASURE_ON: Time of simulation run is printed to
|
||||
* console
|
||||
*/
|
||||
void setTimeMeasure(TIME_MEASURE time_measure) {
|
||||
if (time_measure < TIME_MEASURE_OFF && time_measure > TIME_MEASURE_ON) {
|
||||
throw std::invalid_argument("Invalid time measure option given!");
|
||||
}
|
||||
|
||||
this->time_measure = time_measure;
|
||||
}
|
||||
Diffusion(Grid<T> &_grid, Boundary<T> &_bc) : grid(_grid), bc(_bc){};
|
||||
|
||||
/**
|
||||
* @brief Setting the time step for each iteration step. Time step must be
|
||||
@ -244,20 +162,6 @@ public:
|
||||
*/
|
||||
T getTimestep() const { return this->timestep; }
|
||||
|
||||
/**
|
||||
* @brief Set the desired iterations to be calculated. A value greater
|
||||
* than zero must be specified here. Setting iterations is required.
|
||||
*
|
||||
* @param iterations Number of iterations to be simulated.
|
||||
*/
|
||||
void setIterations(int iterations) {
|
||||
if (iterations <= 0) {
|
||||
throw std::invalid_argument(
|
||||
"Number of iterations must be greater than zero.");
|
||||
}
|
||||
this->iterations = iterations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the number of desired openMP Threads.
|
||||
*
|
||||
@ -277,13 +181,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the currently set iterations to be calculated.
|
||||
*
|
||||
* @return int Number of iterations.
|
||||
*/
|
||||
int getIterations() const { return this->iterations; }
|
||||
|
||||
/**
|
||||
* @brief Outputs the current concentrations of the grid on the console.
|
||||
*
|
||||
@ -393,7 +290,6 @@ public:
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
|
||||
if constexpr (approach == FTCS_APPROACH) { // FTCS case
|
||||
|
||||
for (int i = 0; i < iterations * innerIterations; i++) {
|
||||
if (console_output == CONSOLE_OUTPUT_VERBOSE && i > 0) {
|
||||
printConcentrationsConsole();
|
||||
@ -485,20 +381,5 @@ public:
|
||||
<< milliseconds.count() << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T timestep{-1};
|
||||
int iterations{-1};
|
||||
int innerIterations{1};
|
||||
int numThreads{omp_get_num_procs()};
|
||||
CSV_OUTPUT csv_output{CSV_OUTPUT_OFF};
|
||||
CONSOLE_OUTPUT console_output{CONSOLE_OUTPUT_OFF};
|
||||
TIME_MEASURE time_measure{TIME_MEASURE_OFF};
|
||||
|
||||
Grid<T> &grid;
|
||||
Boundary<T> &bc;
|
||||
|
||||
const std::vector<std::string> approach_names = {"FTCS", "BTCS", "CRNI"};
|
||||
};
|
||||
} // namespace tug
|
||||
#endif // SIMULATION_H_
|
||||
@ -5,8 +5,7 @@
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <tug/Diffusion.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "files.hpp"
|
||||
@ -141,7 +140,7 @@ int main(int argc, char *argv[]) {
|
||||
// // ************************
|
||||
|
||||
// set up a simulation environment
|
||||
Simulation simulation = Simulation(grid, bc); // grid,boundary
|
||||
Diffusion simulation(grid, bc); // grid,boundary
|
||||
|
||||
// set the timestep of the simulation
|
||||
simulation.setTimestep(360); // timestep
|
||||
|
||||
@ -7,11 +7,11 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "files.hpp"
|
||||
#include <files.hpp>
|
||||
#include <tug/Diffusion.hpp>
|
||||
|
||||
using namespace tug;
|
||||
|
||||
@ -142,8 +142,7 @@ template <class T, tug::APPROACH app> int doWork(int ngrid) {
|
||||
bc.setBoundarySideClosed(BC_SIDE_BOTTOM);
|
||||
|
||||
// set up a simulation environment
|
||||
Simulation Sim =
|
||||
Simulation<T, app>(grid, bc); // grid_64,boundary,simulation-approach
|
||||
Diffusion Sim(grid, bc); // grid_64,boundary,simulation-approach
|
||||
|
||||
// Sim64.setSolver(THOMAS_ALGORITHM_SOLVER);
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
find_package(doctest REQUIRED)
|
||||
|
||||
add_executable(testTug setup.cpp testSimulation.cpp testGrid.cpp testFTCS.cpp testBoundary.cpp)
|
||||
add_executable(testTug setup.cpp testDiffusion.cpp testGrid.cpp testFTCS.cpp testBoundary.cpp)
|
||||
target_link_libraries(testTug doctest::doctest tug)
|
||||
|
||||
# get relative path of the CSV file
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
#include "TestUtils.hpp"
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <tug/Diffusion.hpp>
|
||||
|
||||
#include <Eigen/src/Core/Matrix.h>
|
||||
#include <doctest/doctest.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
// include the configured header file
|
||||
@ -62,7 +61,7 @@ TEST_CASE("equality to reference matrix with FTCS") {
|
||||
|
||||
// Simulation
|
||||
|
||||
Simulation sim = Simulation<double, tug::FTCS_APPROACH>(grid, bc);
|
||||
Diffusion<double, tug::FTCS_APPROACH> sim(grid, bc);
|
||||
// sim.setOutputConsole(CONSOLE_OUTPUT_ON);
|
||||
sim.setTimestep(timestep);
|
||||
sim.setIterations(iterations);
|
||||
@ -82,7 +81,7 @@ TEST_CASE("equality to reference matrix with BTCS") {
|
||||
Boundary bc = Boundary(grid);
|
||||
|
||||
// Simulation
|
||||
Simulation sim = Simulation<double, tug::FTCS_APPROACH>(grid, bc);
|
||||
Diffusion<double, tug::FTCS_APPROACH> sim(grid, bc);
|
||||
// sim.setOutputConsole(CONSOLE_OUTPUT_ON);
|
||||
sim.setTimestep(timestep);
|
||||
sim.setIterations(iterations);
|
||||
@ -97,16 +96,16 @@ TEST_CASE("Initialize environment") {
|
||||
Grid64 grid(rc, rc);
|
||||
Boundary boundary(grid);
|
||||
|
||||
CHECK_NOTHROW(Simulation sim(grid, boundary));
|
||||
CHECK_NOTHROW(Diffusion sim(grid, boundary));
|
||||
}
|
||||
|
||||
TEST_CASE("Simulation environment") {
|
||||
int rc = 12;
|
||||
Grid64 grid(rc, rc);
|
||||
Boundary boundary(grid);
|
||||
Simulation<double, tug::FTCS_APPROACH> sim(grid, boundary);
|
||||
Diffusion<double, tug::FTCS_APPROACH> sim(grid, boundary);
|
||||
|
||||
SUBCASE("default paremeters") { CHECK_EQ(sim.getIterations(), -1); }
|
||||
SUBCASE("default paremeters") { CHECK_EQ(sim.getIterations(), 1); }
|
||||
|
||||
SUBCASE("set iterations") {
|
||||
CHECK_NOTHROW(sim.setIterations(2000));
|
||||
@ -141,7 +140,7 @@ TEST_CASE("Closed Boundaries - no change expected") {
|
||||
bc.setBoundarySideConstant(tug::BC_SIDE_TOP, 1.0);
|
||||
bc.setBoundarySideConstant(tug::BC_SIDE_BOTTOM, 1.0);
|
||||
|
||||
tug::Simulation<double> sim(grid, bc);
|
||||
tug::Diffusion<double> sim(grid, bc);
|
||||
sim.setTimestep(1);
|
||||
sim.setIterations(1);
|
||||
|
||||
@ -169,7 +168,7 @@ TEST_CASE("Constant inner cell - 'absorbing' concentration") {
|
||||
// inner
|
||||
bc.setInnerBoundary(2, 2, 0);
|
||||
|
||||
tug::Simulation<double> sim(grid, bc);
|
||||
tug::Diffusion<double> sim(grid, bc);
|
||||
sim.setTimestep(1);
|
||||
sim.setIterations(1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user