diff --git a/problems/cosserat-rod-example.py b/problems/cosserat-rod-example.py new file mode 100644 index 0000000000000000000000000000000000000000..d58d65fd7d0e60944832370e8e9c855c92f7f206 --- /dev/null +++ b/problems/cosserat-rod-example.py @@ -0,0 +1,76 @@ +class ParameterSet(dict): + def __init__(self, *args, **kwargs): + super(ParameterSet, self).__init__(*args, **kwargs) + self.__dict__ = self + +parameterSet = ParameterSet() + +############################################# +# Grid parameters +############################################# + +# Number of grid levels +parameterSet.numLevels = 4 + +# Number of elements of the rod grid +parameterSet.numRodBaseElements = 5 + +############################################# +# Solver parameters +############################################# + +# Initial load increment +parameterSet.loadIncrement = 0.01 + +# Tolerance of the trust region solver +parameterSet.tolerance = 1e-6 + +# Max number of steps of the trust region solver +parameterSet.maxTrustRegionSteps = 100 + +parameterSet.solverScaling = "1 1 1 0.01 0.01 0.01" + +# Initial trust-region radius +parameterSet.initialTrustRegionRadius = 1 + +# Number of multigrid iterations per trust-region step +parameterSet.numIt = 200 + +# Number of presmoothing steps +parameterSet.nu1 = 3 + +# Number of postsmoothing steps +parameterSet.nu2 = 3 + +# Number of coarse grid corrections +parameterSet.mu = 1 + +# Number of base solver iterations +parameterSet.baseIt = 100 + +# Tolerance of the multigrid solver +parameterSet.mgTolerance = 1e-10 + +# Tolerance of the base grid solver +parameterSet.baseTolerance = 1e-8 + +parameterSet.instrumented = "no" + +############################ +# Problem specifications +############################ + +# Interpolation method +parameterSet.interpolationMethod = "geodesic" + +parameterSet.A = 1 +parameterSet.J1 = 1 +parameterSet.J2 = 1 +parameterSet.E = 2.5e5 +parameterSet.nu = 0.3 + +parameterSet.dirichletValue = "1 0 0" + +parameterSet.dirichletAxis = "1 0 0" + +parameterSet.dirichletAngle = 0 diff --git a/problems/staticrod.parset b/problems/staticrod.parset deleted file mode 100644 index 7f8e5fe57d9b1415fca73ae3aca3effedaf644d2..0000000000000000000000000000000000000000 --- a/problems/staticrod.parset +++ /dev/null @@ -1,69 +0,0 @@ -############################################# -# Grid parameters -############################################# - -# Number of grid levels -numLevels = 4 - -# Number of elements of the rod grid -numRodBaseElements = 5 - -############################################# -# Solver parameters -############################################# - -# Initial load increment -loadIncrement = 0.01 - -# Tolerance of the trust region solver -tolerance = 1e-6 - -# Max number of steps of the trust region solver -maxTrustRegionSteps = 100 - -solverScaling = 1 1 1 0.01 0.01 0.01 - -# Initial trust-region radius -initialTrustRegionRadius = 1 - -# Number of multigrid iterations per trust-region step -numIt = 200 - -# Number of presmoothing steps -nu1 = 3 - -# Number of postsmoothing steps -nu2 = 3 - -# Number of coarse grid corrections -mu = 1 - -# Number of base solver iterations -baseIt = 100 - -# Tolerance of the multigrid solver -mgTolerance = 1e-10 - -# Tolerance of the base grid solver -baseTolerance = 1e-8 - -instrumented = no - -############################ -# Problem specifications -############################ - -# Interpolation method -interpolationMethod = geodesic - -A = 1 -J1 = 1 -J2 = 1 -E = 2.5e5 -nu = 0.3 - -dirichletValue = 1 0 0 - -dirichletAxis = 1 0 0 - -dirichletAngle = 0 diff --git a/src/rod3d.cc b/src/rod3d.cc index eedcf5d00235f30e3b2959c524fdb3347d7188d7..f28f30053468b6e374756a740830cb48270ff532 100644 --- a/src/rod3d.cc +++ b/src/rod3d.cc @@ -29,6 +29,7 @@ #include <dune/fufem/boundarypatch.hh> #include <dune/fufem/functiontools/boundarydofs.hh> +#include <dune/fufem/dunepython.hh> #include <dune/gfe/assemblers/cosseratrodenergy.hh> #include <dune/gfe/assemblers/geodesicfeassembler.hh> @@ -55,12 +56,25 @@ int main (int argc, char *argv[]) try { MPIHelper::instance(argc, argv); - // parse data file - ParameterTree parameterSet; - if (argc < 2) - DUNE_THROW(Exception, "Usage: ./rod3d <parameter file>"); + // Check for appropriate number of command line arguments + if (argc < 3) + DUNE_THROW(Exception, "Usage: ./rod3d <python path> <parameter file>"); + + // Start Python interpreter + Python::start(); + auto pyMain = Python::main(); + + Python::runStream() + << std::endl << "import sys" + << std::endl << "sys.path.append('" << argv[1] << "')" + << std::endl; - ParameterTreeParser::readINITree(argv[1], parameterSet); + // Parse data file + auto pyModule = pyMain.import(argv[2]); + + // Get main parameter set + ParameterTree parameterSet; + pyModule.get("parameterSet").toC(parameterSet); ParameterTreeParser::readOptions(argc, argv, parameterSet);