From e01c91d689797f1afc863be52e5788d21754ec35 Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Thu, 20 Oct 2022 13:34:16 +0200 Subject: [PATCH] Check loading subregions with compute --- micromagnetictests/calculatortests/compute.py | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/micromagnetictests/calculatortests/compute.py b/micromagnetictests/calculatortests/compute.py index c5dfe37..af4947d 100644 --- a/micromagnetictests/calculatortests/compute.py +++ b/micromagnetictests/calculatortests/compute.py @@ -16,8 +16,12 @@ def setup(self): p2 = (10e-9, 2e-9, 2e-9) cell = (2e-9, 2e-9, 2e-9) region = df.Region(p1=p1, p2=p2) - mesh = df.Mesh(region=region, cell=cell) - + subregions = { + "a": df.Region(p1=(0, 0, 0), p2=(6e-9, 2e-9, 2e-9)), + "b": df.Region(p1=(6e-9, 0, 0), p2=(10e-9, 2e-9, 2e-9)), + } + mesh = df.Mesh(region=region, cell=cell, subregions=subregions) + self.subregions = subregions self.system = mm.System(name=name) self.system.energy = ( mm.Exchange(A=1e-12) @@ -39,23 +43,24 @@ def test_energy(self): def test_energy_density(self): for term in self.system.energy: - assert isinstance( - self.calculator.compute(term.density, self.system), df.Field - ) - assert isinstance( - self.calculator.compute(self.system.energy.density, self.system), df.Field - ) + e_density = self.calculator.compute(term.density, self.system) + assert isinstance(e_density, df.Field) + assert e_density.mesh.subregions == self.subregions + e_density = self.calculator.compute(self.system.energy.density, self.system) + assert isinstance(e_density, df.Field) + assert e_density.mesh.subregions == self.subregions self.calculator.delete(self.system) def test_effective_field(self): for term in self.system.energy: - assert isinstance( - self.calculator.compute(term.effective_field, self.system), df.Field - ) - assert isinstance( - self.calculator.compute(self.system.energy.effective_field, self.system), - df.Field, + effective_field = self.calculator.compute(term.effective_field, self.system) + assert isinstance(effective_field, df.Field) + assert effective_field.mesh.subregions == self.subregions + effective_field = self.calculator.compute( + self.system.energy.effective_field, self.system ) + assert isinstance(effective_field, df.Field) + assert effective_field.mesh.subregions == self.subregions self.calculator.delete(self.system) def test_invalid_func(self): @@ -79,12 +84,14 @@ def test_dmi(self): assert isinstance( self.calculator.compute(term.energy, self.system), float ) - assert isinstance( - self.calculator.compute(term.density, self.system), df.Field - ) - assert isinstance( - self.calculator.compute(term.effective_field, self.system), df.Field + e_density = self.calculator.compute(term.density, self.system) + assert isinstance(e_density, df.Field) + assert e_density.mesh.subregions == self.subregions + effective_field = self.calculator.compute( + term.effective_field, self.system ) + assert isinstance(effective_field, df.Field) + assert effective_field.mesh.subregions == self.subregions assert isinstance( self.calculator.compute(self.system.energy.energy, self.system), float )