Gaspard Jankowiak 4 months ago
parent
commit
c6a3460024
3 changed files with 22 additions and 12 deletions
  1. 9
    5
      src/CellSim.jl
  2. 1
    1
      src/CellSimCommon.jl
  3. 12
    6
      src/Nucleus.jl

+ 9
- 5
src/CellSim.jl View File

@@ -243,8 +243,8 @@ function launch(P::CSC.Params, F::CSC.Flags, config)
243 243
     end
244 244
     println(" ")
245 245
 
246
-    if F.DEBUG
247
-        println("*** DEBUG MODE ***")
246
+    if F.debug
247
+        println("*** debug MODE ***")
248 248
     end
249 249
 
250 250
     run(`stty -icanon`)
@@ -354,7 +354,7 @@ function launch(P::CSC.Params, F::CSC.Flags, config)
354 354
         if haskey(config, "plot_period")
355 355
             plot_period = config["plot_period"]
356 356
         end
357
-        plot_period = F.DEBUG ? 1 : 10
357
+        plot_period = F.debug ? 1 : 10
358 358
         fig = Plotting.init_plot(coords, P, F)
359 359
         Plotting.update_plot(coords, nucleus_coords, 0, P, F, false, plotables, centro_vr)
360 360
         if F.write_animation
@@ -373,7 +373,7 @@ function launch(P::CSC.Params, F::CSC.Flags, config)
373 373
     metrics_started = false
374 374
 
375 375
 
376
-    stepping = F.DEBUG
376
+    stepping = F.debug
377 377
     breakpoint = -1
378 378
     if !stepping
379 379
         input_task = @async read(stdin, Char)
@@ -453,6 +453,10 @@ function launch(P::CSC.Params, F::CSC.Flags, config)
453 453
                     end
454 454
                 elseif maximum(coords.x[:,2]) >= post_init_target_max_y
455 455
                     metrics_started = true
456
+                elseif k == P.M/4 # wait for max 20k iteration if P.M = 80k
457
+                    println()
458
+                    println("Initialization not finished after " * string(round(Int, P.M/4)) * " iterations, aborting this run")
459
+                    break
456 460
                 end
457 461
             if metrics_started
458 462
                 metrics = Metrics.init_metrics(k, P, F, config, coords, nucleus_coords)
@@ -525,7 +529,7 @@ function launch(P::CSC.Params, F::CSC.Flags, config)
525 529
         end
526 530
 
527 531
         # plot
528
-        if (F.plot && (k % plot_period == 0))
532
+        if (F.plot && ((k % plot_period == 0) || stepping))
529 533
             Plotting.update_plot(coords, nucleus_coords, k, P, F, false, plotables, centro_vr)
530 534
             if F.write_animation
531 535
                 writer.grab_frame()

+ 1
- 1
src/CellSimCommon.jl View File

@@ -121,7 +121,7 @@ mutable struct Flags
121 121
     write_metrics::Bool
122 122
 
123 123
     # debug
124
-    DEBUG::Bool
124
+    debug::Bool
125 125
 end
126 126
 
127 127
 function to_dict(s::Union{Params,Flags})

+ 12
- 6
src/Nucleus.jl View File

@@ -89,6 +89,8 @@ function compute_curvature_4(c::NucleusCoords, sign_k::Vector{Float64})
89 89
 
90 90
     Nnuc = size(c.Y, 1)
91 91
 
92
+    k = zeros(Nnuc)
93
+
92 94
     for i in 1:Nnuc
93 95
         A[1,1] = 8*( c.Y[c.circ_idx.m2[i],1]^2
94 96
                     +c.Y[c.circ_idx.m1[i],1]^2
@@ -134,8 +136,11 @@ function compute_curvature_4(c::NucleusCoords, sign_k::Vector{Float64})
134 136
         b[3] = -0.25*(A[1,1] + A[2,2])
135 137
 
136 138
         x = A\b
137
-        c.k[i] = sign_k[i]./sqrt(x[1]^2 + x[2]^2 - x[3])
139
+        k[i] = sign_k[i]./sqrt(x[1]^2 + x[2]^2 - x[3])
138 140
     end
141
+
142
+    rel_change = abs.(k - c.k)./abs.(c.k) .< 1.0
143
+    c.k[rel_change] = k[rel_change]
139 144
 end
140 145
 
141 146
 function recompute_nucleus_coords(c::NucleusCoords)
@@ -147,8 +152,9 @@ function recompute_nucleus_coords(c::NucleusCoords)
147 152
     delta_θ = rem.(c.θ - c.θ[c.circ_idx.m1], 2π, RoundNearest)
148 153
     c.θ[:] = cumsum([c.θ[1]; delta_θ[1:end-1]])
149 154
 
150
-    sign_k = [sign(c.θ[1] + 2π - c.θ[end]); sign.(delta_θ)]
155
+    sign_k = sign.(delta_θ)
151 156
 
157
+    # compute_curvature_3(c, sign_k)
152 158
     compute_curvature_4(c, sign_k)
153 159
     c.η[:] = log.(c.r)
154 160
     c.L = sum(c.r)
@@ -494,7 +500,7 @@ function update_coords(c::NucleusCoords, new_c::NucleusCoords,
494 500
     N_W = potentials.N_W
495 501
     N_∇W = potentials.N_∇W
496 502
 
497
-    if F.DEBUG
503
+    if F.debug
498 504
         println("PRE alpha, beta, r, q, K, θ")
499 505
         # display([c.α c.β c.r c.q c.k c.θ])
500 506
         display([sum(c.α)/P.Nnuc sum(c.β)/P.Nnuc sum(c.r)/P.Nnuc sum(c.q)/P.Nnuc sum(c.k)/P.Nnuc sum(c.θ)/P.Nnuc])
@@ -507,7 +513,7 @@ function update_coords(c::NucleusCoords, new_c::NucleusCoords,
507 513
     update_θ(c, new_c, N_W, N_∇W, P, F, temparrays)
508 514
     update_Y(c, new_c, N_W, N_∇W, P, F, temparrays)
509 515
 
510
-    if F.DEBUG & recompute
516
+    if F.debug & recompute
511 517
         println("PRE recompute alpha, beta, r, q, K, θ")
512 518
         # display([c.α c.β c.r c.q c.k c.θ])
513 519
         display([sum(new_c.α)/P.Nnuc sum(new_c.β)/P.Nnuc sum(new_c.r)/P.Nnuc sum(new_c.q)/P.Nnuc sum(new_c.k)/P.Nnuc sum(new_c.θ)/P.Nnuc])
@@ -520,12 +526,12 @@ function update_coords(c::NucleusCoords, new_c::NucleusCoords,
520 526
         recompute_nucleus_coords(new_c)
521 527
     end
522 528
 
523
-    if F.DEBUG & recompute
529
+    if F.debug & recompute
524 530
         print("kpost = ")
525 531
         println(new_c.k)
526 532
     end
527 533
 
528
-    if F.DEBUG
534
+    if F.debug
529 535
         println("POST alpha, beta, r, q, K, θ")
530 536
         # display([new_c.α new_c.β new_c.r new_c.q new_c.k new_c.θ])
531 537
         display([sum(new_c.α)/P.Nnuc sum(new_c.β)/P.Nnuc sum(new_c.r)/P.Nnuc sum(new_c.q)/P.Nnuc sum(new_c.k)/P.Nnuc sum(new_c.θ)/P.Nnuc])

Loading…
Cancel
Save