|
16 | 16 | ******************************************************************************/
|
17 | 17 |
|
18 | 18 | #include "Integrator.h"
|
| 19 | + |
19 | 20 | #include <Domain/DomainBase.h>
|
20 | 21 | #include <Domain/Factory.hpp>
|
21 | 22 |
|
22 | 23 | Integrator::Integrator(const unsigned T)
|
23 | 24 | : Tag(T) {}
|
24 | 25 |
|
25 |
| -void Integrator::set_domain(const weak_ptr<DomainBase>& D) { if(database.lock() != D.lock()) database = D; } |
| 26 | +void Integrator::set_domain(const weak_ptr<DomainBase>& D) { |
| 27 | + if(database.lock() != D.lock()) database = D; |
| 28 | +} |
26 | 29 |
|
27 | 30 | shared_ptr<DomainBase> Integrator::get_domain() const { return database.lock(); }
|
28 | 31 |
|
@@ -260,13 +263,69 @@ mat Integrator::solve(sp_mat&& B) {
|
260 | 263 | return X;
|
261 | 264 | }
|
262 | 265 |
|
263 |
| -int Integrator::solve(mat& X, const mat& B) { return database.lock()->get_factory()->get_stiffness()->solve(X, B); } |
| 266 | +int Integrator::solve(mat& X, const mat& B) { |
| 267 | + int info{0}; |
| 268 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 269 | + if(0 == comm_rank) info = database.lock()->get_factory()->get_stiffness()->solve(X, B); |
| 270 | + |
| 271 | + if(SUANPAN_SUCCESS == bcast_from_root(info)) { |
| 272 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 273 | + // ReSharper disable once CppDFAUnreachableCode |
| 274 | + if(0 != comm_rank) X.set_size(B.n_rows, B.n_cols); |
| 275 | + bcast_from_root(X); |
| 276 | + } |
| 277 | + |
| 278 | + return info; |
| 279 | +} |
| 280 | + |
| 281 | +int Integrator::solve(mat& X, const sp_mat& B) { |
| 282 | + int info{0}; |
| 283 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 284 | + if(0 == comm_rank) info = database.lock()->get_factory()->get_stiffness()->solve(X, B); |
264 | 285 |
|
265 |
| -int Integrator::solve(mat& X, const sp_mat& B) { return database.lock()->get_factory()->get_stiffness()->solve(X, B); } |
| 286 | + if(SUANPAN_SUCCESS == bcast_from_root(info)) { |
| 287 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 288 | + // ReSharper disable once CppDFAUnreachableCode |
| 289 | + if(0 != comm_rank) X.set_size(B.n_rows, B.n_cols); |
| 290 | + bcast_from_root(X); |
| 291 | + } |
| 292 | + |
| 293 | + return info; |
| 294 | +} |
266 | 295 |
|
267 |
| -int Integrator::solve(mat& X, mat&& B) { return database.lock()->get_factory()->get_stiffness()->solve(X, std::move(B)); } |
| 296 | +int Integrator::solve(mat& X, mat&& B) { |
| 297 | + const auto n_rows = B.n_rows, n_cols = B.n_cols; |
| 298 | + |
| 299 | + int info{0}; |
| 300 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 301 | + if(0 == comm_rank) info = database.lock()->get_factory()->get_stiffness()->solve(X, std::move(B)); |
| 302 | + |
| 303 | + if(SUANPAN_SUCCESS == bcast_from_root(info)) { |
| 304 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 305 | + // ReSharper disable once CppDFAUnreachableCode |
| 306 | + if(0 != comm_rank) X.set_size(n_rows, n_cols); |
| 307 | + bcast_from_root(X); |
| 308 | + } |
| 309 | + |
| 310 | + return info; |
| 311 | +} |
| 312 | + |
| 313 | +int Integrator::solve(mat& X, sp_mat&& B) { |
| 314 | + const auto n_rows = B.n_rows, n_cols = B.n_cols; |
| 315 | + |
| 316 | + int info{0}; |
| 317 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 318 | + if(0 == comm_rank) info = database.lock()->get_factory()->get_stiffness()->solve(X, std::move(B)); |
| 319 | + |
| 320 | + if(SUANPAN_SUCCESS == bcast_from_root(info)) { |
| 321 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 322 | + // ReSharper disable once CppDFAUnreachableCode |
| 323 | + if(0 != comm_rank) X.set_size(n_rows, n_cols); |
| 324 | + bcast_from_root(X); |
| 325 | + } |
268 | 326 |
|
269 |
| -int Integrator::solve(mat& X, sp_mat&& B) { return database.lock()->get_factory()->get_stiffness()->solve(X, std::move(B)); } |
| 327 | + return info; |
| 328 | +} |
270 | 329 |
|
271 | 330 | /**
|
272 | 331 | * Avoid machine error accumulation.
|
@@ -363,13 +422,69 @@ void ExplicitIntegrator::update_from_ninja() {
|
363 | 422 | W->update_trial_acceleration_by(W->get_ninja());
|
364 | 423 | }
|
365 | 424 |
|
366 |
| -int ExplicitIntegrator::solve(mat& X, const mat& B) { return get_domain()->get_factory()->get_mass()->solve(X, B); } |
| 425 | +int ExplicitIntegrator::solve(mat& X, const mat& B) { |
| 426 | + int info{0}; |
| 427 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 428 | + if(0 == comm_rank) info = get_domain()->get_factory()->get_mass()->solve(X, B); |
| 429 | + |
| 430 | + if(SUANPAN_SUCCESS == bcast_from_root(info)) { |
| 431 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 432 | + // ReSharper disable once CppDFAUnreachableCode |
| 433 | + if(0 != comm_rank) X.set_size(B.n_rows, B.n_cols); |
| 434 | + bcast_from_root(X); |
| 435 | + } |
| 436 | + |
| 437 | + return info; |
| 438 | +} |
| 439 | + |
| 440 | +int ExplicitIntegrator::solve(mat& X, const sp_mat& B) { |
| 441 | + int info{0}; |
| 442 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 443 | + if(0 == comm_rank) info = get_domain()->get_factory()->get_mass()->solve(X, B); |
| 444 | + |
| 445 | + if(SUANPAN_SUCCESS == bcast_from_root(info)) { |
| 446 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 447 | + // ReSharper disable once CppDFAUnreachableCode |
| 448 | + if(0 != comm_rank) X.set_size(B.n_rows, B.n_cols); |
| 449 | + bcast_from_root(X); |
| 450 | + } |
| 451 | + |
| 452 | + return info; |
| 453 | +} |
367 | 454 |
|
368 |
| -int ExplicitIntegrator::solve(mat& X, const sp_mat& B) { return get_domain()->get_factory()->get_mass()->solve(X, B); } |
| 455 | +int ExplicitIntegrator::solve(mat& X, mat&& B) { |
| 456 | + const auto n_rows = B.n_rows, n_cols = B.n_cols; |
369 | 457 |
|
370 |
| -int ExplicitIntegrator::solve(mat& X, mat&& B) { return get_domain()->get_factory()->get_mass()->solve(X, std::move(B)); } |
| 458 | + int info{0}; |
| 459 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 460 | + if(0 == comm_rank) info = get_domain()->get_factory()->get_mass()->solve(X, std::move(B)); |
371 | 461 |
|
372 |
| -int ExplicitIntegrator::solve(mat& X, sp_mat&& B) { return get_domain()->get_factory()->get_mass()->solve(X, std::move(B)); } |
| 462 | + if(SUANPAN_SUCCESS == bcast_from_root(info)) { |
| 463 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 464 | + // ReSharper disable once CppDFAUnreachableCode |
| 465 | + if(0 != comm_rank) X.set_size(n_rows, n_cols); |
| 466 | + bcast_from_root(X); |
| 467 | + } |
| 468 | + |
| 469 | + return info; |
| 470 | +} |
| 471 | + |
| 472 | +int ExplicitIntegrator::solve(mat& X, sp_mat&& B) { |
| 473 | + const auto n_rows = B.n_rows, n_cols = B.n_cols; |
| 474 | + |
| 475 | + int info{0}; |
| 476 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 477 | + if(0 == comm_rank) info = get_domain()->get_factory()->get_mass()->solve(X, std::move(B)); |
| 478 | + |
| 479 | + if(SUANPAN_SUCCESS == bcast_from_root(info)) { |
| 480 | + // ReSharper disable once CppIfCanBeReplacedByConstexprIf |
| 481 | + // ReSharper disable once CppDFAUnreachableCode |
| 482 | + if(0 != comm_rank) X.set_size(n_rows, n_cols); |
| 483 | + bcast_from_root(X); |
| 484 | + } |
| 485 | + |
| 486 | + return info; |
| 487 | +} |
373 | 488 |
|
374 | 489 | vec ExplicitIntegrator::from_incre_velocity(const vec&, const uvec&) { throw invalid_argument("support velocity cannot be used with explicit integrator"); }
|
375 | 490 |
|
|
0 commit comments