#r "BoSSSpad.dll"
// #r "D:\BoSSS2\experimental\public\src\L4-application\BoSSSpad\bin\Release\net5.0\bossspad.dll"
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Data;
using System.Globalization;
using System.Threading;
using ilPSP;
using ilPSP.Utils;
using BoSSS.Platform;
using BoSSS.Foundation;
using BoSSS.Foundation.Grid;
using BoSSS.Foundation.Grid.Classic;
using BoSSS.Foundation.IO;
using BoSSS.Solution;
using BoSSS.Solution.Control;
using BoSSS.Solution.GridImport;
using BoSSS.Solution.Statistic;
using BoSSS.Solution.Utils;
using BoSSS.Solution.Gnuplot;
using BoSSS.Application.BoSSSpad;
using BoSSS.Application.XNSE_Solver;
using static BoSSS.Application.BoSSSpad.BoSSSshell;
using BoSSS.Foundation.Grid.RefElements;
using BoSSS.Platform.LinAlg;
using BoSSS.Solution.NSECommon;
using BoSSS.Application.XNSEC;
Init();
BoSSSshell.WorkflowMgm.Init("HeatedCavity_ConvergenceStudy");
Project name is set to 'HeatedCavity_ConvergenceStudy'. Default Execution queue is chosen for the database. Opening existing database '\\fdygitrunner\ValidationTests\databases\HeatedCavity_ConvergenceStudy'.
var myBatch = BoSSSshell.GetDefaultQueue();
var myDb = BoSSSshell.WorkflowMgm.DefaultDatabase;
wmg.Sessions
#0: HeatedCavity_ConvergenceStudy NaturalConvection_k6_DG4_Ra100 10/30/2023 10:55:41 302f0bb7... #1: HeatedCavity_ConvergenceStudy NaturalConvection_k6_DG3_Ra100 10/30/2023 10:50:36 d2399a05... #2: HeatedCavity_ConvergenceStudy NaturalConvection_k6_DG2_Ra100 10/30/2023 10:46:14 ea1038d9... #3: HeatedCavity_ConvergenceStudy NaturalConvection_k5_DG4_Ra100 10/30/2023 10:54:50 ee5b22e8... #4: HeatedCavity_ConvergenceStudy NaturalConvection_k5_DG3_Ra100 10/30/2023 10:49:54 e5a511fb... #5: HeatedCavity_ConvergenceStudy NaturalConvection_k4_DG4_Ra100 10/30/2023 10:53:59 2910bd15... #6: HeatedCavity_ConvergenceStudy NaturalConvection_k6_DG1_Ra100 10/30/2023 10:42:55 a4c37540... #7: HeatedCavity_ConvergenceStudy NaturalConvection_k3_DG4_Ra100 10/30/2023 10:53:01 23b9a027... #8: HeatedCavity_ConvergenceStudy NaturalConvection_k4_DG3_Ra100 10/30/2023 10:49:04 78fa7115... #9: HeatedCavity_ConvergenceStudy NaturalConvection_k2_DG4_Ra100 10/30/2023 10:52:04 e1382850... #10: HeatedCavity_ConvergenceStudy NaturalConvection_k5_DG2_Ra100 10/30/2023 10:45:31 e2f25c6b... #11: HeatedCavity_ConvergenceStudy NaturalConvection_k1_DG4_Ra100 10/30/2023 10:51:12 7a209b3f... #12: HeatedCavity_ConvergenceStudy NaturalConvection_k3_DG3_Ra100 10/30/2023 10:48:16 46cf649d... #13: HeatedCavity_ConvergenceStudy NaturalConvection_k4_DG2_Ra100 10/30/2023 10:45:00 dd6e0af7... #14: HeatedCavity_ConvergenceStudy NaturalConvection_k2_DG3_Ra100 10/30/2023 10:47:31 1df4c4cb... #15: HeatedCavity_ConvergenceStudy NaturalConvection_k3_DG2_Ra100 10/30/2023 10:44:26 43de2912... #16: HeatedCavity_ConvergenceStudy NaturalConvection_k1_DG3_Ra100 10/30/2023 10:46:51 41ea35be... #17: HeatedCavity_ConvergenceStudy NaturalConvection_k5_DG1_Ra100 10/30/2023 10:42:33 9ec0590d... #18: HeatedCavity_ConvergenceStudy NaturalConvection_k4_DG1_Ra100 10/30/2023 10:42:09 8ddf80a3... #19: HeatedCavity_ConvergenceStudy NaturalConvection_k2_DG2_Ra100 10/30/2023 10:43:52 7283b4b7... #20: HeatedCavity_ConvergenceStudy NaturalConvection_k1_DG2_Ra100 10/30/2023 10:43:23 00ff0a4a... #21: HeatedCavity_ConvergenceStudy NaturalConvection_k3_DG1_Ra100 10/30/2023 10:41:51 6cc1f4a0... #22: HeatedCavity_ConvergenceStudy NaturalConvection_k2_DG1_Ra100 10/30/2023 10:41:24 a50c041d... #23: HeatedCavity_ConvergenceStudy NaturalConvection_k1_DG1_Ra100 10/30/2023 10:41:01 52522c54...
// Find number of cells used in the finest mesh
int NCellsFinestMesh = 0;
var allsess = myDb.Sessions;
foreach(var sess in allsess) {
//bool keyPresent = sess.KeysAndQueries.ContainsKey("Grid:NoOfCells");
//Console.WriteLine($"Session: {sess}: {keyPresent}");
int c = Convert.ToInt32(sess.KeysAndQueries["Grid:NoOfCells"]);
if( c > NCellsFinestMesh)
NCellsFinestMesh = c;
}
int[] DGDegrees = new int[] {1,2,3,4} ;
// int counter = 0;
// string[] varNames = new string[]{"VelocityX", "VelocityY", "Pressure","Temperature"};
// IEnumerable<KeyValuePair<string, double>>[] RegressionS = new IEnumerable<KeyValuePair<string, double>>[varNames.Length];
// Plot2Ddata[,] PlotTable = new Plot2Ddata[2, 2];
// int cnt2 = -1;
// for (int iCol = 0; iCol < 2; iCol++) {
// for (int iRow = 0; iRow < 2; iRow++) {
// var allColors = Enum.GetValues(typeof(LineColors)).Cast<LineColors>().ToArray();
// var allPointTypes = Enum.GetValues(typeof(PointTypes)).Cast<PointTypes>().ToArray();
// PointTypes[] myPointTypes = new PointTypes[]{ PointTypes.Diamond, PointTypes.Box, PointTypes.LowerTriangle,PointTypes.OpenLowerTriangle, };
// cnt2++;
// // BoSSS data
// var fmt = new PlotFormat();
// fmt.Style = Styles.Lines;
// fmt.LineColor = allColors[cnt2 % allColors.Length];
// fmt.PointType = allPointTypes[cnt2 % allPointTypes.Length];
// fmt.DashType = DashTypes.Solid;
// string dgDegStr = (varNames[cnt2] == "VelocityX" || varNames[cnt2] == "VelocityY" ) ? "DGdegree:Velocity*":"DGdegree:"+varNames[cnt2];
// var Tab = BoSSSshell.WorkflowMgm.SessionTable;
// var Tab2 = Tab.ExtractColumns( dgDegStr,"Grid:hMin","Grid:NoOfCells" ,"L2Error_"+ varNames[cnt2]);
// //Extract last point, the one against we are comparing our solutions with
// Tab2 = Tab2.ExtractRows((iRow,RowEntries)=> Convert.ToInt32(RowEntries["Grid:NoOfCells"]) != NCellsFinestMesh );
// var plot = Tab2.ToPlot("Grid:hMin","L2Error_"+ varNames[cnt2], dgDegStr);
// int cc = 0;
// foreach(var dataGroup in plot.dataGroups){
// dataGroup.Format.PointType = myPointTypes[cc];
// cc++;
// }
// plot.LogX = true;
// plot.LogY = true;
// plot.Title = varNames[cnt2];
// plot.TitleFont = 20;
// plot.Xlabel = "h";
// plot.Ylabel = "L_2 Error";
// PlotTable[iCol, iRow] = plot;
// RegressionS[cnt2] = plot.Regression();
// }
// }
int counter = 0;
string[] varNames = new string[] { "VelocityX", "VelocityY", "Pressure", "Temperature" };
IEnumerable<KeyValuePair<string, double>>[] RegressionS = new IEnumerable<KeyValuePair<string, double>>[varNames.Length];
Plot2Ddata[,] PlotTable = new Plot2Ddata[2, 2];
int cnt2 = -1;
for (int iCol = 0; iCol < 2; iCol++) {
for (int iRow = 0; iRow < 2; iRow++) {
var allColors = Enum.GetValues(typeof(LineColors)).Cast<LineColors>().ToArray();
var allPointTypes = Enum.GetValues(typeof(PointTypes)).Cast<PointTypes>().ToArray();
PointTypes[] myPointTypes = new PointTypes[] { PointTypes.Diamond, PointTypes.Box, PointTypes.LowerTriangle, PointTypes.OpenLowerTriangle, };
cnt2++;
string varname = varNames[cnt2];
var ExpPlotS = new List<Plot2Ddata>();
var fmt = new PlotFormat();
fmt.Style = Styles.Lines;
fmt.LineColor = allColors[cnt2 % allColors.Length];
fmt.PointType = allPointTypes[cnt2 % allPointTypes.Length];
fmt.DashType = DashTypes.Solid;
foreach (int pDeg in DGDegrees) {
int actualDGDeg = varname == "Pressure" ? pDeg-1:pDeg;
string dgDegStr = (varname == "VelocityX" || varname == "VelocityY" ) ? "DGdegree:Velocity*":"DGdegree:"+varname;
var pDegSessions = myDb.Sessions.Where(
Si => (Convert.ToInt32(Si.KeysAndQueries[dgDegStr]) == actualDGDeg)
).ToArray();
Plot2Ddata pDegPlot =
pDegSessions.ToEstimatedGridConvergenceData(
varname,
xAxis_Is_hOrDof: true, // false selects DOFs for x-axis
normType: varname == "Pressure" ? NormType.L2noMean_embedded : NormType.L2_embedded);
ExpPlotS.Add(pDegPlot);
}
// ExpPlotS[0].dataGroups[0].Format.PointType = PointTypes.Diamond;
// ExpPlotS[1].dataGroups[0].Format.PointType = PointTypes.Box;
// ExpPlotS[2].dataGroups[0].Format.PointType = PointTypes.LowerTriangle;
// ExpPlotS[3].dataGroups[0].Format.PointType = PointTypes.Asterisk;
// ExpPlotS[0].dataGroups[0].Name = "$k = 1$";
// ExpPlotS[1].dataGroups[0].Name = "$k = 2$";
// ExpPlotS[2].dataGroups[0].Name = "$k = 3$";
// ExpPlotS[3].dataGroups[0].Name = "$k = 4$";
// foreach (var p in ExpPlotS) {
// p.dataGroups[0].Format.PointSize = 0.8;
// p.dataGroups[0].Format.DashType = DashTypes.Dotted;
// p.dataGroups[0].Format.LineWidth = 2;
// }
var ExpPlot = ExpPlotS [0]; // select 0-th object
foreach (var p in ExpPlotS.Skip(1)) { // loop over other ( skip 0-th entry )
ExpPlot = ExpPlot.Merge(p); // merge
}
ExpPlot.LogX = true;
ExpPlot.LogY = true;
ExpPlot.Title = varNames[cnt2];
ExpPlot.TitleFont = 20;
ExpPlot.Xlabel = "h";
ExpPlot.Ylabel = "L_2 Error";
PlotTable[iCol, iRow] = ExpPlot;
RegressionS[cnt2] = ExpPlot.Regression();
}
}
var gp = PlotTable.ToGnuplot();
gp.PlotSVG(xRes:1000,yRes:1000)
Using gnuplot: C:\Program Files (x86)\FDY\BoSSS\bin\native\win\gnuplot-gp510-20160418-win32-mingw\gnuplot\bin\gnuplot.exe Note: In a Jupyter Worksheet, you must NOT have a trailing semicolon in order to see the plot on screen; otherwise, the output migth be surpressed.!
warning CS1701: Assuming assembly reference 'Microsoft.AspNetCore.Html.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' used by 'BoSSSpad' matches identity 'Microsoft.AspNetCore.Html.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' of 'Microsoft.AspNetCore.Html.Abstractions', you may need to supply runtime policy
int cnt = 0;
foreach(var reg in RegressionS){
Console.WriteLine(varNames[cnt]);
var regB = reg.ToArray();
for(int j = 0; j < regB.Length; j++){
int dgDeg = ( regB[j].Key).Last() - '0';
Console.Write("DG degree: "+ dgDeg+ " \t");
double slope = regB[j].Value;
Console.Write("Slope: " +slope + "\t");
if((slope - (dgDeg + 1) ) >= -0.2)
Console.WriteLine("Expected slope archieved");
else
Console.WriteLine("The slope value is too low");
}
cnt++;
}
VelocityX DG degree: 1 Slope: 1.2911039853209174 The slope value is too low DG degree: 2 Slope: 3.2743527591854016 Expected slope archieved DG degree: 3 Slope: 3.6433134232281903 The slope value is too low DG degree: 4 Slope: 4.081393349649799 The slope value is too low VelocityY DG degree: 1 Slope: 1.283024265531371 The slope value is too low DG degree: 2 Slope: 3.1261341833830265 Expected slope archieved DG degree: 3 Slope: 3.7577920821230766 The slope value is too low DG degree: 4 Slope: 4.1197526761003695 The slope value is too low Pressure DG degree: 0 Slope: 1.0446117904020176 Expected slope archieved DG degree: 1 Slope: 2.20275981971188 Expected slope archieved DG degree: 2 Slope: 2.509856218284294 The slope value is too low DG degree: 3 Slope: 3.0112804659374754 The slope value is too low Temperature DG degree: 1 Slope: 1.308684040176347 The slope value is too low DG degree: 2 Slope: 3.317817898691089 Expected slope archieved DG degree: 3 Slope: 4.138033048701826 Expected slope archieved DG degree: 4 Slope: 4.839191639594438 Expected slope archieved