From 243f0ee8c13b10c74e68509393cee7429fffcc5d Mon Sep 17 00:00:00 2001 From: Oliver Sander <oliver.sander@tu-dresden.de> Date: Mon, 28 Oct 2024 22:14:30 +0100 Subject: [PATCH] cosserat-rod: Use CosseratVTKWriter This should simplify the code, but it doesn't: Computing the displacement still needs a lot of code lines. --- src/cosserat-rod.cc | 46 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/cosserat-rod.cc b/src/cosserat-rod.cc index 99b2fdfe..d439e44a 100644 --- a/src/cosserat-rod.cc +++ b/src/cosserat-rod.cc @@ -32,6 +32,7 @@ #include <dune/gfe/assemblers/cosseratrodenergy.hh> #include <dune/gfe/assemblers/geodesicfeassembler.hh> #include <dune/gfe/assemblers/localgeodesicfeadolcstiffness.hh> +#include <dune/gfe/cosseratvtkwriter.hh> #include <dune/gfe/localgeodesicfefunction.hh> #include <dune/gfe/localprojectedfefunction.hh> #include <dune/gfe/riemanniantrsolver.hh> @@ -283,21 +284,21 @@ int main (int argc, char *argv[]) try // Output result // ////////////////////////////// -#if DUNE_VERSION_GTE(DUNE_VTK, 2, 10) - auto vtkWriter = Vtk::UnstructuredGridWriter(Vtk::LagrangeDataCollector(gridView,order)); -#else - using DataCollector = Vtk::LagrangeDataCollector<GridView,order>; - DataCollector dataCollector(gridView); - VtkUnstructuredGridWriter<GridView,DataCollector> vtkWriter(gridView, Vtk::FormatTypes::ASCII); -#endif - // Make basis for R^3-valued data auto worldBasis = makeBasis( gridView, power<3>(lagrange<order>()) ); - // The rod displacement field + // Vector-valued basis to represent directors + auto directorBasis = makeBasis( + gridView, + power<3>( + lagrange<order>() + )); + + // Compute the displacement from the deformation, because that's more easily visualized + // in ParaView BlockVector<FieldVector<double,3> > displacement(worldBasis.size()); for (std::size_t i=0; i<x.size(); i++) displacement[i] = x[i][_0].globalCoordinates(); @@ -314,23 +315,18 @@ int main (int argc, char *argv[]) try displacement -= gridEmbedding; auto displacementFunction = Functions::makeDiscreteGlobalBasisFunction<FieldVector<double,3> >(worldBasis, displacement); - vtkWriter.addPointData(displacementFunction, "displacement", 3); - - // The three director fields - using FunctionType = decltype(displacementFunction); - std::array<std::optional<FunctionType>, 3> directorFunction; - std::array<BlockVector<FieldVector<double, 3> >, 3> director; - for (int i=0; i<3; i++) - { - director[i].resize(worldBasis.size()); - for (std::size_t j=0; j<x.size(); j++) - director[i][j] = x[j][_1].director(i); - - directorFunction[i] = Functions::makeDiscreteGlobalBasisFunction<FieldVector<double,3> >(worldBasis, std::move(director[i])); - vtkWriter.addPointData(*directorFunction[i], "director " + std::to_string(i), 3); - } - vtkWriter.write(resultPath + "cosserat-rod-result"); + // Copy the orientation part of the configuration; the CosseratVTKWriter wants it that way + std::vector<Rotation<double,3> > orientationConfiguration(x.size()); + for (size_t i=0; i<x.size(); ++i) + orientationConfiguration[i] = x[i][_1]; + + CosseratVTKWriter<GridView>::write(gridView, + displacementFunction, + directorBasis, + orientationConfiguration, + order, + resultPath + "cosserat-rod-result"); } catch (Exception& e) -- GitLab