ubermag / help

Repository for raising issues and requesting help on Ubermag
BSD 2-Clause "Simplified" License
11 stars 3 forks source link

TypeError: 'nvdim' must be of type int. #267

Closed DebanjanPolley closed 11 months ago

DebanjanPolley commented 11 months ago

Hi,

I am trying to define a circular region containing magnetic materials as the following:

region = df.Region(p1=(-50e-9, -50e-9, -50e-9), p2=(50e-9, 50e-9, 50e-9))
mesh = df.Mesh(region=region, cell=(5e-9, 5e-9, 5e-9))

system = mm.System(name='sine_hysteresis')
system.energy = mm.Exchange(A=1e-12) + mm.UniaxialAnisotropy(K=4e5, u=(0, 0, 1)) + mm.Demag()

def Ms_fun(point):
    x, y, z = point
    if x**2 + y**2 + z**2 <= 50e-9**2:
        return 1e6
    else:
        return 0

system.m = df.Field(mesh, dim=3, value=(0, 0, -1), norm=Ms_fun)

However, I am getting the following error.

Traceback (most recent call last)
Cell In[2], line 14
     11     else:
     12         return 0
---> 14 system.m = df.Field(mesh, dim=3, value=(0, 0, -1), norm=Ms_fun)

File ~/anaconda3/envs/UM/lib/python3.10/site-packages/discretisedfield/field.py:178, in Field.__init__(self, mesh, nvdim, value, norm, vdims, dtype, unit, valid, vdim_mapping, **kwargs)
    175 self._mesh = mesh
    177 if not isinstance(nvdim, numbers.Integral):
--> 178     raise TypeError("'nvdim' must be of type int.")
    179 elif nvdim < 1:
    180     raise ValueError("'nvdim' must be greater than zero.")

TypeError: 'nvdim' must be of type int.

Can you please help me with this?

lang-m commented 11 months ago

Hi @DebanjanPolley, the error is coming from the recent changes introduced in ubermag 2023.10. In short, you have to replace dim=3 with nvdim=3. See here for a full list of changes: https://ubermag.github.io/changelog.html#oct-23-2023