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 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 test_copy(self): """ Test newSection(field). """ fieldB = Field(self.mesh) fieldB.allocate() fieldB.copy(self.field) # No test of result return
def test_operatorAdd(self): """ Test add(). """ fieldB = Field(self.mesh) fieldB.allocate() self.field.add(fieldB) # No test of result return
def test_copy(self): """ Test newSection(field). """ fieldB = Field(self.mesh) fieldB.allocate() fieldB.copy(self.field) # No test of result return
def test_operatorAdd(self): """ Test add(). """ fieldB = Field(self.mesh) fieldB.allocate() self.field.add(fieldB) # No test 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.Field import Field jacobian = Field(mesh) jacobian.newSection(jacobian.VERTICES_FIELD, mesh.coordsys().spaceDim()) jacobian.allocate() 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
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 TestMeshField(unittest.TestCase): """ Unit testing of Field object. """ 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) self.field = Field(self.mesh) self.field.allocate() return def test_constructorA(self): """ Test constructor. """ return def test_mesh(self): """ Test mesh(). """ mesh = self.field.mesh() self.assertEqual(2, mesh.dimension()) return def test_label(self): """ Test label(). """ label = "field A" self.field.label(label) self.assertEqual(label, self.field.label()) return def test_vectorFieldType(self): """ Test vectorFieldType(). """ fieldType = Field.MULTI_SCALAR self.field.vectorFieldType(fieldType) self.assertEqual(fieldType, self.field.vectorFieldType()) return def test_scale(self): """ Test scale(). """ scale = 2.0 self.field.scale(scale) self.assertEqual(scale, self.field.scale()) return def test_dimensionalizeOkay(self): """ Test dimensionalizeOkay(). """ self.assertEqual(False, self.field.dimensionalizeOkay()) self.field.dimensionalizeOkay(True) self.assertEqual(True, self.field.dimensionalizeOkay()) return def test_spaceDim(self): """ Test spaceDim(). """ self.assertEqual(2, self.field.spaceDim()) return def test_newSectionDomain(self): """ Test newSection(domain). """ self.field.newSection(Field.VERTICES_FIELD, 4) # No test of result return def test_cloneSectionField(self): """ Test newSection(field). """ fieldB = Field(self.mesh) fieldB.cloneSection(self.field) # No test of result return def test_operatorAdd(self): """ Test add(). """ fieldB = Field(self.mesh) fieldB.allocate() self.field.add(fieldB) # No test of result return def test_copy(self): """ Test newSection(field). """ fieldB = Field(self.mesh) fieldB.allocate() fieldB.copy(self.field) # 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
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.newSection(jacobian.VERTICES_FIELD, dimension) jacobian.allocate() jacobian.label("jacobian") jacobian.vectorFieldType(jacobian.VECTOR) 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 TestMeshField(unittest.TestCase): """ Unit testing of Field object. """ 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) self.field = Field(self.mesh) self.field.allocate() return def test_constructorA(self): """ Test constructor. """ return def test_mesh(self): """ Test mesh(). """ mesh = self.field.mesh() self.assertEqual(2, mesh.dimension()) return def test_label(self): """ Test label(). """ label = "field A" self.field.label(label) self.assertEqual(label, self.field.label()) return def test_vectorFieldType(self): """ Test vectorFieldType(). """ fieldType = Field.MULTI_SCALAR self.field.vectorFieldType(fieldType) self.assertEqual(fieldType, self.field.vectorFieldType()) return def test_scale(self): """ Test scale(). """ scale = 2.0 self.field.scale(scale) self.assertEqual(scale, self.field.scale()) return def test_dimensionalizeOkay(self): """ Test dimensionalizeOkay(). """ self.assertEqual(False, self.field.dimensionalizeOkay()) self.field.dimensionalizeOkay(True) self.assertEqual(True, self.field.dimensionalizeOkay()) return def test_spaceDim(self): """ Test spaceDim(). """ self.assertEqual(2, self.field.spaceDim()) return def test_newSectionDomain(self): """ Test newSection(domain). """ self.field.newSection(Field.VERTICES_FIELD, 4) # No test of result return def test_cloneSectionField(self): """ Test newSection(field). """ fieldB = Field(self.mesh) fieldB.cloneSection(self.field) # No test of result return def test_operatorAdd(self): """ Test add(). """ fieldB = Field(self.mesh) fieldB.allocate() self.field.add(fieldB) # No test of result return def test_copy(self): """ Test newSection(field). """ fieldB = Field(self.mesh) fieldB.allocate() fieldB.copy(self.field) # No test of result return