VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
TestSimulationImp.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
32//=======================================================================================
33#include <functional>
34
35#include "TestSimulationImp.h"
36
48
49TestSimulationImp::TestSimulationImp(std::function<void()> runSimulation,
50 std::shared_ptr<TestSimulationDataStruct> testSimData,
51 std::shared_ptr<SimulationResults> simResult,
52 std::shared_ptr<TimeTracking> timeTracking,
53 std::shared_ptr<ToVectorWriter> toVectorWriter,
54 std::shared_ptr<AnalyticalResults2DToVTKWriter> anaResultWriter,
55 std::shared_ptr<ColorConsoleOutput> colorOutput)
56{
57 this->simPara = testSimData->simParameter;
58 this->simInfo = testSimData->simInformation;
59 this->analyticalResult = testSimData->analyticalResult;
60 this->initialCondition = testSimData->initialCondition;
61
62 this->timeTracking = timeTracking;
63
64 this->simResult = simResult;
65 this->toVectorWriter = toVectorWriter;
66
67 this->anaResultWriter = anaResultWriter;
68 this->colorOutput = colorOutput;
69
70 this->simObserver.resize(0);
71 this->dataToCalcTests = simInfo->getDataToCalcTests();
72 this->status = initialized;
73 this->runSimulation = runSimulation;
74}
75
77{
79 timeTracking->setSimulationStartTime();
80 runSimulation();
81 timeTracking->setSimulationEndTime();
83}
84
85std::shared_ptr<SimulationParameter> TestSimulationImp::getSimulationParameter()
86{
87 return simPara;
88}
89
90std::shared_ptr<AnalyticalResults> TestSimulationImp::getAnalyticalResults()
91{
92 return analyticalResult;
93}
94
95std::shared_ptr<SimulationInfo> TestSimulationImp::getSimulationInfo()
96{
97 return simInfo;
98}
99
100std::shared_ptr<TimeTracking> TestSimulationImp::getTimeTracking()
101{
102 return timeTracking;
103}
104
109
110void TestSimulationImp::registerSimulationObserver(std::shared_ptr<SimulationObserver> simObserver)
111{
112 this->simObserver.push_back(simObserver);
113}
114
116{
117 return dataToCalcTests;
118}
119
120void TestSimulationImp::notifyObserver()
121{
122 for (uint i = 0; i < simObserver.size(); i++)
123 simObserver.at(i)->update();
124}
125
126void TestSimulationImp::writeAnalyticalResultsToVTK()
127{
128 if (!analyticalResult->isCalculated())
129 analyticalResult->calc(simResult);
130
131 anaResultWriter->writeAnalyticalResult(para, analyticalResult);
132}
133
134void TestSimulationImp::checkSimulationResults()
135{
136 bool dataOkay = simResult->checkYourData();
137 if (!dataOkay)
138 status = crashed;
139}
140
142{
143 colorOutput->makeSimulationHeadOutput(simInfo);
144}
145
147{
148 status = executed;
149
150 timeTracking->setResultCheckStartTime();
151 checkSimulationResults();
152 timeTracking->setResultCheckEndTime();
153
154 timeTracking->setTestStartTime();
155 notifyObserver();
156 timeTracking->setTestEndTime();
157
158 timeTracking->setAnalyticalResultWriteStartTime();
159 writeAnalyticalResultsToVTK();
160 timeTracking->setAnalyticalResultWriteEndTime();
161}
162
163void TestSimulationImp::setParameter(std::shared_ptr<vf::gpu::Parameter> para)
164{
165 this->para = para;
166}
167
168std::shared_ptr<SimulationResults> TestSimulationImp::getSimulationResults()
169{
170 return simResult;
171}
std::shared_ptr< SimulationInfo > getSimulationInfo()
void registerSimulationObserver(std::shared_ptr< SimulationObserver > simObserver) override
std::shared_ptr< AnalyticalResults > getAnalyticalResults()
std::vector< std::string > getDataToCalcTests()
std::shared_ptr< TimeTracking > getTimeTracking() override
std::shared_ptr< SimulationParameter > getSimulationParameter() override
TestSimulationImp(std::function< void()> runSimulation, std::shared_ptr< TestSimulationDataStruct > testSimData, std::shared_ptr< SimulationResults > simResult, std::shared_ptr< TimeTracking > timeTracking, std::shared_ptr< ToVectorWriter > toVectorWriter, std::shared_ptr< AnalyticalResults2DToVTKWriter > anaResultWriter, std::shared_ptr< ColorConsoleOutput > colorOutput)
void startPostProcessing() override
SimulationStatus getSimulationStatus() override
void setParameter(std::shared_ptr< vf::gpu::Parameter > para) override
void makeSimulationHeadOutput() override
std::shared_ptr< SimulationResults > getSimulationResults()
std::shared_ptr< T > SPtr
unsigned int uint
Definition DataTypes.h:47