ENH: add DeprecatedInFunction macro

- run-time warning about deprecated features. For example,

  DeprecatedInFunction(2212)
     << "Prefer using xyz boundary condition. "
     << "This boundary condition will be removed in the future." << endl;

CONFIG: mark exprFixedValue as deprecated

- same functionality is possible with uniformFixedValue and an
  expression PatchFunction1, which can also be easily changed to any
  other PatchFunction1
This commit is contained in:
Mark Olesen 2023-02-20 09:48:58 +01:00
parent c038a9447c
commit 446aff1350
4 changed files with 85 additions and 13 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,6 +31,7 @@ Note
#include "error.H" #include "error.H"
#include "dictionary.H" #include "dictionary.H"
#include "foamVersion.H"
#include "Pstream.H" #include "Pstream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -167,7 +168,7 @@ std::ostream& Foam::messageStream::stdStream()
Foam::OSstream& Foam::messageStream::operator() Foam::OSstream& Foam::messageStream::operator()
( (
const string& functionName const std::string& functionName
) )
{ {
OSstream& os = this->stream(); OSstream& os = this->stream();
@ -182,6 +183,57 @@ Foam::OSstream& Foam::messageStream::operator()
} }
Foam::OSstream& Foam::messageStream::deprecated
(
const int afterVersion,
const char* functionName,
const char* sourceFileName,
const int sourceFileLineNumber
)
{
OSstream& os = this->stream();
// No warning for 0 (unversioned) or -ve values (silent versioning).
// Also no warning for (version >= foamVersion::api), which
// can be used to denote future expiry dates of transition features.
if (afterVersion > 0 && afterVersion < foamVersion::api)
{
const int months =
(
// YYMM -> months
(12 * (foamVersion::api/100) + (foamVersion::api % 100))
- (12 * (afterVersion/100) + (afterVersion % 100))
);
os << nl
<< ">>> DEPRECATED after version " << afterVersion;
if (afterVersion < 1000)
{
// Predates YYMM versioning (eg, 240 for version 2.4)
os << ". This is very old! <<<" << nl;
}
else
{
os << ". This is about " << months << " months old. <<<" << nl;
}
}
os << nl;
if (functionName) // nullptr check
{
os << " From " << functionName << nl
<< " in file " << sourceFileName
<< " at line " << sourceFileLineNumber << nl;
}
os << " ";
return os;
}
Foam::OSstream& Foam::messageStream::operator() Foam::OSstream& Foam::messageStream::operator()
( (
const char* functionName, const char* functionName,
@ -194,7 +246,7 @@ Foam::OSstream& Foam::messageStream::operator()
os << nl os << nl
<< " From " << functionName << nl << " From " << functionName << nl
<< " in file " << sourceFileName << " in file " << sourceFileName
<< " at line " << sourceFileLineNumber << endl << " at line " << sourceFileLineNumber << nl
<< " "; << " ";
return os; return os;
@ -203,7 +255,7 @@ Foam::OSstream& Foam::messageStream::operator()
Foam::OSstream& Foam::messageStream::operator() Foam::OSstream& Foam::messageStream::operator()
( (
const string& functionName, const std::string& functionName,
const char* sourceFileName, const char* sourceFileName,
const int sourceFileLineNumber const int sourceFileLineNumber
) )
@ -222,7 +274,7 @@ Foam::OSstream& Foam::messageStream::operator()
const char* functionName, const char* functionName,
const char* sourceFileName, const char* sourceFileName,
const int sourceFileLineNumber, const int sourceFileLineNumber,
const string& ioFileName, const std::string& ioFileName,
const label ioStartLineNumber, const label ioStartLineNumber,
const label ioEndLineNumber const label ioEndLineNumber
) )
@ -233,7 +285,7 @@ Foam::OSstream& Foam::messageStream::operator()
<< " From " << functionName << nl << " From " << functionName << nl
<< " in file " << sourceFileName << " in file " << sourceFileName
<< " at line " << sourceFileLineNumber << nl << " at line " << sourceFileLineNumber << nl
<< " Reading " << ioFileName; << " Reading \"" << ioFileName.c_str() << '"';
if (ioStartLineNumber >= 0) if (ioStartLineNumber >= 0)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -54,7 +54,8 @@ SourceFiles
#define Foam_messageStream_H #define Foam_messageStream_H
#include "label.H" #include "label.H"
#include "string.H" #include "word.H"
#include <string>
#include <iostream> #include <iostream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -170,6 +171,17 @@ public:
//- Return std::ostream for output operations. //- Return std::ostream for output operations.
std::ostream& stdStream(); std::ostream& stdStream();
//- Report deprecation (after specified API version) with
//- 'From function-name, source file, line number'.
// \return OSstream for further operations
OSstream& deprecated
(
const int afterVersion,
const char* functionName,
const char* sourceFileName,
const int sourceFileLineNumber = 0
);
//- Implicit cast to OSstream for << operations //- Implicit cast to OSstream for << operations
operator OSstream&() operator OSstream&()
{ {
@ -186,11 +198,10 @@ public:
// \return OSstream for further operations // \return OSstream for further operations
OSstream& operator() OSstream& operator()
( (
const string& functionName const std::string& functionName
); );
//- Report 'From function-name, source file, line number' //- Report 'From function-name, source file, line number'
//- Print basic message
// \return OSstream for further operations // \return OSstream for further operations
OSstream& operator() OSstream& operator()
( (
@ -203,7 +214,7 @@ public:
// \return OSstream for further operations // \return OSstream for further operations
OSstream& operator() OSstream& operator()
( (
const string& functionName, const std::string& functionName,
const char* sourceFileName, const char* sourceFileName,
const int sourceFileLineNumber = 0 const int sourceFileLineNumber = 0
); );
@ -216,7 +227,7 @@ public:
const char* functionName, const char* functionName,
const char* sourceFileName, const char* sourceFileName,
const int sourceFileLineNumber, const int sourceFileLineNumber,
const string& ioFileName, const std::string& ioFileName,
const label ioStartLineNumber = -1, const label ioStartLineNumber = -1,
const label ioEndLineNumber = -1 const label ioEndLineNumber = -1
); );
@ -328,6 +339,11 @@ extern messageStream SeriousError;
// for FUNCTION_NAME in file __FILE__ at line __LINE__ // for FUNCTION_NAME in file __FILE__ at line __LINE__
#define WarningInFunction WarningIn(FUNCTION_NAME) #define WarningInFunction WarningIn(FUNCTION_NAME)
//- Report a warning using Foam::Warning
// for FUNCTION_NAME in file __FILE__ at line __LINE__
#define DeprecatedInFunction(afterVersion) \
::Foam::Warning.deprecated(afterVersion, FUNCTION_NAME, __FILE__, __LINE__)
//- Report an IO warning using Foam::Warning //- Report an IO warning using Foam::Warning
// for functionName in file __FILE__ at line __LINE__ // for functionName in file __FILE__ at line __LINE__

View File

@ -107,6 +107,10 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
), ),
driver_(this->patch(), dict_) driver_(this->patch(), dict_)
{ {
DeprecatedInFunction(2212)
<< "Use uniformFixedValue with an expression Function1 instead." << nl
<< " This boundary condition will be removed in the future" << endl;
setDebug(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;

View File

@ -26,7 +26,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "genericPatchFieldBase.H" #include "genericPatchFieldBase.H"
#include "messageStream.H" #include "error.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //