OPALX (Object Oriented Parallel Accelerator Library for Exascal)
MINIorX
OPALX
TriLinearInterpolator.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012, Chris Rogers
3
* All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
* 1. Redistributions of source code must retain the above copyright notice,
7
* this list of conditions and the following disclaimer.
8
* 2. Redistributions in binary form must reproduce the above copyright notice,
9
* this list of conditions and the following disclaimer in the documentation
10
* and/or other materials provided with the distribution.
11
* 3. Neither the name of STFC nor the names of its contributors may be used to
12
* endorse or promote products derived from this software without specific
13
* prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
* POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#include "
Fields/Interpolation/TriLinearInterpolator.h
"
29
30
namespace
interpolation
{
31
32
TriLinearInterpolator::TriLinearInterpolator
(
const
TriLinearInterpolator
& lhs):
33
Interpolator3dGridTo1d
(lhs)
34
{
35
coordinates_m
=
new
ThreeDGrid
(*lhs.
coordinates_m
);
36
f_m
=
new
double
**[
coordinates_m
->xSize()];
37
for
(
int
i = 0; i <
coordinates_m
->xSize(); i++) {
38
f_m
[i] =
new
double
*[
coordinates_m
->ySize()];
39
for
(
int
j = 0; j <
coordinates_m
->ySize(); j++) {
40
f_m
[i][j] =
new
double
[
coordinates_m
->zSize()];
41
for
(
int
k = 0; k <
coordinates_m
->zSize(); k++)
42
f_m
[i][j][k] = lhs.
f_m
[i][j][k];
43
}
44
}
45
coordinates_m
->add(
this
);
46
}
47
48
void
TriLinearInterpolator::function
49
(
const
double
Point
[3],
double
Value
[1])
const
{
50
int
i, j, k;
// position indices
51
coordinates_m
->lowerBound(
Point
[0], i,
Point
[1], j,
Point
[2], k);
52
// bound checking
53
if
(i + 2 >
coordinates_m
->xSize() ||
54
j + 2 >
coordinates_m
->ySize() ||
55
k + 2 >
coordinates_m
->zSize()) {
56
Value
[0] = 0;
57
return
;
58
}
59
if
(i < 0 || j < 0 || k < 0) {
60
Value
[0] = 0;
61
return
;
62
}
63
// interpolation in x
64
double
dx = (
Point
[0]-
coordinates_m
->x(i+1))/
65
(
coordinates_m
->x(i+2)-
coordinates_m
->x(i+1));
66
double
f_x[2][2];
67
f_x[0][0] = (
f_m
[i+1][j] [k] -
f_m
[i][j] [k]) * dx +
f_m
[i][j] [k];
68
f_x[1][0] = (
f_m
[i+1][j+1][k] -
f_m
[i][j+1][k]) * dx +
f_m
[i][j+1][k];
69
f_x[0][1] = (
f_m
[i+1][j] [k+1] -
f_m
[i][j] [k+1]) * dx +
f_m
[i][j] [k+1];
70
f_x[1][1] = (
f_m
[i+1][j+1][k+1] -
f_m
[i][j+1][k+1]) * dx +
f_m
[i][j+1][k+1];
71
// interpolation in y
72
double
f_xy[2];
73
double
dy = (
Point
[1]-
coordinates_m
->y(j+1))/
74
(
coordinates_m
->y(j+2) -
coordinates_m
->y(j+1));
75
f_xy[0] = (f_x[1][0] - f_x[0][0])*dy + f_x[0][0];
76
f_xy[1] = (f_x[1][1] - f_x[0][1])*dy + f_x[0][1];
77
// interpolation in z
78
Value
[0] = (f_xy[1] - f_xy[0])/
79
(
coordinates_m
->z(k+2) -
coordinates_m
->z(k+1))*
80
(
Point
[2] -
coordinates_m
->z(k+1)) + f_xy[0];
81
}
82
}
83
TriLinearInterpolator.h
Point
#define Point(triangle_id, vertex_id)
Definition
BoundaryGeometry.cpp:48
interpolation
Definition
DumpEMFields.h:29
Value
Definition
Value.h:24
interpolation::Interpolator3dGridTo1d::f_m
double *** f_m
Definition
Interpolator3dGridTo1d.h:140
interpolation::Interpolator3dGridTo1d::function
double *** function() const
Definition
Interpolator3dGridTo1d.h:207
interpolation::Interpolator3dGridTo1d::coordinates_m
ThreeDGrid * coordinates_m
Definition
Interpolator3dGridTo1d.h:139
interpolation::Interpolator3dGridTo1d::Interpolator3dGridTo1d
Interpolator3dGridTo1d(ThreeDGrid *grid, double ***F)
Definition
Interpolator3dGridTo1d.h:143
interpolation::ThreeDGrid
Definition
ThreeDGrid.h:57
interpolation::TriLinearInterpolator::TriLinearInterpolator
TriLinearInterpolator(ThreeDGrid *grid, double ***F)
Definition
TriLinearInterpolator.h:83