www.mooseframework.org
RichardsMultiphaseProblem.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
9 
10 // MOOSE includes
11 #include "MooseMesh.h"
12 #include "MooseVariable.h"
13 #include "NonlinearSystem.h"
14 
15 template <>
16 InputParameters
18 {
19  InputParameters params = validParams<FEProblemBase>();
20  params.addRequiredParam<NonlinearVariableName>(
21  "bounded_var", "Variable whose value will be constrained to be greater than lower_var");
22  params.addRequiredParam<NonlinearVariableName>(
23  "lower_var",
24  "Variable that acts as a lower bound to bounded_var. It will not be "
25  "constrained during the solution procedure");
26  return params;
27 }
28 
30  : FEProblem(params),
31  // in the following have to get the names of the variables, and then find their numbers in
32  // initialSetup,
33  // as their numbers won't be defined at the moment of instantiation of this class
34  _bounded_var_name(params.get<NonlinearVariableName>("bounded_var")),
35  _lower_var_name(params.get<NonlinearVariableName>("lower_var")),
36  _bounded_var_num(0),
37  _lower_var_num(0)
38 {
39 }
40 
42 
43 void
45 {
46  // the first argument to getVariable is threadID - i hope the following always works
47  unsigned int tid = 0;
48  MooseVariable & bounded = getVariable(tid, _bounded_var_name);
49  MooseVariable & lower = getVariable(tid, _lower_var_name);
50 
51  // some checks
52  if (!bounded.isNodal() || !lower.isNodal())
53  mooseError("Both the bounded and lower variables must be nodal variables in "
54  "RichardsMultiphaseProblem");
55  if (bounded.feType().family != lower.feType().family)
56  mooseError("Both the bounded and lower variables must belong to the same element family, eg "
57  "LAGRANGE, in RichardsMultiphaseProblem");
58  if (bounded.feType().order != lower.feType().order)
59  mooseError("Both the bounded and lower variables must have the same order, eg FIRST, in "
60  "RichardsMultiphaseProblem");
61 
62  // extract the required info
63  _bounded_var_num = bounded.number();
64  _lower_var_num = lower.number();
65 
66  FEProblemBase::initialSetup();
67 }
68 
69 bool
71 {
72  return true;
73 }
74 
75 bool
76 RichardsMultiphaseProblem::updateSolution(NumericVector<Number> & vec_solution,
77  NumericVector<Number> & ghosted_solution)
78 {
79  bool updatedSolution =
80  false; // this gets set to true if we needed to enforce the bound at any node
81 
82  unsigned int sys_num = getNonlinearSystemBase().number();
83 
84  // For parallel procs i believe that i have to use local_nodes_begin, rather than just nodes_begin
85  // _mesh comes from SystemBase (_mesh = getNonlinearSystemBase().subproblem().mesh(), and
86  // subproblem is this object)
87  MeshBase::node_iterator nit = _mesh.getMesh().local_nodes_begin();
88  const MeshBase::node_iterator nend = _mesh.getMesh().local_nodes_end();
89 
90  for (; nit != nend; ++nit)
91  {
92  const Node & node = *(*nit);
93 
94  // dofs[0] is the dof number of the bounded variable at this node
95  // dofs[1] is the dof number of the lower variable at this node
96  std::vector<dof_id_type> dofs(2);
97  dofs[0] = node.dof_number(sys_num, _bounded_var_num, 0);
98  dofs[1] = node.dof_number(sys_num, _lower_var_num, 0);
99 
100  // soln[0] is the value of the bounded variable at this node
101  // soln[1] is the value of the lower variable at this node
102  std::vector<Number> soln(2);
103  vec_solution.get(dofs, soln);
104 
105  // do the bounding
106  if (soln[0] < soln[1])
107  {
108  vec_solution.set(dofs[0], soln[1]); // set the bounded variable equal to the lower value
109  updatedSolution = true;
110  }
111  }
112 
113  // The above vec_solution.set calls potentially added "set" commands to a queue
114  // The following actions the queue (doing MPI commands if necessary), so
115  // vec_solution will actually be modified by this following command
116  vec_solution.close();
117 
118  // if any proc updated the solution, all procs will know about it
119  _communicator.max(updatedSolution);
120 
121  if (updatedSolution)
122  {
123  ghosted_solution = vec_solution;
124  ghosted_solution.close();
125  }
126 
127  return updatedSolution;
128 }
NonlinearVariableName _bounded_var_name
name of the bounded variable (this is the variable that gets altered to respect bounded_var > lower_v...
NonlinearVariableName _lower_var_name
name of the variable that acts as the lower bound to bounded_var
virtual bool shouldUpdateSolution()
returns true, indicating that updateSolution should be run
RichardsMultiphaseProblem(const InputParameters &params)
unsigned int _bounded_var_num
internal moose variable number associated with _bounded_var
unsigned int _lower_var_num
internal moose variable number associated with _lower_var
virtual void initialSetup()
extracts the moose variable numbers associated with bounded_var and lower_var
virtual bool updateSolution(NumericVector< Number > &vec_solution, NumericVector< Number > &ghosted_solution)
Does the bounding by modifying vec_solution, and then ghosted_solution.
InputParameters validParams< RichardsMultiphaseProblem >()