Skip to content
Snippets Groups Projects
Commit 8e9d35d6 authored by Oliver Sander's avatar Oliver Sander Committed by sander
Browse files

Get Python predicate specifying Neumann and Dirichlet vertices from the parameter file

That way, we can now control what vertices are Dirichlet and Neumann without having
to recompile the code.

[[Imported from SVN: r9794]]
parent 26996755
No related branches found
No related tags found
No related merge requests found
...@@ -84,6 +84,14 @@ kappa = 1 ...@@ -84,6 +84,14 @@ kappa = 1
# Boundary values # Boundary values
############################################# #############################################
### Python predicate specifying all Dirichlet grid vertices
# x is the vertex coordinate
dirichletVerticesPredicate = "x[0] < 0.001"
### Python predicate specifying all Dirichlet grid vertices
# x is the vertex coordinate
neumannVerticesPredicate = "x[1] < -0.239"
### Neumann values, if needed ### Neumann values, if needed
neumannValues = -1e3 0 0 neumannValues = -1e3 0 0
...@@ -230,7 +230,7 @@ int main (int argc, char *argv[]) try ...@@ -230,7 +230,7 @@ int main (int argc, char *argv[]) try
lower = parameterSet.get<FieldVector<double,dim> >("lower"); lower = parameterSet.get<FieldVector<double,dim> >("lower");
upper = parameterSet.get<FieldVector<double,dim> >("upper"); upper = parameterSet.get<FieldVector<double,dim> >("upper");
array<unsigned int,dim> elements = parameterSet.get<array<unsigned int,dim> >("elements"); array<unsigned int,dim> elements = parameterSet.get<array<unsigned int,dim> >("elements");
grid = StructuredGridFactory<GridType>::createCubeGrid(lower, upper, elements); grid = StructuredGridFactory<GridType>::createCubeGrid(lower, upper, elements);
...@@ -269,40 +269,29 @@ int main (int argc, char *argv[]) try ...@@ -269,40 +269,29 @@ int main (int argc, char *argv[]) try
const GridView::IndexSet& indexSet = gridView.indexSet(); const GridView::IndexSet& indexSet = gridView.indexSet();
// Make Python functions that computes which vertices are on the Dirichlet boundary, // Make Python function that computes which vertices are on the Dirichlet boundary,
// based on the vertex positions. // based on the vertex positions.
Python::runStream() Python::runStream()
<< std::endl << "def dirichletVertices(x):" << std::endl << "def dirichletVertices(x):"
#if 1 // Cantilever example << std::endl << " return " << parameterSet.get<std::string>("dirichletVerticesPredicate");
<< std::endl << " result = x[0] < 1.0+1e-3"
#endif
#if 1 // Wong/Pellegrino shearing/wrinkling example
<< std::endl << " result = x[1] < 1e-4 or x[1] > upper[1]-1e-4"
#endif
#if 1 // Twisted-strip example
<< std::endl << " result = x[0] < lower[0]+1e-3 or x[0] > upper[0]-1e-3"
#endif
#if 1 // Wriggers L-shape example
<< std::endl << " result = x[0] < 0.001"
#endif
<< std::endl << " return result";
PythonFunction<FieldVector<double,dim>, int> pythonDirichletVertices(main.get("dirichletVertices")); PythonFunction<FieldVector<double,dim>, int> pythonDirichletVertices(main.get("dirichletVertices"));
// 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"));
for (; vIt!=vEndIt; ++vIt) { for (; vIt!=vEndIt; ++vIt) {
int isDirichlet; int isDirichlet;
pythonDirichletVertices.evaluate(vIt->geometry().corner(0), isDirichlet); pythonDirichletVertices.evaluate(vIt->geometry().corner(0), isDirichlet);
dirichletVertices[indexSet.index(*vIt)] = isDirichlet; dirichletVertices[indexSet.index(*vIt)] = isDirichlet;
// Neumann boundary int isNeumann;
#if 0 // Boundary conditions for the cantilever example pythonNeumannVertices.evaluate(vIt->geometry().corner(0), isNeumann);
if (vIt->geometry().corner(0)[0] > upper[0]-1e-3 ) neumannNodes[indexSet.index(*vIt)] = isNeumann;
neumannNodes[indexSet.index(*vIt)] = true;
#endif
#if 1 // Boundary conditions for the L-shape example
if (vIt->geometry().corner(0)[1] < -0.239 )
neumannNodes[indexSet.index(*vIt)][0] = true;
#endif
} }
BoundaryPatch<GridView> dirichletBoundary(gridView, dirichletVertices); BoundaryPatch<GridView> dirichletBoundary(gridView, dirichletVertices);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment