BELFEM
0.9.0
Berkeley Lab Finite Element Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fn_find_interval.hpp
Go to the documentation of this file.
1
//
2
// Created by Christian Messe on 02.12.19.
3
//
4
5
#ifndef BELFEM_FN_FIND_INTERVAL_HPP
6
#define BELFEM_FN_FIND_INTERVAL_HPP
7
8
#include "
typedefs.hpp
"
9
#include "
cl_Vector.hpp
"
10
11
namespace
belfem
12
{
13
//------------------------------------------------------------------------------
14
15
inline
void
16
find_interval
(
const
Vector< real >
& aData,
const
real
aValue,
index_t
& aIndex,
real
& aXi )
17
{
18
index_t
i = 0;
19
index_t
k = aData.
length
() - 1;
20
index_t
j = ( i + k ) / 2 ;
21
22
if
( aValue <= aData( 1 ) )
23
{
24
aIndex = 0;
25
26
aXi = ( aValue - aData( 0 ) ) / ( aData( 1 ) - aData( 0 ) );
27
}
28
else
if
( aValue >= aData( k - 1 ) )
29
{
30
aIndex = k - 1;
31
aXi = ( aValue - aData( k-1 ) ) / ( aData( k ) - aData( k - 1 ) ) ;
32
}
33
else
34
{
35
while
(
true
)
36
{
37
if
(( aData( i ) <= aValue ) && ( aData( j ) >= aValue ))
38
{
39
// this is the correct interval
40
k = j;
41
}
42
else
43
{
44
// the other one is the correct interval
45
i = j;
46
}
47
if
(( k - i ) == 1 )
48
{
49
aIndex = i;
50
aXi = ( aValue - aData( i ) ) / ( aData( k ) - aData( i ) );
51
break
;
52
}
53
else
54
{
55
j = ( i + k ) / 2 + ( i + k ) % 2;
56
}
57
58
}
59
}
60
}
61
62
//------------------------------------------------------------------------------
63
}
64
65
#endif
//BELFEM_FN_FIND_INTERVAL_HPP
cl_Vector.hpp
belfem::Vector< real >
belfem::Vector::length
size_t length() const
get the length of the vector
Definition
cl_AR_Vector.hpp:257
belfem
USER GUIDES:
Definition
cl_Capacitor.cpp:16
belfem::index_t
uint32_t index_t
Definition
typedefs.hpp:52
belfem::real
double real
Definition
typedefs.hpp:36
belfem::find_interval
void find_interval(const Vector< real > &aData, const real aValue, index_t &aIndex, real &aXi)
Definition
fn_find_interval.hpp:16
typedefs.hpp
src
math
tools
fn_find_interval.hpp
Generated by
1.18.0