67 const tarch::timing::Measurement& measurement,
68 const tarch::timing::Measurement& measurementBoundary,
69 const tarch::timing::Measurement& measurementReconstruct,
70 const tarch::timing::Measurement& measurementRiemann,
71 const tarch::timing::Measurement& measurementProjection
73 if (measurementBoundary.getNumberOfMeasurements() > 0) {
75 "logFinalStatistics()",
77 << measurementBoundary.getAccumulatedValue() <<
"s\t" << measurementBoundary.toString()
80 if (measurementReconstruct.getNumberOfMeasurements() > 0) {
82 "logFinalStatistics()",
84 << measurementReconstruct.getAccumulatedValue() <<
"s\t" << measurementReconstruct.toString()
87 if (measurementRiemann.getNumberOfMeasurements() > 0) {
89 "logFinalStatistics()",
91 << measurementRiemann.getAccumulatedValue() <<
"s\t" << measurementRiemann.toString()
94 if (measurementProjection.getNumberOfMeasurements() > 0) {
96 "logFinalStatistics()",
98 << measurementProjection.getAccumulatedValue() <<
"s\t" << measurementProjection.toString()
102 if (measurement.getNumberOfMeasurements() > 0) {
104 "logFinalStatistics()",
106 << measurement.getAccumulatedValue() <<
"s\t" << measurement.toString()
109 const auto globalNumberOfPatches = _cells.size();
110 const auto totalNumberOfDoFs = globalNumberOfPatches
111 * std::pow(AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch, DIMENSIONS)
112 * (AbstractFVSolver::NumberOfUnknowns + AbstractFVSolver::NumberOfAuxiliaryVariables);
115 "logFinalStatistics()",
116 "Average patch updates per second: " << globalNumberOfPatches / measurement.getValue()
119 "logFinalStatistics()",
120 "Average DoF updates per second: " << totalNumberOfDoFs / measurement.getValue()
126 repositories::startPlottingStep();
128 const std::string outputDirectory =
"solutions";
129 const std::string solutionFileName =
"FVSolver";
131 const double t = 0.5 * (repositories::getMinTimeStamp() + repositories::getMaxTimeStamp());
133 static tarch::plotter::PVDTimeSeriesWriter timeSeriesWriter;
134 tarch::plotter::VTUFileWriter fileWriter(outputDirectory, 1);
135 tarch::plotter::AMRPlotter amrPlotter(fileWriter, 0, 0.5, 0.0);
137 auto cellDataPlotter = fileWriter.createCellDataPlotter(0,
"FVSolverQ", AbstractFVSolver::NumberOfUnknowns);
139 for (
auto& marker : _cells) {
140 if (not marker.hasBeenRefined()) {
141 const auto& patchSize = marker.getH();
142 const auto& patchOffset = marker.getX() - patchSize * 0.5;
144 const auto cellSize = patchSize /
static_cast<double>(AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch);
148 dfor(k, AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch) {
150 tarch::la::Vector<2, double> cellOffset;
151 cellOffset(0) = patchOffset(0) +
static_cast<double>(k(0)) *
cellSize(0);
152 cellOffset(1) = patchOffset(1) +
static_cast<double>(k(1)) *
cellSize(1);
153 const int cellIndex = amrPlotter.plotCell2D(cellOffset,
cellSize, 0);
155 tarch::la::Vector<3, double> cellOffset;
156 cellOffset(0) = patchOffset(0) +
static_cast<double>(k(0)) *
cellSize(0);
157 cellOffset(1) = patchOffset(1) +
static_cast<double>(k(1)) *
cellSize(1);
158 cellOffset(2) = patchOffset(2) +
static_cast<double>(k(2)) *
cellSize(2);
159 const int cellIndex = amrPlotter.plotCell3D(cellOffset,
cellSize, 0);
162 const auto* values = QOut + currentDoF;
163 cellDataPlotter->plotCellData(cellIndex, values, AbstractFVSolver::NumberOfUnknowns);
165 currentDoF += AbstractFVSolver::NumberOfUnknowns;
170 timeSeriesWriter.writeSnapshotFile(solutionFileName, t, fileWriter);
171 timeSeriesWriter.writeTimeSeriesMetaFile(outputDirectory, solutionFileName);
173 repositories::finishPlottingStep();
177 for (
auto& marker : _cells) {
178 if (marker.getH()[0] <
CellSize[0]) {
179 auto parentSize = marker.getH() * 3.0;
180 auto parentCenter = marker.getInvokingParentCellsCentre();
182 for (
int f = 0; f < TWO_TIMES_D; f++) {
183 int normal = f % DIMENSIONS;
184 if ((f >= DIMENSIONS and marker.getRelativePositionWithinFatherCell()[normal] == 2)
185 or (f < DIMENSIONS and marker.getRelativePositionWithinFatherCell()[normal] == 0)) {
186 peano4::datamanagement::FaceMarker faceMarker{};
187 faceMarker.relativePositionWithinFatherCell = marker.getRelativePositionWithinFatherCell();
188 faceMarker.selectedFace = f;
191 toolbox::blockstructured::restrictInnerHalfOfHaloLayer_AoS_inject(
193 AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch,
195 AbstractFVSolver::NumberOfUnknowns,
204 for (
auto& marker : _cells) {
205 if (marker.getH()[0] <
CellSize[0]) {
206 auto parentCenter = marker.getInvokingParentCellsCentre();
207 auto parentSize = marker.getH() * 3.0;
209 for (
int f = 0; f < TWO_TIMES_D; f++) {
210 int normal = f % DIMENSIONS;
211 if ((f >= DIMENSIONS and marker.getRelativePositionWithinFatherCell()[normal] == 2)
212 or (f < DIMENSIONS and marker.getRelativePositionWithinFatherCell()[normal] == 0)) {
213 peano4::datamanagement::FaceMarker faceMarker{};
214 faceMarker.relativePositionWithinFatherCell = marker.getRelativePositionWithinFatherCell();
215 faceMarker.selectedFace = f;
218 toolbox::blockstructured::interpolateHaloLayer_AoS_piecewise_constant(
220 AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch,
222 AbstractFVSolver::NumberOfUnknowns,
267 const tarch ::la ::Vector<DIMENSIONS, int>& index
269 tarch::la::Vector<DIMENSIONS, double> cellIndex = tarch::la::convertScalar<double>(index);
270 tarch::la::Vector<DIMENSIONS, double> deeperCellIndex = cellIndex * 3.0;
271 tarch::la::Vector<DIMENSIONS, double> deeperCellSize =
CellSize / 3.0;
272 tarch::la::Vector<DIMENSIONS, double> cellPositionBase = DomainOffset +
CellSize / 2.0;
273 tarch::la::Vector<DIMENSIONS, double> deepercellPositionBase = DomainOffset + deeperCellSize / 2.0;
275 std::vector<peano4::datamanagement::CellMarker> result;
277 tarch::la::Vector<DIMENSIONS, double>
278 cellPosition = cellPositionBase + tarch::la::multiplyComponents(cellIndex,
CellSize);
279 peano4::datamanagement::CellMarker marker;
280 marker.centre = cellPosition;
282 marker.flags |= peano4::datamanagement::CellMarker::HasBeenRefined;
283 result.push_back(marker);
286 tarch::la::Vector<DIMENSIONS, double> deepCellOffset = tarch::la::convertScalar<double>(offset);
287 tarch::la::Vector<DIMENSIONS, double> localCellIndex = deepCellOffset + deeperCellIndex;
288 tarch::la::Vector<DIMENSIONS, double>
289 deeperCellPosition = deepercellPositionBase + tarch::la::multiplyComponents(localCellIndex, deeperCellSize);
290 peano4::datamanagement::CellMarker marker;
291 marker.centre = deeperCellPosition;
292 marker.h = deeperCellSize;
293 marker.relativePositionWithinFatherCell = offset;
294 result.push_back(marker);
321int main(
int argc,
char** argv) {
322 int returnCode = EXIT_SUCCESS;
324 peano4::init(&argc, &argv, DomainOffset, DomainSize);
326 repositories::loadBalancer.enable(
false);
327 repositories::initLogFilters();
328 repositories::startSimulation();
335 for (
auto& marker : _cells) {
336 if (not marker.hasBeenRefined()) {
343 benchmarks::exahype2::kernelbenchmarks::kernels::FVSolver::projectPatchFused(
351 tarch::timing::Measurement measurement(1.0);
352 tarch::timing::Measurement measurementBoundary(1.0);
353 tarch::timing::Measurement measurementReconstruct(1.0);
354 tarch::timing::Measurement measurementRiemann(1.0);
355 tarch::timing::Measurement measurementProjection(1.0);
356 tarch::timing::Watch timeStepWatch(
"::",
"main()",
false);
358 double nextMinPlotTimeStamp = FirstPlotTimeStamp;
359 double nextMaxPlotTimeStamp = FirstPlotTimeStamp;
360 bool continueToSolve =
true;
363 while (continueToSolve) {
364 if (Samples > 0 and count++ >= Samples) {
365 continueToSolve =
false;
367 if (repositories::getMinTimeStamp() >= nextMinPlotTimeStamp
368 or repositories::getMaxTimeStamp() >= nextMaxPlotTimeStamp) {
369 if (repositories::getMinTimeStamp() >= nextMinPlotTimeStamp) {
370 nextMinPlotTimeStamp += TimeInBetweenPlots;
372 if (repositories::getMaxTimeStamp() >= nextMaxPlotTimeStamp) {
373 nextMaxPlotTimeStamp += TimeInBetweenPlots;
376 if constexpr (ShouldPlot) {
393 benchmarks::exahype2::kernelbenchmarks::kernels::FVSolver::projectPatchFused(
402 timeStepWatch.start();
403 repositories::startTimeStep();
405 double dt = repositories::instanceOfFVSolver.getAdmissibleTimeStepSize();
407 tarch::timing::Watch watch(
"",
"",
false);
410 tarch::timing::Watch watchBoundary(
"",
"",
false);
411 watchBoundary.start();
412 benchmarks::exahype2::kernelbenchmarks::kernels::FVSolver::handleBoundaryFused(
413 repositories::instanceOfFVSolver,
426 watchBoundary.stop();
428 tarch::timing::Watch watchReconstruct(
"",
"",
false);
429 watchReconstruct.start();
430 benchmarks::exahype2::kernelbenchmarks::kernels::FVSolver::reconstructPatchFused(
438 watchReconstruct.stop();
440 tarch::timing::Watch watchRiemann(
"",
"",
false);
441 watchRiemann.start();
442 const auto maxEigenvalue = benchmarks::exahype2::kernelbenchmarks::kernels::FVSolver::riemannSolverFused(
443 repositories::instanceOfFVSolver,
455 tarch::timing::Watch watchProjection(
"",
"",
false);
456 watchProjection.start();
457 benchmarks::exahype2::kernelbenchmarks::kernels::FVSolver::projectPatchFused(
464 watchProjection.stop();
467 measurement.setValue(watch.getCalendarTime());
468 measurementBoundary.setValue(watchBoundary.getCalendarTime());
469 measurementReconstruct.setValue(watchReconstruct.getCalendarTime());
470 measurementRiemann.setValue(watchRiemann.getCalendarTime());
471 measurementProjection.setValue(watchProjection.getCalendarTime());
473 repositories::instanceOfFVSolver.setMaxEigenvalue(maxEigenvalue);
474 const auto newTimeStepSize = repositories::instanceOfFVSolver.getAdmissibleTimeStepSize();
475 repositories::instanceOfFVSolver
478 timeStamp += repositories::instanceOfFVSolver.getAdmissibleTimeStepSize();
479 repositories::finishTimeStep();
481 timeStepWatch.stop();
487 const auto globalNumberOfPatches = _cells.size();
488 const auto totalNumberOfDoFs
489 = globalNumberOfPatches * std::pow(AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch, DIMENSIONS)
490 * (AbstractFVSolver::NumberOfUnknowns + AbstractFVSolver::NumberOfAuxiliaryVariables);
492 std::ostringstream msg;
494 <<
"Patches=" << toScientificNotationString(globalNumberOfPatches) <<
", DoFs="
495 << toScientificNotationString(totalNumberOfDoFs) <<
", Memory=" << std::fixed << std::setprecision(2)
496 << tarch::convertMemorySize(totalPersistentMemory, tarch::chooseMemoryUsageFormat(totalPersistentMemory)) <<
" "
497 << tarch::toString(tarch::chooseMemoryUsageFormat(totalPersistentMemory));
498 logInfo(
"main()", msg.str());
501 const auto dt = measurement.getMostRecentValue();
502 const auto patchesPerSecond = globalNumberOfPatches / dt;
503 const auto dofsPerSecond = totalNumberOfDoFs / dt;
507 "Patch updates per second: "
508 << toScientificNotationString(patchesPerSecond)
509 <<
", DoF updates per second: " << toScientificNotationString(dofsPerSecond)
513 repositories::logTimeStep();
514 logNextTimeStep += repositories::LogTimeStepIntervalInSeconds;
517 if (repositories::getMinTimeStamp() >= MinTerminalTime and repositories::getMaxTimeStamp() >= MaxTerminalTime) {
518 continueToSolve =
false;
521 if (tarch::hasNonCriticalAssertionBeenViolated() and not haveReceivedNonCriticalAssertion) {
522 continueToSolve =
false;
523 haveReceivedNonCriticalAssertion =
true;
524 logError(
"main()",
"Noncritical assertion has been triggered in code. Dump final state and terminate.");
529 if constexpr (ShouldPlot) {
533 repositories::finishSimulation();
535 if (haveReceivedNonCriticalAssertion) {
536 logWarning(
"main()",
"Terminated gracefully after noncritical assertion");
537 returnCode = EXIT_FAILURE;
540 repositories::logTimeStep();
541 logInfo(
"main()",
"Terminated successfully");
542 returnCode = EXIT_SUCCESS;
548 measurementReconstruct,
550 measurementProjection
const tarch::la::Vector< DIMENSIONS, double > cellSize
const tarch::la::Vector< DIMENSIONS, double > CellSize
tarch::timing::Measurement timeStepMeasurement
tarch::logging::Log _log("::")
peano4::datamanagement::CellMarker createMarkerFromIndex(const tarch ::la ::Vector< DIMENSIONS, int > &index)
int main(int argc, char **argv)
void logFinalStatistics(const tarch::timing::Measurement &measurement, const tarch::timing::Measurement &measurementBoundary, const tarch::timing::Measurement &measurementReconstruct, const tarch::timing::Measurement &measurementRiemann, const tarch::timing::Measurement &measurementProjection)
std::vector< peano4::datamanagement::CellMarker > createRefinedMarkersFromIndex(const tarch ::la ::Vector< DIMENSIONS, int > &index)