class SimulationDC(BaseSimulation): """ A wrapper to run a DC Forward Simulation :param CasingSimulations.model.WholeSpace modelParameters: casing parameters object :param CasingSimulations.mesh.BaseMeshGenerator mesh: a CasingSimulation mesh generator object """ src_a = properties.Vector3Array("a electrode location", required=True) src_b = properties.Vector3Array("return electrode location", required=True) fields_filename = properties.String("filename for the fields", default="fieldsDC.npy") formulation = properties.String("field that we are solving for", default="phi") physics = "DC" def __init__(self, **kwargs): super(SimulationDC, self).__init__(**kwargs) self._prob = DC.Problem3D_CC(self.meshGenerator.mesh, sigmaMap=self.physprops.wires.sigma, bc_type='Dirichlet', Solver=Solver) self._srcList = [ DC.Src.Dipole([], self.src_a[i, :], self.src_b[i, :]) for i in range(self.src_a.shape[0]) ] # self._src = DC.Src.Dipole([], self.src_a, self.src_b) self._survey = DC.Survey(self._srcList) self._prob.pair(self._survey)
class Vector3Array(ScalarArray): """Shared array of 3D vectors""" array = properties.Vector3Array( 'Shared Vector3 Array', serializer=array_serializer, deserializer=array_deserializer(('*', 3)) )
def test_vector3array(self): class HasVec3Arr(properties.HasProperties): vec3 = properties.Vector3Array('simple vector array') hv3 = HasVec3Arr() hv3.vec3 = np.array([[1., 2., 3.]]) assert isinstance(hv3.vec3, vmath.Vector3Array) hv3.vec3 = ['east', 'south', [1., 1., 1.]] assert np.allclose(hv3.vec3, [[1., 0., 0.], [0., -1., 0.], [1., 1., 1.]]) hv3.vec3 = [1., 2., 3.] assert hv3.vec3.shape == (1, 3) with self.assertRaises(ValueError): hv3.vec3 = 'diagonal' with self.assertRaises(ValueError): hv3.vec3 = ['diagonal'] with self.assertRaises(ValueError): hv3.vec3 = [[1., 2.]] class HasLenVec3Arr(properties.HasProperties): vec3 = properties.Vector3Array('length 5 vector', length=5) hv3 = HasLenVec3Arr() hv3.vec3 = [[0., 0., 1.], [1., 0., 0.]] assert np.allclose(hv3.vec3, [[0., 0., 5.], [5., 0., 0.]]) assert isinstance( properties.Vector3Array.from_json([[4., 5., 6.], [7., 8., 9.]]), vmath.Vector3Array ) assert properties.Vector3Array('').equal( vmath.Vector3Array([[4., 5., 6.], [7., 8., 9.]]), vmath.Vector3Array([[4., 5., 6.], [7., 8., 9.]]) ) assert not properties.Vector3Array('').equal( vmath.Vector3Array([[4., 5., 6.], [7., 8., 9.]]), vmath.Vector3Array([[4., 5., 6.]]) ) assert not properties.Vector3Array('').equal( vmath.Vector3Array([[4., 5., 6.], [7., 8., 9.]]), np.array([[4., 5., 6.], [7., 8., 9.]]) ) assert not properties.Vector3Array('').equal('hi', 'hi')
class HasShapeVec3Arr(properties.HasProperties): vec3 = properties.Vector3Array('', shape={(2, 3), (3, 3)})
class HasLenVec3Arr(properties.HasProperties): vec3 = properties.Vector3Array('length 5 vector', length=5)
class HasVec3Arr(properties.HasProperties): vec3 = properties.Vector3Array('simple vector array')
class HasProps2(properties.HasProperties): my_list = properties.List('my list', properties.Bool('')) five = properties.GettableProperty('five', default=5) my_array = properties.Vector3Array('my array')