+ "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",
0 commit comments