geo-fluid-dynamics / phaseflow-fenics

Phaseflow simulates the convection-coupled melting and solidification of phase-change materials.
MIT License
52 stars 22 forks source link

Newton method not quadratic for variable viscosity test #175

Open agzimmerman opened 6 years ago

agzimmerman commented 6 years ago

tests/test_variable_viscosity.py::test_variable_viscosity Number of cells increased from 2000 to 2040 (2.0% increase). Number of cells increased from 2040 to 2360 (15.7% increase). Number of cells increased from 2360 to 3000 (27.1% increase). Number of cells increased from 3000 to 4280 (42.7% increase). Calling DOLFIN just-in-time (JIT) compiler, this may take some time. --- Instant: compiling --- ^[[BRunning Phaseflow with the following arguments: ({'temperature_of_fusion': -0.01, 'output_dir': 'output/test_variable_viscosity', 'start_time': 0.0, 'adaptive': False, 'initial_values': Coefficient(FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 12), MixedElement(VectorElement(FiniteElement('Lagrange', triangle, 2), dim=2), FiniteElement('Lagrange', triangle, 1), FiniteElement('Lagrange', triangle, 1))), 17), 'nlp_relative_tolerance': 1e-08, 'heat_capacity': 1.0, 'end_time': 20.0, 'steady_relative_tolerance': 0.0001, 'rayleigh_number': 1000000.0, 'ddT_m_B': <function run..ddT_m_B at 0x7fc38350d9d8>, 'nlp_absolute_tolerance': 1e-08, 'adaptive_solver_tolerance': 0.0001, 'penalty_parameter': 1e-07, 'boundary_conditions': [<dolfin.fem.bcs.DirichletBC; proxy of <Swig Object of type 'std::shared_ptr< dolfin::DirichletBC > ' at 0x7fc383524cf0> >, <dolfin.fem.bcs.DirichletBC; proxy of <Swig Object of type 'std::shared_ptr< dolfin::DirichletBC > ' at 0x7fc38350be10> >], 'adaptive_metric': 'all', 'gravity': (0.0, 0.0), 'stefan_number': 1e+16, 'solid_viscosity': 1000000.0, 'time_step_size': 20.0, 'regularization_smoothing_factor': 0.01, 'nlp_max_iterations': 50, 'm_B': <function run..m_B at 0x7fc38367c488>, 'thermal_conductivity': 0.0, 'liquid_viscosity': 0.01, 'nlp_relaxation': 1.0, 'prandtl_number': 0.71, 'stop_whensteady': True}, []) Running 2D problem Writing solution to HDF5+XDMF Solving nonlinear variational problem. Newton iteration 0: r (abs) = 2.540e+06 (tol = 1.000e-08) r (rel) = 1.000e+00 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 1: r (abs) = 4.360e+05 (tol = 1.000e-08) r (rel) = 1.716e-01 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 2: r (abs) = 1.316e+03 (tol = 1.000e-08) r (rel) = 5.179e-04 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 3: r (abs) = 4.040e+02 (tol = 1.000e-08) r (rel) = 1.590e-04 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 4: r (abs) = 1.628e+02 (tol = 1.000e-08) r (rel) = 6.409e-05 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 5: r (abs) = 6.912e+01 (tol = 1.000e-08) r (rel) = 2.721e-05 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 6: r (abs) = 4.120e+01 (tol = 1.000e-08) r (rel) = 1.622e-05 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 7: r (abs) = 2.093e+01 (tol = 1.000e-08) r (rel) = 8.237e-06 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 8: r (abs) = 1.351e+01 (tol = 1.000e-08) r (rel) = 5.316e-06 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 9: r (abs) = 7.652e+00 (tol = 1.000e-08) r (rel) = 3.012e-06 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 10: r (abs) = 4.924e+00 (tol = 1.000e-08) r (rel) = 1.938e-06 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 11: r (abs) = 2.951e+00 (tol = 1.000e-08) r (rel) = 1.161e-06 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 12: r (abs) = 1.877e+00 (tol = 1.000e-08) r (rel) = 7.389e-07 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 13: r (abs) = 1.154e+00 (tol = 1.000e-08) r (rel) = 4.544e-07 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 14: r (abs) = 7.296e-01 (tol = 1.000e-08) r (rel) = 2.872e-07 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 15: r (abs) = 4.543e-01 (tol = 1.000e-08) r (rel) = 1.788e-07 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 16: r (abs) = 2.864e-01 (tol = 1.000e-08) r (rel) = 1.127e-07 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 17: r (abs) = 1.794e-01 (tol = 1.000e-08) r (rel) = 7.061e-08 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 18: r (abs) = 1.130e-01 (tol = 1.000e-08) r (rel) = 4.448e-08 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 19: r (abs) = 7.100e-02 (tol = 1.000e-08) r (rel) = 2.795e-08 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 20: r (abs) = 4.472e-02 (tol = 1.000e-08) r (rel) = 1.760e-08 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 21: r (abs) = 2.814e-02 (tol = 1.000e-08) r (rel) = 1.108e-08 (tol = 1.000e-08) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 22: r (abs) = 1.773e-02 (tol = 1.000e-08) r (rel) = 6.979e-09 (tol = 1.000e-08) Newton solver finished in 22 iterations and 22 linear solver iterations. Reached time t = 20.0 Writing solution to HDF5+XDMF Unsteadiness (L2 norm of relative time residual), || w{n+1} || / || w_n || = 0.23221617812108658 Reached end time, t = 20.0 Computed bounding box tree with 8559 nodes for 4280 entities. PASSED

