[Users] Plotting all refinement levels using Kuibit

Bruno Giacomazzo bruno.giacomazzo at unimib.it
Wed Oct 9 05:00:56 CDT 2024


Steve Brandt produced the attached script to plot raw data without
interpolation using Kuibit. The script is for 2D data, but I assume the
same can be done with 1D data.

Cheers,
Bruno


Il giorno mar 8 ott 2024 alle ore 19:53 Gabriele Bozzola <
bozzola.gabriele at gmail.com> ha scritto:

> Hi José,
>
> Dealing with plotting a hierarchical grid in full generality (with/without
> ghost zones, handling multiple possibly overlapping components, ...)  is a
> hard problem.
> This is especially the case for 2/3D grids, which are commonly plotted
> with heatmaps/colormaps. To go around this, we resample the grids to a
> uniform grid
> for plotting purposes. In kuibit, these are "UniformGridData". These can
> be plotted directly.
>
> In the 1D case, we can just resample everything onto the finest grid, and
> that's why you see more points. By default, the resampling method is just
> nearest
> neighbor, so this method is not making data up, just adding more
> "intermediate" points where there are fewer.
>
> Indeed, as you say, HierarchicalGridData objects have all the information
> to plot one level at the time and it is probably feasible to use them for
> simple 1D plots.
>
> `HierarchicalGridData` can be iterated over: when you iterate over with
> something like:
>
> for ref_level, component, grid_data in hier_grid:
>     Here you plot the grid_data
>
> (I haven't tested this)
>
> kuibit also has a method `to_GridSeries()`. This is a specialized method
> for 1D variables. Currently, this is only implemented for UniformGridData,
> so you'd have
> to merge the refinement levels to use it. We could extend it to
> HierarchicalGridData and instead of resampling to the finest grid, we'd
> just collect all the points.
> In this way, you could just call this method and call `plt.plot` to have a
> line plot (as you do with timeseries in kuibit). This should be
> straightforward (it's essentially
> what I sketched above) and I can guide you to the implementation if that's
> something you'd be interested in contributing.
>
> Please, let me know if this helps,
> Gabriele
>
> On Tue, Oct 8, 2024 at 10:05 AM José Ferreira <jpmferreira at ua.pt> wrote:
>
>> Dear toolkit community,
>>
>>
>> I’m struggling to find a way to plot a 1D quantity in Kuibit without
>> merging the different meshes originated from the mesh refinement.
>>
>> As a workaround, I have made a Python script that reads the file of a
>> grid function and plots every point along the axis and its corresponding
>> value. I can share this script if somebody is interested, but it is not
>> very good as it breaks once you use checkpoints and has hardcoded paths.
>>
>> However, it gets the job done, as you can see in an example plot below,
>> where it is hopefully obvious that there is an increase in the number of
>> points as z approaches 0.
>>
>> Obviously, a solution that uses Kuibit would be much better. However, I
>> cannot come up with such a solution and so I’m writing this e-mail.
>>
>>
>> From the documentation, the object that represents the simulation data
>> (including the mesh refinement levels), is the HierarchicalGridData, and
>> I know how to go from a grid function to this object.
>>
>> For instance, to get the HierarchicalGridData that represents the real
>> part of a scalar field along the x-axis at t=0, we do
>>
>> sd = SimDir("<output>")
>> gf = sd.gf
>> phi1=gf.x["phi1"].get_time(0)
>>
>> All I have to do now is plot this somehow. As it turns out, this is
>> impossible, because according to the documentation
>>
>> We cannot plot directly this object, because it is a complicated object.
>> To plot it, we have to merge the refinement levels to a single
>> UniformGridData. We can do this with refinement_levels_merged().
>>
>> But, all of the information regarding the mesh refinement levels is here,
>> so it should be possible to extract this information and plot it, right?
>>
>> Looking at the methods and variables in HierarchicalGridData I came up
>> with nothing.
>>
>> Does anybody have a solution to this?
>>
>>
>> Thank you in advance,
>>
>> Best Regards,
>>
>> José Ferreira
>>
>>
>>>> _______________________________________________
>> Users mailing list
>> Users at einsteintoolkit.org
>> http://lists.einsteintoolkit.org/mailman/listinfo/users
>>
> _______________________________________________
> Users mailing list
> Users at einsteintoolkit.org
> http://lists.einsteintoolkit.org/mailman/listinfo/users
>


-- 

Prof. Bruno Giacomazzo
Department of Physics
University of Milano-Bicocca
Piazza della Scienza 3
20126 Milano
Italy

email: bruno.giacomazzo at unimib.it
phone: (+39) 02 6448 2321
web: http://www.brunogiacomazzo.org

---------------------------------------------------------------------
There are only 10 types of people in the world:
Those who understand binary, and those who don't
----------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.einsteintoolkit.org/pipermail/users/attachments/20241009/f9ba4c4f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kplot.py
Type: application/octet-stream
Size: 2665 bytes
Desc: not available
URL: <http://lists.einsteintoolkit.org/pipermail/users/attachments/20241009/f9ba4c4f/attachment.obj>


More information about the Users mailing list