Peano
Loading...
Searching...
No Matches
RefinementControl.cpp
Go to the documentation of this file.
1#include "RefinementControl.h"
2
4#include "peano4/grid/grid.h"
6
7
11
12
28
29
31 switch (value) {
32 case exahype2::RefinementCommand::Refine: return "refine";
33 case exahype2::RefinementCommand::Keep: return "keep";
34 case exahype2::RefinementCommand::Erase: return "erase";
35 }
36 return "<undef>";
37}
38
39
40tarch::logging::Log exahype2::RefinementControl::_log( "exahype2::RefinementControl" );
41
43
44
46 _Tolerance( tolerance ) {
47}
48
49
52
53
55 _newEvents.clear();
56}
57
58
63 int lifetime
64) {
65 logTraceInWith3Arguments( "addCommand()", x, h, ::toString(command) );
66 tarch::multicore::Lock lock( _semaphore );
67
68 assertion(lifetime>=1);
69
70 switch (command) {
71 case ::exahype2::RefinementCommand::Refine:
72 {
73 tarch::la::Vector<Dimensions,double> expandedWidth = (1.0+_Tolerance) * h;
74 tarch::la::Vector<Dimensions,double> refinedMeshSize = (1.0+_Tolerance) * 1.0/3.0 * h;
75
78 x-0.5*expandedWidth,
79 expandedWidth,
80 refinedMeshSize
81 );
82
83 assertionNumericalEquals1( newEvent.getWidth(0), newEvent.getWidth(1), newEvent.toString() );
84 assertionNumericalEquals1( newEvent.getH(0), newEvent.getH(1), newEvent.toString() );
85 _newEvents.push_back( std::pair<peano4::grid::GridControlEvent,int>(newEvent, lifetime) );
86 logDebug( "addCommend()", "added refinement for x=" << x << ", h=" << h << ": " << newEvent.toString() << " (total of " << _newEvents.size() << " instructions)" );
87 }
88 break;
89 case ::exahype2::RefinementCommand::Keep:
90 break;
91 case ::exahype2::RefinementCommand::Erase:
92 {
93 tarch::la::Vector<Dimensions,double> expandedWidth = (1.0+_Tolerance) * h;
94 tarch::la::Vector<Dimensions,double> shift = 0.5 * (expandedWidth - h);
95 tarch::la::Vector<Dimensions,double> refinedMeshSize = 3.1 * h;
96
99 x-0.5 * h - shift,
100 expandedWidth,
101 refinedMeshSize
102 );
103
104 assertionNumericalEquals1( newEvent.getWidth(0), newEvent.getWidth(1), newEvent.toString() );
105 assertionNumericalEquals1( newEvent.getH(0), newEvent.getH(1), newEvent.toString() );
106 _newEvents.push_back( std::pair<peano4::grid::GridControlEvent,int>(newEvent, lifetime) );
107 logDebug( "addCommend()", "added erase for x=" << x << ", h=" << h << ": " << newEvent.toString() << " (total of " << _newEvents.size() << " instructions)" );
108 }
109 break;
110 }
111 logTraceOutWith1Argument( "addCommand()", _newEvents.size() );
112}
113
114
116 std::ostringstream msg;
117 msg << "("
118 << "#events=" << _newEvents.size()
119 << ")";
120 return msg.str();
121}
#define assertionNumericalEquals1(lhs, rhs, a)
#define assertion(expr)
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
#define logTraceOutWith1Argument(methodName, argument0)
Definition Log.h:380
#define logTraceInWith3Arguments(methodName, argument0, argument1, argument2)
Definition Log.h:372
std::string toString(exahype2::RefinementCommand value)
exahype2::RefinementCommand operator&&(exahype2::RefinementCommand lhs, exahype2::RefinementCommand rhs)
If one of the flags says refine, then refine.
void clear()
Clears the new events.
static tarch::logging::Log _log
RefinementControl(double tolerance=0.01)
void addCommand(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > &h, exahype2::RefinementCommand command, int lifetime)
Add a new command.
static tarch::multicore::BooleanSemaphore _semaphore
Log Device.
Definition Log.h:516
Create a lock around a boolean semaphore region.
Definition Lock.h:19
std::string toString(Filter filter)
Definition convert.cpp:170
RefinementCommand getDefaultRefinementCommand()
The default is coarsen as this is the lowest priority command.
tarch::la::Vector< Dimensions, double > getWidth() const
tarch::la::Vector< Dimensions, double > getH() const
Simple vector class.
Definition Vector.h:134