API: Core
matmdl.core
crystalPlasticity
This module contains functions relevant to the application of Huang's crystal plasticity subroutine.
do_orientation_inputs(next_params, orient, in_opt)
Get and write new orientation information, if necessary.
If input file is in orientation structure, uses that.
Source code in matmdl/core/crystalPlasticity.py
get_offset_angle(direction_og, direction_to, angle)
Iterative solution for finding vectors tilted toward other vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction_og
|
vector
|
Real space vector defining the original direction to be tilted away from. |
required |
direction_to
|
vector
|
Real space vector defining the direction to be tilted towards. |
required |
angle
|
float
|
The angle, in degrees, by which to tilt. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
a scalar multiplier such that the angle between |
Source code in matmdl/core/crystalPlasticity.py
get_orient_info(next_params, orient, in_opt)
Get components of orientation-defining vectors and their names for substitution into the orientation input files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_params
|
list
|
Next set of parameters to be evaluated by the optimization scheme. |
required |
orient
|
str
|
Index string for dictionary of input
orientations specified in :ref: |
required |
Source code in matmdl/core/crystalPlasticity.py
param_check(param_list)
True if tau0 >= tauS
In theory, tau0 should always come before tauS, even though it doesn't make a difference
mathematically/practically. Function checks for multiple systems if numbered in the form
TauS, TauS1, TauS2 and Tau0, Tau01, Tau02.
Note
Deprecated. Better to do this by mapping whatever hyper-rectangular input bounds
to your acceptable parameter space. E.g. optimizing on tauS_shift on [0,10]
and adding a derived parameter in the Abaqus inputs: tauS = tau0 + tauS_shift.
Source code in matmdl/core/crystalPlasticity.py
experimental
Contains the class for extracting and storing experimental data from plain text inputs for comparison to iterative solution attempts.
ExpData
Loads and stores experimental data.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
dict
|
Indexed by orientation name defined in :ref: |
Note
Experimental stress-strain data are expected as plaintext in two columns: strain (unitless), and stress (matching the CPFEM inputs, often MPa).
Source code in matmdl/core/experimental.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
optimizer
Module for instantiating and updating the optimizer object.
InOpt
Stores information about the optimization input parameters.
Since the hardening parameters and orientation parameters are fundamentally different, this object stores information about both in such a way that they can still be access independently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orientations
|
dict
|
Orientation information directly from |
required |
params
|
dict
|
name and bounds of parameters to be optimized. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
orients |
list
|
Nickname strings defining orientations, as given
in :ref: |
material_params |
list
|
Parameter names to be optimized, as in :ref: |
material_bounds |
list
|
Tuple of floats defining bounds of parameter in the same
index of |
orient_params |
list
|
Holds orientation parameters to be optimized, or single
orientation parameters if not given as a tuple in :ref: |
orient_bounds |
list
|
List of tuples corresponding to the bounds for the parameters
stored in |
params |
list
|
Combined list consisting of both |
bounds |
list
|
Combined list consisting of both |
has_orient_opt |
dict
|
Dictionary with orientation nickname as key and boolean as value indicating whether slight loading offsets should be considered for that orientation. |
fixed_vars |
dict
|
Dictionary with orientation nickname as key and any fixed
orientation information ( |
offsets |
list
|
List of dictionaries containing all information about the offset as given in the input file. Not used/called anymore? |
num_params_material |
int
|
Number of material parameters to be optimized. |
num_params_orient |
int
|
Number of orientation parameters to be optimized. |
num_params_total |
int
|
Number of parameters to be optimized in total. |
Note
Checks if orientations[orient]['offset']['deg_bounds']
in :ref:orientations is a tuple to determine whether
orientation should also be optimized.
Source code in matmdl/core/optimizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
__init__(orientations, params)
Sorted orientations here defines order for use in single list passed to optimizer.
Source code in matmdl/core/optimizer.py
get_next_param_set(opt, in_opt)
Give next parameter set to try using current optimizer state.
Allow to sample bounds exactly, round all else to reasonable precision.
Source code in matmdl/core/optimizer.py
instantiate(in_opt, uset)
Define all optimization settings, return optimizer object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_opt
|
object
|
Input settings defined in :class: |
required |
uset
|
User settings from input file. |
required |
Returns:
| Type | Description |
|---|---|
object
|
skopt.Optimize: Instantiated optimization object. |
Source code in matmdl/core/optimizer.py
load_previous(opt, search_local=False)
Load input files of previous optimizations to use as initial points in current optimization.
Looks for a file named out_progress.txt from which to load previous results.
Requires access to global variable opt_progress that stores optimization output.
The parameter bounds for the input files must be within current parameter bounds.
Renumbers old/loaded results in opt_progress to have negative iteration numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
opt
|
object
|
Current instance of the optimizer object. |
required |
search_local
|
bool
|
Look in the current directory for files (convenient for plotting from parallel instances). |
False
|
Returns:
| Type | Description |
|---|---|
object
|
skopt.Optimizer: Updated instance of the optimizer object. |
Source code in matmdl/core/optimizer.py
update_if_needed(opt, in_params, in_errors)
Give params and errors to state, updating optimizer if needed.
Need is determined by state.num_paramsets, which is set by relative timing of the FEA and opt.tell() procedures.
in_params and state.last_params may contain duplicate updates from
parallel instances, but these will be dealt with by opt.tell()
Source code in matmdl/core/optimizer.py
parallel
Module for dealing with the present optimization being one of many simultaneous instances.
This is presumed to be the case when the setting main_path has a value.
Everything here should be called within a Checkout guard.
Checkout
Checkout shared resource without write collisions.
Source code in matmdl/core/parallel.py
__call__(fn)
assert_db_lengths_match()
loads and checks lengths of all output files; used for debugging
Source code in matmdl/core/parallel.py
check_parallel()
Starts parallel initialization if needed.
Note
This copies files from uset.main_path but does not reload the input file.
Source code in matmdl/core/parallel.py
copy_files(file_patterns)
copy files from uset.main_path to runner dir
Source code in matmdl/core/parallel.py
update_parallel()
Update state if needed based on shared database timing information.
Returns:
| Name | Type | Description |
|---|---|---|
params |
list
|
parameter values (list) of unseen points to be updated |
errors |
list
|
error values (scalar) of unseen points to be updated |
Note
Also updates state.last_updated timing information.
Source code in matmdl/core/parallel.py
parser
Module that loads and checks input file.
UserSettings
Load, check, and store input from the input file.
Note
Attributes must be written/deleted within an unlock context manager and should not be overwitten during the optimization since changing behavior makes the history harder to follow.
Source code in matmdl/core/parser.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
Option
Options that are commonly associated with each input.
Source code in matmdl/core/parser.py
__init__(**kwargs)
Defaults for option instances.
Source code in matmdl/core/parser.py
runner
Helper module for some abstracted commands used in run.
check_single()
rough copy of run/single_loop that does not use an optimizer object
Source code in matmdl/core/runner.py
get_first(opt, in_opt, exp_data)
Run one simulation so its output dimensions can later inform the shape of output data.
Source code in matmdl/core/runner.py
refine_run(ct=0)
Restart simulation with smaller maximum increment size.
Cut max increment size by factor (hardcoded), possibly multiple
times up to uset.recursion_depth or until Abaqus finished successfully.
After eventual success or failure, rewrites original input file so that the
next run starts with the initial, large maximum increment.
Recursive calls tracked through ct parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ct
|
int
|
Number of times this function has already been called. Starts
at 0 and can go up to |
0
|
Source code in matmdl/core/runner.py
remove_out_files()
Delete files from previous optimization runs if not reloading results.
Source code in matmdl/core/runner.py
state
Module for optimization state meta-indicators, like iteration number and time.
State
Contains and updates iteration and timing for each optimization process.
Attributes:
| Name | Type | Description |
|---|---|---|
iterations |
int
|
number of iterations performed by this process |
last_updated |
int
|
time in unix nanoseconds of the last update to the optimizer state from any process |
tell_time |
float
|
duration of time in seconds for the opt.tell process |
run_time |
float
|
duration of time in seconds for a single iteration of the run process |
Note
Warns when tell_time > run_time but does not change behavior.
Source code in matmdl/core/state.py
utilities
Utility functions that fit nowhere else.
These should have no matmdl dependencies.
as_float_tuples(list_of_tuples)
Make sure tuples contain only floats.
Take list of tuples that may include ints and return list of tuples containing only floats. Useful for optimizer param bounds since type of input determines type of param guesses. Skips non-tuple items in list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_of_tuples
|
list[tuple[Union[int, float]]]
|
Tuples in this list may contain a mix of floats and ints. |
required |
Returns: The same list of tuples containing only floats.
Source code in matmdl/core/utilities.py
log(message)
msg(message)
unit_vector(vector)
warn(message, warn_type=UserWarning)
Raise warning with consistent formatting
writer
Module for writing to files.
combine_SS(zeros, orientation)
Reads npy stress-strain output and appends current results.
Loads from temp_time_disp_force_{orientation}.csv and writes to
out_time_disp_force_{orientation}.npy. Should only be called after all
orientations have run, since zeros==True if any one fails.
For parallel, needs to be called within a parallel.Checkout guard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zeros
|
bool
|
True if the run failed and a sheet of zeros should be written in place of real time-force-displacement data. |
required |
orientation
|
str
|
Orientation nickname to keep temporary output files separate. |
required |
Source code in matmdl/core/writer.py
write_error_to_file(error_list, orient_list, combination_function)
Write error values separated by orientation, if applicable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_list
|
list[float]
|
List of floats indicated error values for each orientation
in |
required |
orient_list
|
list[str]
|
List of strings holding orientation nicknames. |
required |
Source code in matmdl/core/writer.py
write_input_params(fname, param_names, param_values, debug=False)
Write parameter values to file with = as separator.
Used for material and orientation input files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Name of file in which to look for parameters. |
required |
param_names
|
Union[list[str], str]
|
List of strings (or single string) describing parameter names.
Shares order with |
required |
param_values
|
Union[list[float], float]
|
List of parameter values (or single value) to be written.
Shares order with |
required |
Note
Finds first match in file, so put derived parameters at end of file.
Source code in matmdl/core/writer.py
write_params_to_file(param_values, param_names)
Appends last iteration params to file out_progress.txt.