| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "mesh.hpp" | |||
| 2 | #include "geometry.hpp" | |||
| 3 | #include "trajectory.hpp" | |||
| 4 | #include "region.hpp" | |||
| 5 | #include "system.hpp" | |||
| 6 | #include "mt_tip.hpp" | |||
| 7 | #include "parameters.hpp" | |||
| 8 | #include "linalg.hpp" | |||
| 9 | ||||
| 10 | ✗ | void Geometry::call_translator(SurfaceVector& s_vec, int region_index, int region_index_neigh) | ||
| 11 | { | |||
| 12 | ✗ | int index1(regions[region_index]->side_rev_map[region_index_neigh]); | ||
| 13 | ||||
| 14 | // use affine transformation of triangle to map a point from one region to other region | |||
| 15 | Eigen::Vector2d v1(s_vec.x, s_vec.y), v2; | |||
| 16 | ✗ | v2 = regions[region_index]->side[index1].a * v1 + regions[region_index]->side[index1].b; | ||
| 17 | ✗ | s_vec.x = v2(0, 0); | ||
| 18 | ✗ | s_vec.y = v2(1, 0); | ||
| 19 | ||||
| 20 | ✗ | s_vec.angle += regions[region_index]->side[index1].xy_rotation_angle; | ||
| 21 | ||||
| 22 | ✗ | return; | ||
| 23 | } | |||
| 24 | ||||
| 25 | ✗ | TrajectoryVector Geometry::create_trajectory(const SurfaceVector& s_vec) | ||
| 26 | { | |||
| 27 | // create a new trajectory with give trajectory vector | |||
| 28 | ✗ | return s_vec.region->insert_trajectory(s_vec); | ||
| 29 | } | |||
| 30 | ||||
| 31 | ✗ | TrajectoryVector Geometry::create_and_link_trajectory( | ||
| 32 | const SurfaceVector& new_base, Trajectory* oldtr, Direction olddir, double cos_angle, double p_cat) | |||
| 33 | { | |||
| 34 | // first create a new trajectory vector (trajectory) | |||
| 35 | ✗ | TrajectoryVector t_vec = create_trajectory(new_base); | ||
| 36 | ||||
| 37 | // declare a dummy trajectory vector | |||
| 38 | TrajectoryVector this_vec; | |||
| 39 | ||||
| 40 | // copy old trajectory vector | |||
| 41 | this_vec.trajectory = oldtr; | |||
| 42 | ||||
| 43 | // old trajectory vector has direction forward, set the new trajectory vector as next | |||
| 44 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (olddir == Direction::FORWARD) | |
| 45 | { | |||
| 46 | ✗ | oldtr->next_tr = t_vec; | ||
| 47 | ✗ | oldtr->next_tr_cos_angle = cos_angle; | ||
| 48 | ✗ | oldtr->next_trp_cat = p_cat; | ||
| 49 | ||||
| 50 | // get the direction and position of the dummy trajectory vector | |||
| 51 | this_vec.dir = Direction::BACKWARD; | |||
| 52 | ✗ | this_vec.pos = oldtr->length; | ||
| 53 | } | |||
| 54 | ||||
| 55 | // old trajectory vector has direction backward, set the new trajectory vector as previous | |||
| 56 | else | |||
| 57 | { | |||
| 58 | ✗ | oldtr->prev_tr = t_vec; | ||
| 59 | ✗ | oldtr->prev_tr_cos_angle = cos_angle; | ||
| 60 | ✗ | oldtr->prev_trp_cat = p_cat; | ||
| 61 | ||||
| 62 | // get the direction and position of the dummy trajectory vector | |||
| 63 | this_vec.dir = Direction::FORWARD; | |||
| 64 | this_vec.pos = 0; | |||
| 65 | } | |||
| 66 | ||||
| 67 | // new trajectory vector has direction forward, set the dummy trajectory vector as previous | |||
| 68 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (t_vec.dir == Direction::FORWARD) | |
| 69 | { | |||
| 70 | ✗ | t_vec.trajectory->prev_tr = this_vec; | ||
| 71 | ✗ | t_vec.trajectory->prev_tr_cos_angle = cos_angle; | ||
| 72 | ✗ | t_vec.trajectory->prev_trp_cat = p_cat; | ||
| 73 | } | |||
| 74 | ||||
| 75 | // new trajectory vector has direction backward, set the dummy trajectory vector as next | |||
| 76 | else | |||
| 77 | { | |||
| 78 | ✗ | t_vec.trajectory->next_tr = this_vec; | ||
| 79 | ✗ | t_vec.trajectory->next_tr_cos_angle = cos_angle; | ||
| 80 | ✗ | t_vec.trajectory->next_trp_cat = p_cat; | ||
| 81 | } | |||
| 82 | ||||
| 83 | ✗ | return t_vec; | ||
| 84 | } | |||
| 85 | ||||
| 86 | ✗ | SurfaceVector Geometry::random_surface_vector() | ||
| 87 | { | |||
| 88 | int region_selector{ 0 }; | |||
| 89 | double r_area{ 0.0 }; | |||
| 90 | int domain_type{ 0 }; | |||
| 91 | ||||
| 92 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (regions.size() > 1) | |
| 93 | { | |||
| 94 | // nucleation on PPB | |||
| 95 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (system->p.pp_bk_nuc_fraction > 0) | |
| 96 | { | |||
| 97 | ✗ | double rand_gen = system->random_gen.rand(); | ||
| 98 | ✗ | domain_type = (rand_gen < system->p.pp_bk_nuc_fraction) ? 1 : 2; | ||
| 99 | } | |||
| 100 | ||||
| 101 | // nucleation outside PPB | |||
| 102 | else | |||
| 103 | { | |||
| 104 | domain_type = 0; | |||
| 105 | } | |||
| 106 | ||||
| 107 | // select a region | |||
| 108 | ✗ | r_area = system->random_gen.rand_dbl_exc(patch_area[domain_type]); | ||
| 109 | ||||
| 110 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (r_area < 0.5 * patch_area[domain_type]) | |
| 111 | { | |||
| 112 | region_selector = 0; | |||
| 113 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (r_area > regions[regions_index[domain_type][region_selector]]->area) | |
| 114 | { | |||
| 115 | ✗ | r_area -= regions[regions_index[domain_type][region_selector++]]->area; | ||
| 116 | ||||
| 117 | #ifdef DBG_ACID_TEST | |||
| 118 | if (regionSelector == regions.size()) | |||
| 119 | { | |||
| 120 | cerr << "DBG/ASSERT: ERROR: Ran out of surfaces for random surface vector creation.\n"; | |||
| 121 | exit(-1); | |||
| 122 | } | |||
| 123 | #endif | |||
| 124 | } | |||
| 125 | } | |||
| 126 | ||||
| 127 | else | |||
| 128 | { | |||
| 129 | ✗ | region_selector = regions_index[domain_type].size() - 1; | ||
| 130 | ✗ | r_area = patch_area[domain_type] - r_area; | ||
| 131 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (r_area > regions[regions_index[domain_type][region_selector]]->area) | |
| 132 | { | |||
| 133 | ✗ | r_area -= regions[regions_index[domain_type][region_selector--]]->area; | ||
| 134 | ||||
| 135 | #ifdef DBG_ACID_TEST | |||
| 136 | if (regionSelector == -1) | |||
| 137 | { | |||
| 138 | cerr << "DBG/ASSERT: ERROR: Ran out of surfaces for random surface vector creation.\n"; | |||
| 139 | exit(-1); | |||
| 140 | } | |||
| 141 | #endif | |||
| 142 | } | |||
| 143 | } | |||
| 144 | } | |||
| 145 | ||||
| 146 | ✗ | return regions[regions_index[domain_type][region_selector]]->random_surface_vector(); | ||
| 147 | } | |||
| 148 | ||||
| 149 | ✗ | bool Geometry::integrity_check() | ||
| 150 | { | |||
| 151 | bool valid(true); | |||
| 152 | int plus_grow_count(0); | |||
| 153 | int plus_shrink_count(0); | |||
| 154 | int minus_count(0); | |||
| 155 | Trajectory* tptr(nullptr); | |||
| 156 | ||||
| 157 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (size_t ridx = 0; ridx < regions.size(); ridx++) | |
| 158 | { | |||
| 159 | ✗ | plus_grow_count += regions[ridx]->growing_plus_tip_list.size(); | ||
| 160 | ✗ | plus_shrink_count += regions[ridx]->shrinking_plus_tip_list.size(); | ||
| 161 | ✗ | minus_count += regions[ridx]->minus_tip_list.size(); | ||
| 162 | tptr = regions[ridx]->trajectories.first(); | |||
| 163 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (tptr != nullptr) | |
| 164 | { | |||
| 165 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (!tptr->integrity_check()) | |
| 166 | { | |||
| 167 | valid = false; | |||
| 168 | } | |||
| 169 | ||||
| 170 | tptr = tptr->next(); | |||
| 171 | } | |||
| 172 | } | |||
| 173 | ||||
| 174 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (minus_count != plus_grow_count + plus_shrink_count) | |
| 175 | { | |||
| 176 | ✗ | std::cerr << "Integrity check failed: unequal number of plus and minus ends registered on regions\n"; | ||
| 177 | valid = false; | |||
| 178 | } | |||
| 179 | ||||
| 180 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (plus_grow_count != system->growing_mts.size()) | |
| 181 | { | |||
| 182 | std::cerr << "Integrity check failed: number of registered growing tips does not equal the number of growing " | |||
| 183 | ✗ | "microtubules.\n"; | ||
| 184 | valid = false; | |||
| 185 | } | |||
| 186 | ||||
| 187 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (plus_shrink_count != system->shrinking_mts.size()) | |
| 188 | { | |||
| 189 | std::cerr | |||
| 190 | << "Integrity check failed: number of registered shrinking tips does not equal the number of shrinking " | |||
| 191 | ✗ | "microtubules.\n"; | ||
| 192 | valid = false; | |||
| 193 | } | |||
| 194 | ||||
| 195 | int total_plus_grow_count(0); | |||
| 196 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (int d_tag = 0; d_tag <= system->p.face_number; d_tag++) | |
| 197 | { | |||
| 198 | ✗ | total_plus_grow_count += system->growing_tips_reg[d_tag]; | ||
| 199 | } | |||
| 200 | ||||
| 201 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (plus_grow_count != total_plus_grow_count) | |
| 202 | { | |||
| 203 | ✗ | std::cerr << "Integrity check failed: number of growing tips does not equal cached values\n"; | ||
| 204 | valid = false; | |||
| 205 | } | |||
| 206 | ||||
| 207 | ✗ | return valid; | ||
| 208 | } | |||
| 209 | ||||
| 210 | ✗ | double Geometry::optical_length() | ||
| 211 | { | |||
| 212 | double sum(0.0); | |||
| 213 | ||||
| 214 | // calculate total optical length present in the geometry | |||
| 215 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (size_t ridx = 0; ridx < regions.size(); ridx++) | |
| 216 | { | |||
| 217 | ✗ | sum += regions[ridx]->optical_length(); | ||
| 218 | } | |||
| 219 | ✗ | return sum; | ||
| 220 | } | |||
| 221 | ||||
| 222 | ✗ | int Geometry::trajectory_count() | ||
| 223 | { | |||
| 224 | int sum(0); | |||
| 225 | ||||
| 226 | // calculate total number of trajectory present in the geometry | |||
| 227 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (size_t ridx = 0; ridx < regions.size(); ridx++) | |
| 228 | { | |||
| 229 | ✗ | sum += regions[ridx]->trajectories.size(); | ||
| 230 | } | |||
| 231 | ||||
| 232 | ✗ | return sum; | ||
| 233 | } | |||
| 234 | ||||
| 235 | ✗ | TriMeshGeometry::TriMeshGeometry(System* s): | ||
| 236 | ✗ | Geometry(s, 0.0) | ||
| 237 | { | |||
| 238 | // loading a triangle mesh | |||
| 239 | ✗ | pickup_shape(this); | ||
| 240 | ||||
| 241 | ✗ | return; | ||
| 242 | ✗ | } | ||
| 243 | ||||
| 244 | ✗ | void TriMeshGeometry::get_order_parameters(OrderParameters& op) | ||
| 245 | { | |||
| 246 | ✗ | OrderParametersRaw op_raw; | ||
| 247 | ||||
| 248 | // calculate order parameter components | |||
| 249 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (int eno = 0; eno < element_max; eno++) | |
| 250 | { | |||
| 251 | ✗ | static_cast<Cartesian*>(regions[eno]) | ||
| 252 | ✗ | ->get_order_parameters_raw_flat(op_raw, regions[eno]->orientation, regions[eno]->area); | ||
| 253 | ||||
| 254 | // store local scalar order parameter | |||
| 255 | ✗ | op.local_order.push_back(op_raw.local_order); | ||
| 256 | ✗ | op.sv.push_back(op_raw.sv); | ||
| 257 | } | |||
| 258 | ||||
| 259 | // normalizing the order parameter components | |||
| 260 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (op_raw.local_l > ZERO_CUTOFF) | |
| 261 | { | |||
| 262 | ✗ | op_raw.qxx /= op_raw.local_l; | ||
| 263 | ✗ | op_raw.qxy /= op_raw.local_l; | ||
| 264 | ✗ | op_raw.qxz /= op_raw.local_l; | ||
| 265 | ✗ | op_raw.qyy /= op_raw.local_l; | ||
| 266 | ✗ | op_raw.qyz /= op_raw.local_l; | ||
| 267 | ✗ | op_raw.qzz /= op_raw.local_l; | ||
| 268 | } | |||
| 269 | ||||
| 270 | /// calculate Q(2) tensor order parameter | |||
| 271 | ✗ | op.r = op_raw.extract_r(op.rdirector, system->p.geometry); | ||
| 272 | ||||
| 273 | // normalize the order parameter director | |||
| 274 | Eigen::Vector3d rvec(op.rdirector[0], op.rdirector[1], op.rdirector[2]); | |||
| 275 | ✗ | rvec /= rvec.norm(); | ||
| 276 | ||||
| 277 | ✗ | op.rdirector[0] = rvec(0, 0); | ||
| 278 | ✗ | op.rdirector[1] = rvec(1, 0); | ||
| 279 | ✗ | op.rdirector[2] = rvec(2, 0); | ||
| 280 | ||||
| 281 | ✗ | op.c = std::fabs(op.rdirector[2]) | ||
| 282 | ✗ | - 0.5 * std::sqrt(op.rdirector[0] * op.rdirector[0] + op.rdirector[1] * op.rdirector[1]); | ||
| 283 | ||||
| 284 | ✗ | return; | ||
| 285 | } | |||
| 286 | ||||
| 287 | ✗ | void TriMeshGeometry::output_snapshot(std::ostream& out) | ||
| 288 | { | |||
| 289 | // output the simulation results | |||
| 290 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (int eno = 0; eno < element_max; eno++) | |
| 291 | { | |||
| 292 | ✗ | regions[eno]->output_snapshot(out); | ||
| 293 | } | |||
| 294 | ||||
| 295 | out << std::endl; | |||
| 296 | ||||
| 297 | ✗ | return; | ||
| 298 | } | |||
| 299 | ||||
| 300 | ✗ | void TriMeshGeometry::output_order_heat_map(std::ostream& out, | ||
| 301 | std::vector<double>& local_order, | |||
| 302 | std::vector<Eigen::Vector3d>& sv) | |||
| 303 | { | |||
| 304 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (size_t eno = 0; eno < local_order.size(); eno++) | |
| 305 | { | |||
| 306 | Eigen::Vector3d seg_3d; | |||
| 307 | ||||
| 308 | // Incircle radius of the triangle | |||
| 309 | ✗ | double sv_length = (2.0 * regions[eno]->area * regions[eno]->area) / regions[eno]->peri_meter; | ||
| 310 | ||||
| 311 | // get the region 3D rotation axis | |||
| 312 | Eigen::Vector3d cross(regions[eno]->q.x(), regions[eno]->q.y(), regions[eno]->q.z()); | |||
| 313 | double cross_magnitude = cross.norm(); | |||
| 314 | ||||
| 315 | Eigen::Quaternion<double> qr_1(0.0, 0.0, 0.0, 0.0), qr_2(0.0, 0.0, 0.0, 0.0); | |||
| 316 | ||||
| 317 | // region (and hence all the sgments in this region) need 3D rotation + translation | |||
| 318 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (cross_magnitude > 0.0) | |
| 319 | { | |||
| 320 | // translate and rotate the start point of the segment | |||
| 321 | qr_2.w() = 0; | |||
| 322 | ✗ | qr_2.x() = -1.0 * sv_length * sv[eno](0, 0) + regions[eno]->mid_point(0, 0); | ||
| 323 | ✗ | qr_2.y() = -1.0 * sv_length * sv[eno](1, 0) + regions[eno]->mid_point(1, 0); | ||
| 324 | ✗ | qr_2.z() = -1.0 * sv_length * sv[eno](2, 0) + regions[eno]->z_offset; | ||
| 325 | ||||
| 326 | ✗ | qr_1 = regions[eno]->q.inverse() * qr_2 * regions[eno]->q; | ||
| 327 | ✗ | seg_3d << qr_1.x(), qr_1.y(), qr_1.z(); | ||
| 328 | seg_3d += object_cm; | |||
| 329 | ||||
| 330 | ✗ | out << seg_3d(0, 0) << "," << seg_3d(1, 0) << "," << seg_3d(2, 0) << ","; | ||
| 331 | ||||
| 332 | // translate and rotate the end point of the segment | |||
| 333 | qr_2.w() = 0; | |||
| 334 | ✗ | qr_2.x() = sv_length * sv[eno](0, 0) + regions[eno]->mid_point(0, 0); | ||
| 335 | ✗ | qr_2.y() = sv_length * sv[eno](1, 0) + regions[eno]->mid_point(1, 0); | ||
| 336 | ✗ | qr_2.z() = sv_length * sv[eno](2, 0) + regions[eno]->z_offset; | ||
| 337 | ||||
| 338 | ✗ | qr_1 = regions[eno]->q.inverse() * qr_2 * regions[eno]->q; | ||
| 339 | ✗ | seg_3d << qr_1.x(), qr_1.y(), qr_1.z(); | ||
| 340 | seg_3d += object_cm; | |||
| 341 | ||||
| 342 | ✗ | out << seg_3d(0, 0) << "," << seg_3d(1, 0) << "," << seg_3d(2, 0) << "," << regions[eno]->region_id << "@"; | ||
| 343 | } | |||
| 344 | ||||
| 345 | // need no rotation of the region (and hence all the sgments in this region) | |||
| 346 | else | |||
| 347 | { | |||
| 348 | // translate the start point of the segment | |||
| 349 | ✗ | seg_3d << -1.0 * sv_length * sv[eno](0, 0) + regions[eno]->mid_point(0, 0), | ||
| 350 | ✗ | -1.0 * sv_length * sv[eno](1, 0) + regions[eno]->mid_point(1, 0), | ||
| 351 | ✗ | -1.0 * sv_length * sv[eno](2, 0) + regions[eno]->z_offset; | ||
| 352 | seg_3d += object_cm; | |||
| 353 | ✗ | out << seg_3d(0, 0) << "," << seg_3d(1, 0) << "," << seg_3d(2, 0) << ","; | ||
| 354 | ||||
| 355 | // translate the end point of the segment | |||
| 356 | ✗ | seg_3d << sv_length * sv[eno](0, 0) + regions[eno]->mid_point(0, 0), | ||
| 357 | ✗ | sv_length * sv[eno](1, 0) + regions[eno]->mid_point(1, 0), | ||
| 358 | ✗ | -1.0 * sv_length * sv[eno](2, 0) + regions[eno]->z_offset; | ||
| 359 | seg_3d += object_cm; | |||
| 360 | ✗ | out << seg_3d(0, 0) << "," << seg_3d(1, 0) << "," << seg_3d(2, 0) << "," << regions[eno]->region_id << "@"; | ||
| 361 | } | |||
| 362 | } | |||
| 363 | ||||
| 364 | out << std::endl; | |||
| 365 | ||||
| 366 | ✗ | return; | ||
| 367 | } | |||
| 368 | ||||
| 369 | ✗ | TrajectoryVector TriMeshGeometry::extend_trajectory(Trajectory* oldtr, Direction dir) | ||
| 370 | { | |||
| 371 | #ifdef DBG_GEOMETRY | |||
| 372 | cout << "DBG/GEOMETRY: Triangle::extend_trajectory() called\n"; | |||
| 373 | #endif | |||
| 374 | ||||
| 375 | // trajectory-director | |||
| 376 | Eigen::Vector2d t_director(0.0, 0.0); | |||
| 377 | ||||
| 378 | ✗ | SurfaceVector new_base(oldtr->base); | ||
| 379 | ||||
| 380 | // get copy of old trajectory region index | |||
| 381 | ✗ | int region_index(oldtr->base.region->region_id), region_index_neigh(0); | ||
| 382 | ||||
| 383 | // forward direction: move to the end of the trajectory | |||
| 384 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (dir == Direction::FORWARD) | |
| 385 | { | |||
| 386 | ✗ | new_base.x = oldtr->end_point[1].x; | ||
| 387 | ✗ | new_base.y = oldtr->end_point[1].y; | ||
| 388 | ||||
| 389 | // unit vector along the direction of old trajectory | |||
| 390 | ✗ | double t_dx = oldtr->end_point[1].x - oldtr->end_point[0].x; | ||
| 391 | ✗ | double t_dy = oldtr->end_point[1].y - oldtr->end_point[0].y; | ||
| 392 | ✗ | t_director << t_dx / oldtr->length, t_dy / oldtr->length; | ||
| 393 | ||||
| 394 | // get the neighbouring region index | |||
| 395 | ✗ | region_index_neigh = oldtr->end_point[1].next_element; | ||
| 396 | } | |||
| 397 | ||||
| 398 | // backward direction: stay at the start of the trajectory | |||
| 399 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (dir == Direction::BACKWARD) | |
| 400 | { | |||
| 401 | // unit vector along the direction of old trajectory | |||
| 402 | ✗ | double t_dx = oldtr->end_point[0].x - oldtr->end_point[1].x; | ||
| 403 | ✗ | double t_dy = oldtr->end_point[0].y - oldtr->end_point[1].y; | ||
| 404 | ✗ | t_director << t_dx / oldtr->length, t_dy / oldtr->length; | ||
| 405 | ||||
| 406 | // get the neighbouring region index | |||
| 407 | ✗ | region_index_neigh = oldtr->end_point[0].next_element; | ||
| 408 | ||||
| 409 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (new_base.angle >= PI) | |
| 410 | { | |||
| 411 | ✗ | new_base.angle -= PI; | ||
| 412 | } | |||
| 413 | else | |||
| 414 | { | |||
| 415 | ✗ | new_base.angle += PI; | ||
| 416 | } | |||
| 417 | } | |||
| 418 | ||||
| 419 | // get base coordinates for a fresh trajectory (to be created) | |||
| 420 | ✗ | call_translator(new_base, region_index, region_index_neigh); | ||
| 421 | ||||
| 422 | // get the new region for the fresh trajectory (to be created) | |||
| 423 | ✗ | new_base.region = regions[region_index_neigh]; | ||
| 424 | ||||
| 425 | double cos_edge_angle(1.0), p_cat_reg(0.0); | |||
| 426 | ✗ | int s(oldtr->base.region->side_rev_map[region_index_neigh]); | ||
| 427 | ||||
| 428 | // cos-angle: between (encountered) triangle-edge and the trajectory-director | |||
| 429 | ✗ | double cos_bending_angle(t_director.dot(oldtr->base.region->side[s].dir_2d)); | ||
| 430 | ||||
| 431 | // assign square of the cos-angle for this (encountered) triangle edge | |||
| 432 | ✗ | cos_edge_angle = cos_bending_angle * cos_bending_angle; | ||
| 433 | ||||
| 434 | // assign pCatReg for this for this (encountered) triangle edge | |||
| 435 | ✗ | p_cat_reg = oldtr->base.region->side[s].p_cat; | ||
| 436 | ||||
| 437 | // final correction to newBase angle -> [0 ... 2*PI] | |||
| 438 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (new_base.angle >= 2 * PI) | |
| 439 | { | |||
| 440 | ✗ | new_base.angle -= 2 * PI; | ||
| 441 | } | |||
| 442 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | else if (new_base.angle < 0) | |
| 443 | { | |||
| 444 | ✗ | new_base.angle += 2 * PI; | ||
| 445 | } | |||
| 446 | ||||
| 447 | #ifdef DBG_GEOMETRY | |||
| 448 | cout << RegionTypeText[oldtr->base.region->type] << " to " << RegionTypeText[newBase.region->type] << "\n"; | |||
| 449 | #endif | |||
| 450 | ||||
| 451 | // create a fresh trajectory | |||
| 452 | ✗ | return create_and_link_trajectory(new_base, oldtr, dir, cos_edge_angle, p_cat_reg); | ||
| 453 | } | |||
| 454 | ||||
| 455 | ✗ | Cartesian::Cartesian(Geometry* g, double a): | ||
| 456 | ✗ | Region(g, a) | ||
| 457 | { | |||
| 458 | // necessary to use many of its member functions | |||
| 459 | ✗ | return; | ||
| 460 | } | |||
| 461 | ||||
| 462 | ✗ | double Cartesian::intersection_angle(Trajectory* t1, Trajectory* t2) | ||
| 463 | { | |||
| 464 | #ifdef DBG_ACID_TEST | |||
| 465 | if ((t2->base.angle < 0) || (t2->base.angle > 2 * PI)) | |||
| 466 | { | |||
| 467 | std::cerr << "ERROR: angle out of bounds: " << t2->base.angle | |||
| 468 | << ", region=" << RegionTypeText[t2->base.region->type] << "\n"; | |||
| 469 | } | |||
| 470 | if ((t1->base.angle < 0) || (t1->base.angle > 2 * PI)) | |||
| 471 | { | |||
| 472 | std::cerr << "ERROR: angle out of bounds: " << t1->base.angle | |||
| 473 | << ", region=" << RegionTypeText[t1->base.region->type] << "\n"; | |||
| 474 | } | |||
| 475 | #endif | |||
| 476 | ||||
| 477 | // calculate collision angle between two interacting trajectories | |||
| 478 | ✗ | double angle(t2->base.angle - t1->base.angle); | ||
| 479 | ||||
| 480 | // angle is now in the interval -2PI..2PI | |||
| 481 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (angle < 0) | |
| 482 | { | |||
| 483 | ✗ | angle += 2 * PI; // to 0..2PI | ||
| 484 | } | |||
| 485 | ||||
| 486 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (angle > PI) | |
| 487 | { | |||
| 488 | ✗ | angle = 2 * PI - angle; | ||
| 489 | } | |||
| 490 | ||||
| 491 | ✗ | return (angle); | ||
| 492 | } | |||
| 493 | ||||
| 494 | ✗ | void Cartesian::get_order_parameters_raw_flat(OrderParametersRaw& op_r, | ||
| 495 | std::vector<Eigen::Vector3d>& orientation, | |||
| 496 | double area) | |||
| 497 | { | |||
| 498 | double sin2(0.0), cos2(0.0); | |||
| 499 | Eigen::Vector3d sv(0.0, 0.0, 0.0); | |||
| 500 | double angle(0.0), length(0.0), local_length(0.); | |||
| 501 | ✗ | double qxx(0.0), qxy(0.0), qxz(0.0), qyy(0.0), qyz(0.0), qzz(0.0); | ||
| 502 | double u1(0.0), u2(0.0), u3(0.0), order_local(0.0); | |||
| 503 | ✗ | Eigen::MatrixXd qf(3, 3), qc(3, 3), e(3, 3), o_l(2, 2); | ||
| 504 | ||||
| 505 | // get the rotation matrix | |||
| 506 | ✗ | e << orientation[0][0], orientation[1][0], orientation[2][0], orientation[0][1], orientation[1][1], | ||
| 507 | ✗ | orientation[2][1], orientation[0][2], orientation[1][2], orientation[2][2]; | ||
| 508 | ||||
| 509 | Trajectory* tr(trajectories.first()); | |||
| 510 | ||||
| 511 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (tr != nullptr) | |
| 512 | { | |||
| 513 | ✗ | length = tr->segment_length(); | ||
| 514 | ||||
| 515 | // add up all the segmnt lengths | |||
| 516 | ✗ | local_length += length; | ||
| 517 | ||||
| 518 | ✗ | angle = tr->base.angle; | ||
| 519 | ||||
| 520 | // scalar (local) order parameter components | |||
| 521 | ✗ | sin2 += length * std::sin(2 * angle); | ||
| 522 | ✗ | cos2 += length * std::cos(2 * angle); | ||
| 523 | ||||
| 524 | // director for segment in local 2d-region | |||
| 525 | ✗ | u1 = std::cos(angle); | ||
| 526 | ✗ | u2 = std::sin(angle); | ||
| 527 | u3 = 0.0; | |||
| 528 | ||||
| 529 | // Q(2) tensor (local) order parameter components | |||
| 530 | ✗ | qxx += length * (2 * u1 * u1); | ||
| 531 | ✗ | qxy += length * (2 * u1 * u2); | ||
| 532 | ✗ | qxz += length * (2 * u1 * u3); | ||
| 533 | ✗ | qyy += length * (2 * u2 * u2); | ||
| 534 | ✗ | qyz += length * (2 * u2 * u3); | ||
| 535 | ✗ | qzz += length * (2 * u3 * u3); | ||
| 536 | ||||
| 537 | tr = tr->next(); | |||
| 538 | } | |||
| 539 | ||||
| 540 | // only if trace of MT segment found | |||
| 541 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (local_length > 0) | |
| 542 | { | |||
| 543 | ✗ | qxx /= local_length; | ||
| 544 | ✗ | qxy /= local_length; | ||
| 545 | ✗ | qxz /= local_length; | ||
| 546 | ✗ | qyy /= local_length; | ||
| 547 | ✗ | qyz /= local_length; | ||
| 548 | ✗ | qzz /= local_length; | ||
| 549 | ||||
| 550 | ✗ | sin2 /= local_length; | ||
| 551 | ✗ | cos2 /= local_length; | ||
| 552 | ||||
| 553 | // local order | |||
| 554 | ✗ | Eigen::Matrix3d matrix{ { qxx, qxy, qxz }, { qxy, qyy, qyz }, { qxz, qyz, qzz } }; | ||
| 555 | Eigen::Matrix3d evec_mat{ Eigen::Matrix3d::Zero() }; | |||
| 556 | Eigen::Vector3d e_val{ Eigen::Vector3d::Zero() }; | |||
| 557 | ||||
| 558 | ✗ | eigen_decomposition(matrix, evec_mat, e_val); | ||
| 559 | ||||
| 560 | int max_pos(0); | |||
| 561 | ||||
| 562 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (e_val[1] > e_val[0]) | |
| 563 | { | |||
| 564 | max_pos = 1; | |||
| 565 | } | |||
| 566 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (e_val[2] > e_val[max_pos]) | |
| 567 | { | |||
| 568 | max_pos = 2; | |||
| 569 | } | |||
| 570 | ||||
| 571 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (size_t i = 0; i < 3; ++i) | |
| 572 | { | |||
| 573 | ✗ | sv[i] = evec_mat(i, max_pos); | ||
| 574 | } | |||
| 575 | ||||
| 576 | ✗ | sv /= sv.norm(); | ||
| 577 | ✗ | order_local = std::sqrt(sin2 * sin2 + cos2 * cos2) / area; | ||
| 578 | ||||
| 579 | // global order | |||
| 580 | ✗ | qxx -= 1; | ||
| 581 | ✗ | qyy -= 1; | ||
| 582 | ✗ | qf << qxx, qxy, qxz, qxy, qyy, qyz, qxz, qyz, qzz; | ||
| 583 | ||||
| 584 | // make tensor transformation | |||
| 585 | ✗ | qc = e * qf * e.transpose(); | ||
| 586 | ||||
| 587 | // accumulate all the Q(2) tensors components from different regions | |||
| 588 | ✗ | op_r.qxx += local_length * qc(0, 0); | ||
| 589 | ✗ | op_r.qxy += local_length * qc(0, 1); | ||
| 590 | ✗ | op_r.qxz += local_length * qc(0, 2); | ||
| 591 | ✗ | op_r.qyy += local_length * qc(1, 1); | ||
| 592 | ✗ | op_r.qyz += local_length * qc(1, 2); | ||
| 593 | ✗ | op_r.qzz += local_length * qc(2, 2); | ||
| 594 | ||||
| 595 | // add up length of the segments from all the regions | |||
| 596 | ✗ | op_r.local_l += local_length; | ||
| 597 | } | |||
| 598 | ||||
| 599 | ✗ | op_r.local_order = order_local; | ||
| 600 | op_r.sv = sv; | |||
| 601 | ✗ | return; | ||
| 602 | } | |||
| 603 | ||||
| 604 | ✗ | void Cartesian::output_snapshot(std::ostream& out) | ||
| 605 | { | |||
| 606 | ✗ | Cartesian::output_snapshot_offset(out, 0.0, 0.0); | ||
| 607 | ✗ | return; | ||
| 608 | } | |||
| 609 | ||||
| 610 | ✗ | void Cartesian::output_order_heat_map(std::ostream& out, | ||
| 611 | std::vector<double>& local_order, | |||
| 612 | std::vector<Eigen::Vector3d>& sv) | |||
| 613 | { | |||
| 614 | ✗ | return; | ||
| 615 | } | |||
| 616 | ||||
| 617 | ✗ | void Cartesian::output_snapshot_offset(std::ostream& out, double x_offset, double y_offset) | ||
| 618 | { | |||
| 619 | Eigen::Vector3d seg_3d; | |||
| 620 | ||||
| 621 | // get the region 3D rotation axis | |||
| 622 | Eigen::Vector3d cross(q.x(), q.y(), q.z()); | |||
| 623 | double cross_magnitude = cross.norm(); | |||
| 624 | ||||
| 625 | Eigen::Quaternion<double> qr_1(0.0, 0.0, 0.0, 0.0), qr_2(0.0, 0.0, 0.0, 0.0); | |||
| 626 | ||||
| 627 | Trajectory* tr; | |||
| 628 | SurfaceVector svec; | |||
| 629 | std::list<Segment*>::iterator seg; | |||
| 630 | ||||
| 631 | tr = trajectories.first(); | |||
| 632 | ||||
| 633 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (tr != nullptr) | |
| 634 | { | |||
| 635 | svec = tr->base; | |||
| 636 | ||||
| 637 | // record segments in the snapshots | |||
| 638 | seg = tr->segments.begin(); | |||
| 639 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (seg != tr->segments.end()) | |
| 640 | { | |||
| 641 | ✗ | svec = tr->base; | ||
| 642 | ||||
| 643 | // move to the starting end of the segment | |||
| 644 | ✗ | translate_vector(svec, (**seg).start); | ||
| 645 | ||||
| 646 | // for backward direction retrieve actual base angle (during nucleation) | |||
| 647 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if ((**seg).dir == Direction::BACKWARD) | |
| 648 | { | |||
| 649 | ✗ | svec.angle -= PI; | ||
| 650 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (svec.angle < 0) | |
| 651 | { | |||
| 652 | ✗ | svec.angle += 2 * PI; | ||
| 653 | } | |||
| 654 | } | |||
| 655 | ||||
| 656 | // region (and hence all the sgments in this region) need 3D rotation + translation | |||
| 657 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (cross_magnitude > 0.0) | |
| 658 | { | |||
| 659 | // translate and rotate the start point of the segment | |||
| 660 | qr_2.w() = 0; | |||
| 661 | ✗ | qr_2.x() = svec.x + mid_point(0, 0); | ||
| 662 | ✗ | qr_2.y() = svec.y + mid_point(1, 0); | ||
| 663 | ✗ | qr_2.z() = z_offset; | ||
| 664 | ||||
| 665 | ✗ | qr_1 = q.inverse() * qr_2 * q; | ||
| 666 | ✗ | seg_3d << qr_1.x(), qr_1.y(), qr_1.z(); | ||
| 667 | ✗ | seg_3d += geometry->object_cm; | ||
| 668 | ||||
| 669 | ✗ | out << seg_3d(0, 0) << "," << seg_3d(1, 0) << "," << seg_3d(2, 0) << ","; | ||
| 670 | ||||
| 671 | // translate and rotate the end point of the segment | |||
| 672 | qr_2.w() = 0; | |||
| 673 | ✗ | qr_2.x() = svec.x + mid_point(0, 0) + (**seg).length() * std::cos(svec.angle); | ||
| 674 | ✗ | qr_2.y() = svec.y + mid_point(1, 0) + (**seg).length() * std::sin(svec.angle); | ||
| 675 | ✗ | qr_2.z() = z_offset; | ||
| 676 | ||||
| 677 | ✗ | qr_1 = q.inverse() * qr_2 * q; | ||
| 678 | ✗ | seg_3d << qr_1.x(), qr_1.y(), qr_1.z(); | ||
| 679 | ✗ | seg_3d += geometry->object_cm; | ||
| 680 | ||||
| 681 | ✗ | out << seg_3d(0, 0) << "," << seg_3d(1, 0) << "," << seg_3d(2, 0) << "," << region_id << "@"; | ||
| 682 | } | |||
| 683 | ||||
| 684 | // need no rotation of the region (and hence all the sgments in this region) | |||
| 685 | else | |||
| 686 | { | |||
| 687 | // translate the start point of the segment | |||
| 688 | ✗ | seg_3d << svec.x + mid_point(0, 0), svec.y + mid_point(1, 0), z_offset; | ||
| 689 | ✗ | seg_3d += geometry->object_cm; | ||
| 690 | ✗ | out << seg_3d(0, 0) << "," << seg_3d(1, 0) << "," << seg_3d(2, 0) << ","; | ||
| 691 | ||||
| 692 | // translate the end point of the segment | |||
| 693 | ✗ | seg_3d << svec.x + mid_point(0, 0) + (**seg).length() * cos(svec.angle), | ||
| 694 | ✗ | svec.y + mid_point(1, 0) + (**seg).length() * std::sin(svec.angle), z_offset; | ||
| 695 | ✗ | seg_3d += geometry->object_cm; | ||
| 696 | ✗ | out << seg_3d(0, 0) << "," << seg_3d(1, 0) << "," << seg_3d(2, 0) << "," << region_id << "@"; | ||
| 697 | } | |||
| 698 | seg++; | |||
| 699 | } | |||
| 700 | ||||
| 701 | tr = tr->next(); | |||
| 702 | } | |||
| 703 | ||||
| 704 | ✗ | return; | ||
| 705 | } | |||
| 706 | ||||
| 707 | ✗ | void Cartesian::translate_vector(SurfaceVector& s_vec, const double dist) | ||
| 708 | { | |||
| 709 | // this can be used to move a point along a trajectory (used in making snap-shots) | |||
| 710 | ✗ | s_vec.x += std::cos(s_vec.angle) * dist; | ||
| 711 | ✗ | s_vec.y += std::sin(s_vec.angle) * dist; | ||
| 712 | ✗ | return; | ||
| 713 | } | |||
| 714 | ||||
| 715 | ✗ | void Cartesian::make_intersection_list(Trajectory* tr1) | ||
| 716 | { | |||
| 717 | #ifdef DBG_GEOMETRY | |||
| 718 | cout << "DBG/GEOMETRY: Cartesian::makeIntersectionList() called\n"; | |||
| 719 | #endif | |||
| 720 | ||||
| 721 | double cos_diff(0.0); | |||
| 722 | double denominator(0.0); | |||
| 723 | double temp1(0.0), temp2(0.0); | |||
| 724 | double bp1(0.0), bp2(0.0); | |||
| 725 | double cos1(0.0), cos2(0.0), sin1(0.0), sin2(0.0); | |||
| 726 | ||||
| 727 | // take cos/sin of first trajectory base angle | |||
| 728 | ✗ | cos1 = std::cos(tr1->base.angle); | ||
| 729 | ✗ | sin1 = std::sin(tr1->base.angle); | ||
| 730 | ||||
| 731 | Intersection is_this; | |||
| 732 | Intersection is_that; | |||
| 733 | IntersectionItr this_itr; | |||
| 734 | IntersectionItr that_itr; | |||
| 735 | ||||
| 736 | is_this.occupancy = 0; | |||
| 737 | is_that.occupancy = 0; | |||
| 738 | is_that.other_trajectory = tr1; | |||
| 739 | ||||
| 740 | Trajectory* tr2(trajectories.first()); | |||
| 741 | ||||
| 742 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (tr2 != nullptr) | |
| 743 | { | |||
| 744 | // imagine a triangle with vertices sitting at: (a) one at the trajectory intersection point and (b) other two | |||
| 745 | // at the base of the two trajectories | |||
| 746 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (tr1 != tr2) | |
| 747 | { | |||
| 748 | // take cos/sin of first trajectory base angle | |||
| 749 | ✗ | cos2 = std::cos(tr2->base.angle); | ||
| 750 | ✗ | sin2 = std::sin(tr2->base.angle); | ||
| 751 | ||||
| 752 | ✗ | cos_diff = cos1 * cos2 + sin1 * sin2; | ||
| 753 | ✗ | denominator = 1 - cos_diff * cos_diff; | ||
| 754 | ||||
| 755 | // find the intersection point distance on the trajectory | |||
| 756 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (denominator > ZERO_CUTOFF) | |
| 757 | { | |||
| 758 | ✗ | denominator = 1 / denominator; | ||
| 759 | ✗ | temp1 = (tr2->base.x - tr1->base.x) * denominator; | ||
| 760 | ✗ | temp2 = (tr2->base.y - tr1->base.y) * denominator; | ||
| 761 | ||||
| 762 | ✗ | bp1 = temp1 * (cos1 - cos_diff * cos2) + temp2 * (sin1 - cos_diff * sin2); | ||
| 763 | ||||
| 764 | // intersetion located within the range of trajectory length | |||
| 765 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (!((bp1 < 0) || (bp1 > tr1->length))) | |
| 766 | { | |||
| 767 | ✗ | bp2 = -temp1 * (cos2 - cos_diff * cos1) - temp2 * (sin2 - cos_diff * sin1); | ||
| 768 | #ifdef DBG_ASSERT | |||
| 769 | if ((bp2 < 0) || (bp2 > tr2->length)) | |||
| 770 | { | |||
| 771 | std::cout << "ERROR: DBG/extra check: incompatible results for line intersection.\n"; | |||
| 772 | std::cout << "tr1: " << bp1 << " out of " << tr1->length << ", base=" << tr1->base.x << "," | |||
| 773 | << tr1->base.y << " angle=" << tr1->base.angle << "\n"; | |||
| 774 | std::cout << "tr2: " << bp2 << " out of " << tr2->length << ", base=" << tr2->base.x << "," | |||
| 775 | << tr2->base.y << " angle=" << tr2->base.angle << "\n"; | |||
| 776 | exit(-2); | |||
| 777 | } | |||
| 778 | #endif | |||
| 779 | ||||
| 780 | // first insert 'isThat': occupancy and other are still incorrect | |||
| 781 | ✗ | that_itr = tr2->intersections.insert(std::pair<double, Intersection>(bp2, is_that)); | ||
| 782 | is_this.mirror = that_itr; | |||
| 783 | is_this.other_trajectory = tr2; | |||
| 784 | ✗ | this_itr = tr1->intersections.insert(std::pair<double, Intersection>(bp1, is_this)); | ||
| 785 | ||||
| 786 | // update the reference in the other half of the intersection | |||
| 787 | ✗ | that_itr->second.mirror = this_itr; | ||
| 788 | ||||
| 789 | // call the update routine of the other trajectory, this will also correct the occupancy number | |||
| 790 | ✗ | tr2->new_intersection(that_itr); | ||
| 791 | } | |||
| 792 | } | |||
| 793 | } | |||
| 794 | ||||
| 795 | tr2 = tr2->next(); | |||
| 796 | } | |||
| 797 | #ifdef DBG_GEOMETRY | |||
| 798 | cout << "DBG/GEOMETRY: " << tr1->intersections.size() - 1 << " intersections\n"; | |||
| 799 | #endif | |||
| 800 | ||||
| 801 | ✗ | return; | ||
| 802 | } | |||
| 803 | ||||
| 804 | ✗ | Triangle::Triangle(double element_area, Geometry* g): | ||
| 805 | ✗ | Cartesian(g, element_area) | ||
| 806 | { | |||
| 807 | // necessary to create a full geometry, made with many triangles | |||
| 808 | ✗ | return; | ||
| 809 | } | |||
| 810 | ||||
| 811 | ✗ | SurfaceVector Triangle::random_surface_vector() | ||
| 812 | { | |||
| 813 | SurfaceVector v; | |||
| 814 | double r1(0.0), r2(0.0); | |||
| 815 | ||||
| 816 | // get system pointer | |||
| 817 | ✗ | System* s(geometry->system); | ||
| 818 | ||||
| 819 | // random number between (0,1) | |||
| 820 | ✗ | r1 = s->random_gen.rand_dbl_exc(1.0); | ||
| 821 | r2 = s->random_gen.rand_dbl_exc(1.0); | |||
| 822 | ||||
| 823 | // store sqrt(r1) to use it many times, hence avoid expensive call of sqrt() | |||
| 824 | ✗ | double sqr1 = std::sqrt(r1); | ||
| 825 | ||||
| 826 | // generate uniformly and isotropically distributed nucleation points on each triangle | |||
| 827 | ✗ | v.x = (1 - sqr1) * vertices[0](0, 0) + (sqr1 * (1 - r2)) * vertices[1](0, 0) + (sqr1 * r2) * vertices[2](0, 0); | ||
| 828 | ✗ | v.y = (1 - sqr1) * vertices[0](1, 0) + (sqr1 * (1 - r2)) * vertices[1](1, 0) + (sqr1 * r2) * vertices[2](1, 0); | ||
| 829 | ||||
| 830 | // make the unifor distribution also isotropic | |||
| 831 | ✗ | v.angle = s->random_gen.rand_exc(2 * PI); | ||
| 832 | ||||
| 833 | ✗ | v.region = this; | ||
| 834 | ||||
| 835 | ✗ | return v; | ||
| 836 | } | |||
| 837 | ||||
| 838 | ✗ | void Triangle::get_trajectory_coordinates(SurfaceVector& s_vec, | ||
| 839 | double& total_length, | |||
| 840 | std::vector<PointAtEdge>& end_point, | |||
| 841 | TrajectoryVector& t_vec) | |||
| 842 | { | |||
| 843 | // copy old base coordinate | |||
| 844 | ✗ | double old_x(s_vec.x); | ||
| 845 | ✗ | double old_y(s_vec.y); | ||
| 846 | ||||
| 847 | ✗ | t_vec.trajectory = nullptr; | ||
| 848 | ||||
| 849 | ✗ | double angle_cos(std::cos(s_vec.angle)); | ||
| 850 | ✗ | double angle_sin(std::sin(s_vec.angle)); | ||
| 851 | ||||
| 852 | // direction and base angle of the trajectory | |||
| 853 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (std::abs(angle_cos) < ZERO_CUTOFF) | |
| 854 | { | |||
| 855 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (s_vec.angle < PI) | |
| 856 | { | |||
| 857 | ✗ | t_vec.dir = Direction::FORWARD; | ||
| 858 | } | |||
| 859 | else | |||
| 860 | { | |||
| 861 | ✗ | t_vec.dir = Direction::BACKWARD; | ||
| 862 | ✗ | s_vec.angle -= PI; | ||
| 863 | } | |||
| 864 | } | |||
| 865 | ||||
| 866 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | else if (angle_cos < 0) | |
| 867 | { | |||
| 868 | ✗ | s_vec.angle += PI; | ||
| 869 | ✗ | t_vec.dir = Direction::BACKWARD; | ||
| 870 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (s_vec.angle > 2 * PI) | |
| 871 | { | |||
| 872 | ✗ | s_vec.angle -= 2 * PI; | ||
| 873 | } | |||
| 874 | } | |||
| 875 | ||||
| 876 | else | |||
| 877 | { | |||
| 878 | ✗ | t_vec.dir = Direction::FORWARD; | ||
| 879 | } | |||
| 880 | ||||
| 881 | // use the triangle perimeter to create a trajectory, this will to make sure to have exactly two intersections | |||
| 882 | ✗ | Eigen::Vector2d v1(s_vec.x + peri_meter * angle_cos, s_vec.y + peri_meter * angle_sin); | ||
| 883 | ✗ | Eigen::Vector2d v2(s_vec.x - peri_meter * angle_cos, s_vec.y - peri_meter * angle_sin); | ||
| 884 | ||||
| 885 | // intersection points of the trajectory with the triangle edges | |||
| 886 | int encounter(0), neno(0); | |||
| 887 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (int i = 0; i < 3; i++) | |
| 888 | { | |||
| 889 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (encounter == 2) | |
| 890 | { | |||
| 891 | break; | |||
| 892 | } | |||
| 893 | ||||
| 894 | Eigen::Vector2d u1; | |||
| 895 | ✗ | u1 = vertices[side[i].dir[0]]; | ||
| 896 | ||||
| 897 | Eigen::Vector2d u2; | |||
| 898 | ✗ | u2 = vertices[side[i].dir[1]]; | ||
| 899 | ||||
| 900 | Eigen::Vector2d u; | |||
| 901 | u = u2 - u1; | |||
| 902 | ||||
| 903 | Eigen::Vector2d v; | |||
| 904 | v = v2 - v1; | |||
| 905 | ||||
| 906 | Eigen::Vector2d w; | |||
| 907 | w = u1 - v1; | |||
| 908 | ||||
| 909 | double sval(0.0); | |||
| 910 | ✗ | sval = (v(1, 0) * w(0, 0) - v(0, 0) * w(1, 0)) / (v(0, 0) * u(1, 0) - v(1, 0) * u(0, 0)); | ||
| 911 | ||||
| 912 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if ((sval >= 0.0) && (sval <= 1.0)) | |
| 913 | { | |||
| 914 | ✗ | encounter += 1; | ||
| 915 | ✗ | neno = side_map[i]; | ||
| 916 | ||||
| 917 | // get triangle-edge to trajectory intersection point | |||
| 918 | end_point.push_back( | |||
| 919 | ✗ | PointAtEdge(u1(0, 0) + sval * (u2(0, 0) - u1(0, 0)), u1(1, 0) + sval * (u2(1, 0) - u1(1, 0)), 0.0, neno)); | ||
| 920 | } | |||
| 921 | } | |||
| 922 | ||||
| 923 | // base coordinate (x_base < x_other) of the trajectory | |||
| 924 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (end_point[0].x > end_point[1].x) | |
| 925 | { | |||
| 926 | reverse(end_point.begin(), end_point.end()); | |||
| 927 | } | |||
| 928 | ||||
| 929 | ✗ | s_vec.x = end_point[0].x; | ||
| 930 | ✗ | s_vec.y = end_point[0].y; | ||
| 931 | ||||
| 932 | // nucleation position (distance between old base and nucleation point) on the trajectory | |||
| 933 | ✗ | double dx(s_vec.x - old_x), dy(s_vec.y - old_y); | ||
| 934 | ✗ | t_vec.pos = std::sqrt(dx * dx + dy * dy); | ||
| 935 | ||||
| 936 | // length of the trajectory (distance between the end points of the trajectory) | |||
| 937 | ✗ | dx = end_point[1].x - end_point[0].x; | ||
| 938 | ✗ | dy = end_point[1].y - end_point[0].y; | ||
| 939 | ✗ | total_length = std::sqrt(dx * dx + dy * dy); | ||
| 940 | ||||
| 941 | // eacch trajectory should have exacty two intersection point with exactly two triangle edges | |||
| 942 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (encounter != 2) | |
| 943 | { | |||
| 944 | ✗ | std::cout << "Problem with the number of trajectory-triangle intersections (should be == 2) ---> " << encounter | ||
| 945 | << std::endl; | |||
| 946 | ✗ | exit(-1); | ||
| 947 | } | |||
| 948 | ||||
| 949 | ✗ | return; | ||
| 950 | } | |||
| 951 |