diff --git a/smart/model.py b/smart/model.py index 7581cb3f..f394d5e9 100644 --- a/smart/model.py +++ b/smart/model.py @@ -8,6 +8,7 @@ import logging import dolfin as d +from dolfin.common.timer import timed import numpy as np import pandas import petsc4py.PETSc as PETSc @@ -210,6 +211,7 @@ def max_dim(self): self.parent_mesh.max_dim = dim return dim + @timed("Initialize Model") def initialize(self, initialize_solver=True): """Main model initialization function, split into 5 subfunctions""" @@ -239,8 +241,10 @@ def initialize(self, initialize_solver=True): self.print_meshes() self.rc.print() + @timed("Initialize model step 1") def _init_1(self): """Checking validity of model""" + logger.debug("Checking validity of model (step 1 of ZZ)", extra=dict(format_type="title")) self._init_1_1_check_mesh_dimensionality() self._init_1_2_check_namespace_conflicts() @@ -250,9 +254,11 @@ def _init_1(self): extra=dict(text_color="magenta"), ) + @timed("Initialize model step 2") def _init_2(self): """Cross-container dependent initializations (requires information from multiple containers)""" + logger.debug( "Cross-Container Dependent Initializations (step 2 of ZZ)", extra=dict( @@ -271,6 +277,7 @@ def _init_2(self): extra=dict(text_color="magenta"), ) + @timed("Initialize model step 3") def _init_3(self): """Mesh-related initializations""" logger.debug( @@ -290,8 +297,10 @@ def _init_3(self): extra=dict(format_type="log_important"), ) + @timed("Initialize model step 4") def _init_4(self): """Dolfin function initializations""" + logger.debug("Dolfin Initializations (step 4 of ZZ)", extra=dict(format_type="title")) self._init_4_0_initialize_dolfin_parameters() self._init_4_1_get_active_compartments() @@ -302,6 +311,7 @@ def _init_4(self): self._init_4_6_check_dolfin_function_validity() self._init_4_7_set_initial_conditions() + @timed("Initialize model step 5") def _init_5(self, initialize_solver): """Convert reactions to fluxes and define variational form. If initialize_solver is true, also initialize solver. diff --git a/smart/solvers.py b/smart/solvers.py index 8e663504..ad8c5992 100644 --- a/smart/solvers.py +++ b/smart/solvers.py @@ -3,6 +3,7 @@ from typing import Dict, List, Optional import dolfin as d +from dolfin.common.timer import timed import petsc4py.PETSc as p from .common import Stopwatch @@ -40,6 +41,7 @@ class smartSNESProblem: and `snes initialize zero matrices` """ + @timed("Initialize smartSNESProblem") def __init__( self, u: d.Function, @@ -113,6 +115,7 @@ def __init__( extra=dict(format_type="data"), ) + @timed("Initialize PETSc Nested Matrix") def init_petsc_matnest(self): Jforms = self.Jforms_all dim = self.dim @@ -195,6 +198,7 @@ def init_petsc_matnest(self): def d_to_p(self, dolfin_matrix): return d.as_backend_type(dolfin_matrix).mat() + @timed("Initialize PETSc Nested Vector") def init_petsc_vecnest(self): dim = self.dim logger.info("Initializing block residual vector", extra=dict(format_type="assembly")) @@ -237,6 +241,7 @@ def init_petsc_vecnest(self): self.Fpetsc_nest = p.Vec().createNest(Fpetsc, comm=self.comm) self.Fpetsc_nest.assemble() + @timed("SNES Assemble Jacobian Nested Matrix") def assemble_Jnest(self, Jnest): """Assemble Jacobian nest matrix. @@ -316,6 +321,7 @@ def assemble_Jnest(self, Jnest): self.stopwatches["snes jacobian assemble"].pause() + @timed("SNES Assemble Residual Nest Vector") def assemble_Fnest(self, Fnest): """ Assemble residual nest vector @@ -366,6 +372,7 @@ def J(self, snes, u, Jnest, P): self.copy_u(u) self.assemble_Jnest(Jnest) + @timed("SNES Initialize Zero Matrices") def init_petsc_matrix(self, i, j, nnz_guess=None, set_lgmap=False, assemble=False): """ Initialize a PETSc matrix with appropriate structure @@ -406,6 +413,7 @@ def init_petsc_matrix(self, i, j, nnz_guess=None, set_lgmap=False, assemble=Fals return M + @timed("SNES Initialize Zero Vectors") def init_petsc_vector(self, j, assemble=False): """Initialize a dolfin wrapped PETSc vector with appropriate structure @@ -420,6 +428,7 @@ def init_petsc_vector(self, j, assemble=False): if assemble: V.assemble() + return V def Jijk_name(self, i: int, j: int, k: Optional[int] = None):