interpolation2DTable.H 4.69 KB
Newer Older
sergio's avatar
sergio committed
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
sergio's avatar
sergio committed
6
     \\/     M anipulation  |
OpenFOAM bot's avatar
OpenFOAM bot committed
7
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9
    Copyright (C) 2019-2020 OpenCFD Ltd.
sergio's avatar
sergio committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::interpolation2DTable

Description
31 32
    2D table interpolation.
    The data must be in ascending order in both dimensions x and y.
sergio's avatar
sergio committed
33 34 35 36 37 38 39 40 41

SourceFiles
    interpolation2DTable.C

\*---------------------------------------------------------------------------*/

#ifndef interpolation2DTable_H
#define interpolation2DTable_H

42
#include "interpolationTable.H"
sergio's avatar
sergio committed
43 44 45 46 47 48 49 50 51 52 53 54 55

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
                    Class interpolation2DTable Declaration
\*---------------------------------------------------------------------------*/

template<class Type>
class interpolation2DTable
:
56
    public List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>
sergio's avatar
sergio committed
57
{
58
    // Private Data
sergio's avatar
sergio committed
59

60 61
        //- Handling for out-of-bound values
        bounds::normalBounding bounding_;
sergio's avatar
sergio committed
62 63 64 65

        //- File name
        fileName fileName_;

66
        //- Table reader
67
        autoPtr<tableReader<Type>> reader_;
sergio's avatar
sergio committed
68 69 70 71 72 73 74


    // Private Member Functions

        //- Read the table of data from file
        void readTable();

75
        //- Interpolated value within 1-D list
sergio's avatar
sergio committed
76 77
        Type interpolateValue
        (
78 79
            const List<Tuple2<scalar, Type>>& list,
            scalar lookupValue
sergio's avatar
sergio committed
80 81
        ) const;

andy's avatar
andy committed
82 83 84 85 86 87 88 89 90
        //- Return an X index from the matrix
        template<class BinaryOp>
        label Xi
        (
            const BinaryOp& bop,
            const scalar valueX,
            const bool reverse
        ) const;

sergio's avatar
sergio committed
91 92 93

public:

94 95 96 97 98 99 100 101 102
    // Public Data Types

        //- The element data type
        typedef Tuple2<scalar, List<Tuple2<scalar, Type>>> value_type;

        //- Convenience typedef
        typedef List<Tuple2<scalar, List<Tuple2<scalar, Type>>>> table;


sergio's avatar
sergio committed
103 104
    // Constructors

105
        //- Default construct
sergio's avatar
sergio committed
106 107 108 109 110
        interpolation2DTable();

        //- Construct from components
        interpolation2DTable
        (
111
            const List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>& values,
112
            const bounds::normalBounding bounding,
sergio's avatar
sergio committed
113 114 115 116
            const fileName& fName
        );

        //- Construct given the name of the file containing the table of data
117
        explicit interpolation2DTable(const fileName& fName);
sergio's avatar
sergio committed
118

119
        //- Construct by reading file name and outOfBounds from dictionary
120
        explicit interpolation2DTable(const dictionary& dict);
sergio's avatar
sergio committed
121

122
        //- Copy construct
123
        interpolation2DTable(const interpolation2DTable& tbl);
sergio's avatar
sergio committed
124 125 126 127 128 129


    // Member Functions

        //- Check that list is monotonically increasing
        //  Exit with a FatalError if there is a problem
130
        void check() const;
sergio's avatar
sergio committed
131 132 133 134 135 136 137

        //- Write
        void write(Ostream& os) const;


    // Member Operators

138 139 140
        //- Copy assignment
        void operator=(const interpolation2DTable<Type>& rhs);

sergio's avatar
sergio committed
141
        //- Return an interpolated value
142
        Type operator()(const scalar valueX, const scalar valueY) const;
143 144 145 146 147 148 149


    // Housekeeping

        //- Deprecated(2019-08) check list is monotonically increasing
        //  \deprecated(2019-08) - older name for check() method
        void checkOrder() const { check(); }
sergio's avatar
sergio committed
150 151 152 153 154 155 156 157 158 159
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#ifdef NoRepository
160
    #include "interpolation2DTable.C"
sergio's avatar
sergio committed
161 162 163 164 165 166 167
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //