-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathPyHistoryCollection.cpp
More file actions
144 lines (107 loc) · 3.74 KB
/
PyHistoryCollection.cpp
File metadata and controls
144 lines (107 loc) · 3.74 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2024 TotalEnergies
* Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2023-2024 Chevron
* Copyright (c) 2019- GEOS/GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
// Source includes
#include "fileIO/timeHistory/HistoryCollection.hpp"
#include "PyHistoryCollectionType.hpp"
#include "dataRepository/python/PyGroupType.hpp"
#define VERIFY_NON_NULL_SELF( self ) \
PYTHON_ERROR_IF( self == nullptr, PyExc_RuntimeError, "Passed a nullptr as self.", nullptr )
#define VERIFY_INITIALIZED( self ) \
PYTHON_ERROR_IF( self->group == nullptr, PyExc_RuntimeError, "The PyHistoryCollection is not initialized.", nullptr )
namespace geos
{
namespace python
{
struct PyHistoryCollection
{
PyObject_HEAD
static constexpr char const * docString =
"A Python interface to HistoryCollection.";
geos::HistoryCollection * group;
};
static PyObject * PyHistoryCollection_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
GEOS_UNUSED_VAR( args, kwds );
PyHistoryCollection *self;
self = (PyHistoryCollection *)type->tp_alloc( type, 0 );
if( self != nullptr )
{
self->group = nullptr;
}
return (PyObject *)self;
}
static PyObject * PyHistoryCollection_repr( PyObject * const obj ) noexcept
{
PyHistoryCollection const * const pyHistoryCollection = LvArray::python::convert< PyHistoryCollection >( obj, getPyHistoryCollectionType() );
if( pyHistoryCollection == nullptr )
{
return nullptr;
}
VERIFY_INITIALIZED( pyHistoryCollection );
string repr;
string const path = pyHistoryCollection->group->getPath();
string const type = LvArray::system::demangle( typeid( *(pyHistoryCollection->group) ).name() );
repr = path + " ( " + type + " )";
return PyUnicode_FromString( repr.c_str() );
}
static PyObject * collect( PyHistoryCollection * self, PyObject * args )
{
VERIFY_NON_NULL_SELF( self );
VERIFY_INITIALIZED( self );
double time;
double dt;
int cycleNumber;
if( !PyArg_ParseTuple( args, "ddi", &time, &dt, &cycleNumber ) )
{
return nullptr;
}
geos::DomainPartition & domain = self->group->getGroupByPath< DomainPartition >( "/Problem/domain" );
try
{
self->group->execute( time, dt, cycleNumber, 0, 0, domain );
}
catch( std::out_of_range const & e )
{
std::cout<<"Target not found. Impossible output."<<std::endl;
}
Py_RETURN_NONE;
}
static PyMethodDef PyHistoryCollection_methods[] = {
{ "collect", (PyCFunction) collect, METH_VARARGS, "wrapper to routine HistoryCollection::execute" },
{ nullptr, nullptr, 0, nullptr } /* Sentinel */
};
/**
* Initialize the module object for Python with the exported functions
*/
BEGIN_ALLOW_DESIGNATED_INITIALIZERS
static PyTypeObject PyHistoryCollectionType = {
PyVarObject_HEAD_INIT( nullptr, 0 )
.tp_name = "pygeosx.HistoryCollection",
.tp_basicsize = sizeof( PyHistoryCollection ),
.tp_itemsize = 0,
.tp_repr = PyHistoryCollection_repr,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = PyHistoryCollection::docString,
.tp_methods = PyHistoryCollection_methods,
.tp_base = getPyGroupType(),
.tp_new = PyHistoryCollection_new,
};
END_ALLOW_DESIGNATED_INITIALIZERS
PyTypeObject * getPyHistoryCollectionType()
{ return &PyHistoryCollectionType; }
}
}