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

Thermo refactor #11

Merged
merged 43 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
83fec95
removed some redundant code between functions
Jul 30, 2024
a496b80
remove returnComp from driving force functions
Jul 30, 2024
890e15b
list comprehension when iterating over x,T for driving force and diff…
Jul 30, 2024
6d2dbcd
simplify driving force return values
Jul 30, 2024
5a04a71
separate diffusivity and driving force cache
Jul 31, 2024
2498b1e
clean up driving force caching
Jul 31, 2024
e75df5a
minor optimizations
Jul 31, 2024
c80fe3a
initial cleanup of MultiTherm.py
Jul 31, 2024
f4d792c
simplify MultiTherm.py
Aug 1, 2024
f35705e
fix caching of composition sets when finding growth rate in MultiTher…
Aug 1, 2024
9119da6
compatible surrogate and multi therm outputs
Aug 1, 2024
48738b1
search direction for impingement factor
Aug 12, 2024
44482bf
merge changes from main
Aug 12, 2024
3c99ba2
testing thermodynamic outputs for both shape and value
Aug 13, 2024
b5e8e26
expose homogenization functions and some minor fixes in the homogeniz…
Aug 22, 2024
3a0e14e
trying a parameter class for diffusion
Aug 30, 2024
42e105a
making api of diffusion parameters more consistent with rest of api
Sep 5, 2024
043af52
set homogenization functions by int ID
Sep 6, 2024
808c92c
back compatibility with old way of setting diffusion parameters
Sep 6, 2024
a468333
merge upstream
Sep 17, 2024
0d04f18
option to override vacancy rich interstitial sublattice assumption fo…
Sep 17, 2024
4dc4fc7
precipitate parameters and exposing nucleation rate calculations
Oct 8, 2024
4a2fe50
moved precipitate time constraints to separate class
Oct 21, 2024
d917612
moved precipitation data to separate class
Oct 21, 2024
038e2eb
minor changes to precipitation data class
Oct 30, 2024
440954f
move precipitate model parameters into MatrixParameters, PrecipitateP…
Oct 30, 2024
5ba38ef
make coupled models compatible with KWN model changes
Oct 30, 2024
7b1cd81
clean up KWNBase and KWNEuler
Nov 4, 2024
f56bcbf
replace internal nucleation functions in PrecipitateBase with externa…
Nov 12, 2024
edb29c1
make examples compatible to API changes
Nov 12, 2024
8d5a4b7
allow for initializing models with parameters
Nov 28, 2024
62be85e
update all examples to new API and add helper functions in thermo to …
Nov 28, 2024
900981b
start refactoring surrogate model
Dec 3, 2024
8aa1aa1
refactored surrogate models
Dec 3, 2024
dd63032
refactor of ShapeFactors, ElasticFactors and Nucleation Barrier param…
Dec 11, 2024
6393949
fix packages names
Dec 12, 2024
a1c185d
add json saving/loading to surrogate models, remove old surrogate models
Dec 12, 2024
8600954
added tests for shape factor and strain energy
Dec 13, 2024
a6698c8
back compatiblity tests for diffusion and precipitation modules
Dec 13, 2024
e121edf
basic saving/loading of model data
Dec 23, 2024
dc7977a
nucleation rate example and dynamic updating of nucleation site param…
Dec 26, 2024
422344b
added doctstrings
Jan 13, 2025
4cd299f
update readme
Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Python implementation of the Kampmann-Wagner Numerical (KWN) model to predict pr

Notes
-----
There are some API changes between kawin 0.3.0 and 0.2.0. Please see the examples for more details.
There has been a lot of changes in the API between the current release and the development version of kawin. The current examples reflect the API of the development version. Examples using the release API can be found in commit f748761. Users of the development version are encouraged to switch to the new API. While back-compatibility was sought to be maintained, there may have been some changes. If there are any issues in running the development or release version of kawin, please open an issue.

Installation
------------
Expand Down
134 changes: 56 additions & 78 deletions examples/01_Binary_Precipitation.ipynb

Large diffs are not rendered by default.

113 changes: 54 additions & 59 deletions examples/02_Multicomponent_Precipitation.ipynb

Large diffs are not rendered by default.

148 changes: 80 additions & 68 deletions examples/03_Multiphase_Precipitation.ipynb

Large diffs are not rendered by default.

63 changes: 28 additions & 35 deletions examples/04_Precipitation_with_Elastic_Energy.ipynb

Large diffs are not rendered by default.

68 changes: 30 additions & 38 deletions examples/05_Strength_Modeling.ipynb

Large diffs are not rendered by default.

39 changes: 18 additions & 21 deletions examples/06_Single_Phase_Diffusion.ipynb

Large diffs are not rendered by default.

85 changes: 46 additions & 39 deletions examples/07_Homogenization_Model.ipynb

