Skip to content
Snippets Groups Projects
Commit f8064f89 authored by Soeren Peters's avatar Soeren Peters
Browse files

Merge pull request 'Add clang format and apply it to basics and cpu.' (#47)...

Merge pull request 'Add clang format and apply it to basics and cpu.' (#47) from peters/VirtualFluids_dev:feature/clang_format_dev into develop

Reviewed-on: https://git.irmb.bau.tu-bs.de/VirtualFluids/VirtualFluids_dev/pulls/47
parents 1c89a765 4a4691b1
No related branches found
No related tags found
No related merge requests found
Showing
with 1813 additions and 2306 deletions
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Linux
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
...
...@@ -6,6 +6,8 @@ file(GLOB metis_sources *.c) ...@@ -6,6 +6,8 @@ file(GLOB metis_sources *.c)
add_library(metis ${METIS_LIBRARY_TYPE} ${GKlib_sources} ${metis_sources}) add_library(metis ${METIS_LIBRARY_TYPE} ${GKlib_sources} ${metis_sources})
if(UNIX) if(UNIX)
target_link_libraries(metis m) target_link_libraries(metis m)
target_compile_options(metis PRIVATE "-Wno-format")
endif() endif()
if(MSVC) if(MSVC)
......
...@@ -5,58 +5,58 @@ ...@@ -5,58 +5,58 @@
#include "DataTypes.h" #include "DataTypes.h"
typedef std::array< uint, 2 > uint_2 ; typedef std::array<uint, 2> uint_2;
typedef std::array< uint, 3 > uint_3 ; typedef std::array<uint, 3> uint_3;
typedef std::array< uint, 4 > uint_4 ; typedef std::array<uint, 4> uint_4;
typedef std::array< uint, 5 > uint_5 ; typedef std::array<uint, 5> uint_5;
typedef std::array< uint, 6 > uint_6 ; typedef std::array<uint, 6> uint_6;
typedef std::array< uint, 7 > uint_7 ; typedef std::array<uint, 7> uint_7;
typedef std::array< uint, 8 > uint_8 ; typedef std::array<uint, 8> uint_8;
typedef std::array< uint, 9 > uint_9 ; typedef std::array<uint, 9> uint_9;
typedef std::array< uint, 10 > uint_10; typedef std::array<uint, 10> uint_10;
typedef std::array< uint, 11 > uint_11; typedef std::array<uint, 11> uint_11;
typedef std::array< uint, 12 > uint_12; typedef std::array<uint, 12> uint_12;
typedef std::array< uint, 13 > uint_13; typedef std::array<uint, 13> uint_13;
typedef std::array< uint, 14 > uint_14; typedef std::array<uint, 14> uint_14;
typedef std::array< uint, 15 > uint_15; typedef std::array<uint, 15> uint_15;
typedef std::array< uint, 16 > uint_16; typedef std::array<uint, 16> uint_16;
typedef std::array< uint, 17 > uint_17; typedef std::array<uint, 17> uint_17;
typedef std::array< uint, 18 > uint_18; typedef std::array<uint, 18> uint_18;
typedef std::array< uint, 19 > uint_19; typedef std::array<uint, 19> uint_19;
typedef std::array< uint, 20 > uint_20; typedef std::array<uint, 20> uint_20;
typedef std::array< uint, 21 > uint_21; typedef std::array<uint, 21> uint_21;
typedef std::array< uint, 22 > uint_22; typedef std::array<uint, 22> uint_22;
typedef std::array< uint, 23 > uint_23; typedef std::array<uint, 23> uint_23;
typedef std::array< uint, 24 > uint_24; typedef std::array<uint, 24> uint_24;
typedef std::array< uint, 25 > uint_25; typedef std::array<uint, 25> uint_25;
typedef std::array< uint, 26 > uint_26; typedef std::array<uint, 26> uint_26;
typedef std::array< uint, 27 > uint_27; typedef std::array<uint, 27> uint_27;
typedef std::array< bool, 2 > bool_2 ; typedef std::array<bool, 2> bool_2;
typedef std::array< bool, 3 > bool_3 ; typedef std::array<bool, 3> bool_3;
typedef std::array< bool, 4 > bool_4 ; typedef std::array<bool, 4> bool_4;
typedef std::array< bool, 5 > bool_5 ; typedef std::array<bool, 5> bool_5;
typedef std::array< bool, 6 > bool_6 ; typedef std::array<bool, 6> bool_6;
typedef std::array< bool, 7 > bool_7 ; typedef std::array<bool, 7> bool_7;
typedef std::array< bool, 8 > bool_8 ; typedef std::array<bool, 8> bool_8;
typedef std::array< bool, 9 > bool_9 ; typedef std::array<bool, 9> bool_9;
typedef std::array< bool, 10 > bool_10; typedef std::array<bool, 10> bool_10;
typedef std::array< bool, 11 > bool_11; typedef std::array<bool, 11> bool_11;
typedef std::array< bool, 12 > bool_12; typedef std::array<bool, 12> bool_12;
typedef std::array< bool, 13 > bool_13; typedef std::array<bool, 13> bool_13;
typedef std::array< bool, 14 > bool_14; typedef std::array<bool, 14> bool_14;
typedef std::array< bool, 15 > bool_15; typedef std::array<bool, 15> bool_15;
typedef std::array< bool, 16 > bool_16; typedef std::array<bool, 16> bool_16;
typedef std::array< bool, 17 > bool_17; typedef std::array<bool, 17> bool_17;
typedef std::array< bool, 18 > bool_18; typedef std::array<bool, 18> bool_18;
typedef std::array< bool, 19 > bool_19; typedef std::array<bool, 19> bool_19;
typedef std::array< bool, 20 > bool_20; typedef std::array<bool, 20> bool_20;
typedef std::array< bool, 21 > bool_21; typedef std::array<bool, 21> bool_21;
typedef std::array< bool, 22 > bool_22; typedef std::array<bool, 22> bool_22;
typedef std::array< bool, 23 > bool_23; typedef std::array<bool, 23> bool_23;
typedef std::array< bool, 24 > bool_24; typedef std::array<bool, 24> bool_24;
typedef std::array< bool, 25 > bool_25; typedef std::array<bool, 25> bool_25;
typedef std::array< bool, 26 > bool_26; typedef std::array<bool, 26> bool_26;
typedef std::array< bool, 27 > bool_27; typedef std::array<bool, 27> bool_27;
#endif #endif
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <string> #include <string>
#ifdef VF_DOUBLE_ACCURACY #ifdef VF_DOUBLE_ACCURACY
typedef double real; typedef double real;
#else #else
...@@ -11,6 +10,6 @@ using real = float; ...@@ -11,6 +10,6 @@ using real = float;
#endif #endif
using uint = unsigned int; using uint = unsigned int;
#define INVALID_INDEX 4294967295 //max uint #define INVALID_INDEX 4294967295 // max uint
#endif #endif
...@@ -11,177 +11,175 @@ class ConfigData ...@@ -11,177 +11,175 @@ class ConfigData
public: public:
virtual ~ConfigData() = default; virtual ~ConfigData() = default;
virtual real getViscosity() = 0; virtual real getViscosity() = 0;
virtual uint getNumberOfDevices() = 0; virtual uint getNumberOfDevices() = 0;
virtual std::vector<uint> getDevices() = 0; virtual std::vector<uint> getDevices() = 0;
virtual std::string getOutputPath() = 0; virtual std::string getOutputPath() = 0;
virtual std::string getPrefix() = 0; virtual std::string getPrefix() = 0;
virtual std::string getGridPath() = 0; virtual std::string getGridPath() = 0;
virtual bool getPrintOutputFiles() = 0; virtual bool getPrintOutputFiles() = 0;
virtual bool getGeometryValues() = 0; virtual bool getGeometryValues() = 0;
virtual bool getCalc2ndOrderMoments() = 0; virtual bool getCalc2ndOrderMoments() = 0;
virtual bool getCalc3rdOrderMoments() = 0; virtual bool getCalc3rdOrderMoments() = 0;
virtual bool getCalcHighOrderMoments() = 0; virtual bool getCalcHighOrderMoments() = 0;
virtual bool getReadGeo() = 0; virtual bool getReadGeo() = 0;
virtual bool getCalcMedian() = 0; virtual bool getCalcMedian() = 0;
virtual bool getCalcDragLift() = 0; virtual bool getCalcDragLift() = 0;
virtual bool getCalcCp() = 0; virtual bool getCalcCp() = 0;
virtual bool getWriteVeloASCIIfiles() = 0; virtual bool getWriteVeloASCIIfiles() = 0;
virtual bool getCalcPlaneConc() = 0; virtual bool getCalcPlaneConc() = 0;
virtual bool getConcFile() = 0; virtual bool getConcFile() = 0;
virtual bool getStreetVelocityFile() = 0; virtual bool getStreetVelocityFile() = 0;
virtual bool getUseMeasurePoints() = 0; virtual bool getUseMeasurePoints() = 0;
virtual bool getUseWale() = 0; virtual bool getUseWale() = 0;
virtual bool getUseInitNeq() = 0; virtual bool getUseInitNeq() = 0;
virtual bool getSimulatePorousMedia() = 0; virtual bool getSimulatePorousMedia() = 0;
virtual uint getD3Qxx() = 0; virtual uint getD3Qxx() = 0;
virtual uint getTEnd() = 0; virtual uint getTEnd() = 0;
virtual uint getTOut() = 0; virtual uint getTOut() = 0;
virtual uint getTStartOut() = 0; virtual uint getTStartOut() = 0;
virtual uint getTimeCalcMedStart() = 0; virtual uint getTimeCalcMedStart() = 0;
virtual uint getTimeCalcMedEnd() = 0; virtual uint getTimeCalcMedEnd() = 0;
virtual uint getPressInID() = 0; virtual uint getPressInID() = 0;
virtual uint getPressOutID() = 0; virtual uint getPressOutID() = 0;
virtual uint getPressInZ() = 0; virtual uint getPressInZ() = 0;
virtual uint getPressOutZ() = 0; virtual uint getPressOutZ() = 0;
virtual bool getDiffOn() = 0; virtual bool getDiffOn() = 0;
virtual uint getDiffMod() = 0; virtual uint getDiffMod() = 0;
virtual real getDiffusivity() = 0; virtual real getDiffusivity() = 0;
virtual real getTemperatureInit() = 0; virtual real getTemperatureInit() = 0;
virtual real getTemperatureBC() = 0; virtual real getTemperatureBC() = 0;
virtual real getVelocity() = 0; virtual real getVelocity() = 0;
virtual real getViscosityRatio() = 0; virtual real getViscosityRatio() = 0;
virtual real getVelocityRatio() = 0; virtual real getVelocityRatio() = 0;
virtual real getDensityRatio() = 0; virtual real getDensityRatio() = 0;
virtual real getPressRatio() = 0; virtual real getPressRatio() = 0;
virtual real getRealX() = 0; virtual real getRealX() = 0;
virtual real getRealY() = 0; virtual real getRealY() = 0;
virtual real getFactorPressBC() = 0; virtual real getFactorPressBC() = 0;
virtual std::string getGeometryFileC() = 0; virtual std::string getGeometryFileC() = 0;
virtual std::string getGeometryFileM() = 0; virtual std::string getGeometryFileM() = 0;
virtual std::string getGeometryFileF() = 0; virtual std::string getGeometryFileF() = 0;
virtual uint getClockCycleForMP() = 0; virtual uint getClockCycleForMP() = 0;
virtual uint getTimestepForMP() = 0; virtual uint getTimestepForMP() = 0;
virtual real getForcingX() = 0; virtual real getForcingX() = 0;
virtual real getForcingY() = 0; virtual real getForcingY() = 0;
virtual real getForcingZ() = 0; virtual real getForcingZ() = 0;
virtual real getQuadricLimiterP() = 0; virtual real getQuadricLimiterP() = 0;
virtual real getQuadricLimiterM() = 0; virtual real getQuadricLimiterM() = 0;
virtual real getQuadricLimiterD() = 0; virtual real getQuadricLimiterD() = 0;
virtual bool getCalcParticles() = 0; virtual bool getCalcParticles() = 0;
virtual int getParticleBasicLevel() = 0; virtual int getParticleBasicLevel() = 0;
virtual int getParticleInitLevel() = 0; virtual int getParticleInitLevel() = 0;
virtual int getNumberOfParticles() = 0; virtual int getNumberOfParticles() = 0;
virtual real getStartXHotWall() = 0; virtual real getStartXHotWall() = 0;
virtual real getEndXHotWall() = 0; virtual real getEndXHotWall() = 0;
virtual std::vector<std::string> getPossNeighborFilesX() = 0; virtual std::vector<std::string> getPossNeighborFilesX() = 0;
virtual std::vector<std::string> getPossNeighborFilesY() = 0; virtual std::vector<std::string> getPossNeighborFilesY() = 0;
virtual std::vector<std::string> getPossNeighborFilesZ() = 0; virtual std::vector<std::string> getPossNeighborFilesZ() = 0;
//virtual std::vector<std::string> getPossNeighborFilesX() = 0; // virtual std::vector<std::string> getPossNeighborFilesX() = 0;
//virtual std::vector<std::string> getPossNeighborFilesY() = 0; // virtual std::vector<std::string> getPossNeighborFilesY() = 0;
//virtual std::vector<std::string> getPossNeighborFilesZ() = 0; // virtual std::vector<std::string> getPossNeighborFilesZ() = 0;
virtual int getTimeDoCheckPoint() = 0; virtual int getTimeDoCheckPoint() = 0;
virtual int getTimeDoRestart() = 0; virtual int getTimeDoRestart() = 0;
virtual bool getDoCheckPoint() = 0; virtual bool getDoCheckPoint() = 0;
virtual bool getDoRestart() = 0; virtual bool getDoRestart() = 0;
virtual uint getMaxLevel() = 0; virtual uint getMaxLevel() = 0;
virtual std::vector<int> getGridX() = 0; virtual std::vector<int> getGridX() = 0;
virtual std::vector<int> getGridY() = 0; virtual std::vector<int> getGridY() = 0;
virtual std::vector<int> getGridZ() = 0; virtual std::vector<int> getGridZ() = 0;
virtual std::vector<int> getDistX() = 0; virtual std::vector<int> getDistX() = 0;
virtual std::vector<int> getDistY() = 0; virtual std::vector<int> getDistY() = 0;
virtual std::vector<int> getDistZ() = 0; virtual std::vector<int> getDistZ() = 0;
virtual std::vector<bool> getNeedInterface() = 0; virtual std::vector<bool> getNeedInterface() = 0;
virtual std::string getMainKernel() = 0; virtual std::string getMainKernel() = 0;
virtual bool getMultiKernelOn() = 0; virtual bool getMultiKernelOn() = 0;
virtual std::vector<int> getMultiKernelLevel() = 0; virtual std::vector<int> getMultiKernelLevel() = 0;
virtual std::vector<std::string>getMultiKernelName() = 0; virtual std::vector<std::string> getMultiKernelName() = 0;
virtual bool isViscosityInConfigFile() = 0;
virtual bool isNumberOfDevicesInConfigFile() = 0;
virtual bool isDevicesInConfigFile() = 0;
virtual bool isOutputPathInConfigFile() = 0;
virtual bool isPrefixInConfigFile() = 0;
virtual bool isGridPathInConfigFile() = 0;
virtual bool isPrintOutputFilesInConfigFile() = 0;
virtual bool isGeometryValuesInConfigFile() = 0;
virtual bool isCalc2ndOrderMomentsInConfigFile() = 0;
virtual bool isCalc3rdOrderMomentsInConfigFile() = 0;
virtual bool isCalcHighOrderMomentsInConfigFile() = 0;
virtual bool isReadGeoInConfigFile() = 0;
virtual bool isCalcMedianInConfigFile() = 0;
virtual bool isCalcDragLiftInConfigFile() = 0;
virtual bool isCalcCpInConfigFile() = 0;
virtual bool isWriteVeloASCIIfilesInConfigFile() = 0;
virtual bool isCalcPlaneConcInConfigFile() = 0;
virtual bool isConcFileInConfigFile() = 0;
virtual bool isStreetVelocityFileInConfigFile() = 0;
virtual bool isUseMeasurePointsInConfigFile() = 0;
virtual bool isUseWaleInConfigFile() = 0;
virtual bool isUseInitNeqInConfigFile() = 0;
virtual bool isSimulatePorousMediaInConfigFile() = 0;
virtual bool isD3QxxInConfigFile() = 0;
virtual bool isTEndInConfigFile() = 0;
virtual bool isTOutInConfigFile() = 0;
virtual bool isTStartOutInConfigFile() = 0;
virtual bool isTimeCalcMedStartInConfigFile() = 0;
virtual bool isTimeCalcMedEndInConfigFile() = 0;
virtual bool isPressInIDInConfigFile() = 0;
virtual bool isPressOutIDInConfigFile() = 0;
virtual bool isPressInZInConfigFile() = 0;
virtual bool isPressOutZInConfigFile() = 0;
virtual bool isDiffOnInConfigFile() = 0;
virtual bool isDiffModInConfigFile() = 0;
virtual bool isDiffusivityInConfigFile() = 0;
virtual bool isTemperatureInitInConfigFile() = 0;
virtual bool isTemperatureBCInConfigFile() = 0;
//virtual bool isViscosityInConfigFile() = 0;
virtual bool isVelocityInConfigFile() = 0;
virtual bool isViscosityRatioInConfigFile() = 0;
virtual bool isVelocityRatioInConfigFile() = 0;
virtual bool isDensityRatioInConfigFile() = 0;
virtual bool isPressRatioInConfigFile() = 0;
virtual bool isRealXInConfigFile() = 0;
virtual bool isRealYInConfigFile() = 0;
virtual bool isFactorPressBCInConfigFile() = 0;
virtual bool isGeometryFileCInConfigFile() = 0;
virtual bool isGeometryFileMInConfigFile() = 0;
virtual bool isGeometryFileFInConfigFile() = 0;
virtual bool isClockCycleForMPInConfigFile() = 0;
virtual bool isTimestepForMPInConfigFile() = 0;
virtual bool isForcingXInConfigFile() = 0;
virtual bool isForcingYInConfigFile() = 0;
virtual bool isForcingZInConfigFile() = 0;
virtual bool isQuadricLimiterPInConfigFile() = 0;
virtual bool isQuadricLimiterMInConfigFile() = 0;
virtual bool isQuadricLimiterDInConfigFile() = 0;
virtual bool isCalcParticlesInConfigFile() = 0;
virtual bool isParticleBasicLevelInConfigFile() = 0;
virtual bool isParticleInitLevelInConfigFile() = 0;
virtual bool isNumberOfParticlesInConfigFile() = 0;
virtual bool isNeighborWSBInConfigFile() = 0;
virtual bool isStartXHotWallInConfigFile() = 0;
virtual bool isEndXHotWallInConfigFile() = 0;
virtual bool isPossNeighborFilesXInConfigFile() = 0;
virtual bool isPossNeighborFilesYInConfigFile() = 0;
virtual bool isPossNeighborFilesZInConfigFile() = 0;
virtual bool isTimeDoCheckPointInConfigFile() = 0;
virtual bool isTimeDoRestartInConfigFile() = 0;
virtual bool isDoCheckPointInConfigFile() = 0;
virtual bool isDoRestartInConfigFile() = 0;
virtual bool isMaxLevelInConfigFile() = 0;
virtual bool isGridXInConfigFile() = 0;
virtual bool isGridYInConfigFile() = 0;
virtual bool isGridZInConfigFile() = 0;
virtual bool isDistXInConfigFile() = 0;
virtual bool isDistYInConfigFile() = 0;
virtual bool isDistZInConfigFile() = 0;
virtual bool isNeedInterfaceInConfigFile() = 0;
virtual bool isMainKernelInConfigFile() = 0;
virtual bool isMultiKernelOnInConfigFile() = 0;
virtual bool isMultiKernelLevelInConfigFile() = 0;
virtual bool isMultiKernelNameInConfigFile() = 0;
virtual bool isViscosityInConfigFile() = 0;
virtual bool isNumberOfDevicesInConfigFile() = 0;
virtual bool isDevicesInConfigFile() = 0;
virtual bool isOutputPathInConfigFile() = 0;
virtual bool isPrefixInConfigFile() = 0;
virtual bool isGridPathInConfigFile() = 0;
virtual bool isPrintOutputFilesInConfigFile() = 0;
virtual bool isGeometryValuesInConfigFile() = 0;
virtual bool isCalc2ndOrderMomentsInConfigFile() = 0;
virtual bool isCalc3rdOrderMomentsInConfigFile() = 0;
virtual bool isCalcHighOrderMomentsInConfigFile() = 0;
virtual bool isReadGeoInConfigFile() = 0;
virtual bool isCalcMedianInConfigFile() = 0;
virtual bool isCalcDragLiftInConfigFile() = 0;
virtual bool isCalcCpInConfigFile() = 0;
virtual bool isWriteVeloASCIIfilesInConfigFile() = 0;
virtual bool isCalcPlaneConcInConfigFile() = 0;
virtual bool isConcFileInConfigFile() = 0;
virtual bool isStreetVelocityFileInConfigFile() = 0;
virtual bool isUseMeasurePointsInConfigFile() = 0;
virtual bool isUseWaleInConfigFile() = 0;
virtual bool isUseInitNeqInConfigFile() = 0;
virtual bool isSimulatePorousMediaInConfigFile() = 0;
virtual bool isD3QxxInConfigFile() = 0;
virtual bool isTEndInConfigFile() = 0;
virtual bool isTOutInConfigFile() = 0;
virtual bool isTStartOutInConfigFile() = 0;
virtual bool isTimeCalcMedStartInConfigFile() = 0;
virtual bool isTimeCalcMedEndInConfigFile() = 0;
virtual bool isPressInIDInConfigFile() = 0;
virtual bool isPressOutIDInConfigFile() = 0;
virtual bool isPressInZInConfigFile() = 0;
virtual bool isPressOutZInConfigFile() = 0;
virtual bool isDiffOnInConfigFile() = 0;
virtual bool isDiffModInConfigFile() = 0;
virtual bool isDiffusivityInConfigFile() = 0;
virtual bool isTemperatureInitInConfigFile() = 0;
virtual bool isTemperatureBCInConfigFile() = 0;
// virtual bool isViscosityInConfigFile() = 0;
virtual bool isVelocityInConfigFile() = 0;
virtual bool isViscosityRatioInConfigFile() = 0;
virtual bool isVelocityRatioInConfigFile() = 0;
virtual bool isDensityRatioInConfigFile() = 0;
virtual bool isPressRatioInConfigFile() = 0;
virtual bool isRealXInConfigFile() = 0;
virtual bool isRealYInConfigFile() = 0;
virtual bool isFactorPressBCInConfigFile() = 0;
virtual bool isGeometryFileCInConfigFile() = 0;
virtual bool isGeometryFileMInConfigFile() = 0;
virtual bool isGeometryFileFInConfigFile() = 0;
virtual bool isClockCycleForMPInConfigFile() = 0;
virtual bool isTimestepForMPInConfigFile() = 0;
virtual bool isForcingXInConfigFile() = 0;
virtual bool isForcingYInConfigFile() = 0;
virtual bool isForcingZInConfigFile() = 0;
virtual bool isQuadricLimiterPInConfigFile() = 0;
virtual bool isQuadricLimiterMInConfigFile() = 0;
virtual bool isQuadricLimiterDInConfigFile() = 0;
virtual bool isCalcParticlesInConfigFile() = 0;
virtual bool isParticleBasicLevelInConfigFile() = 0;
virtual bool isParticleInitLevelInConfigFile() = 0;
virtual bool isNumberOfParticlesInConfigFile() = 0;
virtual bool isNeighborWSBInConfigFile() = 0;
virtual bool isStartXHotWallInConfigFile() = 0;
virtual bool isEndXHotWallInConfigFile() = 0;
virtual bool isPossNeighborFilesXInConfigFile() = 0;
virtual bool isPossNeighborFilesYInConfigFile() = 0;
virtual bool isPossNeighborFilesZInConfigFile() = 0;
virtual bool isTimeDoCheckPointInConfigFile() = 0;
virtual bool isTimeDoRestartInConfigFile() = 0;
virtual bool isDoCheckPointInConfigFile() = 0;
virtual bool isDoRestartInConfigFile() = 0;
virtual bool isMaxLevelInConfigFile() = 0;
virtual bool isGridXInConfigFile() = 0;
virtual bool isGridYInConfigFile() = 0;
virtual bool isGridZInConfigFile() = 0;
virtual bool isDistXInConfigFile() = 0;
virtual bool isDistYInConfigFile() = 0;
virtual bool isDistZInConfigFile() = 0;
virtual bool isNeedInterfaceInConfigFile() = 0;
virtual bool isMainKernelInConfigFile() = 0;
virtual bool isMultiKernelOnInConfigFile() = 0;
virtual bool isMultiKernelLevelInConfigFile() = 0;
virtual bool isMultiKernelNameInConfigFile() = 0;
}; };
#endif #endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
class ConfigData; class ConfigData;
class ConfigFileReader class ConfigFileReader
{ {
public: public:
BASICS_EXPORT static std::shared_ptr<ConfigFileReader> getNewInstance(); BASICS_EXPORT static std::shared_ptr<ConfigFileReader> getNewInstance();
...@@ -16,6 +16,6 @@ public: ...@@ -16,6 +16,6 @@ public:
BASICS_EXPORT std::shared_ptr<ConfigData> readConfigFile(const std::string &filePath) const; BASICS_EXPORT std::shared_ptr<ConfigData> readConfigFile(const std::string &filePath) const;
private: private:
ConfigFileReader(); ConfigFileReader();
}; };
#endif #endif
#include "ConfigInput.h" #include "ConfigInput.h"
#include <cerrno>
#include <algorithm> #include <algorithm>
#include <sstream> #include <cerrno>
#include <iostream> #include <iostream>
#include <sstream>
#include <string> #include <string>
#define COMMENT '#' #define COMMENT '#'
namespace input namespace input
{ {
// Trim the given characters from the beginning and end of a string. // Trim the given characters from the beginning and end of a string.
// the default is to trim whitespace. If the string is empty or contains // the default is to trim whitespace. If the string is empty or contains
// only the trim characters, an empty string is returned. // only the trim characters, an empty string is returned.
std::string trim(const std::string &instring, const std::string &trimstring = std::string(" \t\n")) std::string trim(const std::string &instring, const std::string &trimstring = std::string(" \t\n"))
{ {
if (trimstring.size() == 0) if (trimstring.size() == 0)
return instring; return instring;
std::string temp = ""; std::string temp = "";
std::string::size_type begpos = instring.find_first_not_of(trimstring); std::string::size_type begpos = instring.find_first_not_of(trimstring);
if (begpos == std::string::npos) if (begpos == std::string::npos) {
{
return temp;
}
else
{
std::string::size_type endpos = instring.find_last_not_of(trimstring);
temp = instring.substr(begpos, endpos - begpos + 1);
}
return temp; return temp;
} else {
std::string::size_type endpos = instring.find_last_not_of(trimstring);
temp = instring.substr(begpos, endpos - begpos + 1);
} }
return temp;
}
ConfigInput::ConfigInput(std::istream &stream) : stream(stream) ConfigInput::ConfigInput(std::istream &stream) : stream(stream)
{ {
while (!stream.eof()) while (!stream.eof())
this->setTokenValuePair(); this->setTokenValuePair();
} }
ConfigInput::~ConfigInput() ConfigInput::~ConfigInput() = default;
= default;
bool ConfigInput::hasValue(const std::string &key) const bool ConfigInput::hasValue(const std::string &key) const
{ {
bool valueFound = false; bool valueFound = false;
std::string keyCopy = key; std::string keyCopy = key;
this->makeLower(keyCopy); this->makeLower(keyCopy);
if (configEntries.find(keyCopy.c_str()) != configEntries.end()) if (configEntries.find(keyCopy.c_str()) != configEntries.end())
valueFound = true; valueFound = true;
return valueFound; return valueFound;
} }
std::string ConfigInput::getValue(const std::string &key) std::string ConfigInput::getValue(const std::string &key)
{ {
std::string keyCopy = key; std::string keyCopy = key;
this->makeLower(keyCopy); this->makeLower(keyCopy);
if (configEntries.find(keyCopy.c_str()) != configEntries.end()) if (configEntries.find(keyCopy.c_str()) != configEntries.end())
return (*configEntries.find(keyCopy.c_str())).second; return (*configEntries.find(keyCopy.c_str())).second;
return ""; return "";
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// private methods // // private methods //
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void ConfigInput::makeLower(std::string &value) const void ConfigInput::makeLower(std::string &value) const
{ {
for (size_t i = 0; i < value.size(); i++) for (size_t i = 0; i < value.size(); i++)
value[i] = tolower(value[i]); value[i] = tolower(value[i]);
} }
void ConfigInput::setTokenValuePair() void ConfigInput::setTokenValuePair()
{ {
this->eatWhiteAndComments(true); this->eatWhiteAndComments(true);
std::string token; std::string token;
if(!this->setToken(token)) if (!this->setToken(token))
return; return;
std::string value; std::string value;
this->setValue(value); this->setValue(value);
configEntries.insert(String_Pair(token, value)); configEntries.insert(String_Pair(token, value));
} }
bool ConfigInput::setToken(std::string &token) bool ConfigInput::setToken(std::string &token)
{ {
char tokenChar[1024]; char tokenChar[1024];
bool foundEqualSign = false; bool foundEqualSign = false;
int charIndex = 0; int charIndex = 0;
this->findToken(foundEqualSign, tokenChar, charIndex); this->findToken(foundEqualSign, tokenChar, charIndex);
if (!isToken(charIndex, foundEqualSign)) if (!isToken(charIndex, foundEqualSign))
return false; return false;
this->nullTerminate(tokenChar, charIndex); this->nullTerminate(tokenChar, charIndex);
token = tokenChar; token = tokenChar;
makeLower(token); makeLower(token);
return true; return true;
} }
void ConfigInput::findToken(bool &foundEqualSign, char *token, int &i) void ConfigInput::findToken(bool &foundEqualSign, char *token, int &i)
{ {
char ch; char ch;
while (!(stream.get(ch)).fail()) while (!(stream.get(ch)).fail()) {
{ if ((ch != '\t')) {
if ((ch != '\t')) if ((ch == '=') || (ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t')) {
{ foundEqualSign = true;
if ((ch == '=') || (ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t')) break;
{
foundEqualSign = true;
break;
}
token[i++] = ch;
} }
token[i++] = ch;
} }
} }
}
bool ConfigInput::isToken(int charIndex, bool foundEqualSign)
bool ConfigInput::isToken(int charIndex, bool foundEqualSign) {
{ if (charIndex == 0) {
if (charIndex == 0) configEntries.insert(String_Pair("", ""));
{ return false;
configEntries.insert(String_Pair("", ""));
return false;
}
if (!foundEqualSign && !advanceToEqualSignOnLine())
{
configEntries.insert(String_Pair("", ""));
return false;
}
return true;
} }
void ConfigInput::setValue(std::string &value) if (!foundEqualSign && !advanceToEqualSignOnLine()) {
{ configEntries.insert(String_Pair("", ""));
int charIndex = 0; return false;
char valueChar[1024];
this->findValue(charIndex, valueChar);
if (charIndex == 0)
value = "";
else
{
this->nullTerminate(valueChar, charIndex);
value = valueChar;
value = trim(value);
this->stripLeadingAndTrailingQuotes(value);
}
} }
return true;
}
void ConfigInput::setValue(std::string &value)
{
int charIndex = 0;
char valueChar[1024];
this->findValue(charIndex, valueChar);
if (charIndex == 0)
value = "";
else {
this->nullTerminate(valueChar, charIndex);
value = valueChar;
value = trim(value);
this->stripLeadingAndTrailingQuotes(value);
}
}
int ConfigInput::findValue(int &charIndex, char * value) int ConfigInput::findValue(int &charIndex, char *value)
{ {
char ch; char ch;
char c = eatWhiteAndComments(false); char c = eatWhiteAndComments(false);
if (c != '\n') if (c != '\n') {
{ charIndex = 0;
charIndex = 0; while (!(stream.get(ch)).fail()) {
while (!(stream.get(ch)).fail()) if ((ch == '\t') || (ch == '\r') || (ch == '\n') || (ch == '#')) {
{ while (ch != '\n') {
if ((ch == '\t') || (ch == '\r') || (ch == '\n') || (ch == '#')) if (stream.get(ch).fail())
{ break;
while (ch != '\n')
{
if (stream.get(ch).fail()) break;
}
break;
}
else
{
value[charIndex++] = ch;
} }
break;
} else {
value[charIndex++] = ch;
} }
} }
return charIndex;
} }
return charIndex;
}
void ConfigInput::stripLeadingAndTrailingQuotes(std::string &m_value)
{
if (m_value[0] == '"')
m_value = m_value.substr(1);
if (m_value[m_value.length() - 1] == '"')
m_value = m_value.substr(0, m_value.length() - 1);
}
void ConfigInput::nullTerminate(char *value, int &i) { value[i++] = '\0'; }
void ConfigInput::stripLeadingAndTrailingQuotes(std::string &m_value) bool ConfigInput::advanceToEqualSignOnLine()
{ {
if (m_value[0] == '"') char ch;
m_value = m_value.substr(1); bool foundEqual = false;
if (m_value[m_value.length() - 1] == '"') while (!(stream.get(ch)).fail()) {
m_value = m_value.substr(0, m_value.length() - 1); if (isNewLine(ch) || isCarriageReturn(ch))
} break;
if (isEqualSign(ch)) {
void ConfigInput::nullTerminate(char *value, int &i) foundEqual = true;
{ break;
value[i++] = '\0';
}
bool ConfigInput::advanceToEqualSignOnLine()
{
char ch;
bool foundEqual = false;
while (!(stream.get(ch)).fail())
{
if (isNewLine(ch) || isCarriageReturn(ch))
break;
if (isEqualSign(ch))
{
foundEqual = true;
break;
}
} }
return foundEqual;
} }
return foundEqual;
}
char ConfigInput::eatWhiteAndComments(bool traverseNewlines) char ConfigInput::eatWhiteAndComments(bool traverseNewlines)
{ {
char ch; char ch;
bool isComment = false; bool isComment = false;
while (!(stream.get(ch)).fail()) while (!(stream.get(ch)).fail()) {
{ if (isCommentSign(ch))
if (isCommentSign(ch)) isComment = true;
isComment = true; else if (isNewLine(ch)) {
else if (isNewLine(ch)) isComment = false;
{ if (!traverseNewlines)
isComment = false; return (ch);
if (!traverseNewlines) } else if (isRegularChar(isComment, ch)) {
return(ch); stream.putback(ch);
} return 0;
else if (isRegularChar(isComment, ch))
{
stream.putback(ch);
return 0;
}
} }
return 0;
}
bool ConfigInput::isRegularChar(bool isComment, char ch)
{
return (!isComment) && (ch != ' ') && (ch != '\t') && (ch != '\r');
} }
return 0;
}
bool ConfigInput::isCommentSign(char ch) bool ConfigInput::isRegularChar(bool isComment, char ch)
{ {
return ch == COMMENT; return (!isComment) && (ch != ' ') && (ch != '\t') && (ch != '\r');
} }
bool ConfigInput::isEqualSign(char ch) bool ConfigInput::isCommentSign(char ch) { return ch == COMMENT; }
{
return ch == '=';
}
bool ConfigInput::isNewLine(char ch) bool ConfigInput::isEqualSign(char ch) { return ch == '='; }
{
return ch == '\n';
}
bool ConfigInput::isCarriageReturn(char ch) bool ConfigInput::isNewLine(char ch) { return ch == '\n'; }
{
return ch == '\r';
}
bool ConfigInput::isCarriageReturn(char ch) { return ch == '\r'; }
} } // namespace input
#ifndef ConfigInput_H #ifndef ConfigInput_H
#define ConfigInput_H #define ConfigInput_H
#include <string>
#include <vector>
#include <istream> #include <istream>
#include <memory>
#include <map>
#include <list> #include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "basics_export.h"
#include "../Input.h" #include "../Input.h"
#include "basics_export.h"
namespace input namespace input
{
class ConfigInput : public Input
{ {
class ConfigInput : public Input public:
{ BASICS_EXPORT ConfigInput(std::istream &stream);
public: BASICS_EXPORT ~ConfigInput() override;
BASICS_EXPORT ConfigInput(std::istream &stream);
BASICS_EXPORT ~ConfigInput() override; BASICS_EXPORT bool hasValue(const std::string &key) const override;
BASICS_EXPORT std::string getValue(const std::string &key) override;
BASICS_EXPORT bool hasValue(const std::string &key) const override;
BASICS_EXPORT std::string getValue(const std::string &key) override;
protected: protected:
virtual void setTokenValuePair(); virtual void setTokenValuePair();
void setValue(std::string &value); void setValue(std::string &value);
bool setToken(std::string &token); bool setToken(std::string &token);
bool isToken(int charIndex, bool foundEqualSign); bool isToken(int charIndex, bool foundEqualSign);
int findValue(int &charIndex, char * value); int findValue(int &charIndex, char *value);
void stripLeadingAndTrailingQuotes(std::string &m_value); void stripLeadingAndTrailingQuotes(std::string &m_value);
void nullTerminate(char * token, int &i); void nullTerminate(char *token, int &i);
void findToken(bool &foundEqualSign, char * token, int &i); void findToken(bool &foundEqualSign, char *token, int &i);
char eatWhiteAndComments(bool traverse_newlines = true); char eatWhiteAndComments(bool traverse_newlines = true);
bool isRegularChar(bool isComment, char ch); bool isRegularChar(bool isComment, char ch);
bool isNewLine(char ch); bool isNewLine(char ch);
bool isCommentSign(char ch); bool isCommentSign(char ch);
bool advanceToEqualSignOnLine(); bool advanceToEqualSignOnLine();
bool isCarriageReturn(char ch); bool isCarriageReturn(char ch);
bool isEqualSign(char ch); bool isEqualSign(char ch);
void makeLower(std::string &instring) const; void makeLower(std::string &instring) const;
protected: protected:
std::istream &stream; std::istream &stream;
using String_Pair = std::pair <std::string, std::string>; using String_Pair = std::pair<std::string, std::string>;
std::map<std::string, std::string> configEntries; std::map<std::string, std::string> configEntries;
}; };
} } // namespace input
#endif #endif
...@@ -11,15 +11,14 @@ ...@@ -11,15 +11,14 @@
namespace input namespace input
{ {
std::unique_ptr<input::Input> Input::makeInput(std::istream &stream, const std::string & /*inputType*/) std::unique_ptr<input::Input> Input::makeInput(std::istream &stream, const std::string & /*inputType*/)
{ {
#ifdef BUILD_JSONCPP #ifdef BUILD_JSONCPP
if(inputType == "json") if (inputType == "json")
return std::unique_ptr<Input>(new JsonInput(stream)); return std::unique_ptr<Input>(new JsonInput(stream));
#endif #endif
return std::make_unique<ConfigInput>(stream); return std::make_unique<ConfigInput>(stream);
}
} }
} // namespace input
...@@ -3,23 +3,22 @@ ...@@ -3,23 +3,22 @@
#include "basics_export.h" #include "basics_export.h"
#include <string>
#include <memory>
#include <istream> #include <istream>
#include <memory>
#include <string>
namespace input namespace input
{ {
class Input class Input
{ {
public: public:
static BASICS_EXPORT std::unique_ptr<Input> makeInput(std::istream &stream, const std::string &inputType); static BASICS_EXPORT std::unique_ptr<Input> makeInput(std::istream &stream, const std::string &inputType);
virtual ~Input() = default; virtual ~Input() = default;
virtual bool hasValue(const std::string &key) const = 0; virtual bool hasValue(const std::string &key) const = 0;
virtual std::string getValue(const std::string &key) = 0; virtual std::string getValue(const std::string &key) = 0;
}; };
} } // namespace input
#endif #endif
...@@ -3,64 +3,65 @@ ...@@ -3,64 +3,65 @@
#include "JsonInput.h" #include "JsonInput.h"
#include <fstream> #include <fstream>
#include <string> #include <iterator>
#include <sstream> #include <sstream>
#include <string>
#include <vector> #include <vector>
#include <iterator>
namespace input namespace input
{ {
template<typename Out> template <typename Out>
void split(const std::string &s, char delim, Out result) { void split(const std::string &s, char delim, Out result)
std::stringstream ss; {
ss.str(s); std::stringstream ss;
std::string item; ss.str(s);
while (std::getline(ss, item, delim)) { std::string item;
*(result++) = item; while (std::getline(ss, item, delim)) {
} *(result++) = item;
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems));
return elems;
}
JsonInput::JsonInput(std::istream &stream)
{
Json::Reader reader;
reader.parse(stream, jsonValue);
} }
}
bool JsonInput::hasValue(const std::string &key) const std::vector<std::string> split(const std::string &s, char delim)
{ {
auto keys = split(key, ' '); std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems));
return elems;
}
if (keys.size() == 1 && !jsonValue[keys[0]].isNull()) JsonInput::JsonInput(std::istream &stream)
return true; {
else if (keys.size() == 2 && !jsonValue[keys[0]][keys[1]].isNull()) Json::Reader reader;
return true; reader.parse(stream, jsonValue);
else if (keys.size() == 3 && !jsonValue[keys[0]][keys[1]][keys[2]].isNull()) }
return true;
else
return false;
}
std::string JsonInput::getValue(const std::string &key) bool JsonInput::hasValue(const std::string &key) const
{ {
auto keys = split(key, ' '); auto keys = split(key, ' ');
if(keys.size() == 1) if (keys.size() == 1 && !jsonValue[keys[0]].isNull())
return jsonValue[keys[0]].asString(); return true;
else if (keys.size() == 2) else if (keys.size() == 2 && !jsonValue[keys[0]][keys[1]].isNull())
return jsonValue[keys[0]][keys[1]].asString(); return true;
else if (keys.size() == 3) else if (keys.size() == 3 && !jsonValue[keys[0]][keys[1]][keys[2]].isNull())
return jsonValue[keys[0]][keys[1]][keys[2]].asString(); return true;
else else
return ""; return false;
} }
std::string JsonInput::getValue(const std::string &key)
{
auto keys = split(key, ' ');
if (keys.size() == 1)
return jsonValue[keys[0]].asString();
else if (keys.size() == 2)
return jsonValue[keys[0]][keys[1]].asString();
else if (keys.size() == 3)
return jsonValue[keys[0]][keys[1]][keys[2]].asString();
else
return "";
} }
} // namespace input
#endif #endif
...@@ -3,31 +3,27 @@ ...@@ -3,31 +3,27 @@
#ifndef JsonInput_H #ifndef JsonInput_H
#define JsonInput_H #define JsonInput_H
#include <string>
#include <json/json.h> #include <json/json.h>
#include <string>
#include "basics_export.h" #include "basics_export.h"
#include "../Input.h" #include "../Input.h"
namespace input namespace input
{ {
class JsonInput : public Input class JsonInput : public Input
{ {
public: public:
BASICS_EXPORT JsonInput(std::istream &stream); BASICS_EXPORT JsonInput(std::istream &stream);
BASICS_EXPORT virtual bool hasValue(const std::string &key) const override;
BASICS_EXPORT virtual std::string getValue(const std::string &key) override;
private: BASICS_EXPORT virtual bool hasValue(const std::string &key) const override;
Json::Value jsonValue; BASICS_EXPORT virtual std::string getValue(const std::string &key) override;
}; private:
} Json::Value jsonValue;
};
} // namespace input
#endif #endif
......
//======================================================================================= //=======================================================================================
// ____ ____ __ ______ __________ __ __ __ __ // ____ ____ __ ______ __________ __ __ __ __
// \ \ | | | | | _ \ |___ ___| | | | | / \ | | // \ \ | | | | | _ \ |___ ___| | | | | / \ | |
// \ \ | | | | | |_) | | | | | | | / \ | | // \ \ | | | | | |_) | | | | | | | / \ | |
// \ \ | | | | | _ / | | | | | | / /\ \ | | // \ \ | | | | | _ / | | | | | | / /\ \ | |
// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ // \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| // \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
// \ \ | | ________________________________________________________________ // \ \ | | ________________________________________________________________
// \ \ | | | ______________________________________________________________| // \ \ | | | ______________________________________________________________|
// \ \| | | | __ __ __ __ ______ _______ // \ \| | | | __ __ __ __ ______ _______
// \ | | |_____ | | | | | | | | | _ \ / _____) // \ | | |_____ | | | | | | | | | _ \ / _____)
// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | _____| | | | | | | | | | | \ \ \_______
// \ | | | | |_____ | \_/ | | | | |_/ / _____ | // \ | | | | |_____ | \_/ | | | | |_/ / _____ |
// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // \ _____| |__| |________| \_______/ |__| |______/ (_______/
// //
// This file is part of VirtualFluids. VirtualFluids is free software: you can // This file is part of VirtualFluids. VirtualFluids is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public // 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 // License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version. // the License, or (at your option) any later version.
// //
// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT // VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details. // for more details.
// //
// You should have received a copy of the GNU General Public License along // You should have received a copy of the GNU General Public License along
// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
// //
...@@ -33,10 +33,6 @@ ...@@ -33,10 +33,6 @@
#ifndef LBMORGKS_H #ifndef LBMORGKS_H
#define LBMORGKS_H #define LBMORGKS_H
enum LbmOrGks enum LbmOrGks { LBM, GKS };
{
LBM,
GKS
};
#endif #endif
#include "Logger.h" #include "Logger.h"
//#include "mpi.h" //#include "mpi.h"
#include <memory>
#include <iostream> #include <iostream>
#include <memory>
#include "implementations/LoggerImp.h" #include "implementations/LoggerImp.h"
namespace logging
{
std::shared_ptr<Logger> out = nullptr;
namespace logging { logging::Logger::Level logging::Logger::globalLogLevel = logging::Logger::INFO_LOW;
logging::Logger::Level logging::Logger::localLogLevel = logging::Logger::INFO_LOW;
std::shared_ptr<Logger> out = nullptr; bool logging::Logger::printRankNumber = false;
bool logging::Logger::timeStampEnabled = false;
logging::Logger::Level logging::Logger::globalLogLevel = logging::Logger::INFO_LOW; logging::Logger::Logger(std::ostream *stream) { streams.push_back(stream); }
logging::Logger::Level logging::Logger::localLogLevel = logging::Logger::INFO_LOW;
bool logging::Logger::printRankNumber = false;
bool logging::Logger::timeStampEnabled = false;
logging::Logger::Logger(std::ostream* stream) logging::Logger::~Logger() = default;
{
streams.push_back(stream);
}
logging::Logger::~Logger() void Logger::addStreamToList(std::ostream *stream) { streams.push_back(stream); }
= default;
void Logger::addStreamToList(std::ostream* stream)
{
streams.push_back(stream);
}
void Logger::resetStreamList()
{
streams.clear();
}
void Logger::resetStreamList() { streams.clear(); }
//-----------static methods----------------// //-----------static methods----------------//
void logging::Logger::resetStreams() void logging::Logger::resetStreams()
{ {
if (!out) if (!out)
out = std::make_shared<LoggerImp>(&std::cout); out = std::make_shared<LoggerImp>(&std::cout);
out->resetStreamList(); out->resetStreamList();
} }
void logging::Logger::setStream(std::ostream* stream) void logging::Logger::setStream(std::ostream *stream) { out = std::make_shared<LoggerImp>(stream); }
{
out = std::make_shared<LoggerImp>(stream);
}
void logging::Logger::addStream(std::ostream* stream) void logging::Logger::addStream(std::ostream *stream)
{ {
if (!out) if (!out)
out = std::make_shared<LoggerImp>(stream); out = std::make_shared<LoggerImp>(stream);
else else
out->addStreamToList(stream); out->addStreamToList(stream);
} }
void logging::Logger::timeStamp(TimeStamp timeStamp) void logging::Logger::timeStamp(TimeStamp timeStamp)
{ {
switch(timeStamp) switch (timeStamp) {
{
case ENABLE: case ENABLE:
timeStampEnabled = true; timeStampEnabled = true;
break; break;
case DISABLE: case DISABLE:
timeStampEnabled = false; timeStampEnabled = false;
break; break;
}
} }
}
void logging::Logger::setDebugLevel(const Level &level) { globalLogLevel = level; }
void logging::Logger::enablePrintedRankNumbers(bool print) { printRankNumber = print; }
void logging::Logger::setDebugLevel(const Level &level) } // namespace logging
{
globalLogLevel = level;
}
void logging::Logger::enablePrintedRankNumbers(bool print)
{
printRankNumber = print;
}
}
...@@ -3,68 +3,54 @@ ...@@ -3,68 +3,54 @@
#include "basics_export.h" #include "basics_export.h"
#include <string>
#include <memory> #include <memory>
#include <ostream> #include <ostream>
#include <string>
#include <vector> #include <vector>
namespace logging namespace logging
{ {
class BASICS_EXPORT Logger class BASICS_EXPORT Logger
{ {
protected: protected:
Logger(std::ostream* stream); Logger(std::ostream *stream);
public:
virtual ~Logger();
enum Level
{
INFO_LOW = 3,
INFO_INTERMEDIATE = 2,
INFO_HIGH = 1,
WARNING = 0,
LOGGER_ERROR = -1
};
enum TimeStamp
{
ENABLE,
DISABLE
};
static void setStream(std::ostream* stream); public:
static void addStream(std::ostream* stream); virtual ~Logger();
static void resetStreams();
static void timeStamp(TimeStamp timeStamp); enum Level { INFO_LOW = 3, INFO_INTERMEDIATE = 2, INFO_HIGH = 1, WARNING = 0, LOGGER_ERROR = -1 };
static void setDebugLevel(const Level &level = Level::LOGGER_ERROR); enum TimeStamp { ENABLE, DISABLE };
static void enablePrintedRankNumbers(bool printRankNumbers);
virtual Logger& operator<<(const Level &level) = 0; static void setStream(std::ostream *stream);
virtual Logger& operator<<(const std::string &log) = 0; static void addStream(std::ostream *stream);
virtual Logger& operator<<(const int &log) = 0; static void resetStreams();
virtual Logger& operator<<(const unsigned int &log) = 0;
virtual Logger& operator<<(const unsigned long& log) = 0;
virtual Logger& operator<<(const float &log) = 0;
virtual Logger& operator<<(const double &log) = 0;
protected: static void timeStamp(TimeStamp timeStamp);
void addStreamToList(std::ostream* stream);
void resetStreamList();
std::vector<std::ostream*> streams; static void setDebugLevel(const Level &level = Level::LOGGER_ERROR);
static void enablePrintedRankNumbers(bool printRankNumbers);
static Level globalLogLevel; virtual Logger &operator<<(const Level &level) = 0;
static Level localLogLevel; virtual Logger &operator<<(const std::string &log) = 0;
static bool printRankNumber; virtual Logger &operator<<(const int &log) = 0;
static bool timeStampEnabled; virtual Logger &operator<<(const unsigned int &log) = 0;
virtual Logger &operator<<(const unsigned long &log) = 0;
virtual Logger &operator<<(const float &log) = 0;
virtual Logger &operator<<(const double &log) = 0;
}; protected:
extern BASICS_EXPORT std::shared_ptr<Logger> out; void addStreamToList(std::ostream *stream);
} void resetStreamList();
std::vector<std::ostream *> streams;
static Level globalLogLevel;
static Level localLogLevel;
static bool printRankNumber;
static bool timeStampEnabled;
};
extern BASICS_EXPORT std::shared_ptr<Logger> out;
} // namespace logging
#endif #endif
#include "LoggerImp.h" #include "LoggerImp.h"
#include <chrono>
#include <iomanip>
#include <iostream>
#include <mpi.h> #include <mpi.h>
#include <sstream> #include <sstream>
#include <iostream>
#include <iomanip>
#include <chrono>
logging::LoggerImp::LoggerImp(std::ostream *stream) : logging::Logger(stream)
logging::LoggerImp::LoggerImp(std::ostream* stream) : logging::Logger(stream)
{ {
levelString[Level::WARNING] = "[WARNING] "; levelString[Level::WARNING] = "[WARNING] ";
levelString[Level::LOGGER_ERROR] = "[ERROR] "; levelString[Level::LOGGER_ERROR] = "[ERROR] ";
levelString[Level::INFO_LOW] = "[INFO_LOW] "; levelString[Level::INFO_LOW] = "[INFO_LOW] ";
levelString[Level::INFO_INTERMEDIATE] = "[INFO_INTERMEDIATE]"; levelString[Level::INFO_INTERMEDIATE] = "[INFO_INTERMEDIATE]";
levelString[Level::INFO_HIGH] = "[INFO_HIGH] "; levelString[Level::INFO_HIGH] = "[INFO_HIGH] ";
} }
logging::LoggerImp::~LoggerImp() logging::LoggerImp::~LoggerImp() = default;
= default;
logging::Logger& logging::LoggerImp::operator<<(const Level &level) logging::Logger &logging::LoggerImp::operator<<(const Level &level)
{ {
localLogLevel = level; localLogLevel = level;
return *this; return *this;
} }
logging::Logger &logging::LoggerImp::operator<<(const std::string &message) { return this->log(message); }
logging::Logger& logging::LoggerImp::operator<<(const std::string &message) logging::Logger &logging::LoggerImp::operator<<(const int &message) { return this->log(std::to_string(message)); }
{
return this->log(message);
}
logging::Logger& logging::LoggerImp::operator<<(const int &message)
{
return this->log(std::to_string(message));
}
logging::Logger& logging::LoggerImp::operator<<(const unsigned int &message) logging::Logger &logging::LoggerImp::operator<<(const unsigned int &message)
{ {
return this->log(std::to_string(message)); return this->log(std::to_string(message));
} }
logging::Logger& logging::LoggerImp::operator<<(const unsigned long &message) logging::Logger &logging::LoggerImp::operator<<(const unsigned long &message)
{ {
return this->log(std::to_string(message)); return this->log(std::to_string(message));
} }
logging::Logger& logging::LoggerImp::operator<<(const float &message) logging::Logger &logging::LoggerImp::operator<<(const float &message) { return this->log(std::to_string(message)); }
{
return this->log(std::to_string(message));
}
logging::Logger& logging::LoggerImp::operator<<(const double &message) logging::Logger &logging::LoggerImp::operator<<(const double &message) { return this->log(std::to_string(message)); }
{
return this->log(std::to_string(message));
}
logging::Logger& logging::LoggerImp::log(const std::string &message) logging::Logger &logging::LoggerImp::log(const std::string &message)
{ {
if (shouldBeLogged()) if (shouldBeLogged()) {
{
std::string modifiedMessage = message; std::string modifiedMessage = message;
addDebugInformation(modifiedMessage); addDebugInformation(modifiedMessage);
for(auto stream : streams) for (auto stream : streams)
*stream << modifiedMessage << std::flush; *stream << modifiedMessage << std::flush;
} }
std::size_t found = message.find(std::string("\n")); std::size_t found = message.find(std::string("\n"));
...@@ -74,43 +58,37 @@ logging::Logger& logging::LoggerImp::log(const std::string &message) ...@@ -74,43 +58,37 @@ logging::Logger& logging::LoggerImp::log(const std::string &message)
return *this; return *this;
} }
bool logging::LoggerImp::shouldBeLogged() bool logging::LoggerImp::shouldBeLogged() { return localLogLevel <= globalLogLevel; }
{
return localLogLevel <= globalLogLevel;
}
void logging::LoggerImp::addDebugInformation(std::string& message) void logging::LoggerImp::addDebugInformation(std::string &message)
{ {
if (newLoggingLine) { if (newLoggingLine) {
std::stringstream os; std::stringstream os;
os << levelString[localLogLevel] << getTimeStamp() << " " << message; os << levelString[localLogLevel] << getTimeStamp() << " " << message;
message = os.str(); message = os.str();
} }
} }
std::string logging::LoggerImp::getTimeStamp() std::string logging::LoggerImp::getTimeStamp()
{ {
if (!timeStampEnabled) if (!timeStampEnabled)
return ""; return "";
const auto now = std::chrono::system_clock::now(); const auto now = std::chrono::system_clock::now();
time_t tt = std::chrono::system_clock::to_time_t(now); time_t tt = std::chrono::system_clock::to_time_t(now);
//const tm utc_tm = *gmtime(&tt); // const tm utc_tm = *gmtime(&tt);
const tm local_tm = *localtime(&tt); const tm local_tm = *localtime(&tt);
std::stringstream os; std::stringstream os;
os << " [" << std::setw(2) << std::setfill('0') << local_tm.tm_hour << ":"; os << " [" << std::setw(2) << std::setfill('0') << local_tm.tm_hour << ":";
os << std::setw(2) << std::setfill('0') << local_tm.tm_min << ":"; os << std::setw(2) << std::setfill('0') << local_tm.tm_min << ":";
os << std::setw(2) << std::setfill('0') << local_tm.tm_sec << "]"; os << std::setw(2) << std::setfill('0') << local_tm.tm_sec << "]";
return os.str(); return os.str();
} }
std::string logging::LoggerImp::getRankString() std::string logging::LoggerImp::getRankString()
{ {
int rank; int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
return printRankNumber ? "[" + std::to_string(rank) + "] " : ""; return printRankNumber ? "[" + std::to_string(rank) + "] " : "";
} }
#ifndef LoggerImp_H #ifndef LoggerImp_H
#define LoggerImp_H #define LoggerImp_H
#include "basics_export.h" #include "basics_export.h"
#include <string> #include <string>
...@@ -12,35 +11,33 @@ ...@@ -12,35 +11,33 @@
namespace logging namespace logging
{ {
class BASICS_EXPORT LoggerImp : public Logger class BASICS_EXPORT LoggerImp : public Logger
{ {
public: public:
LoggerImp(std::ostream* stream); LoggerImp(std::ostream *stream);
~LoggerImp() override; ~LoggerImp() override;
Logger& operator<<(const Level &level) override; Logger &operator<<(const Level &level) override;
Logger& operator<<(const std::string &message) override; Logger &operator<<(const std::string &message) override;
Logger& operator<<(const int &message) override; Logger &operator<<(const int &message) override;
Logger& operator<<(const unsigned int &message) override; Logger &operator<<(const unsigned int &message) override;
Logger& operator<<(const unsigned long& log) override; Logger &operator<<(const unsigned long &log) override;
Logger& operator<<(const float &message) override; Logger &operator<<(const float &message) override;
Logger& operator<<(const double &message) override; Logger &operator<<(const double &message) override;
private:
private: std::string getRankString();
std::string getRankString(); static bool shouldBeLogged();
static bool shouldBeLogged();
static std::string getTimeStamp();
static std::string getTimeStamp(); void addDebugInformation(std::string &message);
void addDebugInformation(std::string& message); logging::Logger &log(const std::string &message);
logging::Logger& log(const std::string &message);
private:
private: std::map<Logger::Level, std::string> levelString;
std::map<Logger::Level, std::string> levelString; bool newLoggingLine = true;
bool newLoggingLine = true; };
};
} // namespace logging
}
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment