From df734f23ab88950a85c3513cc85413e0cfa50518 Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Sun, 11 Mar 2012 22:09:06 +0100 Subject: [PATCH] Externalise evolution printing --- src/Makefile.am | 2 +- src/one-body-sample.cc | 22 +++++----------------- src/print.cc | 30 ++++++++++++++++++++++++++++++ src/print.hh | 14 ++++++++++++++ src/print_tmpl.cc | 26 ++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 src/print.cc create mode 100644 src/print.hh create mode 100644 src/print_tmpl.cc diff --git a/src/Makefile.am b/src/Makefile.am index 6e924008..b97aa8ce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,7 @@ run-one-body-sample-gdb: one-body-sample libtool --mode execute gdb ./one-body-sample one_body_sample_SOURCES = \ - one-body-sample.cc assemblers.cc LambertW.cc compute_state.cc vtk.cc + one-body-sample.cc assemblers.cc LambertW.cc compute_state.cc vtk.cc print.cc one_body_sample_CPPFLAGS = \ $(AM_CPPFLAGS) -Dsrcdir=\"$(srcdir)\" one_body_sample_LDADD = \ diff --git a/src/one-body-sample.cc b/src/one-body-sample.cc index 4d08d013..06ec0cea 100644 --- a/src/one-body-sample.cc +++ b/src/one-body-sample.cc @@ -64,6 +64,7 @@ #include "assemblers.hh" #include "compute_state.hh" +#include "print.hh" #include "vtk.hh" int const dim = 2; @@ -310,23 +311,10 @@ int main(int argc, char *argv[]) { } } - if (parset.get<bool>("printEvolution")) { - // Find the first node that belongs to the frictional boundary - for (size_t i = 0; i < frictionalNodes.size(); ++i) { - if (!frictionalNodes[i][0]) - continue; - - boost::format const formatter("s[%03d] = %+3e, " - "%|40t|u[%03d] = %+3e"); - std::cout << boost::format(formatter) % run % (*s4_new)[i] % run % - u4[i] << std::endl; - double out; - functions.get("sampleFunction").evaluate(h * run, out); - octave_writer << (*s4_new)[i] << " " << u4[i][0] * 1e6 << " " << out - << std::endl; - break; - } - } + if (parset.get<bool>("printEvolution")) + print_evolution<SingletonVectorType, VectorType>( + frictionalNodes, *s4_new, u4, functions.get("sampleFunction"), + run, h * run, octave_writer); } u4 += u4_diff; diff --git a/src/print.cc b/src/print.cc new file mode 100644 index 00000000..4441bf3d --- /dev/null +++ b/src/print.cc @@ -0,0 +1,30 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <boost/format.hpp> + +#include "print.hh" + +template <class SingletonVectorType, class VectorType> +void print_evolution(Dune::BitSetVector<1> const &frictionalNodes, + SingletonVectorType const &state, + VectorType const &displacement, + Dune::VirtualFunction<double, double> const &function, + int run, double time, std::ostream &octave_writer) { + // Find the first node that belongs to the frictional boundary + for (size_t i = 0; i < frictionalNodes.size(); ++i) { + if (!frictionalNodes[i][0]) + continue; + + double out; + function.evaluate(time, out); + std::cout << boost::format("s[%03d] = %+3e, %|20t|u[%03d] = %+3e") % run % + state[i] % run % displacement[i] << std::endl; + octave_writer << state[i][0] << " " << displacement[i][0] * 1e6 << " " + << out << std::endl; + break; + } +} + +#include "print_tmpl.cc" diff --git a/src/print.hh b/src/print.hh new file mode 100644 index 00000000..79d52066 --- /dev/null +++ b/src/print.hh @@ -0,0 +1,14 @@ +#ifndef PRINT_HH +#define PRINT_HH + +#include <dune/common/function.hh> +#include <dune/common/bitsetvector.hh> + +template <class SingletonVectorType, class VectorType> +void print_evolution(Dune::BitSetVector<1> const &frictionalNodes, + SingletonVectorType const &state, + VectorType const &displacement, + Dune::VirtualFunction<double, double> const &function, + int run, double time, std::ostream &octave_writer); + +#endif diff --git a/src/print_tmpl.cc b/src/print_tmpl.cc new file mode 100644 index 00000000..ae475a81 --- /dev/null +++ b/src/print_tmpl.cc @@ -0,0 +1,26 @@ +#include <dune/common/fvector.hh> +#include <dune/istl/bvector.hh> + +typedef Dune::BlockVector<Dune::FieldVector<double, 1>> SingletonVectorType; + +// {{{ 2D +typedef Dune::FieldVector<double, 2> SmallVector2; +typedef Dune::BlockVector<SmallVector2> VectorType2; + +template void print_evolution<SingletonVectorType, VectorType2>( + Dune::BitSetVector<1> const &frictionalNodes, + SingletonVectorType const &state, VectorType2 const &displacement, + Dune::VirtualFunction<double, double> const &function, int run, double time, + std::ostream &octave_writer); +// }}} + +// {{{ 3D +typedef Dune::FieldVector<double, 3> SmallVector3; +typedef Dune::BlockVector<SmallVector3> VectorType3; + +template void print_evolution<SingletonVectorType, VectorType3>( + Dune::BitSetVector<1> const &frictionalNodes, + SingletonVectorType const &state, VectorType3 const &displacement, + Dune::VirtualFunction<double, double> const &function, int run, double time, + std::ostream &octave_writer); +// }}} -- GitLab