Defining the structures in main.cpp

134 views
Skip to first unread message

Sagar G Nayak

unread,
Jul 20, 2023, 1:47:46 AM7/20/23
to IBAMR Users
Hi All,
I am trying to solve particle sedimentation problem of 504 particles (https://doi.org/10.1016/S0301-9322(98)00048-2) using ConstraintIB. When I define all 504 particles in the input2d, the code throws error. I tried shortening the name of the structures to check whether a reduced string size would help, but it didn't. Is there any limitation on the number of structures that can be given?

Is there any way to define these structures in the main.cpp instead of input2d? I tried, but main.cpp seems to take everything as 'objects'.

An example code or any suggestions would be very helpful.

( If you are wondering, the code seems to accept num_structures<=143. PFA)

Thanks

Screenshot from 2023-07-20 11-16-37.png

Amneet Bhalla

unread,
Jul 20, 2023, 12:40:43 PM7/20/23
to ibamr...@googlegroups.com
For these many structures, you should add them programmatically rather than through input or vertex files. Here is an example of it:


Basically create an IBInitializer object that registers a callback function to generate vertices of the structure instead of reading it off from the input file. 

--
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/e475ad0f-b2bd-4843-a647-e9be077f46ben%40googlegroups.com.


--
--Amneet 



Boyce Griffith

unread,
Jul 20, 2023, 1:35:46 PM7/20/23
to ibamr...@googlegroups.com

On Jul 20, 2023, at 1:47 AM, Sagar G Nayak <nayaks...@gmail.com> wrote:

Hi All,
I am trying to solve particle sedimentation problem of 504 particles (https://doi.org/10.1016/S0301-9322(98)00048-2) using ConstraintIB. When I define all 504 particles in the input2d, the code throws error. I tried shortening the name of the structures to check whether a reduced string size would help, but it didn't. Is there any limitation on the number of structures that can be given?

This error says that the file “p_0.vertex” is missing — can you confirm that file is present? I don’t think that there is any fundamental restriction on the number of structures that you should hit with this number of structures.

That said — I don’t know how well we have tested cases that involve large numbers of structures — there could be some performance bugs lurking …

Is there any way to define these structures in the main.cpp instead of input2d? I tried, but main.cpp seems to take everything as 'objects'.

An example code or any suggestions would be very helpful.

( If you are wondering, the code seems to accept num_structures<=143. PFA)

Thanks


--
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/e475ad0f-b2bd-4843-a647-e9be077f46ben%40googlegroups.com.
<Screenshot from 2023-07-20 11-16-37.png>

Sagar G Nayak

unread,
Jul 21, 2023, 1:06:21 AM7/21/23
to IBAMR Users
Thank you very much, Dr Amneet. I will try to implement it into ConstraintIB.

This error says that the file “p_0.vertex” is missing — can you confirm that file is present?
Thank you Dr Griffith. Yes, I have checked its presence. For num_structures=143, the code successfully reads all the vertex files (including p_0.vertex) but for num_structures=144 it throws this error.

I am also wondering why 143?. I have also tried reducing number of Lagrangian points, it doesn't help. Error seems to depend only on number of structures.

Thanks

govind sharma

unread,
Jul 21, 2023, 1:20:35 AM7/21/23
to ibamr...@googlegroups.com
HI,

Yes Sagar, I also tested for n number of structures and got the same number '143'. It seems to be the limitation on reading the files from a system directory. However, internally generating the structures will alleviate this issue and with that it would be possible to insert thousands of particles.

Regards,
Govind

Sagar G Nayak

unread,
Jul 21, 2023, 6:19:56 AM7/21/23
to IBAMR Users
Thank you, Govind for confirming. I doubt that it is not a system limitation. When I used std::ifstream to read 504 vertex files in a separate code, it works just fine.
Thank you for the idea of generating structures internally.

Boyce Griffith

unread,
Jul 21, 2023, 9:30:46 AM7/21/23
to noreply-spamdigest via IBAMR Users

On Jul 21, 2023, at 6:19 AM, Sagar G Nayak <nayaks...@gmail.com> wrote:

Thank you, Govind for confirming. I doubt that it is not a system limitation. When I used std::ifstream to read 504 vertex files in a separate code, it works just fine.
Thank you for the idea of generating structures internally.

Can you reproduce this bug with one of the IBAMR examples? This sounds like something that we should fix.

Sagar G Nayak

unread,
Jul 23, 2023, 12:05:48 PM7/23/23
to IBAMR Users
Dear Dr. Griffith,

Please find the attached code. I modified ConstraintIB/flow_over_cylinder code to simulate sedimentation problem I mentioned earlier. Directory contains two extra C codes.
1. 504particlesPacking.C generates vertex files for all 504 particles (p_0 - p_503) as mentioned in the paper (https://doi.org/10.1016/S0301-9322(98)00048-2)
2. generateInput.C generates a valid input file for the given number of structures. It takes number of structures as command line argument. It also generates the file 'visit.txt' which contains visit-macro that can be used if you wish to visualize the result.

I run the code in the following manner:
i)     g++ 504particlesPacking.C
ii)    ./a.out
iii)   g++ generateInput.C
iv)  ./a.out 143
v)   make
vi) ./main2d input2D

Now, in step (iv) if I give anything more than 143 it throws the error that I shared earlier (and what Govind also confirmed).

Please let me know if it works for you. 

Thank you,
sedimentation.zip

Sagar G Nayak

unread,
Jul 29, 2023, 10:24:21 AM7/29/23
to IBAMR Users
Hello Dr. Griffith,
Any chance you got to work on that code?

Meanwhile, I worked on the technique that Dr. Amneet suggested (i.e generating the structures within the code itself). I am able to do that, but the problem still persists. It throws error when I try to generate large number of structures. Please find the attached screenshot.

Thanks
Screenshot from 2023-07-29 19-52-55.png

Amneet Bhalla

unread,
Jul 29, 2023, 11:52:58 AM7/29/23
to ibamr...@googlegroups.com
It could be a different error. The error message is not clear. Suggest building IBAMR in debug mode, and running the application via debugger (e.g., gdb)

$gdb ./main2d

This launches the app in debugger

$ r input2d 

This runs the application via gdb

$ bt

(this shows the backtrace)

$ f  <X>

(without `<' and '>') 

 You can move to frame X, which is the problematic frame, and see what is going on.   

Here are gdb command references:



--
--Amneet 



Sagar G Nayak

unread,
Aug 9, 2023, 9:33:51 AM8/9/23
to IBAMR Users
Thank you, Dr. Amneet. I resolved some bugs using debugger, but the problem is still present. The code seems to behave differently when number of structures is more than 143 (yes, even in this case it is the same number). By "different" I mean, it is not able to read from a file properly (an operation that it can do perfectly if num_structures <=143). It takes zeros instead of what is present in the file. I am attaching snippets of my implementations and also outputs.

I am reading COM of particles from "comFile.dat" and generating those structures in "generate_structure" function. I am giving "generate_structure" as a call back function as you suggested.

In a different attempt, I tried inserting the vertex generating code in IBStandardInitializer.cpp/IBRedundantInitializer.cpp and also tried modifying ConstraintIBKinematics.cpp. All these attempts did work but again only for num_structures<=143. I even checked my system memory usage while running the code, it doesn't seem to cause any error.

Can you please help?

Thanks
function_definition.png
output_structures>143.png
output_strcutres<143.png
function_call.png

Sagar G Nayak

unread,
Aug 9, 2023, 10:18:02 AM8/9/23
to IBAMR Users
I thought, a working code would better explain the issue. I am attaching the code.

Generate input2D for whatever number of structures you want e.g for num_structures=143, do
g++ generateInput.C
./a.out 143

then
make
./main2d input2D

Please note that for num_structures>=144 you get the "Lagrangian Data must be inside the domain" error. It is because the code takes center of masses wrongly (from comFile) and not because they actually lie outside.

Thanks
sedimentation.zip

Sagar G Nayak

unread,
Aug 17, 2023, 12:25:22 AM8/17/23
to ibamr...@googlegroups.com
Hello Dr. Amneet, Dr. Griffith,
Any chance you could work on the problem? Any insights to solve the problem?

Thanks

You received this message because you are subscribed to a topic in the Google Groups "IBAMR Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ibamr-users/bPuICoAPgOw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ibamr-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ibamr-users/2275f434-e39d-4a20-8e7e-92bad60157b0n%40googlegroups.com.


--
Regards
Sagar G. Nayak
Research Scholar,
University of Queensland-IIT Delhi Academy of Research (UQIDAR),
Indian Institute of Technology Delhi,
Hauz Khas, New Delhi-110016, India. 

Aaron Barrett

unread,
Aug 17, 2023, 1:40:03 PM8/17/23
to IBAMR Users
I believe this issue is related to the number of file handles generated by ConstraintIBMethod. Currently, it generates 7 files per structure. With 144 structures, that's 1008 file handles. The default max on some linux systems is 1024.

A quick verification that this is the issue to put this code in the main routine directly before the first error (code from https://stackoverflow.com/questions/8163757/find-current-number-of-open-filehandle-not-lsof)

        int j, n = 0;

        // count open file descriptors
        for (j = 0;  j < 8000;  ++j)     // FDMAX should be retrieved from process limits,
                                          // but a constant value of >=4K should be
                                          // adequate for most systems
        {
            int fd = dup (j);
            if (fd < 0)
                continue;
            ++n;
            close (fd);
        }
        printf ("%d file descriptors open\n", n);

Boyce Griffith

unread,
Aug 19, 2023, 10:31:09 AM8/19/23
to ibamr...@googlegroups.com

On Aug 17, 2023, at 1:40 PM, Aaron Barrett <bar...@math.utah.edu> wrote:

I believe this issue is related to the number of file handles generated by ConstraintIBMethod. Currently, it generates 7 files per structure. With 144 structures, that's 1008 file handles. The default max on some linux systems is 1024.

Is this an issue that is unique to ConstraintIBMethod?

Amneet Bhalla

unread,
Aug 19, 2023, 10:35:33 AM8/19/23
to ibamr...@googlegroups.com
In the input file one can specify what to output or not. Although I’m not if empty files are created or not.

In any case, I suggest that Sagar can modify the I/O part of ConstraintIBMethod locally to generate a few files that still has all the information that is needed for postprocessing. For example, center of mass position of all structures can be outputted in a single file. 

Boyce Griffith

unread,
Aug 19, 2023, 10:37:21 AM8/19/23
to noreply-spamdigest via IBAMR Users

On Aug 19, 2023, at 10:35 AM, Amneet Bhalla <mail2...@gmail.com> wrote:

In the input file one can specify what to output or not. Although I’m not if empty files are created or not.

In any case, I suggest that Sagar can modify the I/O part of ConstraintIBMethod locally to generate a few files that still has all the information that is needed for postprocessing. For example, center of mass position of all structures can be outputted in a single file. 

We should probably default to providing a small number of summary output files for cases involving “large" numbers of structures.

Sagar G Nayak

unread,
Sep 19, 2023, 2:57:00 AM9/19/23
to IBAMR Users
Thank you very much Dr Barrett, Dr Amneet and Dr Griffith. That exactly was the problem. Now I am able put any number of structures.

I am printing everything on to single file, as Dr Amneet suggested. It works perfectly fine for me.

Also, it seems there are no "file closing" statements for these files. I think we can also solve this issue by opening and closing the files every time step (and append the data, like how it is done when restarted).

I am extremely sorry for my late reply. I could not check this group for a long time now.

Thanks again,
Reply all
Reply to author
Forward
0 new messages