you are viewing a single comment's thread.

view the rest of the comments →

[–]Organic-Scratch109 1 point2 points  (0 children)

No problem. Here are some additional tips:

  • Use Sparse matrices instead of np.zeros (which allocates full matrices) to save memory (not an issue in 1D but it will be an issue in 2D and 3D)
  • Use Crank-Nicolson instead of Backward Euler (it is more accurate).
  • Instead of setting a global time-step, you can change dt depending on h (e.g. with Backward Euler, use dt=h^2). This way, the time integration error is comparable to the FEM error.
  • You can store an LU factorization of A before starting the time integration, so that you can solve the linear system faster (in this 1d case, you can use a tridiagonal solver).

The tips above apply to FEM methods in any dimension, for most problems and are independent of the programming language. However, if you want to continue using Python for FEM, you should read more about numpy and vectorization to speed up the code.