Commit f7e75398 authored by jannick.wolters's avatar jannick.wolters
Browse files

fixed neighbor to normal sorting; fixed index error; all fluxes of cell a to b...

fixed neighbor to normal sorting; fixed index error; all fluxes of cell a to b are equal to b to a everywhere
parent 5bde8a95
cmake_minimum_required( VERSION 3.12.4 )
project( RTSN LANGUAGES C CXX VERSION 0.0.1 )
set( CMAKE_CXX_STANDARD 20 )
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -Wno-dev -DNDEBUG" )
......
% This is a comment
%%%%%%%%%%%%%%%%%%%%%%
% Example config file
%
% ---- File specifications ----
%
% Output directory
OUTPUT_DIR = ../result
% Output file
OUTPUT_FILE = example
% Log directory
LOG_DIR = ../result/logs
% Mesh File
MESH_FILE = checkerboard.su2
%
% ---- Solver specifications ----
%
% CFL number
CFL_NUMBER = 0.9
% Final time for simulation
TIME_FINAL = 0.3
% ---- Boundary Conditions ----
% Example: BC_DIRICLET = (dummyMarker1, dummyMarker2)
% Dirichlet Boundary
BC_DIRICHLET = ( void )
%
%% Quadrature Specifications
% Quadrature Type
QUAD_TYPE = MONTE_CARLO
% Quadrature Order
QUAD_ORDER = 42
......@@ -42,7 +42,6 @@ class Mesh
void ComputeCellAreas();
void ComputeCellMidpoints();
void ComputeConnectivity();
void ComputeNormals();
void ComputePartitioning();
Vector ComputeOutwardFacingNormal( const Vector& nodeA, const Vector& nodeB, const Vector& cellCenter );
......
......@@ -9,9 +9,10 @@
#ifndef CONFIG_H
#define CONFIG_H
#include <map>
#include "OptionStructure.h"
#include "GlobalConstants.h"
#include "OptionStructure.h"
#include <filesystem>
#include <map>
/*!
* \class CConfig
......@@ -19,168 +20,167 @@
* stores all the information.
*/
class CConfig {
private:
std::string _fileName; /*!< \brief Name of the current file without extension */
bool _base_config;
int _comm_rank, _comm_size; /*!< \brief MPI rank and size.*/
// --- Options ---
// File Structure
std::string _outputDir; /*!< \brief Directory for output files*/
std::string _outputFile; /*!< \brief Name of output file*/
std::string _logDir; /*!< \brief Directory of log file*/
std::string _meshFile; /*!< \brief Name of mesh file*/
// Quadrature
QUAD_NAME _quadName; /*!< \brief Quadrature Name*/
unsigned short _quadOrder; /*!< \brief Quadrature Order*/
// Solver
double _CFL; /*!< \brief CFL Number for Solver*/
double _tEnd; /*!< \brief Final Time for Simulation */
// Boundary Conditions
/*!< \brief List of all Pairs (marker, BOUNDARY_TYPE), e.g. (farfield,DIRICHLET).
Each Boundary Conditions must have an entry in enum BOUNDARY_TYPE*/
std::vector<std::pair<std::string, BOUNDARY_TYPE>> _boundaries;
unsigned short _nMarkerDirichlet; /*!< \brief Number of Dirichlet BC markers. Enum entry: DIRICHLET */
std::string *_MarkerDirichlet; /*!< \brief Dirichlet BC markers. */
// --- Parsing Functionality and Initializing of Options ---
/*!
* \brief Set default values for all options not yet set.
*/
void SetDefault(void);
/*!
* \brief Set the config options.
* ==> Set new config options here.
*/
void SetConfigOptions(void);
/*!
* \brief Set the config file parsing.
*/
void SetConfigParsing(char case_filename[MAX_STRING_SIZE]);
/*!
* \brief Config file screen output.
*/
void SetOutput(void);
/*!
* \brief Initializes pointers to null
*/
void SetPointersNull(void);
/*!
* \brief Config file postprocessing.
*/
void SetPostprocessing(void);
/*!
* \brief breaks an input line from the config file into a set of tokens
* \param[in] str - the input line string
* \param[out] option_name - the name of the option found at the beginning of the line
* \param[out] option_value - the tokens found after the "=" sign on the line
* \return false if the line is empty or a commment, true otherwise
*/
bool TokenizeString(std::string & str, std::string & option_name,
std::vector<std::string> & option_value);
/*--- all_options is a map containing all of the options. This is used during config file parsing
to track the options which have not been set (so the default values can be used). Without this map
there would be no list of all the config file options. ---*/
std::map<std::string, bool> all_options;
/*--- brief param is a map from the option name (config file string) to its decoder (the specific child
class of COptionBase that turns the string into a value) ---*/
std::map<std::string, COptionBase*> option_map;
// ---- Option Types ----
// All of the addXxxOptions take in the name of the option, and a refernce to the field of that option
// in the option structure. Depending on the specific type, it may take in a default value, and may
// take in extra options. The addXxxOptions mostly follow the same pattern, so please see addDoubleOption
// for detailed comments.
//
// List options are those that can be an unknown number of elements, and also take in a reference to
// an integer. This integer will be populated with the number of elements of that type unmarshaled.
//
// Array options are those with a fixed number of elements.
//
// List and Array options should also be able to be specified with the string "NONE" indicating that there
// are no elements. This allows the option to be present in a config file but left blank.
/*!< \brief addDoubleOption creates a config file parser for an option with the given name whose
value can be represented by a su2double.*/
// Simple Options
void addBoolOption(const std::string name, bool & option_field, bool default_value);
void addDoubleOption(const std::string name, double & option_field, double default_value);
void addIntegerOption(const std::string name, int & option_field, int default_value);
void addLongOption(const std::string name, long & option_field, long default_value);
void addStringOption(const std::string name, std::string & option_field, std::string default_value);
void addUnsignedLongOption(const std::string name, unsigned long & option_field, unsigned long default_value);
void addUnsignedShortOption(const std::string name, unsigned short & option_field, unsigned short default_value);
// enum types work differently than all of the others because there are a small number of valid
// string entries for the type. One must also provide a list of all the valid strings of that type.
template <class Tenum>
void addEnumOption(const std::string name, Tenum & option_field, const std::map<std::string, Tenum> & enum_map, Tenum default_value);
//List Options
void addStringListOption(const std::string name, unsigned short & num_marker, std::string* & option_field);
public:
/*!
* \brief Constructor of the class which reads the input file.
*/
CConfig(char case_filename[MAX_STRING_SIZE]);
/*!
* \brief Destructor of the class.
*/
~CConfig(void);
// ---- Getters for option values ----
/*!
* \brief Get Value of this option.
* Please keep alphabetical order within each subcategory
*/
// File structure
std::string inline GetMeshFile() const { return _meshFile; }
std::string inline GetOutputDir() const { return _outputDir; }
std::string inline GetOutputFile() const { return _outputFile; }
// Quadrature Structure
QUAD_NAME inline GetQuadName() const {return _quadName;}
unsigned short inline GetQuadOrder() const {return _quadOrder;}
// Solver Structure
double inline GetCFL() const { return _CFL; }
double inline GetTEnd() const { return _tEnd; }
// Boundary Conditions
BOUNDARY_TYPE GetBoundaryType( std::string nameMarker ) const; /*! \brief Get Boundary Type of given marker */
//Output Structure
class CConfig
{
private:
std::string _fileName; /*!< \brief Name of the current file without extension */
bool _base_config;
int _comm_rank, _comm_size; /*!< \brief MPI rank and size.*/
// --- Options ---
// File Structure
std::string _inputDir; /*!< \brief Directory for input files*/
std::string _outputDir; /*!< \brief Directory for output files*/
std::string _outputFile; /*!< \brief Name of output file*/
std::string _logDir; /*!< \brief Directory of log file*/
std::string _meshFile; /*!< \brief Name of mesh file*/
// Quadrature
QUAD_NAME _quadName; /*!< \brief Quadrature Name*/
unsigned short _quadOrder; /*!< \brief Quadrature Order*/
// Solver
double _CFL; /*!< \brief CFL Number for Solver*/
double _tEnd; /*!< \brief Final Time for Simulation */
// Boundary Conditions
/*!< \brief List of all Pairs (marker, BOUNDARY_TYPE), e.g. (farfield,DIRICHLET).
Each Boundary Conditions must have an entry in enum BOUNDARY_TYPE*/
std::vector<std::pair<std::string, BOUNDARY_TYPE>> _boundaries;
unsigned short _nMarkerDirichlet; /*!< \brief Number of Dirichlet BC markers. Enum entry: DIRICHLET */
std::string* _MarkerDirichlet; /*!< \brief Dirichlet BC markers. */
// --- Parsing Functionality and Initializing of Options ---
/*!
* \brief Set default values for all options not yet set.
*/
void SetDefault( void );
/*!
* \brief Set the config options.
* ==> Set new config options here.
*/
void SetConfigOptions( void );
/*!
* \brief Set the config file parsing.
*/
void SetConfigParsing( char case_filename[MAX_STRING_SIZE] );
/*!
* \brief Config file screen output.
*/
void SetOutput( void );
/*!
* \brief Initializes pointers to null
*/
void SetPointersNull( void );
/*!
* \brief Config file postprocessing.
*/
void SetPostprocessing( void );
/*!
* \brief breaks an input line from the config file into a set of tokens
* \param[in] str - the input line string
* \param[out] option_name - the name of the option found at the beginning of the line
* \param[out] option_value - the tokens found after the "=" sign on the line
* \return false if the line is empty or a commment, true otherwise
*/
bool TokenizeString( std::string& str, std::string& option_name, std::vector<std::string>& option_value );
/*--- all_options is a map containing all of the options. This is used during config file parsing
to track the options which have not been set (so the default values can be used). Without this map
there would be no list of all the config file options. ---*/
std::map<std::string, bool> all_options;
/*--- brief param is a map from the option name (config file string) to its decoder (the specific child
class of COptionBase that turns the string into a value) ---*/
std::map<std::string, COptionBase*> option_map;
// ---- Option Types ----
// All of the addXxxOptions take in the name of the option, and a refernce to the field of that option
// in the option structure. Depending on the specific type, it may take in a default value, and may
// take in extra options. The addXxxOptions mostly follow the same pattern, so please see addDoubleOption
// for detailed comments.
//
// List options are those that can be an unknown number of elements, and also take in a reference to
// an integer. This integer will be populated with the number of elements of that type unmarshaled.
//
// Array options are those with a fixed number of elements.
//
// List and Array options should also be able to be specified with the string "NONE" indicating that there
// are no elements. This allows the option to be present in a config file but left blank.
/*!< \brief addDoubleOption creates a config file parser for an option with the given name whose
value can be represented by a su2double.*/
// Simple Options
void addBoolOption( const std::string name, bool& option_field, bool default_value );
void addDoubleOption( const std::string name, double& option_field, double default_value );
void addIntegerOption( const std::string name, int& option_field, int default_value );
void addLongOption( const std::string name, long& option_field, long default_value );
void addStringOption( const std::string name, std::string& option_field, std::string default_value );
void addUnsignedLongOption( const std::string name, unsigned long& option_field, unsigned long default_value );
void addUnsignedShortOption( const std::string name, unsigned short& option_field, unsigned short default_value );
// enum types work differently than all of the others because there are a small number of valid
// string entries for the type. One must also provide a list of all the valid strings of that type.
template <class Tenum>
void addEnumOption( const std::string name, Tenum& option_field, const std::map<std::string, Tenum>& enum_map, Tenum default_value );
// List Options
void addStringListOption( const std::string name, unsigned short& num_marker, std::string*& option_field );
public:
/*!
* \brief Constructor of the class which reads the input file.
*/
CConfig( char case_filename[MAX_STRING_SIZE] );
/*!
* \brief Destructor of the class.
*/
~CConfig( void );
// ---- Getters for option values ----
/*!
* \brief Get Value of this option.
* Please keep alphabetical order within each subcategory
*/
// File structure
std::string inline GetMeshFile() const { return _inputDir + _meshFile; }
std::string inline GetOutputDir() const {
if( _outputDir.at( _outputDir.size() - 1 ) != '/' )
return _outputDir + "/";
else
return _outputDir;
}
std::string inline GetOutputFile() const { return _outputFile; }
// Quadrature Structure
QUAD_NAME inline GetQuadName() const { return _quadName; }
unsigned short inline GetQuadOrder() const { return _quadOrder; }
// Solver Structure
double inline GetCFL() const { return _CFL; }
double inline GetTEnd() const { return _tEnd; }
// Boundary Conditions
BOUNDARY_TYPE GetBoundaryType( std::string nameMarker ) const; /*! \brief Get Boundary Type of given marker */
// Output Structure
};
#endif // CONFIG_H
#endif // CONFIG_H
......@@ -9,43 +9,32 @@
#ifndef GLOBAL_CONSTANTS_H
#define GLOBAL_CONSTANTS_H
#include <map>
#include <cmath>
#include <map>
#include <string>
// --- Definition for global constants goes here ---
const double PI_NUMBER = 4.0 * std::atan(1.0); /*!< \brief Pi number. */
const unsigned int MAX_STRING_SIZE = 200; /*!< \brief Maximum size for strings. */
const double PI_NUMBER = 4.0 * std::atan( 1.0 ); /*!< \brief Pi number. */
const unsigned int MAX_STRING_SIZE = 200; /*!< \brief Maximum size for strings. */
// --- Definition of enums goes here ---
enum BOUNDARY_TYPE{
DIRICHLET,
INVALID
};
enum BOUNDARY_TYPE { DIRICHLET, INVALID };
// --- Definition of enums for EnumOptions goes here ---
/*! \brief Enum for all currently available quadratures in rtsn.
* Option enums are written in capital letters with underscores as spaces (e.g option "time integration" has option enum "TIME_INTEGRATION")
*/
enum QUAD_NAME{
QUAD_MonteCarlo,
QUAD_GaussLegendreTensorized,
QUAD_LevelSymmetric,
QUAD_Lebedev,
QUAD_LDFESA
};
enum QUAD_NAME { QUAD_MonteCarlo, QUAD_GaussLegendreTensorized, QUAD_LevelSymmetric, QUAD_Lebedev, QUAD_LDFESA };
/*! \brief Conversion Map String to enum
*/
inline std::map <std::string,QUAD_NAME> Quadrature_Map {
{ "MONTE_CARLO", QUAD_MonteCarlo },
{ "GAUSS_LEGENDRE_TENSORIZED", QUAD_GaussLegendreTensorized },
{ "LEVEL_SYMMETRIC", QUAD_LevelSymmetric },
{ "LEBEDEV", QUAD_Lebedev },
{ "LDFESA",QUAD_LDFESA }
};
#endif // GLOBAL_CONSTANTS_H
inline std::map<std::string, QUAD_NAME> Quadrature_Map{ { "MONTE_CARLO", QUAD_MonteCarlo },
{ "GAUSS_LEGENDRE_TENSORIZED", QUAD_GaussLegendreTensorized },
{ "LEVEL_SYMMETRIC", QUAD_LevelSymmetric },
{ "LEBEDEV", QUAD_Lebedev },
{ "LDFESA", QUAD_LDFESA } };
#endif // GLOBAL_CONSTANTS_H
......@@ -11,8 +11,8 @@
* \brief utility function for converting strings to uppercase
* \param[in,out] str - string we want to convert
*/
inline void StringToUpperCase(std::string & str) {
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
inline void StringToUpperCase( std::string& str ) {
for( auto& c : str ) c = std::toupper( c );
}
#endif // TEXTPROCESSINGTOOLBOX_H
#endif // TEXTPROCESSINGTOOLBOX_H
......@@ -12,7 +12,7 @@ def add_block(x0,y0,length,char_length,geom):
])
return geom.add_polygon(coords, char_length)
char_length = 0.1
char_length = 0.05
geom = pg.opencascade.Geometry()
domain = add_block(0, 0, 1.2, char_length, geom)
xpos = ypos = [0.1, 0.3, 0.5, 0.7, 0.9]
......
This diff is collapsed.
......@@ -18,7 +18,7 @@ void ExportVTK( const std::string fileName,
auto writer = vtkUnstructuredGridWriterSP::New();
std::string fileNameWithExt = fileName;
if( !fileNameWithExt.ends_with( ".vtk" ) ) {
if( fileNameWithExt.substr( fileNameWithExt.find_last_of( "." ) + 1 ) != ".vtk" ) {
fileNameWithExt.append( ".vtk" );
}
writer->SetFileName( ( settings->GetOutputDir() + fileNameWithExt ).c_str() );
......@@ -237,8 +237,8 @@ Mesh* LoadSU2MeshFromFile( const CConfig* settings ) {
markerTag.erase( end_pos, markerTag.end() );
btype = settings->GetBoundaryType( markerTag );
if( btype == BOUNDARY_TYPE::INVALID ) {
std::string errorMsg = std::string("Invalid Boundary at marker \"" + markerTag + "\".");
CRTSNError::Error(errorMsg,CURRENT_FUNCTION);
std::string errorMsg = std::string( "Invalid Boundary at marker \"" + markerTag + "\"." );
CRTSNError::Error( errorMsg, CURRENT_FUNCTION );
}
}
else if( line.find( "MARKER_ELEMS", 0 ) != std::string::npos ) {
......@@ -411,7 +411,7 @@ Settings* ReadInputFile( std::string inputFile ) {
auto cwd = std::filesystem::current_path();
std::string tmp = std::filesystem::path( inputFile ).parent_path().string();
if( !tmp.ends_with( "/" ) ) tmp.append( "/" );
if( tmp.substr( tmp.size() - 1 ) != "/" ) tmp.append( "/" );
settings->_inputDir = tmp;
// section IO
......@@ -428,7 +428,7 @@ Settings* ReadInputFile( std::string inputFile ) {
auto outputDir = io->get_as<std::string>( "outputDir" );
if( outputDir ) {
std::string tmp = *outputDir;
if( !tmp.ends_with( "/" ) ) tmp.append( "/" );
if( tmp.substr( tmp.size() - 1 ) != "/" ) tmp.append( "/" );
settings->_outputDir = std::filesystem::path( tmp );
}
else {
......@@ -448,7 +448,7 @@ Settings* ReadInputFile( std::string inputFile ) {
auto logDir = io->get_as<std::string>( "logDir" );
if( logDir ) {
std::string tmp = *logDir;
if( !tmp.ends_with( "/" ) ) tmp.append( "/" );
if( tmp.substr( tmp.size() - 1 ) != "/" ) tmp.append( "/" );
settings->_logDir = std::filesystem::path( tmp );
}
else {
......
......@@ -9,7 +9,7 @@ int main( int argc, char** argv ) {
MPI_Init( &argc, &argv );
/*std::string inputFile = ParseArguments( argc, argv );
/*
Settings* settings = ReadInputFile( inputFile );
InitLogger( settings->GetLogDir(), spdlog::level::info, spdlog::level::info );
PrintLogHeader( settings->GetInputFile() );
......@@ -20,25 +20,22 @@ int main( int argc, char** argv ) {
solver->Save();
*/
std::string filename = "default.cfg";
char config_file_name[MAX_STRING_SIZE];
filename = ParseArguments( argc, argv );
std::string filename = ParseArguments( argc, argv );
/*--- Load in the number of zones and spatial dimensions in the mesh file (If no config
file is specified, default.cfg is used) ---*/
strcpy(config_file_name, filename.c_str());
//Load Settings from File
CConfig* config = new CConfig(config_file_name);
strcpy( config_file_name, filename.c_str() );
// Load Settings from File
CConfig* config = new CConfig( config_file_name );
// build solver
Solver* solver = Solver::Create( config );
solver->Solve();
solver->Save();
// TODO: call solver
MPI_Finalize();
return EXIT_SUCCESS;
......
......@@ -8,7 +8,6 @@ Mesh::Mesh( std::vector<Vector> nodes,
_boundaries( boundaries ) {
ComputeCellAreas();
ComputeCellMidpoints();
ComputeNormals();
ComputeConnectivity();
ComputePartitioning();
}
......@@ -19,10 +18,17 @@ void Mesh::ComputeConnectivity() {
int comm_size, comm_rank;
MPI_Comm_size( MPI_COMM_WORLD, &comm_size );
MPI_Comm_rank( MPI_COMM_WORLD, &comm_rank );
unsigned chunkSize = std::ceil( static_cast<float>( _numCells ) / static_cast<float>( comm_size ) );
unsigned mpiCellStart = comm_rank * chunkSize;
unsigned mpiCellEnd = std::min( ( comm_rank + 1 ) * chunkSize, _numCells );
std::vector<int> neighborsFlatPart( _numNodesPerCell * chunkSize, -1 );
// unsigned chunkSize = std::ceil( static_cast<float>( _numCells ) / static_cast<float>( comm_size ) );
// unsigned mpiCellStart = comm_rank * chunkSize;
// unsigned mpiCellEnd = std::min( ( comm_rank + 1 ) * chunkSize, _numCells );
// std::vector<int> neighborsFlatPart( _numNodesPerCell * chunkSize, -1 );
// std::vector<Vector> normalsFlatPart( _numNodesPerCell * chunkSize, Vect