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 349 : ProblemOperatorBase::ProblemOperatorBase(MFEMProblem & problem) 20 349 : : _problem(problem), _problem_data(problem.getProblemData()) 21 : { 22 349 : } 23 : 24 : void 25 349 : ProblemOperatorBase::SetGridFunctions() 26 : { 27 349 : _test_variables = _problem_data.gridfunctions.Get(_test_var_names); 28 349 : _trial_variables = _problem_data.gridfunctions.Get(_trial_var_names); 29 : 30 : // Set operator size and block structure 31 349 : _block_true_offsets.SetSize(_trial_variables.size() + 1); 32 349 : _block_true_offsets[0] = 0; 33 658 : for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind) 34 : { 35 309 : _block_true_offsets[ind + 1] = _trial_variables.at(ind)->ParFESpace()->TrueVSize(); 36 : } 37 349 : _block_true_offsets.PartialSum(); 38 : 39 349 : _true_x.Update(_block_true_offsets); 40 349 : _true_rhs.Update(_block_true_offsets); 41 349 : } 42 : 43 : void 44 349 : ProblemOperatorBase::Init(mfem::BlockVector & X) 45 : { 46 349 : X.Update(_block_true_offsets); 47 658 : for (const auto i : index_range(_test_variables)) 48 309 : X.GetBlock(i) = _test_variables[i]->GetTrueVector(); 49 : // Sync the flags from sub-block vectors to global vector 50 349 : 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 658 : for (const auto i : index_range(_test_variables)) 55 309 : _test_variables[i]->MakeTRef(_test_variables[i]->ParFESpace(), X, _block_true_offsets[i]); 56 349 : _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 349 : SetTestVariablesFromTrueVectors(); 62 349 : } 63 : 64 : void 65 1631 : ProblemOperatorBase::SetTestVariablesFromTrueVectors() 66 : { 67 3222 : for (unsigned int ind = 0; ind < _test_variables.size(); ++ind) 68 : { 69 1591 : 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 1591 : test_var->GetTrueVector().SyncMemory(*_test_true_vector); 75 1591 : test_var->SetFromTrueVector(); 76 : } 77 1631 : } 78 : 79 : void 80 641 : ProblemOperatorBase::SetTrialVariablesFromTrueVectors() 81 : { 82 1282 : for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind) 83 : { 84 641 : _trial_variables.at(ind)->SetFromTrueVector(); 85 : } 86 641 : } 87 : } 88 : 89 : #endif