VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
MathematicaAssistantImp.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
37
38#include <cmath>
39
40
44
45MathematicaAssistantImp::MathematicaAssistantImp(std::shared_ptr<MathematicaFunctionFactory> functionFactory)
46{
47 this->functionFactory = functionFactory;
48}
49
50std::vector<std::string> MathematicaAssistantImp::finalizeListNames(std::vector<std::string> basicListNames, std::string testName, std::string dataToCalc)
51{
52 std::vector<std::string> finalListNames;
53
54 for (int i = 0; i < basicListNames.size(); i++)
55 finalListNames.push_back(finalizeListName(basicListNames.at(i), testName, dataToCalc));
56
57 return finalListNames;
58}
59
60std::vector<std::string> MathematicaAssistantImp::finalizeListNames(std::vector<std::string> basicListNames, std::string testName, std::string dataToCalc, std::string normalizeData)
61{
62 std::vector<std::string> finalListNames;
63
64 for (int i = 0; i < basicListNames.size(); i++)
65 finalListNames.push_back(testName + basicListNames.at(i) + dataToCalc + normalizeData);
66
67 return finalListNames;
68}
69
70std::vector<std::string> MathematicaAssistantImp::finalizeListNames(std::vector<std::string> basicListNames, std::string testName, std::string dataToCalc, std::string normalizeData, std::string timeStep)
71{
72 std::vector<std::string> finalListNames;
73
74 for (int i = 0; i < basicListNames.size(); i++)
75 finalListNames.push_back(testName + basicListNames.at(i) + dataToCalc + normalizeData + timeStep);
76
77 return finalListNames;
78}
79
80std::vector<std::string> MathematicaAssistantImp::finalizeListNames(std::vector<std::string> basicListNames, std::string testName, std::string dataToCalc, std::string normalizeData, std::vector<std::string> timeSteps)
81{
82 std::vector<std::string> finalListNames;
83
84 for (int i = 0; i < basicListNames.size(); i++)
85 finalListNames.push_back(testName + basicListNames.at(i) + dataToCalc + normalizeData + timeSteps.at(i));
86
87 return finalListNames;
88}
89
90std::vector<std::string> MathematicaAssistantImp::finalizeListNames(std::vector<std::string> basicListNames, std::string testName, std::string dataToCalc, std::string normalizeData, std::vector<std::string> timeSteps, std::vector<std::string> basicKernels)
91{
92 std::vector<std::string> finalListNames;
93
94 for (int i = 0; i < basicListNames.size(); i++)
95 finalListNames.push_back(testName + basicListNames.at(i) + dataToCalc + normalizeData + timeSteps.at(i) + basicKernels.at(i));
96
97 return finalListNames;
98}
99
100std::string MathematicaAssistantImp::finalizeListName(std::string basicListName, std::string testName, std::string dataToCalc)
101{
102 return testName + basicListName + dataToCalc;
103}
104
105void MathematicaAssistantImp::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)
106{
107 std::vector<std::vector<std::shared_ptr<DataPoint> > > dataPointGroup;
108
109 for (int i = 0; i < xAxesData.size(); i++) {
110 std::vector<std::shared_ptr<DataPoint> > dataPoints;
111 for (int j = 0; j < xAxesData.at(i).size(); j++)
112 dataPoints.push_back(DataPoint::getNewInstance(xAxesData.at(i).at(j), yAxesData.at(i).at(j)));
113 dataPointGroup.push_back(dataPoints);
114 }
115 std::vector<std::shared_ptr<MathematicaPointList> > pointList;
116 for (int i = 0; i < dataPointGroup.size(); i++) {
117 std::shared_ptr<MathematicaPointList> aPointList = functionFactory->makeMathematicaPointList(aMathmaticaFile, listNames.at(i), dataPointGroup.at(i));
118 pointList.push_back(aPointList);
119 }
120 std::shared_ptr<MathematicaListPlot> listLogLogPlot = functionFactory->makeMathematicaListPlot(aMathmaticaFile, pointList, "ListLogLogPlot", labelXAxes, labelYAxes);
121}
122
123void MathematicaAssistantImp::addListOfListsToMathematicaFile(std::shared_ptr<MathematicaFile> aMathmaticaFile, std::string listNames, std::vector<std::vector<double>> listOfLists)
124{
125 functionFactory->makeMathematicaListOfLists(aMathmaticaFile, listNames, listOfLists);
126}
127
128void MathematicaAssistantImp::addSecondOrderOfAccuracyRef(std::vector<std::vector<double>>& xAxesData, std::vector<std::vector<double>>& yAxesData, std::vector<std::string>& listNames)
129{
130 int maxLength = 0;
131 int maxLengthAtNumber = 0;
132 for (int i = 0; i < xAxesData.size(); i++) {
133 if (xAxesData.at(i).size() > maxLength) {
134 maxLength = xAxesData.at(i).size();
136 }
137 }
138 std::vector<double> x = xAxesData.at(maxLengthAtNumber);
139
140 double maxData = 0.0;
141 for (int i = 0; i < yAxesData.size(); i++) {
142 for (int j = 0; j < yAxesData.at(i).size(); j++) {
143 if (yAxesData.at(i).at(j) > maxData)
144 maxData = yAxesData.at(i).at(j);
145 }
146 }
147
148 std::vector<double> sec = { maxData * 10.0 };
149 for (int l = 1; l < x.size(); l++)
150 sec.push_back(sec.at(l - 1) / exp(-2.0 * log(x.at(l - 1) / x.at(l))));
151 xAxesData.push_back(x);
152 yAxesData.push_back(sec);
153 listNames.push_back("SecondOrderOfAccuracy");
154}
155
156void MathematicaAssistantImp::addFourthOrderOfAccuracyRef(std::vector<std::vector<double>>& xAxesData, std::vector<std::vector<double>>& yAxesData, std::vector<std::string>& listNames)
157{
158 int maxLength = 0;
159 int maxLengthAtNumber = 0;
160 for (int i = 0; i < xAxesData.size(); i++) {
161 if (xAxesData.at(i).size() > maxLength) {
162 maxLength = xAxesData.at(i).size();
164 }
165 }
166 std::vector<double> x = xAxesData.at(maxLengthAtNumber);
167
168 double minData = yAxesData.at(0).at(0);
169 for (int i = 1; i < yAxesData.size(); i++) {
170 if (yAxesData.at(i).at(0) < minData)
171 minData = yAxesData.at(i).at(0);
172 }
173 std::vector<double> fourth = { minData / 10.0 };
174 for (int l = 1; l < x.size(); l++)
175 fourth.push_back(fourth.at(l - 1) / std::exp(-4.0 * std::log(x.at(l - 1) / x.at(l))));
176
177
178 xAxesData.push_back(x);
179 yAxesData.push_back(fourth);
180 listNames.push_back("FourthOrderOfAccuracy");
181}
182
std::shared_ptr< MathematicaFunctionFactory > functionFactory
std::vector< std::string > finalizeListNames(std::vector< std::string > basicListNames, std::string testName, std::string dataToCalc)
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)
MathematicaAssistantImp()
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::string finalizeListName(std::string basicListName, std::string testName, std::string dataToCalc)
static std::shared_ptr< DataPoint > getNewInstance(double x, double y)
Definition DataPoint.cpp:39
void addListOfListsToMathematicaFile(std::shared_ptr< MathematicaFile > aMathmaticaFile, std::string listName, std::vector< std::vector< double > > listOfLists)
void log(const char *fmt)
std::shared_ptr< T > SPtr
@ x
Definition Axis.h:42