Forked from
agnumpde / dune-tectonic
1347 commits behind the upstream repository.
-
Elias Pipping authoredElias Pipping authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
test-python.cc 1.06 KiB
/* -*- mode:c++; mode:semantic -*- */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_PYTHON
#error Python is necessary
#else
#define EMBEDDED_PYTHON 1
#endif
#include <Python.h>
#include <dune/common/exceptions.hh>
#include <dune/common/stdstreams.hh>
#include <dune/fufem/dunepython.hh>
#include <dune/fufem/sharedpointermap.hh>
int main() {
typedef Dune::VirtualFunction<double, double> Function;
typedef SharedPointerMap<std::string, Function> FunctionMap;
FunctionMap functions;
try {
Python::start();
Python::run("import sys");
Python::run(
"sys.path.append('../../src')"); // FIXME: use path to source here
Python::Reference module = Python::import("nicefunction");
Python::Reference funcRef = module.get("Functions");
funcRef.toC<FunctionMap::Base>(functions);
double const in(2.0);
Function const &foo = functions.get("sampleFunction");
double out;
foo.evaluate(in, out);
Python::stop();
}
catch (Dune::Exception &e) {
Dune::derr << "Dune reported error: " << e << std::endl;
}
}