Skip to content

Commit 30b5794

Browse files
committed
Update advection-diffusion example to correct plot data and improve visualization
1 parent a38d215 commit 30b5794

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

generalFormPDEScript/advection-diffusion-1d.jsnb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"jsnbversion": "v0.1",
1010
"cells": [
1111
{
12-
"code": "//> module\n// Import FEAScript library\nimport { FEAScriptModel } from \"https://core.feascript.com/dist/feascript.esm.js\";\n\n// Create a new FEAScript model\nconst model = new FEAScriptModel();\n\n// Set solver configuration\nmodel.setSolverConfig(\"generalFormPDEScript\", {\n coefficientFunctions: {\n // Equation d²u/dx² - 10 du/dx = 10 * exp(-200 * (x - 0.5)²)\n A: (x) => 1, // Diffusion coefficient\n B: (x) => -10, // Advection coefficient\n C: (x) => 0, // Reaction coefficient\n D: (x) => 10 * Math.exp(-200 * Math.pow(x - 0.5, 2)), // Source term\n },\n});\n\n// Define mesh configuration\nmodel.setMeshConfig({\n meshDimension: \"1D\",\n elementOrder: \"linear\",\n numElementsX: 20,\n maxX: 1.0,\n});\n\n// Define boundary conditions\nmodel.addBoundaryCondition(\"0\", [\"constantValue\", 1]); // Left boundary, u(0) = 1\nmodel.addBoundaryCondition(\"1\", \"zeroGradient\"); // Right boundary, zero gradient (du/dx = 0)\n\n// Set solver method\nmodel.setSolverMethod(\"jacobi\");\n\n// Solve the problem and get the solution\nconst { solutionVector, nodesCoordinates } = model.solve();\n\n// Print results to console\nconsole.log(\"Node coordinates:\", nodesCoordinates);\nconsole.log(\"Solution vector:\", solutionVector);\n\n// Plot results using Plotly\n// Define trace\nconst trace = {\n x: nodesCoordinates,\n y: solutionVector,\n type: 'scatter',\n mode: 'lines+markers',\n marker: {color: 'blue'}\n};\n\n// Define layout\nconst layout = {\n title: 'Temperature distribution along wall thickness',\n xaxis: {title: 'X-axis'},\n yaxis: {title: 'Temperature (°C)'}\n};\n\n// Render plot\nscrib.show(\"<div style='height:500px;width:500px' id='line-chart'></div>\")\nPlotly.newPlot(\"line-chart\", [trace], layout);\n",
12+
"code": "//> module\n// Import FEAScript library\nimport { FEAScriptModel } from \"https://core.feascript.com/dist/feascript.esm.js\";\n\n// Create a new FEAScript model\nconst model = new FEAScriptModel();\n\n// Set solver configuration\nmodel.setSolverConfig(\"generalFormPDEScript\", {\n coefficientFunctions: {\n // Equation d²u/dx² - 10 du/dx = 10 * exp(-200 * (x - 0.5)²)\n A: (x) => 1, // Diffusion coefficient\n B: (x) => -10, // Advection coefficient\n C: (x) => 0, // Reaction coefficient\n D: (x) => 10 * Math.exp(-200 * Math.pow(x - 0.5, 2)), // Source term\n },\n});\n\n// Define mesh configuration\nmodel.setMeshConfig({\n meshDimension: \"1D\",\n elementOrder: \"linear\",\n numElementsX: 20,\n maxX: 1.0,\n});\n\n// Define boundary conditions\nmodel.addBoundaryCondition(\"0\", [\"constantValue\", 1]); // Left boundary, u(0) = 1\nmodel.addBoundaryCondition(\"1\", \"zeroGradient\"); // Right boundary, zero gradient (du/dx = 0)\n\n// Set solver method\nmodel.setSolverMethod(\"jacobi\");\n\n// Solve the problem and get the solution\nconst { solutionVector, nodesCoordinates } = model.solve();\n\n// Print results to console\nconsole.log(\"Node coordinates:\", nodesCoordinates);\nconsole.log(\"Solution vector:\", solutionVector);\n\n// Plot results using Plotly\n\n// Create the x-coordinates for the plot\nconst numNodes = model.meshConfig.numElementsX + 1;\nconst xCoords = Array.from({ length: numNodes }, (_, i) => i * (model.meshConfig.maxX / model.meshConfig.numElementsX));\n\n// Define trace\nconst trace = {\n x: xCoords,\n y: solutionVector,\n type: 'scatter',\n mode: 'lines+markers',\n marker: {color: 'blue'}\n};\n\n// Define layout\nconst layout = {\n title: '1D Advection-Diffusion with Gaussian Source',\n xaxis: {title: 'X-coordinate'},\n yaxis: {title: 'Solution u(x)'}\n};\n\n// Render plot\nscrib.show(\"<div style='height:500px;width:500px' id='line-chart'></div>\")\nPlotly.newPlot(\"line-chart\", [trace], layout);\n",
1313
"status": "",
1414
"output": "",
1515
"type": "code"
1616
}
1717
],
18-
"source": "https://github.com/nikoscham/FEAScript-Scribbler-examples",
18+
"source": "https://github.com/gopi-suvanam/scribbler",
1919
"run_on_load": false
2020
}

0 commit comments

Comments
 (0)