https://mooseframework.inl.gov
ProblemOperatorInterface.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 
13 
14 namespace Moose::MFEM
15 {
16 void
18 {
21 
22  // Set operator size and block structure
23  _block_true_offsets.SetSize(_trial_variables.size() + 1);
24  _block_true_offsets[0] = 0;
25  for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind)
26  {
27  _block_true_offsets[ind + 1] = _trial_variables.at(ind)->ParFESpace()->TrueVSize();
28  }
29  _block_true_offsets.PartialSum();
30 
33 }
34 
35 void
36 ProblemOperatorInterface::Init(mfem::BlockVector & X)
37 {
38  X.Update(_block_true_offsets);
39  for (const auto i : index_range(_test_variables))
40  X.GetBlock(i) = _test_variables[i]->GetTrueVector();
41  // Sync the flags from sub-block vectors to global vector
42  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  for (const auto i : index_range(_test_variables))
47  _test_variables[i]->MakeTRef(_test_variables[i]->ParFESpace(), X, _block_true_offsets[i]);
48  _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
54 }
55 
56 void
58 {
59  for (unsigned int ind = 0; ind < _test_variables.size(); ++ind)
60  {
61  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  test_var->GetTrueVector().SyncMemory(*_test_true_vector);
67  test_var->SetFromTrueVector();
68  }
69 }
70 
71 void
73 {
74  for (unsigned int ind = 0; ind < _trial_variables.size(); ++ind)
75  {
76  _trial_variables.at(ind)->SetFromTrueVector();
77  }
78 }
79 }
80 
81 #endif
std::vector< mfem::ParGridFunction * > _trial_variables
MFEMProblemData & _problem
Reference to the current problem.
std::vector< mfem::ParGridFunction * > _test_variables
std::vector< std::string > _test_var_names
Vector of names of state gridfunctions used in formulation, ordered by appearance in block vector dur...
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...
std::vector< std::string > _trial_var_names
Vector of names of state gridfunctions used in formulation, ordered by appearance in block vector dur...
Moose::MFEM::GridFunctions gridfunctions
auto index_range(const T &sizable)
virtual void Init(mfem::BlockVector &X)