Skip to main content
added 1 character in body
Source Link
Nasser
  • 150.3k
  • 12
  • 161
  • 374

btw, you have this

        Warning: boundary and initial conditions are inconsistent.

You can change IC to use Piecewise to make BC and IC agree.

k = 1; A = 1; u0 = 1; L = 1; β = 1; T = 10;
solNFiniteElements = 
 NDSolveValue[{D[u[x, t], t] - k D[u[x, t], x, x] == 
    A Exp[-β t] + NeumannValue[0, x == 0],
   u[L, t] == 0,
   u[x, 0] == Piecewise[{{u0, 0 <<= x < L}, {0, x == L}}]
   },
  u, {x, 0, L}, {t, 0, T},
  Method -> {"PDEDiscretization" -> {"MethodOfLines", 
      "SpatialDiscretization" -> {"FiniteElement"}}}
  ]

And now

Manipulate[
 Plot[solNFiniteElements[x, t0], {x, 0, 1}, PlotRange -> {0, 1.3}],
 {{t0, 0, "time"}, 0, 0.5, .01, Appearance -> "Labeled"},
 TrackedSymbols :> {t0}
 ]

enter image description here

Due to abrupt change in solution at t=0 from 1 to zero at x=L, solution at t=0 will not be smooth. But will be at any time after t=0

btw, you have this

        Warning: boundary and initial conditions are inconsistent.

You can change IC to use Piecewise to make BC and IC agree.

k = 1; A = 1; u0 = 1; L = 1; β = 1; T = 10;
solNFiniteElements = 
 NDSolveValue[{D[u[x, t], t] - k D[u[x, t], x, x] == 
    A Exp[-β t] + NeumannValue[0, x == 0],
   u[L, t] == 0,
   u[x, 0] == Piecewise[{{u0, 0 < x < L}, {0, x == L}}]
   },
  u, {x, 0, L}, {t, 0, T},
  Method -> {"PDEDiscretization" -> {"MethodOfLines", 
      "SpatialDiscretization" -> {"FiniteElement"}}}
  ]

And now

Manipulate[
 Plot[solNFiniteElements[x, t0], {x, 0, 1}, PlotRange -> {0, 1.3}],
 {{t0, 0, "time"}, 0, 0.5, .01, Appearance -> "Labeled"},
 TrackedSymbols :> {t0}
 ]

enter image description here

btw, you have this

        Warning: boundary and initial conditions are inconsistent.

You can change IC to use Piecewise to make BC and IC agree.

k = 1; A = 1; u0 = 1; L = 1; β = 1; T = 10;
solNFiniteElements = 
 NDSolveValue[{D[u[x, t], t] - k D[u[x, t], x, x] == 
    A Exp[-β t] + NeumannValue[0, x == 0],
   u[L, t] == 0,
   u[x, 0] == Piecewise[{{u0, 0 <= x < L}, {0, x == L}}]
   },
  u, {x, 0, L}, {t, 0, T},
  Method -> {"PDEDiscretization" -> {"MethodOfLines", 
      "SpatialDiscretization" -> {"FiniteElement"}}}
  ]

And now

Manipulate[
 Plot[solNFiniteElements[x, t0], {x, 0, 1}, PlotRange -> {0, 1.3}],
 {{t0, 0, "time"}, 0, 0.5, .01, Appearance -> "Labeled"},
 TrackedSymbols :> {t0}
 ]

enter image description here

Due to abrupt change in solution at t=0 from 1 to zero at x=L, solution at t=0 will not be smooth. But will be at any time after t=0

Source Link
Nasser
  • 150.3k
  • 12
  • 161
  • 374

btw, you have this

        Warning: boundary and initial conditions are inconsistent.

You can change IC to use Piecewise to make BC and IC agree.

k = 1; A = 1; u0 = 1; L = 1; β = 1; T = 10;
solNFiniteElements = 
 NDSolveValue[{D[u[x, t], t] - k D[u[x, t], x, x] == 
    A Exp[-β t] + NeumannValue[0, x == 0],
   u[L, t] == 0,
   u[x, 0] == Piecewise[{{u0, 0 < x < L}, {0, x == L}}]
   },
  u, {x, 0, L}, {t, 0, T},
  Method -> {"PDEDiscretization" -> {"MethodOfLines", 
      "SpatialDiscretization" -> {"FiniteElement"}}}
  ]

And now

Manipulate[
 Plot[solNFiniteElements[x, t0], {x, 0, 1}, PlotRange -> {0, 1.3}],
 {{t0, 0, "time"}, 0, 0.5, .01, Appearance -> "Labeled"},
 TrackedSymbols :> {t0}
 ]

enter image description here