Flow123d
master-94c4283
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
y
Functions
_
a
b
c
d
e
f
g
h
i
m
n
o
p
r
s
t
u
w
Variables
Typedefs
Enumerations
Enumerator
a
b
c
d
f
g
h
i
m
n
o
p
r
s
u
w
y
Classes
Class List
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
z
Enumerations
a
b
c
d
f
h
i
m
n
o
p
r
s
t
u
v
Enumerator
a
b
c
d
e
f
g
i
k
l
m
n
o
p
r
s
t
u
v
w
x
y
z
Related Functions
a
b
c
d
e
f
g
i
l
m
n
o
p
r
s
t
Files
File List
File Members
All
_
a
b
c
d
e
f
g
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
Functions
_
a
c
d
f
i
k
l
m
n
o
p
r
s
t
v
Variables
_
a
c
d
g
m
n
p
q
s
u
v
Typedefs
_
a
d
f
g
i
j
l
m
o
p
q
r
s
t
u
v
Enumerations
Enumerator
a
b
c
d
e
f
i
m
n
o
p
r
s
u
v
w
Macros
_
a
b
c
d
e
f
g
i
j
k
l
m
n
o
p
q
r
s
t
w
z
src
fields
python_field_proxy.hh
Go to the documentation of this file.
1
/*!
2
*
3
* Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4
*
5
* This program is free software; you can redistribute it and/or modify it under
6
* the terms of the GNU General Public License version 3 as published by the
7
* Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
*
13
*
14
* @file python_field_proxy.hh
15
* @brief
16
*/
17
18
#ifndef PYTHON_FIELD_BASE_HH_
19
#define PYTHON_FIELD_BASE_HH_
20
21
#include <pybind11/pybind11.h>
22
#include <pybind11/stl.h>
23
#include <pybind11/numpy.h>
24
//#include <pybind11/common.h>
25
#include "
fields/field_value_cache.hh
"
26
27
namespace
py = pybind11;
28
#pragma GCC visibility push(hidden)
29
30
/// Helper class, holds data of one field
31
class
FieldCacheProxy
32
{
33
public
:
34
/**
35
* Method encapsulates FieldValueCache data array for usage in Python.
36
* Allows to create C++ and Python objects above shared block of memory.
37
*/
38
static
py::buffer_info
field_proxy_get_buffer
(
FieldCacheProxy
&proxy)
39
{
40
ssize_t n_comp = ( (proxy.
shape_
.size()==1) ? proxy.
shape_
[0] : proxy.
shape_
[0]*proxy.
shape_
[1]);
41
ssize_t size = proxy.
data_size_
/ n_comp;
42
std::vector<ssize_t>
shape;
43
std::vector<ssize_t>
strides;
44
45
if
(proxy.
shape_
[0] > 1) {
// add dimensions only for vector and tensor
46
shape.push_back(proxy.
shape_
[0]);
47
if
(proxy.
shape_
.size() == 2) shape.push_back(proxy.
shape_
[1]);
48
}
49
shape.push_back(size);
50
51
ssize_t n_dim = shape.size();
52
strides.resize(n_dim);
53
strides[n_dim-1] =
sizeof
(double);
54
for
(
uint
i=n_dim-1; i>0; i--) {
55
strides[i-1] = strides[i] * shape[i];
56
}
57
58
// create n_dim NumPy array
59
return
py::buffer_info(
60
proxy.
field_cache_data_
,
/* data as contiguous array */
61
sizeof
(
double
),
/* size of one scalar */
62
py::format_descriptor<double>::format
(),
/* data type */
63
n_dim,
/* number of dimensions */
64
shape,
/* shape of the matrix */
65
strides
/* strides for each axis */
66
);
67
}
68
69
/// Constructor
70
FieldCacheProxy
(std::string
field_name
,
std::vector<uint>
shape,
double
* field_cache_data,
uint
data_size)
71
:
field_name_
(
field_name
),
shape_
(shape),
field_cache_data_
(field_cache_data),
data_size_
(data_size)
72
{}
73
74
/// Copy constructor
75
FieldCacheProxy
(
const
FieldCacheProxy
&other)
76
:
field_name_
(other.
field_name_
),
shape_
(other.
shape_
),
field_cache_data_
(other.
field_cache_data_
),
data_size_
(other.
data_size_
)
77
{}
78
79
/// Getter returns field name
80
const
std::string &
field_name
()
const
{
return
field_name_
; }
81
82
83
private
:
84
std::string
field_name_
;
85
std::vector<uint>
shape_
;
86
double
*
field_cache_data_
;
87
uint
data_size_
;
88
};
89
90
#pragma GCC visibility pop
91
92
#endif
/* PYTHON_FIELD_BASE_HH_ */
format
manipulators::Array< T, Delim > format(T const &deduce, Delim delim=", ")
Definition:
logger.hh:325
std::vector
Definition:
doxy_dummy_defs.hh:7
FieldCacheProxy::field_name
const std::string & field_name() const
Getter returns field name.
Definition:
python_field_proxy.hh:80
uint
unsigned int uint
Definition:
mh_dofhandler.hh:101
FieldCacheProxy::field_cache_data_
double * field_cache_data_
Definition:
python_field_proxy.hh:86
FieldCacheProxy
Helper class, holds data of one field.
Definition:
python_field_proxy.hh:31
FieldCacheProxy::field_proxy_get_buffer
static py::buffer_info field_proxy_get_buffer(FieldCacheProxy &proxy)
Definition:
python_field_proxy.hh:38
FieldCacheProxy::FieldCacheProxy
FieldCacheProxy(const FieldCacheProxy &other)
Copy constructor.
Definition:
python_field_proxy.hh:75
field_value_cache.hh
FieldCacheProxy::shape_
std::vector< uint > shape_
Definition:
python_field_proxy.hh:85
FieldCacheProxy::FieldCacheProxy
FieldCacheProxy(std::string field_name, std::vector< uint > shape, double *field_cache_data, uint data_size)
Constructor.
Definition:
python_field_proxy.hh:70
FieldCacheProxy::data_size_
uint data_size_
Definition:
python_field_proxy.hh:87
FieldCacheProxy::field_name_
std::string field_name_
Definition:
python_field_proxy.hh:84
Generated by
1.8.17