File: field_props.cpp

package info (click to toggle)
opm-common 2022.10%2Bds-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 78,468 kB
  • sloc: cpp: 164,554; python: 2,872; sh: 216; xml: 174; ansic: 149; pascal: 136; makefile: 12
file content (59 lines) | stat: -rw-r--r-- 1,611 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <string>

#include <opm/input/eclipse/EclipseState/Grid/FieldPropsManager.hpp>

#include <pybind11/stl.h>

#include "export.hpp"
#include "converters.hpp"

namespace {

    bool contains( const FieldPropsManager& manager, const std::string& kw) {
        if (manager.has_int(kw))
            return true;
        if (manager.has_double(kw))
            return true;

        return false;
    }

    py::array_t<double> get_double_array(const FieldPropsManager& m, const std::string& kw) {
        if (m.has_double(kw))
            return convert::numpy_array( m.get_double(kw) );
        else
            throw std::invalid_argument("Keyword '" + kw + "'is not of type double.");
    }

    py::array_t<int> get_int_array(const FieldPropsManager& m, const std::string& kw) {
        if (m.has_int(kw))
            return convert::numpy_array( m.get_int(kw) );
        else
            throw std::invalid_argument("Keyword '" + kw + "'is not of type int.");
    }


    py::array get_array(const FieldPropsManager& m, const std::string& kw) {
        if (m.has_double(kw))
            return convert::numpy_array(m.get_double(kw));

        if (m.has_int(kw))
            return convert::numpy_array(m.get_int(kw));

        throw std::invalid_argument("No such keyword: " + kw);
    }


}


void python::common::export_FieldProperties(py::module& module) {

    py::class_< FieldPropsManager >( module, "FieldProperties")
    .def( "__contains__", &contains )
    .def("__getitem__", &get_array)
    .def( "get_double_array",  &get_double_array )
    .def( "get_int_array",  &get_int_array )
    ;

}