-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65c2ee4
commit 4fbcd9d
Showing
2 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
sys.path.append('../..') | ||
|
||
import numpy as np | ||
import numpy.random as ra | ||
|
||
from neml.cp import polycrystal, crystallography, slipharden, sliprules, inelasticity, kinematics, singlecrystal, polefigures | ||
from neml.math import rotations, tensors, nemlmath | ||
from neml import elasticity, drivers | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
if __name__ == "__main__": | ||
nthreads = 32 | ||
ngrain = 500 | ||
|
||
# Let's pretend these are active convention | ||
orientations = rotations.random_orientations(ngrain) | ||
|
||
# For plotting get in the passive convention | ||
orientations_passive = [o.inverse() for o in orientations] | ||
|
||
# Setup the model with fairly arbitrary properties | ||
C11 = 287750.0 # MPa | ||
C12 = 127920.0 # MPa | ||
C44 = 120710.0 # MPa | ||
|
||
t0 = 50.0 | ||
ts = 40.0 | ||
b = 1.0 | ||
|
||
g0 = 1.0 | ||
n = 12.0 | ||
|
||
lattice = crystallography.CubicLattice(1.0) | ||
lattice.add_slip_system([1,1,0],[1,1,1]) | ||
|
||
strengthmodel = slipharden.VoceSlipHardening(ts, b, t0) | ||
slipmodel = sliprules.PowerLawSlipRule(strengthmodel, g0, n) | ||
imodel = inelasticity.AsaroInelasticity(slipmodel) | ||
emodel = elasticity.CubicLinearElasticModel(C11,C12,C44, "components") | ||
kmodel = kinematics.StandardKinematicModel(emodel, imodel) | ||
|
||
model = singlecrystal.SingleCrystalModel(kmodel, lattice) | ||
|
||
pmodel = polycrystal.TaylorModel(model, orientations, nthreads = nthreads) | ||
|
||
|
||
# Pass in passive convention, ugh, sorry | ||
polefigures.inverse_pole_figure_discrete(orientations_passive, [1,0,0], lattice, reduce_figure = "cubic", axis_labels = ["100", "110", "111"]) | ||
plt.show() | ||
|
||
# Strain rate and target strain for loading | ||
erate = 8.33e-5 | ||
emax = 0.01 | ||
nsteps = 50 | ||
|
||
res = drivers.uniaxial_test(pmodel, erate, emax = emax, nsteps = nsteps, | ||
full_results = True, verbose = True) | ||
|
||
internal_state = np.array(res['history']) | ||
|
||
# Final orientations, in the passive convention | ||
final_orientations = pmodel.orientations(internal_state[-1]) | ||
|
||
# Stress history for each crystal | ||
nhist = model.nstore | ||
stress = internal_state[:,pmodel.n*nhist:pmodel.n*nhist+6*pmodel.n:6] | ||
|
||
# Overall strain history | ||
strain = np.array(res['strain'])[:,0] | ||
|
||
# Overall stress | ||
stress_overall = np.array(res['stress'])[:,0] | ||
|
||
# Pass in passive convention, ugh, sorry | ||
polefigures.inverse_pole_figure_discrete(final_orientations, [1,0,0], lattice, reduce_figure = "cubic", axis_labels = ["100", "110", "111"], | ||
color = stress[-1]) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4fbcd9d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example doesn't seem to work on my end.
{
"name": "ValueError",
"message": "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()",
"stack": "---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File z:/M5Jobs/_neml/cp/tension_example_mark_original.py:66
63 stress_overall = np.array(res['stress'])[:,0]
65 # Pass in passive convention, ugh, sorry
---> 66 polefigures.inverse_pole_figure_discrete(final_orientations, [1,0,0], lattice, reduce_figure = "cubic", axis_labels = ["100", "110", "111"],
67 color = stress[-1])
68 plt.show()
File ~/Software/neml/neml/cp/polefigures.py:195, in inverse_pole_figure_discrete(orientations, direction, lattice, reduce_figure, color, sample_symmetry, x, y, axis_labels, nline)
193 if reduce_figure:
194 ax = plt.subplot(111)
--> 195 if color == "rgb":
196 rgb = ipf_color(pts, v0 = vs[0], v1 = vs[1], v2=vs[2])
197 ax.scatter(cpoints[:,0], cpoints[:,1], c=rgb, s = 10.0)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
}