There are many things to make your code use less memory. See for instance: Form compilation — FEniCS Tutorial @ Sorbonne
or
PETSc NonlinearProblem running slow - #4 by dokken
Speed up repeated evaluation, derivative (and assembly) of form - #2 by dokken
Out of memory error in frequency for loop - #4 by nate
1 Like