Large diffs are not rendered by default.

76 changes: 37 additions & 39 deletions examples/08_Model_Coupling.ipynb

Large diffs are not rendered by default.

185 changes: 70 additions & 115 deletions examples/09_Thermodynamics.ipynb

Large diffs are not rendered by default.

223 changes: 106 additions & 117 deletions examples/10_Surrogates.ipynb

Large diffs are not rendered by default.

202 changes: 132 additions & 70 deletions examples/11_Extra_Factors.ipynb

Large diffs are not rendered by default.

88 changes: 49 additions & 39 deletions examples/12_Custom_Iterators.ipynb

Large diffs are not rendered by default.

169 changes: 169 additions & 0 deletions examples/13_Nucleation_Rate.ipynb

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions kawin/Constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# Constants that all modules may find useful
GAS_CONSTANT = 8.314
AVOGADROS_NUMBER = 6.022e23
BOLTZMANN_CONSTANT = GAS_CONSTANT / AVOGADROS_NUMBER
76 changes: 20 additions & 56 deletions kawin/GenericModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,20 @@
def __init__(self):
self.clearCouplingModels()

def _getVarDict(self):
def toDict(self):
'''
Returns variable dictionary mapping variable name to internal member name
Creates a dictionary data set of the following:
- this will only save the data that was solved for and not model parameters

This is used to when saving the model into a npz format, where the member names
will be replaced with the variable names defined by this dictionary
TODO: eventually support saving model parameters. This is a bit tough with all the nested parameters right now
'''
return {}

def _addExtraSaveVariables(self, saveDict):
'''
Adds extra variables to the save dictionary that are not covered by the variable dictionary
The variable dictionary only cover members that can be retrieved from getattr, so
this function is used to save data if it is from another class that itself is an attribute

Parameters
----------
saveDict : dictionary { str : np.ndarray }
Dictionary to add data to
'''
return

def _loadExtraVariables(self, data):
'''
Loads extra variables in data not covered by the variable dictionary

Parameters
----------
data : dictionary { str : np.ndarray }
Dictionary to read data from
'''
return
@classmethod
def fromDict(self, data):
pass

Check warning on line 46 in kawin/GenericModel.py

View check run for this annotation

Codecov / codecov/patch

kawin/GenericModel.py#L46

Added line #L46 was not covered by tests

def save(self, filename, compressed = True):
def save(self, filename: str):
'''
Saves model data into file

Expand All @@ -80,32 +60,16 @@
compressed : bool (defaults to True)
Whether to save in compressed format
'''
varDict = self._getVarDict()
saveDict = {}
for var in varDict:
saveDict[var] = getattr(self, varDict[var])
self._addExtraSaveVariables(saveDict)
if compressed:
np.savez_compressed(filename, **saveDict)
else:
np.savez(filename, **saveDict)

def _loadData(self, data):
'''
Loads data taken from .npz file into model

1. Sets attributes using mapping defined from _getVarDict
2. Loads extra variables using _loadExtraVariables
data = self.toDict()
if not filename.endswith('.npz'):
filename += '.npz'

Check warning on line 65 in kawin/GenericModel.py

View check run for this annotation

Codecov / codecov/patch

kawin/GenericModel.py#L65

Added line #L65 was not covered by tests
np.savez_compressed(filename, **data)

Parameters
----------
data : dictionary { str : np.ndarray }
Data to load from
'''
varDict = self._getVarDict()
for var in varDict:
setattr(self, varDict[var], data[var])
self._loadExtraVariables(data)
def load(self, filename: str):
if not filename.endswith('.npz'):
filename += '.npz'

Check warning on line 70 in kawin/GenericModel.py

View check run for this annotation

Codecov / codecov/patch

kawin/GenericModel.py#L70

Added line #L70 was not covered by tests
data = np.load(filename)
self.fromDict(dict(data))

def addCouplingModel(self, model):
'''
Expand Down Expand Up @@ -261,7 +225,7 @@
This is sometimes useful for determining the time step
'''
self.deltaTime = simTime
self.startTime = currTime
self.initialTime = currTime
self.finalTime = currTime+simTime

def flattenX(self, X):
Expand Down Expand Up @@ -347,8 +311,8 @@

t, X0 = self.getCurrentX()
self.setTimeInfo(t, simTime)
solver.solve(self.startTime, X0, self.finalTime, verbose, vIt)
#solver.solve(self.getdXdt, self.startTime, X0, self.finalTime, verbose, vIt, self.correctdXdt, self.flattenX, self.unflattenX)
solver.solve(self.initialTime, X0, self.finalTime, verbose, vIt)
#solver.solve(self.getdXdt, self.initialTime, X0, self.finalTime, verbose, vIt, self.correctdXdt, self.flattenX, self.unflattenX)

class Coupler(GenericModel):
'''
Expand Down
Loading
Loading