def test_constructor(self): """ Test constructor. """ # setUp() tests constructor with default type jacobianA = Jacobian(self.fields.solution(), "aij") jacobianB = Jacobian(self.fields.solution(), "baij") return
def setUp(self): """ Setup mesh and associated field. """ from spatialdata.geocoords.CSCart import CSCart cs = CSCart() cs.inventory.spaceDim = 2 cs._configure() from spatialdata.units.Nondimensional import Nondimensional normalizer = Nondimensional() normalizer._configure() from pylith.meshio.MeshIOAscii import MeshIOAscii importer = MeshIOAscii() importer.inventory.filename = "data/tri3.mesh" importer.inventory.coordsys = cs importer._configure() self.mesh = importer.read(debug=False, interpolate=False) from pylith.topology.SolutionFields import SolutionFields fields = SolutionFields(self.mesh) fields.add("disp t+dt", "displacement") fields.solutionName("disp t+dt") solution = fields.solution() solution.newSection(solution.VERTICES_FIELD, self.mesh.dimension()) solution.allocate() solution.zero() self.fields = fields self.jacobian = Jacobian(solution) return
def initialize(self, dimension, normalizer): """ Initialize problem for implicit time integration. """ logEvent = "%sinit" % self._loggingPrefix self._eventLogger.eventBegin(logEvent) comm = self.mesh().comm() 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("velocity(t)", "velocity") self.fields.copyLayout("dispIncr(t->t+dt)") # Setup fields and set to zero 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() self._debug.log(resourceUsageString()) #memoryLogger.stagePop() # Allocates memory for nonzero pattern and Jacobian if 0 == comm.rank: self._info.log("Creating Jacobian matrix.") self._setJacobianMatrixType() from pylith.topology.Jacobian import Jacobian self.jacobian = Jacobian(self.fields.solution(), self.matrixType, self.blockMatrixOkay) self.jacobian.zero() # TEMPORARY, to get correct memory usage 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) return
def test_write(self): """ Test write(). :WARNING: This is not a complete test of write(). We do not verify the results. """ self.jacobian = Jacobian(self.fields.solution(), "aij") self.jacobian.assemble("final_assembly") self.jacobian.write("jacobian.mat", self.mesh.comm()) # No testing of result. return
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, fault, fields) = self._initialize() from pylith.topology.Jacobian import Jacobian jacobian = Jacobian(fields.solution()) jacobian.zero() t = 1.0 fault.integrateJacobian(jacobian, t, fields) self.assertEqual(False, fault.needNewJacobian()) # We should really add something here to check to make sure things # actually initialized correctly return
def test_integrateJacobian(self): """ Test integrateJacobian(). WARNING: This is not a rigorous test of integrateJacobian() because we don't verify the results. """ (mesh, bc, fields) = self._initialize() from pylith.topology.Jacobian import Jacobian jacobian = Jacobian(fields.solution()) jacobian.zero() t = 0.24 bc.integrateJacobian(jacobian, t, fields) self.assertEqual(False, bc.needNewJacobian()) # No testing of result. return
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.Jacobian import Jacobian jacobian = Jacobian(fields.solution()) jacobian.zero() t = 7.3 self.assertEqual(True, integrator.needNewJacobian()) integrator.integrateJacobian(jacobian, t, fields) self.assertEqual(False, integrator.needNewJacobian()) # No test of result. return