def test_DMI_energy_density_3D(): """Same as above, on a 3D mesh.""" mesh = df.UnitCubeMesh(4, 4, 4) V = df.VectorFunctionSpace(mesh, "CG", 1, dim=3) M = Field(V, df.Expression(("-0.5*x[1]", "0.5*x[0]", "1"), degree=1)) Ms = 10 D = 1 dmi = DMI(D) dmi.setup(M, Field(df.FunctionSpace(mesh, 'DG', 0), Ms)) density = dmi.energy_density() deviation = np.abs(density - 1.0) print "3D energy density (expect array of 1):" print density print "Max deviation: %g" % np.max(deviation) assert np.all(deviation < TOL), \ "Max deviation %g, should be zero." % np.max(deviation)
def test_DMI_energy_density_2D(): """ For a vector field (x, y, z) = 0.5 * (-y, x, c), the curl is exactly 1.0. (HF) """ mesh = df.UnitSquareMesh(4, 4) V = df.VectorFunctionSpace(mesh, "CG", 1, dim=3) M = Field(V, value=df.Expression(("-0.5*x[1]", "0.5*x[0]", "1"), degree=1)) Ms = 1 D = 1 dmi = DMI(D) dmi.setup(M, Field(df.FunctionSpace(mesh, 'DG', 0), Ms)) density = dmi.energy_density() deviation = np.abs(density - 1.0) print "2D energy density (expect array of 1):" print density print "Max deviation: %g" % np.max(deviation) assert np.all(deviation < TOL), \ "Max deviation %g, should be zero." % np.max(deviation)