@@ -414,10 +414,11 @@ function Base.show(io::IO, d::LaMEM_grid)
414414end
415415
416416"""
417- save_LaMEM_markers_parallel(Grid::CartData; PartitioningFile=empty, directory="./markers", verbose=true, is64bit=false)
417+ save_LaMEM_markers_parallel(Grid::CartData; PartitioningFile=empty, directory="./markers", verbose=true, is64bit=false, add_APS=false )
418418
419419Saves a LaMEM marker file from the `CartData` structure `Grid`. It must have a field called `Phases`, holding phase information (as integers) and optionally a field `Temp` with temperature info.
420420It is possible to provide a LaMEM partitioning file `PartitioningFile`. If not, output is assumed to be for one processor. By default it is assumed that the partitioning file was generated on a 32bit PETSc installation. If `Int64` was used instead, set the flag.
421+ if `add_APS` is true it will add a new field to all particles (needed in newer versions of LaMEM, but not supported in LaMEM 2.2.0 or before)
421422
422423The size of `Grid` should be consistent with what is provided in the LaMEM input file. In practice, the size of the mesh can be retrieved from a LaMEM input file using `read_LaMEM_inputfile`.
423424
@@ -441,7 +442,7 @@ Writing LaMEM marker file -> ./markers/mdb.00000003.dat
441442```
442443
443444"""
444- function save_LaMEM_markers_parallel (Grid:: CartData ; PartitioningFile = empty, directory = " ./markers" , verbose = true , is64bit = false )
445+ function save_LaMEM_markers_parallel (Grid:: CartData ; PartitioningFile = empty, directory = " ./markers" , verbose = true , is64bit = false , add_APS = false )
445446
446447 x = ustrip .(Grid. x. val[:, 1 , 1 ])
447448 y = ustrip .(Grid. y. val[1 , :, 1 ])
@@ -471,8 +472,8 @@ function save_LaMEM_markers_parallel(Grid::CartData; PartitioningFile = empty, d
471472 zeros (size (Phases))
472473 end
473474
474- if PartitioningFile == empty
475- # in case we run this on 1 processor only
475+ if PartitioningFile == empty || isnothing (PartitioningFile)
476+ # in case we run this on 1 processor only (or partitioning file could not be created)
476477 Nprocx = 1
477478 Nprocy = 1
478479 Nprocz = 1
@@ -510,10 +511,13 @@ function save_LaMEM_markers_parallel(Grid::CartData; PartitioningFile = empty, d
510511 part_phs = Phases[x_start[n]: x_end[n], y_start[n]: y_end[n], z_start[n]: z_end[n]]
511512 part_T = Temp[x_start[n]: x_end[n], y_start[n]: y_end[n], z_start[n]: z_end[n]]
512513 part_APS = APS[x_start[n]: x_end[n], y_start[n]: y_end[n], z_start[n]: z_end[n]]
514+
513515 num_particles = size (part_x, 1 ) * size (part_x, 2 ) * size (part_x, 3 )
514516
515517 # Information vector per processor
516- num_prop = 6 # number of properties we save [x/y/z/phase/T/APS]
518+ # add_APS=false: 5 props [x/y/z/phase/T], header 1211214, LaMEM >= 2.2.0
519+ # add_APS=true: 6 props [x/y/z/phase/T/APS], header 1211215, LaMEM >= 2.2.1
520+ num_prop = add_APS ? 6 : 5
517521 lvec_info = num_particles
518522
519523 lvec_prtcls = zeros (Float64, num_prop * num_particles)
@@ -523,7 +527,9 @@ function save_LaMEM_markers_parallel(Grid::CartData; PartitioningFile = empty, d
523527 lvec_prtcls[3 : num_prop: end ] = part_z[:]
524528 lvec_prtcls[4 : num_prop: end ] = part_phs[:]
525529 lvec_prtcls[5 : num_prop: end ] = part_T[:]
526- lvec_prtcls[6 : num_prop: end ] = part_APS[:]
530+ if add_APS
531+ lvec_prtcls[6 : num_prop: end ] = part_APS[:]
532+ end
527533
528534 # Write output files
529535 if ~ isdir (directory)
@@ -535,7 +541,7 @@ function save_LaMEM_markers_parallel(Grid::CartData; PartitioningFile = empty, d
535541 end
536542 lvec_output = [lvec_info; lvec_prtcls] # one vec with info about length
537543
538- PetscBinaryWrite_Vec (fname, lvec_output) # Write PETSc vector as binary file
544+ PetscBinaryWrite_Vec (fname, lvec_output; add_APS) # Write PETSc vector as binary file
539545
540546 end
541547 return
@@ -619,17 +625,18 @@ end
619625Writes a vector `A` to disk, such that it can be read with `PetscBinaryRead` (which assumes a Big Endian type)
620626
621627"""
622- function PetscBinaryWrite_Vec (filename, A)
628+ function PetscBinaryWrite_Vec (filename, A; add_APS = false )
623629
624630 # Note: use "hton" to transfer to Big Endian type, which is what PETScBinaryRead expects
625631 return open (filename, " w+" ) do f
626632 n = length (A)
627633 nummark = A[1 ] # number of markers
628634
629- # header number encodes the version of particle data file
630- # version with APS is 1211215
631- # version without APS was 1211214
632- write (f, hton (Float64 (1211215 ))) # header
635+ # header encodes the marker file version:
636+ # 1211214 = without APS (LaMEM >= 2.2.0, default)
637+ # 1211215 = with APS (LaMEM >= 2.2.1)
638+ header = add_APS ? Float64 (1211215 ) : Float64 (1211214 )
639+ write (f, hton (header)) # header
633640 write (f, hton (Float64 (nummark))) # info about # of markers written
634641
635642 for i in 2 : n
0 commit comments