From e696e4a11e8db6e5b3e0f0be48c49bef261c60fb Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@igpm.rwth-aachen.de> Date: Tue, 17 Jun 2014 18:07:44 +0000 Subject: [PATCH] Simplify Python code by using lambda functions [[Imported from SVN: r9796]] --- cosserat-continuum.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cosserat-continuum.cc b/cosserat-continuum.cc index 6bb8597f..d507b7c4 100644 --- a/cosserat-continuum.cc +++ b/cosserat-continuum.cc @@ -271,16 +271,12 @@ int main (int argc, char *argv[]) try // Make Python function that computes which vertices are on the Dirichlet boundary, // based on the vertex positions. - Python::runStream() - << std::endl << "def dirichletVertices(x):" - << std::endl << " return " << parameterSet.get<std::string>("dirichletVerticesPredicate"); - PythonFunction<FieldVector<double,dim>, int> pythonDirichletVertices(main.get("dirichletVertices")); + std::string lambda = std::string("lambda x: (") + parameterSet.get<std::string>("dirichletVerticesPredicate") + std::string(")"); + PythonFunction<FieldVector<double,dim>, int> pythonDirichletVertices(Python::evaluate(lambda)); // Same for the Neumann boundary - Python::runStream() - << std::endl << "def neumannVertices(x):" - << std::endl << " return " << parameterSet.get<std::string>("neumannVerticesPredicate", "0"); - PythonFunction<FieldVector<double,dim>, int> pythonNeumannVertices(main.get("neumannVertices")); + lambda = std::string("lambda x: (") + parameterSet.get<std::string>("neumannVerticesPredicate", "0") + std::string(")"); + PythonFunction<FieldVector<double,dim>, int> pythonNeumannVertices(Python::evaluate(lambda)); for (; vIt!=vEndIt; ++vIt) { -- GitLab