BELFEM
0.9.0
Berkeley Lab Finite Element Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fn_polyval.hpp
Go to the documentation of this file.
1
/*
2
* BELFEM -- The Berkeley Lab Finite Element Framework
3
* Copyright (c) 2026, The Regents of the University of California,
4
* through Lawrence Berkeley National Laboratory (subject to receipt of any required
5
* approvals from the U.S. Dept. of Energy). All rights reserved.
6
*
7
* Developers: Christian Messe, Gregory Giard
8
*
9
* See the top-level LICENSE file for the complete license and disclaimer.
10
*/
11
23
24
#ifndef BELFEM_FN_POLYVAL_HPP
25
#define BELFEM_FN_POLYVAL_HPP
26
27
#ifdef BELFEM_ARMADILLO
28
#include "
armadillo.hpp
"
29
#endif
30
31
#include "
typedefs.hpp
"
32
#include "assert.h"
33
#include "
cl_Vector.hpp
"
34
35
namespace
belfem
36
{
37
38
//------------------------------------------------------------------------------
39
47
template
<
typename
T >
48
T
49
polyval
(
const
Vector< T >
& aCoeffs,
const
T aX )
50
{
51
const
index_t
tN = aCoeffs.
length
();
52
T aResult = aCoeffs( 0 );
53
54
for
(
index_t
k=1; k<tN; ++k )
55
{
56
aResult *= aX;
57
aResult += aCoeffs( k );
58
}
59
60
return
aResult;
61
}
62
63
//------------------------------------------------------------------------------
64
65
66
template
<
typename
T >
67
void
68
polyval
(
const
Vector< T >
& aCoeffs,
const
Vector< T >
& aX,
Vector< T >
& aY )
69
{
70
#ifdef BELFEM_ARMADILLO
71
aY.
vector_data
() = arma::polyval( aCoeffs.
vector_data
(), aX.
vector_data
() );
72
#elif BELFEM_BLAZE
73
index_t
tN = aX.
length
();
74
aY.
set_size
( tN );
75
76
if
( aCoeffs.
length
() == 0 )
77
{
78
aY.
vector_data
() = 0;
79
return
;
80
}
81
82
// Initialize with highest order coefficient
83
aY.
vector_data
() = aCoeffs(0);
84
85
// Horner's method with vectorized operations
86
for
(
index_t
i = 1; i < aCoeffs.
length
(); ++i )
87
{
88
aY.
vector_data
() = aY.
vector_data
() * aX.
vector_data
() + aCoeffs(i);
89
}
90
#else
91
index_t
tN = aX.
vector_data
();
92
aY.
set_size
( tN );
93
for
(
uint
k=0; k<tN; ++k )
94
{
95
aY( k ) =
polyval
( aCoeffs, aX( k ) );
96
}
97
#endif
98
}
99
100
101
102
//------------------------------------------------------------------------------
103
}
104
#endif
//BELFEM_FN_POLYVAL_HPP
armadillo.hpp
cl_Vector.hpp
belfem::Vector
Column vector.
Definition
cl_BZ_Vector.hpp:41
belfem::Vector::set_size
void set_size(const size_t aNumRows)
change the size of the vector
Definition
cl_AR_Vector.hpp:237
belfem::Vector::length
size_t length() const
get the length of the vector
Definition
cl_AR_Vector.hpp:257
belfem::Vector::vector_data
VectorType & vector_data()
expose the underlying matrix implementation ( writable version )
Definition
cl_AR_Vector.hpp:204
belfem::polyval
T polyval(const Vector< T > &aCoeffs, const T aX)
Evaluates a polynomial at one point, by Horner's scheme.
Definition
fn_polyval.hpp:49
belfem
USER GUIDES:
Definition
cl_Capacitor.cpp:16
belfem::MaterialDependency::T
@ T
Definition
cl_Material.hpp:122
belfem::uint
unsigned int uint
Definition
typedefs.hpp:30
belfem::index_t
uint32_t index_t
Definition
typedefs.hpp:52
typedefs.hpp
src
linalg
fn_polyval.hpp
Generated by
1.18.0