Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Miguel! Here are all the modifications I made in order to solve the segmentation faults we encountered during our coding session.
As I anticipated to you, I have mainly restructured the way metabolites are handled by the dFBAModel and dFBAReaction classes. Below there is a summary of the changes I have made (summary gently offered and powered by chatGPT based on my notes):
Revised Metabolite Management:
Updated the dFBAModel to centrally manage metabolites using metabolite IDs instead of pointers. This ensures better memory management and reduces the risk of dangling pointers when metabolites are referenced across different classes.
Modified the dFBAReaction class to store only metabolite IDs and stoichiometric coefficients, instead of maintaining direct pointers to dFBAMetabolite objects.
Reaction Handling Overhaul:
Updated dFBAModel to manage reactions in a similar way by using reaction IDs. This centralized the responsibility of managing reactions, reducing redundancy and improving overall code clarity.
Adjusted functions across dFBAModel and dFBAReaction to work with IDs, allowing dFBAModel to maintain ownership of metabolites and reactions.
Constructor, Destructor, and Copy Constructor Updates:
Revised constructors, destructors, and copy constructors for dFBAModel and dFBAReaction classes to properly implement deep copying and safe deletion of objects. This change prevents memory leaks and segmentation faults when creating or destroying instances of these classes.
Refactored Intracellular Class:
Updated the intracellular class to be compatible with the new metabolite and reaction management structure. This involved adapting methods for adding, retrieving, and debugging reactions within the model.
Debug Statements:
Added debug statements to print reaction details during initialization to help trace the creation and setup of each reaction. This proved helpful in identifying issues during model setup.
Header and Compilation Fixes:
Fixed several compilation errors by adding forward declarations and updating header files to ensure correct inclusion. This resolved issues related to incomplete types and allowed all classes to correctly reference each other.
End of the summary.
Since I was there, I have also cleaned a bit the code, removed some printing statements and corrected some comments.
Let me know what you think!
I have not tested if the results are actually correct but the code runs with no seg fault for one or more cells on single core and on multiple cores. I have also updated the python script to download the necessary files for fba and the ecoli sample project with the specifics you asked me (two cells on the two half of the domain, oxygen diffusing from the right border).