libMesh
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::ContinuationSystem Class Reference

This class inherits from the FEMSystem. More...

#include <continuation_system.h>

Inheritance diagram for libMesh::ContinuationSystem:
[legend]

Public Types

enum  Predictor { Euler, AB2, Invalid_Predictor }
 The code provides the ability to select from different predictor schemes for getting the initial guess for the solution at the next point on the solution arc. More...
 
typedef ContinuationSystem sys_type
 The type of system. More...
 
typedef FEMSystem Parent
 The type of the parent. More...
 
typedef bool(TimeSolver::* TimeSolverResPtr) (bool, DiffContext &)
 Syntax sugar to make numerical_jacobian() declaration easier. More...
 
typedef std::map< std::string, SparseMatrix< Number > * >::iterator matrices_iterator
 Matrix iterator typedefs. More...
 
typedef std::map< std::string, SparseMatrix< Number > * >::const_iterator const_matrices_iterator
 
typedef std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
 Vector iterator typedefs. More...
 
typedef std::map< std::string, NumericVector< Number > * >::const_iterator const_vectors_iterator
 

Public Member Functions

 ContinuationSystem (EquationSystems &es, const std::string &name, const unsigned int number)
 Constructor. More...
 
virtual ~ContinuationSystem ()
 Destructor. More...
 
virtual void clear () libmesh_override
 Clear all the data structures associated with the system. More...
 
virtual void solve () libmesh_override
 Perform a standard "solve" of the system, without doing continuation. More...
 
void continuation_solve ()
 Perform a continuation solve of the system. More...
 
void advance_arcstep ()
 Call this function after a continuation solve to compute the tangent and get the next initial guess. More...
 
void set_max_arclength_stepsize (Real maxds)
 Sets (initializes) the max-allowable ds value and the current ds value. More...
 
void save_current_solution ()
 Stores the current solution and continuation parameter (as "previous_u" and "old_continuation_parameter") for later referral. More...
 
virtual void assembly (bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) libmesh_override
 Prepares matrix or rhs for matrix assembly. More...
 
void mesh_position_get ()
 Tells the FEMSystem to set the degree of freedom coefficients which should correspond to mesh nodal coordinates. More...
 
void mesh_position_set ()
 Tells the FEMSystem to set the mesh nodal coordinates which should correspond to degree of freedom coefficients. More...
 
virtual UniquePtr< DiffContextbuild_context () libmesh_override
 Builds a FEMContext object with enough information to do evaluations on each element. More...
 
virtual void init_context (DiffContext &) libmesh_override
 
virtual void postprocess () libmesh_override
 Runs a postprocessing loop over all elements, and if postprocess_sides is true over all sides. More...
 
virtual void assemble_qoi (const QoISet &indices=QoISet()) libmesh_override
 Runs a qoi assembly loop over all elements, and if assemble_qoi_sides is true over all sides. More...
 
virtual void assemble_qoi_derivative (const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) libmesh_override
 Runs a qoi derivative assembly loop over all elements, and if assemble_qoi_sides is true over all sides. More...
 
Real numerical_jacobian_h_for_var (unsigned int var_num) const
 If numerical_jacobian_h_for_var(var_num) is changed from its default value (numerical_jacobian_h), the FEMSystem will perturb solution vector entries for variable var_num by that amount when calculating finite differences with respect to that variable. More...
 
void set_numerical_jacobian_h_for_var (unsigned int var_num, Real new_h)
 
void numerical_jacobian (TimeSolverResPtr res, FEMContext &context) const
 Uses the results of multiple res calls to numerically differentiate the corresponding jacobian. More...
 
void numerical_elem_jacobian (FEMContext &context) const
 Uses the results of multiple element_residual() calls to numerically differentiate the corresponding jacobian on an element. More...
 
void numerical_side_jacobian (FEMContext &context) const
 Uses the results of multiple side_residual() calls to numerically differentiate the corresponding jacobian on an element's side. More...
 
void numerical_nonlocal_jacobian (FEMContext &context) const
 Uses the results of multiple side_residual() calls to numerically differentiate the corresponding jacobian on nonlocal DoFs. More...
 
virtual void reinit () libmesh_override
 Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be used. More...
 
virtual void assemble () libmesh_override
 Prepares matrix and rhs for matrix assembly. More...
 
virtual LinearSolver< Number > * get_linear_solver () const libmesh_override
 
virtual std::pair< unsigned int, Realget_linear_solve_parameters () const libmesh_override
 
virtual void release_linear_solver (LinearSolver< Number > *) const libmesh_override
 Releases a pointer to a linear solver acquired by this->get_linear_solver() More...
 
virtual std::pair< unsigned int, Realadjoint_solve (const QoISet &qoi_indices=QoISet()) libmesh_override
 This function sets the _is_adjoint boolean member of TimeSolver to true and then calls the adjoint_solve in implicit system. More...
 
virtual UniquePtr< DifferentiablePhysicsclone_physics () libmesh_override
 We don't allow systems to be attached to each other. More...
 
virtual UniquePtr< DifferentiableQoIclone () libmesh_override
 We don't allow systems to be attached to each other. More...
 
const DifferentiablePhysicsget_physics () const
 
DifferentiablePhysicsget_physics ()
 
void attach_physics (DifferentiablePhysics *physics_in)
 Attach external Physics object. More...
 
void swap_physics (DifferentiablePhysics *&swap_physics)
 Swap current physics object with external object. More...
 
const DifferentiableQoIget_qoi () const
 
DifferentiableQoIget_qoi ()
 
void attach_qoi (DifferentiableQoI *qoi_in)
 Attach external QoI object. More...
 
void set_time_solver (UniquePtr< TimeSolver > _time_solver)
 Sets the time_solver FIXME: This code is a little dangerous as it transfers ownership from the TimeSolver creator to this class. More...
 
TimeSolverget_time_solver ()
 
const TimeSolverget_time_solver () const
 Non-const version of the above. More...
 
virtual void element_postprocess (DiffContext &)
 Does any work that needs to be done on elem in a postprocessing loop. More...
 
virtual void side_postprocess (DiffContext &)
 Does any work that needs to be done on side of elem in a postprocessing loop. More...
 
unsigned int get_second_order_dot_var (unsigned int var) const
 For a given second order (in time) variable var, this method will return the index to the corresponding "dot" variable. More...
 
bool have_first_order_scalar_vars () const
 Check for any first order vars that are also belong to FEFamily::SCALAR. More...
 
bool have_second_order_scalar_vars () const
 Check for any second order vars that are also belong to FEFamily::SCALAR. More...
 
sys_typesystem ()
 
virtual void disable_cache () libmesh_override
 Avoids use of any cached data that might affect any solve result. More...
 
virtual std::string system_type () const libmesh_override
 
virtual void assemble_residual_derivatives (const ParameterVector &parameters) libmesh_override
 Residual parameter derivative function. More...
 
virtual std::pair< unsigned int, Realsensitivity_solve (const ParameterVector &parameters) libmesh_override
 Assembles & solves the linear system(s) (dR/du)*u_p = -dR/dp, for those parameters contained within parameters. More...
 
virtual std::pair< unsigned int, Realweighted_sensitivity_solve (const ParameterVector &parameters, const ParameterVector &weights) libmesh_override
 Assembles & solves the linear system(s) (dR/du)*u_w = sum(w_p*-dR/dp), for those parameters p contained within parameters weighted by the values w_p found within weights. More...
 
virtual std::pair< unsigned int, Realweighted_sensitivity_adjoint_solve (const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet()) libmesh_override
 Assembles & solves the linear system(s) (dR/du)^T*z_w = sum(w_p*(d^2q/dudp - d^2R/dudp*z)), for those parameters p contained within parameters, weighted by the values w_p found within weights. More...
 
virtual void adjoint_qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) libmesh_override
 Solves for the derivative of each of the system's quantities of interest q in qoi[qoi_indices] with respect to each parameter in parameters, placing the result for qoi i and parameter j into sensitivities[i][j]. More...
 
virtual void forward_qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) libmesh_override
 Solves for the derivative of each of the system's quantities of interest q in qoi[qoi_indices] with respect to each parameter in parameters, placing the result for qoi i and parameter j into sensitivities[i][j]. More...
 
virtual void qoi_parameter_hessian (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian) libmesh_override
 For each of the system's quantities of interest q in qoi[qoi_indices], and for a vector of parameters p, the parameter sensitivity Hessian H_ij is defined as H_ij = (d^2 q)/(d p_i d p_j) This Hessian is the output of this method, where for each q_i, H_jk is stored in hessian.second_derivative(i,j,k). More...
 
virtual void qoi_parameter_hessian_vector_product (const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product) libmesh_override
 For each of the system's quantities of interest q in qoi[qoi_indices], and for a vector of parameters p, the parameter sensitivity Hessian H_ij is defined as H_ij = (d^2 q)/(d p_i d p_j) The Hessian-vector product, for a vector v_k in parameter space, is S_j = H_jk v_k This product is the output of this method, where for each q_i, S_j is stored in sensitivities[i][j]. More...
 
SparseMatrix< Number > & add_matrix (const std::string &mat_name)
 Adds the additional matrix mat_name to this system. More...
 
void remove_matrix (const std::string &mat_name)
 Removes the additional matrix mat_name from this system. More...
 
bool have_matrix (const std::string &mat_name) const
 
const SparseMatrix< Number > * request_matrix (const std::string &mat_name) const
 
SparseMatrix< Number > * request_matrix (const std::string &mat_name)
 
const SparseMatrix< Number > & get_matrix (const std::string &mat_name) const
 
SparseMatrix< Number > & get_matrix (const std::string &mat_name)
 
virtual unsigned int n_matrices () const libmesh_override
 
void init ()
 Initializes degrees of freedom on the current mesh. More...
 
virtual void reinit_constraints ()
 Reinitializes the constraints for this system. More...
 
bool is_initialized ()
 
virtual void update ()
 Update the local values to reflect the solution on neighboring processors. More...
 
virtual void restrict_solve_to (const SystemSubset *subset, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO)
 After calling this method, any solve will be restricted to the given subdomain. More...
 
bool is_adjoint_already_solved () const
 Accessor for the adjoint_already_solved boolean. More...
 
void set_adjoint_already_solved (bool setting)
 Setter for the adjoint_already_solved boolean. More...
 
virtual void qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
 Solves for the derivative of each of the system's quantities of interest q in qoi[qoi_indices] with respect to each parameter in parameters, placing the result for qoi i and parameter j into sensitivities[i][j]. More...
 
virtual bool compare (const System &other_system, const Real threshold, const bool verbose) const
 
const std::string & name () const
 
void project_solution (FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr) const
 Projects arbitrary functions onto the current solution. More...
 
void project_solution (FEMFunctionBase< Number > *f, FEMFunctionBase< Gradient > *g=libmesh_nullptr) const
 Projects arbitrary functions onto the current solution. More...
 
void project_solution (Number fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), Gradient gptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), const Parameters &parameters) const
 Projects arbitrary functions onto the current solution. More...
 
void project_vector (NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
 Projects arbitrary functions onto a vector of degree of freedom values for the current system. More...
 
void project_vector (NumericVector< Number > &new_vector, FEMFunctionBase< Number > *f, FEMFunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
 Projects arbitrary functions onto a vector of degree of freedom values for the current system. More...
 
void project_vector (Number fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), Gradient gptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), const Parameters &parameters, NumericVector< Number > &new_vector, int is_adjoint=-1) const
 Projects arbitrary functions onto a vector of degree of freedom values for the current system. More...
 
void boundary_project_solution (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr)
 Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system. More...
 
void boundary_project_solution (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, Number fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), Gradient gptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), const Parameters &parameters)
 Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system. More...
 
void boundary_project_vector (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
 Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system. More...
 
void boundary_project_vector (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, Number fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), Gradient gptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), const Parameters &parameters, NumericVector< Number > &new_vector, int is_adjoint=-1) const
 Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system. More...
 
unsigned int number () const
 
void update_global_solution (std::vector< Number > &global_soln) const
 Fill the input vector global_soln so that it contains the global solution on all processors. More...
 
void update_global_solution (std::vector< Number > &global_soln, const processor_id_type dest_proc) const
 Fill the input vector global_soln so that it contains the global solution on processor dest_proc. More...
 
const MeshBaseget_mesh () const
 
MeshBaseget_mesh ()
 
const DofMapget_dof_map () const
 
DofMapget_dof_map ()
 
const EquationSystemsget_equation_systems () const
 
EquationSystemsget_equation_systems ()
 
bool active () const
 
void activate ()
 Activates the system. More...
 
void deactivate ()
 Deactivates the system. More...
 
void set_basic_system_only ()
 Sets the system to be "basic only": i.e. More...
 
vectors_iterator vectors_begin ()
 Beginning of vectors container. More...
 
const_vectors_iterator vectors_begin () const
 Beginning of vectors container. More...
 
vectors_iterator vectors_end ()
 End of vectors container. More...
 
const_vectors_iterator vectors_end () const
 End of vectors container. More...
 
