Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] State variable vtk output for different phases #683

Merged
merged 8 commits into from
Aug 8, 2020

Conversation

bodhinandach
Copy link
Contributor

@bodhinandach bodhinandach commented Aug 5, 2020

Describe the PR
This PR enhances the capability to output vtk files for two-phase particles following the material container refactoring done in PR #675 and #678.

Related Issues/PRs
PR #675 and #678 as well as PR #680 and Issue #633.

Additional context
This will break the existing input configuration. User should change the current vtk_statevars arrangement:

"vtk_statevars": ["pressure", "pdstrain"]

to the new one with phase_id:

"vtk_statevars": [
	{
		"phase_id" : 0,
		"statevars": ["pressure", "pdstrain"]
	},
	{
		"phase_id" : 1,
		"statevars": ["pressure"]
	}
]

If the user doesn't specify the phase_id, it is assumed that the phase_id is 0 by default.

"vtk_statevars": [
	{
		"statevars": ["pressure", "pdstrain"]
	}
]

There is a slight change also in the outputted file name. Instead of producing pressureXYZ.vtp or pressureXYZ.pvtp as output, the modified code will produce P0pressureXYZ.vtp and P0pressureXYZ.pvtp or P1pressureXYZ.vtp and P1pressureXYZ.pvtp for the solid and liquid phase, respectively. I am okay with any other idea of naming the output file, though we need to make it different, as otherwise, the second phase will overwrite the first one.

@codecov
Copy link

codecov bot commented Aug 5, 2020

Codecov Report

Merging #683 into develop will increase coverage by 0.02%.
The diff coverage is 77.14%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #683      +/-   ##
===========================================
+ Coverage    96.66%   96.68%   +0.02%     
===========================================
  Files          123      123              
  Lines        25375    25387      +12     
===========================================
+ Hits         24527    24543      +16     
+ Misses         848      844       -4     
Impacted Files Coverage Δ
include/mesh.h 100.00% <ø> (ø)
include/solvers/mpm_base.h 0.00% <ø> (ø)
tests/io/write_mesh_particles.cc 87.27% <0.00%> (-0.40%) ⬇️
tests/io/write_mesh_particles_unitcell.cc 87.68% <0.00%> (-0.42%) ⬇️
include/solvers/mpm_base.tcc 75.12% <79.31%> (+1.43%) ⬆️
include/mesh.tcc 83.90% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b20da5...6b6c735. Read the comment docs.

// Phase id
if (svars.contains("phase_id"))
phase_id = svars.at("phase_id").template get<unsigned>();

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a check for the valid input of phase_id?

Copy link
Contributor Author

@bodhinandach bodhinandach Aug 5, 2020

Choose a reason for hiding this comment

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

Good point. I think this part is defined globally for simulating single-phase and two-phase, so checking phase_id might be a bit difficult as we need to go to particle level initially unless we specify it somewhere. Nevertheless, if you look at these lines:

double state_variable(
const std::string& var,
unsigned phase = mpm::ParticlePhase::Solid) const override {
return (state_variables_[phase].find(var) != state_variables_[phase].end())
? state_variables_[phase].at(var)
: std::numeric_limits<double>::quiet_NaN();
}

Maybe we can use state_variables_.at(phase) instead of state_variables_[phase] for all the above to assert if the given phase is not allocated. Just that it will be a slower call. What do you think @kks32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any further thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this guarantee that the variable is available: state_variables_[phase].find(var) != state_variables_[phase].end()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, if the state_variables_ have the appropriate phase. If the passed phase is equal or larger than state_variables_.size(), then it will cause a segmentation fault. For instance, if I am accessing index phase=1 in single-phase particle, it will be seg-fault

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kks32 Are we good with this? The current implementation has no phase_id check. So if input phase_id is not available, we will have seg fault.

include/solvers/mpm_base.h Outdated Show resolved Hide resolved
include/solvers/mpm_base.tcc Outdated Show resolved Hide resolved
include/solvers/mpm_base.tcc Outdated Show resolved Hide resolved
@kks32
Copy link
Contributor

kks32 commented Aug 5, 2020

We can use the updated alternative, no reason for us to be backward compatible in this case.

"vtk_statevars": [
	{
		"phase_id" : 0,
		"statevars": ["pressure", "pdstrain"]
	},
	{
		"phase_id" : 1,
		"statevars": ["pressure"]
	}
]

@bodhinandach
Copy link
Contributor Author

It means then we need to modify all mpm.json, are you ok with that? Can we at least make it deprecated for some time and output a deprecated message to let the user change their format?

@kks32
Copy link
Contributor

kks32 commented Aug 5, 2020

Yes, otherwise it's too much of unnecessary branching conditions. No, we create a breaking change, no need for deprecated message or sometime to change. If they use the old format, the code will throw an error, that should be sufficient.

@bodhinandach
Copy link
Contributor Author

bodhinandach commented Aug 6, 2020

@kks32 I added the breaking change. Ping @cb-geo/mpm for info. I will make a new pull request to the benchmark repo to change the input json there as soon as this is merged.

Copy link
Contributor

@kks32 kks32 left a comment

Choose a reason for hiding this comment

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

We never check if the state variable is valid, do we?

include/solvers/mpm_base.tcc Outdated Show resolved Hide resolved
include/solvers/mpm_base.tcc Outdated Show resolved Hide resolved
include/mesh.h Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants