code to read samrai file

225 views
Skip to first unread message

Hong Nguyen

unread,
Apr 6, 2021, 11:05:23 AM4/6/21
to IBAMR Users
Hi All,

I was wondering if there is a C++ code that can read *.samrai file, an output of IBAMR. This code will be very useful as it allows quick post-processing of the flow fields; for example the calculation of momentum flux at a given surface.

Can anyone point me to where the code (if any) located in the SAMRAI package distribution?

Thank you,
Hong

Amneet Bhalla

unread,
Apr 6, 2021, 12:05:43 PM4/6/21
to ibamr...@googlegroups.com
The momentum flux calculation over a surface of a box is done here:

The theory behind these integrals is given here:

Is this what you are looking for?

--Amneet

--
You received this message because you are subscribed to the Google Groups "IBAMR Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ibamr-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ibamr-users/79fa8efe-82dc-4d94-96ae-4f9257c1e3f8n%40googlegroups.com.


--
--Amneet 



Hong Nguyen

unread,
Apr 6, 2021, 12:20:09 PM4/6/21
to IBAMR Users
Thanks for your suggestion, Amneet.

My goal is more general than your suggestions. With a code that can directly read a *.samrai file, I will have a full control over the output flow field. For example, I can extract velocity/pressure at a given physical point, plot the velocity/vorticity distribution in a certain region of interest and much more.

Currently, I am using Visit to read samrai files and then export the flow field to a VTK file, then do post-processing within this VTK file. However, this route is very time-consuming, so, if there is a code to directly work with *.samrai, that would be great.

Thanks,
Hong   

Yadong Zeng

unread,
Apr 6, 2021, 12:23:49 PM4/6/21
to ibamr...@googlegroups.com

Can anyone give more tips about doing this?

Best.



--

Yadong (Jordan) Zeng

Ph.D. Candidate

Department of Mechanical Engineering  

University of Minnesota 

Amneet Bhalla

unread,
Apr 6, 2021, 12:45:50 PM4/6/21
to ibamr...@googlegroups.com
You might want to contact SAMRAI developers if they have something in their toolkit for this purpose?

I'm not sure if we have such routines in the library that work with hdf5 files directly, but would be happy to have them in the library as a patch. 

Another question is: is it not possible to write C++ and .m4 codes to do the post-processing of data in-situ till you figure out post processing of hdf5 files?    



--
--Amneet 



Boyce Griffith

unread,
Apr 6, 2021, 1:17:32 PM4/6/21
to IBAMR Users
If you are using staggered-grid solvers, I would suggest using restart files rather than the visualization files for postprocessing, and to post process using SAMRAI-based tools. (This approach is used, for instance, in the convergence testers in the examples.) The reason is that the output files do not store the staggered-grid velocity fields directly, but instead store cell-centered interpolations of those fields. Also, the VisIt output files are stored in single precision to cut down on file size.

I am not 100% sure, but I also think that it is possible to read in the VisIt files using an HDF5 reader. I haven’t done it, but I feel like I remember people successfully doing this in the past.

If there is a particular example analysis that you’d like to add to a particular example, we can help you to set it up.

Boyce Griffith

unread,
Apr 6, 2021, 1:21:36 PM4/6/21
to ibamr...@googlegroups.com

On Apr 6, 2021, at 12:45 PM, Amneet Bhalla <mail2...@gmail.com> wrote:

You might want to contact SAMRAI developers if they have something in their toolkit for this purpose?

We probably ought to be using something newer than SAMRAI 2.4.4 before asking the SAMRAI folks for help. :-D

I'm not sure if we have such routines in the library that work with hdf5 files directly, but would be happy to have them in the library as a patch. 

I think that the VisIt files are just HDF5 files, so anything that works with HDF5 should work with them. E.g.

