Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "FullSolveMultiApp.h" 11 : #include "LayeredSideDiffusiveFluxAverage.h" 12 : #include "Executioner.h" 13 : #include "TransientBase.h" 14 : #include "Console.h" 15 : 16 : // libMesh 17 : #include "libmesh/mesh_tools.h" 18 : 19 : registerMooseObject("MooseApp", FullSolveMultiApp); 20 : 21 : InputParameters 22 32814 : FullSolveMultiApp::validParams() 23 : { 24 32814 : InputParameters params = MultiApp::validParams(); 25 32814 : params.addClassDescription("Performs a complete simulation during each execution."); 26 98442 : params.addParam<bool>( 27 : "keep_full_output_history", 28 65628 : false, 29 : "Whether or not to keep the full output history when this multiapp has multiple entries"); 30 98442 : params.addParam<bool>("ignore_solve_not_converge", 31 65628 : false, 32 : "True to continue main app even if a sub app's solve does not converge."); 33 32814 : return params; 34 0 : } 35 : 36 2139 : FullSolveMultiApp::FullSolveMultiApp(const InputParameters & parameters) 37 2139 : : MultiApp(parameters), _ignore_diverge(getParam<bool>("ignore_solve_not_converge")) 38 : { 39 : // You could end up with some dirty hidden behavior if you do this. We could remove this check, 40 : // but I don't think that it's sane to do so. 41 2139 : if (_no_restore && (_app.isRecovering() || _app.isRestarting())) 42 0 : paramError("no_restore", 43 : "The parent app is restarting or recovering, restoration cannot be disabled"); 44 2139 : } 45 : 46 : void 47 1355 : FullSolveMultiApp::restore(bool force) 48 : { 49 1355 : if (!_no_restore) 50 899 : MultiApp::restore(force); 51 1351 : } 52 : 53 : void 54 2027 : FullSolveMultiApp::initialSetup() 55 : { 56 2027 : MultiApp::initialSetup(); 57 : 58 2027 : if (_has_an_app) 59 : { 60 2027 : Moose::ScopedCommSwapper swapper(_my_comm); 61 : 62 2027 : _executioners.resize(_my_num_apps); 63 : 64 : // Grab Executioner from each app 65 5537 : for (unsigned int i = 0; i < _my_num_apps; i++) 66 : { 67 3514 : auto & app = _apps[i]; 68 3514 : Executioner * ex = app->getExecutioner(); 69 : 70 3514 : if (!ex) 71 0 : mooseError("Executioner does not exist!"); 72 : 73 3514 : if (_ignore_diverge) 74 : { 75 17 : TransientBase * tex = dynamic_cast<TransientBase *>(ex); 76 17 : if (tex && tex->parameters().get<bool>("error_on_dtmin")) 77 4 : mooseError("Requesting to ignore failed solutions, but 'Executioner/error_on_dtmin' is " 78 : "true in sub-application. Set this parameter to false in sub-application to " 79 : "avoid an error if Transient solve fails."); 80 : } 81 : 82 3510 : ex->init(); 83 : 84 3510 : _executioners[i] = ex; 85 : } 86 2023 : } 87 2023 : } 88 : 89 : bool 90 3268 : FullSolveMultiApp::solveStep(Real /*dt*/, Real /*target_time*/, bool auto_advance) 91 : { 92 3268 : if (!auto_advance) 93 0 : mooseError("FullSolveMultiApp is not compatible with auto_advance=false"); 94 : 95 3268 : if (!_has_an_app) 96 0 : return true; 97 : 98 3268 : TIME_SECTION(_solve_step_timer); 99 : 100 3268 : Moose::ScopedCommSwapper swapper(_my_comm); 101 : 102 : int rank; 103 : int ierr; 104 3268 : ierr = MPI_Comm_rank(_communicator.get(), &rank); 105 3268 : mooseCheckMPIErr(ierr); 106 : 107 3268 : bool last_solve_converged = true; 108 7814 : for (unsigned int i = 0; i < _my_num_apps; i++) 109 : { 110 : // reset output system if desired 111 4554 : if (!getParam<bool>("keep_full_output_history")) 112 4257 : _apps[i]->getOutputWarehouse().reset(); 113 : 114 4554 : Executioner * ex = _executioners[i]; 115 4554 : ex->execute(); 116 : 117 4546 : last_solve_converged = last_solve_converged && ex->lastSolveConverged(); 118 : 119 4546 : showStatusMessage(i); 120 : } 121 : 122 3260 : return last_solve_converged || _ignore_diverge; 123 3260 : } 124 : 125 : void 126 4546 : FullSolveMultiApp::showStatusMessage(unsigned int i) const 127 : { 128 8894 : if (!_fe_problem.verboseMultiApps() && 129 8894 : _apps[i]->getOutputWarehouse().getOutputs<Console>().size() > 0) 130 4348 : return; 131 198 : else if (!_executioners[i]->lastSolveConverged()) 132 0 : _console << COLOR_RED << "Subapp " << _apps[i]->name() << " solve Did NOT Converge!" 133 0 : << COLOR_DEFAULT << std::endl; 134 : else 135 198 : _console << COLOR_GREEN << "Subapp " << _apps[i]->name() << " solve converged!" << COLOR_DEFAULT 136 198 : << std::endl; 137 : }