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