diff --git a/dumux/implicit/2p2c/2p2cmodel.hh b/dumux/implicit/2p2c/2p2cmodel.hh index d4c6b89f54882e9f38a6d7c2ca1748d6085ceb55..ee295dc614a47305a9bb38e8192e5fbd2a193871 100644 --- a/dumux/implicit/2p2c/2p2cmodel.hh +++ b/dumux/implicit/2p2c/2p2cmodel.hh @@ -507,45 +507,66 @@ public: const SolutionVector &oldGlobalSol) { bool wasSwitched = false; - - for (unsigned i = 0; i < staticDat_.size(); ++i) - staticDat_[i].visited = false; - - FVElementGeometry fvGeometry; - static VolumeVariables volVars; - ElementIterator eIt = this->gridView_().template begin<0> (); - const ElementIterator &eEndIt = this->gridView_().template end<0> (); - for (; eIt != eEndIt; ++eIt) - { - fvGeometry.update(this->gridView_(), *eIt); - for (int scvIdx = 0; scvIdx < fvGeometry.numScv; ++scvIdx) + int succeeded; + try { + for (unsigned i = 0; i < staticDat_.size(); ++i) + staticDat_[i].visited = false; + + FVElementGeometry fvGeometry; + static VolumeVariables volVars; + ElementIterator eIt = this->gridView_().template begin<0> (); + const ElementIterator &eEndIt = this->gridView_().template end<0> (); + for (; eIt != eEndIt; ++eIt) { + fvGeometry.update(this->gridView_(), *eIt); + for (int scvIdx = 0; scvIdx < fvGeometry.numScv; ++scvIdx) + { #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 4) - int dofIdxGlobal = this->dofMapper().subIndex(*eIt, scvIdx, dofCodim); + int dofIdxGlobal = this->dofMapper().subIndex(*eIt, scvIdx, dofCodim); #else - int dofIdxGlobal = this->dofMapper().map(*eIt, scvIdx, dofCodim); + int dofIdxGlobal = this->dofMapper().map(*eIt, scvIdx, dofCodim); #endif - if (staticDat_[dofIdxGlobal].visited) - continue; - - staticDat_[dofIdxGlobal].visited = true; - volVars.update(curGlobalSol[dofIdxGlobal], - this->problem_(), - *eIt, - fvGeometry, - scvIdx, - false); - const GlobalPosition &globalPos = fvGeometry.subContVol[scvIdx].global; - if (primaryVarSwitch_(curGlobalSol, - volVars, - dofIdxGlobal, - globalPos)) - { - this->jacobianAssembler().markDofRed(dofIdxGlobal); - wasSwitched = true; + if (staticDat_[dofIdxGlobal].visited) + continue; + + staticDat_[dofIdxGlobal].visited = true; + volVars.update(curGlobalSol[dofIdxGlobal], + this->problem_(), + *eIt, + fvGeometry, + scvIdx, + false); + const GlobalPosition &globalPos = fvGeometry.subContVol[scvIdx].global; + if (primaryVarSwitch_(curGlobalSol, + volVars, + dofIdxGlobal, + globalPos)) + { + this->jacobianAssembler().markDofRed(dofIdxGlobal); + wasSwitched = true; + } } } + succeeded = 1; + } + catch (Dumux::NumericalProblem &e) + { + std::cout << "\n" + << "Rank " << this->problem_().gridView().comm().rank() + << " caught an exception while updating the static data." << e.what() + << "\n"; + succeeded = 0; + } + //make sure that all processes succeeded. If not throw a NumericalProblem to decrease the time step size. + if (this->gridView_().comm().size() > 1) + succeeded = this->gridView_().comm().min(succeeded); + + if (!succeeded) { + if(this->problem_().gridView().comm().rank() == 0) + DUNE_THROW(NumericalProblem, + "A process did not succeed in updating the static data."); + return; } // make sure that if there was a variable switch in an diff --git a/dumux/implicit/3p3c/3p3cmodel.hh b/dumux/implicit/3p3c/3p3cmodel.hh index 87bbef18cb9fc890f2f4875eb6a25fd056cb0b9b..9241602ed53df33186733fb25c9ba50d6f295e8c 100644 --- a/dumux/implicit/3p3c/3p3cmodel.hh +++ b/dumux/implicit/3p3c/3p3cmodel.hh @@ -495,45 +495,67 @@ public: const SolutionVector &oldGlobalSol) { bool wasSwitched = false; + int succeeded; + try { - for (unsigned i = 0; i < staticDat_.size(); ++i) - staticDat_[i].visited = false; + for (unsigned i = 0; i < staticDat_.size(); ++i) + staticDat_[i].visited = false; - FVElementGeometry fvGeometry; - static VolumeVariables volVars; - ElementIterator eIt = this->gridView_().template begin<0> (); - const ElementIterator &eEndIt = this->gridView_().template end<0> (); - for (; eIt != eEndIt; ++eIt) - { - fvGeometry.update(this->gridView_(), *eIt); - for (int scvIdx = 0; scvIdx < fvGeometry.numScv; ++scvIdx) + FVElementGeometry fvGeometry; + static VolumeVariables volVars; + ElementIterator eIt = this->gridView_().template begin<0> (); + const ElementIterator &eEndIt = this->gridView_().template end<0> (); + for (; eIt != eEndIt; ++eIt) { + fvGeometry.update(this->gridView_(), *eIt); + for (int scvIdx = 0; scvIdx < fvGeometry.numScv; ++scvIdx) + { #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 4) - int dofIdxGlobal = this->dofMapper().subIndex(*eIt, scvIdx, dofCodim); + int dofIdxGlobal = this->dofMapper().subIndex(*eIt, scvIdx, dofCodim); #else - int dofIdxGlobal = this->dofMapper().map(*eIt, scvIdx, dofCodim); + int dofIdxGlobal = this->dofMapper().map(*eIt, scvIdx, dofCodim); #endif - if (staticDat_[dofIdxGlobal].visited) - continue; - - staticDat_[dofIdxGlobal].visited = true; - volVars.update(curGlobalSol[dofIdxGlobal], - this->problem_(), - *eIt, - fvGeometry, - scvIdx, - false); - const GlobalPosition &globalPos = fvGeometry.subContVol[scvIdx].global; - if (primaryVarSwitch_(curGlobalSol, - volVars, - dofIdxGlobal, - globalPos)) - { - this->jacobianAssembler().markDofRed(dofIdxGlobal); - wasSwitched = true; + if (staticDat_[dofIdxGlobal].visited) + continue; + + staticDat_[dofIdxGlobal].visited = true; + volVars.update(curGlobalSol[dofIdxGlobal], + this->problem_(), + *eIt, + fvGeometry, + scvIdx, + false); + const GlobalPosition &globalPos = fvGeometry.subContVol[scvIdx].global; + if (primaryVarSwitch_(curGlobalSol, + volVars, + dofIdxGlobal, + globalPos)) + { + this->jacobianAssembler().markDofRed(dofIdxGlobal); + wasSwitched = true; + } } } + succeeded = 1; + } + catch (Dumux::NumericalProblem &e) + { + std::cout << "\n" + << "Rank " << this->problem_().gridView().comm().rank() + << " caught an exception while updating the static data." << e.what() + << "\n"; + succeeded = 0; + } + //make sure that all processes succeeded. If not throw a NumericalProblem to decrease the time step size. + if (this->gridView_().comm().size() > 1) + succeeded = this->gridView_().comm().min(succeeded); + + if (!succeeded) { + if(this->problem_().gridView().comm().rank() == 0) + DUNE_THROW(NumericalProblem, + "A process did not succeed in updating the static data."); + return; } // make sure that if there was a variable switch in an diff --git a/dumux/implicit/co2/co2model.hh b/dumux/implicit/co2/co2model.hh index 7c107d97dda6d961f9b0c6890cacd265b5e30323..2028656bf83aecb54bd54999f7e0b4a44ba7ab6b 100644 --- a/dumux/implicit/co2/co2model.hh +++ b/dumux/implicit/co2/co2model.hh @@ -100,41 +100,64 @@ public: const SolutionVector &oldGlobalSol) { bool wasSwitched = false; + int succeeded; + try { - for (unsigned i = 0; i < ParentType::staticDat_.size(); ++i) - ParentType::staticDat_[i].visited = false; + for (unsigned i = 0; i < ParentType::staticDat_.size(); ++i) + ParentType::staticDat_[i].visited = false; - FVElementGeometry fvGeometry; - static VolumeVariables volVars; - ElementIterator eIt = this->gridView_().template begin<0> (); - const ElementIterator &eEndIt = this->gridView_().template end<0> (); - for (; eIt != eEndIt; ++eIt) - { - fvGeometry.update(this->gridView_(), *eIt); - for (int scvIdx = 0; scvIdx < fvGeometry.numScv; ++scvIdx) + FVElementGeometry fvGeometry; + static VolumeVariables volVars; + ElementIterator eIt = this->gridView_().template begin<0> (); + const ElementIterator &eEndIt = this->gridView_().template end<0> (); + for (; eIt != eEndIt; ++eIt) { - int dofIdxGlobal = this->dofMapper().map(*eIt, scvIdx, dofCodim); - - if (ParentType::staticDat_[dofIdxGlobal].visited) - continue; - - ParentType::staticDat_[dofIdxGlobal].visited = true; - volVars.update(curGlobalSol[dofIdxGlobal], - this->problem_(), - *eIt, - fvGeometry, - scvIdx, - false); - const GlobalPosition &globalPos = eIt->geometry().corner(scvIdx); - if (primaryVarSwitch_(curGlobalSol, - volVars, - dofIdxGlobal, - globalPos)) + + fvGeometry.update(this->gridView_(), *eIt); + for (int scvIdx = 0; scvIdx < fvGeometry.numScv; ++scvIdx) { - this->jacobianAssembler().markDofRed(dofIdxGlobal); - wasSwitched = true; + int dofIdxGlobal = this->dofMapper().map(*eIt, scvIdx, dofCodim); + + if (ParentType::staticDat_[dofIdxGlobal].visited) + continue; + + ParentType::staticDat_[dofIdxGlobal].visited = true; + volVars.update(curGlobalSol[dofIdxGlobal], + this->problem_(), + *eIt, + fvGeometry, + scvIdx, + false); + const GlobalPosition &globalPos = eIt->geometry().corner(scvIdx); + if (primaryVarSwitch_(curGlobalSol, + volVars, + dofIdxGlobal, + globalPos)) + { + this->jacobianAssembler().markDofRed(dofIdxGlobal); + wasSwitched = true; + } } } + succeeded = 1; + } + catch (Dumux::NumericalProblem &e) + { + std::cout << "\n" + << "Rank " << this->problem_().gridView().comm().rank() + << " caught an exception while updating the static data." << e.what() + << "\n"; + succeeded = 0; + } + //make sure that all processes succeeded. If not throw a NumericalProblem to decrease the time step size. + if (this->gridView_().comm().size() > 1) + succeeded = this->gridView_().comm().min(succeeded); + + if (!succeeded) { + if(this->problem_().gridView().comm().rank() == 0) + DUNE_THROW(NumericalProblem, + "A process did not succeed in updating the static data."); + return; } // make sure that if there was a variable switch in an diff --git a/dumux/implicit/common/implicitmodel.hh b/dumux/implicit/common/implicitmodel.hh index 8757481b6418f460376068df748a71095fd2072a..f8cd345735d765a6b37f787a521970e81ffe4622 100644 --- a/dumux/implicit/common/implicitmodel.hh +++ b/dumux/implicit/common/implicitmodel.hh @@ -459,7 +459,12 @@ public: asImp_().updateBegin(); - bool converged = solver.execute(controller); + int converged = solver.execute(controller); + + if (this->gridView_().comm().size() > 1) + { + converged = this->gridView_().comm().min(converged); + } if (converged) { asImp_().updateSuccessful(); }