=========================================== 11 tests deselected by '-kvariable_viscosity' ============================================ ============================================== 1 passed, 11 deselected in 23.46 seconds ==============================================

agzimmerman commented 6 years ago

While refactoring in another branch, I discovered that reducing the quadrature degree fixed this issue, as was done in commit 9a9e88b7bc31cfc864a717afdf0db6c27256a2dd.

Here's the new output:

tests/test_benchmarks.py::test_lid_driven_cavity_with_solid_subdomain_benchmark Number of cells increased from 2000 to 2040 (2.0% increase). Number of cells increased from 2040 to 2360 (15.7% increase). Number of cells increased from 2360 to 3000 (27.1% increase). Number of cells increased from 3000 to 4280 (42.7% increase). Writing solution to output/benchmarks/lid_driven_cavity_with_solid_subdomain/solution.xdmf Solving nonlinear variational problem. Newton iteration 0: r (abs) = 2.836e+00 (tol = 1.000e-10) r (rel) = 1.000e+00 (tol = 1.000e-09) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 1: r (abs) = 1.452e-02 (tol = 1.000e-10) r (rel) = 5.120e-03 (tol = 1.000e-09) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 2: r (abs) = 1.110e-03 (tol = 1.000e-10) r (rel) = 3.914e-04 (tol = 1.000e-09) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 3: r (abs) = 1.437e-05 (tol = 1.000e-10) r (rel) = 5.068e-06 (tol = 1.000e-09) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 4: r (abs) = 2.432e-08 (tol = 1.000e-10) r (rel) = 8.572e-09 (tol = 1.000e-09) Solving linear system of size 21710 x 21710 (PETSc LU solver, umfpack). PETSc Krylov solver starting to solve 21710 x 21710 system. Newton iteration 5: r (abs) = 1.493e-14 (tol = 1.000e-10) r (rel) = 5.264e-15 (tol = 1.000e-09) Newton solver finished in 5 iterations and 5 linear solver iterations. Reached time t = 20.0 Writing solution to output/benchmarks/lid_driven_cavity_with_solid_subdomain/solution.xdmf Writing checkpoint file to output/benchmarks/lid_driven_cavity_with_solid_subdomain/checkpoint_t20.0.h5 Reached end time, t = 20.0 Computed bounding box tree with 8559 nodes for 4280 entities. PASSED [ 50%]

agzimmerman commented 6 years ago

I've recently had much success by starting with a large smoothing parameter $r$ and then solving a sequence of problems with progressively smaller $r$, maintaining quadratic convergence of the Newton iterations at every step.