RichardsMultiphaseProblem Class Reference

Allows a constraint u>=v to be enforced during the nonlinear iteration process. More...

#include <RichardsMultiphaseProblem.h>

Inheritance diagram for RichardsMultiphaseProblem:
[legend]

## Public Member Functions

RichardsMultiphaseProblem (const InputParameters &params)

virtual ~RichardsMultiphaseProblem ()

virtual void initialSetup ()
extracts the moose variable numbers associated with bounded_var and lower_var More...

returns true, indicating that updateSolution should be run More...

virtual bool updateSolution (NumericVector< Number > &vec_solution, NumericVector< Number > &ghosted_solution)
Does the bounding by modifying vec_solution, and then ghosted_solution. More...

## Protected Attributes

NonlinearVariableName _bounded_var_name
name of the bounded variable (this is the variable that gets altered to respect bounded_var > lower_var) More...

NonlinearVariableName _lower_var_name
name of the variable that acts as the lower bound to bounded_var More...

unsigned int _bounded_var_num
internal moose variable number associated with _bounded_var More...

unsigned int _lower_var_num
internal moose variable number associated with _lower_var More...

## Detailed Description

Allows a constraint u>=v to be enforced during the nonlinear iteration process.

This is done by modifying u (which is called bounded_var below)

Definition at line 25 of file RichardsMultiphaseProblem.h.

## ◆ RichardsMultiphaseProblem()

 RichardsMultiphaseProblem::RichardsMultiphaseProblem ( const InputParameters & params )

Definition at line 33 of file RichardsMultiphaseProblem.C.

34  : FEProblem(params),
35  // in the following have to get the names of the variables, and then find their numbers in
36  // initialSetup,
37  // as their numbers won't be defined at the moment of instantiation of this class
38  _bounded_var_name(params.get<NonlinearVariableName>("bounded_var")),
39  _lower_var_name(params.get<NonlinearVariableName>("lower_var")),
42 {
43 }
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
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

## ◆ ~RichardsMultiphaseProblem()

 RichardsMultiphaseProblem::~RichardsMultiphaseProblem ( )
virtual

Definition at line 45 of file RichardsMultiphaseProblem.C.

45 {}

## ◆ initialSetup()

 void RichardsMultiphaseProblem::initialSetup ( )
virtual

extracts the moose variable numbers associated with bounded_var and lower_var

Definition at line 48 of file RichardsMultiphaseProblem.C.

49 {
50  // the first argument to getVariable is threadID - i hope the following always works
51  unsigned int tid = 0;
52
53  // We are going to do more specific checks below, hence allowing
54  // more specific error messages to be printed in case something goes
55  // wrong. Therefore we just pass VAR_ANY here.
56  MooseVariableFEBase & bounded = getVariable(
57  tid, _bounded_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
58  MooseVariableFEBase & lower = getVariable(
59  tid, _lower_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
60
61  // some checks
62  if (!bounded.isNodal() || !lower.isNodal())
63  mooseError("Both the bounded and lower variables must be nodal variables in "
64  "RichardsMultiphaseProblem");
65  if (bounded.feType().family != lower.feType().family)
66  mooseError("Both the bounded and lower variables must belong to the same element family, eg "
67  "LAGRANGE, in RichardsMultiphaseProblem");
68  if (bounded.feType().order != lower.feType().order)
69  mooseError("Both the bounded and lower variables must have the same order, eg FIRST, in "
70  "RichardsMultiphaseProblem");
71
72  // extract the required info
73  _bounded_var_num = bounded.number();
74  _lower_var_num = lower.number();
75
76  FEProblemBase::initialSetup();
77 }
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
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

returns true, indicating that updateSolution should be run

Definition at line 80 of file RichardsMultiphaseProblem.C.

81 {
82  return true;
83 }

 bool RichardsMultiphaseProblem::updateSolution ( NumericVector< Number > & vec_solution, NumericVector< Number > & ghosted_solution )
virtual

Does the bounding by modifying vec_solution, and then ghosted_solution.

Parameters
 vec_solution is the solution that Petsc says we should use. ghosted_solution is a ghosted version of vec_solution.
Returns
true if vec_solution was changed at a node in order to respect the bounds

Definition at line 86 of file RichardsMultiphaseProblem.C.

88 {
89  bool updatedSolution =
90  false; // this gets set to true if we needed to enforce the bound at any node
91
92  unsigned int sys_num = getNonlinearSystemBase().number();
93
94  // For parallel procs i believe that i have to use local_nodes_begin, rather than just nodes_begin
95  // _mesh comes from SystemBase (_mesh = getNonlinearSystemBase().subproblem().mesh(), and
96  // subproblem is this object)
97  for (const auto & node : _mesh.getMesh().local_node_ptr_range())
98  {
99  // dofs[0] is the dof number of the bounded variable at this node
100  // dofs[1] is the dof number of the lower variable at this node
101  std::vector<dof_id_type> dofs(2);
102  dofs[0] = node->dof_number(sys_num, _bounded_var_num, 0);
103  dofs[1] = node->dof_number(sys_num, _lower_var_num, 0);
104
105  // soln[0] is the value of the bounded variable at this node
106  // soln[1] is the value of the lower variable at this node
107  std::vector<Number> soln(2);
108  vec_solution.get(dofs, soln);
109
110  // do the bounding
111  if (soln[0] < soln[1])
112  {
113  vec_solution.set(dofs[0], soln[1]); // set the bounded variable equal to the lower value
114  updatedSolution = true;
115  }
116  }
117
118  // The above vec_solution.set calls potentially added "set" commands to a queue
119  // The following actions the queue (doing MPI commands if necessary), so
120  // vec_solution will actually be modified by this following command
121  vec_solution.close();
122
123  // if any proc updated the solution, all procs will know about it
124  _communicator.max(updatedSolution);
125
126  if (updatedSolution)
127  {
128  ghosted_solution = vec_solution;
129  ghosted_solution.close();
130  }
131
132  return updatedSolution;
133 }
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

## ◆ _bounded_var_name

 NonlinearVariableName RichardsMultiphaseProblem::_bounded_var_name
protected

name of the bounded variable (this is the variable that gets altered to respect bounded_var > lower_var)

Definition at line 50 of file RichardsMultiphaseProblem.h.

Referenced by initialSetup().

## ◆ _bounded_var_num

 unsigned int RichardsMultiphaseProblem::_bounded_var_num
protected

internal moose variable number associated with _bounded_var

Definition at line 56 of file RichardsMultiphaseProblem.h.

## ◆ _lower_var_name

 NonlinearVariableName RichardsMultiphaseProblem::_lower_var_name
protected

name of the variable that acts as the lower bound to bounded_var

Definition at line 53 of file RichardsMultiphaseProblem.h.

Referenced by initialSetup().

## ◆ _lower_var_num

 unsigned int RichardsMultiphaseProblem::_lower_var_num
protected

internal moose variable number associated with _lower_var

Definition at line 59 of file RichardsMultiphaseProblem.h.