Skip to content

Hysteresis loops with a list of field tuples #20

Description

@dmsilev

When calling "hysteresis" with an array of tuples for the field, i.e. using the example in the API documentation:

'# Create hysteresis loop with field sweep from -100 mT to 100 mT along y-direction
Hs = [(0, i*mT, 0) for i = -100:10:100]
hysteresis(sim, Hs; full_loop=true)`

it fails with an error of

ERROR: LoadError: MethodError: no method matching getindex(::Nothing, ::Int64)
The function getindex exists, but no method is defined for this combination of argument types.
Stacktrace:
[1] hysteresis(sim::MicroMagnetic.MicroSim{Float64}, Hs::Vector{Tuple{Float64, Float64, Float64}}; direction::Tuple{Int64, Int64, Int64}, stopping_dmdt::Float64, max_steps::Int64, output::String, full_loop::Bool, H_output::Nothing)
@ MicroMagnetic ~/mag_solve/MicroMagnetic/MicroMagnetic.jl/src/sim.jl:712

712 in sim.jl is update_zeeman(sim, H, H_output=H_output[i]), and the problem seems to be H_output, which is an optional parameter for hysteresis() that defaults to nothing. If it's specified by the calling routine, everything runs correctly. Simplest fixes would probably be either to make it a required parameter or initialize it to something at the beginning of the function before enumerating over the list of fields. The workaround is just to specify the output:

'Hs = [(0, i*mT, 0) for i = -100:10:100]
H_output = Hs
hysteresis(sim, Hs; full_loop=true,H_output=H_output)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions