ENH: use factory Clone method for handling member clone() methods

- reduces code clutter, simplifies modification for new types.
  Handled classes:

    Function1, PatchFunction1, coordinateRotation, coordinateSystem,
    particle, liquidProperties, solidProperties
This commit is contained in:
Mark Olesen
2024-01-08 11:30:58 +01:00
committed by Andrew Heather
parent 39e054b0b8
commit 987dbe4589
110 changed files with 543 additions and 570 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -140,10 +140,10 @@ public:
//- Copy construct
explicit CSV(const CSV<Type>& csv);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new CSV<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -84,8 +84,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_CodedFunction1_H
#define Function1Types_CodedFunction1_H
#ifndef Foam_Function1Types_CodedFunction1_H
#define Foam_Function1Types_CodedFunction1_H
#include "Function1.H"
#include "codedBase.H"
@ -184,10 +184,10 @@ public:
//- Copy construct
explicit CodedFunction1(const CodedFunction1<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new CodedFunction1<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -53,8 +53,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_Constant_H
#define Function1Types_Constant_H
#ifndef Foam_Function1Types_Constant_H
#define Foam_Function1Types_Constant_H
#include "Function1.H"
@ -118,10 +118,10 @@ public:
//- Copy constructor
explicit Constant(const Constant<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Constant<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2022 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -96,8 +96,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_Cosine_H
#define Function1Types_Cosine_H
#ifndef Foam_Function1Types_Cosine_H
#define Foam_Function1Types_Cosine_H
#include "Sine.H"
@ -148,10 +148,10 @@ public:
Sine<Type>(rhs)
{}
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Cosine<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -134,17 +134,6 @@ Foam::FieldFunction1<Function1Type>::FieldFunction1
{}
template<class Function1Type>
Foam::tmp<Foam::Function1<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::clone() const
{
return tmp<Function1<Type>>
(
new FieldFunction1<Function1Type>(*this)
);
}
template<class Function1Type>
Foam::tmp<Foam::Field<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::integrate

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2023 OpenCFD Ltd.
Copyright (C) 2018-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -164,11 +164,18 @@ public:
//- Copy construct
explicit Function1(const Function1<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const = 0;
// Selectors
// Factory Methods
//- Clone a Function1
template<class Derived>
static tmp<Function1<Type>> Clone(const Derived& fun)
{
return tmp<Function1<Type>>(new Derived(fun));
}
//- Selector, with fallback redirection
static autoPtr<Function1<Type>> New
@ -321,8 +328,11 @@ public:
const objectRegistry* obrPtr = nullptr
);
//- Construct and return a clone
virtual tmp<Function1<Type>> clone() const;
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return Function1<Type>::Clone(*this);
}
//- Destructor

View File

@ -25,8 +25,8 @@ License
\*---------------------------------------------------------------------------*/
#ifndef Function1Fwd_H
#define Function1Fwd_H
#ifndef Foam_Function1Fwd_H
#define Foam_Function1Fwd_H
#include "Function1.H"
#include "vector.H"

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -58,8 +58,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_FunctionObjectTrigger_H
#define Function1Types_FunctionObjectTrigger_H
#ifndef Foam_Function1Types_FunctionObjectTrigger_H
#define Foam_Function1Types_FunctionObjectTrigger_H
#include "Function1.H"
#include "labelList.H"
@ -80,7 +80,6 @@ class FunctionObjectTrigger
:
public Function1<Type>
{
// Private Data
//- Trigger indices when it is considered active
@ -124,10 +123,10 @@ public:
//- Copy construct
explicit FunctionObjectTrigger(const FunctionObjectTrigger<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new FunctionObjectTrigger<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -49,8 +49,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_FunctionObjectValue_H
#define Function1Types_FunctionObjectValue_H
#ifndef Foam_Function1Types_FunctionObjectValue_H
#define Foam_Function1Types_FunctionObjectValue_H
#include "Function1.H"
@ -116,10 +116,10 @@ public:
//- Copy construct
explicit FunctionObjectValue(const FunctionObjectValue<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new FunctionObjectValue<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -104,8 +104,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_InputValueMapper_H
#define Function1Types_InputValueMapper_H
#ifndef Foam_Function1Types_InputValueMapper_H
#define Foam_Function1Types_InputValueMapper_H
#include "Function1.H"
#include "Enum.H"
@ -201,10 +201,10 @@ public:
//- Copy construct
explicit InputValueMapper(const InputValueMapper<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new InputValueMapper<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021-2022 OpenCFD Ltd.
Copyright (C) 2021-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -86,10 +86,10 @@ public:
const objectRegistry* obrPtr = nullptr
);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new None<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,8 +40,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_OneConstant_H
#define Function1Types_OneConstant_H
#ifndef Foam_Function1Types_OneConstant_H
#define Foam_Function1Types_OneConstant_H
#include "Function1.H"
@ -93,10 +93,10 @@ public:
const objectRegistry* obrPtr = nullptr
);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new OneConstant<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,8 +59,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_Polynomial_H
#define Function1Types_Polynomial_H
#ifndef Foam_Function1Types_Polynomial_H
#define Foam_Function1Types_Polynomial_H
#include "Function1.H"
#include "Tuple2.H"
@ -127,10 +127,10 @@ public:
//- Copy constructor
explicit Polynomial(const Polynomial& poly);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Polynomial<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -72,8 +72,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_Scale_H
#define Function1Types_Scale_H
#ifndef Foam_Function1Types_Scale_H
#define Foam_Function1Types_Scale_H
#include "Function1.H"
@ -133,10 +133,10 @@ public:
//- Copy construct
explicit Scale(const Scale<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Scale<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -98,8 +98,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_Sine_H
#define Function1Types_Sine_H
#ifndef Foam_Function1Types_Sine_H
#define Foam_Function1Types_Sine_H
#include "Function1.H"
@ -192,10 +192,10 @@ public:
//- Copy construct
explicit Sine(const Sine<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Sine<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -101,8 +101,8 @@ Note
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_Square_H
#define Function1Types_Square_H
#ifndef Foam_Function1Types_Square_H
#define Foam_Function1Types_Square_H
#include "Sine.H"
@ -155,10 +155,10 @@ public:
//- Copy construct
explicit Square(const Square<Type>& rhs);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Square<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -79,8 +79,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_Table_H
#define Function1Types_Table_H
#ifndef Foam_Function1Types_Table_H
#define Foam_Function1Types_Table_H
#include "TableBase.H"
@ -130,10 +130,10 @@ public:
//- Copy construct
explicit Table(const Table<Type>& tbl);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Table<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,8 +59,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_TableFile_H
#define Function1Types_TableFile_H
#ifndef Foam_Function1Types_TableFile_H
#define Foam_Function1Types_TableFile_H
#include "TableBase.H"
@ -111,10 +111,10 @@ public:
//- Copy construct
explicit TableFile(const TableFile<Type>& tbl);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new TableFile<Type>(*this));
return Function1<Type>::Clone(*this);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,8 +40,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_Uniform_H
#define Function1Types_Uniform_H
#ifndef Foam_Function1Types_Uniform_H
#define Foam_Function1Types_Uniform_H
#include "Constant.H"
@ -89,10 +89,10 @@ public:
Constant<Type>(entryName, dict, obrPtr)
{}
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new Uniform<Type>(*this));
return Function1<Type>::Clone(*this);
}
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -49,8 +49,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Function1Types_ZeroConstant_H
#define Function1Types_ZeroConstant_H
#ifndef Foam_Function1Types_ZeroConstant_H
#define Foam_Function1Types_ZeroConstant_H
#include "Function1.H"
@ -102,10 +102,10 @@ public:
const objectRegistry* obrPtr = nullptr
);
//- Construct and return a clone
//- Return a clone
virtual tmp<Function1<Type>> clone() const
{
return tmp<Function1<Type>>(new ZeroConstant<Type>(*this));
return Function1<Type>::Clone(*this);
}