Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v4
- uses: actions/cache@v5
env:
cache-name: cache-artifacts
with:
Expand Down
2 changes: 1 addition & 1 deletion gui/src/GUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class GUIManager {
});

// Data events
this.wsClient.on('magnetization_data', this.handleMagnetizationData.bind(this));
this.wsClient.on('m_data', this.handleMagnetizationData.bind(this));
this.wsClient.on('run_code_response', this.handleCommandResponse.bind(this));
}

Expand Down
2 changes: 1 addition & 1 deletion src/MicroMagnetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ function dynamic_matrix end

export ovf2png, plot_m, plot_ts, ovf2movie, dynamic_matrix

include("server.jl")
include("const.jl")
include("micro/mesh.jl")
include("fem/mesh.jl")
Expand Down Expand Up @@ -229,7 +230,6 @@ include("init_m.jl")
include("ovf2.jl")
include("vtk.jl")
include("voronoi.jl")
include("server.jl")

include("atomistic/mesh.jl")
include("atomistic/head.jl")
Expand Down
53 changes: 32 additions & 21 deletions src/sim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ end

"""
relax(sim::AbstractSim; max_steps=10000, stopping_dmdt=0.01, save_data_every=100,
save_m_every=-1, using_time_factor=true)
save_m_every=-1, using_time_factor=true, maxsteps=nothing, output="ovf", update_time=1.0)

Relaxes the system using either the `LLG` or `SD` driver. This function is compatible with both [Micromagnetic model](@ref) and [Atomistic spin model](@ref).

Expand All @@ -369,6 +369,7 @@ Relaxes the system using either the `LLG` or `SD` driver. This function is compa
- `save_data_every::Int`: Interval for saving overall data such as energies and average magnetization. A negative value disables data saving (e.g., `save_data_every=-1` saves data only at the end of the relaxation).
- `save_m_every::Int`: Interval for saving magnetization data. A negative value disables magnetization saving.
- `using_time_factor::Bool`: Boolean flag to apply a time factor in `SD` mode for comparison with `LLG` mode. Default is `true`.
- `update_time::Float64`: Time interval (in seconds) for updating visualization data. Default is `1.0`.

**Examples:**

Expand All @@ -377,7 +378,7 @@ Relaxes the system using either the `LLG` or `SD` driver. This function is compa
```
"""
function relax(sim::AbstractSim; max_steps=10000, stopping_dmdt=0.01, save_data_every=100,
save_m_every=-1, using_time_factor=true, maxsteps=nothing, output="ovf")
save_m_every=-1, using_time_factor=true, maxsteps=nothing, output="ovf", update_time=1.0)
if !isnothing(maxsteps)
@warn "The parameter 'maxsteps' is deprecated. Please use 'max_steps' in relax function."
max_steps = maxsteps
Expand All @@ -396,6 +397,8 @@ function relax(sim::AbstractSim; max_steps=10000, stopping_dmdt=0.01, save_data_

N_spins = sim.n_total
dm = create_zeros(3 * N_spins)

last_update_time = time()

driver = sim.driver
@info @sprintf("Running Driver : %s.", typeof(driver))
Expand All @@ -413,6 +416,8 @@ function relax(sim::AbstractSim; max_steps=10000, stopping_dmdt=0.01, save_data_
compute_dm!(dm, sim.prespin, sim.spin, N_spins)
max_dmdt = maximum(dm) / step_size

stop_flag = max_dmdt < stopping_dmdt * dmdt_factor

t = llg_driver ? sim.driver.integrator.t : 0.0
if llg_driver
Verbose[] &&
Expand All @@ -428,38 +433,39 @@ function relax(sim::AbstractSim; max_steps=10000, stopping_dmdt=0.01, save_data_
sim.saver.nsteps += 1
end

if save_data_every > 0 && i % save_data_every == 0
if save_data_every > 0 && (i % save_data_every == 0 || stop_flag)
compute_system_energy(sim, sim.spin, t)
sim.saver.t = t
write_data(sim)
end

if save_m_every > 0 && i % save_m_every == 0
if save_m_every > 0 && (i % save_m_every == 0 || stop_flag)
if output == "ovf"
save_ovf(sim, joinpath(output_folder, @sprintf("m_%08d.ovf", i)))
elseif output == "vts" || output == "vtu"
save_vtk_points(sim, joinpath(output_folder, @sprintf("m_%08d", i)))
end
end

if max_dmdt < stopping_dmdt * dmdt_factor
@info @sprintf("max_dmdt is less than stopping_dmdt=%g @steps=%g, Done!",
stopping_dmdt, i)
if save_data_every > 0 || save_data_every == -1
compute_system_energy(sim, sim.spin, t)
write_data(sim)
end

if save_m_every > 0
if output == "ovf"
save_ovf(sim, joinpath(output_folder, @sprintf("m_%08d.ovf", i)))
elseif output == "vts" || output == "vtu"
save_vtk_points(sim, joinpath(output_folder, @sprintf("m_%08d", i)))
end
current_time = time()
if update_time > 0 && (current_time - last_update_time >= update_time || stop_flag)
if global_client != nothing
response = Dict(
"type" => "m_data",
"m_data" => Array(sim.spin),
)
send_message(global_client, "m_data", response)
# 更新上次更新时间
last_update_time = current_time
end
end

if stop_flag
@info @sprintf("max_dmdt is less than stopping_dmdt=%g @steps=%g, Done!",
stopping_dmdt, i)
break
end

end

return nothing
Expand Down Expand Up @@ -627,8 +633,8 @@ Create a micromagnetic simulation instance with given arguments.
- `axis1`: the cubic anisotropy axis1, should be a tuple, such as (1,0,0)
- `axis2`: the cubic anisotropy axis2, should be a tuple, such as (0,1,0)
- `demag` : include demagnetization or not, should be a boolean, i.e., true or false. By default, demag=false.
- `H`: the external field, should be a tuple or function, i.e., [`TupleOrArrayOrFunction`](@ref).
- `m0` : the initial magnetization, should be a tuple or function, i.e., [`TupleOrArrayOrFunction`](@ref).
- `H`: the external field, should be a tuple or function, i.e., [`TupleOrArrayOrFunction`](@ref).
- `m0` : the initial magnetization, should be a tuple or function, i.e., [`TupleOrArrayOrFunction`](@ref).
- `T` : the temperature, should be should be [`NumberOrArrayOrFunction`](@ref).
- `shape` : the shape defines the geometry of the sample, where parameters are configured.
"""
Expand All @@ -647,7 +653,7 @@ function create_sim(mesh, args::Dict)
#Create the mesh using given driver and name
sim = Sim(mesh; driver=driver, integrator=integrator, name=name)

#If the simulation is the standard micromagnetic simulation.
#If the simulation is the standard micromagnetics simulation.
if isa(mesh, FDMesh)

# we set the Ms anyway
Expand Down Expand Up @@ -1043,3 +1049,8 @@ end
function advance_step(sim::AbstractSim)
return advance_step(sim, sim.driver.integrator)
end





Loading