diff --git a/src/mesa_pd/vtk/WriteOutput.h b/src/mesa_pd/vtk/WriteOutput.h index 91ef8141fc8e6944f34f97d742cadc11a94e757b..e190e1387e0164e1f4f643b6b2e230d02319ba2e 100644 --- a/src/mesa_pd/vtk/WriteOutput.h +++ b/src/mesa_pd/vtk/WriteOutput.h @@ -59,6 +59,14 @@ void writeOutput(std::ostream& os, const Vec3& data, const uint_t component) walberla::vtk::toStream(os, data[component]); } +template <> +inline +void writeOutput(std::ostream& os, const Rot3& data, const uint_t component) +{ + WALBERLA_ASSERT_LESS(component, 3); + walberla::vtk::toStream(os, (data.getMatrix() * Vec3(1_r, 0_r, 0_r))[component]); +} + template <typename T> inline void writeOutput(walberla::vtk::Base64Writer& b64, const T& data, const uint_t component) @@ -85,6 +93,14 @@ void writeOutput(walberla::vtk::Base64Writer& b64, const Vec3& data, const uint_ b64 << data[component]; } +template <> +inline +void writeOutput(walberla::vtk::Base64Writer& b64, const Rot3& data, const uint_t component) +{ + WALBERLA_ASSERT_LESS(component, 3); + b64 << (data.getMatrix() * Vec3(1_r, 0_r, 0_r))[component]; +} + } // namespace vtk } // namespace pe } // namespace walberla diff --git a/src/vtk/VTKTrait.h b/src/vtk/VTKTrait.h index 3592dc87fca00db20c009955a50b727a51e8a874..1f451a622b1a0a0c32fe96680c328747382f9ae8 100644 --- a/src/vtk/VTKTrait.h +++ b/src/vtk/VTKTrait.h @@ -21,6 +21,7 @@ #pragma once #include <core/DataTypes.h> +#include <core/math/Rot3.h> #include <core/math/Vector3.h> namespace walberla { @@ -117,5 +118,13 @@ struct VTKTrait<math::Vector3<T>> constexpr static const uint_t components = 3; }; +template <typename T> +struct VTKTrait<math::Rot3<T>> +{ + using type = typename VTKTrait<T>::type; + constexpr static char const * const type_string = VTKTrait<T>::type_string; + constexpr static const uint_t components = 3; +}; + } // namespace vtk } // namespace walberla diff --git a/tests/mesa_pd/vtk/VTKOutputs.cpp b/tests/mesa_pd/vtk/VTKOutputs.cpp index ee1a02d47c8128422ccf58cf4833ed5b180de396..6481f053ec2e9e952aef2d4cea5068c8eaf9b2d5 100644 --- a/tests/mesa_pd/vtk/VTKOutputs.cpp +++ b/tests/mesa_pd/vtk/VTKOutputs.cpp @@ -26,6 +26,7 @@ #include <core/Environment.h> #include <core/grid_generator/SCIterator.h> #include <core/logging/Logging.h> +#include <core/math/Constants.h> #include <core/math/Random.h> #include <vtk/VTKOutput.h> @@ -50,6 +51,8 @@ int main( int argc, char ** argv ) Vector3<uint_t>(2,2,2), Vector3<bool>(false, false, false) ); + auto rank = mpi::MPIManager::instance()->rank(); + //initialize particles const Vec3 shift(real_t(0.5), real_t(0.5), real_t(0.5)); for (auto& iBlk : *forest) @@ -61,15 +64,16 @@ int main( int argc, char ** argv ) auto p = ps->create(); p->setPosition( pt ); p->setOwner( mpi::MPIManager::instance()->rank() ); + p->getRotationRef().rotate(Vec3(0_r,1_r,0_r), real_c(rank) * math::pi * 0.5_r); } } auto vtkOutput = make_shared<mesa_pd::vtk::ParticleVtkOutput>(ps); vtkOutput->addOutput<data::SelectParticleOwner>("owner"); vtkOutput->addOutput<data::SelectParticleLinearVelocity>("velocity"); - auto rank = mpi::MPIManager::instance()->rank(); + vtkOutput->addOutput<data::SelectParticleRotation>("rotation"); vtkOutput->setParticleSelector( [rank](const data::ParticleStorage::iterator& pIt) {return pIt->getIdx() < uint_c(rank);} ); - auto vtkWriter = walberla::vtk::createVTKOutput_PointData(vtkOutput, "Bodies", 1, "vtk", "simulation_step", false, false); + auto vtkWriter = walberla::vtk::createVTKOutput_PointData(vtkOutput, "particles", 1, "vtk_outputs", "simulation_step", false, false); vtkWriter->write();