1 #include "MyObserver.h"
3 #include "peano4/grid/GridControlEvent.h"
4 #include "peano4/parallel/Node.h"
5 #include "peano4/parallel/Tasks.h"
6 #include "peano4/grid/GridTraversalEvent.h"
8 #include "tarch/la/MatrixOperations.h"
9 #include "tarch/multicore/Core.h"
11 #include "toolbox/finiteelements/ElementMatrix.h"
12 #include "toolbox/finiteelements/StencilFactory.h"
21 _spacetreeId(spacetreeId),
23 _flopsPerCell(flopsPerCell),
33 const tarch::la::Vector<DIMENSIONS,double>&
x,
34 const tarch::la::Vector<DIMENSIONS,double>&
h
37 _taskAccumulator = 0.0;
42 const tarch::la::Vector<DIMENSIONS,double>&
x,
43 const tarch::la::Vector<DIMENSIONS,double>&
h
45 tarch::multicore::processPendingTasks();
46 logDebug(
"endTraversal", _accumulator );
51 const peano4::grid::GridTraversalEvent& event
54 event.getIsRefined()==
false
56 event.getCellData() != TraversalObserver::NoData
58 for (
int i=0; i<_flopsPerCell; i++) {
62 if (_spacetreeId==0) {
63 _taskAccumulator += std::abs(FractionOfCellsYieldingIntegrationTask) * tarch::multicore::Core::getInstance().getNumberOfThreads();
66 if (_taskAccumulator>=1.0) {
67 _taskAccumulator -= 1.0;
68 assertion(IntegrationAccuracy>=1);
69 peano4::parallel::Tasks(
71 tarch::la::Matrix<TWO_POWER_D,TWO_POWER_D,double> localStiffnessMatrix =
72 toolbox::finiteelements::getPoissonMatrixWithJumpingCoefficient(
73 event.getX(), event.getH(), IntegrationAccuracy,
74 [](
const tarch::la::Vector<DIMENSIONS,double>&
x) ->
double {
75 const double Theta = 32.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 );
82 _accumulator += tarch::la::frobeniusNorm(localStiffnessMatrix);
85 FractionOfCellsYieldingIntegrationTask<0 ? peano4::parallel::Tasks::TaskType::Sequential : peano4::parallel::Tasks::TaskType::Task,
86 peano4::parallel::Tasks::getLocationIdentifier(
"examples::regulargridupscaling::MyObserver::enterCell" )
94 const peano4::grid::GridTraversalEvent& event
100 return new MyObserver( spacetreeId, _h, _flopsPerCell );
105 std::vector< peano4::grid::GridControlEvent > controlEvents;
107 peano4::grid::GridControlEvent newEvent;
108 newEvent.setRefinementControl( peano4::grid::GridControlEvent::RefinementControl::Refine );
110 newEvent.setOffset( {0.0,0.0} );
111 newEvent.setWidth( {1.0,1.0} );
112 newEvent.setH( {_h,_h} );
114 newEvent.setOffset( {0.0,0.0,0.0} );
115 newEvent.setWidth( {1.0,1.0,1.0} );
116 newEvent.setH( {_h,_h,_h} );
118 controlEvents.push_back(newEvent);
120 return controlEvents;
static tarch::logging::Log _log
void enterCell(const peano4::grid::GridTraversalEvent &event) override
static double FractionOfCellsYieldingIntegrationTask
std::vector< peano4::grid::GridControlEvent > getGridControlEvents() override
void leaveCell(const peano4::grid::GridTraversalEvent &event) override
static int IntegrationAccuracy
MyObserver(int spacetreeId, double h, int flopsPerCell)
void endTraversal(const tarch::la::Vector< DIMENSIONS, double > &x, const tarch::la::Vector< DIMENSIONS, double > &h) override
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