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 "MultiAppVectorPostprocessorTransfer.h" 11 : 12 : // MOOSE includes 13 : #include "MooseTypes.h" 14 : #include "FEProblem.h" 15 : #include "MultiApp.h" 16 : 17 : // libMesh 18 : #include "libmesh/meshfree_interpolation.h" 19 : #include "libmesh/system.h" 20 : 21 : registerMooseObject("MooseApp", MultiAppVectorPostprocessorTransfer); 22 : 23 : InputParameters 24 14361 : MultiAppVectorPostprocessorTransfer::validParams() 25 : { 26 14361 : InputParameters params = MultiAppTransfer::validParams(); 27 14361 : params.addRequiredParam<PostprocessorName>( 28 : "postprocessor", "The name of the Postprocessors on the sub-app to transfer from/to."); 29 14361 : params.addRequiredParam<VectorPostprocessorName>("vector_postprocessor", 30 : "The name of the VectorPostprocessor in " 31 : "the MultiApp to transfer values " 32 : "from/to."); 33 14361 : params.addRequiredParam<std::string>( 34 : "vector_name", "Named vector quantity to transfer from/to in VectorPostprocessor."); 35 14361 : params.addClassDescription("This transfer distributes the N values of a " 36 : "VectorPostprocessor to Postprocessors located in " 37 : "N sub-apps or" 38 : " collects Postprocessor values from N sub-apps " 39 : "into a VectorPostprocessor"); 40 14361 : return params; 41 0 : } 42 : 43 48 : MultiAppVectorPostprocessorTransfer::MultiAppVectorPostprocessorTransfer( 44 48 : const InputParameters & parameters) 45 : : MultiAppTransfer(parameters), 46 48 : _sub_pp_name(getParam<PostprocessorName>("postprocessor")), 47 48 : _master_vpp_name(getParam<VectorPostprocessorName>("vector_postprocessor")), 48 96 : _vector_name(getParam<std::string>("vector_name")) 49 : { 50 48 : if (_directions.size() != 1) 51 0 : paramError("direction", "This transfer is only unidirectional"); 52 48 : } 53 : 54 : void 55 24 : MultiAppVectorPostprocessorTransfer::executeToMultiapp() 56 : { 57 : const VectorPostprocessorValue & vpp = 58 24 : getToMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name, 59 : _vector_name); 60 : 61 : // Execute VPP if it was specified to execute on transfers 62 24 : _fe_problem.computeUserObjectByName(EXEC_TRANSFER, Moose::PRE_AUX, _master_vpp_name); 63 24 : _fe_problem.computeUserObjectByName(EXEC_TRANSFER, Moose::POST_AUX, _master_vpp_name); 64 : 65 24 : if (vpp.size() != getToMultiApp()->numGlobalApps()) 66 0 : mooseError("VectorPostprocessor ", 67 : _master_vpp_name, 68 : " and number of sub-apps do not match: ", 69 0 : vpp.size(), 70 : "/", 71 0 : getToMultiApp()->numGlobalApps()); 72 : 73 72 : for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); ++i) 74 48 : if (getToMultiApp()->hasLocalApp(i)) 75 28 : getToMultiApp()->appProblemBase(i).setPostprocessorValueByName(_sub_pp_name, vpp[i]); 76 24 : } 77 : 78 : void 79 24 : MultiAppVectorPostprocessorTransfer::executeFromMultiapp() 80 : { 81 : const VectorPostprocessorValue & vpp = 82 24 : getFromMultiApp()->problemBase().getVectorPostprocessorValueByName(_master_vpp_name, 83 : _vector_name); 84 24 : errorIfObjectExecutesOnTransferInSourceApp(_sub_pp_name); 85 : 86 20 : if (vpp.size() != getFromMultiApp()->numGlobalApps()) 87 0 : mooseError("VectorPostprocessor ", 88 : _master_vpp_name, 89 : " and number of sub-apps do not match: ", 90 0 : vpp.size(), 91 : "/", 92 0 : getFromMultiApp()->numGlobalApps()); 93 : 94 20 : VectorPostprocessorValue value(getFromMultiApp()->numGlobalApps(), 0.0); 95 60 : for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); ++i) 96 : { 97 : // To avoid duplication and thus a wrong pp value after summing value accross procs, we should 98 : // ensure that value[i] is only set by one procs. To do this, we check isFirstLocalRank to see 99 : // if the current proc is the first rank that subapp i lives on. 100 40 : if (getFromMultiApp()->hasLocalApp(i) && getFromMultiApp()->isFirstLocalRank()) 101 20 : value[i] = getFromMultiApp()->appProblemBase(i).getPostprocessorValueByName(_sub_pp_name); 102 : } 103 : 104 : // Sum to distribute entries of 'value' accross all procs 105 60 : for (auto & v : value) 106 40 : _communicator.sum(v); 107 : 108 40 : getFromMultiApp()->problemBase().setVectorPostprocessorValueByName( 109 20 : _master_vpp_name, _vector_name, value); 110 20 : } 111 : 112 : void 113 48 : MultiAppVectorPostprocessorTransfer::execute() 114 : { 115 48 : TIME_SECTION( 116 : "MultiAppVectorPostprocessorTransfer::execute()", 5, "Transferring a vector postprocessor"); 117 : 118 48 : if (_current_direction == FROM_MULTIAPP) 119 24 : executeFromMultiapp(); 120 : else 121 24 : executeToMultiapp(); 122 44 : }