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

Abstract Model and some fixes #6

Merged
merged 34 commits into from
Jan 24, 2024
Merged

Abstract Model and some fixes #6

merged 34 commits into from
Jan 24, 2024

Conversation

nury12n
Copy link
Collaborator

@nury12n nury12n commented Dec 22, 2023

This is a fairly large refactor of kawin which implements an abstract GenericModel object that the precipitate and diffusion models inherit.

Changes

  • Re-organization of package into submodules
    • Submodules include: solver, precipitation, diffusion and thermo
    • Commonly used imported objects are now done by "from kawin import ..." instead of "from kawin.(module_name).import ..."


  • Addition of an abstract model class GenericModel
    • Precipitate and diffusion models inherit this
    • Any model that inherit this will need to implement the getCurrentX, getDt and getdXdt functions to have a complete implementation
    • The solve function for all models will take in delta time and an iterator (default in 4th order Runga Kutta)
      • This changes the API for the PrecipitateModel where the simulation time is defined when solving rather than during initialization
      • Built-in iterators include explicit Euler and 4th order Runga Kutta
      • Custom iterators can easily be implemented and used for solving (see examples/12_Custom_Iterators.ipynb)
    • Model coupling can be done several ways (see examples/08_Model_Coupling.ipynb)
      • By solving multiple models for a given length of time and updating each other
      • Adding one model to another to be updated during solving
      • Using the Coupler object which takes in a list of GenericModels
    • Removed .csv support for saving and loading. Only .npz formats are supported currently as it was easier to generalize across models. I will want to rewrite saving/loading behavior in the future to allow users to combine multiple objects (diffusion, precipitation, strength, etc) into a single output file.


  • SinglePhaseModel changes
    • Diffusivity at the cell boundaries are now done by calculating the diffusivities at the cell centers then interpolating (this differs from the previous implementation where the composition was interpolation to the cell boundaries and the diffusivities were calculated from the interpolated compositions)


  • PrecipitateModel changes
    • Refactor to be compatible with the GenericModel
      • The initial time, final times, number of steps and linear time spacing parameters are removed during initialization. This avoids having the estimate a good number of steps to use during solving as the model will estimate the time step automatically
      • This also simplifies how each iteration is done when solving, where there's no longer a need to track whether the population balance model changed in the number of bins and bin sizes (this was necessary before since the PBM would update in the middle of an iteration rather than at the end).
    • Phase volume parameter is combined to a single function to give the value for the volume and a parameter stating whether it's a lattice parameter, atomic volume (unit cell volume) or molar volume)
    • Shape factors is combined to a single function where a parameter is required stating the shape to use
    • Stopping conditions are a set of classes that can be added to the mode rather than lambda functions. Information for the time that a stopping condition is satisfied can be taken direction from the stopping condition class rather than the precipitate model
      • Time-temperature-precipitation plots can be made from a precipitate model and a set of stopping conditions


  • Thermodynamic changes
    • GeneralThermodynamics, MulticomponentThermodynamics and BinaryThermodynamics are separated into their respective files
    • Tangent driving force method added, which solves for the energy difference for a precipitate to be on the same chemical potential hyperplane as the matrix phase. This allows for negative driving force to be calculated without resorting to the sampling method so the transition from positive to negative driving force is smoother
    • Growth rate for multicomponent systems can be computed for negative driving forces to properly describe dissolution behavior
    • Refactor of GeneralThermodynamics and MutlicomponentThermodynamics to remove repeated code
    • List of parameters can be added upon initialization to be freed when building the thermodynamic and mobility models


  • Mobility and Diffusivity changes
    • Mobility can handle order/disordered models
    • Free energy curvature function will correctly calculate the thermodynamic factor when the mole of formula units for a single phase at equilibrium is not 1 (this occurs for intermetallics and ordered phases with a) multiple sublattices with the sum of site ratios > 1, b) mixing of vacancies and elements on a sublattice)
    • Diffusivity calculations will handle interstitial behavior (implements u-fraction and vacancy consideration on the interstitial sublattice)


  • Additional changes
    • Diffusion models support non-isothermal simulations
    • Population balance model supports recording the time history of the PSD along with saving/loading to/from a .npz file
    • Grain growth model with zener pinning added which can be coupled to a precipitate model
    • Fix precipitation behavior when assuming no diffusion occurs within a precipitate
    • Plotting on strength model is more flexible to allow for single contributions to be plotted (rather than every contribution or total contribution)
    • Updated docstrings
    • Examples are renamed to remove spaces and have them ordered
    • Plotting for diffusion and precipitation is separated into its own file to be a bit cleaner

Documentation is currently in progress. But once we merge this to the main branch and I finish the documentation, I will most likely officially release this to kawin 0.3.0

Ury and others added 25 commits December 7, 2022 18:55
@richardotis
Copy link
Contributor

richardotis commented Jan 14, 2024

I'm starting to go through this now. The diff is so big and touches so much of the codebase, I'm not going to bother to try to go through the diff itself. I've pulled the PR branch and I've started going through it separately. Here is my list of what I'm reviewing:

  • Review Examples
  • Add automated test coverage
  • Review Tests
  • Review Codebase
  • Review Dependencies

Copy link

codecov bot commented Jan 14, 2024

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@richardotis
Copy link
Contributor

Code coverage isn't in the default branch yet, so we don't get the in-PR report, but you can see the results here: https://app.codecov.io/gh/materialsgenomefoundation/kawin/tree/nonisothermal_fixes

@nury12n Do you think you could add additional tests and get total coverage up to, let's say, 60-70%? I recommend focusing attention on the precipitation module.

@richardotis richardotis self-requested a review January 24, 2024 16:41
@nury12n nury12n merged commit b99eec7 into main Jan 24, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants