Skip to content

Commit 31fdd86

Browse files
committed
Fix signs in advection-diffusion equations and update comments accordingly
1 parent 4fd5889 commit 31fdd86

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

examples/generalFormPDEScript/advectionDiffusion1D/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This example demonstrates solving a one-dimensional advection-diffusion problem with a Gaussian source term using the FEAScript library. The problem models the transport equation:
66

77
$$
8-
\frac{d^2u}{dx^2} + 10 \frac{du}{dx} = -10 \cdot e^{-200 \cdot (x - 0.5)^2}
8+
\frac{d^2u}{dx^2} - 10 \frac{du}{dx} = 10 \cdot e^{-200 \cdot (x - 0.5)^2}
99
$$
1010

1111
This can be written in the general form as:
@@ -17,9 +17,9 @@ $$
1717
where:
1818

1919
- $A(x) = 1$ (diffusion coefficient)
20-
- $B(x) = 10$ (advection coefficient)
20+
- $B(x) = -10$ (advection coefficient)
2121
- $C(x) = 0$ (no reaction term)
22-
- $D(x) = -10 \cdot e^{-200 \cdot (x - 0.5)^2}$ (Gaussian source term centered at x = 0.5)
22+
- $D(x) = 10 \cdot e^{-200 \cdot (x - 0.5)^2}$ (Gaussian source term centered at x = 0.5)
2323

2424
### Instructions
2525

examples/generalFormPDEScript/advectionDiffusion1D/advectionDiffusion1D.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const model = new FEAScriptModel();
2323
// Set solver configuration with coefficient functions
2424
model.setSolverConfig("generalFormPDEScript", {
2525
coefficientFunctions: {
26-
// Equation d²u/dx² + 10 du/dx = -10 * exp(-200 * (x - 0.5)²)
26+
// Equation d²u/dx² - 10 du/dx = 10 * exp(-200 * (x - 0.5)²)
2727
A: (x) => 1, // Diffusion coefficient
28-
B: (x) => 10, // Advection coefficient
28+
B: (x) => -10, // Advection coefficient
2929
C: (x) => 0, // Reaction coefficient
30-
D: (x) => -10 * Math.exp(-200 * Math.pow(x - 0.5, 2)), // Source term
30+
D: (x) => 10 * Math.exp(-200 * Math.pow(x - 0.5, 2)), // Source term
3131
},
3232
});
3333

src/solvers/generalFormPDEScript.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function assembleGeneralFormPDEMat(meshData, boundaryConditions, coeffici
9595
const globalNodeIndex1 = localToGlobalMap[localNodeIndex1];
9696

9797
// Source term contribution to residual vector
98-
residualVector[globalNodeIndex1] +=
98+
residualVector[globalNodeIndex1] -=
9999
gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];
100100

101101
for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {
@@ -110,15 +110,15 @@ export function assembleGeneralFormPDEMat(meshData, boundaryConditions, coeffici
110110
basisFunctionDerivX[localNodeIndex2];
111111

112112
// Advection term
113-
jacobianMatrix[globalNodeIndex1][globalNodeIndex2] +=
113+
jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=
114114
gaussWeights[gaussPointIndex] *
115115
detJacobian *
116116
b *
117117
basisFunctionDerivX[localNodeIndex2] *
118118
basisFunction[localNodeIndex1];
119119

120120
// Reaction term
121-
jacobianMatrix[globalNodeIndex1][globalNodeIndex2] -=
121+
jacobianMatrix[globalNodeIndex1][globalNodeIndex2] +=
122122
gaussWeights[gaussPointIndex] *
123123
detJacobian *
124124
c *
@@ -219,7 +219,7 @@ export function assembleGeneralFormPDEFront({
219219
// Computation of local Jacobian matrix and residual vector
220220
for (let localNodeIndex1 = 0; localNodeIndex1 < numNodes; localNodeIndex1++) {
221221
// Source term contribution to local residual vector
222-
localResidualVector[localNodeIndex1] +=
222+
localResidualVector[localNodeIndex1] -=
223223
gaussWeights[gaussPointIndex] * detJacobian * d * basisFunction[localNodeIndex1];
224224

225225
for (let localNodeIndex2 = 0; localNodeIndex2 < numNodes; localNodeIndex2++) {
@@ -232,15 +232,15 @@ export function assembleGeneralFormPDEFront({
232232
basisFunctionDerivX[localNodeIndex2];
233233

234234
// Advection term
235-
localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=
235+
localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=
236236
gaussWeights[gaussPointIndex] *
237237
detJacobian *
238238
b *
239239
basisFunctionDerivX[localNodeIndex2] *
240240
basisFunction[localNodeIndex1];
241241

242242
// Reaction term
243-
localJacobianMatrix[localNodeIndex1][localNodeIndex2] -=
243+
localJacobianMatrix[localNodeIndex1][localNodeIndex2] +=
244244
gaussWeights[gaussPointIndex] *
245245
detJacobian *
246246
c *

0 commit comments

Comments
 (0)