Flow123d
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
fields
field_python.hh
Go to the documentation of this file.
1
/*
2
* field_python.hh
3
*
4
* Created on: Aug 30, 2012
5
* Author: jb
6
*/
7
// TODO: make FieldPython dummy class if we do not have python, so that we
8
// need not optional code elsewhere
9
10
11
#ifndef FIELD_PYTHON_HH_
12
#define FIELD_PYTHON_HH_
13
14
15
#include "
system/system.hh
"
16
#include "
system/python_loader.hh
"
17
#include "
fields/field_base.hh
"
18
#include "
mesh/point.hh
"
19
20
#include <string>
21
using namespace
std;
22
23
/**
24
*
25
* This class assumes field python field with @p spacedim arguments containing coordinates of the given point.
26
* The field should return a tuple representing a vector value (possibly of size one for scalar fields)
27
*
28
* TODO:
29
* - use rather only one argument - tuple representing the whole point
30
* - time fields
31
* - set some parameter in the python module
32
* - for fields with one component allow python fields returning the value directly
33
*
34
*/
35
template
<
int
spacedim,
class
Value>
36
class
FieldPython
:
public
FieldBase
<spacedim, Value>
37
{
38
public
:
39
typedef
typename
FieldBase<spacedim, Value>::Point
Point
;
40
41
FieldPython
(
unsigned
int
n_comp=0);
42
43
static
Input::Type::Record
input_type
;
44
45
virtual
void
init_from_input(
const
Input::Record
&rec);
46
47
static
Input::Type::Record
get_input_type(
Input::Type::AbstractRecord
&a_type,
const
typename
Value::ElementInputType *eit);
48
49
/**
50
* Set the file and field to be called.
51
* TODO: use FilePath
52
*/
53
void
set_python_field_from_file(
const
FilePath
&file_name,
const
string
&func_name);
54
55
/**
56
* Set the source in a string and name of the field to be called.
57
*/
58
void
set_python_field_from_string(
const
string
&python_source,
const
string
&func_name);
59
60
/**
61
* Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
62
*/
63
virtual
typename
Value::return_type
const
&value(
const
Point
&p,
const
ElementAccessor<spacedim>
&elm);
64
65
/**
66
* Returns std::vector of scalar values in several points at once.
67
*/
68
virtual
void
value_list (
const
std::vector< Point >
&point_list,
const
ElementAccessor<spacedim>
&elm,
69
std::vector<typename Value::return_type>
&value_list);
70
71
72
virtual
~
FieldPython
();
73
74
private
:
75
/**
76
* Common part of set_python_field_from_* methods
77
*/
78
void
set_func(
const
string
&func_name);
79
80
/**
81
* Implementation.
82
*/
83
inline
void
set_value(
const
Point
&p,
const
ElementAccessor<spacedim>
&elm, Value &value);
84
85
#ifdef HAVE_PYTHON
86
PyObject *p_func_;
87
PyObject *p_module_;
88
mutable
PyObject *p_args_;
89
mutable
PyObject *p_value_;
90
#endif // HAVE_PYTHON
91
92
};
93
94
95
96
#endif
/* FUNCTION_PYTHON_HH_ */
Generated on Thu May 29 2014 23:14:47 for Flow123d by
1.8.4