Plotting of variables through f2grid file

Hello peeps. I’m probably missing something simple here, but I could use a hand figuring this out.

I want to export grid properties and contents for post-processing and overall “beautification” of plots with python later.

The zone export command (zone export s ) simply gives me all the geometry properties in an f2grid file. If I want to export contour contents (stresses, say vertical effective ones, or field quantities stored in extra variables), can I use this command or is there another one that would work? I tried doing zone export ‘filepath’ extra 1 range x-position 0 66.0 or zone export ‘filepath’ stress-effective quantity yy range group ‘soil’ but I don’t think it the keyword slot is meant for what I am trying to do.

In FLAC 8.1 I used to create a 2D array with information per column and then write it into a .txt file. Totally fine to write a fish function to do something similar in FLAC9 but wondering if it could be easier!

Hi there!

I am not familiar with Flac, but since that you are planning on post-processing with Python, maybe you could dump your data directly into a NumPy .npz file?

An example of script to execute in Flac iPython console could be:

import itasca as it
import numpy as np

my_extras = [1, 10, 12]
to_dump = dict(
    stresses = it.zonearray.stress(),
    gp_pos = it.gridpointarray.pos(),
    zone_gps = it.zonearray.gridpoints()
)
for index in my_extras:
    to_dump[f'zone_extra_{index}']=it.zonearray.extra(index)

np.savez_compressed('demo.npz', **to_dump)

Now, in an external Python session:

>>> import numpy as np
>>> data_flac = np.load('demo.npz')
>>> tuple(data_flac.keys())
('stresses', 'zone_extra_12', 'zone_extra_1', 'zone_extra_10', 'zone_gps', 'gp_pos')
>>> data_flac['gp_pos']
array([[  0.,   0.,   0.],
       [  1.,   0.,   0.],
       [  0.,   1.,   0.],
       ...,
       [ 98., 100., 100.],
       [ 99., 100., 100.],
       [100., 100., 100.]])
>>>

By the way, you could do the plotting directly from Flac’s Python!

Cheers

Theophile

2 Likes

Below is a small example to export zone ID, zone coordinates, and zone effective vertical stress in FLAC2D:

fish define export
   local zonedata = list.sequence(::zone.id(::zone.list), ::zone.pos(::zone.list)->x, ...
   ::zone.pos(::zone.list)->y, ::zone.stress.eff(::zone.list)->yy)
   file.all('zone.csv', 'text') = string.csv.to(::zonedata)
end
[export]
3 Likes

Thank you Zhao!! Will give this a try.

Thank you!
I haven’t played with Python within the software but I guess this will get me there.