VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
L2NormMathematicaAssistant.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//=======================================================================================
34
38
39#include <sstream>
40
41
42std::shared_ptr<L2NormMathematicaAssistant> L2NormMathematicaAssistant::getNewInstance(std::shared_ptr<MathematicaFunctionFactory> functionFactory)
43{
44 return std::shared_ptr<L2NormMathematicaAssistant>(new L2NormMathematicaAssistant(functionFactory));
45}
46
47void L2NormMathematicaAssistant::makeMathematicaOutput(std::shared_ptr<LogFileDataGroup> logFileData, std::shared_ptr<MathematicaFile> aMathmaticaFile)
48{
49 std::shared_ptr<SortedDataL2Norm> mySortedData = sortLogFileData(logFileData);
50
51 makeL2NormDiffMathematicaOutput(aMathmaticaFile, mySortedData);
52 makeL2NormBasicTimeStepMathematicaOutput(aMathmaticaFile, mySortedData);
53 makeL2NormDivergentTimeStepMathematicaOutput(aMathmaticaFile, mySortedData);
54}
55
56L2NormMathematicaAssistant::L2NormMathematicaAssistant(std::shared_ptr<MathematicaFunctionFactory> functionFactory) : MathematicaAssistantImp(functionFactory)
57{
58}
59
60bool L2NormMathematicaAssistant::checkTestParameter(std::shared_ptr<L2NormLogFileData> logFileData1, std::shared_ptr<L2NormLogFileData> logFileData2)
61{
62 if (logFileData1->getDataToCalc() != logFileData2->getDataToCalc())
63 return false;
64 if (logFileData1->getNormalizeData() != logFileData2->getNormalizeData())
65 return false;
66 if (logFileData1->getBasicTimeStep() != logFileData2->getBasicTimeStep())
67 return false;
68 if (logFileData1->getDivergentTimeStep() != logFileData2->getDivergentTimeStep())
69 return false;
70
71
72 return true;
73}
74
75std::shared_ptr<SortedDataL2Norm> L2NormMathematicaAssistant::sortLogFileData(std::shared_ptr<LogFileDataGroup> logFileData)
76{
77 std::vector<std::vector<std::shared_ptr<L2NormLogFileData> > > testLogFileData;
78 std::vector<std::vector<std::string> > basicListNames;
79 for (int i = 0; i < logFileData->getLogFileData(0)->getL2NormLogFileData().size(); i++) {
80 std::vector<std::shared_ptr<L2NormLogFileData> > aTestLogFileDataGroup;
81 aTestLogFileDataGroup.push_back(logFileData->getLogFileData(0)->getL2NormLogFileData().at(i));
82 std::vector<std::string> aListNameGroup;
83 aListNameGroup.push_back(logFileData->getLogFileData(0)->getSimulationSigniture());
84 basicListNames.push_back(aListNameGroup);
85 }
86 for (int i = 0; i < logFileData->getGroupSize(); i++) {
87 for (int j = 0; j < logFileData->getLogFileData(i)->getL2NormLogFileData().size(); j++) {
88 std::string dataToCalc = logFileData->getLogFileData(i)->getL2NormLogFileData().at(j)->getDataToCalc();
89 bool added = false;
90 for (int k = 0; k < testLogFileData.size(); k++) {
91 if (checkTestParameter(logFileData->getLogFileData(i)->getL2NormLogFileData().at(j), testLogFileData.at(k).at(0))) {
92 testLogFileData.at(k).push_back(logFileData->getLogFileData(i)->getL2NormLogFileData().at(j));
93 basicListNames.at(k).push_back(logFileData->getLogFileData(i)->getSimulationSigniture());
94 added = true;
95 }
96 }
97 if (!added) {
98 std::vector<std::shared_ptr<L2NormLogFileData> > aTestLogFileDataGroup;
99 aTestLogFileDataGroup.push_back(logFileData->getLogFileData(i)->getL2NormLogFileData().at(j));
100 testLogFileData.push_back(aTestLogFileDataGroup);
101 std::vector<std::string> aListNameGroup;
102 aListNameGroup.push_back(logFileData->getLogFileData(i)->getSimulationSigniture());
103 basicListNames.push_back(aListNameGroup);
104 }
105 }
106 }
107 std::shared_ptr<SortedDataL2Norm> mySortedData = std::shared_ptr<SortedDataL2Norm>(new SortedDataL2Norm);
108 mySortedData->basicListNames = basicListNames;
109 mySortedData->testLogFileData = testLogFileData;
110
111 return mySortedData;
112}
113
114void L2NormMathematicaAssistant::makeL2NormDiffMathematicaOutput(std::shared_ptr<MathematicaFile> aMathmaticaFile, std::shared_ptr<SortedDataL2Norm> sortedData)
115{
116 for (int i = 0; i < sortedData->testLogFileData.size(); i++) {
117 std::vector<std::vector<double> > gridLengths;
118 std::vector<std::vector<double> > l2NormDiff;
119 std::vector<std::string> aBasicListNamesList;
120 for (int j = 0; j < sortedData->testLogFileData.at(i).size(); j++) {
121 gridLengths.push_back(sortedData->testLogFileData.at(i).at(j)->getBasicGridLengths());
122 l2NormDiff.push_back(sortedData->testLogFileData.at(i).at(j)->getL2NormDiff());
123 aBasicListNamesList.push_back(sortedData->basicListNames.at(i).at(j));
124 }
125 std::vector<std::string> finalListNames = finalizeListNames(aBasicListNamesList, "L2NormDiff", sortedData->testLogFileData.at(i).at(0)->getDataToCalc(), sortedData->testLogFileData.at(i).at(0)->getNormalizeData());
126
129 addListLogLogPlotToMathematicaFile(aMathmaticaFile, finalListNames, gridLengths, l2NormDiff, "L[dx]", "L2NormDiff[-]");
130 }
131}
132
133void L2NormMathematicaAssistant::makeL2NormAllTimeStepsMathematicaOutput(std::shared_ptr<MathematicaFile> aMathmaticaFile, std::shared_ptr<SortedDataL2Norm> sortedData)
134{
135 for (int i = 0; i < sortedData->testLogFileData.size(); i++) {
136 std::vector<std::vector<double> > gridLengths;
137 std::vector<std::vector<double> > l2Norm;
138 std::vector<std::string> aBasicListNamesList;
139 std::vector<std::string> basicTimeSteps;
140 for (int j = 0; j < sortedData->testLogFileData.at(i).size(); j++) {
141 gridLengths.push_back(sortedData->testLogFileData.at(i).at(j)->getBasicGridLengths());
142 gridLengths.push_back(sortedData->testLogFileData.at(i).at(j)->getBasicGridLengths());
143 l2Norm.push_back(sortedData->testLogFileData.at(i).at(j)->getL2NormForBasicTimeStep());
144 l2Norm.push_back(sortedData->testLogFileData.at(i).at(j)->getL2NormForDivergentTimeStep());
145 aBasicListNamesList.push_back(sortedData->basicListNames.at(i).at(j));
146 aBasicListNamesList.push_back(sortedData->basicListNames.at(i).at(j));
147 std::ostringstream aBasicTimeStep;
148 aBasicTimeStep << "TimeStep" << sortedData->testLogFileData.at(i).at(j)->getBasicTimeStep();
149 basicTimeSteps.push_back(aBasicTimeStep.str());
150 std::ostringstream aDivTimeStep;
151 aDivTimeStep << "TimeStep" << sortedData->testLogFileData.at(i).at(j)->getDivergentTimeStep();
152 basicTimeSteps.push_back(aDivTimeStep.str());
153 }
154
155 std::vector<std::string> finalListNamesBasic = finalizeListNames(aBasicListNamesList, "L2NormAllTimeSteps", sortedData->testLogFileData.at(i).at(0)->getDataToCalc(), sortedData->testLogFileData.at(i).at(0)->getNormalizeData(), basicTimeSteps);
156
158 }
159}
160
161void L2NormMathematicaAssistant::makeL2NormBasicTimeStepMathematicaOutput(std::shared_ptr<MathematicaFile> aMathmaticaFile, std::shared_ptr<SortedDataL2Norm> sortedData)
162{
163 for (int i = 0; i < sortedData->testLogFileData.size(); i++) {
164 std::vector<std::vector<double> > gridLengths;
165 std::vector<std::vector<double> > l2NormBasic;
166 std::vector<std::string> aBasicListNamesList;
167 for (int j = 0; j < sortedData->testLogFileData.at(i).size(); j++) {
168 gridLengths.push_back(sortedData->testLogFileData.at(i).at(j)->getBasicGridLengths());
169 l2NormBasic.push_back(sortedData->testLogFileData.at(i).at(j)->getL2NormForBasicTimeStep());
170 aBasicListNamesList.push_back(sortedData->basicListNames.at(i).at(j));
171 }
172 std::ostringstream basicTimeStep;
173 basicTimeStep << "TimeStep" << sortedData->testLogFileData.at(i).at(0)->getBasicTimeStep();
174 std::vector<std::string> finalListNamesBasic = finalizeListNames(aBasicListNamesList, "L2Norm", sortedData->testLogFileData.at(i).at(0)->getDataToCalc(), sortedData->testLogFileData.at(i).at(0)->getNormalizeData(), basicTimeStep.str());
175
179 }
180}
181
182void L2NormMathematicaAssistant::makeL2NormDivergentTimeStepMathematicaOutput(std::shared_ptr<MathematicaFile> aMathmaticaFile, std::shared_ptr<SortedDataL2Norm> sortedData)
183{
184 for (int i = 0; i < sortedData->testLogFileData.size(); i++) {
185 std::vector<std::vector<double> > gridLengths;
186 std::vector<std::vector<double> > l2NormDivergent;
187 std::vector<std::string> aBasicListNamesList;
188 for (int j = 0; j < sortedData->testLogFileData.at(i).size(); j++) {
189 gridLengths.push_back(sortedData->testLogFileData.at(i).at(j)->getBasicGridLengths());
190 l2NormDivergent.push_back(sortedData->testLogFileData.at(i).at(j)->getL2NormForDivergentTimeStep());
191 aBasicListNamesList.push_back(sortedData->basicListNames.at(i).at(j));
192 }
193 std::ostringstream divTimeStep;
194 divTimeStep << "TimeStep" << sortedData->testLogFileData.at(i).at(0)->getDivergentTimeStep();
195 std::vector<std::string> finalListNamesDiv = finalizeListNames(aBasicListNamesList, "L2Norm", sortedData->testLogFileData.at(i).at(0)->getDataToCalc(), sortedData->testLogFileData.at(i).at(0)->getNormalizeData(), divTimeStep.str());
196
200 }
201}
202
203L2NormMathematicaAssistant::L2NormMathematicaAssistant()
204{
205}
206
std::shared_ptr< MathematicaFunctionFactory > functionFactory
std::vector< std::string > finalizeListNames(std::vector< std::string > basicListNames, std::string testName, std::string dataToCalc)
void makeMathematicaOutput(std::shared_ptr< LogFileDataGroup > logFileData, std::shared_ptr< MathematicaFile > aMathmaticaFile)
void addListLogLogPlotToMathematicaFile(std::shared_ptr< MathematicaFile > aMathmaticaFile, std::vector< std::string > listNames, std::vector< std::vector< double > > xAxesData, std::vector< std::vector< double > > yAxesData, std::string labelXAxes, std::string labelYAxes)
static std::shared_ptr< L2NormMathematicaAssistant > getNewInstance(std::shared_ptr< MathematicaFunctionFactory > functionFactory)
void addSecondOrderOfAccuracyRef(std::vector< std::vector< double > > &xAxesData, std::vector< std::vector< double > > &yAxesData, std::vector< std::string > &listNames)
void addFourthOrderOfAccuracyRef(std::vector< std::vector< double > > &xAxesData, std::vector< std::vector< double > > &yAxesData, std::vector< std::string > &listNames)
std::shared_ptr< T > SPtr