opts[f"{option_prefix}ksp_type"] = "preonly" opts[f"{option_prefix}pc_type"] = "lu" opts[f"{option_prefix}pc_factor_mat_solver_type"] = "mumps" ksp.setFromOptions() wfil = XDMFFile(comm, "disp_Visco_0_05_realEta_Fixed.xdmf", "w") wfil.write_mesh(mesh) with open("sfiles.txt", "w") as fil: fil.write(f"0.0, 0.0\n") for i, t in enumerate(timeVals): right_disp.value = stretchVals[i] print(f"Load step: {i+1}") set_output_file("viscoTrialrunW.log") num_its, converged = solver.solve(u) print(f"Newton iteration: {num_its}") dl_interp(CC, C) k_terms(dt, C, Cn, Cvn, C_quart, C_half, C_thr_quart, CCv, k_cache) CCv.vector.copy(result=Cv_iter.vector) CCv.x.scatter_forward() with del_Cv.vector.localForm() as loc: loc.set(0.0) del_Cv.vector.axpy(1.0, Cv_iter.vector - Cvn.vector) del_Cv.x.scatter_forward() norm_delCv = del_Cv.x.norm() print(f"norm(delta_Cv): {norm_delCv:.5e}") itr: int = 0 max_iters: int = 10
import os import numpy as np from mpi4py import MPI from petsc4py import PETSc from dolfinx import (Form, Function, FunctionSpace, NewtonSolver, NonlinearProblem, UnitSquareMesh, log) from dolfinx.cpp.mesh import CellType from dolfinx.fem.assemble import assemble_matrix, assemble_vector from dolfinx.io import XDMFFile from ufl import (FiniteElement, TestFunctions, TrialFunction, derivative, diff, dx, grad, inner, split, variable) # Save all logging to file log.set_output_file("log.txt") # .. index:: # single: NonlinearProblem; (in Cahn-Hilliard demo) # # A class which will represent the Cahn-Hilliard in an abstract from for # use in the Newton solver is now defined. It is a subclass of # :py:class:`NonlinearProblem <dolfinx.cpp.NonlinearProblem>`.:: class CahnHilliardEquation(NonlinearProblem): def __init__(self, a, L): super().__init__() self.L = Form(L) self.a = Form(a) self._F = None