https://mooseframework.inl.gov
ProblemOperatorBase.C
Go to the documentation of this file.
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 
20  : _problem(problem), _problem_data(problem.getProblemData())
21 {
22 }
23 
24 void
26 {
29 
30  // Set operator size and block structure
31  _block_true_offsets.SetSize(_trial_variables.size() + 1);
32  _block_true_offsets[0] = 0;
33  for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind)
34  {
35  _block_true_offsets[ind + 1] = _trial_variables.at(ind)->ParFESpace()->TrueVSize();
36  }
37  _block_true_offsets.PartialSum();
38 
41 }
42 
43 void
44 ProblemOperatorBase::Init(mfem::BlockVector & X)
45 {
46  X.Update(_block_true_offsets);
47  for (const auto i : index_range(_test_variables))
48  X.GetBlock(i) = _test_variables[i]->GetTrueVector();
49  // Sync the flags from sub-block vectors to global vector
50  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  for (const auto i : index_range(_test_variables))
55  _test_variables[i]->MakeTRef(_test_variables[i]->ParFESpace(), X, _block_true_offsets[i]);
56  _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
62 }
63 
64 void
66 {
67  for (unsigned int ind = 0; ind < _test_variables.size(); ++ind)
68  {
69  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  test_var->GetTrueVector().SyncMemory(*_test_true_vector);
75  test_var->SetFromTrueVector();
76  }
77 }
78 
79 void
81 {
82  for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind)
83  {
84  _trial_variables.at(ind)->SetFromTrueVector();
85  }
86 }
87 }
88 
89 #endif
std::vector< std::string > _test_var_names
Vector of names of state gridfunctions used in formulation, ordered by appearance in block vector dur...
std::vector< std::string > _trial_var_names
Vector of names of state gridfunctions used in formulation, ordered by appearance in block vector dur...
ProblemOperatorBase(MFEMProblem &problem)
std::vector< mfem::ParGridFunction * > _test_variables
T * Get(const std::string &field_name) const
Returns a non-owning pointer to the field. This is guaranteed to return a non-null pointer...
const mfem::Vector * _test_true_vector
std::vector< mfem::ParGridFunction * > _trial_variables
virtual void Init(mfem::BlockVector &X)
Moose::MFEM::GridFunctions gridfunctions
auto index_range(const T &sizable)