From 735749d367b8288c547d1caabbb8c9b60943586c Mon Sep 17 00:00:00 2001 From: Oliver Sander <oliver.sander@tu-dresden.de> Date: Mon, 12 Aug 2024 12:06:42 +0200 Subject: [PATCH] cosserat-continuum.cc: Move Dirichlet values into main problem file That way, a single Python file is enough to describe the entire boundary value problem. --- problems/cantilever-dirichlet-values.py | 17 ----------- problems/cosserat-continuum-cantilever.py | 18 ++++++++++-- problems/cosserat-continuum-twisted-strip.py | 29 +++++++++++++++++-- ...rat-continuum-wong-pellegrino-wrinkling.py | 18 ++++++++++-- .../cosserat-continuum-wriggers-l-shape.py | 22 ++++++++++++-- problems/twisted-strip-dirichlet-values.py | 28 ------------------ problems/wong-pellegrino-dirichlet-values.py | 14 --------- problems/wriggers-l-shape-dirichlet-values.py | 18 ------------ src/cosserat-continuum.cc | 9 +++--- 9 files changed, 83 insertions(+), 90 deletions(-) delete mode 100644 problems/cantilever-dirichlet-values.py delete mode 100644 problems/twisted-strip-dirichlet-values.py delete mode 100644 problems/wong-pellegrino-dirichlet-values.py delete mode 100644 problems/wriggers-l-shape-dirichlet-values.py diff --git a/problems/cantilever-dirichlet-values.py b/problems/cantilever-dirichlet-values.py deleted file mode 100644 index 0d1d60a5..00000000 --- a/problems/cantilever-dirichlet-values.py +++ /dev/null @@ -1,17 +0,0 @@ -import math - -class DirichletValues: - def __init__(self, homotopyParameter): - self.homotopyParameter = homotopyParameter - - def deformation(self, x): - # Dirichlet b.c. simply clamp the shell in the reference configuration - out = [x[0], x[1], 0] - - return out - - - def orientation(self, x): - rotation = [[1,0,0], [0, 1, 0], [0, 0, 1]] - return rotation - diff --git a/problems/cosserat-continuum-cantilever.py b/problems/cosserat-continuum-cantilever.py index 538adaa6..f99abbfe 100644 --- a/problems/cosserat-continuum-cantilever.py +++ b/problems/cosserat-continuum-cantilever.py @@ -106,13 +106,27 @@ parameterSet.materialParameters.b3 = 1 # Boundary values ############################################# -parameterSet.problem = "cantilever" - ### Python predicate specifying all Dirichlet grid vertices # x is the vertex coordinate parameterSet.dirichletVerticesPredicate = "[x[0] < 0.01, x[0] < 0.01, x[0] < 0.01]" parameterSet.dirichletRotationVerticesPredicate = "x[0] < 0.01" +### The actual Dirichlet values +class DirichletValues: + def __init__(self, homotopyParameter): + self.homotopyParameter = homotopyParameter + + def deformation(self, x): + # Dirichlet b.c. simply clamp the shell in the reference configuration + out = [x[0], x[1], 0] + + return out + + + def orientation(self, x): + rotation = [[1,0,0], [0, 1, 0], [0, 0, 1]] + return rotation + ### Python predicate specifying all Neumann grid vertices # x is the vertex coordinate parameterSet.neumannVerticesPredicate = "x[0] > 99.99" diff --git a/problems/cosserat-continuum-twisted-strip.py b/problems/cosserat-continuum-twisted-strip.py index b8120ec6..d32cf33e 100644 --- a/problems/cosserat-continuum-twisted-strip.py +++ b/problems/cosserat-continuum-twisted-strip.py @@ -103,13 +103,38 @@ parameterSet.materialParameters.b3 = 1 # Boundary values ############################################# -parameterSet.problem = "twisted-strip" - ### Python predicate specifying all Dirichlet grid vertices # x is the vertex coordinate parameterSet.dirichletVerticesPredicate = "[x[0] < 0.001 or x[0] > 0.0999, x[0] < 0.001 or x[0] > 0.0999, x[0] < 0.001 or x[0] > 0.0999]" parameterSet.dirichletRotationVerticesPredicate = "x[0] < 0.001 or x[0] > 0.0999" +### The actual Dirichlet values +class DirichletValues: + def __init__(self, homotopyParameter): + self.homotopyParameter = homotopyParameter + self.upper = [0.1, 0.01] + self.totalAngle = 6*math.pi + + def deformation(self, x): + angle = self.totalAngle * x[0]/self.upper[0] + angle *= self.homotopyParameter + + # Rotation matrix (around y-axis) + rotation = [[1,0,0], [0, math.cos(angle), -math.sin(angle)], [0, math.sin(angle), math.cos(angle)]] + + # Matrix-vector product, vector is [x[0], x[1], 0] + out = [rotation[0][0]*x[0]+rotation[0][1]*x[1], rotation[1][0]*x[0]+rotation[1][1]*x[1], rotation[2][0]*x[0]+rotation[2][1]*x[1]] + + return out + + + def orientation(self, x): + angle = self.totalAngle * x[0]/self.upper[0] + angle *= self.homotopyParameter + + rotation = [[1,0,0], [0, math.cos(angle), -math.sin(angle)], [0, math.sin(angle), math.cos(angle)]] + return rotation + # Initial deformation parameterSet.initialDeformation = "[x[0], x[1], 0]" diff --git a/problems/cosserat-continuum-wong-pellegrino-wrinkling.py b/problems/cosserat-continuum-wong-pellegrino-wrinkling.py index cffce139..7b805648 100644 --- a/problems/cosserat-continuum-wong-pellegrino-wrinkling.py +++ b/problems/cosserat-continuum-wong-pellegrino-wrinkling.py @@ -102,13 +102,27 @@ parameterSet.materialParameters.b3 = 1 # Boundary values ############################################# -parameterSet.problem = "wong-pellegrino" - ### Python predicate specifying all Dirichlet grid vertices # x is the vertex coordinate parameterSet.dirichletVerticesPredicate = "[x[1] < 0.0001 or x[1] > 0.128 - 0.0001, x[1] < 0.0001 or x[1] > 0.128 - 0.0001, x[1] < 0.0001 or x[1] > 0.128 - 0.0001]" parameterSet.dirichletRotationVerticesPredicate = "x[1] < 0.0001 or x[1] > 0.128 - 0.0001" +### The actual Dirichlet values +class DirichletValues: + def __init__(self, homotopyParameter): + self.homotopyParameter = homotopyParameter + + def deformation(self, x): + out = [x[0], x[1], 0] + if x[1] > 0.128-1e-4 : + out[0] += 0.003 * self.homotopyParameter + out[1] += 0.0005 + return out + + def orientation(self, x): + rotation = [[1,0,0], [0, 1, 0], [0, 0, 1]] + return rotation + # Initial deformation #parameterSet.startFromFile = True parameterSet.initialIterateFilename = "cosserat_iterate_2.vtu" diff --git a/problems/cosserat-continuum-wriggers-l-shape.py b/problems/cosserat-continuum-wriggers-l-shape.py index 0481d044..cecbc1ae 100644 --- a/problems/cosserat-continuum-wriggers-l-shape.py +++ b/problems/cosserat-continuum-wriggers-l-shape.py @@ -98,13 +98,31 @@ parameterSet.materialParameters.b3 = 1 # Boundary values ############################################# -parameterSet.problem = "wriggers-l-shape" - ### Python predicate specifying all Dirichlet grid vertices # x is the vertex coordinate parameterSet.dirichletVerticesPredicate = "[x[0] < 1, x[0] < 1, x[0] < 1]" parameterSet.dirichletRotationVerticesPredicate = "x[0] < 1" +### The actual Dirichlet values +class DirichletValues: + def __init__(self, homotopyParameter): + self.homotopyParameter = homotopyParameter + + # Deformation of 3d classical materials + def dirichletValues(self, x): + # Clamp the L-shape in its reference configuration + return [x[0], x[1], x[2]] + + # Deformation of Cosserat shells + def deformation(self, x): + # Clamp the L-shape in its reference configuration + return [x[0], x[1], 0] + + # Orientation of Cosserat materials + def orientation(self, x): + rotation = [[1,0,0], [0, 1, 0], [0, 0, 1]] + return rotation + ### Python predicate specifying all Dirichlet grid vertices # x is the vertex coordinate parameterSet.neumannVerticesPredicate = "x[1] < -239" diff --git a/problems/twisted-strip-dirichlet-values.py b/problems/twisted-strip-dirichlet-values.py deleted file mode 100644 index cef4f742..00000000 --- a/problems/twisted-strip-dirichlet-values.py +++ /dev/null @@ -1,28 +0,0 @@ -import math - -class DirichletValues: - def __init__(self, homotopyParameter): - self.homotopyParameter = homotopyParameter - self.upper = [0.1, 0.01] - self.totalAngle = 6*math.pi - - def deformation(self, x): - angle = self.totalAngle * x[0]/self.upper[0] - angle *= self.homotopyParameter - - # Rotation matrix (around y-axis) - rotation = [[1,0,0], [0, math.cos(angle), -math.sin(angle)], [0, math.sin(angle), math.cos(angle)]] - - # Matrix-vector product, vector is [x[0], x[1], 0] - out = [rotation[0][0]*x[0]+rotation[0][1]*x[1], rotation[1][0]*x[0]+rotation[1][1]*x[1], rotation[2][0]*x[0]+rotation[2][1]*x[1]] - - return out - - - def orientation(self, x): - angle = self.totalAngle * x[0]/self.upper[0] - angle *= self.homotopyParameter - - rotation = [[1,0,0], [0, math.cos(angle), -math.sin(angle)], [0, math.sin(angle), math.cos(angle)]] - return rotation - diff --git a/problems/wong-pellegrino-dirichlet-values.py b/problems/wong-pellegrino-dirichlet-values.py deleted file mode 100644 index 4e27ee31..00000000 --- a/problems/wong-pellegrino-dirichlet-values.py +++ /dev/null @@ -1,14 +0,0 @@ -class DirichletValues: - def __init__(self, homotopyParameter): - self.homotopyParameter = homotopyParameter - - def deformation(self, x): - out = [x[0], x[1], 0] - if x[1] > 0.128-1e-4 : - out[0] += 0.003 * self.homotopyParameter - out[1] += 0.0005 - return out - - def orientation(self, x): - rotation = [[1,0,0], [0, 1, 0], [0, 0, 1]] - return rotation diff --git a/problems/wriggers-l-shape-dirichlet-values.py b/problems/wriggers-l-shape-dirichlet-values.py deleted file mode 100644 index eac737a0..00000000 --- a/problems/wriggers-l-shape-dirichlet-values.py +++ /dev/null @@ -1,18 +0,0 @@ -class DirichletValues: - def __init__(self, homotopyParameter): - self.homotopyParameter = homotopyParameter - - # Deformation of 3d classical materials - def dirichletValues(self, x): - # Clamp the L-shape in its reference configuration - return [x[0], x[1], x[2]] - - # Deformation of Cosserat shells - def deformation(self, x): - # Clamp the L-shape in its reference configuration - return [x[0], x[1], 0] - - # Orientation of Cosserat materials - def orientation(self, x): - rotation = [[1,0,0], [0, 1, 0], [0, 0, 1]] - return rotation diff --git a/src/cosserat-continuum.cc b/src/cosserat-continuum.cc index 2b5e301c..d45f1ca6 100644 --- a/src/cosserat-continuum.cc +++ b/src/cosserat-continuum.cc @@ -471,12 +471,11 @@ int main (int argc, char *argv[]) try // Set Dirichlet values //////////////////////////////////////////////////////// - Python::Reference dirichletValuesClass = Python::import(parameterSet.get<std::string>("problem") + "-dirichlet-values"); + // Dirichlet boundary value function, depending on the homotopy parameter + Python::Callable dirichletValuesPythonClass = pyModule.get("DirichletValues"); - Python::Callable C = dirichletValuesClass.get("DirichletValues"); - - // Call a constructor. - Python::Reference dirichletValuesPythonObject = C(homotopyParameter); + // Construct with a particular value of the homotopy parameter + Python::Reference dirichletValuesPythonObject = dirichletValuesPythonClass(homotopyParameter); // Extract object member functions as Dune functions auto deformationDirichletValues = Python::make_function<FieldVector<double,3> > (dirichletValuesPythonObject.get("deformation")); -- GitLab