Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
1593d3c3
Commit
1593d3c3
authored
15 years ago
by
Andrew Heather
Browse files
Options
Downloads
Patches
Plain Diff
adding support for polynomials starting at order -1
parent
0b1cf425
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C
+78
-15
78 additions, 15 deletions
src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C
src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H
+20
-2
20 additions, 2 deletions
src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H
with
98 additions
and
17 deletions
src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C
+
78
−
15
View file @
1593d3c3
...
...
@@ -25,7 +25,6 @@ License
\*---------------------------------------------------------------------------*/
#include
"Polynomial.H"
#include
"error.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
...
...
@@ -33,7 +32,9 @@ template<int PolySize>
Foam
::
Polynomial
<
PolySize
>::
Polynomial
()
:
VectorSpace
<
Polynomial
<
PolySize
>
,
scalar
,
PolySize
>
(),
name_
(
"unknownPolynomialName"
)
name_
(
"unknownPolynomialName"
),
logActive_
(
false
),
logCoeff_
(
0
.
0
)
{}
...
...
@@ -41,25 +42,27 @@ template<int PolySize>
Foam
::
Polynomial
<
PolySize
>::
Polynomial
(
const
word
&
name
,
Istream
&
is
)
:
VectorSpace
<
Polynomial
<
PolySize
>
,
scalar
,
PolySize
>
(),
name_
(
is
)
name_
(
is
),
logActive_
(
false
),
logCoeff_
(
0
.
0
)
{
if
(
name_
!=
name
)
{
FatalErrorIn
(
"
Foam::
Polynomial<PolySize>::Polynomial(const word&, Istream&)"
"Polynomial<PolySize>::Polynomial(const word&, Istream&)"
)
<<
"Expected polynomial name "
<<
name
<<
" but read "
<<
name_
<<
nl
<<
exit
(
FatalError
);
}
VectorSpace
<
Polynomial
<
PolySize
>
,
scalar
,
PolySize
>::
operator
=
(
polyType
(
is
));
operator
=
(
VectorSpace
<
Polynomial
<
PolySize
>
,
scalar
,
PolySize
>
(
is
));
if
(
this
->
size
()
==
0
)
{
FatalErrorIn
(
"
Foam::
Polynomial<PolySize>::Polynomial(const word&, Istream&)"
"Polynomial<PolySize>::Polynomial(const word&, Istream&)"
)
<<
"Polynomial coefficients for entry "
<<
name_
<<
" are invalid (empty)"
<<
nl
<<
exit
(
FatalError
);
}
...
...
@@ -70,7 +73,9 @@ template<int PolySize>
Foam
::
Polynomial
<
PolySize
>::
Polynomial
(
const
Polynomial
<
PolySize
>&
poly
)
:
VectorSpace
<
Polynomial
<
PolySize
>
,
scalar
,
PolySize
>
(
poly
),
name_
(
poly
.
name_
)
name_
(
poly
.
name_
),
logActive_
(
poly
.
logActive_
),
logCoeff_
(
poly
.
logCoeff_
)
{}
...
...
@@ -82,7 +87,9 @@ Foam::Polynomial<PolySize>::Polynomial
)
:
VectorSpace
<
Polynomial
<
PolySize
>
,
scalar
,
PolySize
>
(
poly
),
name_
(
name
)
name_
(
name
),
logActive_
(
poly
.
logActive_
),
logCoeff_
(
poly
.
logCoeff_
)
{}
...
...
@@ -102,15 +109,35 @@ const Foam::word& Foam::Polynomial<PolySize>::name() const
}
template
<
int
PolySize
>
bool
&
Foam
::
Polynomial
<
PolySize
>::
logActive
()
{
return
logActive_
;
}
template
<
int
PolySize
>
Foam
::
scalar
&
Foam
::
Polynomial
<
PolySize
>::
logCoeff
()
{
return
logCoeff_
;
}
template
<
int
PolySize
>
Foam
::
scalar
Foam
::
Polynomial
<
PolySize
>::
evaluate
(
const
scalar
x
)
const
{
scalar
y
=
0
.
0
;
forAll
(
*
this
,
i
)
scalar
y
=
this
->
v_
[
0
];
for
(
label
i
=
1
;
i
<
PolySize
;
i
++
)
{
y
+=
this
->
v_
[
i
]
*
pow
(
x
,
i
);
}
if
(
logActive_
)
{
y
+=
logCoeff_
*
log
(
x
);
}
return
y
;
}
...
...
@@ -122,14 +149,22 @@ Foam::scalar Foam::Polynomial<PolySize>::integrateLimits
const
scalar
x2
)
const
{
scalar
intx
=
0
.
0
;
forAll
(
*
this
,
i
)
if
(
logActive_
)
{
intx
+=
this
->
v_
[
i
]
/
(
i
+
1
)
*
(
pow
(
x2
,
i
+
1
)
-
pow
(
x1
,
i
+
1
));
FatalErrorIn
(
"scalar Polynomial<PolySize>::integrateLimits"
"("
"const scalar, "
"const scalar"
") const"
)
<<
"Cannot integrate polynomial with logarithmic coefficients"
<<
nl
<<
abort
(
FatalError
);
}
return
intx
;
intPolyType
poly
=
this
->
integrate
();
return
poly
.
evaluate
(
x2
)
-
poly
.
evaluate
(
x1
);
}
...
...
@@ -149,6 +184,32 @@ Foam::Polynomial<PolySize>::integrate(const scalar intConstant)
}
template
<
int
PolySize
>
typename
Foam
::
Polynomial
<
PolySize
>::
polyType
Foam
::
Polynomial
<
PolySize
>::
integrateMinus1
(
const
scalar
intConstant
)
{
polyType
newCoeffs
;
if
(
this
->
v_
[
0
]
>
VSMALL
)
{
newCoeffs
.
logActive
()
=
true
;
newCoeffs
.
logCoeff
()
=
this
->
v_
[
0
];
}
newCoeffs
[
0
]
=
intConstant
;
if
(
PolySize
>
0
)
{
for
(
label
i
=
1
;
i
<
PolySize
;
i
++
)
{
newCoeffs
[
i
]
=
this
->
v_
[
i
]
/
i
;
}
}
return
newCoeffs
;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template
<
int
PolySize
>
...
...
@@ -156,6 +217,8 @@ void Foam::Polynomial<PolySize>::operator=(const Polynomial<PolySize>& poly)
{
name_
=
poly
.
name_
;
VectorSpace
<
Polynomial
<
PolySize
>
,
scalar
,
PolySize
>::
operator
=
(
poly
);
logActive_
=
poly
.
logActive_
;
logCoeff_
=
poly
.
logCoeff_
;
}
...
...
This diff is collapsed.
Click to expand it.
src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H
+
20
−
2
View file @
1593d3c3
...
...
@@ -28,7 +28,7 @@ Class
Description
Polynomial templated on size (order):
poly = sum(coeff_[i]*x^i)
poly =
logCoeff*log(x) +
sum(coeff_[i]*x^i)
where 0 <= i <= n
...
...
@@ -37,6 +37,8 @@ Description
- integrate(x1, x2) between two scalar values
- integrate() to return a new, intergated coeff polynomial
- increases the size (order)
- integrateMinus1() to return a new, integrated coeff polynomial where
the base poly starts at order -1
SourceFiles
Polynomial.C
...
...
@@ -86,10 +88,16 @@ private:
//- Polynomial name
word
name_
;
//- Include the log term? - only activated using integrateMinus1()
bool
logActive_
;
//- Log coefficient - only activated using integrateMinus1()
scalar
logCoeff_
;
public:
typedef
VectorSpace
<
Polynomial
<
PolySize
>
,
scalar
,
PolySize
>
polyType
;
typedef
Polynomial
<
PolySize
>
polyType
;
typedef
Polynomial
<
PolySize
+
1
>
intPolyType
;
...
...
@@ -123,6 +131,12 @@ public:
//- Return const access to the polynomial name
const
word
&
name
()
const
;
//- Return access to the log term active flag
bool
&
logActive
();
//- Return access to the log coefficient
scalar
&
logCoeff
();
// Evaluation
...
...
@@ -133,6 +147,10 @@ public:
// argument becomes zeroth element (constant of integration)
intPolyType
integrate
(
const
scalar
intConstant
=
0.0
);
//- Return integrated polynomial coefficients when lowest order
// is -1. Argument added to zeroth element
polyType
integrateMinus1
(
const
scalar
intConstant
=
0.0
);
//- Integrate between two values
scalar
integrateLimits
(
const
scalar
x1
,
const
scalar
x2
)
const
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment