Peano 4
Loading...
Searching...
No Matches
MyObserver.cpp
Go to the documentation of this file.
1#include "MyObserver.h"
2
5#include "peano4/parallel/Tasks.h"
7
10
13
14
15tarch::logging::Log examples::regulargridupscaling::MyObserver::_log( "examples::regulargridupscaling::MyObserver" );
18
19
20examples::regulargridupscaling::MyObserver::MyObserver(int spacetreeId, double h, int flopsPerCell):
21 _spacetreeId(spacetreeId),
22 _h(h),
23 _flopsPerCell(flopsPerCell),
24 _accumulator(0.0) {
25}
26
27
30
31
35) {
36 _accumulator = 0.0;
37 _taskAccumulator = 0.0;
38}
39
40
48
49
52) {
53 if (
54 event.getIsRefined()==false
55 and
56 event.getCellData() != TraversalObserver::NoData
57 ) {
58 for (int i=0; i<_flopsPerCell; i++) {
59 _accumulator += 1.0;
60 }
61
62 if (_spacetreeId==0) {
63 _taskAccumulator += std::abs(FractionOfCellsYieldingIntegrationTask) * tarch::multicore::Core::getInstance().getNumberOfThreads();
64 }
65
66 if (_taskAccumulator>=1.0) {
67 _taskAccumulator -= 1.0;
68 assertion(IntegrationAccuracy>=1);
69 peano4::parallel::Tasks(
70 [&]() -> bool {
73 event.getX(), event.getH(), IntegrationAccuracy,
74 [](const tarch::la::Vector<Dimensions,double>& x) -> double {
75 const double Theta = 32.0;
76 return 1.0
77 + 0.3/Dimensions * std::exp(-Theta * x(0)) * std::cos( tarch::la::PI * x(0) * Theta )
78 + 0.3/Dimensions * std::exp(-Theta * x(1)) * std::cos( tarch::la::PI * x(1) * Theta );
79 }
80 );
81 // just to ensure we cannot remove it.
82 _accumulator += tarch::la::frobeniusNorm(localStiffnessMatrix);
83 return false;
84 },
85 FractionOfCellsYieldingIntegrationTask<0 ? peano4::parallel::Tasks::TaskType::Sequential : peano4::parallel::Tasks::TaskType::Task,
86 peano4::parallel::Tasks::getLocationIdentifier( "examples::regulargridupscaling::MyObserver::enterCell" )
87 );
88 }
89 }
90}
91
92
97
98
100 return new MyObserver( spacetreeId, _h, _flopsPerCell );
101}
102
103
104std::vector< peano4::grid::GridControlEvent > examples::regulargridupscaling::MyObserver::getGridControlEvents() {
105 std::vector< peano4::grid::GridControlEvent > controlEvents;
106
109 #if Dimensions==2
110 newEvent.setOffset( {0.0,0.0} );
111 newEvent.setWidth( {1.0,1.0} );
112 newEvent.setH( {_h,_h} );
113 #elif Dimensions==3
114 newEvent.setOffset( {0.0,0.0,0.0} );
115 newEvent.setWidth( {1.0,1.0,1.0} );
116 newEvent.setH( {_h,_h,_h} );
117 #endif
118 controlEvents.push_back(newEvent);
119
120 return controlEvents;
121}
#define assertion(expr)
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
static tarch::logging::Log _log
Definition MyObserver.h:20
void enterCell(const peano4::grid::GridTraversalEvent &event) override
Event is invoked per cell.
std::vector< peano4::grid::GridControlEvent > getGridControlEvents() override
void leaveCell(const peano4::grid::GridTraversalEvent &event) override
void endTraversal(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > &h) override
MyObserver(int spacetreeId, double h, int flopsPerCell)
TraversalObserver * clone(int spacetreeId) override
I use the clone to create one observer object per traversal thread.
void beginTraversal(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > &h) override
Begin the traversal.
Static (i.e.
Definition Matrix.h:31
Log Device.
Definition Log.h:516
static Core & getInstance()
Definition Core.cpp:55
int getNumberOfThreads() const
Returns the number of threads that is used.
Definition Core.cpp:66
Scalar frobeniusNorm(const Matrix< Rows, Cols, Scalar > &matrix)
bool processPendingTasks(int maxTasks=std::numeric_limits< int >::max(), bool fifo=true)
Process a few tasks from my backlog of tasks.
Definition Tasks.cpp:240
ElementWiseAssemblyMatrix getPoissonMatrixWithJumpingCoefficient(const tarch::la::Vector< Dimensions, double > &cellCentre, const tarch::la::Vector< Dimensions, double > &h, int integrationPointsPerAxis, std::function< double(const tarch::la::Vector< Dimensions, double > &)>)
Integrate over element with a subvoxel scheme (cmp.
void setOffset(const tarch::la::Vector< Dimensions, double > &value)
void setH(const tarch::la::Vector< Dimensions, double > &value)
void setRefinementControl(RefinementControl value)
void setWidth(const tarch::la::Vector< Dimensions, double > &value)
tarch::la::Vector< Dimensions, double > getH() const
tarch::la::Vector< Dimensions, double > getX() const
Simple vector class.
Definition Vector.h:134