https://mooseframework.inl.gov
InterWrapperSolutionTransferBase.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 
11 #include "MultiApp.h"
12 #include "FEProblemBase.h"
13 #include "DisplacedProblem.h"
14 #include "InterWrapperMesh.h"
15 
18 {
20  params.addRequiredParam<std::vector<AuxVariableName>>("variable",
21  "The auxiliary variables to transfer.");
22  return params;
23 }
24 
26  const InputParameters & parameters)
27  : MultiAppTransfer(parameters), _var_names(getParam<std::vector<AuxVariableName>>("variable"))
28 {
30  paramError("from_multiapp", "This transfer works only into multi-app.");
31 }
32 
33 void
35 {
37  for (std::size_t var_index = 0; var_index < _var_names.size(); ++var_index)
38  {
39  // Check source variable on regular subchannel problem
41  0, _var_names[var_index], Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_ANY);
42  System & from_sys = from_var.sys().system();
43  const auto & fe_type = from_sys.variable_type(from_var.number());
44 
45  if (fe_type.family != LAGRANGE || fe_type.order != FIRST)
46  paramError("variable",
47  "This transfer requires a first order Lagrange variable for the source variable");
48 
49  // Check target variable in visualization mesh
50  MooseVariableFieldBase & to_var = _to_problems[0]->getVariable(
51  0, _var_names[var_index], Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_ANY);
52 
53  System & to_sys = to_var.sys().system();
54  const auto & fe_type_target = to_sys.variable_type(to_var.number());
55 
56  if (fe_type_target.family != LAGRANGE || fe_type_target.order != FIRST)
57  paramError("variable",
58  "This transfer requires a first order Lagrange variable for the source variable");
59  }
60 }
61 
62 void
64 {
65  getAppInfo();
66 
67  switch (_current_direction)
68  {
69  case TO_MULTIAPP:
71  break;
72 
73  default:
74  break;
75  }
76 }
77 
78 void
80 {
81  mooseAssert(_from_meshes.size() == 1, "Only one source mesh can be active in this transfer.");
82  if (dynamic_cast<InterWrapperMesh *>(_from_meshes[0]) == nullptr)
83  mooseError("This transfer works only with InterWrapperMesh classes.");
84 
85  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
86  if (_multi_app->hasLocalApp(i))
88 }
89 
90 void
92 {
93  transferNodalVars(app_idx);
94 }
95 
96 void
98 {
99  Moose::ScopedCommSwapper swapper(_multi_app->comm());
100 
101  FEProblemBase & to_problem = _multi_app->appProblemBase(app_idx);
102  MooseMesh * mesh = NULL;
103  if (_displaced_target_mesh && to_problem.getDisplacedProblem())
104  mesh = &to_problem.getDisplacedProblem()->mesh();
105  else
106  mesh = &to_problem.mesh();
107 
108  const InterWrapperMesh & from_mesh = dynamic_cast<InterWrapperMesh &>(*_from_meshes[0]);
109  FEProblemBase & from_problem = *_from_problems[0];
110 
111  for (auto & node : mesh->getMesh().local_node_ptr_range())
112  {
113  Node * from_node = getFromNode(from_mesh, *node);
114 
115  for (auto & var_name : _var_names)
116  {
117  System * to_sys = find_sys(to_problem.es(), var_name);
118  unsigned int to_sys_num = to_sys->number();
119  unsigned int to_var_num = to_sys->variable_number(var_name);
120 
121  if (node->n_dofs(to_sys_num, to_var_num) > 0)
122  {
123  System * from_sys = find_sys(from_problem.es(), var_name);
124  unsigned int from_sys_num = from_sys->number();
125  unsigned int from_var_num = from_sys->variable_number(var_name);
126 
127  swapper.forceSwap();
128  NumericVector<Real> * from_solution = from_sys->solution.get();
129  dof_id_type from_dof = from_node->dof_number(from_sys_num, from_var_num, 0);
130  Real from_value = (*from_solution)(from_dof);
131  swapper.forceSwap();
132 
133  NumericVector<Real> & to_solution = _multi_app->appTransferVector(app_idx, var_name);
134  dof_id_type to_dof = node->dof_number(to_sys_num, to_var_num, 0);
135  to_solution.set(to_dof, from_value);
136  }
137  }
138  }
139 
140  for (auto & var_name : _var_names)
141  {
142  _multi_app->appTransferVector(app_idx, var_name).close();
143  find_sys(to_problem.es(), var_name)->update();
144  }
145 }
LAGRANGE
MooseEnum _current_direction
Base class for inter-wrapper meshes.
unsigned int number() const
virtual Node * getFromNode(const InterWrapperMesh &from_mesh, const Point &src_node)=0
Find node on computational mesh given the visualization point.
FIRST
virtual libMesh::System & system()=0
MeshBase & mesh
std::vector< FEProblemBase *> _to_problems
void transferVarsToApp(unsigned int app_idx)
Transfer variables into the sub-app.
std::shared_ptr< MultiApp > _multi_app
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool _displaced_target_mesh
bool contains(const std::string &value) const
unsigned int number() const
std::vector< MooseMesh *> _from_meshes
void initialSetup() override
const std::vector< AuxVariableName > & _var_names
Variable names to transfer.
virtual libMesh::EquationSystems & es() override
static libMesh::System * find_sys(libMesh::EquationSystems &es, const std::string &var_name)
InterWrapperSolutionTransferBase(const InputParameters &parameters)
void paramError(const std::string &param, Args... args) const
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const=0
void transferToMultiApps()
Do the transfer into the sub-app.
static InputParameters validParams()
SubProblem & _subproblem
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
MultiMooseEnum _directions
void mooseError(Args &&... args) const
virtual void getAppInfo()
SystemBase & sys()
std::vector< FEProblemBase *> _from_problems
uint8_t dof_id_type