cadet / CADET-Core

A modular, fast, and accurate simulation framework for (bio)chemical processes
Other
55 stars 26 forks source link

Choose best defaults for modified Newton method #221

Open jbreue16 opened 3 months ago

jbreue16 commented 3 months ago

We have made the choice of full and modified Newton method optional. Full Newton method is still the default since FV is also still the default, for which the modified Newton showed mixed results with full Newton being more performant for more time consuming models (i.e. non-linear binding for LRMP and GRM), see the FV benchmarks.

For DG and the LRMP and GRM however, modifed Newton was generally faster, see the DG benchmarks. We added modified Newton as the recommended default for these settings to the documentation.

Once DG becomes the spatial methods default, we need to make modified Newton the default.

Edit: We should also find out which method works best for all new submodules, e.g. crystalliaztion and document that accordingly

jbreue16 commented 3 months ago

Ive tested full vs modified Newton for specific SMB systems (thanks to @schmoelder) and these settings show similar results to what we saw for the single column benchmakrs, i.e. an advantage of the full newton method for FV $N_e=100$ and of the modified Newton method for DG ($N_d=4, N_e=16$). Notably, DG was substantially faster, even though the number of axial discrete points is only slightly smaller (80 for DG and100 for FV ). A more rigorous convergence benchmark could be conducted to get more detailed insights into the perfromance differences.

The results are:

    "single_column_DG": {
        "DG_Modified_Newton_sim_time": 1.2131713000000002,
        "DG_Full_Newton_sim_time": 3.3930438,
        "FV_Modified_Newton_sim_time": 6.588945300000001,
        "FV_Full_Newton_sim_time": 5.599763
    },
    "single_column_DG_cstr": {
        "DG_Modified_Newton_sim_time": 1.2799902,
        "DG_Full_Newton_sim_time": 4.2717521000000005,
        "FV_Modified_Newton_sim_time": 6.9316716000000005,
        "FV_Full_Newton_sim_time": 6.087354
    },
    "single_column_DG_lrm": {
        "DG_Modified_Newton_sim_time": 1.3860162,
        "DG_Full_Newton_sim_time": 4.4453478,
        "FV_Modified_Newton_sim_time": 22.029851,
        "FV_Full_Newton_sim_time": 23.743489200000003
    },
    "smb_DG_cstr": {
        "DG_Modified_Newton_sim_time": 32.962329100000005,
        "DG_Full_Newton_sim_time": 48.967928900000004,
        "FV_Modified_Newton_sim_time": 252.32834300000002,
        "FV_Full_Newton_sim_time": 158.61109960000002
    },
    "smb_DG_lrm": {
        "DG_Modified_Newton_sim_time": 14.4318898,
        "DG_Full_Newton_sim_time": 28.966108900000002,
        "FV_Modified_Newton_sim_time": 416.86199000000005,
        "FV_Full_Newton_sim_time": 254.41401140000002
    }

The benchmark code and its results can be found on gitlab.

jbreue16 commented 3 months ago

I suspected that the difference in performance of the full/modified Newton method for DG and FV comes from the fact that DG is a linear method and our WENO FV is not. So I tested the performance of the full and modified Newton method for linear upwind FV with the assumption that the results might be similar to what we saw for DG For the upwind FV I observed a performance advantage of modified Newton for linear bindings but an advantage fo full Newton for full Newton, so the results do not fully align with the DG results. Results of the upwind FV modified vs full Newton benchmark can be found here.