ex0/viz_IB2d/visit_dump.00132 ➜ h5dump processor_cluster.00000.samrai | head -n15
HDF5 "processor_cluster.00000.samrai" {
GROUP "/" {
   GROUP "processor.00000" {
      GROUP "level.00000" {
         GROUP "patch.00000" {
            DATASET "Div U" {
               DATATYPE  H5T_IEEE_F32BE
               DATASPACE  SIMPLE { ( 4096 ) / ( 4096 ) }
               DATA {
               (0): -3.24996e-11, 3.20709e-10, 4.84678e-10, -1.68284e-09,
               (4): 6.13809e-09, -1.15283e-08, 2.17587e-08, -3.23835e-08,
               (8): 5.24507e-08, -7.36663e-08, 1.00761e-07, -1.30182e-07,
               (12): 1.71854e-07, -2.16352e-07, 2.61903e-07, -3.08971e-07,
               (16): 3.70147e-07, -4.30081e-07, 4.83467e-07, -5.28443e-07,
               (20): 5.85827e-07, -6.33274e-07, 6.54918e-07, -6.64745e-07,

The main challenges are in dealing with the parallel data layout and multiple patches/patch levels.

Hong Nguyen

unread,
Apr 6, 2021, 2:24:28 PM4/6/21
to IBAMR Users
Thanks, Amneet and Boyce. It is good to know that a HDF5 viewer should work with *.samrai files.

I actually like the idea of working with restart files better because it is the most accurate way to extract the data.

@Boyce, could you please walk me through, say extracting the fluid velocity at a given point with a restart file?
Let start with an example ./examples/ConstraintIB/flow_past_cylinder.

Thank you,
Hong

P.S. For some reasons, I have trouble with file attachment.


Yadong Zeng

unread,
Apr 6, 2021, 2:40:49 PM4/6/21
to ibamr...@googlegroups.com
@Hong, are you using AMR in your simulation? 

I am considering writing some codes to process HDF5 files in a parallel way when AMR is involved. Maybe we can collaborate to do it. 

Best. 


--
You received this message because you are subscribed to the Google Groups "IBAMR Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ibamr-users...@googlegroups.com.

Hong Nguyen

unread,
Apr 6, 2021, 3:01:45 PM4/6/21
to IBAMR Users
@Yadong: yeah, AMR is a must in my work. I am glad to collaborate with you on this, but let wait for expert advice. It seems very challenging to deal with parallel data dump,  staggered grids or many levels of patch hierarchy like Boyce mentioned.


Best,
Hong   

Boyce Griffith

unread,
Apr 6, 2021, 3:35:55 PM4/6/21
to IBAMR Users
If you are using AMR in parallel I think it will be easiest to use existing SAMRAI functionality for the analysis that you want to perform. I’ll try to help get a template analysis code set up that maybe you guys can fill out.

Yadong Zeng

unread,
Apr 12, 2021, 1:32:53 PM4/12/21
to IBAMR Users
Thanks, Prof Boyce Griffith. It will be helpful if you can provide a template analysis code as our starting point.  After that, maybe @Hong can I can work together to add some post-processing subroutines there, which can then be used for future IBAMR users.

Best.

Yadong Zeng

unread,
May 4, 2021, 1:43:32 AM5/4/21
to IBAMR Users
Hello Professor Boyce Griffith,

Any updates or directions for this question. Since one of my current tasks is to write some post-processing subroutines. any specific instructions will be very helpful.

Best.

Boyce Griffith

unread,
May 4, 2021, 11:30:02 PM5/4/21
to noreply-spamdigest via IBAMR Users

On May 4, 2021, at 1:43 AM, 'Yadong Zeng' via IBAMR Users <ibamr...@googlegroups.com> wrote:

Hello Professor Boyce Griffith,

Any updates or directions for this question. Since one of my current tasks is to write some post-processing subroutines. any specific instructions will be very helpful.

Sorry for the delay; I should have some time to get to this once I am done teaching for the semester (which is ending soon here at UNC).

— Boyce

Yadong Zeng

unread,
May 6, 2021, 1:37:50 AM5/6/21
to ibamr...@googlegroups.com
Hi Prof. Boyce Griffith,

Thanks for the information. 

On Tuesday (05042021), Prof. Amneet Bhalla had given me some tips through a zoom meeting. To avoid confusion, let me summarize the discussions in that meeting and further clarify what I prefer to do.

Basically, there are two methods to do the post-processing, i.e., on-the-fly and off-the-fly. 
 
On-the-fly: do the post-processing along with the simulation. For this method, we may use these codes (https://github.com/IBAMR/IBAMR/blob/daa16a42e6ff77be06e03b18c8a12660bbb16137/examples/turbulence/ex0/example.cpp#L467) to generate the HDF5 files, not .samrai files. We can then search for some ways to post-processing these HDF5 files.  We can also extract the line data (https://github.com/IBAMR/IBAMR/blob/daa16a42e6ff77be06e03b18c8a12660bbb16137/examples/turbulence/ex0/example.cpp#L467) during the simulation if needed. 

Off-the-fly: do the post-processing when the simulation is finished, i.e., directly extract the point-wise data from the .samrai files. This is what I prefer to do. The reason is that if I want to deal with the HDF5 data, then I need to re-run the simulation. Maybe I will keep in mind that I also need to generate the HDF5 files, but that is something I want to avoid at this time. 

Prof. Amneet Bhalla: anything to add or comment on?

Best.



Amneet Bhalla

unread,
May 6, 2021, 9:35:20 PM5/6/21
to ibamr...@googlegroups.com
On Wed, May 5, 2021 at 10:37 PM 'Yadong Zeng' via IBAMR Users <ibamr...@googlegroups.com> wrote:
Hi Prof. Boyce Griffith,

Thanks for the information. 

On Tuesday (05042021), Prof. Amneet Bhalla had given me some tips through a zoom meeting. To avoid confusion, let me summarize the discussions in that meeting and further clarify what I prefer to do.

Basically, there are two methods to do the post-processing, i.e., on-the-fly and off-the-fly. 
 
On-the-fly: do the post-processing along with the simulation. For this method, we may use these codes (https://github.com/IBAMR/IBAMR/blob/daa16a42e6ff77be06e03b18c8a12660bbb16137/examples/turbulence/ex0/example.cpp#L467) to generate the HDF5 files, not .samrai files. We can then search for some ways to post-processing these HDF5 files.  We can also extract the line data (https://github.com/IBAMR/IBAMR/blob/daa16a42e6ff77be06e03b18c8a12660bbb16137/examples/turbulence/ex0/example.cpp#L467) during the simulation if needed. 

Off-the-fly: do the post-processing when the simulation is finished, i.e., directly extract the point-wise data from the .samrai files. This is what I prefer to do. The reason is that if I want to deal with the HDF5 data, then I need to re-run the simulation. Maybe I will keep in mind that I also need to generate the HDF5 files, but that is something I want to avoid at this time. 

Prof. Amneet Bhalla: anything to add or comment on?

My recommendation is to check with SAMRAI team if they have some post-processing tools to analyze HDF5 data. 

(Boyce, were you planning on doing something related to HDF5 processing? )
--
--Amneet 



Yadong Zeng

unread,
Jun 17, 2021, 11:43:38 PM6/17/21
to IBAMR Users
Hello all, 

Are there some subroutines that can do the weighted sum/average over a plane (e.g., vertical plane or horizontal plane) when the multilevel grid is present?  

Best.

Boyce Griffith

unread,
Jun 21, 2021, 12:57:22 PM6/21/21
to IBAMR Users

On Jun 17, 2021, at 11:43 PM, 'Yadong Zeng' via IBAMR Users <ibamr...@googlegroups.com> wrote:

Hello all, 

Are there some subroutines that can do the weighted sum/average over a plane (e.g., vertical plane or horizontal plane) when the multilevel grid is present?  

Is this a plane in a 3D data set? If so, you might be able to adapt the values provided by HierarchyMathOps::get{Cell,Face,Side}Weight{Variable,PatchDescriptorIndex} to do this. These are essentially providing control volume weights for each non-ghosted position on the AMR grid. This will be easier if you are computing this average over a plane that is aligned with the coordinate axes.

— Boyce

Yadong Zeng

unread,
Jun 21, 2021, 6:05:17 PM6/21/21
to ibamr...@googlegroups.com
Thanks, Prof. Boyce Griffith,

Yes, it is a 3D case. 

Let us assume that I want to get the averaging value of the face-centered U_adv on a plane perpendicular to the y axis. Suppose the refinement ratio is 2 and the max_level is 2. Maybe we want to avoid the repeating calculation for the coarser cells underlying the finer cells. 

How to choose the input variables in the HierarchyMathOps::get{Cell,Face,Side}Weight{Variable,PatchDescriptorIndex} in this case?  Can you make them more specific?

Best. 


Boyce Griffith

unread,
Jun 22, 2021, 4:35:59 PM6/22/21
to IBAMR Users

On Jun 21, 2021, at 6:04 PM, 'Yadong Zeng' via IBAMR Users <ibamr...@googlegroups.com> wrote:

Thanks, Prof. Boyce Griffith,

Yes, it is a 3D case. 

Let us assume that I want to get the averaging value of the face-centered U_adv on a plane perpendicular to the y axis. Suppose the refinement ratio is 2 and the max_level is 2. Maybe we want to avoid the repeating calculation for the coarser cells underlying the finer cells. 

If you are using face-centered vector field, then you would want to use the weights provided by getFaceWeightVariable() and getFaceWeightPatchDescriptorIndex(). This is a face-centered variable that is set up to enable you to compute discrete volume integrals of the form:

sum_{levels l} sum_{grid locations i,j,k on level l} u^{l}_{i,j,k} dx^{l}_{i,j,k}

over all levels and locations on the grid. The weights are automatically zeroed out in coarse regions that are covered by finer regions, so that you do not need to worry about double-counting. For face-centered data, there also are overlapping degrees of freedom along interior patch borders — the weights are appropriately scaled to account for these as well.

You can get the corresponding discrete area element by dividing the volumetric weight by the cell length (on the appropriate level) in the normal direction of interest.

If you wanted to do the same thing for cell-centered or side-centered data, you would use the corresponding cell-centered or side-centered weights.

Does that make sense?

— Boyce

Reply all
Reply to author
Forward
0 new messages