5
$\begingroup$

In this example the wave equation

U = NDSolveValue[{D[u[x, t], {t, 2}] == D[u[x, t], {x, 2}],
u[0, t] == 0, u[1, t] == 0, (* RBn *)
u[x, 0] == 1 - Abs[2 x - 1], (D[u[x, t], t] /. t -> 0) == 0 (* 
ABn *)
}, u, {x, 0, 1}, {t, 0, 2 },
Method -> {"MethodOfLines", "TemporalVariable" -> t, 
"SpatialDiscretization" -> {"FiniteElement","MeshOptions" -> 
{"MaxCellMeasure" -> 0.3}}}]
Plot3D[ U[x, t] , {x, 0, 1}, {t, 0, 2}, Mesh -> All,AxesLabel -> {x, t}]

enter image description here

is solved with the "MethodOfLines" and "FiniteElement".

My questions

#1 How can I get the complete mesh(two dimensional), which NDSolve uses? U["ElementMesh"["Wireframe" ] seems to be onedimensional?

#2 How can I get the time grid of "MethodOfLines"?

#3 Is it possible to expand the pde with an additional variable to a DAE system and calculate for example NIntegrate[u[x,t],{x,0,1}]in every time step t?

Thanks!

answers #1: xi = Union@Flatten[Map[Union@#[[All, 1]] &, U["Grid"]] , 1] ;

answers #2: ti=U["Coordinates"] [[-1]];

$\endgroup$
  • $\begingroup$ by "complete mesh(two dimensional)" do you mean a List of TriangleElements ? $\endgroup$ – andre314 Jul 27 '18 at 9:43
  • $\begingroup$ Yes, elements or node coordinates! $\endgroup$ – Ulrich Neumann Jul 27 '18 at 9:44
  • 1
    $\begingroup$ The problem is that in your example the finite element method is used only for the temporal variable x. The resolution over the time t is done with the "method of line" (which considers the equations as a set of ODEs). Hence from the Finite Element Method point of view, the problem is a 1D problem. That's the reason why the Finite Element Method returns some 'LineElement' and not 'TriangleElement'. By the way, the mesh we see in your question has nothing to do with the real mesh internaly used by the FEM (it's a mesh created by Plot3D) $\endgroup$ – andre314 Jul 27 '18 at 9:54
  • $\begingroup$ @andre: Thank you for your helpful answer, which solves my first question. $\endgroup$ – Ulrich Neumann Jul 27 '18 at 10:02
  • 1
    $\begingroup$ I think that U["ValuesOnGrid"] is what you are looking for in the first 2 questions (?) $\endgroup$ – andre314 Jul 27 '18 at 10:08
2
$\begingroup$

From the comments/OP (for completeness):

answers #1: xi = Union@Flatten[Map[Union@#[[All, 1]] &, U["Grid"]] , 1] ;

answers #2: ti=U["Coordinates"] [[-1]];

answers #3:

I don't think computing the integrals after NDSolve[] would be any less efficient than computing them during. It's probably possible to do it during the NDSolve integration (I've done it before here on the site with the method of lines and a tensor grid, (192707), (192736)), but it's much simpler after NSolve has finished.

{xmesh, tgrid} = U["Coordinates"];
ivals = Table[NIntegrate[U[x, t], {x} \[Element] xmesh], {t, tgrid}];
ListLinePlot[ivals]

enter image description here

$\endgroup$
  • $\begingroup$ @ MichaelE2 Thanks, very helpful links! $\endgroup$ – Ulrich Neumann May 30 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.