\brief compute the right hand side of the system in a matrix-free fashion and store the result in result*/
| 369 | |
| 370 | /** \brief compute the right hand side of the system in a matrix-free fashion and store the result in result*/ |
| 371 | void SPH::TimeStepPF::matrixFreeRHS(const VectorXr & x, VectorXr & result) |
| 372 | { |
| 373 | Simulation *sim = Simulation::getCurrent(); |
| 374 | const Real h = TimeManager::getCurrent()->getTimeStepSize();; |
| 375 | const unsigned int nFluids = sim->numberOfFluidModels(); |
| 376 | const unsigned int nBoundaries = sim->numberOfBoundaryModels(); |
| 377 | |
| 378 | ////////////////////////////////////////////////////////////////////////// |
| 379 | // helper functions |
| 380 | ////////////////////////////////////////////////////////////////////////// |
| 381 | // constraint value |
| 382 | const auto calculateC = [&](const unsigned int fluidModelIndex, const unsigned int i, std::vector<Vector3r> & p) -> Real |
| 383 | { |
| 384 | const FluidModel * model = sim->getFluidModel(fluidModelIndex); |
| 385 | // Compute current density for particle i |
| 386 | Real density = model->getVolume(i) * sim->W_zero(); |
| 387 | const Vector3r &xi = p[0]; |
| 388 | unsigned int counter = 1; |
| 389 | |
| 390 | for (unsigned int pid = 0; pid < nFluids; pid++) |
| 391 | { |
| 392 | const FluidModel *fm_neighbor = sim->getFluidModelFromPointSet(pid); |
| 393 | for (unsigned int j = 0; j < sim->numberOfNeighbors(fluidModelIndex, pid, i); j++) |
| 394 | { |
| 395 | const unsigned int neighborIndex = sim->getNeighbor(fluidModelIndex, pid, i, j); |
| 396 | const Vector3r & xj = p[counter++]; |
| 397 | density += fm_neighbor->getVolume(neighborIndex) * sim->W(xi - xj); |
| 398 | } |
| 399 | } |
| 400 | // influence of boundary on density |
| 401 | if (sim->getBoundaryHandlingMethod() == BoundaryHandlingMethods::Akinci2012) |
| 402 | { |
| 403 | forall_boundary_neighbors( |
| 404 | // Boundary: Akinci2012 |
| 405 | density += bm_neighbor->getVolume(neighborIndex) * sim->W(xi - xj); |
| 406 | ); |
| 407 | } |
| 408 | else if (sim->getBoundaryHandlingMethod() == BoundaryHandlingMethods::Koschier2017) |
| 409 | { |
| 410 | forall_density_maps( |
| 411 | density += rho; |
| 412 | ); |
| 413 | } |
| 414 | else if (sim->getBoundaryHandlingMethod() == BoundaryHandlingMethods::Bender2019) |
| 415 | { |
| 416 | forall_volume_maps( |
| 417 | density += Vj * sim->W(xi - xj); |
| 418 | ); |
| 419 | } |
| 420 | // constraint value = density / density0 - 1 |
| 421 | const auto C = density - 1; |
| 422 | // pressure clamping |
| 423 | return (C < 0) ? 0 : C; |
| 424 | }; |
| 425 | // constraint gradient |
| 426 | const auto calculateNablaC = [&](const unsigned int fluidModelIndex, const unsigned int i, std::vector<Vector3r> & p) -> std::vector<Vector3r> |
| 427 | { |
| 428 | std::vector<Vector3r> nablaC(p.size()); |
nothing calls this directly
no test coverage detected