www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
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...
 
virtual bool shouldUpdateSolution ()
 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 23 of file RichardsMultiphaseProblem.h.

Constructor & Destructor Documentation

RichardsMultiphaseProblem::RichardsMultiphaseProblem ( const InputParameters &  params)

Definition at line 29 of file RichardsMultiphaseProblem.C.

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")),
38 {
39 }
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 ( )
virtual

Definition at line 41 of file RichardsMultiphaseProblem.C.

41 {}

Member Function Documentation

void RichardsMultiphaseProblem::initialSetup ( )
virtual

extracts the moose variable numbers associated with bounded_var and lower_var

Definition at line 44 of file RichardsMultiphaseProblem.C.

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 }
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
bool RichardsMultiphaseProblem::shouldUpdateSolution ( )
virtual

returns true, indicating that updateSolution should be run

Definition at line 70 of file RichardsMultiphaseProblem.C.

71 {
72  return true;
73 }
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_solutionis the solution that Petsc says we should use.
ghosted_solutionis 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 76 of file RichardsMultiphaseProblem.C.

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 }
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

Member Data Documentation

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 48 of file RichardsMultiphaseProblem.h.

Referenced by initialSetup().

unsigned int RichardsMultiphaseProblem::_bounded_var_num
protected

internal moose variable number associated with _bounded_var

Definition at line 54 of file RichardsMultiphaseProblem.h.

Referenced by initialSetup(), and updateSolution().

NonlinearVariableName RichardsMultiphaseProblem::_lower_var_name
protected

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

Definition at line 51 of file RichardsMultiphaseProblem.h.

Referenced by initialSetup().

unsigned int RichardsMultiphaseProblem::_lower_var_num
protected

internal moose variable number associated with _lower_var

Definition at line 57 of file RichardsMultiphaseProblem.h.

Referenced by initialSetup(), and updateSolution().


The documentation for this class was generated from the following files: