Peano 4
Loading...
Searching...
No Matches
TraversalVTKPlotter.cpp
Go to the documentation of this file.
2#include "Spacetree.h"
3#include "GridControlEvent.h"
5
6#include "peano4/utils/Loop.h"
8
9#include "tarch/mpi/Rank.h"
10#include "tarch/mpi/Lock.h"
13
16
17#include <string>
18
19tarch::logging::Log peano4::grid::TraversalVTKPlotter::_log( "peano4::grid::TraversalVTKPlotter" );
21
22peano4::grid::TraversalVTKPlotter::TraversalVTKPlotter( const std::string& filename, int treeId ):
23 _filename(filename),
24 _spacetreeId(treeId),
25 _writer(nullptr),
26 _vertexWriter(nullptr),
27 _cellWriter(nullptr),
28 _spacetreeIdWriter(nullptr),
29 _coreWriter(nullptr) {
30}
31
33
35 [[maybe_unused]] const tarch::la::Vector<Dimensions,double>& x,
36 [[maybe_unused]] const tarch::la::Vector<Dimensions,double>& h
37) {
38 static int counter = -1;
39 counter++;
40
41 std::ostringstream snapshotFileName;
42 snapshotFileName << _filename << "-" << counter;
43
44 if (tarch::mpi::Rank::getInstance().getNumberOfRanks()>0 ) {
45 snapshotFileName << "-rank-" << tarch::mpi::Rank::getInstance().getRank();
46 }
47
48 tarch::mpi::Lock lock( _sempahore );
49
51 snapshotFileName.str(),
52 _filename,
54 0.0
55 );
56
57 _vertexWriter = _writer->createVertexWriter();
58 _cellWriter = _writer->createCellWriter();
59 _spacetreeIdWriter = _writer->createCellDataWriter( "tree-id", 1 );
60 _coreWriter = _writer->createCellDataWriter( "core-number", 1 );
61}
62
64 [[maybe_unused]] const tarch::la::Vector<Dimensions,double>& x,
65 [[maybe_unused]] const tarch::la::Vector<Dimensions,double>& h
66) {
67 assertion(_writer!=nullptr);
68
69 _vertexWriter->close();
70 _cellWriter->close();
71 _spacetreeIdWriter->close();
72 _coreWriter->close();
73
74 if (_spacetreeId>=0) {
75 _writer->writeToFile();
76 }
77
78 delete _writer;
79 delete _vertexWriter;
80 delete _cellWriter;
81 delete _spacetreeIdWriter;
82 delete _coreWriter;
83
84 _writer = nullptr;
85 _vertexWriter = nullptr;
86 _cellWriter = nullptr;
87 _spacetreeIdWriter = nullptr;
88 _coreWriter = nullptr;
89
90}
91
93 [[maybe_unused]] const GridTraversalEvent& event
94) {}
95
97 [[maybe_unused]]const GridTraversalEvent& event
98) {}
99
101 const GridTraversalEvent& event
102) {
103 bool plot = event.getWillBeRefined()==0 and event.getIsCellLocal();
104 if (plot) {
105 plotCell(event);
106 }
107}
108
110 const GridTraversalEvent& event
111) {
112 int vertexIndices[TwoPowerD];
113
114 dfor2(k)
115 assertion( _vertexWriter!=nullptr );
116 vertexIndices[kScalar] = _vertexWriter->plotVertex(
117 event.getX() + tarch::la::multiplyComponents( tarch::la::convertScalar<double>(k), event.getH() ) - event.getH() * 0.5
118 );
120
121 assertion( _cellWriter!=nullptr );
122 int cellIndex = -1;
123
124 #if Dimensions==2
125 cellIndex = _cellWriter->plotQuadrangle(vertexIndices);
126 #elif Dimensions==3
127 cellIndex = _cellWriter->plotHexahedron(vertexIndices);
128 #else
129 logError( "enterCell(...)", "supports only 2d and 3d" );
130 #endif
131
132 assertion( _spacetreeIdWriter!=nullptr );
133 assertion( _coreWriter!=nullptr );
134 _spacetreeIdWriter->plotCell(cellIndex,_spacetreeId);
135 _coreWriter->plotCell(cellIndex,tarch::multicore::Core::getInstance().getCoreNumber());
136}
137
139 [[maybe_unused]]const GridTraversalEvent& event
140) {}
141
144 _filename,
145 spacetreeId
146 );
147}
148
149std::vector< peano4::grid::GridControlEvent > peano4::grid::TraversalVTKPlotter::getGridControlEvents() const {
150 return std::vector< peano4::grid::GridControlEvent >();
151}
#define assertion(expr)
we integrate over each cell and then take the sum across each of the cells We also consider the terms that enter the f$ k
#define TwoPowerD
Definition Globals.h:19
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:464
#define dfor2(counter)
Shortcut For dfor(counter,2)
Definition Loop.h:906
#define enddforx
I prefer to use this macro for dforx instead of a closing bracket as many syntax parser fail otherwis...
Definition Loop.h:928
Observer which pipes the automaton transitions into a VTK file.
static tarch::logging::Log _log
virtual void loadCell(const GridTraversalEvent &event) override
virtual std::vector< GridControlEvent > getGridControlEvents() const override
Obviously empty for this particular observer.
TraversalVTKPlotter(const std::string &filename, int treeId=-1)
You have to invoke startNewSnapshot() if you wanna have a pvd file immediately after you've created t...
virtual TraversalObserver * clone(int spacetreeId) override
virtual void endTraversal(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > &h) override
static tarch::mpi::BooleanSemaphore _sempahore
virtual void leaveCell(const GridTraversalEvent &event) override
virtual void beginTraversal(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > &h) override
Begin the traversal.
virtual void storeCell(const GridTraversalEvent &event) override
virtual void enterCell(const GridTraversalEvent &event) override
Event is invoked per cell.
void plotCell(const GridTraversalEvent &event)
Does the actual plotting, i.e.
Log Device.
Definition Log.h:516
Boolean semaphore across MPI ranks.
Create a lock around a boolean semaphore region.
Definition Lock.h:20
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:538
int getRank() const
Return rank of this node.
Definition Rank.cpp:528
static Core & getInstance()
Definition Core.cpp:55
-lift-drop-statistics
Matrix< Rows, Cols, Scalar > multiplyComponents(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
tarch::la::Vector< Dimensions, double > getH() const
tarch::la::Vector< Dimensions, double > getX() const
Simple vector class.
Definition Vector.h:134