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 : #ifdef MOOSE_MFEM_ENABLED 11 : 12 : #include "ProblemOperatorInterface.h" 13 : 14 : namespace Moose::MFEM 15 : { 16 : void 17 236 : ProblemOperatorInterface::SetGridFunctions() 18 : { 19 236 : _test_variables = _problem.gridfunctions.Get(_test_var_names); 20 236 : _trial_variables = _problem.gridfunctions.Get(_trial_var_names); 21 : 22 : // Set operator size and block structure 23 236 : _block_true_offsets.SetSize(_trial_variables.size() + 1); 24 236 : _block_true_offsets[0] = 0; 25 432 : for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind) 26 : { 27 196 : _block_true_offsets[ind + 1] = _trial_variables.at(ind)->ParFESpace()->TrueVSize(); 28 : } 29 236 : _block_true_offsets.PartialSum(); 30 : 31 236 : _true_x.Update(_block_true_offsets); 32 236 : _true_rhs.Update(_block_true_offsets); 33 236 : } 34 : 35 : void 36 236 : ProblemOperatorInterface::Init(mfem::BlockVector & X) 37 : { 38 236 : X.Update(_block_true_offsets); 39 432 : for (const auto i : index_range(_test_variables)) 40 196 : X.GetBlock(i) = _test_variables[i]->GetTrueVector(); 41 : // Sync the flags from sub-block vectors to global vector 42 236 : X.SyncFromBlocks(); 43 : 44 : // After initial assignment of X from the grid function, which may contain initial conditions, 45 : // we alias the grid function to X 46 432 : for (const auto i : index_range(_test_variables)) 47 196 : _test_variables[i]->MakeTRef(_test_variables[i]->ParFESpace(), X, _block_true_offsets[i]); 48 236 : _test_true_vector = &X; 49 : 50 : // This might seem silly but after making the tref the memory flags of the grid function and its 51 : // true vector are in an empty state other than the aliasing. This operation syncs the flags and 52 : // should be a no-op in terms of actual data transfer 53 236 : SetTestVariablesFromTrueVectors(); 54 236 : } 55 : 56 : void 57 516 : ProblemOperatorInterface::SetTestVariablesFromTrueVectors() 58 : { 59 992 : for (unsigned int ind = 0; ind < _test_variables.size(); ++ind) 60 : { 61 476 : auto * const test_var = _test_variables.at(ind); 62 : 63 : // We must sync the memory flags from the true true vector to the grid function copy of the true 64 : // vector 65 : mooseAssert(_test_true_vector, "The true vector should already have been set"); 66 476 : test_var->GetTrueVector().SyncMemory(*_test_true_vector); 67 476 : test_var->SetFromTrueVector(); 68 : } 69 516 : } 70 : 71 : void 72 140 : ProblemOperatorInterface::SetTrialVariablesFromTrueVectors() 73 : { 74 280 : for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind) 75 : { 76 140 : _trial_variables.at(ind)->SetFromTrueVector(); 77 : } 78 140 : } 79 : } 80 : 81 : #endif