1
$\begingroup$

This question already has an answer here:

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.

$\endgroup$

marked as duplicate by xzczd differential-equations Apr 2 at 16:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ To be more specific, just add Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 100}} to NDSolveValue. Still the eerr warning 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}}. $\endgroup$ – xzczd Apr 2 at 17:00
  • $\begingroup$ Thanks a lot xzczd ! If I understand well the answer 3 of the already answered question, it is not possible to tell NDSolve that an ic does not apply at a boundary with the method of lines and finite differences :-(. $\endgroup$ – user3650925 Apr 2 at 18:08
  • $\begingroup$ I had already tried "DifferentiateBoundaryConditions" -> True but not with a scale factor of 100! The solution is however negatively biased (-1.2 to 0.8 instead of -1 to 1) and it improves very slowly with the scale factor. Now that I have understood that there is no way to really solve the problem, I prefer to multiply my drive by a fast branching function with zero initial derivative. Like this there is no inconsistency, no warning, and no bias on the solution. What should I do with my duplicate question ? $\endgroup$ – user3650925 Apr 2 at 18:08
  • $\begingroup$ It's OK to keep the duplicate question as a guidepost, please don't take it as kind of punishment. :) $\endgroup$ – xzczd Apr 3 at 6:14