NumericVector< Number > & add_vector (const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
 Adds the additional vector vec_name to this system. More...
 
void remove_vector (const std::string &vec_name)
 Removes the additional vector vec_name from this system. More...
 
bool & project_solution_on_reinit (void)
 Tells the System whether or not to project the solution vector onto new grids when the system is reinitialized. More...
 
bool have_vector (const std::string &vec_name) const
 
const NumericVector< Number > * request_vector (const std::string &vec_name) const
 
NumericVector< Number > * request_vector (const std::string &vec_name)
 
const NumericVector< Number > * request_vector (const unsigned int vec_num) const
 
NumericVector< Number > * request_vector (const unsigned int vec_num)
 
const NumericVector< Number > & get_vector (const std::string &vec_name) const
 
NumericVector< Number > & get_vector (const std::string &vec_name)
 
const NumericVector< Number > & get_vector (const unsigned int vec_num) const
 
NumericVector< Number > & get_vector (const unsigned int vec_num)
 
const std::string & vector_name (const unsigned int vec_num) const
 
const std::string & vector_name (const NumericVector< Number > &vec_reference) const
 
void set_vector_as_adjoint (const std::string &vec_name, int qoi_num)
 Allows one to set the QoI index controlling whether the vector identified by vec_name represents a solution from the adjoint (qoi_num >= 0) or primal (qoi_num == -1) space. More...
 
int vector_is_adjoint (const std::string &vec_name) const
 
void set_vector_preservation (const std::string &vec_name, bool preserve)
 Allows one to set the boolean controlling whether the vector identified by vec_name should be "preserved": projected to new meshes, saved, etc. More...
 
bool vector_preservation (const std::string &vec_name) const
 
NumericVector< Number > & add_adjoint_solution (unsigned int i=0)
 
NumericVector< Number > & get_adjoint_solution (unsigned int i=0)
 
const NumericVector< Number > & get_adjoint_solution (unsigned int i=0) const
 
NumericVector< Number > & add_sensitivity_solution (unsigned int i=0)
 
NumericVector< Number > & get_sensitivity_solution (unsigned int i=0)
 
const NumericVector< Number > & get_sensitivity_solution (unsigned int i=0) const
 
NumericVector< Number > & add_weighted_sensitivity_adjoint_solution (unsigned int i=0)
 
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution (unsigned int i=0)
 
const NumericVector< Number > & get_weighted_sensitivity_adjoint_solution (unsigned int i=0) const
 
NumericVector< Number > & add_weighted_sensitivity_solution ()
 
NumericVector< Number > & get_weighted_sensitivity_solution ()
 
const NumericVector< Number > & get_weighted_sensitivity_solution () const
 
NumericVector< Number > & add_adjoint_rhs (unsigned int i=0)
 
NumericVector< Number > & get_adjoint_rhs (unsigned int i=0)
 
const NumericVector< Number > & get_adjoint_rhs (unsigned int i=0) const
 
NumericVector< Number > & add_sensitivity_rhs (unsigned int i=0)
 
NumericVector< Number > & get_sensitivity_rhs (unsigned int i=0)
 
const NumericVector< Number > & get_sensitivity_rhs (unsigned int i=0) const
 
unsigned int n_vectors () const
 
unsigned int n_vars () const
 
unsigned int n_variable_groups () const
 
unsigned int n_components () const
 
dof_id_type n_dofs () const
 
dof_id_type n_active_dofs () const
 
dof_id_type n_constrained_dofs () const
 
dof_id_type n_local_constrained_dofs () const
 
dof_id_type n_local_dofs () const
 
unsigned int add_variable (const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
 Adds the variable var to the list of variables for this system. More...
 
unsigned int add_variable (const std::string &var, const Order order=FIRST, const FEFamily=LAGRANGE, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
 Adds the variable var to the list of variables for this system. More...
 
unsigned int add_variables (const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
 Adds the variable var to the list of variables for this system. More...
 
unsigned int add_variables (const std::vector< std::string > &vars, const Order order=FIRST, const FEFamily=LAGRANGE, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
 Adds the variable var to the list of variables for this system. More...
 
const Variablevariable (unsigned int var) const
 Return a constant reference to Variable var. More...
 
const VariableGroupvariable_group (unsigned int vg) const
 Return a constant reference to VariableGroup vg. More...
 
bool has_variable (const std::string &var) const
 
const std::string & variable_name (const unsigned int i) const
 
unsigned short int variable_number (const std::string &var) const
 
void get_all_variable_numbers (std::vector< unsigned int > &all_variable_numbers) const
 Fills all_variable_numbers with all the variable numbers for the variables that have been added to this system. More...
 
unsigned int variable_scalar_number (const std::string &var, unsigned int component) const
 
unsigned int variable_scalar_number (unsigned int var_num, unsigned int component) const
 
const FETypevariable_type (const unsigned int i) const
 
const FETypevariable_type (const std::string &var) const
 
bool identify_variable_groups () const
 
void identify_variable_groups (const bool)
 Toggle automatic VariableGroup identification. More...
 
Real calculate_norm (const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=libmesh_nullptr) const
 
Real calculate_norm (const NumericVector< Number > &v, const SystemNorm &norm, std::set< unsigned int > *skip_dimensions=libmesh_nullptr) const
 
void read_header (Xdr &io, const std::string &version, const bool read_header=true, const bool read_additional_data=true, const bool read_legacy_format=false)
 Reads the basic data header for this System. More...
 
void read_legacy_data (Xdr &io, const bool read_additional_data=true)
 Reads additional data, namely vectors, for this System. More...
 
template<typename ValType >
void read_serialized_data (Xdr &io, const bool read_additional_data=true)
 Reads additional data, namely vectors, for this System. More...
 
void read_serialized_data (Xdr &io, const bool read_additional_data=true)
 Non-templated version for backward compatibility. More...
 
template<typename InValType >
std::size_t read_serialized_vectors (Xdr &io, const std::vector< NumericVector< Number > * > &vectors) const
 Read a number of identically distributed vectors. More...
 
std::size_t read_serialized_vectors (Xdr &io, const std::vector< NumericVector< Number > * > &vectors) const
 Non-templated version for backward compatibility. More...
 
template<typename InValType >
void read_parallel_data (Xdr &io, const bool read_additional_data)
 Reads additional data, namely vectors, for this System. More...
 
void read_parallel_data (Xdr &io, const bool read_additional_data)
 Non-templated version for backward compatibility. More...
 
void write_header (Xdr &io, const std::string &version, const bool write_additional_data) const
 Writes the basic data header for this System. More...
 
void write_serialized_data (Xdr &io, const bool write_additional_data=true) const
 Writes additional data, namely vectors, for this System. More...
 
std::size_t write_serialized_vectors (Xdr &io, const std::vector< const NumericVector< Number > * > &vectors) const
 Serialize & write a number of identically distributed vectors. More...
 
void write_parallel_data (Xdr &io, const bool write_additional_data) const
 Writes additional data, namely vectors, for this System. More...
 
std::string get_info () const
 
void attach_init_function (void fptr(EquationSystems &es, const std::string &name))
 Register a user function to use in initializing the system. More...
 
void attach_init_object (Initialization &init)
 Register a user class to use to initialize the system. More...
 
void attach_assemble_function (void fptr(EquationSystems &es, const std::string &name))
 Register a user function to use in assembling the system matrix and RHS. More...
 
void attach_assemble_object (Assembly &assemble)
 Register a user object to use in assembling the system matrix and RHS. More...
 
void attach_constraint_function (void fptr(EquationSystems &es, const std::string &name))
 Register a user function for imposing constraints. More...
 
void attach_constraint_object (Constraint &constrain)
 Register a user object for imposing constraints. More...
 
void attach_QOI_function (void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices))
 Register a user function for evaluating the quantities of interest, whose values should be placed in System::qoi. More...
 
void attach_QOI_object (QOI &qoi)
 Register a user object for evaluating the quantities of interest, whose values should be placed in System::qoi. More...
 
void attach_QOI_derivative (void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints))
 Register a user function for evaluating derivatives of a quantity of interest with respect to test functions, whose values should be placed in System::rhs. More...
 
void attach_QOI_derivative_object (QOIDerivative &qoi_derivative)
 Register a user object for evaluating derivatives of a quantity of interest with respect to test functions, whose values should be placed in System::rhs. More...
 
virtual void user_initialization ()
 Calls user's attached initialization function, or is overridden by the user in derived classes. More...
 
virtual void user_assembly ()
 Calls user's attached assembly function, or is overridden by the user in derived classes. More...
 
virtual void user_constrain ()
 Calls user's attached constraint function, or is overridden by the user in derived classes. More...
 
virtual void user_QOI (const QoISet &qoi_indices)
 Calls user's attached quantity of interest function, or is overridden by the user in derived classes. More...
 
virtual void user_QOI_derivative (const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
 Calls user's attached quantity of interest derivative function, or is overridden by the user in derived classes. More...
 
virtual void re_update ()
 Re-update the local values when the mesh has changed. More...
 
virtual void restrict_vectors ()
 Restrict vectors after the mesh has coarsened. More...
 
virtual void prolong_vectors ()
 Prolong vectors after the mesh has refined. More...
 
Number current_solution (const dof_id_type global_dof_number) const
 
Number point_value (unsigned int var, const Point &p, const bool insist_on_success=true) const
 
Number point_value (unsigned int var, const Point &p, const Elem &e) const
 
Number point_value (unsigned int var, const Point &p, const Elem *e) const
 Calls the version of point_value() which takes a reference. More...
 
Gradient point_gradient (unsigned int var, const Point &p, const bool insist_on_success=true) const
 
Gradient point_gradient (unsigned int var, const Point &p, const Elem &e) const
 
Gradient point_gradient (unsigned int var, const Point &p, const Elem *e) const
 Calls the version of point_gradient() which takes a reference. More...
 
Tensor point_hessian (unsigned int var, const Point &p, const bool insist_on_success=true) const
 
Tensor point_hessian (unsigned int var, const Point &p, const Elem &e) const
 
Tensor point_hessian (unsigned int var, const Point &p, const Elem *e) const
 Calls the version of point_hessian() which takes a reference. More...
 
void local_dof_indices (const unsigned int var, std::set< dof_id_type > &var_indices) const
 Fills the std::set with the degrees of freedom on the local processor corresponding the the variable number passed in. More...
 
void zero_variable (NumericVector< Number > &v, unsigned int var_num) const
 Zeroes all dofs in v that correspond to variable number var_num. More...
 
bool & hide_output ()
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
virtual void clear_physics ()
 Clear any data structures associated with the physics. More...
 
virtual void init_physics (const System &sys)
 Initialize any data structures associated with the physics. More...
 
virtual bool element_time_derivative (bool request_jacobian, DiffContext &)
 Adds the time derivative contribution on elem to elem_residual. More...
 
virtual bool element_constraint (bool request_jacobian, DiffContext &)
 Adds the constraint contribution on elem to elem_residual. More...
 
virtual bool side_time_derivative (bool request_jacobian, DiffContext &)
 Adds the time derivative contribution on side of elem to elem_residual. More...
 
virtual bool side_constraint (bool request_jacobian, DiffContext &)
 Adds the constraint contribution on side of elem to elem_residual. More...
 
virtual bool nonlocal_time_derivative (bool request_jacobian, DiffContext &)
 Adds any nonlocal time derivative contributions (e.g. More...
 
virtual bool nonlocal_constraint (bool request_jacobian, DiffContext &)
 Adds any nonlocal constraint contributions (e.g. More...
 
virtual void time_evolving (unsigned int var)
 Tells the DiffSystem that variable var is evolving with respect to time. More...
 
virtual void time_evolving (unsigned int var, unsigned int order)
 Tells the DiffSystem that variable var is evolving with respect to time. More...
 
bool is_time_evolving (unsigned int var) const
 
virtual bool eulerian_residual (bool request_jacobian, DiffContext &)
 Adds a pseudo-convection contribution on elem to elem_residual, if the nodes of elem are being translated by a moving mesh. More...
 
virtual bool eulerian_residual (bool request_jacobian, DiffContext &context) libmesh_override
 Adds a pseudo-convection contribution on elem to elem_residual, if the nodes of elem are being translated by a moving mesh. More...
 
virtual bool mass_residual (bool request_jacobian, DiffContext &)
 Subtracts a mass vector contribution on elem from elem_residual. More...
 
virtual bool mass_residual (bool request_jacobian, DiffContext &) libmesh_override
 Subtracts a mass vector contribution on elem from elem_residual. More...
 
virtual bool side_mass_residual (bool request_jacobian, DiffContext &)
 Subtracts a mass vector contribution on side of elem from elem_residual. More...
 
virtual bool nonlocal_mass_residual (bool request_jacobian, DiffContext &c)
 Subtracts any nonlocal mass vector contributions (e.g. More...
 
virtual bool damping_residual (bool request_jacobian, DiffContext &)
 Subtracts a damping vector contribution on elem from elem_residual. More...
 
virtual bool side_damping_residual (bool request_jacobian, DiffContext &)
 Subtracts a damping vector contribution on side of elem from elem_residual. More...
 
virtual bool nonlocal_damping_residual (bool request_jacobian, DiffContext &)
 Subtracts any nonlocal damping vector contributions (e.g. More...
 
virtual void set_mesh_system (System *sys)
 Tells the DifferentiablePhysics that system sys contains the isoparametric Lagrangian variables which correspond to the coordinates of mesh nodes, in problems where the mesh itself is expected to move in time. More...
 
const Systemget_mesh_system () const
 
Systemget_mesh_system ()
 
virtual void set_mesh_x_var (unsigned int var)
 Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the x coordinate of mesh nodes, in problems where the mesh itself is expected to move in time. More...
 
unsigned int get_mesh_x_var () const
 
virtual void set_mesh_y_var (unsigned int var)
 Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the y coordinate of mesh nodes. More...
 
unsigned int get_mesh_y_var () const
 
virtual void set_mesh_z_var (unsigned int var)
 Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the z coordinate of mesh nodes. More...
 
unsigned int get_mesh_z_var () const
 
bool _eulerian_time_deriv (bool request_jacobian, DiffContext &)
 This method simply combines element_time_derivative() and eulerian_residual(), which makes its address useful as a pointer-to-member-function when refactoring. More...
 
bool have_first_order_vars () const
 
const std::set< unsigned int > & get_first_order_vars () const
 
bool is_first_order_var (unsigned int var) const
 
bool have_second_order_vars () const
 
const std::set< unsigned int > & get_second_order_vars () const
 
bool is_second_order_var (unsigned int var) const
 
virtual void init_qoi (std::vector< Number > &)
 Initialize system qoi. More...
 
virtual void clear_qoi ()
 Clear all the data structures associated with the QoI. More...
 
virtual void element_qoi (DiffContext &, const QoISet &)
 Does any work that needs to be done on elem in a quantity of interest assembly loop, outputting to elem_qoi. More...
 
virtual void element_qoi_derivative (DiffContext &, const QoISet &)
 Does any work that needs to be done on elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative. More...
 
virtual void side_qoi (DiffContext &, const QoISet &)
 Does any work that needs to be done on side of elem in a quantity of interest assembly loop, outputting to elem_qoi. More...
 
virtual void side_qoi_derivative (DiffContext &, const QoISet &)
 Does any work that needs to be done on side of elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative. More...
 
virtual void thread_join (std::vector< Number > &qoi, const std::vector< Number > &other_qoi, const QoISet &qoi_indices)
 Method to combine thread-local qois. More...
 
virtual void parallel_op (const Parallel::Communicator &communicator, std::vector< Number > &sys_qoi, std::vector< Number > &local_qoi, const QoISet &qoi_indices)
 Method to populate system qoi data structure with process-local qoi. More...
 
virtual void finalize_derivative (NumericVector< Number > &derivatives, std::size_t qoi_index)
 Method to finalize qoi derivatives which require more than just a simple sum of element contributions. More...
 

Static Public Member Functions

static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Public Attributes

Realcontinuation_parameter
 The continuation parameter must be a member variable of the derived class, and the "continuation_parameter" pointer defined here must be a pointer to that variable. More...
 
bool quiet
 If quiet==false, the System prints extra information about what it is doing. More...
 
Real continuation_parameter_tolerance
 How tightly should the Newton iterations attempt to converge delta_lambda. More...
 
Real solution_tolerance
 How tightly should the Newton iterations attempt to converge ||delta_u|| Defaults to 1.e-6. More...
 
Real initial_newton_tolerance
 How much to try to reduce the residual by at the first (inexact) Newton step. More...
 
Real old_continuation_parameter
 The system also keeps track of the old value of the continuation parameter. More...
 
Real min_continuation_parameter
 The minimum-allowable value of the continuation parameter. More...
 
Real max_continuation_parameter
 The maximum-allowable value of the continuation parameter. More...
 
Real Theta
 Arclength normalization parameter. More...
 
Real Theta_LOCA
 Another normalization parameter, which is described in the LOCA manual. More...
 
unsigned int n_backtrack_steps
 Another scaling parameter suggested by the LOCA people. More...
 
unsigned int n_arclength_reductions
 Number of arclength reductions to try when Newton fails to reduce the residual. More...
 
Real ds_min
 The minimum-allowed steplength, defaults to 1.e-8. More...
 
Predictor predictor
 
Real newton_stepgrowth_aggressiveness
 A measure of how rapidly one should attempt to grow the arclength stepsize based on the number of Newton iterations required to solve the problem. More...
 
bool newton_progress_check
 True by default, the Newton progress check allows the Newton loop to exit if half the allowed iterations have elapsed without a reduction in the initial residual. More...
 
bool fe_reinit_during_postprocess
 If fe_reinit_during_postprocess is true (it is true by default), FE objects will be reinit()ed with their default quadrature rules. More...
 
Real numerical_jacobian_h
 If calculating numeric jacobians is required, the FEMSystem will perturb each solution vector entry by numerical_jacobian_h when calculating finite differences. More...
 
Real verify_analytic_jacobians
 If verify_analytic_jacobian is equal to zero (as it is by default), no numeric jacobians will be calculated unless an overridden element_time_derivative(), element_constraint(), side_time_derivative(), or side_constraint() function cannot provide an analytic jacobian upon request. More...
 
UniquePtr< TimeSolvertime_solver
 A pointer to the solver object we're going to use. More...
 
Real deltat
 For time-dependent problems, this is the amount delta t to advance the solution in time. More...
 
bool postprocess_sides
 If postprocess_sides is true (it is false by default), the postprocessing loop will loop over all sides as well as all elements. More...
 
bool print_solution_norms
 Set print_residual_norms to true to print |U| whenever it is used in an assembly() call. More...
 
bool print_solutions
 Set print_solutions to true to print U whenever it is used in an assembly() call. More...
 
bool print_residual_norms
 Set print_residual_norms to true to print |F| whenever it is assembled. More...
 
bool print_residuals
 Set print_residuals to true to print F whenever it is assembled. More...
 
bool print_jacobian_norms
 Set print_jacobian_norms to true to print |J| whenever it is assembled. More...
 
bool print_jacobians
 Set print_jacobians to true to print J whenever it is assembled. More...
 
bool print_element_solutions
 Set print_element_solutions to true to print each U_elem input. More...
 
bool print_element_residuals
 Set print_element_residuals to true to print each R_elem contribution. More...
 
bool print_element_jacobians
 Set print_element_jacobians to true to print each J_elem contribution. More...
 
SparseMatrix< Number > * matrix
 The system matrix. More...
 
bool zero_out_matrix_and_rhs
 By default, the system will zero out the matrix and the right hand side. More...
 
NumericVector< Number > * rhs
 The system matrix. More...
 
bool assemble_before_solve
 Flag which tells the system to whether or not to call the user assembly function during each call to solve(). More...
 
bool use_fixed_solution
 A boolean to be set to true by systems using elem_fixed_solution, for optional use by e.g. More...
 
int extra_quadrature_order
 A member int that can be employed to indicate increased or reduced quadrature order. More...
 
UniquePtr< NumericVector< Number > > solution
 Data structure to hold solution values. More...
 
UniquePtr< NumericVector< Number > > current_local_solution
 All the values I need to compute my contribution to the simulation at hand. More...
 
Real time
 For time-dependent problems, this is the time t at the beginning of the current timestep. More...
 
std::vector< Numberqoi
 Values of the quantities of interest. More...
 
bool compute_internal_sides
 compute_internal_sides is false by default, indicating that side_* computations will only be done on boundary sides. More...
 
bool assemble_qoi_sides
 If assemble_qoi_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over domain boundary sides. More...
 
bool assemble_qoi_internal_sides
 If assemble_qoi_internal_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over element sides which do not fall on domain boundaries. More...
 
bool assemble_qoi_elements
 If assemble_qoi_elements is false (it is true by default), the assembly loop for a quantity of interest or its derivatives will skip computing on mesh elements, and will only compute on mesh sides. More...
 

Protected Types

enum  RHS_Mode { Residual, G_Lambda }
 There are (so far) two different vectors which may be assembled using the assembly routine: 1.) The Residual = the normal PDE weighted residual 2.) G_Lambda = the derivative wrt the parameter lambda of the PDE weighted residual. More...
 
typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

virtual void init_data () libmesh_override
 Initializes the member data fields associated with the system, so that, e.g., assemble() may be used. More...
 
void add_second_order_dot_vars ()
 Helper function to add "velocity" variables that are cousins to second order-in-time variables in the DifferentiableSystem. More...
 
void add_dot_var_dirichlet_bcs (unsigned int var_idx, unsigned int dot_var_idx)
 Helper function to and Dirichlet boundary conditions to "dot" variable cousins of second order variables in the system. More...
 
virtual void init_matrices ()
 Initializes the matrices associated with this system. More...
 
void project_vector (NumericVector< Number > &, int is_adjoint=-1) const
 Projects the vector defined on the old mesh onto the new mesh. More...
 
void project_vector (const NumericVector< Number > &, NumericVector< Number > &, int is_adjoint=-1) const
 Projects the vector defined on the old mesh onto the new mesh. More...
 
void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Protected Attributes

RHS_Mode rhs_mode
 
DifferentiablePhysics_diff_physics
 Pointer to object to use for physics assembly evaluations. More...
 
DifferentiableQoIdiff_qoi
 Pointer to object to use for quantity of interest assembly evaluations. More...
 
const Parallel::Communicator_communicator
 
System_mesh_sys
 System from which to acquire moving mesh information. More...
 
unsigned int _mesh_x_var
 Variables from which to acquire moving mesh information. More...
 
unsigned int _mesh_y_var
 
unsigned int _mesh_z_var
 
std::vector< unsigned int_time_evolving
 Stores unsigned int to tell us which variables are evolving as first order in time (1), second order in time (2), or are not time evolving (0). More...
 
std::set< unsigned int_first_order_vars
 Variable indices for those variables that are first order in time. More...
 
std::set< unsigned int_second_order_vars
 Variable indices for those variables that are second order in time. More...
 
std::map< unsigned int, unsigned int_second_order_dot_vars
 If the user adds any second order variables, then we need to also cache the map to their corresponding dot variable that will be added by this TimeSolver class. More...
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int_n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called. More...
 

Private Member Functions

void initialize_tangent ()
 Before starting arclength continuation, we need at least 2 prior solutions (both solution and u_previous should be filled with meaningful values) And we need to initialize the tangent vector. More...
 
void solve_tangent ()
 Special solve algorithm for solving the tangent system. More...
 
void update_solution ()
 This function (which assumes the most recent tangent vector has been computed) updates the solution and the control parameter with the initial guess for the next point on the continuation path. More...
 
void set_Theta ()
 A centralized function for setting the normalization parameter theta. More...
 
void set_Theta_LOCA ()
 A centralized function for setting the other normalization parameter, i.e. More...
 
void apply_predictor ()
 Applies the predictor to the current solution to get a guess for the next solution. More...
 

Private Attributes

NumericVector< Number > * du_ds
 Extra work vectors used by the continuation algorithm. More...
 
NumericVector< Number > * previous_du_ds
 The value of du_ds from the previous solution. More...
 
NumericVector< Number > * previous_u
 The solution at the previous value of the continuation variable. More...
 
NumericVector< Number > * y
 Temporary vector "y" ... More...
 
NumericVector< Number > * y_old
 Temporary vector "y_old" ... More...
 
NumericVector< Number > * z
 Temporary vector "z" ... More...
 
NumericVector< Number > * delta_u
 Temporary vector "delta u" ... More...
 
UniquePtr< LinearSolver< Number > > linear_solver
 We maintain our own linear solver interface, for solving custom systems of equations and/or things which do not require a full-blown NewtonSolver. More...
 
bool tangent_initialized
 False until initialize_tangent() is called. More...
 
NewtonSolvernewton_solver
 A pointer to the underlying Newton solver used by the DiffSystem. More...
 
Real dlambda_ds
 The most recent value of the derivative of the continuation parameter with respect to s. More...
 
Real ds
 The initial arclength stepsize, selected by the user. More...
 
Real ds_current
 Value of stepsize currently in use. More...
 
Real previous_dlambda_ds
 The old parameter tangent value. More...
 
Real previous_ds
 The previous arcstep length used. More...
 
unsigned int newton_step
 Loop counter for nonlinear (Newton) iteration loop. More...
 

Detailed Description

This class inherits from the FEMSystem.

It can be used to do arclength continuation. Most of the ideas and the notation here come from HB Keller's 1977 paper:

* @InProceedings{Kell-1977,
*   author    = {H.~B.~Keller},
*   title     = {{Numerical solution of bifurcation and nonlinear eigenvalue problems}},
*   booktitle = {Applications of Bifurcation Theory, P.~H.~Rabinowitz (ed.)},
*   year      = 1977,
*   publisher = {Academic Press},
*   pages     = {359--389},
*   notes     = {QA 3 U45 No.\ 38 (PMA)}
* }
* 
Author
John W. Peterson
Date
2007

Definition at line 55 of file continuation_system.h.

Member Typedef Documentation

typedef std::map<std::string, SparseMatrix<Number> *>::const_iterator libMesh::ImplicitSystem::const_matrices_iterator
inherited

Definition at line 283 of file implicit_system.h.

typedef std::map<std::string, NumericVector<Number> *>::const_iterator libMesh::System::const_vectors_iterator
inherited

Definition at line 749 of file system.h.

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 119 of file reference_counter.h.

typedef std::map<std::string, SparseMatrix<Number> *>::iterator libMesh::ImplicitSystem::matrices_iterator
inherited

Matrix iterator typedefs.

Definition at line 282 of file implicit_system.h.

The type of the parent.

Definition at line 79 of file continuation_system.h.

The type of system.

Definition at line 74 of file continuation_system.h.

typedef bool(TimeSolver::* libMesh::FEMSystem::TimeSolverResPtr) (bool, DiffContext &)
inherited

Syntax sugar to make numerical_jacobian() declaration easier.

Definition at line 208 of file fem_system.h.

typedef std::map<std::string, NumericVector<Number> *>::iterator libMesh::System::vectors_iterator
inherited

Vector iterator typedefs.

Definition at line 748 of file system.h.

Member Enumeration Documentation

The code provides the ability to select from different predictor schemes for getting the initial guess for the solution at the next point on the solution arc.

Enumerator
Euler 

First-order Euler predictor.

AB2 

Second-order explicit Adams-Bashforth predictor.

Invalid_Predictor 

Invalid predictor.

Definition at line 221 of file continuation_system.h.

221  {
225  Euler,
226 
230  AB2,
231 
236  };
Second-order explicit Adams-Bashforth predictor.
First-order Euler predictor.

There are (so far) two different vectors which may be assembled using the assembly routine: 1.) The Residual = the normal PDE weighted residual 2.) G_Lambda = the derivative wrt the parameter lambda of the PDE weighted residual.

It is up to the derived class to handle writing separate assembly code for the different cases. Usually something like: switch (rhs_mode) { case Residual: { Fu(i) += ... // normal PDE residual break; }

case G_Lambda: { Fu(i) += ... // derivative wrt control parameter break; }

Enumerator
Residual 
G_Lambda 

Definition at line 286 of file continuation_system.h.

Constructor & Destructor Documentation

libMesh::ContinuationSystem::ContinuationSystem ( EquationSystems es,
const std::string &  name,
const unsigned int  number 
)

Constructor.

Optionally initializes required data structures.

Definition at line 29 of file continuation_system.C.

References linear_solver, libMesh::System::name(), and libMesh::on_command_line().

31  :
32  Parent(es, name_in, number_in),
34  quiet(true),
36  solution_tolerance(1.e-6),
41  Theta(1.),
42  Theta_LOCA(1.),
45  ds_min(1.e-8),
51  tangent_initialized(false),
53  dlambda_ds(0.707),
54  ds(0.1),
55  ds_current(0.1),
57  previous_ds(0.),
58  newton_step(0)
59 {
60  // Warn about using untested code
61  libmesh_experimental();
62 
63  if (libMesh::on_command_line("--solver_system_names"))
64  linear_solver->init((this->name()+"_").c_str());
65  else
66  linear_solver->init();
67 }
Real Theta
Arclength normalization parameter.
Real previous_dlambda_ds
The old parameter tangent value.
Real dlambda_ds
The most recent value of the derivative of the continuation parameter with respect to s...
UniquePtr< LinearSolver< Number > > linear_solver
We maintain our own linear solver interface, for solving custom systems of equations and/or things wh...
static UniquePtr< LinearSolver< Number > > build(const libMesh::Parallel::Communicator &comm_in, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a LinearSolver using the linear solver package specified by solver_package.
Real initial_newton_tolerance
How much to try to reduce the residual by at the first (inexact) Newton step.
Real old_continuation_parameter
The system also keeps track of the old value of the continuation parameter.
Real * continuation_parameter
The continuation parameter must be a member variable of the derived class, and the "continuation_para...
const class libmesh_nullptr_t libmesh_nullptr
Real solution_tolerance
How tightly should the Newton iterations attempt to converge ||delta_u|| Defaults to 1...
const std::string & name() const
Definition: system.h:1998
Real Theta_LOCA
Another normalization parameter, which is described in the LOCA manual.
Real ds_min
The minimum-allowed steplength, defaults to 1.e-8.
unsigned int n_arclength_reductions
Number of arclength reductions to try when Newton fails to reduce the residual.
bool tangent_initialized
False until initialize_tangent() is called.
Real max_continuation_parameter
The maximum-allowable value of the continuation parameter.
Real ds
The initial arclength stepsize, selected by the user.
Real newton_stepgrowth_aggressiveness
A measure of how rapidly one should attempt to grow the arclength stepsize based on the number of New...
bool quiet
If quiet==false, the System prints extra information about what it is doing.
Real previous_ds
The previous arcstep length used.
Real min_continuation_parameter
The minimum-allowable value of the continuation parameter.
Real ds_current
Value of stepsize currently in use.
NewtonSolver * newton_solver
A pointer to the underlying Newton solver used by the DiffSystem.
bool on_command_line(const std::string &arg)
Definition: libmesh.C:921
bool newton_progress_check
True by default, the Newton progress check allows the Newton loop to exit if half the allowed iterati...
unsigned int n_backtrack_steps
Another scaling parameter suggested by the LOCA people.
Real continuation_parameter_tolerance
How tightly should the Newton iterations attempt to converge delta_lambda.
FEMSystem Parent
The type of the parent.
First-order Euler predictor.
unsigned int newton_step
Loop counter for nonlinear (Newton) iteration loop.
libMesh::ContinuationSystem::~ContinuationSystem ( )
virtual

Destructor.

Definition at line 72 of file continuation_system.C.

References clear().

73 {
74  this->clear();
75 }
virtual void clear() libmesh_override
Clear all the data structures associated with the system.

Member Function Documentation

bool libMesh::DifferentiablePhysics::_eulerian_time_deriv ( bool  request_jacobian,
DiffContext context 
)
inherited

This method simply combines element_time_derivative() and eulerian_residual(), which makes its address useful as a pointer-to-member-function when refactoring.

Definition at line 102 of file diff_physics.C.

References libMesh::DifferentiablePhysics::element_time_derivative(), and libMesh::DifferentiablePhysics::eulerian_residual().

Referenced by libMesh::EulerSolver::element_residual(), libMesh::Euler2Solver::element_residual(), libMesh::NewmarkSolver::element_residual(), and libMesh::DifferentiablePhysics::init_context().

104 {
105  // For any problem we need time derivative terms
106  request_jacobian =
107  this->element_time_derivative(request_jacobian, context);
108 
109  // For a moving mesh problem we may need the pseudoconvection term too
110  return this->eulerian_residual(request_jacobian, context) &&
111  request_jacobian;
112 }
virtual bool element_time_derivative(bool request_jacobian, DiffContext &)
Adds the time derivative contribution on elem to elem_residual.
Definition: diff_physics.h:123
virtual bool eulerian_residual(bool request_jacobian, DiffContext &)
Adds a pseudo-convection contribution on elem to elem_residual, if the nodes of elem are being transl...
Definition: diff_physics.h:293
void libMesh::System::activate ( )
inherited

Activates the system.

Only active systems are solved.

Definition at line 2054 of file system.h.

References libMesh::System::_active.

Referenced by libMesh::System::get_equation_systems().

2055 {
2056  _active = true;
2057 }
bool _active
Flag stating if the system is active or not.
Definition: system.h:1908
bool libMesh::System::active ( ) const
inherited
Returns
true if the system is active, false otherwise. An active system will be solved.

Definition at line 2046 of file system.h.

References libMesh::System::_active.

Referenced by libMesh::System::get_equation_systems().

2047 {
2048  return _active;
2049 }
bool _active
Flag stating if the system is active or not.
Definition: system.h:1908
NumericVector< Number > & libMesh::System::add_adjoint_rhs ( unsigned int  i = 0)
inherited
Returns
A reference to one of the system's adjoint rhs vectors, by default the one corresponding to the first qoi. Creates the vector if it doesn't already exist.

Definition at line 1041 of file system.C.

References libMesh::System::add_vector().

Referenced by libMesh::ExplicitSystem::assemble_qoi_derivative(), libMesh::FEMSystem::assemble_qoi_derivative(), and libMesh::System::project_solution_on_reinit().

1042 {
1043  std::ostringstream adjoint_rhs_name;
1044  adjoint_rhs_name << "adjoint_rhs" << i;
1045 
1046  return this->add_vector(adjoint_rhs_name.str(), false);
1047 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:681
NumericVector< Number > & libMesh::System::add_adjoint_solution ( unsigned int  i = 0)
inherited
Returns
A reference to one of the system's adjoint solution vectors, by default the one corresponding to the first qoi. Creates the vector if it doesn't already exist.

Definition at line 977 of file system.C.

References libMesh::System::add_vector(), and libMesh::System::set_vector_as_adjoint().

Referenced by libMesh::ImplicitSystem::adjoint_solve(), and libMesh::System::project_solution_on_reinit().

978 {
979  std::ostringstream adjoint_name;
980  adjoint_name << "adjoint_solution" << i;
981 
982  NumericVector<Number> & returnval = this->add_vector(adjoint_name.str());
983  this->set_vector_as_adjoint(adjoint_name.str(), i);
984  return returnval;
985 }
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Allows one to set the QoI index controlling whether the vector identified by vec_name represents a so...
Definition: system.C:905
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:681
void libMesh::DifferentiableSystem::add_dot_var_dirichlet_bcs ( unsigned int  var_idx,
unsigned int  dot_var_idx 
)
protectedinherited

Helper function to and Dirichlet boundary conditions to "dot" variable cousins of second order variables in the system.

The function takes the second order variable index, it's corresponding "dot" variable index and then searches for DirichletBoundary objects for var_idx and then adds a DirichletBoundary object for dot_var_idx using the same boundary ids and functors for the var_idx DirichletBoundary.

Definition at line 228 of file diff_system.C.

References libMesh::DofMap::add_dirichlet_boundary(), libMesh::DirichletBoundary::b, libMesh::DirichletBoundary::f, libMesh::DirichletBoundary::f_fem, libMesh::DofMap::get_dirichlet_boundaries(), libMesh::System::get_dof_map(), libMesh::libmesh_assert(), and libMesh::DirichletBoundary::variables.

Referenced by libMesh::DifferentiableSystem::add_second_order_dot_vars().

230 {
231  // We're assuming that there could be a lot more variables than
232  // boundary conditions, so we search each of the boundary conditions
233  // for this variable rather than looping over boundary conditions
234  // in a separate loop and searching through all the variables.
235  const DirichletBoundaries * all_dbcs =
237 
238  if (all_dbcs)
239  {
240  // We need to cache the DBCs to be added so that we add them
241  // after looping over the existing DBCs. Otherwise, we're polluting
242  // the thing we're looping over.
243  std::vector<DirichletBoundary*> new_dbcs;
244 
245  DirichletBoundaries::const_iterator dbc_it = all_dbcs->begin();
246  for ( ; dbc_it != all_dbcs->end(); ++dbc_it )
247  {
248  libmesh_assert(*dbc_it);
249  DirichletBoundary & dbc = *(*dbc_it);
250 
251  // Look for second order variable in the current
252  // DirichletBoundary object
253  std::vector<unsigned int>::const_iterator dbc_var_it =
254  std::find( dbc.variables.begin(), dbc.variables.end(), var_idx );
255 
256  // If we found it, then we also need to add it's corresponding
257  // "dot" variable to a DirichletBoundary
258  std::vector<unsigned int> vars_to_add;
259  if (dbc_var_it != dbc.variables.end())
260  vars_to_add.push_back(dot_var_idx);
261 
262  if (!vars_to_add.empty())
263  {
264  // We need to check if the boundary condition is time-dependent.
265  // Currently, we cannot automatically differentiate w.r.t. time
266  // so if the user supplies a time-dependent Dirichlet BC, then
267  // we can't automatically support the Dirichlet BC for the
268  // "velocity" boundary condition, so we error. Otherwise,
269  // the "velocity boundary condition will just be zero.
270  bool is_time_evolving_bc = false;
271  if (dbc.f)
272  is_time_evolving_bc = dbc.f->is_time_dependent();
273  else if (dbc.f_fem)
274  // We it's a FEMFunctionBase object, it will be implicitly
275  // time-dependent since it is assumed to depend on the solution.
276  is_time_evolving_bc = true;
277  else
278  libmesh_error_msg("Could not find valid boundary function!");
279 
280  if (is_time_evolving_bc)
281  libmesh_error_msg("Cannot currently support time-dependent Dirichlet BC for dot variables!");
282 
283 
284  DirichletBoundary * new_dbc;
285 
286  if (dbc.f)
287  {
288  ZeroFunction<Number> zf;
289 
290  new_dbc = new DirichletBoundary(dbc.b, vars_to_add, zf);
291  }
292  else
293  libmesh_error();
294 
295  new_dbcs.push_back(new_dbc);
296  }
297  }
298 
299  // Now add the new DBCs for the "dot" vars to the DofMap
300  std::vector<DirichletBoundary*>::iterator new_dbc_it =
301  new_dbcs.begin();
302 
303  for ( ; new_dbc_it != new_dbcs.end(); ++new_dbc_it )
304  {
305  const DirichletBoundary & dbc = *(*new_dbc_it);
306  this->get_dof_map().add_dirichlet_boundary(dbc);
307  delete *new_dbc_it;
308  }
309 
310  } // if (all_dbcs)
311 }
libmesh_assert(j)
const DofMap & get_dof_map() const
Definition: system.h:2030
const DirichletBoundaries * get_dirichlet_boundaries() const
Definition: dof_map.h:1145
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
SparseMatrix< Number > & libMesh::ImplicitSystem::add_matrix ( const std::string &  mat_name)
inherited

Adds the additional matrix mat_name to this system.

Only allowed prior to assemble(). All additional matrices have the same sparsity pattern as the matrix used during solution. When not System but the user wants to initialize the mayor matrix, then all the additional matrices, if existent, have to be initialized by the user, too.

Definition at line 210 of file implicit_system.C.

References libMesh::ImplicitSystem::_can_add_matrices, libMesh::ImplicitSystem::_matrices, libMesh::SparseMatrix< T >::build(), libMesh::ParallelObject::comm(), and libMesh::ImplicitSystem::have_matrix().

Referenced by libMesh::ImplicitSystem::add_system_matrix(), libMesh::EigenTimeSolver::init(), main(), and libMesh::NewmarkSystem::NewmarkSystem().

211 {
212  // only add matrices before initializing...
213  if (!_can_add_matrices)
214  libmesh_error_msg("ERROR: Too late. Cannot add matrices to the system after initialization"
215  << "\n any more. You should have done this earlier.");
216 
217  // Return the matrix if it is already there.
218  if (this->have_matrix(mat_name))
219  return *(_matrices[mat_name]);
220 
221  // Otherwise build the matrix and return it.
222  SparseMatrix<Number> * buf = SparseMatrix<Number>::build(this->comm()).release();
223  _matrices.insert (std::make_pair (mat_name, buf));
224 
225  return *buf;
226 }
static UniquePtr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
std::map< std::string, SparseMatrix< Number > * > _matrices
Some systems need an arbitrary number of matrices.
bool have_matrix(const std::string &mat_name) const
bool _can_add_matrices
true when additional matrices may still be added, false otherwise.
const Parallel::Communicator & comm() const
void libMesh::DifferentiableSystem::add_second_order_dot_vars ( )
protectedinherited

Helper function to add "velocity" variables that are cousins to second order-in-time variables in the DifferentiableSystem.

This function is only called if the TimeSolver is a FirstOrderUnsteadySolver.

Definition at line 198 of file diff_system.C.

References libMesh::DifferentiablePhysics::_second_order_dot_vars, libMesh::Variable::active_subdomains(), libMesh::DifferentiableSystem::add_dot_var_dirichlet_bcs(), libMesh::System::add_variable(), libMesh::DifferentiablePhysics::get_second_order_vars(), libMesh::Variable::name(), libMesh::DifferentiablePhysics::time_evolving(), libMesh::Variable::type(), and libMesh::System::variable().

Referenced by libMesh::DifferentiableSystem::init_data().

199 {
200  const std::set<unsigned int> & second_order_vars = this->get_second_order_vars();
201  if (!second_order_vars.empty())
202  {
203  for (std::set<unsigned int>::const_iterator var_it = second_order_vars.begin();
204  var_it != second_order_vars.end(); ++var_it)
205  {
206  const Variable & var = this->variable(*var_it);
207  std::string new_var_name = std::string("dot_")+var.name();
208 
209  unsigned int v_var_idx;
210 
211  if (var.active_subdomains().empty())
212  v_var_idx = this->add_variable( new_var_name, var.type() );
213  else
214  v_var_idx = this->add_variable( new_var_name, var.type(), &var.active_subdomains() );
215 
216  _second_order_dot_vars.insert( std::pair<unsigned int,unsigned int>(*var_it,v_var_idx) );
217 
218  // The new velocities are time evolving variables of first order
219  this->time_evolving( v_var_idx, 1 );
220 
221  // And if there are any boundary conditions set on the second order
222  // variable, we also need to set it on its velocity variable.
223  this->add_dot_var_dirichlet_bcs( *var_it, v_var_idx );
224  }
225  }
226 }
const std::set< unsigned int > & get_second_order_vars() const
Definition: diff_physics.h:529
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1101
void add_dot_var_dirichlet_bcs(unsigned int var_idx, unsigned int dot_var_idx)
Helper function to and Dirichlet boundary conditions to "dot" variable cousins of second order variab...
Definition: diff_system.C:228
std::map< unsigned int, unsigned int > _second_order_dot_vars
If the user adds any second order variables, then we need to also cache the map to their correspondin...
Definition: diff_physics.h:570
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.h:2114
virtual void time_evolving(unsigned int var)
Tells the DiffSystem that variable var is evolving with respect to time.
Definition: diff_physics.h:248
NumericVector< Number > & libMesh::System::add_sensitivity_rhs ( unsigned int  i = 0)
inherited
Returns
A reference to one of the system's sensitivity rhs vectors, by default the one corresponding to the first parameter. Creates the vector if it doesn't already exist.

Definition at line 1071 of file system.C.

References libMesh::System::add_vector().

Referenced by libMesh::ImplicitSystem::assemble_residual_derivatives(), and libMesh::System::project_solution_on_reinit().

1072 {
1073  std::ostringstream sensitivity_rhs_name;
1074  sensitivity_rhs_name << "sensitivity_rhs" << i;
1075 
1076  return this->add_vector(sensitivity_rhs_name.str(), false);
1077 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:681
NumericVector< Number > & libMesh::System::add_sensitivity_solution ( unsigned int  i = 0)
inherited
Returns
A reference to one of the system's solution sensitivity vectors, by default the one corresponding to the first parameter. Creates the vector if it doesn't already exist.

Definition at line 926 of file system.C.

References libMesh::System::add_vector().

Referenced by libMesh::System::project_solution_on_reinit(), and libMesh::ImplicitSystem::sensitivity_solve().

927 {
928  std::ostringstream sensitivity_name;
929  sensitivity_name << "sensitivity_solution" << i;
930 
931  return this->add_vector(sensitivity_name.str());
932 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:681
unsigned int libMesh::System::add_variable ( const std::string &  var,
const FEType type,
const std::set< subdomain_id_type > *const  active_subdomains = libmesh_nullptr 
)
inherited

Adds the variable var to the list of variables for this system.

Returns
The index number for the new variable.

Definition at line 1101 of file system.C.

References libMesh::System::_variable_groups, libMesh::System::_variable_numbers, libMesh::System::_variables, libMesh::System::add_variables(), libMesh::VariableGroup::append(), libMesh::System::identify_variable_groups(), libMesh::System::is_initialized(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::System::n_variable_groups(), libMesh::System::n_vars(), libMesh::System::number(), libMesh::System::variable_name(), and libMesh::System::variable_type().

Referenced by libMesh::DifferentiableSystem::add_second_order_dot_vars(), libMesh::System::add_variable(), assemble_and_solve(), SolidSystem::init_data(), CurlCurlSystem::init_data(), HeatSystem::init_data(), main(), libMesh::ErrorVector::plot_error(), libMesh::System::project_solution_on_reinit(), ParsedFEMFunctionTest::setUp(), FETest< order, family, elem_type >::setUp(), SlitMeshRefinedSystemTest::setUp(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), DofMapTest::testDofOwner(), EquationSystemsTest::testPostInitAddElem(), EquationSystemsTest::testPostInitAddRealSystem(), SystemsTest::testProjectCube(), SystemsTest::testProjectCubeWithMeshFunction(), SystemsTest::testProjectLine(), SystemsTest::testProjectSquare(), EquationSystemsTest::testRefineThenReinitPreserveFlags(), BoundaryInfoTest::testShellFaceConstraints(), and WriteVecAndScalar::testWrite().

1104 {
1105  libmesh_assert(!this->is_initialized());
1106 
1107  // Make sure the variable isn't there already
1108  // or if it is, that it's the type we want
1109  for (unsigned int v=0; v<this->n_vars(); v++)
1110  if (this->variable_name(v) == var)
1111  {
1112  if (this->variable_type(v) == type)
1113  return _variables[v].number();
1114 
1115  libmesh_error_msg("ERROR: incompatible variable " << var << " has already been added for this system!");
1116  }
1117 
1118  // Optimize for VariableGroups here - if the user is adding multiple
1119  // variables of the same FEType and subdomain restriction, catch
1120  // that here and add them as members of the same VariableGroup.
1121  //
1122  // start by setting this flag to whatever the user has requested
1123  // and then consider the conditions which should negate it.
1124  bool should_be_in_vg = this->identify_variable_groups();
1125 
1126  // No variable groups, nothing to add to
1127  if (!this->n_variable_groups())
1128  should_be_in_vg = false;
1129 
1130  else
1131  {
1132  VariableGroup & vg(_variable_groups.back());
1133 
1134  // get a pointer to their subdomain restriction, if any.
1135  const std::set<subdomain_id_type> * const
1136  their_active_subdomains (vg.implicitly_active() ?
1137  libmesh_nullptr : &vg.active_subdomains());
1138 
1139  // Different types?
1140  if (vg.type() != type)
1141  should_be_in_vg = false;
1142 
1143  // they are restricted, we aren't?
1144  if (their_active_subdomains && !active_subdomains)
1145  should_be_in_vg = false;
1146 
1147  // they aren't restricted, we are?
1148  if (!their_active_subdomains && active_subdomains)
1149  should_be_in_vg = false;
1150 
1151  if (their_active_subdomains && active_subdomains)
1152  // restricted to different sets?
1153  if (*their_active_subdomains != *active_subdomains)
1154  should_be_in_vg = false;
1155 
1156  // OK, after all that, append the variable to the vg if none of the conditions
1157  // were violated
1158  if (should_be_in_vg)
1159  {
1160  const unsigned short curr_n_vars = cast_int<unsigned short>
1161  (this->n_vars());
1162 
1163  vg.append (var);
1164 
1165  _variables.push_back(vg(vg.n_variables()-1));
1166  _variable_numbers[var] = curr_n_vars;
1167  return curr_n_vars;
1168  }
1169  }
1170 
1171  // otherwise, fall back to adding a single variable group
1172  return this->add_variables (std::vector<std::string>(1, var),
1173  type,
1174  active_subdomains);
1175 }
std::map< std::string, unsigned short int > _variable_numbers
The variable numbers corresponding to user-specified names, useful for name-based lookups...
Definition: system.h:1903
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2134
const class libmesh_nullptr_t libmesh_nullptr
std::vector< Variable > _variables
The Variable in this System.
Definition: system.h:1892
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2164
libmesh_assert(j)
unsigned int n_variable_groups() const
Definition: system.h:2094
std::vector< VariableGroup > _variable_groups
The VariableGroup in this System.
Definition: system.h:1897
bool is_initialized()
Definition: system.h:2070
bool identify_variable_groups() const
Definition: system.h:2182
unsigned int number() const
Definition: system.h:2006
unsigned int add_variables(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1191
unsigned int n_vars() const
Definition: system.h:2086
unsigned int libMesh::System::add_variable ( const std::string &  var,
const Order  order = FIRST,
const FEFamily  family = LAGRANGE,
const std::set< subdomain_id_type > *const  active_subdomains = libmesh_nullptr 
)
inherited

Adds the variable var to the list of variables for this system.

Same as before, but assumes LAGRANGE as default value for FEType.family.

Definition at line 1179 of file system.C.

References libMesh::System::add_variable().

1183 {
1184  return this->add_variable(var,
1185  FEType(order, family),
1186  active_subdomains);
1187 }
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1101
unsigned int libMesh::System::add_variables ( const std::vector< std::string > &  vars,
const FEType type,
const std::set< subdomain_id_type > *const  active_subdomains = libmesh_nullptr 
)
inherited

Adds the variable var to the list of variables for this system.

Returns
The index number for the new variable.

Definition at line 1191 of file system.C.

References libMesh::System::_variable_groups, libMesh::System::_variable_numbers, libMesh::System::_variables, libMesh::System::is_initialized(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::System::n_components(), libMesh::System::n_vars(), libMesh::System::number(), libMesh::System::variable_name(), and libMesh::System::variable_type().

Referenced by libMesh::System::add_variable(), libMesh::System::add_variables(), and libMesh::System::project_solution_on_reinit().

1194 {
1195  libmesh_assert(!this->is_initialized());
1196 
1197  // Make sure the variable isn't there already
1198  // or if it is, that it's the type we want
1199  for (std::size_t ov=0; ov<vars.size(); ov++)
1200  for (unsigned int v=0; v<this->n_vars(); v++)
1201  if (this->variable_name(v) == vars[ov])
1202  {
1203  if (this->variable_type(v) == type)
1204  return _variables[v].number();
1205 
1206  libmesh_error_msg("ERROR: incompatible variable " << vars[ov] << " has already been added for this system!");
1207  }
1208 
1209  const unsigned short curr_n_vars = cast_int<unsigned short>
1210  (this->n_vars());
1211 
1212  const unsigned int next_first_component = this->n_components();
1213 
1214  // Add the variable group to the list
1215  _variable_groups.push_back((active_subdomains == libmesh_nullptr) ?
1216  VariableGroup(this, vars, curr_n_vars,
1217  next_first_component, type) :
1218  VariableGroup(this, vars, curr_n_vars,
1219  next_first_component, type, *active_subdomains));
1220 
1221  const VariableGroup & vg (_variable_groups.back());
1222 
1223  // Add each component of the group individually
1224  for (std::size_t v=0; v<vars.size(); v++)
1225  {
1226  _variables.push_back (vg(v));
1227  _variable_numbers[vars[v]] = cast_int<unsigned short>
1228  (curr_n_vars+v);
1229  }
1230 
1231  libmesh_assert_equal_to ((curr_n_vars+vars.size()), this->n_vars());
1232 
1233  // BSK - Defer this now to System::init_data() so we can detect
1234  // VariableGroups 12/28/2012
1235  // // Add the variable group to the _dof_map
1236  // _dof_map->add_variable_group (vg);
1237 
1238  // Return the number of the new variable
1239  return cast_int<unsigned int>(curr_n_vars+vars.size()-1);
1240 }
std::map< std::string, unsigned short int > _variable_numbers
The variable numbers corresponding to user-specified names, useful for name-based lookups...
Definition: system.h:1903
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2134
const class libmesh_nullptr_t libmesh_nullptr
std::vector< Variable > _variables
The Variable in this System.
Definition: system.h:1892
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2164
libmesh_assert(j)
unsigned int n_components() const
Definition: system.h:2102
std::vector< VariableGroup > _variable_groups
The VariableGroup in this System.
Definition: system.h:1897
bool is_initialized()
Definition: system.h:2070
unsigned int number() const
Definition: system.h:2006
unsigned int n_vars() const
Definition: system.h:2086
unsigned int libMesh::System::add_variables ( const std::vector< std::string > &  vars,
const Order  order = FIRST,
const FEFamily  family = LAGRANGE,
const std::set< subdomain_id_type > *const  active_subdomains = libmesh_nullptr 
)
inherited

Adds the variable var to the list of variables for this system.

Same as before, but assumes LAGRANGE as default value for FEType.family.

Definition at line 1244 of file system.C.

References libMesh::System::add_variables().

1248 {
1249  return this->add_variables(vars,
1250  FEType(order, family),
1251  active_subdomains);
1252 }
unsigned int add_variables(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1191
NumericVector< Number > & libMesh::System::add_vector ( const std::string &  vec_name,
const bool  projections = true,
const ParallelType  type = PARALLEL 
)
inherited

Adds the additional vector vec_name to this system.

All the additional vectors are similarly distributed, like the solution, and initialized to zero.

By default vectors added by add_vector are projected to changed grids by reinit(). To zero them instead (more efficient), pass "false" as the second argument

Definition at line 681 of file system.C.

References libMesh::System::_dof_map, libMesh::System::_is_initialized, libMesh::System::_vector_is_adjoint, libMesh::System::_vector_projections, libMesh::System::_vector_types, libMesh::System::_vectors, libMesh::NumericVector< T >::build(), libMesh::ParallelObject::comm(), libMesh::GHOSTED, libMesh::System::have_vector(), libMesh::NumericVector< T >::init(), libMesh::System::n_dofs(), and libMesh::System::n_local_dofs().

Referenced by libMesh::System::add_adjoint_rhs(), libMesh::System::add_adjoint_solution(), libMesh::System::add_sensitivity_rhs(), libMesh::System::add_sensitivity_solution(), libMesh::ExplicitSystem::add_system_rhs(), libMesh::System::add_weighted_sensitivity_adjoint_solution(), libMesh::System::add_weighted_sensitivity_solution(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::SecondOrderUnsteadySolver::init(), libMesh::UnsteadySolver::init(), libMesh::OptimizationSystem::init_data(), init_data(), main(), libMesh::NewmarkSystem::NewmarkSystem(), libMesh::FrequencySystem::set_frequencies(), libMesh::FrequencySystem::set_frequencies_by_range(), and libMesh::FrequencySystem::set_frequencies_by_steps().

684 {
685  // Return the vector if it is already there.
686  if (this->have_vector(vec_name))
687  return *(_vectors[vec_name]);
688 
689  // Otherwise build the vector
690  NumericVector<Number> * buf = NumericVector<Number>::build(this->comm()).release();
691  _vectors.insert (std::make_pair (vec_name, buf));
692  _vector_projections.insert (std::make_pair (vec_name, projections));
693 
694  _vector_types.insert (std::make_pair (vec_name, type));
695 
696  // Vectors are primal by default
697  _vector_is_adjoint.insert (std::make_pair (vec_name, -1));
698 
699  // Initialize it if necessary
700  if (_is_initialized)
701  {
702  if (type == GHOSTED)
703  {
704 #ifdef LIBMESH_ENABLE_GHOSTED
705  buf->init (this->n_dofs(), this->n_local_dofs(),
706  _dof_map->get_send_list(), false,
707  GHOSTED);
708 #else
709  libmesh_error_msg("Cannot initialize ghosted vectors when they are not enabled.");
710 #endif
711  }
712  else
713  buf->init (this->n_dofs(), this->n_local_dofs(), false, type);
714  }
715 
716  return *buf;
717 }
std::map< std::string, ParallelType > _vector_types
Holds the type of a vector.
Definition: system.h:1933
bool _is_initialized
true when additional vectors and variables do not require immediate initialization, false otherwise.
Definition: system.h:1952
UniquePtr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:1865
static UniquePtr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
bool have_vector(const std::string &vec_name) const
Definition: system.h:2206
std::map< std::string, int > _vector_is_adjoint
Holds non-negative if a vector by that name should be projected using adjoint constraints/BCs, -1 if primal.
Definition: system.h:1928
dof_id_type n_local_dofs() const
Definition: system.C:185
std::map< std::string, NumericVector< Number > * > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:1916
const Parallel::Communicator & comm() const
std::map< std::string, bool > _vector_projections
Holds true if a vector by that name should be projected onto a changed grid, false if it should be ze...
Definition: system.h:1922
dof_id_type n_dofs() const
Definition: system.C:148
NumericVector< Number > & libMesh::System::add_weighted_sensitivity_adjoint_solution ( unsigned int  i = 0)
inherited
Returns
A reference to one of the system's weighted sensitivity adjoint solution vectors, by default the one corresponding to the first qoi. Creates the vector if it doesn't already exist.

Definition at line 1009 of file system.C.

References libMesh::System::add_vector(), and libMesh::System::set_vector_as_adjoint().

Referenced by libMesh::System::project_solution_on_reinit(), and libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve().

1010 {
1011  std::ostringstream adjoint_name;
1012  adjoint_name << "weighted_sensitivity_adjoint_solution" << i;
1013 
1014  NumericVector<Number> & returnval = this->add_vector(adjoint_name.str());
1015  this->set_vector_as_adjoint(adjoint_name.str(), i);
1016  return returnval;
1017 }
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Allows one to set the QoI index controlling whether the vector identified by vec_name represents a so...
Definition: system.C:905
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:681
NumericVector< Number > & libMesh::System::add_weighted_sensitivity_solution ( )
inherited
Returns
A reference to the solution of the last weighted sensitivity solve Creates the vector if it doesn't already exist.

Definition at line 956 of file system.C.

References libMesh::System::add_vector().

Referenced by libMesh::System::project_solution_on_reinit(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

957 {
958  return this->add_vector("weighted_sensitivity_solution");
959 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:681
void libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity ( const QoISet qoi_indices,
const ParameterVector parameters,
SensitivityData sensitivities 
)
virtualinherited

Solves for the derivative of each of the system's quantities of interest q in qoi[qoi_indices] with respect to each parameter in parameters, placing the result for qoi i and parameter j into sensitivities[i][j].

Uses adjoint_solve() and the adjoint sensitivity method.

Currently uses finite differenced derivatives (partial q / partial p) and (partial R / partial p).

Reimplemented from libMesh::System.

Definition at line 708 of file implicit_system.C.

References std::abs(), libMesh::ImplicitSystem::adjoint_solve(), libMesh::SensitivityData::allocate_data(), libMesh::ExplicitSystem::assemble_qoi(), libMesh::ImplicitSystem::assemble_residual_derivatives(), libMesh::NumericVector< T >::dot(), libMesh::System::get_sensitivity_rhs(), libMesh::QoISet::has_index(), libMesh::System::is_adjoint_already_solved(), std::max(), libMesh::System::qoi, libMesh::Real, libMesh::ParameterVector::size(), and libMesh::TOLERANCE.

Referenced by libMesh::ImplicitSystem::assembly(), and main().

711 {
712  ParameterVector & parameters =
713  const_cast<ParameterVector &>(parameters_in);
714 
715  const unsigned int Np = cast_int<unsigned int>
716  (parameters.size());
717  const unsigned int Nq = cast_int<unsigned int>
718  (qoi.size());
719 
720  // An introduction to the problem:
721  //
722  // Residual R(u(p),p) = 0
723  // partial R / partial u = J = system matrix
724  //
725  // This implies that:
726  // d/dp(R) = 0
727  // (partial R / partial p) +
728  // (partial R / partial u) * (partial u / partial p) = 0
729 
730  // We first do an adjoint solve:
731  // J^T * z = (partial q / partial u)
732  // if we havent already or dont have an initial condition for the adjoint
733  if (!this->is_adjoint_already_solved())
734  {
735  this->adjoint_solve(qoi_indices);
736  }
737 
738  this->assemble_residual_derivatives(parameters_in);
739 
740  // Get ready to fill in sensitivities:
741  sensitivities.allocate_data(qoi_indices, *this, parameters);
742 
743  // We use the identities:
744  // dq/dp = (partial q / partial p) + (partial q / partial u) *
745  // (partial u / partial p)
746  // dq/dp = (partial q / partial p) + (J^T * z) *
747  // (partial u / partial p)
748  // dq/dp = (partial q / partial p) + z * J *
749  // (partial u / partial p)
750 
751  // Leading to our final formula:
752  // dq/dp = (partial q / partial p) - z * (partial R / partial p)
753 
754  // In the case of adjoints with heterogenous Dirichlet boundary
755  // function phi, where
756  // q := S(u) - R(u,phi)
757  // the final formula works out to:
758  // dq/dp = (partial S / partial p) - z * (partial R / partial p)
759  // Because we currently have no direct access to
760  // (partial S / partial p), we use the identity
761  // (partial S / partial p) = (partial q / partial p) +
762  // phi * (partial R / partial p)
763  // to derive an equivalent equation:
764  // dq/dp = (partial q / partial p) - (z-phi) * (partial R / partial p)
765 
766  // Since z-phi degrees of freedom are zero for constrained indices,
767  // we can use the same constrained -(partial R / partial p) that we
768  // use for forward sensitivity solves, taking into account the
769  // differing sign convention.
770  //
771  // Since that vector is constrained, its constrained indices are
772  // zero, so its product with phi is zero, so we can neglect the
773  // evaluation of phi terms.
774 
775  for (unsigned int j=0; j != Np; ++j)
776  {
777  // We currently get partial derivatives via central differencing
778 
779  // (partial q / partial p) ~= (q(p+dp)-q(p-dp))/(2*dp)
780  // (partial R / partial p) ~= (rhs(p+dp) - rhs(p-dp))/(2*dp)
781 
782  Number old_parameter = *parameters[j];
783 
784  const Real delta_p =
785  TOLERANCE * std::max(std::abs(old_parameter), 1e-3);
786 
787  *parameters[j] = old_parameter - delta_p;
788  this->assemble_qoi(qoi_indices);
789  std::vector<Number> qoi_minus = this->qoi;
790 
791  NumericVector<Number> & neg_partialR_partialp = this->get_sensitivity_rhs(j);
792 
793  *parameters[j] = old_parameter + delta_p;
794  this->assemble_qoi(qoi_indices);
795  std::vector<Number> & qoi_plus = this->qoi;
796 
797  std::vector<Number> partialq_partialp(Nq, 0);
798  for (unsigned int i=0; i != Nq; ++i)
799  if (qoi_indices.has_index(i))
800  partialq_partialp[i] = (qoi_plus[i] - qoi_minus[i]) / (2.*delta_p);
801 
802  // Don't leave the parameter changed
803  *parameters[j] = old_parameter;
804 
805  for (unsigned int i=0; i != Nq; ++i)
806  if (qoi_indices.has_index(i))
807  sensitivities[i][j] = partialq_partialp[i] +
808  neg_partialR_partialp.dot(this->get_adjoint_solution(i));
809  }
810 
811  // All parameters have been reset.
812  // Reset the original qoi.
813 
814  this->assemble_qoi(qoi_indices);
815 }
double abs(double a)
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) libmesh_override
Assembles & solves the linear system (dR/du)^T*z = dq/du, for those quantities of interest q specifie...
NumericVector< Number > & get_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1081
static const Real TOLERANCE
long double max(long double a, double b)
std::vector< Number > qoi
Values of the quantities of interest.
Definition: system.h:1553
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Definition: system.h:372
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) libmesh_override
Prepares qoi for quantity of interest assembly, then calls user qoi function.
virtual void assemble_residual_derivatives(const ParameterVector &parameters) libmesh_override
Residual parameter derivative function.
std::pair< unsigned int, Real > libMesh::DifferentiableSystem::adjoint_solve ( const QoISet qoi_indices = QoISet())
virtualinherited

This function sets the _is_adjoint boolean member of TimeSolver to true and then calls the adjoint_solve in implicit system.

Reimplemented from libMesh::ImplicitSystem.

Definition at line 164 of file diff_system.C.

References libMesh::ImplicitSystem::adjoint_solve(), libMesh::DifferentiableSystem::get_time_solver(), and libMesh::TimeSolver::set_is_adjoint().

Referenced by main().

165 {
166  // Get the time solver object associated with the system, and tell it that
167  // we are solving the adjoint problem
168  this->get_time_solver().set_is_adjoint(true);
169 
170  return this->ImplicitSystem::adjoint_solve(qoi_indices);
171 }
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) libmesh_override
Assembles & solves the linear system (dR/du)^T*z = dq/du, for those quantities of interest q specifie...
void set_is_adjoint(bool _is_adjoint_value)
Accessor for setting whether we need to do a primal or adjoint solve.
Definition: time_solver.h:239
TimeSolver & get_time_solver()
Definition: diff_system.h:402
void libMesh::ContinuationSystem::advance_arcstep ( )

Call this function after a continuation solve to compute the tangent and get the next initial guess.

Definition at line 936 of file continuation_system.C.

References solve_tangent(), and update_solution().

937 {
938  // Solve for the updated tangent du1/ds, d(lambda1)/ds
939  solve_tangent();
940 
941  // Advance the solution and the parameter to the next value.
942  update_solution();
943 }
void solve_tangent()
Special solve algorithm for solving the tangent system.
void update_solution()
This function (which assumes the most recent tangent vector has been computed) updates the solution a...
void libMesh::ContinuationSystem::apply_predictor ( )
private

Applies the predictor to the current solution to get a guess for the next solution.

Definition at line 1375 of file continuation_system.C.

References AB2, continuation_parameter, dlambda_ds, ds_current, du_ds, Euler, predictor, previous_dlambda_ds, previous_ds, previous_du_ds, libMesh::Real, and libMesh::System::solution.

Referenced by continuation_solve(), and update_solution().

1376 {
1377  if (predictor == Euler)
1378  {
1379  // 1.) Euler Predictor
1380  // Predict next the solution
1381  solution->add(ds_current, *du_ds);
1382  solution->close();
1383 
1384  // Predict next parameter value
1386  }
1387 
1388 
1389  else if (predictor == AB2)
1390  {
1391  // 2.) 2nd-order explicit AB predictor
1392  libmesh_assert_not_equal_to (previous_ds, 0.0);
1393  const Real stepratio = ds_current/previous_ds;
1394 
1395  // Build up next solution value.
1396  solution->add( 0.5*ds_current*(2.+stepratio), *du_ds);
1397  solution->add(-0.5*ds_current*stepratio , *previous_du_ds);
1398  solution->close();
1399 
1400  // Next parameter value
1402  0.5*ds_current*((2.+stepratio)*dlambda_ds -
1403  stepratio*previous_dlambda_ds);
1404  }
1405 
1406  else
1407  libmesh_error_msg("Unknown predictor!");
1408 }
Real previous_dlambda_ds
The old parameter tangent value.
Real dlambda_ds
The most recent value of the derivative of the continuation parameter with respect to s...
NumericVector< Number > * previous_du_ds
The value of du_ds from the previous solution.
Real * continuation_parameter
The continuation parameter must be a member variable of the derived class, and the "continuation_para...
NumericVector< Number > * du_ds
Extra work vectors used by the continuation algorithm.
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
Real previous_ds
The previous arcstep length used.
Real ds_current
Value of stepsize currently in use.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Second-order explicit Adams-Bashforth predictor.
First-order Euler predictor.
void libMesh::DifferentiableSystem::assemble ( )
virtualinherited

Prepares matrix and rhs for matrix assembly.

Users should not reimplement this

Reimplemented from libMesh::ImplicitSystem.

Definition at line 145 of file diff_system.C.

References libMesh::DifferentiableSystem::assembly().

146 {
147  this->assembly(true, true);
148 }
virtual void assembly(bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) libmesh_override=0
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
void FEMSystem::assemble_qoi ( const QoISet indices = QoISet())
virtualinherited

Runs a qoi assembly loop over all elements, and if assemble_qoi_sides is true over all sides.

Users may have to override this function if they have any quantities of interest that are not expressible as a sum of element qois.

Reimplemented from libMesh::ExplicitSystem.

Definition at line 1127 of file fem_system.C.

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::ParallelObject::comm(), libMesh::DifferentiableSystem::diff_qoi, libMesh::System::get_mesh(), libMesh::QoISet::has_index(), mesh, libMesh::DifferentiableQoI::parallel_op(), libMesh::Threads::parallel_reduce(), libMesh::System::qoi, libMesh::StoredRange< iterator_type, object_type >::reset(), and libMesh::System::update().

1128 {
1129  LOG_SCOPE("assemble_qoi()", "FEMSystem");
1130 
1131  const MeshBase & mesh = this->get_mesh();
1132 
1133  this->update();
1134 
1135  const unsigned int Nq = cast_int<unsigned int>(qoi.size());
1136 
1137  // the quantity of interest is assumed to be a sum of element and
1138  // side terms
1139  for (unsigned int i=0; i != Nq; ++i)
1140  if (qoi_indices.has_index(i))
1141  qoi[i] = 0;
1142 
1143  // Create a non-temporary qoi_contributions object, so we can query
1144  // its results after the reduction
1145  QoIContributions qoi_contributions(*this, *(this->diff_qoi), qoi_indices);
1146 
1147  // Loop over every active mesh element on this processor
1148  Threads::parallel_reduce(elem_range.reset(mesh.active_local_elements_begin(),
1149  mesh.active_local_elements_end()),
1150  qoi_contributions);
1151 
1152  this->diff_qoi->parallel_op( this->comm(), this->qoi, qoi_contributions.qoi, qoi_indices );
1153 }
virtual void parallel_op(const Parallel::Communicator &communicator, std::vector< Number > &sys_qoi, std::vector< Number > &local_qoi, const QoISet &qoi_indices)
Method to populate system qoi data structure with process-local qoi.
Definition: diff_qoi.C:39
MeshBase & mesh
This is the MeshBase class.
Definition: mesh_base.h:68
DifferentiableQoI * diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
Definition: diff_system.h:365
const MeshBase & get_mesh() const
Definition: system.h:2014
std::vector< Number > qoi
Values of the quantities of interest.
Definition: system.h:1553
virtual element_iterator active_local_elements_begin()=0
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:425
const Parallel::Communicator & comm() const
void parallel_reduce(const Range &range, Body &body)
Execute the provided reduction operation in parallel on the specified range.
Definition: threads_none.h:101
virtual element_iterator active_local_elements_end()=0
void FEMSystem::assemble_qoi_derivative ( const QoISet qoi_indices = QoISet(),
bool  include_liftfunc = true,
bool  apply_constraints = true 
)
virtualinherited

Runs a qoi derivative assembly loop over all elements, and if assemble_qoi_sides is true over all sides.

Users may have to override this function for quantities of interest that are not expressible as a sum of element qois.

Reimplemented from libMesh::ExplicitSystem.

Definition at line 1157 of file fem_system.C.

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::System::add_adjoint_rhs(), libMesh::DifferentiableSystem::diff_qoi, libMesh::DifferentiableQoI::finalize_derivative(), libMesh::System::get_mesh(), libMesh::QoISet::has_index(), mesh, libMesh::Threads::parallel_for(), libMesh::System::qoi, libMesh::StoredRange< iterator_type, object_type >::reset(), libMesh::System::update(), and libMesh::NumericVector< T >::zero().

1160 {
1161  LOG_SCOPE("assemble_qoi_derivative()", "FEMSystem");
1162 
1163  const MeshBase & mesh = this->get_mesh();
1164 
1165  this->update();
1166 
1167  // The quantity of interest derivative assembly accumulates on
1168  // initially zero vectors
1169  for (std::size_t i=0; i != qoi.size(); ++i)
1170  if (qoi_indices.has_index(i))
1171  this->add_adjoint_rhs(i).zero();
1172 
1173  // Loop over every active mesh element on this processor
1174  Threads::parallel_for (elem_range.reset(mesh.active_local_elements_begin(),
1175  mesh.active_local_elements_end()),
1176  QoIDerivativeContributions(*this, qoi_indices,
1177  *(this->diff_qoi),
1178  include_liftfunc,
1179  apply_constraints));
1180 
1181  for (std::size_t i=0; i != qoi.size(); ++i)
1182  if (qoi_indices.has_index(i))
1183  this->diff_qoi->finalize_derivative(this->get_adjoint_rhs(i),i);
1184 }
void parallel_for(const Range &range, const Body &body)
Execute the provided function object in parallel on the specified range.
Definition: threads_none.h:73
MeshBase & mesh
This is the MeshBase class.
Definition: mesh_base.h:68
virtual void zero()=0
Set all entries to zero.
DifferentiableQoI * diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
Definition: diff_system.h:365
const MeshBase & get_mesh() const
Definition: system.h:2014
std::vector< Number > qoi
Values of the quantities of interest.
Definition: system.h:1553
virtual element_iterator active_local_elements_begin()=0
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1041
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:425
virtual element_iterator active_local_elements_end()=0
bool has_index(unsigned int) const
Return whether or not this index is in the set to be calculated.
Definition: qoi_set.h:221
virtual void finalize_derivative(NumericVector< Number > &derivatives, std::size_t qoi_index)
Method to finalize qoi derivatives which require more than just a simple sum of element contributions...
Definition: diff_qoi.C:51
void libMesh::ImplicitSystem::assemble_residual_derivatives ( const ParameterVector parameters)
virtualinherited

Residual parameter derivative function.

Uses finite differences by default.

This will assemble the sensitivity rhs vectors to hold -(partial R / partial p_i), making them ready to solve the forward sensitivity equation.

Can be overridden in derived classes.

Reimplemented from libMesh::System.

Definition at line 665 of file implicit_system.C.

References std::abs(), libMesh::System::add_sensitivity_rhs(), libMesh::ImplicitSystem::assembly(), libMesh::NumericVector< T >::close(), std::max(), libMesh::Real, libMesh::ExplicitSystem::rhs, libMesh::ParameterVector::size(), and libMesh::TOLERANCE.

Referenced by libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity(), libMesh::ImplicitSystem::assembly(), and libMesh::ImplicitSystem::sensitivity_solve().

666 {
667  ParameterVector & parameters =
668  const_cast<ParameterVector &>(parameters_in);
669 
670  const unsigned int Np = cast_int<unsigned int>
671  (parameters.size());
672 
673  for (unsigned int p=0; p != Np; ++p)
674  {
675  NumericVector<Number> & sensitivity_rhs = this->add_sensitivity_rhs(p);
676 
677  // Approximate -(partial R / partial p) by
678  // (R(p-dp) - R(p+dp)) / (2*dp)
679 
680  Number old_parameter = *parameters[p];
681 
682  const Real delta_p =
683  TOLERANCE * std::max(std::abs(old_parameter), 1e-3);
684 
685  *parameters[p] -= delta_p;
686 
687  // this->assembly(true, false, true);
688  this->assembly(true, false, false);
689  this->rhs->close();
690  sensitivity_rhs = *this->rhs;
691 
692  *parameters[p] = old_parameter + delta_p;
693 
694  // this->assembly(true, false, true);
695  this->assembly(true, false, false);
696  this->rhs->close();
697 
698  sensitivity_rhs -= *this->rhs;
699  sensitivity_rhs /= (2*delta_p);
700  sensitivity_rhs.close();
701 
702  *parameters[p] = old_parameter;
703  }
704 }
double abs(double a)
NumericVector< Number > * rhs
The system matrix.
NumericVector< Number > & add_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1071
static const Real TOLERANCE
long double max(long double a, double b)
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void FEMSystem::assembly ( bool  get_residual,
bool  get_jacobian,
bool  apply_heterogeneous_constraints = false,
bool  apply_no_constraints = false 
)
virtualinherited

Prepares matrix or rhs for matrix assembly.

Users may reimplement this to add pre- or post-assembly code before or after calling FEMSystem::assembly()

Implements libMesh::DifferentiableSystem.

Definition at line 852 of file fem_system.C.

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::DenseMatrix< T >::add(), libMesh::FEMSystem::build_context(), libMesh::NumericVector< T >::close(), libMesh::SparseMatrix< T >::close(), libMesh::err, libMesh::FEType::family, libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::System::get_mesh(), libMesh::FEMSystem::init_context(), libMesh::NumericVector< T >::l1_norm(), libMesh::DenseMatrix< T >::l1_norm(), libMesh::SparseMatrix< T >::l1_norm(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::ImplicitSystem::matrix, std::max(), mesh, libMesh::ParallelObject::n_processors(), libMesh::System::n_variable_groups(), libMesh::FEMSystem::numerical_nonlocal_jacobian(), libMesh::out, libMesh::Threads::parallel_for(), libMesh::FEMContext::pre_fe_reinit(), libMesh::BasicOStreamProxy< charT, traits >::precision(), libMesh::DifferentiableSystem::print_jacobian_norms, libMesh::DifferentiableSystem::print_jacobians, libMesh::DifferentiableSystem::print_residual_norms, libMesh::DifferentiableSystem::print_residuals, libMesh::DifferentiableSystem::print_solution_norms, libMesh::DifferentiableSystem::print_solutions, libMesh::ParallelObject::processor_id(), libMesh::Real, libMesh::StoredRange< iterator_type, object_type >::reset(), libMesh::ExplicitSystem::rhs, libMesh::SCALAR, libMesh::DenseVector< T >::size(), libMesh::System::solution, libMesh::DifferentiableSystem::time_solver, libMesh::Variable::type(), libMesh::System::update(), libMesh::System::variable_group(), libMesh::FEMSystem::verify_analytic_jacobians, libMesh::DenseMatrix< T >::zero(), libMesh::SparseMatrix< T >::zero(), and libMesh::NumericVector< T >::zero().

Referenced by continuation_solve(), HeatSystem::perturb_accumulate_residuals(), and solve_tangent().

855 {
856  libmesh_assert(get_residual || get_jacobian);
857 
858 // Log residual and jacobian and combined performance separately
859 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
860  const char * log_name;
861  if (get_residual && get_jacobian)
862  log_name = "assembly()";
863  else if (get_residual)
864  log_name = "assembly(get_residual)";
865  else
866  log_name = "assembly(get_jacobian)";
867 
868  LOG_SCOPE(log_name, "FEMSystem");
869 #endif
870 
871  const MeshBase & mesh = this->get_mesh();
872 
873  // this->get_vector("_nonlinear_solution").localize
874  // (*current_local_nonlinear_solution,
875  // dof_map.get_send_list());
876  this->update();
877 
879  {
880  // this->get_vector("_nonlinear_solution").close();
881  this->solution->close();
882 
883  std::streamsize old_precision = libMesh::out.precision();
885  libMesh::out << "|U| = "
886  // << this->get_vector("_nonlinear_solution").l1_norm()
887  << this->solution->l1_norm()
888  << std::endl;
889  libMesh::out.precision(old_precision);
890  }
891  if (print_solutions)
892  {
893  std::streamsize old_precision = libMesh::out.precision();
895  // libMesh::out << "U = [" << this->get_vector("_nonlinear_solution")
896  libMesh::out << "U = [" << *(this->solution)
897  << "];" << std::endl;
898  libMesh::out.precision(old_precision);
899  }
900 
901  // Is this definitely necessary? [RHS]
902  // Yes. [RHS 2012]
903  if (get_jacobian)
904  matrix->zero();
905  if (get_residual)
906  rhs->zero();
907 
908  // Stupid C++ lets you set *Real* verify_analytic_jacobians = true!
909  if (verify_analytic_jacobians > 0.5)
910  {
911  libMesh::err << "WARNING! verify_analytic_jacobians was set "
912  << "to absurdly large value of "
913  << verify_analytic_jacobians << std::endl;
914  libMesh::err << "Resetting to 1e-6!" << std::endl;
916  }
917 
918  // In time-dependent problems, the nonlinear function we're trying
919  // to solve at each timestep may depend on the particular solver
920  // we're using
922 
923  // Build the residual and jacobian contributions on every active
924  // mesh element on this processor
926  (elem_range.reset(mesh.active_local_elements_begin(),
928  AssemblyContributions(*this, get_residual, get_jacobian,
929  apply_heterogeneous_constraints,
930  apply_no_constraints));
931 
932  // Check and see if we have SCALAR variables
933  bool have_scalar = false;
934  for (unsigned int i=0; i != this->n_variable_groups(); ++i)
935  {
936  if (this->variable_group(i).type().family == SCALAR)
937  {
938  have_scalar = true;
939  break;
940  }
941  }
942 
943  // SCALAR dofs are stored on the last processor, so we'll evaluate
944  // their equation terms there and only if we have a SCALAR variable
945  if (this->processor_id() == (this->n_processors()-1) && have_scalar)
946  {
948  FEMContext & _femcontext = cast_ref<FEMContext &>(*con);
949  this->init_context(_femcontext);
950  _femcontext.pre_fe_reinit(*this, libmesh_nullptr);
951 
952  bool jacobian_computed =
953  this->time_solver->nonlocal_residual(get_jacobian, _femcontext);
954 
955  // Nonlocal residuals are likely to be length 0, in which case we
956  // don't need to do any more. And we shouldn't try to do any
957  // more; lots of DenseVector/DenseMatrix code assumes rank>0.
958  if (_femcontext.get_elem_residual().size())
959  {
960  // Compute a numeric jacobian if we have to
961  if (get_jacobian && !jacobian_computed)
962  {
963  // Make sure we didn't compute a jacobian and lie about it
964  libmesh_assert_equal_to (_femcontext.get_elem_jacobian().l1_norm(), 0.0);
965  // Logging of numerical jacobians is done separately
966  this->numerical_nonlocal_jacobian(_femcontext);
967  }
968 
969  // Compute a numeric jacobian if we're asked to verify the
970  // analytic jacobian we got
971  if (get_jacobian && jacobian_computed &&
972  this->verify_analytic_jacobians != 0.0)
973  {
974  DenseMatrix<Number> analytic_jacobian(_femcontext.get_elem_jacobian());
975 
976  _femcontext.get_elem_jacobian().zero();
977  // Logging of numerical jacobians is done separately
978  this->numerical_nonlocal_jacobian(_femcontext);
979 
980  Real analytic_norm = analytic_jacobian.l1_norm();
981  Real numerical_norm = _femcontext.get_elem_jacobian().l1_norm();
982 
983  // If we can continue, we'll probably prefer the analytic jacobian
984  analytic_jacobian.swap(_femcontext.get_elem_jacobian());
985 
986  // The matrix "analytic_jacobian" will now hold the error matrix
987  analytic_jacobian.add(-1.0, _femcontext.get_elem_jacobian());
988  Real error_norm = analytic_jacobian.l1_norm();
989 
990  Real relative_error = error_norm /
991  std::max(analytic_norm, numerical_norm);
992 
993  if (relative_error > this->verify_analytic_jacobians)
994  {
995  libMesh::err << "Relative error " << relative_error
996  << " detected in analytic jacobian on nonlocal dofs!"
997  << std::endl;
998 
999  std::streamsize old_precision = libMesh::out.precision();
1000  libMesh::out.precision(16);
1001  libMesh::out << "J_analytic nonlocal = "
1002  << _femcontext.get_elem_jacobian() << std::endl;
1003  analytic_jacobian.add(1.0, _femcontext.get_elem_jacobian());
1004  libMesh::out << "J_numeric nonlocal = "
1005  << analytic_jacobian << std::endl;
1006 
1007  libMesh::out.precision(old_precision);
1008 
1009  libmesh_error_msg("Relative error too large, exiting!");
1010  }
1011  }
1012 
1013  add_element_system
1014  (*this, get_residual, get_jacobian,
1015  apply_heterogeneous_constraints, apply_no_constraints, _femcontext);
1016  }
1017  }
1018 
1019  if (get_residual && (print_residual_norms || print_residuals))
1020  this->rhs->close();
1021  if (get_residual && print_residual_norms)
1022  {
1023  std::streamsize old_precision = libMesh::out.precision();
1024  libMesh::out.precision(16);
1025  libMesh::out << "|F| = " << this->rhs->l1_norm() << std::endl;
1026  libMesh::out.precision(old_precision);
1027  }
1028  if (get_residual && print_residuals)
1029  {
1030  std::streamsize old_precision = libMesh::out.precision();
1031  libMesh::out.precision(16);
1032  libMesh::out << "F = [" << *(this->rhs) << "];" << std::endl;
1033  libMesh::out.precision(old_precision);
1034  }
1035 
1036  if (get_jacobian && (print_jacobian_norms || print_jacobians))
1037  this->matrix->close();
1038  if (get_jacobian && print_jacobian_norms)
1039  {
1040  std::streamsize old_precision = libMesh::out.precision();
1041  libMesh::out.precision(16);
1042  libMesh::out << "|J| = " << this->matrix->l1_norm() << std::endl;
1043  libMesh::out.precision(old_precision);
1044  }
1045  if (get_jacobian && print_jacobians)
1046  {
1047  std::streamsize old_precision = libMesh::out.precision();
1048  libMesh::out.precision(16);
1049  libMesh::out << "J = [" << *(this->matrix) << "];" << std::endl;
1050  libMesh::out.precision(old_precision);
1051  }
1052 }
OStreamProxy err
FEFamily family
The type of finite element.
Definition: fe_type.h:203
const FEType & type() const
Definition: variable.h:119
UniquePtr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:221
Real verify_analytic_jacobians
If verify_analytic_jacobian is equal to zero (as it is by default), no numeric jacobians will be calc...
Definition: fem_system.h:203
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
Definition: fem_context.C:1582
virtual void zero() libmesh_override
Set every element in the matrix to 0.
Definition: dense_matrix.h:792
void parallel_for(const Range &range, const Body &body)
Execute the provided function object in parallel on the specified range.
Definition: threads_none.h:73
bool print_jacobian_norms
Set print_jacobian_norms to true to print |J| whenever it is assembled.
Definition: diff_system.h:329
processor_id_type n_processors() const
MeshBase & mesh
Real l1_norm() const
Definition: dense_matrix.h:990
const class libmesh_nullptr_t libmesh_nullptr
NumericVector< Number > * rhs
The system matrix.
const VariableGroup & variable_group(unsigned int vg) const
Return a constant reference to VariableGroup vg.
Definition: system.h:2124
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:248
bool print_jacobians
Set print_jacobians to true to print J whenever it is assembled.
Definition: diff_system.h:334
virtual unsigned int size() const libmesh_override
Definition: dense_vector.h:87
virtual Real l1_norm() const =0
long double max(long double a, double b)
virtual UniquePtr< DiffContext > build_context() libmesh_override
Builds a FEMContext object with enough information to do evaluations on each element.
Definition: fem_system.C:1321
This is the MeshBase class.
Definition: mesh_base.h:68
virtual void zero()=0
Set all entries to zero.
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
void numerical_nonlocal_jacobian(FEMContext &context) const
Uses the results of multiple side_residual() calls to numerically differentiate the corresponding jac...
Definition: fem_system.C:1313
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:282
bool print_solution_norms
Set print_residual_norms to true to print |U| whenever it is used in an assembly() call...
Definition: diff_system.h:308
unsigned int n_variable_groups() const
Definition: system.h:2094
const MeshBase & get_mesh() const
Definition: system.h:2014
virtual void zero()=0
Set all entries to 0.
bool print_residual_norms
Set print_residual_norms to true to print |F| whenever it is assembled.
Definition: diff_system.h:319
virtual element_iterator active_local_elements_begin()=0
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrix< T3 > &mat)
Adds factor times mat to this matrix.
Definition: dense_matrix.h:883
bool print_residuals
Set print_residuals to true to print F whenever it is assembled.
Definition: diff_system.h:324
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
bool print_solutions
Set print_solutions to true to print U whenever it is used in an assembly() call. ...
Definition: diff_system.h:314
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:425
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
SparseMatrix< Number > * matrix
The system matrix.
virtual element_iterator active_local_elements_end()=0
virtual Real l1_norm() const =0
std::streamsize precision() const
Get the associated write precision.
processor_id_type processor_id() const
virtual void init_context(DiffContext &) libmesh_override
Definition: fem_system.C:1345
void libMesh::System::attach_assemble_function ( void   fptrEquationSystems &es, const std::string &name)
inherited

Register a user function to use in assembling the system matrix and RHS.

Definition at line 1795 of file system.C.

References libMesh::System::_assemble_system_function, libMesh::System::_assemble_system_object, fptr(), libMesh::libmesh_assert(), libmesh_nullptr, and libMesh::out.

Referenced by assemble_and_solve(), main(), and libMesh::System::read_parallel_data().

1797 {
1799 
1801  {
1802  libmesh_here();
1803  libMesh::out << "WARNING: Cannot specify both assembly function and object!"
1804  << std::endl;
1805 
1807  }
1808 
1810 }
Assembly * _assemble_system_object
Object that assembles the system.
Definition: system.h:1822
const class libmesh_nullptr_t libmesh_nullptr
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
libmesh_assert(j)
OStreamProxy out
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Function that assembles the system.
Definition: system.h:1816
void libMesh::System::attach_assemble_object ( System::Assembly assemble_in)
inherited

Register a user object to use in assembling the system matrix and RHS.

Definition at line 1814 of file system.C.

References libMesh::System::_assemble_system_function, libMesh::System::_assemble_system_object, libmesh_nullptr, and libMesh::out.

Referenced by main(), and libMesh::System::read_parallel_data().

1815 {
1817  {
1818  libmesh_here();
1819  libMesh::out << "WARNING: Cannot specify both assembly object and function!"
1820  << std::endl;
1821 
1823  }
1824 
1825  _assemble_system_object = &assemble_in;
1826 }
Assembly * _assemble_system_object
Object that assembles the system.
Definition: system.h:1822
const class libmesh_nullptr_t libmesh_nullptr
OStreamProxy out
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Function that assembles the system.
Definition: system.h:1816
void libMesh::System::attach_constraint_function ( void   fptrEquationSystems &es, const std::string &name)
inherited

Register a user function for imposing constraints.

Definition at line 1830 of file system.C.

References libMesh::System::_constrain_system_function, libMesh::System::_constrain_system_object, fptr(), libMesh::libmesh_assert(), libmesh_nullptr, and libMesh::out.

Referenced by libMesh::System::read_parallel_data().

1832 {
1834 
1836  {
1837  libmesh_here();
1838  libMesh::out << "WARNING: Cannot specify both constraint function and object!"
1839  << std::endl;
1840 
1842  }
1843 
1845 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition: system.h:1827
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:1833
const class libmesh_nullptr_t libmesh_nullptr
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
libmesh_assert(j)
OStreamProxy out
void libMesh::System::attach_constraint_object ( System::Constraint constrain)
inherited

Register a user object for imposing constraints.

Definition at line 1849 of file system.C.

References libMesh::System::_constrain_system_function, libMesh::System::_constrain_system_object, libmesh_nullptr, and libMesh::out.

Referenced by libMesh::System::read_parallel_data().

1850 {
1852  {
1853  libmesh_here();
1854  libMesh::out << "WARNING: Cannot specify both constraint object and function!"
1855  << std::endl;
1856 
1858  }
1859 
1860  _constrain_system_object = &constrain;
1861 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition: system.h:1827
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:1833
const class libmesh_nullptr_t libmesh_nullptr
OStreamProxy out
void libMesh::System::attach_init_function ( void   fptrEquationSystems &es, const std::string &name)
inherited

Register a user function to use in initializing the system.

Definition at line 1760 of file system.C.

References libMesh::System::_init_system_function, libMesh::System::_init_system_object, fptr(), libMesh::libmesh_assert(), libmesh_nullptr, and libMesh::out.

Referenced by main(), and libMesh::System::read_parallel_data().

1762 {
1764 
1766  {
1767  libmesh_here();
1768  libMesh::out << "WARNING: Cannot specify both initialization function and object!"
1769  << std::endl;
1770 
1772  }
1773 
1775 }
const class libmesh_nullptr_t libmesh_nullptr
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
libmesh_assert(j)
Initialization * _init_system_object
Object that initializes the system.
Definition: system.h:1811
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition: system.h:1805
OStreamProxy out
void libMesh::System::attach_init_object ( System::Initialization init_in)
inherited

Register a user class to use to initialize the system.

Note
This is exclusive with the attach_init_function.

Definition at line 1779 of file system.C.

References libMesh::System::_init_system_function, libMesh::System::_init_system_object, libmesh_nullptr, and libMesh::out.

Referenced by libMesh::System::read_parallel_data().

1780 {
1782  {
1783  libmesh_here();
1784  libMesh::out << "WARNING: Cannot specify both initialization object and function!"
1785  << std::endl;
1786 
1788  }
1789 
1790  _init_system_object = &init_in;
1791 }
const class libmesh_nullptr_t libmesh_nullptr
Initialization * _init_system_object
Object that initializes the system.
Definition: system.h:1811
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition: system.h:1805
OStreamProxy out
void libMesh::DifferentiableSystem::attach_physics ( DifferentiablePhysics physics_in)
inherited

Attach external Physics object.

Definition at line 184 of file diff_system.h.

References libMesh::DifferentiableSystem::_diff_physics, libMesh::DifferentiablePhysics::clone_physics(), libMesh::DifferentiablePhysics::init_physics(), and libMesh::DifferentiableSystem::swap_physics().

185  { this->_diff_physics = (physics_in->clone_physics()).release();
186  this->_diff_physics->init_physics(*this);}
virtual void init_physics(const System &sys)
Initialize any data structures associated with the physics.
Definition: diff_physics.C:40
DifferentiablePhysics * _diff_physics
Pointer to object to use for physics assembly evaluations.
Definition: diff_system.h:358
void libMesh::DifferentiableSystem::attach_qoi ( DifferentiableQoI qoi_in)
inherited

Attach external QoI object.

Definition at line 212 of file diff_system.h.

References libMesh::DifferentiableQoI::clone(), libMesh::DifferentiableSystem::diff_qoi, libMesh::DifferentiableQoI::init_qoi(), and libMesh::System::qoi.

Referenced by main().

213  { this->diff_qoi = (qoi_in->clone()).release();
214  // User needs to resize qoi system qoi accordingly
215  this->diff_qoi->init_qoi( this->qoi );}
DifferentiableQoI * diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
Definition: diff_system.h:365
std::vector< Number > qoi
Values of the quantities of interest.
Definition: system.h:1553
virtual void init_qoi(std::vector< Number > &)
Initialize system qoi.
Definition: diff_qoi.h:68
void libMesh::System::attach_QOI_derivative ( void   fptrEquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
inherited

Register a user function for evaluating derivatives of a quantity of interest with respect to test functions, whose values should be placed in System::rhs.

Definition at line 1901 of file system.C.

References libMesh::System::_qoi_evaluate_derivative_function, libMesh::System::_qoi_evaluate_derivative_object, fptr(), libMesh::libmesh_assert(), libmesh_nullptr, and libMesh::out.

Referenced by libMesh::System::read_parallel_data().

1903 {
1905 
1907  {
1908  libmesh_here();
1909  libMesh::out << "WARNING: Cannot specify both QOI derivative function and object!"
1910  << std::endl;
1911 
1913  }
1914 
1916 }
const class libmesh_nullptr_t libmesh_nullptr
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
libmesh_assert(j)
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition: system.h:1859
OStreamProxy out
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Function to evaluate quantity of interest derivative.
Definition: system.h:1850
void libMesh::System::attach_QOI_derivative_object ( QOIDerivative qoi_derivative)
inherited

Register a user object for evaluating derivatives of a quantity of interest with respect to test functions, whose values should be placed in System::rhs.

Definition at line 1920 of file system.C.

References libMesh::System::_qoi_evaluate_derivative_function, libMesh::System::_qoi_evaluate_derivative_object, libmesh_nullptr, and libMesh::out.

Referenced by libMesh::System::read_parallel_data().

1921 {
1923  {
1924  libmesh_here();
1925  libMesh::out << "WARNING: Cannot specify both QOI derivative object and function!"
1926  << std::endl;
1927 
1929  }
1930 
1931  _qoi_evaluate_derivative_object = &qoi_derivative;
1932 }
const class libmesh_nullptr_t libmesh_nullptr
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition: system.h:1859
OStreamProxy out
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Function to evaluate quantity of interest derivative.
Definition: system.h:1850
void libMesh::System::attach_QOI_function ( void   fptrEquationSystems &es, const std::string &name, const QoISet &qoi_indices)
inherited

Register a user function for evaluating the quantities of interest, whose values should be placed in System::qoi.

Definition at line 1865 of file system.C.

References libMesh::System::_qoi_evaluate_function, libMesh::System::_qoi_evaluate_object, fptr(), libMesh::libmesh_assert(), libmesh_nullptr, and libMesh::out.

Referenced by libMesh::System::read_parallel_data().

1868 {
1870 
1872  {
1873  libmesh_here();
1874  libMesh::out << "WARNING: Cannot specify both QOI function and object!"
1875  << std::endl;
1876 
1878  }
1879 
1881 }
const class libmesh_nullptr_t libmesh_nullptr
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition: system.h:1838
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
libmesh_assert(j)
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition: system.h:1845
OStreamProxy out
void libMesh::System::attach_QOI_object ( QOI qoi)
inherited

Register a user object for evaluating the quantities of interest, whose values should be placed in System::qoi.

Definition at line 1885 of file system.C.

References libMesh::System::_qoi_evaluate_function, libMesh::System::_qoi_evaluate_object, libmesh_nullptr, and libMesh::out.

Referenced by libMesh::System::read_parallel_data().

1886 {
1888  {
1889  libmesh_here();
1890  libMesh::out << "WARNING: Cannot specify both QOI object and function!"
1891  << std::endl;
1892 
1894  }
1895 
1896  _qoi_evaluate_object = &qoi_in;
1897 }
const class libmesh_nullptr_t libmesh_nullptr
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition: system.h:1838
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition: system.h:1845
OStreamProxy out
void libMesh::System::boundary_project_solution ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
FunctionBase< Number > *  f,
FunctionBase< Gradient > *  g = libmesh_nullptr 
)
inherited

Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system.

This method projects an arbitrary boundary function onto the solution via L2 projections and nodal interpolations on each element.

Only degrees of freedom which affect the function's trace on a boundary in the set b are affected. Only degrees of freedom associated with the variables listed in the vector variables are projected. The function value f and its gradient g are user-provided cloneable functors. A gradient g is only required/used for projecting onto finite element spaces with continuous derivatives. If non-default Parameters are to be used, they can be provided in the parameters argument.

Definition at line 999 of file system_projection.C.

References libMesh::System::boundary_project_vector(), fptr(), and gptr().

Referenced by libMesh::System::project_vector(), and libMesh::System::system_type().

1003 {
1004  this->boundary_project_vector(b, variables, *solution, f, g);
1005 
1006  solution->localize(*current_local_solution);
1007 }
void boundary_project_vector(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...
UniquePtr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1535
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
void libMesh::System::boundary_project_solution ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
Number   fptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
Gradient   gptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
const Parameters parameters 
)
inherited

Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system.

Only degrees of freedom which affect the function's trace on a boundary in the set b are affected. Only degrees of freedom associated with the variables listed in the vector variables are projected. The function value fptr and its gradient gptr are represented by function pointers. A gradient gptr is only required/used for projecting onto finite element spaces with continuous derivatives.

void libMesh::System::boundary_project_vector ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
NumericVector< Number > &  new_vector,
FunctionBase< Number > *  f,
FunctionBase< Gradient > *  g = libmesh_nullptr,
int  is_adjoint = -1 
) const
inherited

Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system.

This method projects an arbitrary function via L2 projections and nodal interpolations on each element.

Only degrees of freedom which affect the function's trace on a boundary in the set b are affected. Only degrees of freedom associated with the variables listed in the vector variables are projected. The function value f and its gradient g are user-provided cloneable functors. A gradient g is only required/used for projecting onto finite element spaces with continuous derivatives. If non-default Parameters are to be used, they can be provided in the parameters argument.

Constrain the new vector using the requested adjoint rather than primal constraints if is_adjoint is non-negative.

Definition at line 1041 of file system_projection.C.

References libMesh::NumericVector< T >::close(), libMesh::get_dof_map(), and libMesh::Threads::parallel_for().

Referenced by libMesh::System::boundary_project_solution(), and libMesh::System::system_type().

1047 {
1048  LOG_SCOPE ("boundary_project_vector()", "System");
1049 
1051  (ConstElemRange (this->get_mesh().active_local_elements_begin(),
1052  this->get_mesh().active_local_elements_end() ),
1053  BoundaryProjectSolution(b, variables, *this, f, g,
1054  this->get_equation_systems().parameters,
1055  new_vector)
1056  );
1057 
1058  // We don't do SCALAR dofs when just projecting the boundary, so
1059  // we're done here.
1060 
1061  new_vector.close();
1062 
1063 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1064  if (is_adjoint == -1)
1065  this->get_dof_map().enforce_constraints_exactly(*this, &new_vector);
1066  else if (is_adjoint >= 0)
1068  is_adjoint);
1069 #endif
1070 }
void parallel_for(const Range &range, const Body &body)
Execute the provided function object in parallel on the specified range.
Definition: threads_none.h:73
StoredRange< MeshBase::const_element_iterator, const Elem * > ConstElemRange
Definition: elem_range.h:34
const MeshBase & get_mesh() const
Definition: system.h:2014
const DofMap & get_dof_map() const
Definition: system.h:2030
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
const EquationSystems & get_equation_systems() const
Definition: system.h:712
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
Heterogenously constrains the numeric vector v, which represents an adjoint solution defined on the m...
Definition: dof_map.h:1820
void libMesh::System::boundary_project_vector ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
Number   fptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
Gradient   gptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
const Parameters parameters,
NumericVector< Number > &  new_vector,
int  is_adjoint = -1 
) const
inherited

Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system.

Only degrees of freedom which affect the function's trace on a boundary in the set b are affected. Only degrees of freedom associated with the variables listed in the vector variables are projected. The function value fptr and its gradient gptr are represented by function pointers. A gradient gptr is only required/used for projecting onto finite element spaces with continuous derivatives.

Constrain the new vector using the requested adjoint rather than primal constraints if is_adjoint is non-negative.

UniquePtr< DiffContext > FEMSystem::build_context ( )
virtualinherited

Builds a FEMContext object with enough information to do evaluations on each element.

For most problems, the default FEMSystem implementation is correct; users who subclass FEMContext will need to also reimplement this method to build it.

Reimplemented from libMesh::DifferentiableSystem.

Definition at line 1321 of file fem_system.C.

References libMesh::DifferentiableSystem::deltat, libMesh::DifferentiablePhysics::get_mesh_system(), libMesh::DifferentiablePhysics::get_mesh_x_var(), libMesh::DifferentiablePhysics::get_mesh_y_var(), libMesh::DifferentiablePhysics::get_mesh_z_var(), libMesh::DifferentiableSystem::get_physics(), libMesh::DifferentiableSystem::get_time_solver(), libMesh::TimeSolver::is_adjoint(), libMesh::DiffContext::is_adjoint(), libMesh::libmesh_assert(), libMesh::DiffContext::set_deltat_pointer(), libMesh::FEMContext::set_mesh_system(), libMesh::FEMContext::set_mesh_x_var(), libMesh::FEMContext::set_mesh_y_var(), and libMesh::FEMContext::set_mesh_z_var().

Referenced by libMesh::FEMSystem::assembly(), libMesh::FEMSystem::mesh_position_get(), and libMesh::FEMSystem::mesh_position_set().

1322 {
1323  FEMContext * fc = new FEMContext(*this);
1324 
1325  DifferentiablePhysics * phys = this->get_physics();
1326 
1327  libmesh_assert (phys);
1328 
1329  // If we are solving a moving mesh problem, tell that to the Context
1330  fc->set_mesh_system(phys->get_mesh_system());
1331  fc->set_mesh_x_var(phys->get_mesh_x_var());
1332  fc->set_mesh_y_var(phys->get_mesh_y_var());
1333  fc->set_mesh_z_var(phys->get_mesh_z_var());
1334 
1335  fc->set_deltat_pointer( &deltat );
1336 
1337  // If we are solving the adjoint problem, tell that to the Context
1338  fc->is_adjoint() = this->get_time_solver().is_adjoint();
1339 
1340  return UniquePtr<DiffContext>(fc);
1341 }
bool is_adjoint() const
Accessor for querying whether we need to do a primal or adjoint solve.
Definition: time_solver.h:232
void set_mesh_z_var(unsigned int z_var)
Accessor for z-variable of moving mesh System.
Definition: fem_context.h:859
void set_mesh_x_var(unsigned int x_var)
Accessor for x-variable of moving mesh System.
Definition: fem_context.h:831
bool is_adjoint() const
Accessor for querying whether we need to do a primal or adjoint solve.
Definition: diff_context.h:453
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
const System * get_mesh_system() const
Definition: diff_physics.h:623
unsigned int get_mesh_x_var() const
Definition: diff_physics.h:635
virtual void set_mesh_system(System *sys)
Tells the FEMContext that system sys contains the isoparametric Lagrangian variables which correspond...
Definition: fem_context.h:805
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time...
Definition: diff_system.h:248
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
const DifferentiablePhysics * get_physics() const
Definition: diff_system.h:169
This class provides a specific system class.
Definition: diff_physics.h:74
unsigned int get_mesh_z_var() const
Definition: diff_physics.h:647
unsigned int get_mesh_y_var() const
Definition: diff_physics.h:641
void set_mesh_y_var(unsigned int y_var)
Accessor for y-variable of moving mesh System.
Definition: fem_context.h:845
void set_deltat_pointer(Real *dt)
Points the _deltat member of this class at a timestep value stored in the creating System...
Definition: diff_context.C:138
TimeSolver & get_time_solver()
Definition: diff_system.h:402
Real libMesh::System::calculate_norm ( const NumericVector< Number > &  v,
unsigned int  var,
FEMNormType  norm_type,
std::set< unsigned int > *  skip_dimensions = libmesh_nullptr 
) const
inherited
Returns
A norm of variable var in the vector v, in the specified norm (e.g. L2, L_INF, H1)

Definition at line 1383 of file system.C.

References libMesh::DISCRETE_L1, libMesh::DISCRETE_L2, libMesh::DISCRETE_L_INF, libMesh::System::discrete_var_norm(), libMesh::L2, libMesh::System::n_vars(), and libMesh::Real.

Referenced by libMesh::AdaptiveTimeSolver::calculate_norm(), libMesh::UnsteadySolver::du(), main(), output_norms(), and libMesh::System::project_solution_on_reinit().

1387 {
1388  //short circuit to save time
1389  if (norm_type == DISCRETE_L1 ||
1390  norm_type == DISCRETE_L2 ||
1391  norm_type == DISCRETE_L_INF)
1392  return discrete_var_norm(v,var,norm_type);
1393 
1394  // Not a discrete norm
1395  std::vector<FEMNormType> norms(this->n_vars(), L2);
1396  std::vector<Real> weights(this->n_vars(), 0.0);
1397  norms[var] = norm_type;
1398  weights[var] = 1.0;
1399  Real val = this->calculate_norm(v, SystemNorm(norms, weights), skip_dimensions);
1400  return val;
1401 }
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=libmesh_nullptr) const
Definition: system.C:1383
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int n_vars() const
Definition: system.h:2086
Real discrete_var_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type) const
Finds the discrete norm for the entries in the vector corresponding to Dofs associated with var...
Definition: system.C:1364
Real libMesh::System::calculate_norm ( const NumericVector< Number > &  v,
const SystemNorm norm,
std::set< unsigned int > *  skip_dimensions = libmesh_nullptr 
) const
inherited
Returns
A norm of the vector v, using component_norm and component_scale to choose and weight the norms of each variable.

Definition at line 1405 of file system.C.

References libMesh::System::_dof_map, libMesh::System::_mesh, std::abs(), libMesh::TypeVector< T >::add_scaled(), libMesh::TypeTensor< T >::add_scaled(), libMesh::FEGenericBase< OutputType >::build(), libMesh::NumericVector< T >::build(), libMesh::ParallelObject::comm(), libMesh::FEType::default_quadrature_rule(), dim, libMesh::DISCRETE_L1, libMesh::DISCRETE_L2, libMesh::DISCRETE_L_INF, libMesh::System::discrete_var_norm(), libMesh::DofMap::dof_indices(), libMesh::MeshBase::elem_dimensions(), libMesh::FEGenericBase< OutputType >::get_d2phi(), libMesh::System::get_dof_map(), libMesh::FEGenericBase< OutputType >::get_dphi(), libMesh::FEAbstract::get_JxW(), libMesh::System::get_mesh(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::H1, libMesh::H1_SEMINORM, libMesh::H2, libMesh::H2_SEMINORM, libMesh::SystemNorm::is_discrete(), libMesh::L1, libMesh::NumericVector< T >::l1_norm(), libMesh::L2, libMesh::NumericVector< T >::l2_norm(), libMesh::L_INF, libMesh::libmesh_assert(), libmesh_nullptr, libMesh::NumericVector< T >::linfty_norm(), libMesh::NumericVector< T >::localize(), std::max(), libMesh::Parallel::Communicator::max(), libMesh::QBase::n_points(), libMesh::System::n_vars(), libMesh::TypeVector< T >::norm(), libMesh::TypeTensor< T >::norm(), libMesh::TensorTools::norm_sq(), libMesh::TypeVector< T >::norm_sq(), libMesh::TypeTensor< T >::norm_sq(), libMesh::Real, libMesh::FEAbstract::reinit(), libMesh::SERIAL, libMesh::NumericVector< T >::size(), libMesh::Parallel::Communicator::sum(), libMesh::SystemNorm::type(), libMesh::DofMap::variable_type(), libMesh::W1_INF_SEMINORM, libMesh::W2_INF_SEMINORM, libMesh::SystemNorm::weight(), and libMesh::SystemNorm::weight_sq().

1408 {
1409  // This function must be run on all processors at once
1410  parallel_object_only();
1411 
1412  LOG_SCOPE ("calculate_norm()", "System");
1413 
1414  // Zero the norm before summation
1415  Real v_norm = 0.;
1416 
1417  if (norm.is_discrete())
1418  {
1419  //Check to see if all weights are 1.0 and all types are equal
1420  FEMNormType norm_type0 = norm.type(0);
1421  unsigned int check_var = 0;
1422  for (; check_var != this->n_vars(); ++check_var)
1423  if ((norm.weight(check_var) != 1.0) || (norm.type(check_var) != norm_type0))
1424  break;
1425 
1426  //All weights were 1.0 so just do the full vector discrete norm
1427  if (check_var == this->n_vars())
1428  {
1429  if (norm_type0 == DISCRETE_L1)
1430  return v.l1_norm();
1431  if (norm_type0 == DISCRETE_L2)
1432  return v.l2_norm();
1433  if (norm_type0 == DISCRETE_L_INF)
1434  return v.linfty_norm();
1435  else
1436  libmesh_error_msg("Invalid norm_type0 = " << norm_type0);
1437  }
1438 
1439  for (unsigned int var=0; var != this->n_vars(); ++var)
1440  {
1441  // Skip any variables we don't need to integrate
1442  if (norm.weight(var) == 0.0)
1443  continue;
1444 
1445  v_norm += norm.weight(var) * discrete_var_norm(v, var, norm.type(var));
1446  }
1447 
1448  return v_norm;
1449  }
1450 
1451  // Localize the potentially parallel vector
1452  UniquePtr<NumericVector<Number>> local_v = NumericVector<Number>::build(this->comm());
1453  local_v->init(v.size(), true, SERIAL);
1454  v.localize (*local_v, _dof_map->get_send_list());
1455 
1456  // I'm not sure how best to mix Hilbert norms on some variables (for
1457  // which we'll want to square then sum then square root) with norms
1458  // like L_inf (for which we'll just want to take an absolute value
1459  // and then sum).
1460  bool using_hilbert_norm = true,
1461  using_nonhilbert_norm = true;
1462 
1463  // Loop over all variables
1464  for (unsigned int var=0; var != this->n_vars(); ++var)
1465  {
1466  // Skip any variables we don't need to integrate
1467  Real norm_weight_sq = norm.weight_sq(var);
1468  if (norm_weight_sq == 0.0)
1469  continue;
1470  Real norm_weight = norm.weight(var);
1471 
1472  // Check for unimplemented norms (rather than just returning 0).
1473  FEMNormType norm_type = norm.type(var);
1474  if ((norm_type==H1) ||
1475  (norm_type==H2) ||
1476  (norm_type==L2) ||
1477  (norm_type==H1_SEMINORM) ||
1478  (norm_type==H2_SEMINORM))
1479  {
1480  if (!using_hilbert_norm)
1481  libmesh_not_implemented();
1482  using_nonhilbert_norm = false;
1483  }
1484  else if ((norm_type==L1) ||
1485  (norm_type==L_INF) ||
1486  (norm_type==W1_INF_SEMINORM) ||
1487  (norm_type==W2_INF_SEMINORM))
1488  {
1489  if (!using_nonhilbert_norm)
1490  libmesh_not_implemented();
1491  using_hilbert_norm = false;
1492  }
1493  else
1494  libmesh_not_implemented();
1495 
1496  const FEType & fe_type = this->get_dof_map().variable_type(var);
1497 
1498  // Allow space for dims 0-3, even if we don't use them all
1499  std::vector<FEBase *> fe_ptrs(4,libmesh_nullptr);
1500  std::vector<QBase *> q_rules(4,libmesh_nullptr);
1501 
1502  const std::set<unsigned char> & elem_dims = _mesh.elem_dimensions();
1503 
1504  // Prepare finite elements for each dimension present in the mesh
1505  for (std::set<unsigned char>::const_iterator d_it = elem_dims.begin();
1506  d_it != elem_dims.end(); ++d_it)
1507  {
1508  if (skip_dimensions && skip_dimensions->find(*d_it) != skip_dimensions->end())
1509  continue;
1510 
1511  q_rules[*d_it] =
1512  fe_type.default_quadrature_rule (*d_it).release();
1513 
1514  // Construct finite element object
1515 
1516  fe_ptrs[*d_it] = FEBase::build(*d_it, fe_type).release();
1517 
1518  // Attach quadrature rule to FE object
1519  fe_ptrs[*d_it]->attach_quadrature_rule (q_rules[*d_it]);
1520  }
1521 
1522  std::vector<dof_id_type> dof_indices;
1523 
1524  // Begin the loop over the elements
1525  for (const auto & elem : this->get_mesh().active_local_element_ptr_range())
1526  {
1527  const unsigned int dim = elem->dim();
1528 
1529 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1530 
1531  // One way for implementing this would be to exchange the fe with the FEInterface- class.
1532  // However, it needs to be discussed whether integral-norms make sense for infinite elements.
1533  // or in which sense they could make sense.
1534  if (elem->infinite() )
1535  libmesh_not_implemented();
1536 
1537 #endif
1538 
1539  if (skip_dimensions && skip_dimensions->find(dim) != skip_dimensions->end())
1540  continue;
1541 
1542  FEBase * fe = fe_ptrs[dim];
1543  QBase * qrule = q_rules[dim];
1544  libmesh_assert(fe);
1545  libmesh_assert(qrule);
1546 
1547  const std::vector<Real> & JxW = fe->get_JxW();
1548  const std::vector<std::vector<Real>> * phi = libmesh_nullptr;
1549  if (norm_type == H1 ||
1550  norm_type == H2 ||
1551  norm_type == L2 ||
1552  norm_type == L1 ||
1553  norm_type == L_INF)
1554  phi = &(fe->get_phi());
1555 
1556  const std::vector<std::vector<RealGradient>> * dphi = libmesh_nullptr;
1557  if (norm_type == H1 ||
1558  norm_type == H2 ||
1559  norm_type == H1_SEMINORM ||
1560  norm_type == W1_INF_SEMINORM)
1561  dphi = &(fe->get_dphi());
1562 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
1563  const std::vector<std::vector<RealTensor>> * d2phi = libmesh_nullptr;
1564  if (norm_type == H2 ||
1565  norm_type == H2_SEMINORM ||
1566  norm_type == W2_INF_SEMINORM)
1567  d2phi = &(fe->get_d2phi());
1568 #endif
1569 
1570  fe->reinit (elem);
1571 
1572  this->get_dof_map().dof_indices (elem, dof_indices, var);
1573 
1574  const unsigned int n_qp = qrule->n_points();
1575 
1576  const unsigned int n_sf = cast_int<unsigned int>
1577  (dof_indices.size());
1578 
1579  // Begin the loop over the Quadrature points.
1580  for (unsigned int qp=0; qp<n_qp; qp++)
1581  {
1582  if (norm_type == L1)
1583  {
1584  Number u_h = 0.;
1585  for (unsigned int i=0; i != n_sf; ++i)
1586  u_h += (*phi)[i][qp] * (*local_v)(dof_indices[i]);
1587  v_norm += norm_weight *
1588  JxW[qp] * std::abs(u_h);
1589  }
1590 
1591  if (norm_type == L_INF)
1592  {
1593  Number u_h = 0.;
1594  for (unsigned int i=0; i != n_sf; ++i)
1595  u_h += (*phi)[i][qp] * (*local_v)(dof_indices[i]);
1596  v_norm = std::max(v_norm, norm_weight * std::abs(u_h));
1597  }
1598 
1599  if (norm_type == H1 ||
1600  norm_type == H2 ||
1601  norm_type == L2)
1602  {
1603  Number u_h = 0.;
1604  for (unsigned int i=0; i != n_sf; ++i)
1605  u_h += (*phi)[i][qp] * (*local_v)(dof_indices[i]);
1606  v_norm += norm_weight_sq *
1607  JxW[qp] * TensorTools::norm_sq(u_h);
1608  }
1609 
1610  if (norm_type == H1 ||
1611  norm_type == H2 ||
1612  norm_type == H1_SEMINORM)
1613  {
1614  Gradient grad_u_h;
1615  for (unsigned int i=0; i != n_sf; ++i)
1616  grad_u_h.add_scaled((*dphi)[i][qp], (*local_v)(dof_indices[i]));
1617  v_norm += norm_weight_sq *
1618  JxW[qp] * grad_u_h.norm_sq();
1619  }
1620 
1621  if (norm_type == W1_INF_SEMINORM)
1622  {
1623  Gradient grad_u_h;
1624  for (unsigned int i=0; i != n_sf; ++i)
1625  grad_u_h.add_scaled((*dphi)[i][qp], (*local_v)(dof_indices[i]));
1626  v_norm = std::max(v_norm, norm_weight * grad_u_h.norm());
1627  }
1628 
1629 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
1630  if (norm_type == H2 ||
1631  norm_type == H2_SEMINORM)
1632  {
1633  Tensor hess_u_h;
1634  for (unsigned int i=0; i != n_sf; ++i)
1635  hess_u_h.add_scaled((*d2phi)[i][qp], (*local_v)(dof_indices[i]));
1636  v_norm += norm_weight_sq *
1637  JxW[qp] * hess_u_h.norm_sq();
1638  }
1639 
1640  if (norm_type == W2_INF_SEMINORM)
1641  {
1642  Tensor hess_u_h;
1643  for (unsigned int i=0; i != n_sf; ++i)
1644  hess_u_h.add_scaled((*d2phi)[i][qp], (*local_v)(dof_indices[i]));
1645  v_norm = std::max(v_norm, norm_weight * hess_u_h.norm());
1646  }
1647 #endif
1648  }
1649  }
1650 
1651  // Need to delete the FE and quadrature objects to prevent a memory leak
1652  for (std::size_t i=0; i<fe_ptrs.size(); i++)
1653  if (fe_ptrs[i])
1654  delete fe_ptrs[i];
1655 
1656  for (std::size_t i=0; i<q_rules.size(); i++)
1657  if (q_rules[i])
1658  delete q_rules[i];
1659  }
1660 
1661  if (using_hilbert_norm)
1662  {
1663  this->comm().sum(v_norm);
1664  v_norm = std::sqrt(v_norm);
1665  }
1666  else
1667  {
1668  this->comm().max(v_norm);
1669  }
1670 
1671  return v_norm;
1672 }
double abs(double a)
virtual numeric_index_type size() const =0
const FEType & variable_type(const unsigned int c) const
Definition: dof_map.h:1697
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
void add_scaled(const TypeTensor< T2 > &, const T)
Add a scaled tensor to this tensor without creating a temporary.
Definition: type_tensor.h:777
void add_scaled(const TypeVector< T2 > &, const T)
Add a scaled value to this vector without creating a temporary.
Definition: type_vector.h:624
virtual Real l2_norm() const =0
unsigned int dim
const class libmesh_nullptr_t libmesh_nullptr
virtual Real l1_norm() const =0
long double max(long double a, double b)
UniquePtr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:1865
libmesh_assert(j)
static UniquePtr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
const MeshBase & get_mesh() const
Definition: system.h:2014
const DofMap & get_dof_map() const
Definition: system.h:2030
NumberVectorValue Gradient
const std::set< unsigned char > & elem_dimensions() const
Definition: mesh_base.h:206
FEGenericBase< Real > FEBase
virtual Real linfty_norm() const =0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
NumberTensorValue Tensor
const Parallel::Communicator & comm() const
ParallelType type() const
unsigned int n_vars() const
Definition: system.h:2086
void sum(T &r) const
Take a local variable and replace it with the sum of it&#39;s values on all processors.
MeshBase & _mesh
Constant reference to the mesh data structure used for the simulation.
Definition: system.h:1877
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.
Real discrete_var_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type) const
Finds the discrete norm for the entries in the vector corresponding to Dofs associated with var...
Definition: system.C:1364
FEMNormType
defines an enum for norms defined on vectors of finite element coefficients
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1917
static UniquePtr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
void libMesh::ContinuationSystem::clear ( )
virtual

Clear all the data structures associated with the system.

Reimplemented from libMesh::DifferentiableSystem.

Definition at line 80 of file continuation_system.C.

References libMesh::DifferentiableSystem::clear().

Referenced by ~ContinuationSystem().

81 {
82  // FIXME: Do anything here, e.g. zero vectors, etc?
83 
84  // Call the Parent's clear function
85  Parent::clear();
86 }
virtual void clear() libmesh_override
Clear all the data structures associated with the system.
Definition: diff_system.C:69
void libMesh::DifferentiablePhysics::clear_physics ( )
virtualinherited

Clear any data structures associated with the physics.

Definition at line 33 of file diff_physics.C.

References libMesh::DifferentiablePhysics::_time_evolving.

Referenced by libMesh::DifferentiableSystem::clear(), libMesh::DifferentiablePhysics::DifferentiablePhysics(), and libMesh::DifferentiablePhysics::~DifferentiablePhysics().

34 {
35  _time_evolving.resize(0);
36 }
std::vector< unsigned int > _time_evolving
Stores unsigned int to tell us which variables are evolving as first order in time (1)...
Definition: diff_physics.h:553
virtual void libMesh::DifferentiableQoI::clear_qoi ( )
virtualinherited

Clear all the data structures associated with the QoI.

Definition at line 74 of file diff_qoi.h.

Referenced by libMesh::DifferentiableSystem::clear().

74 {}
virtual UniquePtr<DifferentiableQoI> libMesh::DifferentiableSystem::clone ( )
virtualinherited

We don't allow systems to be attached to each other.

Implements libMesh::DifferentiableQoI.

Definition at line 156 of file diff_system.h.

Referenced by libMesh::AdjointRefinementEstimator::estimate_error().

157  {
158  libmesh_not_implemented();
159  // dummy
160  return UniquePtr<DifferentiableQoI>(this);
161  }
virtual UniquePtr<DifferentiablePhysics> libMesh::DifferentiableSystem::clone_physics ( )
virtualinherited

We don't allow systems to be attached to each other.

Implements libMesh::DifferentiablePhysics.

Definition at line 146 of file diff_system.h.

147  {
148  libmesh_not_implemented();
149  // dummy
150  return UniquePtr<DifferentiablePhysics>(this);
151  }
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_preconditioner_apply(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), add_cube_convex_hull_to_mesh(), libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::ImplicitSystem::add_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::RBEIMConstruction::enrich_RB_space(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::RBConstruction::enrich_RB_space(), AssembleOptimization::equality_constraints(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::RBEIMConstruction::evaluate_mesh_function(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshfreeInterpolation::gather_remote_data(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), AssembleOptimization::inequality_constraints(), AssembleOptimization::inequality_constraints_jacobian(), libMesh::LocationMap< T >::init(), libMesh::TopologyMap::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::RBEIMConstruction::initialize_rb_construction(), integrate_function(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), LinearElasticityWithContact::move_mesh(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), new_function_base(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), FEMParameters::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), LinearElasticityWithContact::residual_and_jacobian(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::RBEIMConstruction::set_explicit_sys_subvector(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), libMesh::MeshRefinement::test_unflagged(), PointLocatorTest::testLocator(), BoundaryInfoTest::testMesh(), SystemsTest::testProjectCubeWithMeshFunction(), libMesh::MeshTools::total_weight(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::RBEIMConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::RBEvaluation::write_out_vectors(), libMesh::TransientRBConstruction::write_riesz_representors_to_files(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::TransientRBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBSCMEvaluationSerialization::write_to_file().

88  { return _communicator; }
const Parallel::Communicator & _communicator
bool libMesh::System::compare ( const System other_system,
const Real  threshold,
const bool  verbose 
) const
virtualinherited
Returns
true when the other system contains identical data, up to the given threshold. Outputs some diagnostic info when verbose is set.

Definition at line 531 of file system.C.

References libMesh::System::_is_initialized, libMesh::System::_sys_name, libMesh::System::_vectors, libMesh::System::get_vector(), libMesh::libmesh_assert(), libMesh::System::n_vectors(), libMesh::System::name(), libMesh::out, and libMesh::System::solution.

Referenced by libMesh::EquationSystems::compare(), and libMesh::System::set_adjoint_already_solved().

534 {
535  // we do not care for matrices, but for vectors
537  libmesh_assert (other_system._is_initialized);
538 
539  if (verbose)
540  {
541  libMesh::out << " Systems \"" << _sys_name << "\"" << std::endl;
542  libMesh::out << " comparing matrices not supported." << std::endl;
543  libMesh::out << " comparing names...";
544  }
545 
546  // compare the name: 0 means identical
547  const int name_result = _sys_name.compare(other_system.name());
548  if (verbose)
549  {
550  if (name_result == 0)
551  libMesh::out << " identical." << std::endl;
552  else
553  libMesh::out << " names not identical." << std::endl;
554  libMesh::out << " comparing solution vector...";
555  }
556 
557 
558  // compare the solution: -1 means identical
559  const int solu_result = solution->compare (*other_system.solution.get(),
560  threshold);
561 
562  if (verbose)
563  {
564  if (solu_result == -1)
565  libMesh::out << " identical up to threshold." << std::endl;
566  else
567  libMesh::out << " first difference occurred at index = "
568  << solu_result << "." << std::endl;
569  }
570 
571 
572  // safety check, whether we handle at least the same number
573  // of vectors
574  std::vector<int> ov_result;
575 
576  if (this->n_vectors() != other_system.n_vectors())
577  {
578  if (verbose)
579  {
580  libMesh::out << " Fatal difference. This system handles "
581  << this->n_vectors() << " add'l vectors," << std::endl
582  << " while the other system handles "
583  << other_system.n_vectors()
584  << " add'l vectors." << std::endl
585  << " Aborting comparison." << std::endl;
586  }
587  return false;
588  }
589  else if (this->n_vectors() == 0)
590  {
591  // there are no additional vectors...
592  ov_result.clear ();
593  }
594  else
595  {
596  // compare other vectors
597  for (const_vectors_iterator pos = _vectors.begin();
598  pos != _vectors.end(); ++pos)
599  {
600  if (verbose)
601  libMesh::out << " comparing vector \""
602  << pos->first << "\" ...";
603 
604  // assume they have the same name
605  const NumericVector<Number> & other_system_vector =
606  other_system.get_vector(pos->first);
607 
608  ov_result.push_back(pos->second->compare (other_system_vector,
609  threshold));
610 
611  if (verbose)
612  {
613  if (ov_result[ov_result.size()-1] == -1)
614  libMesh::out << " identical up to threshold." << std::endl;
615  else
616  libMesh::out << " first difference occurred at" << std::endl
617  << " index = " << ov_result[ov_result.size()-1] << "." << std::endl;
618  }
619 
620  }
621 
622  } // finished comparing additional vectors
623 
624 
625  bool overall_result;
626 
627  // sum up the results
628  if ((name_result==0) && (solu_result==-1))
629  {
630  if (ov_result.size()==0)
631  overall_result = true;
632  else
633  {
634  bool ov_identical;
635  unsigned int n = 0;
636  do
637  {
638  ov_identical = (ov_result[n]==-1);
639  n++;
640  }
641  while (ov_identical && n<ov_result.size());
642  overall_result = ov_identical;
643  }
644  }
645  else
646  overall_result = false;
647 
648  if (verbose)
649  {
650  libMesh::out << " finished comparisons, ";
651  if (overall_result)
652  libMesh::out << "found no differences." << std::endl << std::endl;
653  else
654  libMesh::out << "found differences." << std::endl << std::endl;
655  }
656 
657  return overall_result;
658 }
bool _is_initialized
true when additional vectors and variables do not require immediate initialization, false otherwise.
Definition: system.h:1952
std::map< std::string, NumericVector< Number > * >::const_iterator const_vectors_iterator
Definition: system.h:749
libmesh_assert(j)
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
std::map< std::string, NumericVector< Number > * > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:1916
OStreamProxy out
const std::string _sys_name
A name associated with this system.
Definition: system.h:1882
unsigned int n_vectors() const
Definition: system.h:2214
void libMesh::ContinuationSystem::continuation_solve ( )

Perform a continuation solve of the system.

In general, you can only begin the continuation solves after either reading in or solving for two previous values of the control parameter. The prior two solutions are required for starting up the continuation method.

Definition at line 358 of file continuation_system.C.

References std::abs(), libMesh::NumericVector< T >::add(), apply_predictor(), libMesh::FEMSystem::assembly(), libMesh::NumericVector< T >::close(), libMesh::SparseMatrix< T >::close(), continuation_parameter, continuation_parameter_tolerance, delta_u, dlambda_ds, libMesh::NumericVector< T >::dot(), ds_current, du_ds, G_Lambda, initial_newton_tolerance, initialize_tangent(), libMesh::NumericVector< T >::l2_norm(), libMesh::libmesh_real(), linear_solver, libMesh::ImplicitSystem::matrix, max_continuation_parameter, libMesh::DiffSolver::max_linear_iterations, libMesh::DiffSolver::max_nonlinear_iterations, std::min(), min_continuation_parameter, n_arclength_reductions, n_backtrack_steps, newton_progress_check, newton_solver, newton_step, old_continuation_parameter, libMesh::out, std::pow(), libMesh::BasicOStreamProxy< charT, traits >::precision(), previous_u, quiet, libMesh::Real, Residual, libMesh::ExplicitSystem::rhs, rhs_mode, libMesh::NumericVector< T >::scale(), libMesh::BasicOStreamProxy< charT, traits >::setf(), libMesh::System::solution, solution_tolerance, tangent_initialized, Theta, Theta_LOCA, libMesh::DifferentiableSystem::time_solver, libMesh::BasicOStreamProxy< charT, traits >::unsetf(), y, y_old, z, and libMesh::NumericVector< T >::zero().

359 {
360  // Be sure the user has set the continuation parameter pointer
362  libmesh_error_msg("You must set the continuation_parameter pointer " \
363  << "to a member variable of the derived class, preferably in the " \
364  << "Derived class's init_data function. This is how the ContinuationSystem " \
365  << "updates the continuation parameter.");
366 
367  // Use extra precision for all the numbers printed in this function.
368  std::streamsize old_precision = libMesh::out.precision();
370  libMesh::out.setf(std::ios_base::scientific);
371 
372  // We can't start solving the augmented PDE system unless the tangent
373  // vectors have been initialized. This only needs to occur once.
374  if (!tangent_initialized)
376 
377  // Save the old value of -du/dlambda. This will be used after the Newton iterations
378  // to compute the angle between previous tangent vectors. This cosine of this angle is
379  //
380  // tau := abs( (du/d(lambda)_i , du/d(lambda)_{i-1}) / (||du/d(lambda)_i|| * ||du/d(lambda)_{i-1}||) )
381  //
382  // The scaling factor tau (which should vary between 0 and 1) is used to shrink the step-size ds
383  // when we are approaching a turning point. Note that it can only shrink the step size.
384  *y_old = *y;
385 
386  // Set pointer to underlying Newton solver
387  if (!newton_solver)
388  newton_solver = cast_ptr<NewtonSolver *> (this->time_solver->diff_solver().get());
389 
390  // A pair for catching return values from linear system solves.
391  std::pair<unsigned int, Real> rval;
392 
393  // Convergence flag for the entire arcstep
394  bool arcstep_converged = false;
395 
396  // Begin loop over arcstep reductions.
397  for (unsigned int ns=0; ns<n_arclength_reductions; ++ns)
398  {
399  if (!quiet)
400  {
401  libMesh::out << "Current arclength stepsize, ds_current=" << ds_current << std::endl;
402  libMesh::out << "Current parameter value, lambda=" << *continuation_parameter << std::endl;
403  }
404 
405  // Upon exit from the nonlinear loop, the newton_converged flag
406  // will tell us the convergence status of Newton's method.
407  bool newton_converged = false;
408 
409  // The nonlinear residual before *any* nonlinear steps have been taken.
410  Real nonlinear_residual_firststep = 0.;
411 
412  // The nonlinear residual from the current "k" Newton step, before the Newton step
413  Real nonlinear_residual_beforestep = 0.;
414 
415  // The nonlinear residual from the current "k" Newton step, after the Newton step
416  Real nonlinear_residual_afterstep = 0.;
417 
418  // The linear solver tolerance, can be updated dynamically at each Newton step.
419  Real current_linear_tolerance = 0.;
420 
421  // The nonlinear loop
423  {
424  libMesh::out << "\n === Starting Newton step " << newton_step << " ===" << std::endl;
425 
426  // Set the linear system solver tolerance
427  // // 1.) Set the current linear tolerance based as a multiple of the current residual of the system.
428  // const Real residual_multiple = 1.e-4;
429  // Real current_linear_tolerance = residual_multiple*nonlinear_residual_beforestep;
430 
431  // // But if the current residual isn't small, don't let the solver exit with zero iterations!
432  // if (current_linear_tolerance > 1.)
433  // current_linear_tolerance = residual_multiple;
434 
435  // 2.) Set the current linear tolerance based on the method based on technique of Eisenstat & Walker.
436  if (newton_step==0)
437  {
438  // At first step, only try reducing the residual by a small amount
439  current_linear_tolerance = initial_newton_tolerance;//0.01;
440  }
441 
442  else
443  {
444  // The new tolerance is based on the ratio of the most recent tolerances
445  const Real alp=0.5*(1.+std::sqrt(5.));
446  const Real gam=0.9;
447 
448  libmesh_assert_not_equal_to (nonlinear_residual_beforestep, 0.0);
449  libmesh_assert_not_equal_to (nonlinear_residual_afterstep, 0.0);
450 
451  current_linear_tolerance = std::min(gam*std::pow(nonlinear_residual_afterstep/nonlinear_residual_beforestep, alp),
452  current_linear_tolerance*current_linear_tolerance
453  );
454 
455  // Don't let it get ridiculously small!!
456  if (current_linear_tolerance < 1.e-12)
457  current_linear_tolerance = 1.e-12;
458  }
459 
460  if (!quiet)
461  libMesh::out << "Using current_linear_tolerance=" << current_linear_tolerance << std::endl;
462 
463 
464  // Assemble the residual (and Jacobian).
465  rhs_mode = Residual;
466  assembly(true, // Residual
467  true); // Jacobian
468  rhs->close();
469 
470  // Save the current nonlinear residual. We don't need to recompute the residual unless
471  // this is the first step, since it was already computed as part of the convergence check
472  // at the end of the last loop iteration.
473  if (newton_step==0)
474  {
475  nonlinear_residual_beforestep = rhs->l2_norm();
476 
477  // Store the residual before any steps have been taken. This will *not*
478  // be updated at each step, and can be used to see if any progress has
479  // been made from the initial residual at later steps.
480  nonlinear_residual_firststep = nonlinear_residual_beforestep;
481 
482  const Real old_norm_u = solution->l2_norm();
483  libMesh::out << " (before step) ||R||_{L2} = " << nonlinear_residual_beforestep << std::endl;
484  libMesh::out << " (before step) ||R||_{L2}/||u|| = " << nonlinear_residual_beforestep / old_norm_u << std::endl;
485 
486  // In rare cases (very small arcsteps), it's possible that the residual is
487  // already below our absolute linear tolerance.
488  if (nonlinear_residual_beforestep < solution_tolerance)
489  {
490  if (!quiet)
491  libMesh::out << "Initial guess satisfied linear tolerance, exiting with zero Newton iterations!" << std::endl;
492 
493  // Since we go straight from here to the solve of the next tangent, we
494  // have to close the matrix before it can be assembled again.
495  matrix->close();
496  newton_converged=true;
497  break; // out of Newton iterations, with newton_converged=true
498  }
499  }
500 
501  else
502  {
503  nonlinear_residual_beforestep = nonlinear_residual_afterstep;
504  }
505 
506 
507  // Solve the linear system G_u*z = G
508  // Initial guess?
509  z->zero(); // It seems to be extremely important to zero z here, otherwise the solver quits early.
510  z->close();
511 
512  // It's possible that we have selected the current_linear_tolerance so large that
513  // a guess of z=zero yields a linear system residual |Az + R| small enough that the
514  // linear solver exits in zero iterations. If this happens, we will reduce the
515  // current_linear_tolerance until the linear solver does at least 1 iteration.
516  do
517  {
518  rval =
519  linear_solver->solve(*matrix,
520  *z,
521  *rhs,
522  //1.e-12,
523  current_linear_tolerance,
524  newton_solver->max_linear_iterations); // max linear iterations
525 
526  if (rval.first==0)
527  {
528  if (newton_step==0)
529  {
530  libMesh::out << "Repeating initial solve with smaller linear tolerance!" << std::endl;
531  current_linear_tolerance *= initial_newton_tolerance; // reduce the linear tolerance to force the solver to do some work
532  }
533  else
534  // We shouldn't get here ... it means the linear solver did no work on a Newton
535  // step other than the first one. If this happens, we need to think more about our
536  // tolerance selection.
537  libmesh_error_msg("Linear solver did no work!");
538  }
539 
540  } while (rval.first==0);
541 
542 
543  if (!quiet)
544  libMesh::out << " G_u*z = G solver converged at step "
545  << rval.first
546  << " linear tolerance = "
547  << rval.second
548  << "."
549  << std::endl;
550 
551  // Sometimes (I am not sure why) the linear solver exits after zero iterations.
552  // Perhaps it is hitting PETSc's divergence tolerance dtol??? If this occurs,
553  // we should break out of the Newton iteration loop because nothing further is
554  // going to happen... Of course if the tolerance is already small enough after
555  // zero iterations (how can this happen?!) we should not quit.
556  if ((rval.first == 0) && (rval.second > current_linear_tolerance*nonlinear_residual_beforestep))
557  {
558  if (!quiet)
559  libMesh::out << "Linear solver exited in zero iterations!" << std::endl;
560 
561  // Try to find out the reason for convergence/divergence
562  linear_solver->print_converged_reason();
563 
564  break; // out of Newton iterations
565  }
566 
567  // Note: need to scale z by -1 since our code always solves Jx=R
568  // instead of Jx=-R.
569  z->scale(-1.);
570  z->close();
571 
572 
573 
574 
575 
576 
577  // Assemble the G_Lambda vector, skip residual.
578  rhs_mode = G_Lambda;
579 
580  // Assemble both rhs and Jacobian
581  assembly(true, // Residual
582  false); // Jacobian
583 
584  // Not sure if this is really necessary
585  rhs->close();
586  const Real yrhsnorm=rhs->l2_norm();
587  if (yrhsnorm == 0.0)
588  libmesh_error_msg("||G_Lambda|| = 0");
589 
590  // We select a tolerance for the y-system which is based on the inexact Newton
591  // tolerance but scaled by an extra term proportional to the RHS (which is not -> 0 in this case)
592  const Real ysystemtol=current_linear_tolerance*(nonlinear_residual_beforestep/yrhsnorm);
593  if (!quiet)
594  libMesh::out << "ysystemtol=" << ysystemtol << std::endl;
595 
596  // Solve G_u*y = G_{\lambda}
597  // FIXME: Initial guess? This is really a solve for -du/dlambda so we could try
598  // initializing it with the latest approximation to that... du/dlambda ~ du/ds * ds/dlambda
599  //*y = *solution;
600  //y->add(-1., *previous_u);
601  //y->scale(-1. / (*continuation_parameter - old_continuation_parameter)); // Be careful of divide by zero...
602  //y->close();
603 
604  // const unsigned int max_attempts=1;
605  // unsigned int attempt=0;
606  // do
607  // {
608  // if (!quiet)
609  // libMesh::out << "Trying to solve tangent system, attempt " << attempt << std::endl;
610 
611  rval =
612  linear_solver->solve(*matrix,
613  *y,
614  *rhs,
615  //1.e-12,
616  ysystemtol,
617  newton_solver->max_linear_iterations); // max linear iterations
618 
619  if (!quiet)
620  libMesh::out << " G_u*y = G_{lambda} solver converged at step "
621  << rval.first
622  << ", linear tolerance = "
623  << rval.second
624  << "."
625  << std::endl;
626 
627  // Sometimes (I am not sure why) the linear solver exits after zero iterations.
628  // Perhaps it is hitting PETSc's divergence tolerance dtol??? If this occurs,
629  // we should break out of the Newton iteration loop because nothing further is
630  // going to happen...
631  if ((rval.first == 0) && (rval.second > ysystemtol))
632  {
633  if (!quiet)
634  libMesh::out << "Linear solver exited in zero iterations!" << std::endl;
635 
636  break; // out of Newton iterations
637  }
638 
639  // ++attempt;
640  // } while ((attempt<max_attempts) && (rval.first==newton_solver->max_linear_iterations));
641 
642 
643 
644 
645 
646  // Compute N, the residual of the arclength constraint eqn.
647  // Note 1: N(u,lambda,s) := (u-u_{old}, du_ds) + (lambda-lambda_{old}, dlambda_ds) - _ds
648  // We temporarily use the delta_u vector as a temporary vector for this calculation.
649  *delta_u = *solution;
650  delta_u->add(-1., *previous_u);
651 
652  // First part of the arclength constraint
654  const Number N2 = ((*continuation_parameter) - old_continuation_parameter)*dlambda_ds;
655  const Number N3 = ds_current;
656 
657  if (!quiet)
658  {
659  libMesh::out << " N1=" << N1 << std::endl;
660  libMesh::out << " N2=" << N2 << std::endl;
661  libMesh::out << " N3=" << N3 << std::endl;
662  }
663 
664  // The arclength constraint value
665  const Number N = N1+N2-N3;
666 
667  if (!quiet)
668  libMesh::out << " N=" << N << std::endl;
669 
670  const Number duds_dot_z = du_ds->dot(*z);
671  const Number duds_dot_y = du_ds->dot(*y);
672 
673  //libMesh::out << "duds_dot_z=" << duds_dot_z << std::endl;
674  //libMesh::out << "duds_dot_y=" << duds_dot_y << std::endl;
675  //libMesh::out << "dlambda_ds=" << dlambda_ds << std::endl;
676 
677  const Number delta_lambda_numerator = -(N + Theta_LOCA*Theta_LOCA*Theta*duds_dot_z);
678  const Number delta_lambda_denominator = (dlambda_ds - Theta_LOCA*Theta_LOCA*Theta*duds_dot_y);
679 
680  libmesh_assert_not_equal_to (delta_lambda_denominator, 0.0);
681 
682  // Now, we are ready to compute the step delta_lambda
683  const Number delta_lambda_comp = delta_lambda_numerator /
684  delta_lambda_denominator;
685  // Lambda is real-valued
686  const Real delta_lambda = libmesh_real(delta_lambda_comp);
687 
688  // Knowing delta_lambda, we are ready to update delta_u
689  // delta_u = z - delta_lambda*y
690  delta_u->zero();
691  delta_u->add(1., *z);
692  delta_u->add(-delta_lambda, *y);
693  delta_u->close();
694 
695  // Update the system solution and the continuation parameter.
696  solution->add(1., *delta_u);
697  solution->close();
698  *continuation_parameter += delta_lambda;
699 
700  // Did the Newton step actually reduce the residual?
701  rhs_mode = Residual;
702  assembly(true, // Residual
703  false); // Jacobian
704  rhs->close();
705  nonlinear_residual_afterstep = rhs->l2_norm();
706 
707 
708  // In a "normal" Newton step, ||du||/||R|| > 1 since the most recent
709  // step is where you "just were" and the current residual is where
710  // you are now. It can occur that ||du||/||R|| < 1, but these are
711  // likely not good cases to attempt backtracking (?).
712  const Real norm_du_norm_R = delta_u->l2_norm() / nonlinear_residual_afterstep;
713  if (!quiet)
714  libMesh::out << " norm_du_norm_R=" << norm_du_norm_R << std::endl;
715 
716 
717  // Factor to decrease the stepsize by for backtracking
718  Real newton_stepfactor = 1.;
719 
720  const bool attempt_backtracking =
721  (nonlinear_residual_afterstep > solution_tolerance)
722  && (nonlinear_residual_afterstep > nonlinear_residual_beforestep)
723  && (n_backtrack_steps>0)
724  && (norm_du_norm_R > 1.)
725  ;
726 
727  // If residual is not reduced, do Newton back tracking.
728  if (attempt_backtracking)
729  {
730  if (!quiet)
731  libMesh::out << "Newton step did not reduce residual." << std::endl;
732 
733  // back off the previous step.
734  solution->add(-1., *delta_u);
735  solution->close();
736  *continuation_parameter -= delta_lambda;
737 
738  // Backtracking: start cutting the Newton stepsize by halves until
739  // the new residual is actually smaller...
740  for (unsigned int backtrack_step=0; backtrack_step<n_backtrack_steps; ++backtrack_step)
741  {
742  newton_stepfactor *= 0.5;
743 
744  if (!quiet)
745  libMesh::out << "Shrinking step size by " << newton_stepfactor << std::endl;
746 
747  // Take fractional step
748  solution->add(newton_stepfactor, *delta_u);
749  solution->close();
750  *continuation_parameter += newton_stepfactor*delta_lambda;
751 
752  rhs_mode = Residual;
753  assembly(true, // Residual
754  false); // Jacobian
755  rhs->close();
756  nonlinear_residual_afterstep = rhs->l2_norm();
757 
758  if (!quiet)
759  libMesh::out << "At shrink step "
760  << backtrack_step
761  << ", nonlinear_residual_afterstep="
762  << nonlinear_residual_afterstep
763  << std::endl;
764 
765  if (nonlinear_residual_afterstep < nonlinear_residual_beforestep)
766  {
767  if (!quiet)
768  libMesh::out << "Backtracking succeeded!" << std::endl;
769 
770  break; // out of backtracking loop
771  }
772 
773  else
774  {
775  // Back off that step
776  solution->add(-newton_stepfactor, *delta_u);
777  solution->close();
778  *continuation_parameter -= newton_stepfactor*delta_lambda;
779  }
780 
781  // Save a copy of the solution from before the Newton step.
782  //UniquePtr<NumericVector<Number>> prior_iterate = solution->clone();
783  }
784  } // end if (attempte_backtracking)
785 
786 
787  // If we tried backtracking but the residual is still not reduced, print message.
788  if ((attempt_backtracking) && (nonlinear_residual_afterstep > nonlinear_residual_beforestep))
789  {
790  //libMesh::err << "Backtracking failed." << std::endl;
791  libMesh::out << "Backtracking failed." << std::endl;
792 
793  // 1.) Quit, exit program.
794  //libmesh_error_msg("Backtracking failed!");
795 
796  // 2.) Continue with last newton_stepfactor
797  if (newton_step<3)
798  {
799  solution->add(newton_stepfactor, *delta_u);
800  solution->close();
801  *continuation_parameter += newton_stepfactor*delta_lambda;
802  if (!quiet)
803  libMesh::out << "Backtracking could not reduce residual ... continuing anyway!" << std::endl;
804  }
805 
806  // 3.) Break out of Newton iteration loop with newton_converged = false,
807  // reduce the arclength stepsize, and try again.
808  else
809  {
810  break; // out of Newton iteration loop, with newton_converged=false
811  }
812  }
813 
814  // Another type of convergence check: suppose the residual has not been reduced
815  // from its initial value after half of the allowed Newton steps have occurred.
816  // In our experience, this typically means that it isn't going to converge and
817  // we could probably save time by dropping out of the Newton iteration loop and
818  // trying a smaller arcstep.
819  if (this->newton_progress_check)
820  {
821  if ((nonlinear_residual_afterstep > nonlinear_residual_firststep) &&
822  (newton_step+1 > static_cast<unsigned int>(0.5*newton_solver->max_nonlinear_iterations)))
823  {
824  libMesh::out << "Progress check failed: the current residual: "
825  << nonlinear_residual_afterstep
826  << ", is\n"
827  << "larger than the initial residual, and half of the allowed\n"
828  << "number of Newton iterations have elapsed.\n"
829  << "Exiting Newton iterations with converged==false." << std::endl;
830 
831  break; // out of Newton iteration loop, newton_converged = false
832  }
833  }
834 
835  // Safety check: Check the current continuation parameter against user-provided min-allowable parameter value
837  {
838  libMesh::out << "Continuation parameter fell below min-allowable value." << std::endl;
839  break; // out of Newton iteration loop, newton_converged = false
840  }
841 
842  // Safety check: Check the current continuation parameter against user-provided max-allowable parameter value
843  if ( (max_continuation_parameter != 0.0) &&
845  {
846  libMesh::out << "Current continuation parameter value: "
848  << " exceeded max-allowable value."
849  << std::endl;
850  break; // out of Newton iteration loop, newton_converged = false
851  }
852 
853 
854  // Check the convergence of the parameter and the solution. If they are small
855  // enough, we can break out of the Newton iteration loop.
856  const Real norm_delta_u = delta_u->l2_norm();
857  const Real norm_u = solution->l2_norm();
858  libMesh::out << " delta_lambda = " << delta_lambda << std::endl;
859  libMesh::out << " newton_stepfactor*delta_lambda = " << newton_stepfactor*delta_lambda << std::endl;
860  libMesh::out << " lambda_current = " << *continuation_parameter << std::endl;
861  libMesh::out << " ||delta_u|| = " << norm_delta_u << std::endl;
862  libMesh::out << " ||delta_u||/||u|| = " << norm_delta_u / norm_u << std::endl;
863 
864 
865  // Evaluate the residual at the current Newton iterate. We don't want to detect
866  // convergence due to a small Newton step when the residual is still not small.
867  rhs_mode = Residual;
868  assembly(true, // Residual
869  false); // Jacobian
870  rhs->close();
871  const Real norm_residual = rhs->l2_norm();
872  libMesh::out << " ||R||_{L2} = " << norm_residual << std::endl;
873  libMesh::out << " ||R||_{L2}/||u|| = " << norm_residual / norm_u << std::endl;
874 
875 
876  // FIXME: The norm_delta_u tolerance (at least) should be relative.
877  // It doesn't make sense to converge a solution whose size is ~ 10^5 to
878  // a tolerance of 1.e-6. Oh, and we should also probably check the
879  // (relative) size of the residual as well, instead of just the step.
880  if ((std::abs(delta_lambda) < continuation_parameter_tolerance) &&
881  //(norm_delta_u < solution_tolerance) && // This is a *very* strict criterion we can probably skip
882  (norm_residual < solution_tolerance))
883  {
884  if (!quiet)
885  libMesh::out << "Newton iterations converged!" << std::endl;
886 
887  newton_converged = true;
888  break; // out of Newton iterations
889  }
890  } // end nonlinear loop
891 
892  if (!newton_converged)
893  {
894  libMesh::out << "Newton iterations of augmented system did not converge!" << std::endl;
895 
896  // Reduce ds_current, recompute the solution and parameter, and continue to next
897  // arcstep, if there is one.
898  ds_current *= 0.5;
899 
900  // Go back to previous solution and parameter value.
901  *solution = *previous_u;
903 
904  // Compute new predictor with smaller ds
905  apply_predictor();
906  }
907  else
908  {
909  // Set step convergence and break out
910  arcstep_converged=true;
911  break; // out of arclength reduction loop
912  }
913 
914  } // end loop over arclength reductions
915 
916  // Check for convergence of the whole arcstep. If not converged at this
917  // point, we have no choice but to quit.
918  if (!arcstep_converged)
919  libmesh_error_msg("Arcstep failed to converge after max number of reductions! Exiting...");
920 
921  // Print converged solution control parameter and max value.
922  libMesh::out << "lambda_current=" << *continuation_parameter << std::endl;
923  //libMesh::out << "u_max=" << solution->max() << std::endl;
924 
925  // Reset old stream precision and flags.
926  libMesh::out.precision(old_precision);
927  libMesh::out.unsetf(std::ios_base::scientific);
928 
929  // Note: we don't want to go on to the next guess yet, since the user may
930  // want to post-process this data. It's up to the user to call advance_arcstep()
931  // when they are ready to go on.
932 }
T libmesh_real(T a)
double abs(double a)
UniquePtr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:221
Real Theta
Arclength normalization parameter.
Real dlambda_ds
The most recent value of the derivative of the continuation parameter with respect to s...
NumericVector< Number > * previous_u
The solution at the previous value of the continuation variable.
UniquePtr< LinearSolver< Number > > linear_solver
We maintain our own linear solver interface, for solving custom systems of equations and/or things wh...
virtual Real l2_norm() const =0
Real initial_newton_tolerance
How much to try to reduce the residual by at the first (inexact) Newton step.
unsigned int max_nonlinear_iterations
The DiffSolver should exit in failure if max_nonlinear_iterations is exceeded and continue_after_max_...
Definition: diff_solver.h:156
Real old_continuation_parameter
The system also keeps track of the old value of the continuation parameter.
Real * continuation_parameter
The continuation parameter must be a member variable of the derived class, and the "continuation_para...
NumericVector< Number > * delta_u
Temporary vector "delta u" ...
NumericVector< Number > * rhs
The system matrix.
Real solution_tolerance
How tightly should the Newton iterations attempt to converge ||delta_u|| Defaults to 1...
virtual void zero()=0
Set all entries to zero.
Real Theta_LOCA
Another normalization parameter, which is described in the LOCA manual.
unsigned int n_arclength_reductions
Number of arclength reductions to try when Newton fails to reduce the residual.
bool tangent_initialized
False until initialize_tangent() is called.
virtual void scale(const T factor)=0
Scale each element of the vector by the given factor.
NumericVector< Number > * du_ds
Extra work vectors used by the continuation algorithm.
Real max_continuation_parameter
The maximum-allowable value of the continuation parameter.
NumericVector< Number > * z
Temporary vector "z" ...
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
Definition: diff_solver.h:148
NumericVector< Number > * y_old
Temporary vector "y_old" ...
NumericVector< Number > * y
Temporary vector "y" ...
void apply_predictor()
Applies the predictor to the current solution to get a guess for the next solution.
void unsetf(std::ios_base::fmtflags mask)
Clear the associated flags.
bool quiet
If quiet==false, the System prints extra information about what it is doing.
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
Real min_continuation_parameter
The minimum-allowable value of the continuation parameter.
double pow(double a, int b)
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
Real ds_current
Value of stepsize currently in use.
NewtonSolver * newton_solver
A pointer to the underlying Newton solver used by the DiffSystem.
void initialize_tangent()
Before starting arclength continuation, we need at least 2 prior solutions (both solution and u_previ...
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::ios_base::fmtflags setf(std::ios_base::fmtflags fmtfl)
Set the associated flags.
OStreamProxy out
SparseMatrix< Number > * matrix
The system matrix.
virtual void assembly(bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) libmesh_override
Prepares matrix or rhs for matrix assembly.
Definition: fem_system.C:852
virtual T dot(const NumericVector< T > &v) const =0
bool newton_progress_check
True by default, the Newton progress check allows the Newton loop to exit if half the allowed iterati...
unsigned int n_backtrack_steps
Another scaling parameter suggested by the LOCA people.
Real continuation_parameter_tolerance
How tightly should the Newton iterations attempt to converge delta_lambda.
virtual void add(const numeric_index_type i, const T value)=0
Adds value to each entry of the vector.
long double min(long double a, double b)
std::streamsize precision() const
Get the associated write precision.
unsigned int newton_step
Loop counter for nonlinear (Newton) iteration loop.
Number libMesh::System::current_solution ( const dof_id_type  global_dof_number) const
inherited
Returns
The current solution for the specified global DOF.

Definition at line 192 of file system.C.

References libMesh::System::_dof_map, and libMesh::System::current_local_solution.

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::HPCoarsenTest::add_projection(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::ExactErrorEstimator::estimate_error(), main(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::HPCoarsenTest::select_refinement(), SolidSystem::side_time_derivative(), libMesh::EnsightIO::write_scalar_ascii(), and libMesh::EnsightIO::write_vector_ascii().

193 {
194  // Check the sizes
195  libmesh_assert_less (global_dof_number, _dof_map->n_dofs());
196  libmesh_assert_less (global_dof_number, current_local_solution->size());
197 
198  return (*current_local_solution)(global_dof_number);
199 }
UniquePtr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1535
UniquePtr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:1865
virtual bool libMesh::DifferentiablePhysics::damping_residual ( bool  request_jacobian,
DiffContext  
)
virtualinherited

Subtracts a damping vector contribution on elem from elem_residual.

This method is not used in first-order-in-time problems. For second-order-in-time problems, this is the $ C(u,\ddot{u})\ddot{u} $ term. This method is only called for UnsteadySolver-based TimeSolvers.

If this method receives request_jacobian = true, then it should compute elem_jacobian and return true if possible. If elem_jacobian has not been computed then the method should return false.

If the problem has no damping, the default "do-nothing" is correct. Otherwise, this must be reimplemented.

Reimplemented in SecondOrderScalarSystemFirstOrderTimeSolverBase, and SecondOrderScalarSystemSecondOrderTimeSolverBase.

Definition at line 373 of file diff_physics.h.

Referenced by libMesh::EulerSolver::element_residual(), libMesh::Euler2Solver::element_residual(), and libMesh::NewmarkSolver::element_residual().

374  {
375  return request_jacobian;
376  }
void libMesh::System::deactivate ( )
inherited

Deactivates the system.

Only active systems are solved.

Definition at line 2062 of file system.h.

References libMesh::System::_active.

Referenced by libMesh::System::get_equation_systems().

2063 {
2064  _active = false;
2065 }
bool _active
Flag stating if the system is active or not.
Definition: system.h:1908
void libMesh::ImplicitSystem::disable_cache ( )
virtualinherited

Avoids use of any cached data that might affect any solve result.

Should be overridden in derived systems.

Reimplemented from libMesh::System.

Definition at line 313 of file implicit_system.C.

References libMesh::System::assemble_before_solve, libMesh::ImplicitSystem::get_linear_solver(), and libMesh::LinearSolver< T >::reuse_preconditioner().

313  {
314  this->assemble_before_solve = true;
315  this->get_linear_solver()->reuse_preconditioner(false);
316 }
virtual LinearSolver< Number > * get_linear_solver() const
virtual void reuse_preconditioner(bool)
Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent ...
bool assemble_before_solve
Flag which tells the system to whether or not to call the user assembly function during each call to ...
Definition: system.h:1477
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 107 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::LibMeshInit::LibMeshInit(), and libMesh::ReferenceCounter::n_objects().

108 {
109  _enable_print_counter = false;
110  return;
111 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
virtual bool libMesh::DifferentiablePhysics::element_constraint ( bool  request_jacobian,
DiffContext  
)
virtualinherited

Adds the constraint contribution on elem to elem_residual.

If this method receives request_jacobian = true, then it should compute elem_jacobian and return true if possible. If elem_jacobian has not been computed then the method should return false.

Users may need to reimplement this for their particular PDE.

To implement the constraint 0 = G(u), the user should examine u = elem_solution and add (G(u), phi_i) to elem_residual in elem_constraint().

Reimplemented in CoupledSystem, and NavierSystem.

Definition at line 141 of file diff_physics.h.

Referenced by libMesh::EulerSolver::element_residual(), libMesh::Euler2Solver::element_residual(), libMesh::SteadySolver::element_residual(), libMesh::EigenTimeSolver::element_residual(), and libMesh::NewmarkSolver::element_residual().

142  {
143  return request_jacobian;
144  }
virtual void libMesh::DifferentiableSystem::element_postprocess ( DiffContext )
virtualinherited

Does any work that needs to be done on elem in a postprocessing loop.

Reimplemented in LaplaceSystem, LaplaceSystem, and PoissonSystem.

Definition at line 269 of file diff_system.h.

269 {}
virtual void libMesh::DifferentiableQoI::element_qoi ( DiffContext ,
const QoISet  
)
virtualinherited

Does any work that needs to be done on elem in a quantity of interest assembly loop, outputting to elem_qoi.

Only qois included in the supplied QoISet need to be assembled.

Reimplemented in LaplaceQoI.

Definition at line 107 of file diff_qoi.h.

109  {}
virtual void libMesh::DifferentiableQoI::element_qoi_derivative ( DiffContext ,
const QoISet  
)
virtualinherited

Does any work that needs to be done on elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative.

Only qois included in the supplied QoISet need their derivatives assembled.

Reimplemented in HeatSystem, LaplaceSystem, LaplaceSystem, and LaplaceQoI.

Definition at line 119 of file diff_qoi.h.

121  {}
virtual bool libMesh::DifferentiablePhysics::element_time_derivative ( bool  request_jacobian,
DiffContext  
)
virtualinherited

Adds the time derivative contribution on elem to elem_residual.

If this method receives request_jacobian = true, then it should compute elem_jacobian and return true if possible. If elem_jacobian has not been computed then the method should return false.

Users need to reimplement this for their particular PDE.

To implement the physics model du/dt = F(u), the user should examine u = elem_solution and add (F(u), phi_i) to elem_residual in elem_time_derivative().

Reimplemented in SecondOrderScalarSystemFirstOrderTimeSolverBase, FirstOrderScalarSystemBase, HeatSystem, CoupledSystem, ElasticitySystem, LaplaceSystem, CurlCurlSystem, LaplaceSystem, PoissonSystem, LaplaceSystem, LaplaceSystem, CurlCurlSystem, L2System, SolidSystem, NavierSystem, and HeatSystem.

Definition at line 123 of file diff_physics.h.

Referenced by libMesh::DifferentiablePhysics::_eulerian_time_deriv(), libMesh::SteadySolver::element_residual(), and libMesh::EigenTimeSolver::element_residual().

124  {
125  return request_jacobian;
126  }
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

Definition at line 101 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::ReferenceCounter::n_objects().

102 {
103  _enable_print_counter = true;
104  return;
105 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
bool libMesh::FEMPhysics::eulerian_residual ( bool  request_jacobian,
DiffContext context 
)
virtualinherited

Adds a pseudo-convection contribution on elem to elem_residual, if the nodes of elem are being translated by a moving mesh.

This function assumes that the user's time derivative equations (except for any equations involving unknown mesh xyz coordinates themselves) are expressed in an Eulerian frame of reference, and that the user is satisfied with an unstabilized convection term. Lagrangian equations will probably require overriding