Skip to content

[Bug] Resume with multiple particle_types#115

Open
cgeudeker wants to merge 5 commits intomasterfrom
bugfix/resumeParticleType
Open

[Bug] Resume with multiple particle_types#115
cgeudeker wants to merge 5 commits intomasterfrom
bugfix/resumeParticleType

Conversation

@cgeudeker
Copy link
Copy Markdown
Collaborator

Describe the PR
When resuming a simulation with multiple particle_types, a full set of particles would be generated for each particle type. Additionally, it seems that each instance of the same particle type would be loaded in full, though subsequent generation would likely replace the previous. As such the following modifications have been made:

  • In ParticlePODTypeName, each distinct particle type has been assigned a specific POD type name, though these all lead to the eventual use of the "particles" POD type for file reading and writing.
  • In initialise_particle_types, a modification has been made to only add distinct particle types.
  • New .h5 files for each particle_type will be generated as a result, ensuring no multiple generations of the same particle upon resume.

Related Issues/PRs
N/A

Additional context
N/A

…sures that resume does not load particle types multiple times. Also only adds unique particle types to particle_types_. Not clanged. Not tested.
@cgeudeker cgeudeker added the bug Something isn't working label Dec 14, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 14, 2025

Codecov Report

❌ Patch coverage is 86.98630% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.71%. Comparing base (b690d4a) to head (4e248b4).
⚠️ Report is 52 commits behind head on master.

Files with missing lines Patch % Lines
tests/io/write_mesh_particles.cc 77.65% 38 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #115      +/-   ##
==========================================
- Coverage   95.76%   95.71%   -0.05%     
==========================================
  Files         244      245       +1     
  Lines       51467    51730     +263     
==========================================
+ Hits        49284    49509     +225     
- Misses       2183     2221      +38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bodhinandach bodhinandach self-requested a review December 14, 2025 18:30
Copy link
Copy Markdown
Member

@bodhinandach bodhinandach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgeudeker Thanks for finding and fixing this. Perhaps it is good to make some tests, if it is not too difficult?

Comment thread include/solvers/mpm_base.tcc Outdated
@cgeudeker
Copy link
Copy Markdown
Collaborator Author

@cgeudeker Thanks for finding and fixing this. Perhaps it is good to make some tests, if it is not too difficult?

Yes will work on a couple.

@bodhinandach bodhinandach requested a review from Curiim December 17, 2025 10:11
Comment thread include/mesh/mesh.tcc
Comment on lines -529 to -540
for (const auto ptype : particle_types_) {
std::string attribute = mpm::ParticlePODTypeName.at(ptype);
std::string extension = ".h5";

auto particles_file =
io_->output_file(attribute, extension, uuid_, step_, this->nsteps_)
.string();

// Load particle information from file
mesh_->read_particles_hdf5(particles_file, attribute, ptype);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reasons why this is moved to read_hdf5() function? Just to tidy it up?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes its mainly a tidy up, better follows the write approach as well. Just makes it a little more readable in my opinion, can switch it back if we want.

Comment thread include/mesh/mesh.h
@cgeudeker
Copy link
Copy Markdown
Collaborator Author

cgeudeker commented Dec 17, 2025

Updates from attempts with multi-particle-type simulations with pml simulation:

  • 🟢 Write functions working as expected in serial without resume.
  • 🟢 Read and write functions working as expected in serial after resume.
  • 🟡 Write functions maybe working with mpi without resume.
  • 🟡 Read and write functions maybe working with mpi after resume.

Received a segmentation issue in the first time simulating with MPI and then received the previously observed pml-specific material information error in the first resume attempt. I have not been able to reproduce either and have only had it happen in the first instance of using either. After first instances, both have worked in each call so far. Screenshots of both cases below.
Without resume:
image
With resume:
image

@bodhinandach
Copy link
Copy Markdown
Member

@cgeudeker Would you be able to confirm if you have fixed the latest reported problem of seg fault in MPI resume?

Copy link
Copy Markdown
Member

@bodhinandach bodhinandach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgeudeker Thanks for the effort. Overall, looks good to me. But I have some questions that I would like to understand.

Comment thread include/mesh/mesh.tcc
auto pod = std::static_pointer_cast<mpm::PODParticle>((*pitr)->pod());
particle_data.emplace_back(*pod);
if (particle_type == (*pitr)->type()) {
auto pod = std::static_pointer_cast<mpm::PODParticle>((*pitr)->pod());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This casting to mpm::PODParticle means that the different particle types should have the same POD t,ype right? That means single-phase particles cannot be output together with two-phase particles since they have different POD types. Is that the intention? I guess, we are not going to run a scenario of both multi-phase particles and single-phase particles simulated at the same time, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not true, since if there are different particle types, they're gonna call different functions from mpm_base.tcc.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of this check is just to confirm that only particles of the same particle type are output to the file that is being written in a given instance of the function call. I would assume all particles of a given type would have the same POD.

Comment thread include/mesh/mesh.tcc
particle_data.emplace_back(*pod);
if (particle_type == (*pitr)->type()) {
auto pod =
std::static_pointer_cast<mpm::PODParticleTwoPhase>((*pitr)->pod());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, but vice versa.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here....

//! Read HDF5 files
template <unsigned Tdim>
void mpm::MPMBase<Tdim>::read_hdf5() {
// Read hdf5 file for single phase particle
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment may be misleading

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix.

// Load particle information from file
mesh_->read_particles_hdf5(particles_file, attribute, ptype);
}
this->read_hdf5();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too sure what the necessity is to bundle them into a single function. Is this just to improve readability? Or is there any specific efficiency reason?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only to improve readability and match the same naming conventions that the write pathway has. Can change back if desired.

@cgeudeker
Copy link
Copy Markdown
Collaborator Author

@cgeudeker Would you be able to confirm if you have fixed the latest reported problem of seg fault in MPI resume?

Yes this has been fixed. Simple 1D bar compression with two particle types, successfully ran in the four aforementioned cases (serial or mpi with and without resume) and yielded the same results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants