BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
fn_quadratic_gradient.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
12#ifndef BELFEM_FN_QUADRATIC_GRADIENT_HPP
13#define BELFEM_FN_QUADRATIC_GRADIENT_HPP
14
15#include "typedefs.hpp"
16#include "cl_Vector.hpp"
17#include "assert.hpp"
18
19namespace belfem
20{
29 template < typename T >
30 T
32 const Vector< T > & aF,
33 const Vector< T > & aX,
34 const index_t aIndex=1 )
35 {
36 BELFEM_ASSERT( aX.length() == aF.length(), "Lengths do not match" );
37 BELFEM_ASSERT( aIndex < aF.length(), "Invalid Index" );
38
39 index_t n = aX.length();
40
41 if( aIndex == 0 )
42 {
43 return ( aF( 0 ) - aF( 1 ) ) / ( aX( 0 ) - aX( 1 ) )
44 + ( aF( 0 ) - aF( 2 ) ) / ( aX( 0 ) - aX( 2 ) )
45 + ( aF( 2 ) - aF( 1 ) ) / ( aX( 1 ) - aX( 2 ) );
46 }
47 else if ( aIndex == aX.length() - 1 )
48 {
49 return ( aF( n - 2 ) - aF( n - 3 ) ) / ( aX( n - 3 ) - aX( n - 2 ) )
50 + ( aF( n - 3 ) - aF( n - 1 ) ) / ( aX( n - 3 ) - aX( n - 1 ) )
51 + ( aF( n - 2 ) - aF( n - 1 ) ) / ( aX( n - 2 ) - aX( n - 1 ) );
52 }
53 else
54 {
55 return ( aF( aIndex - 1 ) - aF( aIndex ) )/( aX( aIndex-1 ) - aX( aIndex ) )
56 + ( aF( aIndex + 1 ) - aF( aIndex - 1 ) )/( aX( aIndex-1 ) - aX( aIndex + 1 ) )
57 + ( aF( aIndex ) - aF( aIndex + 1 ) )/( aX( aIndex ) - aX( aIndex + 1 ) );
58 }
59
60 }
61
62}
63#endif //BELFEM_FN_QUADRATIC_GRADIENT_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Column vector.
Definition cl_BZ_Vector.hpp:41
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:257
USER GUIDES:
Definition cl_Capacitor.cpp:16
@ T
Definition cl_Material.hpp:122
T quadratic_gradient(const Vector< T > &aF, const Vector< T > &aX, const index_t aIndex=1)
compute the derivative of F to X at index
Definition fn_quadratic_gradient.hpp:31
uint32_t index_t
Definition typedefs.hpp:52