@@ -340,6 +340,26 @@ Position RectLattice::get_local_position(
340340
341341// ==============================================================================
342342
343+ Direction RectLattice::get_normal (
344+ const array<int , 3 >& i_xyz, bool & is_valid) const
345+ {
346+ is_valid = false ;
347+ Direction dir = {0.0 , 0.0 , 0.0 };
348+ if ((std::abs (i_xyz[0 ]) == 1 ) && (i_xyz[1 ] == 0 ) && (i_xyz[2 ] == 0 )) {
349+ is_valid = true ;
350+ dir[0 ] = std::copysign (1.0 , i_xyz[0 ]);
351+ } else if ((i_xyz[0 ] == 0 ) && (std::abs (i_xyz[1 ]) == 1 ) && (i_xyz[2 ] == 0 )) {
352+ is_valid = true ;
353+ dir[1 ] = std::copysign (1.0 , i_xyz[1 ]);
354+ } else if ((i_xyz[0 ] == 0 ) && (i_xyz[1 ] == 0 ) && (std::abs (i_xyz[2 ]) == 1 )) {
355+ is_valid = true ;
356+ dir[2 ] = std::copysign (1.0 , i_xyz[2 ]);
357+ }
358+ return dir;
359+ }
360+
361+ // ==============================================================================
362+
343363int32_t & RectLattice::offset (int map, const array<int , 3 >& i_xyz)
344364{
345365 return offsets_[n_cells_[0 ] * n_cells_[1 ] * n_cells_[2 ] * map +
@@ -986,6 +1006,91 @@ Position HexLattice::get_local_position(
9861006
9871007// ==============================================================================
9881008
1009+ Direction HexLattice::get_normal (
1010+ const array<int , 3 >& i_xyz, bool & is_valid) const
1011+ {
1012+ // Short description of the direction vectors used here. The beta, gamma, and
1013+ // delta vectors point towards the flat sides of each hexagonal tile.
1014+ // Y - orientation:
1015+ // basis0 = (1, 0)
1016+ // basis1 = (-1/sqrt(3), 1) = +120 degrees from basis0
1017+ // beta = (sqrt(3)/2, 1/2) = +30 degrees from basis0
1018+ // gamma = (sqrt(3)/2, -1/2) = -60 degrees from beta
1019+ // delta = (0, 1) = +60 degrees from beta
1020+ // X - orientation:
1021+ // basis0 = (1/sqrt(3), -1)
1022+ // basis1 = (0, 1) = +120 degrees from basis0
1023+ // beta = (1, 0) = +30 degrees from basis0
1024+ // gamma = (1/2, -sqrt(3)/2) = -60 degrees from beta
1025+ // delta = (1/2, sqrt(3)/2) = +60 degrees from beta
1026+
1027+ is_valid = false ;
1028+ Direction dir = {0.0 , 0.0 , 0.0 };
1029+ if ((i_xyz[0 ] == 0 ) && (i_xyz[1 ] == 0 ) && (std::abs (i_xyz[2 ]) == 1 )) {
1030+ is_valid = true ;
1031+ dir[2 ] = std::copysign (1.0 , i_xyz[2 ]);
1032+ } else if ((i_xyz[2 ] == 0 ) &&
1033+ std::max ({std::abs (i_xyz[0 ]), std::abs (i_xyz[1 ]),
1034+ std::abs (i_xyz[0 ] + i_xyz[1 ])}) == 1 ) {
1035+ is_valid = true ;
1036+ // beta direction
1037+ if ((i_xyz[0 ] == 1 ) && (i_xyz[1 ] == 0 )) {
1038+ if (orientation_ == Orientation::y) {
1039+ dir[0 ] = 0.5 * std::sqrt (3.0 );
1040+ dir[1 ] = 0.5 ;
1041+ } else {
1042+ dir[0 ] = 1.0 ;
1043+ dir[1 ] = 0.0 ;
1044+ }
1045+ } else if ((i_xyz[0 ] == -1 ) && (i_xyz[1 ] == 0 )) {
1046+ if (orientation_ == Orientation::y) {
1047+ dir[0 ] = -0.5 * std::sqrt (3.0 );
1048+ dir[1 ] = -0.5 ;
1049+ } else {
1050+ dir[0 ] = -1.0 ;
1051+ dir[1 ] = 0.0 ;
1052+ }
1053+ // gamma direction
1054+ } else if ((i_xyz[0 ] == 1 ) && (i_xyz[1 ] == -1 )) {
1055+ if (orientation_ == Orientation::y) {
1056+ dir[0 ] = 0.5 * std::sqrt (3.0 );
1057+ dir[1 ] = -0.5 ;
1058+ } else {
1059+ dir[0 ] = 0.5 ;
1060+ dir[1 ] = -0.5 * std::sqrt (3.0 );
1061+ }
1062+ } else if ((i_xyz[0 ] == -1 ) && (i_xyz[1 ] == 1 )) {
1063+ if (orientation_ == Orientation::y) {
1064+ dir[0 ] = -0.5 * std::sqrt (3.0 );
1065+ dir[1 ] = 0.5 ;
1066+ } else {
1067+ dir[0 ] = -0.5 ;
1068+ dir[1 ] = 0.5 * std::sqrt (3.0 );
1069+ }
1070+ // delta direction
1071+ } else if ((i_xyz[0 ] == 0 ) && (i_xyz[1 ] == 1 )) {
1072+ if (orientation_ == Orientation::y) {
1073+ dir[0 ] = 0.0 ;
1074+ dir[1 ] = 1.0 ;
1075+ } else {
1076+ dir[0 ] = 0.5 ;
1077+ dir[1 ] = 0.5 * std::sqrt (3.0 );
1078+ }
1079+ } else if ((i_xyz[0 ] == 0 ) && (i_xyz[1 ] == -1 )) {
1080+ if (orientation_ == Orientation::y) {
1081+ dir[0 ] = 0.0 ;
1082+ dir[1 ] = -1.0 ;
1083+ } else {
1084+ dir[0 ] = -0.5 ;
1085+ dir[1 ] = -0.5 * std::sqrt (3.0 );
1086+ }
1087+ }
1088+ }
1089+ return dir;
1090+ }
1091+
1092+ // ==============================================================================
1093+
9891094bool HexLattice::is_valid_index (int indx) const
9901095{
9911096 int nx {2 * n_rings_ - 1 };
0 commit comments