Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
51c2329f
Commit
51c2329f
authored
May 22, 2020
by
Mark OLESEN
Browse files
ENH: additional step function, cleanup autoPtr use in Function1
parent
09d9c5cc
Changes
41
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/Make/files
View file @
51c2329f
...
...
@@ -107,6 +107,7 @@ primitives/triad/triad.C
/* Run-time selectable functions */
primitives/functions/Function1/makeFunction1s.C
primitives/functions/Function1/ramp/ramp.C
primitives/functions/Function1/step/stepFunction.C
primitives/functions/Function1/linearRamp/linearRamp.C
primitives/functions/Function1/quadraticRamp/quadraticRamp.C
primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C
...
...
src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C
View file @
51c2329f
...
...
@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -40,10 +41,10 @@ Foam::Function1<Type>::Function1(const word& entryName)
template
<
class
Type
>
Foam
::
Function1
<
Type
>::
Function1
(
const
Function1
<
Type
>&
de
)
Foam
::
Function1
<
Type
>::
Function1
(
const
Function1
<
Type
>&
rhs
)
:
refCount
(),
name_
(
de
.
name_
)
name_
(
rhs
.
name_
)
{}
...
...
@@ -65,10 +66,10 @@ template<class Type>
Type
Foam
::
Function1
<
Type
>::
value
(
const
scalar
x
)
const
{
NotImplemented
;
return
Zero
;
}
template
<
class
Type
>
Foam
::
tmp
<
Foam
::
Field
<
Type
>>
Foam
::
Function1
<
Type
>::
value
(
...
...
@@ -84,7 +85,6 @@ template<class Type>
Type
Foam
::
Function1
<
Type
>::
integrate
(
const
scalar
x1
,
const
scalar
x2
)
const
{
NotImplemented
;
return
Zero
;
}
...
...
@@ -174,13 +174,13 @@ template<class Type>
Foam
::
Ostream
&
Foam
::
operator
<<
(
Ostream
&
os
,
const
Function1
<
Type
>&
f1
const
Function1
<
Type
>&
rhs
)
{
os
.
check
(
FUNCTION_NAME
);
os
<<
f1
.
name_
;
f1
.
writeData
(
os
);
os
<<
rhs
.
name_
;
rhs
.
writeData
(
os
);
return
os
;
}
...
...
src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H
View file @
51c2329f
...
...
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018
-2020
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -33,6 +33,38 @@ Description
provide functions to return the (interpolated) value, and integral between
limits.
The New factory method attempts to deal with varying types of input.
It accepts primitive or dictionary entries for dispatching to different
function types, but wraps unspecified types as "constant".
In the dictionary form, the coefficents are the dictionary itself.
This is arguably the more readable form.
For example,
\verbatim
<entryName>
{
type linearRamp;
start 10;
duration 20;
}
\endverbatim
In the primitive form, the coefficents are provided separately.
For example,
\verbatim
<entryName> linearRamp;
<entryName>Coeffs
{
start 10;
duration 20;
}
\endverbatim
The coeffs dictionary is optional, since it is not required by all types.
For example,
\verbatim
<entryName> zero;
\endverbatim
SourceFiles
Function1.C
Function1New.C
...
...
@@ -50,10 +82,8 @@ SourceFiles
namespace
Foam
{
// Forward
d
eclarations
// Forward
D
eclarations
class
Time
;
// Forward declaration of friend functions and operators
template
<
class
Type
>
class
Function1
;
template
<
class
Type
>
Ostream
&
operator
<<
(
Ostream
&
,
const
Function1
<
Type
>&
);
...
...
@@ -66,19 +96,18 @@ class Function1
:
public
refCount
{
// Private Member Functions
//- No copy assignment
void
operator
=
(
const
Function1
<
Type
>&
)
=
delete
;
protected:
// Protected
d
ata
// Protected
D
ata
//- Name of entry
const
word
name_
;
// Protected Member Functions
//- No copy assignment
void
operator
=
(
const
Function1
<
Type
>&
)
=
delete
;
public:
...
...
@@ -107,7 +136,7 @@ public:
explicit
Function1
(
const
word
&
entryName
);
//- Copy constructor
explicit
Function1
(
const
Function1
<
Type
>&
f1
);
explicit
Function1
(
const
Function1
<
Type
>&
rhs
);
//- Construct and return a clone
virtual
tmp
<
Function1
<
Type
>>
clone
()
const
=
0
;
...
...
src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C
View file @
51c2329f
...
...
@@ -47,13 +47,6 @@ Foam::Function1Types::OneConstant<Type>::OneConstant
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template
<
class
Type
>
Foam
::
Function1Types
::
OneConstant
<
Type
>::~
OneConstant
()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class
Type
>
...
...
src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H
View file @
51c2329f
...
...
@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -68,7 +69,7 @@ class OneConstant
public:
// Runtime type information
//
-
Runtime type information
TypeName
(
"one"
);
...
...
@@ -88,7 +89,7 @@ public:
//- Destructor
virtual
~
OneConstant
();
virtual
~
OneConstant
()
=
default
;
// Member Functions
...
...
src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C
View file @
51c2329f
...
...
@@ -40,8 +40,8 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
coeffs_
(),
canIntegrate_
(
true
)
{
Istream
&
is
(
dict
.
lookup
(
entryName
)
)
;
word
entryType
(
is
);
Istream
&
is
=
dict
.
lookup
(
entryName
);
const
word
entryType
(
is
);
is
>>
coeffs_
;
...
...
@@ -121,13 +121,6 @@ Foam::Function1Types::Polynomial<Type>::Polynomial(const Polynomial& poly)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template
<
class
Type
>
Foam
::
Function1Types
::
Polynomial
<
Type
>::~
Polynomial
()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class
Type
>
...
...
src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H
View file @
51c2329f
...
...
@@ -67,7 +67,7 @@ class Polynomial
:
public
Function1
<
Type
>
{
// Private
d
ata
// Private
D
ata
//- Polynomial coefficients - list of prefactor, exponent
List
<
Tuple2
<
Type
,
Type
>>
coeffs_
;
...
...
@@ -90,13 +90,14 @@ public:
// Constructors
//- Construct from entry name and dictionary
Polynomial
(
const
word
&
entryName
,
const
dictionary
&
dict
);
//- Construct from components
Polynomial
(
const
word
&
entryName
,
const
List
<
Tuple2
<
Type
,
Type
>>&
const
List
<
Tuple2
<
Type
,
Type
>>&
coeffs
);
//- Copy constructor
...
...
@@ -104,24 +105,19 @@ public:
//- Destructor
virtual
~
Polynomial
();
virtual
~
Polynomial
()
=
default
;
// Member Functions
// Manipulation
//- Convert time
virtual
void
convertTimeBase
(
const
Time
&
t
);
//- Convert tim
e
virtual
void
convertTimeBase
(
const
Time
&
t
)
;
//- Return Polynomial valu
e
virtual
Type
value
(
const
scalar
x
)
const
;
// Evaluation
//- Return Polynomial value
virtual
Type
value
(
const
scalar
x
)
const
;
//- Integrate between two (scalar) values
virtual
Type
integrate
(
const
scalar
x1
,
const
scalar
x2
)
const
;
//- Integrate between two (scalar) values
virtual
Type
integrate
(
const
scalar
x1
,
const
scalar
x2
)
const
;
//- Write in dictionary format
...
...
src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C
View file @
51c2329f
...
...
@@ -51,18 +51,11 @@ Foam::Function1Types::Scale<Type>::Scale
template
<
class
Type
>
Foam
::
Function1Types
::
Scale
<
Type
>::
Scale
(
const
Scale
<
Type
>&
s
e
)
Foam
::
Function1Types
::
Scale
<
Type
>::
Scale
(
const
Scale
<
Type
>&
rh
s
)
:
Function1
<
Type
>
(
se
),
scale_
(
se
.
scale_
.
clone
()),
value_
(
se
.
value_
.
clone
())
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template
<
class
Type
>
Foam
::
Function1Types
::
Scale
<
Type
>::~
Scale
()
Function1
<
Type
>
(
rhs
),
scale_
(
rhs
.
scale_
.
clone
()),
value_
(
rhs
.
value_
.
clone
())
{}
...
...
src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H
View file @
51c2329f
...
...
@@ -92,7 +92,7 @@ class Scale
:
public
Function1
<
Type
>
{
// Private
d
ata
// Private
D
ata
//- Scalar scaling function
autoPtr
<
Function1
<
scalar
>>
scale_
;
...
...
@@ -112,7 +112,7 @@ class Scale
public:
// Runtime type information
//
-
Runtime type information
TypeName
(
"scale"
);
...
...
@@ -125,12 +125,12 @@ public:
const
dictionary
&
dict
);
//- Copy construct
or
explicit
Scale
(
const
Scale
<
Type
>&
s
e
);
//- Copy construct
explicit
Scale
(
const
Scale
<
Type
>&
rh
s
);
//- Destructor
virtual
~
Scale
();
virtual
~
Scale
()
=
default
;
// Member Functions
...
...
src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C
View file @
51c2329f
...
...
@@ -66,13 +66,6 @@ Foam::Function1Types::Sine<Type>::Sine(const Sine<Type>& se)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template
<
class
Type
>
Foam
::
Function1Types
::
Sine
<
Type
>::~
Sine
()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class
Type
>
...
...
src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H
View file @
51c2329f
...
...
@@ -142,7 +142,7 @@ public:
//- Destructor
virtual
~
Sine
();
virtual
~
Sine
()
=
default
;
// Member Functions
...
...
src/OpenFOAM/primitives/functions/Function1/Square/Square.C
View file @
51c2329f
...
...
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016
-2020
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -33,8 +33,8 @@ License
template
<
class
Type
>
void
Foam
::
Function1Types
::
Square
<
Type
>::
read
(
const
dictionary
&
coeffs
)
{
t0_
=
coeffs
.
lookup
OrDefault
<
scalar
>
(
"t0"
,
0
);
markSpace_
=
coeffs
.
lookup
OrDefault
<
scalar
>
(
"markSpace"
,
1
);
t0_
=
coeffs
.
get
OrDefault
<
scalar
>
(
"t0"
,
0
);
markSpace_
=
coeffs
.
get
OrDefault
<
scalar
>
(
"markSpace"
,
1
);
amplitude_
=
Function1
<
scalar
>::
New
(
"amplitude"
,
coeffs
);
frequency_
=
Function1
<
scalar
>::
New
(
"frequency"
,
coeffs
);
scale_
=
Function1
<
Type
>::
New
(
"scale"
,
coeffs
);
...
...
@@ -68,13 +68,6 @@ Foam::Function1Types::Square<Type>::Square(const Square<Type>& se)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template
<
class
Type
>
Foam
::
Function1Types
::
Square
<
Type
>::~
Square
()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class
Type
>
...
...
src/OpenFOAM/primitives/functions/Function1/Square/Square.H
View file @
51c2329f
...
...
@@ -99,7 +99,7 @@ class Square
:
public
Function1
<
Type
>
{
// Private
d
ata
// Private
D
ata
//- Start-time for the square function
scalar
t0_
;
...
...
@@ -145,11 +145,11 @@ public:
);
//- Copy constructor
explicit
Square
(
const
Square
<
Type
>&
s
e
);
explicit
Square
(
const
Square
<
Type
>&
rh
s
);
//- Destructor
virtual
~
Square
();
virtual
~
Square
()
=
default
;
// Member Functions
...
...
src/OpenFOAM/primitives/functions/Function1/Table/Table.C
View file @
51c2329f
...
...
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019
-2020
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -40,7 +40,7 @@ Foam::Function1Types::Table<Type>::Table
TableBase
<
Type
>
(
entryName
,
dict
)
{
Istream
&
is
=
dict
.
lookup
(
entryName
);
word
entryType
(
is
);
const
word
entryType
(
is
);
is
>>
this
->
table_
;
TableBase
<
Type
>::
check
();
}
...
...
src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C
View file @
51c2329f
...
...
@@ -36,11 +36,11 @@ template<class Type>
const
Foam
::
interpolationWeights
&
Foam
::
Function1Types
::
TableBase
<
Type
>::
interpolator
()
const
{
if
(
interpolatorPtr_
.
empty
()
)
if
(
!
interpolatorPtr_
)
{
// Re-work table into linear list
tableSamplesPtr_
.
reset
(
new
scalarField
(
table_
.
size
()));
scalarField
&
samples
=
*
tableSamplesPtr_
;
auto
&
samples
=
*
tableSamplesPtr_
;
forAll
(
table_
,
i
)
{
samples
[
i
]
=
table_
[
i
].
first
();
...
...
@@ -69,7 +69,7 @@ Foam::Function1Types::TableBase<Type>::TableBase
name_
(
name
),
bounding_
(
bounds
::
repeatableBoundingNames
.
lookup
OrDefault
bounds
::
repeatableBoundingNames
.
get
OrDefault
(
"outOfBounds"
,
dict
,
...
...
@@ -79,9 +79,11 @@ Foam::Function1Types::TableBase<Type>::TableBase
),
interpolationScheme_
(
dict
.
lookup
OrDefault
<
word
>
(
"interpolationScheme"
,
"linear"
)
dict
.
get
OrDefault
<
word
>
(
"interpolationScheme"
,
"linear"
)
),
table_
()
table_
(),
tableSamplesPtr_
(
nullptr
),
interpolatorPtr_
(
nullptr
)
{}
...
...
@@ -93,8 +95,8 @@ Foam::Function1Types::TableBase<Type>::TableBase(const TableBase<Type>& tbl)
bounding_
(
tbl
.
bounding_
),
interpolationScheme_
(
tbl
.
interpolationScheme_
),
table_
(
tbl
.
table_
),
tableSamplesPtr_
(
tbl
.
tableSamplesPtr_
),
interpolatorPtr_
(
tbl
.
interpolatorPtr_
)
tableSamplesPtr_
(
tbl
.
tableSamplesPtr_
.
clone
()
),
interpolatorPtr_
(
tbl
.
interpolatorPtr_
)
// steal/reuse (missing clone!)
{}
...
...
src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H
View file @
51c2329f
...
...
@@ -46,6 +46,7 @@ SourceFiles
namespace
Foam
{
// Forward Declarations
class
interpolationWeights
;
namespace
Function1Types
...
...
src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C
View file @
51c2329f
...
...
@@ -50,7 +50,8 @@ Foam::Function1Types::TableFile<Type>::TableFile
if
(
!
is
.
good
())
{
FatalIOErrorInFunction
(
is
)
<<
"Cannot open file."
<<
exit
(
FatalIOError
);
<<
"Cannot open file."
<<
nl
<<
exit
(
FatalIOError
);
}
is
>>
this
->
table_
;
...
...
src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H
View file @
51c2329f
...
...
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019
-2020
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -35,7 +35,7 @@ Description
<entryName> tableFile;
<entryName>Coeffs
{
file
Name
dataFile; // name of data file
file
dataFile; // name of data file
outOfBounds clamp; // optional out-of-bounds handling
interpolationScheme linear; // optional interpolation method
}
...
...
@@ -109,7 +109,7 @@ public:
virtual
~
TableFile
()
=
default
;
//
I/O
//
Member Functions
//- Write in dictionary format
virtual
void
writeData
(
Ostream
&
os
)
const
;
...
...
src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C
View file @
51c2329f
...
...
@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -29,6 +30,13 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
<
class
Type
>
Foam
::
Function1Types
::
ZeroConstant
<
Type
>::
ZeroConstant
(
const
word
&
entryName
)
:
Function1
<
Type
>
(
entryName
)
{}
template
<
class
Type
>
Foam
::
Function1Types
::
ZeroConstant
<
Type
>::
ZeroConstant
(
...
...
@@ -40,13 +48,6 @@ Foam::Function1Types::ZeroConstant<Type>::ZeroConstant
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template
<
class
Type
>
Foam
::
Function1Types
::
ZeroConstant
<
Type
>::~
ZeroConstant
()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class
Type
>
...
...
src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H
View file @
51c2329f
...
...
@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -68,18 +69,21 @@ class ZeroConstant
public:
// Runtime type information
//
-
Runtime type information
TypeName
(
"zero"
);
// Constructors
//- Construct from entry name
explicit
ZeroConstant
(
const
word
&
entryName
);
//- Construct from entry name and dictionary
ZeroConstant
(
const
word
&
entryName
,
const
dictionary
&
dict
);
//- Destructor
virtual
~
ZeroConstant
();
virtual
~
ZeroConstant
()
=
default
;
// Member Functions
...
...
Prev
1
2
3
Next
Andrew Heather
@andy
mentioned in commit
636d2688
·
Jun 08, 2020
mentioned in commit
636d2688
mentioned in commit 636d2688a5f6b2dc8c71bce92b26744ce09bb316
Toggle commit list
Write
Preview