BELFEM 0.9.3
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
fn_find_interval.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_FIND_INTERVAL_HPP
13#define BELFEM_FN_FIND_INTERVAL_HPP
14
15#include "typedefs.hpp"
16#include "cl_Vector.hpp"
17
18namespace belfem
19{
20//------------------------------------------------------------------------------
21
22 inline void
23 find_interval( const Vector< real > & aData, const real aValue, index_t & aIndex, real & aXi )
24 {
25 index_t i = 0;
26 index_t k = aData.length() - 1;
27 index_t j = ( i + k ) / 2 ;
28
29 if( aValue <= aData( 1 ) )
30 {
31 aIndex = 0;
32
33 aXi = ( aValue - aData( 0 ) ) / ( aData( 1 ) - aData( 0 ) );
34 }
35 else if ( aValue >= aData( k - 1 ) )
36 {
37 aIndex = k - 1;
38 aXi = ( aValue - aData( k-1 ) ) / ( aData( k ) - aData( k - 1 ) ) ;
39 }
40 else
41 {
42 while ( true )
43 {
44 if (( aData( i ) <= aValue ) && ( aData( j ) >= aValue ))
45 {
46 // this is the correct interval
47 k = j;
48 }
49 else
50 {
51 // the other one is the correct interval
52 i = j;
53 }
54 if (( k - i ) == 1 )
55 {
56 aIndex = i;
57 aXi = ( aValue - aData( i ) ) / ( aData( k ) - aData( i ) );
58 break;
59 }
60 else
61 {
62 j = ( i + k ) / 2 + ( i + k ) % 2;
63 }
64
65 }
66 }
67 }
68
69//------------------------------------------------------------------------------
70}
71
72#endif //BELFEM_FN_FIND_INTERVAL_HPP
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:235
USER GUIDES:
Definition cl_Capacitor.cpp:16
uint32_t index_t
Definition typedefs.hpp:52
double real
Definition typedefs.hpp:36
void find_interval(const Vector< real > &aData, const real aValue, index_t &aIndex, real &aXi)
Definition fn_find_interval.hpp:23