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

Add python test

parent a1d4aa2c
No related branches found
No related tags found
No related merge requests found
......@@ -2,21 +2,26 @@
SUBDIRS =
check_PROGRAMS = \
test-python \
test-gradient-method
test_python_SOURCES = \
test-python.cc
test_gradient_method_SOURCES = \
test-gradient-method.cc \
mynonlinearity.hh \
nicefunction.hh \
samplefunctional.hh
TESTS= test-gradient-method
TESTS= test-python test-gradient-method
AM_CXXFLAGS = -Wall -Wextra -Wno-unused-parameter
AM_CPPFLAGS = \
$(DUNE_CPPFLAGS) \
$(ALUGRID_CPPFLAGS)
$(ALUGRID_CPPFLAGS) \
$(PYTHON_CPPFLAGS)
# The libraries have to be given in reverse order (most basic libraries
# last). Also, due to some misunderstanding, a lot of libraries include the
......@@ -24,10 +29,12 @@ AM_CPPFLAGS = \
# here as well.
LDADD = \
$(DUNE_LDFLAGS) $(DUNE_LIBS) \
$(ALUGRID_LDFLAGS) $(ALUGRID_LIBS)
$(ALUGRID_LDFLAGS) $(ALUGRID_LIBS) \
$(PYTHON_LIBS)
AM_LDFLAGS = \
$(ALUGRID_LDFLAGS) \
$(DUNE_LDFLAGS)
$(DUNE_LDFLAGS) \
$(PYTHON_LDFLAGS)
# don't follow the full GNU-standard
# we need automake 1.5
......
class sampleFunction:
def __call__(self, x):
if x < 1:
return x
else:
return 2*x - 1
Functions = {'sampleFunction' : sampleFunction()}
/* -*- 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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment