1616 * @param {string } meshDimension - The dimension of the solution
1717 * @param {string } plotType - The type of plot
1818 * @param {string } plotDivId - The id of the div where the plot will be rendered
19+ * @param {boolean } showMesh - Flag to indicate if the mesh should be shown
1920 */
2021export function plotSolution (
2122 solutionVector ,
2223 nodesCoordinates ,
2324 solverConfig ,
2425 meshDimension ,
2526 plotType ,
26- plotDivId
27+ plotDivId ,
28+ showMesh = false // Currently only for rectuangular domains
2729) {
2830 const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates ;
2931
@@ -66,17 +68,47 @@ export function plotSolution(
6668 }
6769
6870 // Create the data structure for the contour plot
69- let data = [
70- {
71- z : transposedSolution ,
72- type : "contour" ,
73- contours : {
74- coloring : "heatmap" ,
75- } ,
76- x : reshapedXForPlot ,
77- y : reshapedYCoordinates [ 0 ] ,
71+ let contourData = {
72+ z : transposedSolution ,
73+ type : "contour" ,
74+ contours : {
75+ coloring : "heatmap" ,
7876 } ,
79- ] ;
77+ x : reshapedXForPlot ,
78+ y : reshapedYCoordinates [ 0 ] ,
79+ } ;
80+
81+ // Create mesh lines for the computational grid if showMesh is true
82+ let meshData = [ ] ;
83+ if ( showMesh ) {
84+ let meshLinesX = [ ] ;
85+ let meshLinesY = [ ] ;
86+
87+ // Horizontal mesh lines
88+ for ( let i = 0 ; i < numNodesY ; i ++ ) {
89+ meshLinesX . push ( ...reshapedXCoordinates . map ( ( row ) => row [ i ] ) , null ) ;
90+ meshLinesY . push ( ...reshapedYCoordinates . map ( ( row ) => row [ i ] ) , null ) ;
91+ }
92+
93+ // Vertical mesh lines
94+ for ( let i = 0 ; i < numNodesX ; i ++ ) {
95+ meshLinesX . push ( ...reshapedXCoordinates [ i ] , null ) ;
96+ meshLinesY . push ( ...reshapedYCoordinates [ i ] , null ) ;
97+ }
98+
99+ // Create the data structure for the mesh lines
100+ meshData = {
101+ x : meshLinesX ,
102+ y : meshLinesY ,
103+ mode : "lines" ,
104+ type : "scatter" ,
105+ line : {
106+ color : "palegoldenrod" ,
107+ width : 1 ,
108+ } ,
109+ showlegend : false ,
110+ } ;
111+ }
80112
81113 // Set a fixed maximum window size for the plot
82114 let maxWindowWidth = Math . min ( window . innerWidth , 700 ) ;
@@ -88,14 +120,18 @@ export function plotSolution(
88120
89121 // Set the layout for the contour plot
90122 let layout = {
91- title : `${ plotType } plot - ${ solverConfig } ` ,
123+ title : `${ plotType } plot${ showMesh ? ' with mesh' : '' } - ${ solverConfig } ` ,
92124 width : plotWidth ,
93125 height : plotHeight ,
94126 xaxis : { title : "x" } ,
95127 yaxis : { title : "y" } ,
96128 } ;
97129
98- // Create the contour plot using Plotly
99- Plotly . newPlot ( plotDivId , data , layout ) ;
130+ // Create the plot using Plotly
131+ let plotData = [ contourData ] ;
132+ if ( showMesh ) {
133+ plotData . push ( meshData ) ;
134+ }
135+ Plotly . newPlot ( plotDivId , plotData , layout ) ;
100136 }
101137}
0 commit comments