-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_bashrc
More file actions
1004 lines (853 loc) · 33.6 KB
/
my_bashrc
File metadata and controls
1004 lines (853 loc) · 33.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
export LESS=-R
export PATH=~/jorek/util/:$PATH
export PATH=~/scripts/bin/:$PATH
export PATH=~/scripts/screenFetch:$PATH
#ulimit -s unlimited
#ulimit -m unlimited
## Compile commands
# ./util/config.sh model=710 n_tor=1 n_period=1 n_plane=1 && make clean && make cleanall && make -j 8 && mv jorek_model710 jorek_model710_ntor1
# ./util/config.sh model=710 n_tor=5 n_period=1 n_plane=8 && make clean && make cleanall && make -j 8 && make -j 8 jorek2vtk jorek2_postproc jorek2_poincare q_fmhd
alias rm="rm -i"
alias lsr="ls -lrt"
alias gv="gv -antialias"
alias myrsync="rsync -aAXvP"
alias myquota="/usr/lpp/mmfs/bin/mmlsquota --block-size auto"
alias gitResetPushedCommit='git reset --soft HEAD~1'
alias sqcdjobid='source ~/scripts/slurm_dir.sh '
alias plot_live_data='plot_live_data.sh'
alias tmux_attach_t='tmux attach -t '
alias dsgetmykeys='cd ~/.ssh/ && ds get mykeys/my_key.pub mykeys/my_key mykeys/my_key-cert.pub && cd -'
# alias mysq="squeue -u $USER"
# alias sqnow='sacct --starttime 2023-08-09 --format=User,JobID,Jobname%30,state,start,end,elapsed,nnodes,WorkDir%180 | grep "$USER " | grep "RUNNING\|PENDING"'
alias sqdir='scontrol show job | grep "WorkDir=$WORKDIR"'
alias mysq="squeue -o '%.29j %.10i %.8q %.8M %.3D %.3L %.1T %.17r %.8u' -u $USER"
alias sqhist='sacct --starttime 2023-08-09 --format=User,JobID,Jobname%30,state,start,end,elapsed,nnodes,WorkDir%180 | grep "$USER "'
alias sqnow='sacct --starttime 2023-08-09 --format=User,JobID,Jobname%20,state,WorkDir%180 | grep "$USER " | grep "RUNNING\|PENDING"'
alias watchsq='watch -n 1 squeue -u $USER'
alias sqmemory='sacct -a --format=user%10,jobname%30,node%10,start%20,end%20,elapsed%10,MaxRSS -j'
alias jorekShowSteps="egrep -i 'info\(2|time iterat|time step :|min,max deltas' logfile"
#alias bpeek="egrep -i 'info\(2|time iterat|time step :|min,max deltas' logfile"
alias tailf='tail logfile -f | grep -e "time step :" -e "Elapsed time ITERATION" -e "min,max deltas =" -e "Elapsed time in construct " -e "Number of iterations" -e "After step " -e "Elapsed time updating preconditioner "'
alias llh='du -h --max-depth=1 | sort -h'
alias cpXfiles='find ./ -maxdepth 1 -type f -perm /a+x | xargs cp -t ' # followed by target path
alias renameH5_to_short='rename jorek0 jorek jorek0?????.h5'
alias renameH5_to_long='rename jorek jorek0 jorek?????.h5'
alias stopJorek='touch STOP_NOW'
alias luJorek='touch REDO_LU'
alias outputJorek='touch OUTPUT_NOW'
alias reg_cases_ls='reg_tests/run_test.sh -l'
alias reg_case_comp_and_run='reg_tests/run_test.sh -j 8 '
alias reg_case_compile='reg_tests/run_test.sh -p -j 8 '
alias reg_case_run='reg_tests/run_test.sh -k -n '
alias reg_clean_all='reg_tests/cleanup.sh'
alias live_data='time2si && plot_live_data -noplot'
#alias time2si="time2si=$(grep "@times_y2si:" macroscopic_vars.dat | awk '{print $2}')"
alias jorek_post='./jorek2_postproc < ~/scripts/postproc_script.txt && sed -i '1s/^#//' postproc/exprs_averaged_s*.dat && sed -i '/^#/d' postproc/qprofile_s*.dat'
alias jorek_post2='sed -i '1s/^#//' ' # remove first # in first line in postproc/exprs_averaged_s*.dat
alias jorek_post3='sed -i '/^#/d' ' # remove first line start with # in postproc/qprofile_s*.dat
alias touch_all_folder_file='find . -exec touch {} +'
alias touch_all_file='find . -type f -exec touch {} +'
alias touch_all_folder='find . -type d -exec touch {} +'
alias plot_multiple_files='plot_multiple_files.py'
# Function to set more_outfile_digits to false
set_more_outfile_digits_false() {
sed -i 's/^more_outfile_digits=true/more_outfile_digits=false/' ~/jorek/util/convert2vtk.sh
echo "Set more_outfile_digits to false."
}
# Function to revert more_outfile_digits back to true
set_more_outfile_digits_true() {
sed -i 's/^more_outfile_digits=false/more_outfile_digits=true/' ~/jorek/util/convert2vtk.sh
echo "Set more_outfile_digits to true."
}
alias cvt2vtkno0='convert2vtk.sh -no0 -j 8 jorek2vtk '
alias cvt2vtk='convert2vtk.sh -j 8 jorek2vtk '
alias cvt2vtkno0si='convert2vtk.sh -no0 -si -j 8 jorek2vtk '
alias cvt2vtksi='convert2vtk.sh -si -j 8 jorek2vtk '
cvt2vtk_itor() {
local itor="$1"
local input="$2"
if [ -n "$3" ]; then
local only="$3"
echo "Only processing nsteps of: "$only
convert2vtk.sh -i_tor "$itor" -only "$only" -j 8 jorek2vtk "$input"
else
convert2vtk.sh -i_tor "$itor" -j 8 jorek2vtk "$input"
fi
}
cvt2vtk_iplane() {
local ip="$1"
local input="$2"
if [ -n "$3" ]; then
local only="$3"
echo "Only processing nsteps of: "$only
convert2vtk.sh -i_plane "$ip" -only "$only" -j 8 jorek2vtk "$input"
else
convert2vtk.sh -i_plane "$ip" -j 8 jorek2vtk "$input"
fi
}
cvt2vtksi_iplane() {
local ip="$1"
local input="$2"
if [ -n "$3" ]; then
local only="$3"
echo "Only processing nsteps of: "$only
convert2vtk.sh -si -i_plane "$ip" -only "$only" -j 8 jorek2vtk "$input"
else
convert2vtk.sh -si -i_plane "$ip" -j 8 jorek2vtk "$input"
fi
}
cvt2vtk_iplane_nsub() {
local ip="$1"
local nsub="$2"
local input="$3"
if [ -n "$4" ]; then
local only="$4"
echo "Only processing nsteps of: "$only
convert2vtk.sh -i_plane "$ip" -nsub "$nsub" -only "$only" -j 8 jorek2vtk "$input"
else
convert2vtk.sh -i_plane "$ip" -nsub "$nsub" -j 8 jorek2vtk "$input"
fi
}
cvt2vtkno0_iplane() {
local ip="$1"
local input="$2"
if [ -n "$3" ]; then
local only="$3"
echo "Only processing nsteps of: "$only
convert2vtk.sh -i_plane "$ip" -only "$only" -no0 -j 8 jorek2vtk "$input"
else
convert2vtk.sh -i_plane "$ip" -no0 -j 8 jorek2vtk "$input"
fi
}
cvt2vtk_itor_iplane() {
local itor="$1"
local ip="$2"
local input="$3"
if [ -n "$4" ]; then
local only="$4"
echo "Only processing nsteps of: "$only
convert2vtk.sh -i_tor "$itor" -i_plane "$ip" -only "$only" -j 8 jorek2vtk "$input"
else
convert2vtk.sh -i_tor "$itor" -i_plane "$ip" -j 8 jorek2vtk "$input"
fi
}
# Define a function to echo array elements
print_array() {
local array=("$@") # Receive the array as arguments
for element in "${array[@]}"; do
echo "$element"
done
}
jorek_post_time() {
./jorek2_postproc < ~/scripts/postproc_script_time_series.txt
sed -i '1s/^#//' postproc/exprs_at*.dat
}
jorek_post_count() {
local directory="$1"
# Check if directory is provided, otherwise use current directory
if [ -z "$directory" ]; then
directory="postproc/"
fi
# Count files with the specified prefix
local prefix="fluxsurfaces_s"
local count=$(find "$directory" -type f -name "${prefix}*" | wc -l)
echo "Find $count ${prefix}* files."
local prefix="qprofile_s"
local count=$(find "$directory" -type f -name "${prefix}*" | wc -l)
echo "Find $count ${prefix}* files."
local prefix="exprs_averaged_s"
local count=$(find "$directory" -type f -name "${prefix}*" | wc -l)
echo "Find $count ${prefix}* files."
local prefix="exprs_midplane_s"
local count=$(find "$directory" -type f -name "${prefix}*" | wc -l)
echo "Find $count ${prefix}* files."
local count=$(find ./ -maxdepth 1 -type f -name "jorek*.h5" | wc -l)
echo "Find $count jorek*.h5 files."
}
jorek_post_all() {
live_data
live_data -q ti
sed -i '1a 0 0' times.dat
unset id ids sorted_ids unique_ids ids_exist file_id
# Check if an ID was provided as a parameter
if [ -n "$1" ]; then
#id="$1" # Use the provided ID
# for id in "$@"; do
# echo "post_porcessing: $id"
# sed -i 's/\b[0-9]\{5\}\b/'"$id"'/g' ~/scripts/postproc_script.txt
# ./jorek2_postproc < ~/scripts/postproc_script.txt > postproc.log
# done
ids=("$@")
else
# Extract IDs and store them in an array
ids=($(find ./ -maxdepth 1 -type f -name 'jorek*.h5' | grep -oE 'jorek[0-9]+\.h5' | sed 's/jorek\([0-9]\+\)\.h5/\1/'))
# print_array "${ids[@]}"
# ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'exprs_averaged_s*.dat' | grep -oE 'exprs_averaged_s[0-9]+\.dat' | sed 's/exprs_averaged_s\([0-9]\+\)\.dat/\1/'))
ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'exprs_midplane_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
# ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'exprs_averaged_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
# ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'fluxsurfaces_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
# ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'qprofile_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
fi
sorted_ids=($(printf "%s\n" "${ids[@]}" | sort -n))
# Loop through the sorted IDs and exist IDs and add them to unique_ids if they are not already in it
for id in "${sorted_ids[@]}"; do
if [[ ! " ${unique_ids[@]} " =~ " $id " ]] && [[ ! " ${ids_exist[@]} " =~ " $id " ]]; then
unique_ids+=("$id")
fi
done
# Counter for active threads
active_threads=0
# Maximum number of threads in parallel
max_threads=10 # Adjust based on your preference
mkdir ~/scripts/tmp_postproc
# Loop through the IDs and replace them in postproc_script.txt
for id in "${unique_ids[@]}"; do
# Check if the maximum number of threads is reached
if [ "$active_threads" -ge "$max_threads" ]; then
# Wait for one background process to finish
wait
active_threads=0
fi
echo "post_porcessing: $id" && \
file_id=~/scripts/tmp_postproc/"postproc_script_$id.txt" && \
cp ~/scripts/postproc_script.txt $file_id && \
sed -i 's/\b[0-9]\{5\}\b/'"$id"'/g' $file_id && \
./jorek2_postproc < $file_id > postproc.log &
((active_threads++))
done
wait
for id in "${unique_ids[@]}"; do
echo "cleaning up: $id"
file_id=~/scripts/tmp_postproc/"postproc_script_$id.txt"
rm $file_id -f
done
sed -i '1s/^#//' postproc/exprs_averaged_s*.dat
sed -i '1s/^#//' postproc/exprs_midplane_s*.dat
sed -i '1s/^#//' postproc/int3Dprofile_s*.dat
sed -i '1s/^#//' postproc/exprs_surface_flux_s*.dat
sed -i '/^#/d' postproc/qprofile_s*.dat
cp ~/scripts/postproc_script.txt postproc/
unset id ids sorted_ids unique_ids ids_exist file_id
}
jorek_post_all_reduced() {
live_data
live_data -q ti
sed -i '1a 0 0' times.dat
unset id ids sorted_ids unique_ids ids_exist file_id
# Check if an ID was provided as a parameter
if [ -n "$1" ]; then
ids=("$@")
else
# Extract IDs and store them in an array
ids=($(find ./ -maxdepth 1 -type f -name 'jorek*.h5' | grep -oE 'jorek[0-9]+\.h5' | sed 's/jorek\([0-9]\+\)\.h5/\1/'))
# print_array "${ids[@]}"
ids_exist=($(find ./postproc_reduced/ -maxdepth 1 -type f -name 'exprs_midplane_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
fi
sorted_ids=($(printf "%s\n" "${ids[@]}" | sort -n))
# Loop through the sorted IDs and exist IDs and add them to unique_ids if they are not already in it
for id in "${sorted_ids[@]}"; do
if [[ ! " ${unique_ids[@]} " =~ " $id " ]] && [[ ! " ${ids_exist[@]} " =~ " $id " ]]; then
unique_ids+=("$id")
fi
done
# Counter for active threads
active_threads=0
# Maximum number of threads in parallel
max_threads=10 # Adjust based on your preference
mkdir ~/scripts/tmp_postproc_reduced
# Loop through the IDs and replace them in postproc_reduced_script.txt
for id in "${unique_ids[@]}"; do
# Check if the maximum number of threads is reached
if [ "$active_threads" -ge "$max_threads" ]; then
# Wait for one background process to finish
wait
active_threads=0
fi
echo "post_porcessing: $id" && \
file_id=~/scripts/tmp_postproc_reduced/"postproc_reduced_script_$id.txt" && \
cp ~/scripts/postproc_reduced_script.txt $file_id && \
sed -i 's/\b[0-9]\{5\}\b/'"$id"'/g' $file_id && \
./jorek2_postproc < $file_id > postproc_reduced.log &
((active_threads++))
done
wait
for id in "${unique_ids[@]}"; do
echo "cleaning up: $id"
file_id=~/scripts/tmp_postproc_reduced/"postproc_reduced_script_$id.txt"
rm $file_id -f
done
mkdir postproc_reduced
mv postproc/* postproc_reduced/
sed -i '1s/^#//' postproc_reduced/exprs_averaged_s*.dat
sed -i '1s/^#//' postproc_reduced/exprs_midplane_s*.dat
sed -i '1s/^#//' postproc_reduced/int3Dprofile_s*.dat
sed -i '1s/^#//' postproc_reduced/exprs_surface_flux_s*.dat
sed -i '/^#/d' postproc_reduced/qprofile_s*.dat
cp ~/scripts/postproc_reduced_script.txt postproc_reduced/
unset id ids sorted_ids unique_ids ids_exist file_id
}
jorek_post_all_ompnum() {
plot_live_data.sh -noplot
plot_live_data.sh -noplot -q ti
unset id ids sorted_ids unique_ids ids_exist file_id
# Check if an ID was provided as a parameter
if [ -n "$1" ]; then
#id="$1" # Use the provided ID
# for id in "$@"; do
# echo "post_porcessing: $id"
# sed -i 's/\b[0-9]\{5\}\b/'"$id"'/g' ~/scripts/postproc_script.txt
# ./jorek2_postproc < ~/scripts/postproc_script.txt > postproc.log
# done
ids=("$@")
else
# Extract IDs and store them in an array
ids=($(find ./ -maxdepth 1 -type f -name 'jorek*.h5' | grep -oE 'jorek[0-9]+\.h5' | sed 's/jorek\([0-9]\+\)\.h5/\1/'))
# print_array "${ids[@]}"
# ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'exprs_averaged_s*.dat' | grep -oE 'exprs_averaged_s[0-9]+\.dat' | sed 's/exprs_averaged_s\([0-9]\+\)\.dat/\1/'))
ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'exprs_midplane_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
# ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'exprs_averaged_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
# ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'fluxsurfaces_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
# ids_exist=($(find ./postproc/ -maxdepth 1 -type f -name 'qprofile_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
fi
sorted_ids=($(printf "%s\n" "${ids[@]}" | sort -n))
# Loop through the sorted IDs and exist IDs and add them to unique_ids if they are not already in it
for id in "${sorted_ids[@]}"; do
if [[ ! " ${unique_ids[@]} " =~ " $id " ]] && [[ ! " ${ids_exist[@]} " =~ " $id " ]]; then
unique_ids+=("$id")
fi
done
# Counter for active threads
active_threads=0
# Maximum number of threads in parallel
max_threads=$OMP_NUM_THREADS # Adjust based on your preference
mkdir ~/scripts/tmp_postproc
# Loop through the IDs and replace them in postproc_script.txt
for id in "${unique_ids[@]}"; do
# Check if the maximum number of threads is reached
if [ "$active_threads" -ge "$max_threads" ]; then
# Wait for one background process to finish
wait
active_threads=0
fi
echo "post_porcessing: $id" && \
file_id=~/scripts/tmp_postproc/"postproc_script_$id.txt" && \
cp ~/scripts/postproc_script.txt $file_id && \
sed -i 's/\b[0-9]\{5\}\b/'"$id"'/g' $file_id && \
./jorek2_postproc < $file_id > postproc.log &
((active_threads++))
done
wait
for id in "${unique_ids[@]}"; do
echo "cleaning up: $id"
file_id=~/scripts/tmp_postproc/"postproc_script_$id.txt"
rm $file_id -f
done
sed -i '1s/^#//' postproc/exprs_averaged_s*.dat
sed -i '1s/^#//' postproc/exprs_midplane_s*.dat
sed -i '1s/^#//' postproc/int3Dprofile_s*.dat
sed -i '1s/^#//' postproc/exprs_surface_flux_s*.dat
sed -i '/^#/d' postproc/qprofile_s*.dat
unset id ids sorted_ids unique_ids ids_exist file_id
}
jorek_poincare_all() {
unset id ids sorted_ids unique_ids ids_exist input_file_name
mkdir poincares
while [[ $# -gt 0 ]]; do
case "$1" in
-fn)
if [ -n "$2" ]; then
input_file_name="$2"
shift 2
else
echo "Error: Missing argument for -fn flag (the input file)."
exit 1
fi
;;
*)
# Capture other parameters in the 'ids' array
ids+=("$1")
shift
;;
esac
done
# Check if an ID was provided as a parameter
# if [ -n "$1" ]; then
# ids=("$@")
# else
if [ ${#ids[@]} -gt 0 ]; then
echo "Ids is not empty: ${ids[@]}"
else
# Extract IDs and store them in an array
ids=($(find ./ -maxdepth 1 -type f -name 'jorek*.h5' | grep -oE 'jorek[0-9]+\.h5' | sed 's/jorek\([0-9]\+\)\.h5/\1/'))
ids_exist=($(find ./poincares/ -maxdepth 1 -type f -name 'poinc_R-Z_s*.dat' | grep -oE '_s[0-9]+\.dat' | sed 's/_s\([0-9]\+\)\.dat/\1/'))
fi
sorted_ids=($(printf "%s\n" "${ids[@]}" | sort -n))
# Loop through the sorted IDs and exist IDs and add them to unique_ids if they are not already in it
for id in "${sorted_ids[@]}"; do
if [[ ! " ${unique_ids[@]} " =~ " $id " ]] && [[ ! " ${ids_exist[@]} " =~ " $id " ]]; then
unique_ids+=("$id")
fi
done
# Loop through the IDs
for id in "${unique_ids[@]}"; do
echo "poincare_porcessing file: jorek$id.h5"
cp "jorek$id.h5" jorek_poincare.h5
time ./jorek2_poincare < $input_file_name > poincare.log
echo "Finished, moving poinc_*.dat to poincares/"
mv poinc_R-Z.dat "poincares/poinc_R-Z_s$id.dat"
mv poinc_rho-theta.dat "poincares/poinc_rho-theta_s$id.dat"
mv poincare.ps "poincares/poincare$id.ps"
done
unset id ids sorted_ids unique_ids ids_exist input_file_name
}
make_jorek_kinetic() {
unset pfix underscore ext origin_file new_file
local usage="Usage: make_jorek_kinetic [model(=7xx) ntor(=2*n_max+1) nperiod(=1, usually) nplane(>=4*n_max)]"
local description="This function compiles executable files for specified model and parameters."
local help_text="$usage\n$description"
if [ $# -eq 0 ]; then
echo -e "$help_text"
echo "Example: make_jorek 710 5 1 8"
return
fi
local para_model="$1"
local para_ntor="$2"
local para_nperiod="$3"
local para_nplane="$4"
pfix="jorek_model"
underscore="_"
numone="1"
ext="$underscore$para_ntor$underscore$para_nperiod$underscore$para_nplane"
origin_file="$pfix$para_model"
new_file="$pfix$para_model$ext"
./util/config.sh model="$para_model" n_tor="$numone" n_period="$para_nperiod" n_plane="$numone" && make cleanall && make -j 8
make -j 8
mv "$origin_file" "$pfix$para_model$underscore$numone$underscore$para_nperiod$underscore$numone"
./util/config.sh model="$para_model" n_tor="$para_ntor" n_period="$para_nperiod" n_plane="$para_nplane" && make cleanall && make -j 8
make -j 8 jorek2vtk jorek2_postproc jorek2_poincare jorek2_four jorek2_target2vtk jorek2vtk_3d q_fmhd jorek2_fieldlines_vtk_newdiag kinetic_main #q_fmhd_3D
mv "$origin_file" "$new_file" && make install
cp models/model$para_model/mod_elt_matrix_fft.f90 bin/
unset pfix underscore ext origin_file new_file
}
make_jorek() {
unset pfix underscore ext origin_file new_file
local usage="Usage: make_jorek [model(=7xx) ntor(=2*n_max+1) nperiod(=1, usually) nplane(>=4*n_max)]"
local description="This function compiles executable files for specified model and parameters."
local help_text="$usage\n$description"
if [ $# -eq 0 ]; then
echo -e "$help_text"
echo "Example: make_jorek 710 5 1 8"
return
fi
local para_model="$1"
local para_ntor="$2"
local para_nperiod="$3"
local para_nplane="$4"
pfix="jorek_model"
underscore="_"
numone="1"
ext="$underscore$para_ntor$underscore$para_nperiod$underscore$para_nplane"
origin_file="$pfix$para_model"
new_file="$pfix$para_model$ext"
./util/config.sh model="$para_model" n_tor="$numone" n_period="$para_nperiod" n_plane="$numone" && make cleanall && make -j 8
make -j 8
mv "$origin_file" "$pfix$para_model$underscore$numone$underscore$para_nperiod$underscore$numone"
./util/config.sh model="$para_model" n_tor="$para_ntor" n_period="$para_nperiod" n_plane="$para_nplane" && make cleanall && make -j 8
make -j 8 jorek2vtk jorek2_postproc jorek2_poincare jorek2_four jorek2_target2vtk jorek2vtk_3d q_fmhd jorek2_fieldlines_vtk_newdiag #q_fmhd_3D
mv "$origin_file" "$new_file" && make install
cp models/model$para_model/mod_elt_matrix_fft.f90 bin/
unset pfix underscore ext origin_file new_file
}
make_jorek_gnu() {
unset pfix underscore ext origin_file new_file
local usage="Usage: make_jorek_gnu [model(=7xx) ntor(=2*n_max+1) nperiod(=1, usually) nplane(>=4*n_max)]"
local description="This function compiles executable files for specified model and parameters."
local help_text="$usage\n$description"
if [ $# -eq 0 ]; then
echo -e "$help_text"
echo "Example: make_jorek_gnu 710 5 1 8"
return
fi
cp Makefile.inc Makefile_backup_temp.inc
cp Makefile_gnu.inc Makefile.inc
source ~/source_gnu_env.sh
local para_model="$1"
local para_ntor="$2"
local para_nperiod="$3"
local para_nplane="$4"
pfix="jorek_model"
underscore="_"
numone="1"
ext="$underscore$para_ntor$underscore$para_nperiod$underscore$para_nplane"
origin_file="$pfix$para_model"
new_file="$pfix$para_model$ext"
./util/config.sh model="$para_model" n_tor="$numone" n_period="$para_nperiod" n_plane="$numone" && make cleanall && make -j 8
make -j 8
mv "$origin_file" "$pfix$para_model$underscore$numone$underscore$para_nperiod$underscore$numone"
./util/config.sh model="$para_model" n_tor="$para_ntor" n_period="$para_nperiod" n_plane="$para_nplane" && make cleanall && make -j 8
make -j 8 jorek2vtk jorek2_postproc jorek2_poincare jorek2_four jorek2_target2vtk jorek2vtk_3d q_fmhd jorek2_fieldlines_vtk_newdiag #q_fmhd_3D
mv "$origin_file" "$new_file" && make install
cp models/model$para_model/mod_elt_matrix_fft.f90 bin/
mv Makefile_backup_temp.inc Makefile.inc
source ~/.bashrc
unset pfix underscore ext origin_file new_file
}
# alias sbatch_dep='sbatch --dependency=afterok:' # e.g., sbatch --dependency=afterok:<first_job_id> my_second_job.sh # rok means run ok (succes)
sbatch_dep_job() {
local first_job_id="$1"
local script_name="$2"
sbatch --dependency=afterok:"$first_job_id" "$script_name"
}
sbatch_dep_job_any() {
local first_job_id="$1"
local script_name="$2"
sbatch --dependency=afternotok:"$first_job_id" "$script_name"
}
function sbatch_chain() {
if [ $# -lt 2 ]; then
echo "Usage: qsubchain jobscript1 jobscript2 [...]"
return
fi
thejobids=""
depend=""
while [ $# -gt 0 ]; do
thejobid=`sbatch $depend $1 | sed -e 's/Submitted batch job *//'`
thejobids="$thejobids $thejobid"
depend="--dependency=afterok:$thejobid"
shift
done
echo "JobIDs: $thejobids"
unset depend thejobid thejobids
}
function sbatch_chain_from() {
if [ $# -lt 2 ]; then
echo "Usage: sbatch_chain_from <job_ID> jobscript1 [jobscript2 ...]"
return 1
fi
start_jobid="$1"
shift
thejobids=""
depend="--dependency=afterok:${start_jobid}"
while [ $# -gt 0 ]; do
thejobid=$(sbatch $depend "$1" | sed -e 's/Submitted batch job *//')
thejobids="$thejobids $thejobid"
depend="--dependency=afterok:${thejobid}"
shift
done
echo "JobIDs:$thejobids"
unset depend thejobid thejobids start_jobid
}
function sbatch_chain_any() {
if [ $# -lt 2 ]; then
echo "Usage: qsubchain jobscript1 jobscript2 [...]"
return
fi
thejobids=""
depend=""
while [ $# -gt 0 ]; do
thejobid=`sbatch $depend $1 | sed -e 's/Submitted batch job *//'`
thejobids="$thejobids $thejobid"
depend="--dependency=afternotok:$thejobid"
shift
done
echo "JobIDs: $thejobids"
unset depend thejobid thejobids
}
# Submit a job that depends on a previous job completing successfully (afterok)
qsub_dep_job() {
local first_job_id="$1"
local script_name="$2"
# PBS uses -W depend=condition:jobid
qsub -W depend=afterok:"$first_job_id" "$script_name"
}
# Submit a job that depends on a previous job failing (afternotok)
# Note: Based on your provided code which used 'afternotok'.
# If you meant "run regardless of success/fail", change to 'afterany'.
qsub_dep_job_any() {
local first_job_id="$1"
local script_name="$2"
qsub -W depend=afternotok:"$first_job_id" "$script_name"
}
# Chain a list of scripts so they run one after another (on success)
function qsub_chain() {
if [ $# -lt 2 ]; then
echo "Usage: qsub_chain jobscript1 jobscript2 [...]"
return
fi
thejobids=""
depend=""
while [ $# -gt 0 ]; do
# qsub usually outputs only the Job ID (e.g., 12345.server), so no sed needed.
# We use -W depend=... only if $depend is set.
if [ -z "$depend" ]; then
thejobid=$(qsub "$1")
else
thejobid=$(qsub -W "$depend" "$1")
fi
thejobids="$thejobids $thejobid"
depend="depend=afterok:$thejobid"
shift
done
echo "JobIDs: $thejobids"
unset depend thejobid thejobids
}
# Chain a list of scripts starting after an existing Job ID
function qsub_chain_from() {
if [ $# -lt 2 ]; then
echo "Usage: qsub_chain_from <job_ID> jobscript1 [jobscript2 ...]"
return 1
fi
start_jobid="$1"
shift
thejobids=""
depend="depend=afterok:${start_jobid}"
while [ $# -gt 0 ]; do
thejobid=$(qsub -W "$depend" "$1")
thejobids="$thejobids $thejobid"
depend="depend=afterok:${thejobid}"
shift
done
echo "JobIDs:$thejobids"
unset depend thejobid thejobids start_jobid
}
# Chain a list of scripts where dependency is 'afternotok' (Run next only if previous failed)
function qsub_chain_any() {
if [ $# -lt 2 ]; then
echo "Usage: qsub_chain_any jobscript1 jobscript2 [...]"
return
fi
thejobids=""
depend=""
while [ $# -gt 0 ]; do
if [ -z "$depend" ]; then
thejobid=$(qsub "$1")
else
thejobid=$(qsub -W "$depend" "$1")
fi
thejobids="$thejobids $thejobid"
depend="depend=afternotok:$thejobid"
shift
done
echo "JobIDs: $thejobids"
unset depend thejobid thejobids
}
time2si() {
time2si=$(grep "@times_y2si:" macroscopic_vars.dat | awk '{print $2}')
echo $time2si
}
bpeek() {
if [ -n "$1" ]; then
filename="$1"
else
filename=logfile
fi
egrep --text -i 'info\(2|time iterat|time step :|min,max deltas' $filename
}
#stopJorekAfterHours() {
# time="$1"
# echo "touch STOP_NOW" | at now + $time hours
#}
stopJorekAfterHoursMins() {
time1="$1" # hours
time2="$2" # minutes
# Calculate the total time in minutes
total_minutes=$((time1 * 60 + time2))
# Schedule the task using 'at' with the calculated time
echo "touch STOP_NOW" | at now + $total_minutes minutes
}
#stopJorekAfterMins() {
# time="$1"
# echo "touch STOP_NOW" | at now + $time minutes
#}
stopJorekAfterHoursMinsCron() {
time1="$1" # hours
time2="$2" # minutes
# Calculate the execution time
target_time=$(date -d "$time1 hours $time2 minutes" "+%M %H %d %m *")
# Add the task to crontab
(crontab -l 2>/dev/null; echo "$target_time touch $PWD/STOP_NOW") | crontab -
echo "Task scheduled: 'STOP_NOW' will be created in $time1 hours and $time2 minutes."
}
n_MPI_from_n_tor() {
local n_tor=$1
# Iterate over k from 1 to 10
for ((k = 1; k <= 10; k++)); do
# Perform the calculation
local n_MPI=$((k * (n_tor + 1) / 2))
# Print the result
echo "For k=$k, n_MPI = $n_MPI"
done
}
n_plane_from_n_tor() {
local n_tor=$1
# Iterate over k from 2 to 10
# At least 2*(n_tor-1)
for ((k = 2; k <= 10; k++)); do
# Perform the calculation
local n_plane=$((k * (n_tor - 1)))
# Print the result
echo "For k=$k, n_plane = $n_plane"
done
}
alias live_data_time="live_data -q ti && sed -i '1a 0 0' times.dat"
jorek_four_all() {
live_data
live_data -q ti
sed -i '1a 0 0' times.dat
unset id ids sorted_ids unique_ids ids_exist file_id input_file_name
while [[ $# -gt 0 ]]; do
case "$1" in
-fn)
if [ -n "$2" ]; then
input_file_name="$2"
shift 2
else
echo "Error: Missing argument for -fn flag (the input file)."
exit 1
fi
;;
*)
# Capture other parameters in the 'ids' array
ids+=("$1")
shift
;;
esac
done
# Check if an ID was provided as a parameter
if [ ${#ids[@]} -gt 0 ]; then
echo "Ids is not empty: ${ids[@]}"
else
# Extract IDs and store them in an array
ids=($(find ./ -maxdepth 1 -type f -name 'jorek*.h5' | grep -oE 'jorek[0-9]+\.h5' | sed 's/jorek\([0-9]\+\)\.h5/\1/'))
# print_array "${ids[@]}"
ids_exist=($(find ./four_results/ -maxdepth 1 -type f -name 'Uphi_n000_m000_step*' | grep -oE 'step[0-9]+' | sed 's/step//'))
fi
sorted_ids=($(printf "%s\n" "${ids[@]}" | sort -n))
# Loop through the sorted IDs and exist IDs and add them to unique_ids if they are not already in it
for id in "${sorted_ids[@]}"; do
if [[ ! " ${unique_ids[@]} " =~ " $id " ]] && [[ ! " ${ids_exist[@]} " =~ " $id " ]]; then
unique_ids+=("$id")
fi
done
# Counter for active threads
active_threads=0
# Maximum number of threads in parallel
max_threads=1 # Adjust based on your preference
# Loop through the IDs and replace them in postproc_script.txt
for id in "${unique_ids[@]}"; do
# Check if the maximum number of threads is reached
if [ "$active_threads" -ge "$max_threads" ]; then
# Wait for one background process to finish
wait
active_threads=0
fi
echo "four_porcessing: $id" && \
cp "jorek$id.h5" jorek_four.h5
./jorek2_four < ./${input_file_name} > four_logfile
((active_threads++))
done
wait
unset id ids sorted_ids unique_ids ids_exist file_id
}
# Function to update the time limit of a SLURM job
update_slurm_time() {
# Check if correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: update_slurm_time <jobid> <new_time_limit>"
echo "Example: update_slurm_time 12345 03:00:00"
return 1
fi
# Assign variables
local jobid="$1"
local new_time_limit="$2"
# Update the time limit using scontrol
scontrol update jobid=$jobid TimeLimit=$new_time_limit
# Check if the command was successful
if [ $? -eq 0 ]; then
echo "Time limit for job $jobid updated to $new_time_limit."
else
echo "Failed to update time limit for job $jobid."
return 1
fi
}
open_paraview() {
if [ -z "$1" ]; then
echo "Usage: open_paraview <directory_name>"
return 1
fi
paraview --data="$1/jorek...vtk"
}
make_install() {
# 1. Create the bin directory if it doesn't exist
if [[ ! -d "bin" ]]; then
mkdir -p bin
echo "Created bin/ directory."
fi
# 2. Loop through all files in the current directory
# -maxdepth 1 ensures we don't look into subdirectories
# -type f ensures we only look at files
for file in *; do
# Check if it's a regular file and if it's executable
if [[ -f "$file" && -x "$file" ]]; then
# Avoid moving the script itself if it's in the same folder
mv "$file" bin/
echo "Moved: $file -> bin/"
fi
done
}
get_step_from_time() {
local si_mode=0
local args=()
for arg in "$@"; do
if [[ "$arg" == "-si" ]]; then
si_mode=1
else
args+=("$arg")
fi
done
local target_time="${args[0]}"
local times_file="${args[1]:-times.dat}"
if [[ "$si_mode" == 1 ]]; then
local time2si
time2si=$(grep "@times_y2si:" macroscopic_vars.dat | awk '{print $2}')
echo time2si = $time2si [ms]
echo target_time = $target_time [ms]
target_time=$(awk -v t="$target_time" -v s="$time2si" 'BEGIN { print t / 1 / s }')
fi
echo target_time = $target_time [JOREK U.]
echo best_step:
awk -v t="$target_time" '
NR == 1 { next }
{
diff = $2 - t; if (diff < 0) diff = -diff
if (NR == 2 || diff < best_diff) { best_diff = diff; best_step = $1 }
}
END { print best_step }
' "$times_file"
}
export u0=1.2566370614359173e-06 # u0 vacuum magnetic permeability
export one_over_u0=795774.7154594767 # 1/u0
# Usage example:
# update_slurm_time 12345 03:00:00
# useful commands
# plot_q_versus_time.py -xm $time2si -xl "time [ms]" -ylim 0.0707 0.5 -cs 1.0 1.01 #-clim 0.928 1.300 -cs 0.99 1.0
# plot_f_versus_time.py -xm $time2si -fn exprs_midplane -yc 7 -xl "time [ms]" -clim -0.0000001 0.0000001 # -ylim 0.0707 0.5 -cs 1.0 1.01 #-clim 0.928 1.300 -cs 0.99 1.0
# plot_f_versus_time.py -xm $time2si -fn exprs_averaged -yc 7 -xl "time [ms]" -clim -0.0000001 0.0000001
# plot_f_versus_time.py -xm $time2si -fn exprs_averaged -yl '$\sqrt{\psi_n}$' -yc 35 -rp 1.0 -xl "time [ms]" -ylim 0.03 0.5 -cm 2170378.6432790086 -ti 'radial distribution of dynamo emf versus time' -fz 18
# plot_VxB_tor.py -np 32 -ns 43200 vtk_no0_iplane # -xylim 1.20 2.00 -0.20 0.30
# plot_multiple_files.py energies.dat -sk 1 -ys log -xm $time2si -xl "time[ms]" -yl "normalized energies" -ti "normalized energies vs time"
# plot_mn_mode_structures.py four_results -va rho T_e -nl 1 2 -ml 1 2 3 23 -st 02000 04000 -tm $time2si #-me al -ex True -er 0.3
# plot_multiple_files.py four_results/U_radial_n001_m001_step000400 -sk 1 -xp 0.5 -yc 1 2 3 -le 'abs' 're' 'im'
# plot_fft_1D_time_series.py four_results/1D_U_radial_n001_m002_vs_time_at_rhop_eq_0.30.dat -sk 1 -yc 2
# plot_midplane_vtk.py vtk_iplane -np 16 -va n_charge_SI -ns 200000 -clim ' -2.1e+10' 2.1e+10 -tm $time2si -ef True
# for i in {1..32}; do cvt2vtkno0_iplane $i input 40000; done
# for i in {1..16}; do cvt2vtk_iplane $i input; done
# rsync -aAXv 20230825_fix_axis_bug_get_all_commits --exclude={"*.vtk"} toki02jump:/u/hazh/WORKSPACE/MarconiSync/ #Ref: https://tecadmin.net/backup-linux-system/
# git checkout -b bugfix/ffprime_integration
# git push -u origin bugfix/ffprime_integration
# jorek_four_all -fn input