Skip to content
Snippets Groups Projects
Commit 63ecbaee authored by Elias Pipping's avatar Elias Pipping Committed by Elias Pipping
Browse files

Remove toy python code

parent 76e0a1fb
No related branches found
No related tags found
No related merge requests found
SUBDIRS =
check_PROGRAMS = \
test-python
TESTS = test-python
test_python_SOURCES = \
test-python.cc
test_python_CPPFLAGS= \
$(AM_CPPFLAGS) -DDUNE_NICE_FUNCTION_MODULE_PATH="\"$(srcdir)\""
AM_CPPFLAGS = \
$(DUNE_CPPFLAGS) \
$(PYTHON_CPPFLAGS) \
-I$(top_srcdir)
LDADD = \
$(DUNE_LDFLAGS) $(DUNE_LIBS) \
$(PYTHON_LIBS)
AM_LDFLAGS = \
$(DUNE_LDFLAGS) \
$(PYTHON_LDFLAGS)
include $(top_srcdir)/am/global-rules
class sampleFunction:
def __call__(self, x):
if x < 1:
return x
else:
return 2*x - 1
Functions = {'sampleFunction' : sampleFunction()}
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef DUNE_NICE_FUNCTION_MODULE_PATH
#error DUNE_NICE_FUNCTION_MODULE_PATH unset
#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");
std::string importString("sys.path.append('");
importString += DUNE_NICE_FUNCTION_MODULE_PATH;
importString += "')";
Python::run(importString.c_str());
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment