From 6ce400c7e2fd13d58c452bf963de0659a7f65ffb Mon Sep 17 00:00:00 2001 From: "J.A. de Jong @ vulgaris" Date: Sun, 13 Nov 2016 15:56:35 +0100 Subject: [PATCH] Added constants, assert --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- src/tasmet_assert.cpp | 22 ++++++++++ src/tasmet_assert.h | 37 ++++++++++++++++ src/tasmet_constants.h | 97 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 src/tasmet_assert.cpp create mode 100644 src/tasmet_assert.h create mode 100644 src/tasmet_constants.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cdf38a..fddf7b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ add_definitions(-DTRACER=1) # add_definitions(-DTRACER_IN_COMMON) add_definitions(-DTASMET_FLOAT=64) - +add_definitions(-DTASMET_DEBUG=1) #==================================================== # Compiler settings ************************************************ #==================================================== diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 267f32f..f8d7204 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,7 +32,7 @@ add_subdirectory(material) # add_subdirectory(sys) # add_subdirectory(var) -add_library(tasmet_src tasmet_tracer.cpp tasmet_exception.cpp) +add_library(tasmet_src tasmet_tracer.cpp tasmet_exception.cpp tasmet_assert.cpp) target_link_libraries(tasmet_src # duct # mech diff --git a/src/tasmet_assert.cpp b/src/tasmet_assert.cpp new file mode 100644 index 0000000..0a0c524 --- /dev/null +++ b/src/tasmet_assert.cpp @@ -0,0 +1,22 @@ +// tasmet_assert.cpp +// +// last-edit-by: J.A. de Jong +// +// Description: +// +////////////////////////////////////////////////////////////////////// + +#include "tasmet_assert.h" + +#if TASMET_DEBUG == 1 +#include + +void tasmet_assertfailed(const char* filename,size_t linenr,const char* statement) { + cout << "ASSERT: file " << filename << ", line " << linenr <<". " << statement << endl; + assert(false); +} +#endif + + + +////////////////////////////////////////////////////////////////////// diff --git a/src/tasmet_assert.h b/src/tasmet_assert.h new file mode 100644 index 0000000..3b208c9 --- /dev/null +++ b/src/tasmet_assert.h @@ -0,0 +1,37 @@ +// tasmet_assert.h +// +// Author: J.A. de Jong +// +// Description: +// Implementation of asserts +////////////////////////////////////////////////////////////////////// +#pragma once +#ifndef TASMET_ASSERT_H +#define TASMET_ASSERT_H + +#ifndef TASMET_DEBUG +#include +static_assert(false, "TASMET_DEBUG macro not defined. Please set it to 1 or 0"); +#endif + +#if TASMET_DEBUG == 1 +#include +#include "tasmet_io.h" + +void tasmet_assertfailed(const char* filename,size_t linenr,const char* statement); + +#define tasmet_assert(assertion,txt) \ + if (!(assertion)) \ + { \ + tasmet_assertfailed(__FILE__, __LINE__, txt ); \ + } \ + } \ + +#else +#define tasmet_assert(assertion,txt) +#endif + + + +#endif // TASMET_ASSERT_H +////////////////////////////////////////////////////////////////////// diff --git a/src/tasmet_constants.h b/src/tasmet_constants.h new file mode 100644 index 0000000..403dd12 --- /dev/null +++ b/src/tasmet_constants.h @@ -0,0 +1,97 @@ +// constants.h +// +// Author: J.A. de Jong +// +// Description: +// Definition of important constants +////////////////////////////////////////////////////////////////////// +#pragma once +#ifndef CONSTANTS_H +#define CONSTANTS_H +#include "tasmet_enum.h" +#include "tasmet_types.h" + +template +T max(T t1,T t2) { return t1>t2?t1:t2;} +template +T min(T t1,T t2) { return t1>t2?t2:t1;} + +// Variables and their names +// Unfortunately to let the code compile with Swig v 2.0, strongly +// typed enums are not supported. Therefore this is a normal +// enumerated type and not an enum class. +DECLARE_ENUM(Varnr, + none, // None + rho, // Density + m, // Mass flow (rho*U) + T, // Temperature + p, // Pressure + Ts, // Temperature of the solid + Tw, // Temperature of the solid wall + mH, // Enthalpy flow (Watts) + U, // Volume flow (m^3/s) + u, // Velocity (U/Sf) + mu, // Momentum flux + Q, // Heat flow + Qs, // Solid heat Flow + F, // A mechanical domain force [N] + x, // A mechanical displacement [m] + Z, // A mechanical impedance [N/m] + mEkin // Kinetic energy flow (Watts) + ); + +DECLARE_ENUM(Pos,left=0,right=1); + +DECLARE_ENUM(EqType, + Con, // Continuity + Mom, // Momentum + Ene, // Energy-like equation + Ise, // Isentropic + Sta, // State + Sol, // SolidEnergy + SolTwEq, // Solid wall temperature equation + Mu_is_m_u, // momentumflow is massflow_squared div + // density*cs_area + BcEqP, + BcEqu, + BcEqStateBc + ); + + + +namespace constants { + + typedef unsigned us; + + const us mingp=4; // Minimum number of gridpoints + const us maxgp=3000; // Maximum number of gridpoints + + const us maxNf=100; // Maximum number of frequencies + const d minomg=1e-3; // Minimal oscillation frequency + const d maxomg=1e5; + + const int maxsegs=30; // Maximum number of segments in a TaSystem + const int maxndofs=600000; // Maximum number of DOFS + + const d minp=1e0; + const d maxp=1e7; + const d minT=2; // Minimal temperature + const d maxT=2000; // Maximal temperature + + const d p0=101325; // Reference pressure [Pa] + const d T0=293.15; // Reference temperature [K] + + // These variable numbers are important, as they determine the + // position of these variables in the array in cell.h + // const int rho=1; + // const int m=2; + // const int T=3; + // const int p=4; + // const int Ts=5; + // Number of variables + const int nvars_reserve=7; + const int neqs_reserve=7; + +} // namespace constants + +#endif // CONSTANTS_H