I am now focusing on using NDSolve with the method of lines and the TensorProductGrid spatial discretization to integrate PDEs. My problem is to integrate the wave equation from t=0 to t=2 with an initial flat shape and zero speed between x=0 and x=1, a harmonic drive on the left, and matched impedances on both sides. Here is my encoding:
eq = D[v[t, x], {t, 2}] - D[v[t, x], {x, 2}] == 0;
ics = {v[0, x] == 0, ((D[v[t, x], t]) /. t -> 0) == 0};
drive[t_] = Sin[2 Pi 2. t];
bcs = {(D[v[t, x], x] /. x -> 0) - (D[v[t, x], t] /. x -> 0) + 2 drive'[t] ==0,
(D[v[t, x], x] /. x -> 1) + (D[v[t, x], t] /. x -> 1) == 0}
sol = NDSolveValue[{eq, ics, bcs} // Flatten, v, {t, 0, 2}, {x, 0, 1},
Method -> {"MethodOfLines", "SpatialDiscretization" -> "TensorProductGrid"},
MaxStepSize -> 0.01]
As expected, I obtain a warning NDSolveValue::ibcinc: Warning: boundary and initial conditions are inconsistent.. As well as a completely wrong result. This is because my zero initial speed is valid everywhere except at x=0, where the bcs gives an initial speed of 8Pi.
How to correct my code to indicate that the initial condition is not valid at x=0?
Thanks.
PS1: I know that the finite element method and Neumann values do the job automatically. I want to learn the finite difference method.
PS2: I don't want to use a cosine for the drive.
Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 100}}toNDSolveValue. Still theeerrwarning comes up, but the estimated error is small and the solution is indeed accurate enough. You can compare the result to the one given by e.g.Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 100}, "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> 200, "MinPoints" -> 200, "DifferenceOrder" -> 2}}. – xzczd Apr 02 '19 at 17:00