25#include "neml2/models/crystallography/CrystalGeometry.h"
27#include "neml2/models/crystallography/crystallography.h"
28#include "neml2/tensors/tensors.h"
30using namespace torch::indexing;
34namespace crystallography
45 "A Data object storing basic crystallographic information for a given crystal system.";
48 options.
set(
"crystal_class").doc() =
"The set of symmetry operations defining the crystal class.";
51 options.
set(
"lattice_vectors").doc() =
52 "The three lattice vectors defining the crystal translational symmetry";
55 options.
set(
"slip_directions").doc() =
"A list of Miller indices defining the slip directions";
58 options.
set(
"slip_planes").doc() =
"A list of Miller indices defining the slip planes";
67 setup_schmid_tensors(options.get<
CrossRef<
Vec>>(
"lattice_vectors"),
90 return _lattice_vectors.batch_index({0});
96 return _lattice_vectors.batch_index({1});
102 return _lattice_vectors.batch_index({2});
108 return _reciprocal_lattice_vectors.batch_index({0});
114 return _reciprocal_lattice_vectors.batch_index({1});
120 return _reciprocal_lattice_vectors.batch_index({2});
126 return _slip_offsets.back();
132 return _slip_offsets.size() - 1;
139 return _slip_offsets[
i + 1] - _slip_offsets[
i];
149 _reciprocal_lattice_vectors(declare_buffer<
Vec>(
"reciprocal_lattice_vectors",
150 make_reciprocal_lattice(_lattice_vectors))),
151 _slip_directions(declare_buffer<
MillerIndex>(
"slip_directions",
"slip_directions")),
152 _slip_planes(declare_buffer<
MillerIndex>(
"slip_planes",
"slip_planes")),
153 _cartesian_slip_directions(
154 declare_buffer<
Vec>(
"cartesian_slip_directions", std::get<0>(
slip_data))),
155 _cartesian_slip_planes(declare_buffer<
Vec>(
"cartesian_slip_planes", std::get<1>(
slip_data))),
158 _A(declare_buffer<
R2>(
"schmid_tensors",
159 (_cartesian_slip_directions / _cartesian_slip_directions.norm())
160 .outer(_cartesian_slip_planes / _cartesian_slip_planes.norm()))),
161 _M(declare_buffer<
SR2>(
"symmetric_schmid_tensors",
SR2(_A))),
162 _W(declare_buffer<
WR2>(
"skew_symmetric_schmid_tensors",
WR2(_A)))
181CrystalGeometry::miller_to_cartesian(
const Vec & A,
const MillerIndex & d)
184 return R2(torch::Tensor(
A)) * d.reduce().to_vec();
187std::tuple<Vec, Vec, Scalar, std::vector<TorchSize>>
188CrystalGeometry::setup_schmid_tensors(
const Vec & A,
190 const MillerIndex & slip_directions,
191 const MillerIndex & slip_planes)
194 Vec B = make_reciprocal_lattice(
A);
197 if (slip_directions.batch_sizes() != slip_planes.batch_sizes())
198 neml_assert(
"Input slip directions and planes must have the same batch sizes");
200 auto bshape = slip_planes.batch_sizes();
201 auto nbatch = slip_planes.batch_dim();
206 std::vector<torch::Tensor> burgers_vectors;
207 std::vector<TorchSize> offsets = {0};
209 for (
TorchSize i = 0; i < bshape[nbatch - 1]; i++)
212 auto cmd = slip_directions.batch_index({torch::indexing::Ellipsis, i});
213 auto cmp = slip_planes.batch_index({torch::indexing::Ellipsis, i});
223 for (
TorchSize j = 0; j < direction_options.batch_sizes()[direction_options.batch_dim() - 1];
226 auto di = direction_options.batch_index({torch::indexing::Ellipsis, j});
227 auto dps = plane_options.dot(di);
229 torch::where(torch::isclose(torch::abs(dps), torch::tensor(0.0, dps.dtype()))).front();
231 for (
TorchSize kk = 0; kk < inds.sizes()[0]; kk++)
233 TorchSize k = inds.index({kk}).item<TorchSize>();
234 auto pi = plane_options.batch_index({torch::indexing::Ellipsis, k});
237 burgers_vectors.push_back(di.norm());
241 offsets.push_back(last);
246 Scalar(torch::stack(burgers_vectors)),
Derived batch_index(TorchSlice indices) const
Get a batch.
Definition BatchTensorBase.cxx:184
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
static OptionSet expected_options()
Definition Data.cxx:30
Represention of a crystal direction or plane a Miller Index.
Definition MillerIndex.h:38
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:91
T & set(const std::string &)
Definition OptionSet.h:436
A basic R2.
Definition R2.h:42
The (logical) symmetric second order tensor.
Definition SR2.h:46
The (logical) scalar.
Definition Scalar.h:38
Derived cross(const VecBase< Derived2 > &v) const
cross product
Definition VecBase.h:106
Scalar dot(const VecBase< Derived2 > &v) const
dot product
Definition VecBase.h:96
The (logical) vector.
Definition Vec.h:42
A skew rank 2, represented as an axial vector.
Definition WR2.h:43
Defines the geometry of a crystal system This includes a basic definition of the crystal lattice,...
Definition CrystalGeometry.h:48
Vec b3() const
accessor for the third reciprocal lattice vector
Definition CrystalGeometry.cxx:118
const R2 & A() const
Accessor for the full Schmid tensors.
Definition CrystalGeometry.h:88
const Vec & cartesian_slip_directions() const
Accessor for the slip directions.
Definition CrystalGeometry.h:81
Vec a1() const
accessor for the first lattice vector
Definition CrystalGeometry.cxx:88
const Vec & cartesian_slip_planes() const
Accessor for the slip planes.
Definition CrystalGeometry.h:83
CrystalGeometry(const OptionSet &options)
Setup from parameter set.
Definition CrystalGeometry.cxx:63
Vec a3() const
accessor for the third lattice vector
Definition CrystalGeometry.cxx:100
Vec b2() const
accessor for the second reciprocal lattice vector
Definition CrystalGeometry.cxx:112
TorchSize nslip_groups() const
Number of slip groups.
Definition CrystalGeometry.cxx:130
TorchSize nslip() const
Total number of slip systems.
Definition CrystalGeometry.cxx:124
static OptionSet expected_options()
Input options.
Definition CrystalGeometry.cxx:40
Vec a2() const
accessor for the second lattice vector
Definition CrystalGeometry.cxx:94
Vec b1() const
accessor for the first reciprocal lattice vector
Definition CrystalGeometry.cxx:106
TorchSize nslip_in_group(TorchSize i) const
Number of slip systems in a given group.
Definition CrystalGeometry.cxx:136
Vec unique_bidirectional(const R2 &ops, const Vec &inp)
Helper to return all symmetrically-equivalent directions from a cartesian vector.
Definition crystallography.cxx:147
Definition CrossRef.cxx:32
void neml_assert_dbg(bool assertion, Args &&... args)
Definition error.h:85
int64_t TorchSize
Definition types.h:35
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73