def test_integrateJacobian(self): """ Test integrateJacobian(). WARNING: This is not a rigorous test of integrateJacobian() because we neither set the input fields or verify the results. """ (mesh, integrator) = self._preinitialize() fields = self._initialize(mesh, integrator) from pylith.topology.Field import Field jacobian = Field(mesh) spaceDim = mesh.coordsys().spaceDim() jacobian.subfieldAdd("displacement", spaceDim, jacobian.VECTOR); jacobian.subfieldAdd("lagrange_multiplier", spaceDim, jacobian.VECTOR); jacobian.subfieldsSetup(); jacobian.setupSolnChart(); jacobian.setupSolnDof(spaceDim); jacobian.allocate(); jacobian.zeroAll(); t = 7.3 self.assertEqual(True, integrator.needNewJacobian()) integrator.integrateJacobian(jacobian, t, fields) self.assertEqual(False, integrator.needNewJacobian()) # No test of result. return
def initialize(self, dimension, normalizer): """ Initialize problem for explicit time integration. """ logEvent = "%sinit" % self._loggingPrefix self._eventLogger.eventBegin(logEvent) from pylith.mpi.Communicator import mpi_comm_world comm = mpi_comm_world() self._initialize(dimension, normalizer) #from pylith.utils.petsc import MemoryLogger #memoryLogger = MemoryLogger.singleton() #memoryLogger.setDebug(0) #memoryLogger.stagePush("Problem") # Allocate other fields, reusing layout from dispIncr if 0 == comm.rank: self._info.log("Creating other fields.") self.fields.add("disp(t-dt)", "displacement") self.fields.add("velocity(t)", "velocity") self.fields.add("acceleration(t)", "acceleration") self.fields.copyLayout("dispIncr(t->t+dt)") self._debug.log(resourceUsageString()) # Setup fields and set to zero dispTmdt = self.fields.get("disp(t-dt)") dispTmdt.zeroAll() dispT = self.fields.get("disp(t)") dispT.zeroAll() residual = self.fields.get("residual") residual.zeroAll() residual.createScatter(residual.mesh()) lengthScale = normalizer.lengthScale() timeScale = normalizer.timeScale() velocityScale = lengthScale / timeScale velocityT = self.fields.get("velocity(t)") velocityT.scale(velocityScale.value) velocityT.zeroAll() accelerationScale = velocityScale / timeScale accelerationT = self.fields.get("acceleration(t)") accelerationT.scale(accelerationScale.value) accelerationT.zeroAll() self._debug.log(resourceUsageString()) #memoryLogger.stagePop() if 0 == comm.rank: self._info.log("Creating lumped Jacobian matrix.") from pylith.topology.Field import Field jacobian = Field(self.mesh()) jacobian.label("jacobian") # Setup section manually. Cloning the solution field includes # constraints which messes up the solve for constrained DOF. pressureScale = normalizer.pressureScale() jacobian.subfieldAdd("displacement", dimension, jacobian.VECTOR, lengthScale.value) jacobian.subfieldAdd("lagrange_multiplier", dimension, jacobian.VECTOR, pressureScale.value) jacobian.subfieldsSetup() jacobian.setupSolnChart() jacobian.setupSolnDof(dimension) # Loop over integrators to adjust DOF layout for integrator in self.integrators: integrator.setupSolnDof(jacobian) jacobian.vectorFieldType(jacobian.VECTOR) jacobian.allocate() jacobian.zeroAll() self.jacobian = jacobian self._debug.log(resourceUsageString()) #memoryLogger.stagePush("Problem") if 0 == comm.rank: self._info.log("Initializing solver.") self.solver.initialize(self.fields, self.jacobian, self) self._debug.log(resourceUsageString()) #memoryLogger.stagePop() #memoryLogger.setDebug(0) self._eventLogger.eventEnd(logEvent) return
class Solution(PetscComponent): """Python abstract base class for solution field for problem. FACTORY: solution. """ import pythia.pyre.inventory from .SolnDisp import SolnDisp from .SolutionSubfield import subfieldFactory subfields = pythia.pyre.inventory.facilityArray( "subfields", family="soln_subfields", itemFactory=subfieldFactory, factory=SolnDisp) subfields.meta['tip'] = "Subfields in solution." # PUBLIC METHODS ///////////////////////////////////////////////////// def __init__(self, name="solution"): """Constructor. """ PetscComponent.__init__(self, name, facility="solution") self.field = None return def preinitialize(self, problem, mesh): """Do minimal initialization of solution. """ from pylith.mpi.Communicator import mpi_comm_world comm = mpi_comm_world() if 0 == comm.rank: self._info.log("Performing minimal initialization of solution.") from pylith.topology.Field import Field self.field = Field(mesh) self.field.setLabel("solution") spaceDim = mesh.getCoordSys().getSpaceDim() for subfield in self.subfields.components(): subfield.initialize(problem.normalizer, spaceDim) if 0 == comm.rank: self._debug.log( "Adding subfield '%s' as '%s' with components %s to solution." % (subfield.fieldName, subfield.userAlias, subfield.componentNames)) descriptor = subfield.getTraitDescriptor("quadrature_order") if hasattr(descriptor.locator, "source") and descriptor.locator.source == "default": quadOrder = problem.defaults.quadOrder else: quadOrder = subfield.quadOrder self.field.subfieldAdd( subfield.fieldName, subfield.userAlias, subfield.vectorFieldType, subfield.componentNames, subfield.scale.value, subfield.basisOrder, quadOrder, subfield.dimension, subfield.cellBasis, subfield.isBasisContinuous, subfield.feSpace) return # PRIVATE METHODS //////////////////////////////////////////////////// def _configure(self): """Set members based using inventory. """ PetscComponent._configure(self) return def _cleanup(self): if self.field: self.field.deallocate() return