libMesh::ContinuationSystem Class Reference

#include <continuation_system.h>

Inheritance diagram for libMesh::ContinuationSystem:

Public Types

enum  Predictor { Euler, AB2, Invalid_Predictor }
 
typedef ContinuationSystem sys_type
 
typedef FEMSystem Parent
 
typedef bool(TimeSolver::* TimeSolverResPtr) (bool, DiffContext &)
 
typedef std::map< std::string, SparseMatrix< Number > * >::iterator matrices_iterator
 
typedef std::map< std::string, SparseMatrix< Number > * >::const_iterator const_matrices_iterator
 
typedef Number(* ValueFunctionPointer) (const Point &p, const Parameters &Parameters, const std::string &sys_name, const std::string &unknown_name)
 
typedef Gradient(* GradientFunctionPointer) (const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
 
typedef std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
 
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)
 
virtual ~ContinuationSystem ()
 
virtual void clear () override
 
virtual void solve () override
 
void continuation_solve ()
 
void advance_arcstep ()
 
void set_max_arclength_stepsize (Real maxds)
 
void save_current_solution ()
 
virtual void assembly (bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) override
 
void mesh_position_get ()
 
void mesh_position_set ()
 
virtual std::unique_ptr< DiffContextbuild_context () override
 
virtual void init_context (DiffContext &) override
 
virtual void postprocess () override
 
virtual void assemble_qoi (const QoISet &indices=QoISet()) override
 
virtual void assemble_qoi_derivative (const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
 
Real numerical_jacobian_h_for_var (unsigned int var_num) const
 
void set_numerical_jacobian_h_for_var (unsigned int var_num, Real new_h)
 
void numerical_jacobian (TimeSolverResPtr res, FEMContext &context) const
 
void numerical_elem_jacobian (FEMContext &context) const
 
void numerical_side_jacobian (FEMContext &context) const
 
void numerical_nonlocal_jacobian (FEMContext &context) const
 
virtual void reinit () override
 
virtual void assemble () override
 
virtual LinearSolver< Number > * get_linear_solver () const override
 
virtual std::pair< unsigned int, Realget_linear_solve_parameters () const override
 
virtual void release_linear_solver (LinearSolver< Number > *) const override
 
virtual std::pair< unsigned int, Realadjoint_solve (const QoISet &qoi_indices=QoISet()) override
 
virtual std::unique_ptr< DifferentiablePhysicsclone_physics () override
 
virtual std::unique_ptr< DifferentiableQoIclone () override
 
const DifferentiablePhysicsget_physics () const
 
DifferentiablePhysicsget_physics ()
 
void attach_physics (DifferentiablePhysics *physics_in)
 
void swap_physics (DifferentiablePhysics *&swap_physics)
 
const DifferentiableQoIget_qoi () const
 
DifferentiableQoIget_qoi ()
 
void attach_qoi (DifferentiableQoI *qoi_in)
 
void set_time_solver (std::unique_ptr< TimeSolver > _time_solver)
 
TimeSolverget_time_solver ()
 
const TimeSolverget_time_solver () const
 
virtual void element_postprocess (DiffContext &)
 
virtual void side_postprocess (DiffContext &)
 
unsigned int get_second_order_dot_var (unsigned int var) const
 
bool have_first_order_scalar_vars () const
 
bool have_second_order_scalar_vars () const
 
sys_typesystem ()
 
virtual void disable_cache () override
 
virtual std::string system_type () const override
 
virtual void assemble_residual_derivatives (const ParameterVector &parameters) override
 
virtual std::pair< unsigned int, Realsensitivity_solve (const ParameterVector &parameters) override
 
virtual std::pair< unsigned int, Realweighted_sensitivity_solve (const ParameterVector &parameters, const ParameterVector &weights) override
 
virtual std::pair< unsigned int, Realweighted_sensitivity_adjoint_solve (const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet()) override
 
virtual void adjoint_qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) override
 
virtual void forward_qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) override
 
virtual void qoi_parameter_hessian (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian) override
 
virtual void qoi_parameter_hessian_vector_product (const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product) override
 
SparseMatrix< Number > & add_matrix (const std::string &mat_name)
 
void remove_matrix (const std::string &mat_name)
 
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 override
 
void init ()
 
virtual void reinit_constraints ()
 
bool is_initialized ()
 
virtual void update ()
 
virtual void restrict_solve_to (const SystemSubset *subset, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO)
 
bool is_adjoint_already_solved () const
 
void set_adjoint_already_solved (bool setting)
 
virtual void qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
 
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=nullptr) const
 
void project_solution (FEMFunctionBase< Number > *f, FEMFunctionBase< Gradient > *g=nullptr) const
 
void project_solution (ValueFunctionPointer fptr, GradientFunctionPointer gptr, const Parameters &parameters) const
 
void project_vector (NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1) const
 
void project_vector (NumericVector< Number > &new_vector, FEMFunctionBase< Number > *f, FEMFunctionBase< Gradient > *g=nullptr, int is_adjoint=-1) const
 
void project_vector (ValueFunctionPointer fptr, GradientFunctionPointer gptr, const Parameters &parameters, NumericVector< Number > &new_vector, int is_adjoint=-1) const
 
void boundary_project_solution (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr)
 
void boundary_project_solution (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, ValueFunctionPointer fptr, GradientFunctionPointer gptr, const Parameters &parameters)
 
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=nullptr, int is_adjoint=-1) const
 
void boundary_project_vector (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, ValueFunctionPointer fptr, GradientFunctionPointer gptr, const Parameters &parameters, NumericVector< Number > &new_vector, int is_adjoint=-1) const
 
unsigned int number () const
 
void update_global_solution (std::vector< Number > &global_soln) const
 
void update_global_solution (std::vector< Number > &global_soln, const processor_id_type dest_proc) const
 
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 ()
 
void deactivate ()
 
void set_basic_system_only ()
 
vectors_iterator vectors_begin ()
 
const_vectors_iterator vectors_begin () const
 
vectors_iterator vectors_end ()
 
const_vectors_iterator vectors_end () const
 
NumericVector< Number > & add_vector (const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
 
void remove_vector (const std::string &vec_name)
 
bool & project_solution_on_reinit (void)
 
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)
 
int vector_is_adjoint (const std::string &vec_name) const
 
void set_vector_preservation (const std::string &vec_name, bool preserve)
 
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=nullptr)
 
unsigned int add_variable (const std::string &var, const Order order=FIRST, const FEFamily=LAGRANGE, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
 
unsigned int add_variables (const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
 
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=nullptr)
 
const Variablevariable (unsigned int var) const
 
const VariableGroupvariable_group (unsigned int vg) const
 
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
 
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)
 
Real calculate_norm (const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
 
Real calculate_norm (const NumericVector< Number > &v, const SystemNorm &norm, std::set< unsigned int > *skip_dimensions=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)
 
void read_legacy_data (Xdr &io, const bool read_additional_data=true)
 
template<typename ValType >
void read_serialized_data (Xdr &io, const bool read_additional_data=true)
 
void read_serialized_data (Xdr &io, const bool read_additional_data=true)
 
template<typename InValType >
std::size_t read_serialized_vectors (Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
 
std::size_t read_serialized_vectors (Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
 
template<typename InValType >
void read_parallel_data (Xdr &io, const bool read_additional_data)
 
void read_parallel_data (Xdr &io, const bool read_additional_data)
 
void write_header (Xdr &io, const std::string &version, const bool write_additional_data) const
 
void write_serialized_data (Xdr &io, const bool write_additional_data=true) const
 
std::size_t write_serialized_vectors (Xdr &io, const std::vector< const NumericVector< Number > *> &vectors) const
 
void write_parallel_data (Xdr &io, const bool write_additional_data) const
 
std::string get_info () const
 
void attach_init_function (void fptr(EquationSystems &es, const std::string &name))
 
void attach_init_object (Initialization &init)
 
void attach_assemble_function (void fptr(EquationSystems &es, const std::string &name))
 
void attach_assemble_object (Assembly &assemble)
 
void attach_constraint_function (void fptr(EquationSystems &es, const std::string &name))
 
void attach_constraint_object (Constraint &constrain)
 
void attach_QOI_function (void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices))
 
void attach_QOI_object (QOI &qoi)
 
void attach_QOI_derivative (void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints))
 
void attach_QOI_derivative_object (QOIDerivative &qoi_derivative)
 
virtual void user_initialization ()
 
virtual void user_assembly ()
 
virtual void user_constrain ()
 
virtual void user_QOI (const QoISet &qoi_indices)
 
virtual void user_QOI_derivative (const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
 
virtual void re_update ()
 
virtual void restrict_vectors ()
 
virtual void prolong_vectors ()
 
Number current_solution (const dof_id_type global_dof_number) const
 
unsigned int n_qois () 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
 
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
 
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
 
void local_dof_indices (const unsigned int var, std::set< dof_id_type > &var_indices) const
 
void zero_variable (NumericVector< Number > &v, unsigned int var_num) const
 
bool & hide_output ()
 
void projection_matrix (SparseMatrix< Number > &proj_mat) const
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
virtual void clear_physics ()
 
virtual void init_physics (const System &sys)
 
virtual bool element_time_derivative (bool request_jacobian, DiffContext &)
 
virtual bool element_constraint (bool request_jacobian, DiffContext &)
 
virtual bool side_time_derivative (bool request_jacobian, DiffContext &)
 
virtual bool side_constraint (bool request_jacobian, DiffContext &)
 
virtual bool nonlocal_time_derivative (bool request_jacobian, DiffContext &)
 
virtual bool nonlocal_constraint (bool request_jacobian, DiffContext &)
 
virtual void time_evolving (unsigned int var)
 
virtual void time_evolving (unsigned int var, unsigned int order)
 
bool is_time_evolving (unsigned int var) const
 
virtual bool eulerian_residual (bool request_jacobian, DiffContext &)
 
virtual bool eulerian_residual (bool request_jacobian, DiffContext &context) override
 
virtual bool mass_residual (bool request_jacobian, DiffContext &)
 
virtual bool mass_residual (bool request_jacobian, DiffContext &) override
 
virtual bool side_mass_residual (bool request_jacobian, DiffContext &)
 
virtual bool nonlocal_mass_residual (bool request_jacobian, DiffContext &c)
 
virtual bool damping_residual (bool request_jacobian, DiffContext &)
 
virtual bool side_damping_residual (bool request_jacobian, DiffContext &)
 
virtual bool nonlocal_damping_residual (bool request_jacobian, DiffContext &)
 
virtual void set_mesh_system (System *sys)
 
const Systemget_mesh_system () const
 
Systemget_mesh_system ()
 
virtual void set_mesh_x_var (unsigned int var)
 
unsigned int get_mesh_x_var () const
 
virtual void set_mesh_y_var (unsigned int var)
 
unsigned int get_mesh_y_var () const
 
virtual void set_mesh_z_var (unsigned int var)
 
unsigned int get_mesh_z_var () const
 
bool _eulerian_time_deriv (bool request_jacobian, DiffContext &)
 
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 > &)
 
virtual void clear_qoi ()
 
virtual void element_qoi (DiffContext &, const QoISet &)
 
virtual void element_qoi_derivative (DiffContext &, const QoISet &)
 
virtual void side_qoi (DiffContext &, const QoISet &)
 
virtual void side_qoi_derivative (DiffContext &, const QoISet &)
 
virtual void thread_join (std::vector< Number > &qoi, const std::vector< Number > &other_qoi, const QoISet &qoi_indices)
 
virtual void parallel_op (const Parallel::Communicator &communicator, std::vector< Number > &sys_qoi, std::vector< Number > &local_qoi, const QoISet &qoi_indices)
 
virtual void finalize_derivative (NumericVector< Number > &derivatives, std::size_t qoi_index)
 

Static Public Member Functions

static std::string get_info ()
 
static void print_info (std::ostream &out=libMesh::out)
 
static unsigned int n_objects ()
 
static void enable_print_counter_info ()
 
static void disable_print_counter_info ()
 

Public Attributes

Realcontinuation_parameter
 
bool quiet
 
Real continuation_parameter_tolerance
 
Real solution_tolerance
 
Real initial_newton_tolerance
 
Real old_continuation_parameter
 
Real min_continuation_parameter
 
Real max_continuation_parameter
 
Real Theta
 
Real Theta_LOCA
 
unsigned int n_backtrack_steps
 
unsigned int n_arclength_reductions
 
Real ds_min
 
Predictor predictor
 
Real newton_stepgrowth_aggressiveness
 
bool newton_progress_check
 
bool fe_reinit_during_postprocess
 
Real numerical_jacobian_h
 
Real verify_analytic_jacobians
 
std::unique_ptr< TimeSolvertime_solver
 
Real deltat
 
bool postprocess_sides
 
bool print_solution_norms
 
bool print_solutions
 
bool print_residual_norms
 
bool print_residuals
 
bool print_jacobian_norms
 
bool print_jacobians
 
bool print_element_solutions
 
bool print_element_residuals
 
bool print_element_jacobians
 
SparseMatrix< Number > * matrix
 
bool zero_out_matrix_and_rhs
 
NumericVector< Number > * rhs
 
bool assemble_before_solve
 
bool use_fixed_solution
 
int extra_quadrature_order
 
std::unique_ptr< NumericVector< Number > > solution
 
std::unique_ptr< NumericVector< Number > > current_local_solution
 
Real time
 
std::vector< Numberqoi
 
bool compute_internal_sides
 
bool assemble_qoi_sides
 
bool assemble_qoi_internal_sides
 
bool assemble_qoi_elements
 

Protected Types

enum  RHS_Mode { Residual, G_Lambda }
 
typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 

Protected Member Functions

virtual void init_data () override
 
void add_second_order_dot_vars ()
 
void add_dot_var_dirichlet_bcs (unsigned int var_idx, unsigned int dot_var_idx)
 
virtual void init_matrices ()
 
void project_vector (NumericVector< Number > &, int is_adjoint=-1) const
 
void project_vector (const NumericVector< Number > &, NumericVector< Number > &, int is_adjoint=-1) const
 
void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

RHS_Mode rhs_mode
 
DifferentiablePhysics_diff_physics
 
DifferentiableQoIdiff_qoi
 
const Parallel::Communicator_communicator
 
System_mesh_sys
 
unsigned int _mesh_x_var
 
unsigned int _mesh_y_var
 
unsigned int _mesh_z_var
 
std::vector< unsigned int > _time_evolving
 
std::set< unsigned int > _first_order_vars
 
std::set< unsigned int > _second_order_vars
 
std::map< unsigned int, unsigned int > _second_order_dot_vars
 

Static Protected Attributes

static Counts _counts
 
static Threads::atomic< unsigned int > _n_objects
 
static Threads::spin_mutex _mutex
 
static bool _enable_print_counter = true
 

Private Member Functions

void initialize_tangent ()
 
void solve_tangent ()
 
void update_solution ()
 
void set_Theta ()
 
void set_Theta_LOCA ()
 
void apply_predictor ()
 

Private Attributes

NumericVector< Number > * du_ds
 
NumericVector< Number > * previous_du_ds
 
NumericVector< Number > * previous_u
 
NumericVector< Number > * y
 
NumericVector< Number > * y_old
 
NumericVector< Number > * z
 
NumericVector< Number > * delta_u
 
std::unique_ptr< LinearSolver< Number > > linear_solver
 
bool tangent_initialized
 
NewtonSolvernewton_solver
 
Real dlambda_ds
 
Real ds
 
Real ds_current
 
Real previous_dlambda_ds
 
Real previous_ds
 
unsigned int newton_step
 

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

◆ const_matrices_iterator

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

Definition at line 306 of file implicit_system.h.

◆ const_vectors_iterator

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

Definition at line 749 of file system.h.

◆ Counts

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 117 of file reference_counter.h.

◆ GradientFunctionPointer

typedef Gradient(* libMesh::System::GradientFunctionPointer) (const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
inherited

Definition at line 524 of file system.h.

◆ matrices_iterator

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

Matrix iterator typedefs.

Definition at line 305 of file implicit_system.h.

◆ Parent

The type of the parent.

Definition at line 79 of file continuation_system.h.

◆ sys_type

The type of system.

Definition at line 74 of file continuation_system.h.

◆ TimeSolverResPtr

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

Syntax sugar to make numerical_jacobian() declaration easier.

Definition at line 214 of file fem_system.h.

◆ ValueFunctionPointer

typedef Number(* libMesh::System::ValueFunctionPointer) (const Point &p, const Parameters &Parameters, const std::string &sys_name, const std::string &unknown_name)
inherited

Projects arbitrary functions onto the current solution. 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.

Definition at line 520 of file system.h.

◆ vectors_iterator

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

◆ 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.

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.

◆ RHS_Mode

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

◆ ContinuationSystem()

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),
33  continuation_parameter(nullptr),
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),
52  newton_solver(nullptr),
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 }
static std::unique_ptr< LinearSolver< Number > > build(const libMesh::Parallel::Communicator &comm_in, const SolverPackage solver_package=libMesh::default_solver_package())
Definition: linear_solver.C:57
std::unique_ptr< LinearSolver< Number > > linear_solver
bool on_command_line(std::string arg)
Definition: libmesh.C:876
const std::string & name() const
Definition: system.h:2017

◆ ~ContinuationSystem()

libMesh::ContinuationSystem::~ContinuationSystem ( )
virtual

Destructor.

Definition at line 72 of file continuation_system.C.

References clear().

73 {
74  this->clear();
75 }
virtual void clear() override

Member Function Documentation

◆ _eulerian_time_deriv()

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

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

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

◆ activate()

void libMesh::System::activate ( )
inlineinherited

Activates the system. Only active systems are solved.

Definition at line 2073 of file system.h.

References libMesh::System::_active.

2074 {
2075  _active = true;
2076 }

◆ active()

bool libMesh::System::active ( ) const
inlineinherited
Returns
true if the system is active, false otherwise. An active system will be solved.

Definition at line 2065 of file system.h.

References libMesh::System::_active.

2066 {
2067  return _active;
2068 }

◆ add_adjoint_rhs()

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 1021 of file system.C.

References libMesh::System::add_vector().

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

1022 {
1023  std::ostringstream adjoint_rhs_name;
1024  adjoint_rhs_name << "adjoint_rhs" << i;
1025 
1026  return this->add_vector(adjoint_rhs_name.str(), false);
1027 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:661

◆ add_adjoint_solution()

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 957 of file system.C.

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

Referenced by libMesh::ImplicitSystem::adjoint_solve().

958 {
959  std::ostringstream adjoint_name;
960  adjoint_name << "adjoint_solution" << i;
961 
962  NumericVector<Number> & returnval = this->add_vector(adjoint_name.str());
963  this->set_vector_as_adjoint(adjoint_name.str(), i);
964  return returnval;
965 }
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Definition: system.C:885
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:661

◆ add_dot_var_dirichlet_bcs()

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 227 of file diff_system.C.

References libMesh::DofMap::add_dirichlet_boundary(), libMesh::DofMap::get_dirichlet_boundaries(), and libMesh::System::get_dof_map().

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

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

◆ add_matrix()

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 203 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(), and libMesh::NewmarkSystem::NewmarkSystem().

204 {
205  // only add matrices before initializing...
206  if (!_can_add_matrices)
207  libmesh_error_msg("ERROR: Too late. Cannot add matrices to the system after initialization"
208  << "\n any more. You should have done this earlier.");
209 
210  // Return the matrix if it is already there.
211  if (this->have_matrix(mat_name))
212  return *(_matrices[mat_name]);
213 
214  // Otherwise build the matrix and return it.
215  SparseMatrix<Number> * buf = SparseMatrix<Number>::build(this->comm()).release();
216  _matrices.insert (std::make_pair (mat_name, buf));
217 
218  return *buf;
219 }
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
bool have_matrix(const std::string &mat_name) const
const Parallel::Communicator & comm() const
std::map< std::string, SparseMatrix< Number > * > _matrices

◆ add_second_order_dot_vars()

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 (const auto & var_id : second_order_vars)
204  {
205  const Variable & var = this->variable(var_id);
206  std::string new_var_name = std::string("dot_")+var.name();
207 
208  unsigned int v_var_idx;
209 
210  if (var.active_subdomains().empty())
211  v_var_idx = this->add_variable( new_var_name, var.type() );
212  else
213  v_var_idx = this->add_variable( new_var_name, var.type(), &var.active_subdomains() );
214 
215  _second_order_dot_vars.insert(std::pair<unsigned int, unsigned int>(var_id, v_var_idx));
216 
217  // The new velocities are time evolving variables of first order
218  this->time_evolving( v_var_idx, 1 );
219 
220  // And if there are any boundary conditions set on the second order
221  // variable, we also need to set it on its velocity variable.
222  this->add_dot_var_dirichlet_bcs(var_id, v_var_idx);
223  }
224  }
225 }
const Variable & variable(unsigned int var) const
Definition: system.h:2133
void add_dot_var_dirichlet_bcs(unsigned int var_idx, unsigned int dot_var_idx)
Definition: diff_system.C:227
std::map< unsigned int, unsigned int > _second_order_dot_vars
Definition: diff_physics.h:571
const std::set< unsigned int > & get_second_order_vars() const
Definition: diff_physics.h:530
virtual void time_evolving(unsigned int var)
Definition: diff_physics.h:249
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Definition: system.C:1081

◆ add_sensitivity_rhs()

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 1051 of file system.C.

References libMesh::System::add_vector().

Referenced by libMesh::ImplicitSystem::assemble_residual_derivatives().

1052 {
1053  std::ostringstream sensitivity_rhs_name;
1054  sensitivity_rhs_name << "sensitivity_rhs" << i;
1055 
1056  return this->add_vector(sensitivity_rhs_name.str(), false);
1057 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:661

◆ add_sensitivity_solution()

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 906 of file system.C.

References libMesh::System::add_vector().

Referenced by libMesh::ImplicitSystem::sensitivity_solve().

907 {
908  std::ostringstream sensitivity_name;
909  sensitivity_name << "sensitivity_solution" << i;
910 
911  return this->add_vector(sensitivity_name.str());
912 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:661

◆ add_variable() [1/2]

unsigned int libMesh::System::add_variable ( const std::string &  var,
const FEType type,
const std::set< subdomain_id_type > *const  active_subdomains = 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 1081 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::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(), libMesh::ErrorVector::plot_error(), and libMesh::System::read_header().

1084 {
1085  libmesh_assert(!this->is_initialized());
1086 
1087  // Make sure the variable isn't there already
1088  // or if it is, that it's the type we want
1089  for (unsigned int v=0; v<this->n_vars(); v++)
1090  if (this->variable_name(v) == var)
1091  {
1092  if (this->variable_type(v) == type)
1093  return _variables[v].number();
1094 
1095  libmesh_error_msg("ERROR: incompatible variable " << var << " has already been added for this system!");
1096  }
1097 
1098  // Optimize for VariableGroups here - if the user is adding multiple
1099  // variables of the same FEType and subdomain restriction, catch
1100  // that here and add them as members of the same VariableGroup.
1101  //
1102  // start by setting this flag to whatever the user has requested
1103  // and then consider the conditions which should negate it.
1104  bool should_be_in_vg = this->identify_variable_groups();
1105 
1106  // No variable groups, nothing to add to
1107  if (!this->n_variable_groups())
1108  should_be_in_vg = false;
1109 
1110  else
1111  {
1112  VariableGroup & vg(_variable_groups.back());
1113 
1114  // get a pointer to their subdomain restriction, if any.
1115  const std::set<subdomain_id_type> * const
1116  their_active_subdomains (vg.implicitly_active() ?
1117  nullptr : &vg.active_subdomains());
1118 
1119  // Different types?
1120  if (vg.type() != type)
1121  should_be_in_vg = false;
1122 
1123  // they are restricted, we aren't?
1124  if (their_active_subdomains && !active_subdomains)
1125  should_be_in_vg = false;
1126 
1127  // they aren't restricted, we are?
1128  if (!their_active_subdomains && active_subdomains)
1129  should_be_in_vg = false;
1130 
1131  if (their_active_subdomains && active_subdomains)
1132  // restricted to different sets?
1133  if (*their_active_subdomains != *active_subdomains)
1134  should_be_in_vg = false;
1135 
1136  // OK, after all that, append the variable to the vg if none of the conditions
1137  // were violated
1138  if (should_be_in_vg)
1139  {
1140  const unsigned short curr_n_vars = cast_int<unsigned short>
1141  (this->n_vars());
1142 
1143  vg.append (var);
1144 
1145  _variables.push_back(vg(vg.n_variables()-1));
1146  _variable_numbers[var] = curr_n_vars;
1147  return curr_n_vars;
1148  }
1149  }
1150 
1151  // otherwise, fall back to adding a single variable group
1152  return this->add_variables (std::vector<std::string>(1, var),
1153  type,
1154  active_subdomains);
1155 }
unsigned int add_variables(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Definition: system.C:1171
std::map< std::string, unsigned short int > _variable_numbers
Definition: system.h:1922
unsigned int n_variable_groups() const
Definition: system.h:2113
std::vector< Variable > _variables
Definition: system.h:1911
unsigned int number() const
Definition: system.h:2025
std::vector< VariableGroup > _variable_groups
Definition: system.h:1916
bool is_initialized()
Definition: system.h:2089
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2153
bool identify_variable_groups() const
Definition: system.h:2201
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2183
unsigned int n_vars() const
Definition: system.h:2105

◆ add_variable() [2/2]

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 = 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 1159 of file system.C.

References libMesh::System::add_variable().

1163 {
1164  return this->add_variable(var,
1165  FEType(order, family),
1166  active_subdomains);
1167 }
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Definition: system.C:1081

◆ add_variables() [1/2]

unsigned int libMesh::System::add_variables ( const std::vector< std::string > &  vars,
const FEType type,
const std::set< subdomain_id_type > *const  active_subdomains = 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 1171 of file system.C.

References libMesh::System::_variable_groups, libMesh::System::_variable_numbers, libMesh::System::_variables, libMesh::System::is_initialized(), 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(), and libMesh::System::add_variables().

1174 {
1175  libmesh_assert(!this->is_initialized());
1176 
1177  // Make sure the variable isn't there already
1178  // or if it is, that it's the type we want
1179  for (std::size_t ov=0; ov<vars.size(); ov++)
1180  for (unsigned int v=0; v<this->n_vars(); v++)
1181  if (this->variable_name(v) == vars[ov])
1182  {
1183  if (this->variable_type(v) == type)
1184  return _variables[v].number();
1185 
1186  libmesh_error_msg("ERROR: incompatible variable " << vars[ov] << " has already been added for this system!");
1187  }
1188 
1189  const unsigned short curr_n_vars = cast_int<unsigned short>
1190  (this->n_vars());
1191 
1192  const unsigned int next_first_component = this->n_components();
1193 
1194  // Add the variable group to the list
1195  _variable_groups.push_back((active_subdomains == nullptr) ?
1196  VariableGroup(this, vars, curr_n_vars,
1197  next_first_component, type) :
1198  VariableGroup(this, vars, curr_n_vars,
1199  next_first_component, type, *active_subdomains));
1200 
1201  const VariableGroup & vg (_variable_groups.back());
1202 
1203  // Add each component of the group individually
1204  for (auto v : IntRange<unsigned int>(0, vars.size()))
1205  {
1206  _variables.push_back (vg(v));
1207  _variable_numbers[vars[v]] = cast_int<unsigned short>
1208  (curr_n_vars+v);
1209  }
1210 
1211  libmesh_assert_equal_to ((curr_n_vars+vars.size()), this->n_vars());
1212 
1213  // BSK - Defer this now to System::init_data() so we can detect
1214  // VariableGroups 12/28/2012
1215  // // Add the variable group to the _dof_map
1216  // _dof_map->add_variable_group (vg);
1217 
1218  // Return the number of the new variable
1219  return cast_int<unsigned int>(curr_n_vars+vars.size()-1);
1220 }
std::map< std::string, unsigned short int > _variable_numbers
Definition: system.h:1922
unsigned int n_components() const
Definition: system.h:2121
std::vector< Variable > _variables
Definition: system.h:1911
unsigned int number() const
Definition: system.h:2025
std::vector< VariableGroup > _variable_groups
Definition: system.h:1916
bool is_initialized()
Definition: system.h:2089
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2153
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2183
unsigned int n_vars() const
Definition: system.h:2105

◆ add_variables() [2/2]

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 = 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 1224 of file system.C.

References libMesh::System::add_variables().

1228 {
1229  return this->add_variables(vars,
1230  FEType(order, family),
1231  active_subdomains);
1232 }
unsigned int add_variables(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Definition: system.C:1171

◆ add_vector()

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 661 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(), libMesh::NewmarkSystem::NewmarkSystem(), libMesh::System::read_header(), libMesh::FrequencySystem::set_frequencies(), libMesh::FrequencySystem::set_frequencies_by_range(), and libMesh::FrequencySystem::set_frequencies_by_steps().

664 {
665  // Return the vector if it is already there.
666  if (this->have_vector(vec_name))
667  return *(_vectors[vec_name]);
668 
669  // Otherwise build the vector
670  NumericVector<Number> * buf = NumericVector<Number>::build(this->comm()).release();
671  _vectors.insert (std::make_pair (vec_name, buf));
672  _vector_projections.insert (std::make_pair (vec_name, projections));
673 
674  _vector_types.insert (std::make_pair (vec_name, type));
675 
676  // Vectors are primal by default
677  _vector_is_adjoint.insert (std::make_pair (vec_name, -1));
678 
679  // Initialize it if necessary
680  if (_is_initialized)
681  {
682  if (type == GHOSTED)
683  {
684 #ifdef LIBMESH_ENABLE_GHOSTED
685  buf->init (this->n_dofs(), this->n_local_dofs(),
686  _dof_map->get_send_list(), false,
687  GHOSTED);
688 #else
689  libmesh_error_msg("Cannot initialize ghosted vectors when they are not enabled.");
690 #endif
691  }
692  else
693  buf->init (this->n_dofs(), this->n_local_dofs(), false, type);
694  }
695 
696  return *buf;
697 }
std::map< std::string, ParallelType > _vector_types
Definition: system.h:1952
bool _is_initialized
Definition: system.h:1971
std::unique_ptr< DofMap > _dof_map
Definition: system.h:1884
const Parallel::Communicator & comm() const
dof_id_type n_local_dofs() const
Definition: system.C:187
dof_id_type n_dofs() const
Definition: system.C:150
std::map< std::string, int > _vector_is_adjoint
Definition: system.h:1947
bool have_vector(const std::string &vec_name) const
Definition: system.h:2225
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
std::map< std::string, NumericVector< Number > *> _vectors
Definition: system.h:1935
std::map< std::string, bool > _vector_projections
Definition: system.h:1941

◆ add_weighted_sensitivity_adjoint_solution()

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 989 of file system.C.

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

Referenced by libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve().

990 {
991  std::ostringstream adjoint_name;
992  adjoint_name << "weighted_sensitivity_adjoint_solution" << i;
993 
994  NumericVector<Number> & returnval = this->add_vector(adjoint_name.str());
995  this->set_vector_as_adjoint(adjoint_name.str(), i);
996  return returnval;
997 }
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Definition: system.C:885
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:661

◆ add_weighted_sensitivity_solution()

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 936 of file system.C.

References libMesh::System::add_vector().

Referenced by libMesh::ImplicitSystem::weighted_sensitivity_solve().

937 {
938  return this->add_vector("weighted_sensitivity_solution");
939 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:661

◆ adjoint_qoi_parameter_sensitivity()

void libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity ( const QoISet qoi_indices,
const ParameterVector parameters,
SensitivityData sensitivities 
)
overridevirtualinherited

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 697 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::n_qois(), libMesh::System::qoi, libMesh::Real, libMesh::ParameterVector::size(), and libMesh::TOLERANCE.

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

◆ adjoint_solve()

std::pair< unsigned int, Real > libMesh::DifferentiableSystem::adjoint_solve ( const QoISet qoi_indices = QoISet())
overridevirtualinherited

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().

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()) override
void set_is_adjoint(bool _is_adjoint_value)
Definition: time_solver.h:240
TimeSolver & get_time_solver()
Definition: diff_system.h:415

◆ advance_arcstep()

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 }

◆ apply_predictor()

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 }
NumericVector< Number > * previous_du_ds
NumericVector< Number > * du_ds
std::unique_ptr< NumericVector< Number > > solution
Definition: system.h:1523
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ assemble()

void libMesh::DifferentiableSystem::assemble ( )
overridevirtualinherited

Prepares matrix and rhs for matrix assembly. Users should not reimplement this. Note that in some cases only current_local_solution is used during assembly, and, therefore, if solution has been altered without update() being called, then the user must call update() before calling this function.

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) override=0

◆ assemble_qoi()

void libMesh::FEMSystem::assemble_qoi ( const QoISet indices = QoISet())
overridevirtualinherited

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 1121 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::System::n_qois(), libMesh::DifferentiableQoI::parallel_op(), libMesh::Threads::parallel_reduce(), libMesh::System::qoi, libMesh::StoredRange< iterator_type, object_type >::reset(), and libMesh::System::update().

1122 {
1123  LOG_SCOPE("assemble_qoi()", "FEMSystem");
1124 
1125  const MeshBase & mesh = this->get_mesh();
1126 
1127  this->update();
1128 
1129  const unsigned int Nq = this->n_qois();
1130 
1131  // the quantity of interest is assumed to be a sum of element and
1132  // side terms
1133  for (unsigned int i=0; i != Nq; ++i)
1134  if (qoi_indices.has_index(i))
1135  qoi[i] = 0;
1136 
1137  // Create a non-temporary qoi_contributions object, so we can query
1138  // its results after the reduction
1139  QoIContributions qoi_contributions(*this, *(this->diff_qoi), qoi_indices);
1140 
1141  // Loop over every active mesh element on this processor
1144  qoi_contributions);
1145 
1146  this->diff_qoi->parallel_op( this->comm(), this->qoi, qoi_contributions.qoi, qoi_indices );
1147 }
unsigned int n_qois() const
Definition: system.h:2278
MeshBase & mesh
const Parallel::Communicator & comm() const
const MeshBase & get_mesh() const
Definition: system.h:2033
Base class for Mesh.
Definition: mesh_base.h:77
DifferentiableQoI * diff_qoi
Definition: diff_system.h:378
virtual void parallel_op(const Parallel::Communicator &communicator, std::vector< Number > &sys_qoi, std::vector< Number > &local_qoi, const QoISet &qoi_indices)
std::vector< Number > qoi
Definition: system.h:1558
virtual element_iterator active_local_elements_begin()=0
virtual void update()
Definition: system.C:408
void parallel_reduce(const Range &range, Body &body)
Definition: threads_none.h:101
virtual element_iterator active_local_elements_end()=0

◆ assemble_qoi_derivative()

void libMesh::FEMSystem::assemble_qoi_derivative ( const QoISet qoi_indices = QoISet(),
bool  include_liftfunc = true,
bool  apply_constraints = true 
)
overridevirtualinherited

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 1151 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::System::n_qois(), libMesh::Threads::parallel_for(), libMesh::StoredRange< iterator_type, object_type >::reset(), libMesh::System::update(), and libMesh::NumericVector< T >::zero().

1154 {
1155  LOG_SCOPE("assemble_qoi_derivative()", "FEMSystem");
1156 
1157  const MeshBase & mesh = this->get_mesh();
1158 
1159  this->update();
1160 
1161  // The quantity of interest derivative assembly accumulates on
1162  // initially zero vectors
1163  for (unsigned int i=0; i != this->n_qois(); ++i)
1164  if (qoi_indices.has_index(i))
1165  this->add_adjoint_rhs(i).zero();
1166 
1167  // Loop over every active mesh element on this processor
1170  QoIDerivativeContributions(*this, qoi_indices,
1171  *(this->diff_qoi),
1172  include_liftfunc,
1173  apply_constraints));
1174 
1175  for (unsigned int i=0; i != this->n_qois(); ++i)
1176  if (qoi_indices.has_index(i))
1177  this->diff_qoi->finalize_derivative(this->get_adjoint_rhs(i),i);
1178 }
virtual void finalize_derivative(NumericVector< Number > &derivatives, std::size_t qoi_index)
void parallel_for(const Range &range, const Body &body)
Definition: threads_none.h:73
unsigned int n_qois() const
Definition: system.h:2278
MeshBase & mesh
const MeshBase & get_mesh() const
Definition: system.h:2033
Base class for Mesh.
Definition: mesh_base.h:77
virtual void zero()=0
DifferentiableQoI * diff_qoi
Definition: diff_system.h:378
bool has_index(std::size_t) const
Definition: qoi_set.h:221
virtual element_iterator active_local_elements_begin()=0
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1021
virtual void update()
Definition: system.C:408
virtual element_iterator active_local_elements_end()=0

◆ assemble_residual_derivatives()

void libMesh::ImplicitSystem::assemble_residual_derivatives ( const ParameterVector parameters)
overridevirtualinherited

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 654 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(), and libMesh::ImplicitSystem::sensitivity_solve().

655 {
656  ParameterVector & parameters =
657  const_cast<ParameterVector &>(parameters_in);
658 
659  const unsigned int Np = cast_int<unsigned int>
660  (parameters.size());
661 
662  for (unsigned int p=0; p != Np; ++p)
663  {
664  NumericVector<Number> & sensitivity_rhs = this->add_sensitivity_rhs(p);
665 
666  // Approximate -(partial R / partial p) by
667  // (R(p-dp) - R(p+dp)) / (2*dp)
668 
669  Number old_parameter = *parameters[p];
670 
671  const Real delta_p =
672  TOLERANCE * std::max(std::abs(old_parameter), 1e-3);
673 
674  *parameters[p] -= delta_p;
675 
676  // this->assembly(true, false, true);
677  this->assembly(true, false, false);
678  this->rhs->close();
679  sensitivity_rhs = *this->rhs;
680 
681  *parameters[p] = old_parameter + delta_p;
682 
683  // this->assembly(true, false, true);
684  this->assembly(true, false, false);
685  this->rhs->close();
686 
687  sensitivity_rhs -= *this->rhs;
688  sensitivity_rhs /= (2*delta_p);
689  sensitivity_rhs.close();
690 
691  *parameters[p] = old_parameter;
692  }
693 }
double abs(double a)
NumericVector< Number > * rhs
NumericVector< Number > & add_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1051
static const Real TOLERANCE
long double max(long double a, double b)
virtual void assembly(bool, bool, bool=false, bool=false)
virtual void close()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ assembly()

void libMesh::FEMSystem::assembly ( bool  get_residual,
bool  get_jacobian,
bool  apply_heterogeneous_constraints = false,
bool  apply_no_constraints = false 
)
overridevirtualinherited

Prepares matrix or rhs for matrix assembly. Users may reimplement this to add pre- or post-assembly code before or after calling FEMSystem::assembly(). Note that in some cases only current_local_solution is used during assembly, and, therefore, if solution has been altered without update() being called, then the user must call update() before calling this function.

Implements libMesh::DifferentiableSystem.

Definition at line 854 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::SparseMatrix< T >::l1_norm(), libMesh::DenseMatrix< T >::l1_norm(), 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::variable_group(), libMesh::FEMSystem::verify_analytic_jacobians, libMesh::DenseMatrix< T >::zero(), libMesh::SparseMatrix< T >::zero(), and libMesh::NumericVector< T >::zero().

Referenced by continuation_solve(), and solve_tangent().

857 {
858  libmesh_assert(get_residual || get_jacobian);
859 
860  // Log residual and jacobian and combined performance separately
861 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
862  const char * log_name;
863  if (get_residual && get_jacobian)
864  log_name = "assembly()";
865  else if (get_residual)
866  log_name = "assembly(get_residual)";
867  else
868  log_name = "assembly(get_jacobian)";
869 
870  LOG_SCOPE(log_name, "FEMSystem");
871 #endif
872 
873  const MeshBase & mesh = this->get_mesh();
874 
876  {
877  this->solution->close();
878 
879  std::streamsize old_precision = libMesh::out.precision();
881  libMesh::out << "|U| = "
882  << this->solution->l1_norm()
883  << std::endl;
884  libMesh::out.precision(old_precision);
885  }
886  if (print_solutions)
887  {
888  std::streamsize old_precision = libMesh::out.precision();
890  libMesh::out << "U = [" << *(this->solution)
891  << "];" << std::endl;
892  libMesh::out.precision(old_precision);
893  }
894 
895  // Is this definitely necessary? [RHS]
896  // Yes. [RHS 2012]
897  if (get_jacobian)
898  matrix->zero();
899  if (get_residual)
900  rhs->zero();
901 
902  // Stupid C++ lets you set *Real* verify_analytic_jacobians = true!
903  if (verify_analytic_jacobians > 0.5)
904  {
905  libMesh::err << "WARNING! verify_analytic_jacobians was set "
906  << "to absurdly large value of "
907  << verify_analytic_jacobians << std::endl;
908  libMesh::err << "Resetting to 1e-6!" << std::endl;
910  }
911 
912  // In time-dependent problems, the nonlinear function we're trying
913  // to solve at each timestep may depend on the particular solver
914  // we're using
915  libmesh_assert(time_solver.get());
916 
917  // Build the residual and jacobian contributions on every active
918  // mesh element on this processor
920  (elem_range.reset(mesh.active_local_elements_begin(),
922  AssemblyContributions(*this, get_residual, get_jacobian,
923  apply_heterogeneous_constraints,
924  apply_no_constraints));
925 
926  // Check and see if we have SCALAR variables
927  bool have_scalar = false;
928  for (unsigned int i=0; i != this->n_variable_groups(); ++i)
929  {
930  if (this->variable_group(i).type().family == SCALAR)
931  {
932  have_scalar = true;
933  break;
934  }
935  }
936 
937  // SCALAR dofs are stored on the last processor, so we'll evaluate
938  // their equation terms there and only if we have a SCALAR variable
939  if (this->processor_id() == (this->n_processors()-1) && have_scalar)
940  {
941  std::unique_ptr<DiffContext> con = this->build_context();
942  FEMContext & _femcontext = cast_ref<FEMContext &>(*con);
943  this->init_context(_femcontext);
944  _femcontext.pre_fe_reinit(*this, nullptr);
945 
946  bool jacobian_computed =
947  this->time_solver->nonlocal_residual(get_jacobian, _femcontext);
948 
949  // Nonlocal residuals are likely to be length 0, in which case we
950  // don't need to do any more. And we shouldn't try to do any
951  // more; lots of DenseVector/DenseMatrix code assumes rank>0.
952  if (_femcontext.get_elem_residual().size())
953  {
954  // Compute a numeric jacobian if we have to
955  if (get_jacobian && !jacobian_computed)
956  {
957  // Make sure we didn't compute a jacobian and lie about it
958  libmesh_assert_equal_to (_femcontext.get_elem_jacobian().l1_norm(), 0.0);
959  // Logging of numerical jacobians is done separately
960  this->numerical_nonlocal_jacobian(_femcontext);
961  }
962 
963  // Compute a numeric jacobian if we're asked to verify the
964  // analytic jacobian we got
965  if (get_jacobian && jacobian_computed &&
966  this->verify_analytic_jacobians != 0.0)
967  {
968  DenseMatrix<Number> analytic_jacobian(_femcontext.get_elem_jacobian());
969 
970  _femcontext.get_elem_jacobian().zero();
971  // Logging of numerical jacobians is done separately
972  this->numerical_nonlocal_jacobian(_femcontext);
973 
974  Real analytic_norm = analytic_jacobian.l1_norm();
975  Real numerical_norm = _femcontext.get_elem_jacobian().l1_norm();
976 
977  // If we can continue, we'll probably prefer the analytic jacobian
978  analytic_jacobian.swap(_femcontext.get_elem_jacobian());
979 
980  // The matrix "analytic_jacobian" will now hold the error matrix
981  analytic_jacobian.add(-1.0, _femcontext.get_elem_jacobian());
982  Real error_norm = analytic_jacobian.l1_norm();
983 
984  Real relative_error = error_norm /
985  std::max(analytic_norm, numerical_norm);
986 
987  if (relative_error > this->verify_analytic_jacobians)
988  {
989  libMesh::err << "Relative error " << relative_error
990  << " detected in analytic jacobian on nonlocal dofs!"
991  << std::endl;
992 
993  std::streamsize old_precision = libMesh::out.precision();
995  libMesh::out << "J_analytic nonlocal = "
996  << _femcontext.get_elem_jacobian() << std::endl;
997  analytic_jacobian.add(1.0, _femcontext.get_elem_jacobian());
998  libMesh::out << "J_numeric nonlocal = "
999  << analytic_jacobian << std::endl;
1000 
1001  libMesh::out.precision(old_precision);
1002 
1003  libmesh_error_msg("Relative error too large, exiting!");
1004  }
1005  }
1006 
1007  add_element_system
1008  (*this, get_residual, get_jacobian,
1009  apply_heterogeneous_constraints, apply_no_constraints, _femcontext);
1010  }
1011  }
1012 
1013  if (get_residual && (print_residual_norms || print_residuals))
1014  this->rhs->close();
1015  if (get_residual && print_residual_norms)
1016  {
1017  std::streamsize old_precision = libMesh::out.precision();
1018  libMesh::out.precision(16);
1019  libMesh::out << "|F| = " << this->rhs->l1_norm() << std::endl;
1020  libMesh::out.precision(old_precision);
1021  }
1022  if (get_residual && print_residuals)
1023  {
1024  std::streamsize old_precision = libMesh::out.precision();
1025  libMesh::out.precision(16);
1026  libMesh::out << "F = [" << *(this->rhs) << "];" << std::endl;
1027  libMesh::out.precision(old_precision);
1028  }
1029 
1030  if (get_jacobian && (print_jacobian_norms || print_jacobians))
1031  this->matrix->close();
1032  if (get_jacobian && print_jacobian_norms)
1033  {
1034  std::streamsize old_precision = libMesh::out.precision();
1035  libMesh::out.precision(16);
1036  libMesh::out << "|J| = " << this->matrix->l1_norm() << std::endl;
1037  libMesh::out.precision(old_precision);
1038  }
1039  if (get_jacobian && print_jacobians)
1040  {
1041  std::streamsize old_precision = libMesh::out.precision();
1042  libMesh::out.precision(16);
1043  libMesh::out << "J = [" << *(this->matrix) << "];" << std::endl;
1044  libMesh::out.precision(old_precision);
1045  }
1046 }
virtual unsigned int size() const override
Definition: dense_vector.h:92
FEFamily family
Definition: fe_type.h:204
const DenseMatrix< Number > & get_elem_jacobian() const
Definition: diff_context.h:283
Real verify_analytic_jacobians
Definition: fem_system.h:209
virtual void pre_fe_reinit(const System &, const Elem *e)
Definition: fem_context.C:1552
std::streamsize precision() const
void parallel_for(const Range &range, const Body &body)
Definition: threads_none.h:73
unsigned int n_variable_groups() const
Definition: system.h:2113
std::unique_ptr< TimeSolver > time_solver
Definition: diff_system.h:234
MeshBase & mesh
NumericVector< Number > * rhs
long double max(long double a, double b)
const MeshBase & get_mesh() const
Definition: system.h:2033
Base class for Mesh.
Definition: mesh_base.h:77
virtual void zero()=0
Real l1_norm() const
Definition: dense_matrix.h:991
processor_id_type n_processors() const
virtual void zero()=0
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)
Definition: dense_matrix.h:884
std::unique_ptr< NumericVector< Number > > solution
Definition: system.h:1523
void numerical_nonlocal_jacobian(FEMContext &context) const
Definition: fem_system.C:1310
OStreamProxy err(std::cerr)
virtual Real l1_norm() const =0
virtual void close()=0
const DenseVector< Number > & get_elem_residual() const
Definition: diff_context.h:249
virtual void close()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void zero() override
Definition: dense_matrix.h:808
SparseMatrix< Number > * matrix
virtual void init_context(DiffContext &) override
Definition: fem_system.C:1342
virtual std::unique_ptr< DiffContext > build_context() override
Definition: fem_system.C:1318
virtual Real l1_norm() const =0
processor_id_type processor_id() const
OStreamProxy out(std::cout)
virtual element_iterator active_local_elements_end()=0
const VariableGroup & variable_group(unsigned int vg) const
Definition: system.h:2143
const FEType & type() const
Definition: variable.h:119

◆ attach_assemble_function()

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 1777 of file system.C.

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

1779 {
1780  libmesh_assert(fptr);
1781 
1782  if (_assemble_system_object != nullptr)
1783  {
1784  libmesh_here();
1785  libMesh::out << "WARNING: Cannot specify both assembly function and object!"
1786  << std::endl;
1787 
1788  _assemble_system_object = nullptr;
1789  }
1790 
1792 }
Assembly * _assemble_system_object
Definition: system.h:1841
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1835
OStreamProxy out(std::cout)

◆ attach_assemble_object()

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 1796 of file system.C.

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

1797 {
1798  if (_assemble_system_function != nullptr)
1799  {
1800  libmesh_here();
1801  libMesh::out << "WARNING: Cannot specify both assembly object and function!"
1802  << std::endl;
1803 
1804  _assemble_system_function = nullptr;
1805  }
1806 
1807  _assemble_system_object = &assemble_in;
1808 }
Assembly * _assemble_system_object
Definition: system.h:1841
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1835
OStreamProxy out(std::cout)

◆ attach_constraint_function()

void libMesh::System::attach_constraint_function ( void   fptrEquationSystems &es, const std::string &name)
inherited

Register a user function for imposing constraints.

Definition at line 1812 of file system.C.

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

1814 {
1815  libmesh_assert(fptr);
1816 
1817  if (_constrain_system_object != nullptr)
1818  {
1819  libmesh_here();
1820  libMesh::out << "WARNING: Cannot specify both constraint function and object!"
1821  << std::endl;
1822 
1823  _constrain_system_object = nullptr;
1824  }
1825 
1827 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1846
Constraint * _constrain_system_object
Definition: system.h:1852
OStreamProxy out(std::cout)

◆ attach_constraint_object()

void libMesh::System::attach_constraint_object ( System::Constraint constrain)
inherited

Register a user object for imposing constraints.

Definition at line 1831 of file system.C.

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

1832 {
1833  if (_constrain_system_function != nullptr)
1834  {
1835  libmesh_here();
1836  libMesh::out << "WARNING: Cannot specify both constraint object and function!"
1837  << std::endl;
1838 
1839  _constrain_system_function = nullptr;
1840  }
1841 
1842  _constrain_system_object = &constrain;
1843 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1846
Constraint * _constrain_system_object
Definition: system.h:1852
OStreamProxy out(std::cout)

◆ attach_init_function()

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 1742 of file system.C.

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

1744 {
1745  libmesh_assert(fptr);
1746 
1747  if (_init_system_object != nullptr)
1748  {
1749  libmesh_here();
1750  libMesh::out << "WARNING: Cannot specify both initialization function and object!"
1751  << std::endl;
1752 
1753  _init_system_object = nullptr;
1754  }
1755 
1756  _init_system_function = fptr;
1757 }
Initialization * _init_system_object
Definition: system.h:1830
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1824
OStreamProxy out(std::cout)

◆ attach_init_object()

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 1761 of file system.C.

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

1762 {
1763  if (_init_system_function != nullptr)
1764  {
1765  libmesh_here();
1766  libMesh::out << "WARNING: Cannot specify both initialization object and function!"
1767  << std::endl;
1768 
1769  _init_system_function = nullptr;
1770  }
1771 
1772  _init_system_object = &init_in;
1773 }
Initialization * _init_system_object
Definition: system.h:1830
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1824
OStreamProxy out(std::cout)

◆ attach_physics()

void libMesh::DifferentiableSystem::attach_physics ( DifferentiablePhysics physics_in)
inlineinherited

Attach external Physics object.

Definition at line 197 of file diff_system.h.

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

198  { this->_diff_physics = (physics_in->clone_physics()).release();
199  this->_diff_physics->init_physics(*this);}
DifferentiablePhysics * _diff_physics
Definition: diff_system.h:371
virtual void init_physics(const System &sys)

◆ attach_qoi()

void libMesh::DifferentiableSystem::attach_qoi ( DifferentiableQoI qoi_in)
inlineinherited

Attach external QoI object.

Definition at line 225 of file diff_system.h.

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

226  { this->diff_qoi = (qoi_in->clone()).release();
227  // User needs to resize qoi system qoi accordingly
228  this->diff_qoi->init_qoi( this->qoi );}
DifferentiableQoI * diff_qoi
Definition: diff_system.h:378
std::vector< Number > qoi
Definition: system.h:1558
virtual void init_qoi(std::vector< Number > &)
Definition: diff_qoi.h:69

◆ attach_QOI_derivative()

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 1883 of file system.C.

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

1885 {
1886  libmesh_assert(fptr);
1887 
1888  if (_qoi_evaluate_derivative_object != nullptr)
1889  {
1890  libmesh_here();
1891  libMesh::out << "WARNING: Cannot specify both QOI derivative function and object!"
1892  << std::endl;
1893 
1895  }
1896 
1898 }
QOIDerivative * _qoi_evaluate_derivative_object
Definition: system.h:1878
OStreamProxy out(std::cout)
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Definition: system.h:1869

◆ attach_QOI_derivative_object()

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 1902 of file system.C.

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

1903 {
1904  if (_qoi_evaluate_derivative_function != nullptr)
1905  {
1906  libmesh_here();
1907  libMesh::out << "WARNING: Cannot specify both QOI derivative object and function!"
1908  << std::endl;
1909 
1911  }
1912 
1913  _qoi_evaluate_derivative_object = &qoi_derivative;
1914 }
QOIDerivative * _qoi_evaluate_derivative_object
Definition: system.h:1878
OStreamProxy out(std::cout)
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Definition: system.h:1869

◆ attach_QOI_function()

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 1847 of file system.C.

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

1850 {
1851  libmesh_assert(fptr);
1852 
1853  if (_qoi_evaluate_object != nullptr)
1854  {
1855  libmesh_here();
1856  libMesh::out << "WARNING: Cannot specify both QOI function and object!"
1857  << std::endl;
1858 
1859  _qoi_evaluate_object = nullptr;
1860  }
1861 
1862  _qoi_evaluate_function = fptr;
1863 }
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Definition: system.h:1857
QOI * _qoi_evaluate_object
Definition: system.h:1864
OStreamProxy out(std::cout)

◆ attach_QOI_object()

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 1867 of file system.C.

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

1868 {
1869  if (_qoi_evaluate_function != nullptr)
1870  {
1871  libmesh_here();
1872  libMesh::out << "WARNING: Cannot specify both QOI object and function!"
1873  << std::endl;
1874 
1875  _qoi_evaluate_function = nullptr;
1876  }
1877 
1878  _qoi_evaluate_object = &qoi_in;
1879 }
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Definition: system.h:1857
QOI * _qoi_evaluate_object
Definition: system.h:1864
OStreamProxy out(std::cout)

◆ boundary_project_solution() [1/2]

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 = nullptr 
)
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 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.

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

Definition at line 985 of file system_projection.C.

989 {
990  this->boundary_project_vector(b, variables, *solution, f, g);
991 
992  solution->localize(*current_local_solution);
993 }
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=nullptr, int is_adjoint=-1) const
std::unique_ptr< NumericVector< Number > > solution
Definition: system.h:1523
std::unique_ptr< NumericVector< Number > > current_local_solution
Definition: system.h:1535

◆ boundary_project_solution() [2/2]

void libMesh::System::boundary_project_solution ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
ValueFunctionPointer  fptr,
GradientFunctionPointer  gptr,
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.

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

Definition at line 968 of file system_projection.C.

973 {
974  WrappedFunction<Number> f(*this, fptr, &parameters);
975  WrappedFunction<Gradient> g(*this, gptr, &parameters);
976  this->boundary_project_solution(b, variables, &f, &g);
977 }
void boundary_project_solution(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr)

◆ boundary_project_vector() [1/2]

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 = nullptr,
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 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.

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

Definition at line 1021 of file system_projection.C.

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

1027 {
1028  LOG_SCOPE ("boundary_project_vector()", "System");
1029 
1031  (ConstElemRange (this->get_mesh().active_local_elements_begin(),
1032  this->get_mesh().active_local_elements_end() ),
1033  BoundaryProjectSolution(b, variables, *this, f, g,
1034  this->get_equation_systems().parameters,
1035  new_vector)
1036  );
1037 
1038  // We don't do SCALAR dofs when just projecting the boundary, so
1039  // we're done here.
1040 
1041  new_vector.close();
1042 
1043 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1044  if (is_adjoint == -1)
1045  this->get_dof_map().enforce_constraints_exactly(*this, &new_vector);
1046  else if (is_adjoint >= 0)
1048  is_adjoint);
1049 #endif
1050 }
void parallel_for(const Range &range, const Body &body)
Definition: threads_none.h:73
const EquationSystems & get_equation_systems() const
Definition: system.h:712
const MeshBase & get_mesh() const
Definition: system.h:2033
StoredRange< MeshBase::const_element_iterator, const Elem * > ConstElemRange
Definition: elem_range.h:34
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
virtual void close()=0
const DofMap & get_dof_map() const
Definition: system.h:2049
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const

◆ boundary_project_vector() [2/2]

void libMesh::System::boundary_project_vector ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
ValueFunctionPointer  fptr,
GradientFunctionPointer  gptr,
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.

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

Definition at line 1003 of file system_projection.C.

1010 {
1011  WrappedFunction<Number> f(*this, fptr, &parameters);
1012  WrappedFunction<Gradient> g(*this, gptr, &parameters);
1013  this->boundary_project_vector(b, variables, new_vector, &f, &g,
1014  is_adjoint);
1015 }
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=nullptr, int is_adjoint=-1) const

◆ build_context()

std::unique_ptr< DiffContext > libMesh::FEMSystem::build_context ( )
overridevirtualinherited

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 1318 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::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().

1319 {
1320  FEMContext * fc = new FEMContext(*this);
1321 
1322  DifferentiablePhysics * phys = this->get_physics();
1323 
1324  libmesh_assert (phys);
1325 
1326  // If we are solving a moving mesh problem, tell that to the Context
1327  fc->set_mesh_system(phys->get_mesh_system());
1328  fc->set_mesh_x_var(phys->get_mesh_x_var());
1329  fc->set_mesh_y_var(phys->get_mesh_y_var());
1330  fc->set_mesh_z_var(phys->get_mesh_z_var());
1331 
1332  fc->set_deltat_pointer( &deltat );
1333 
1334  // If we are solving the adjoint problem, tell that to the Context
1335  fc->is_adjoint() = this->get_time_solver().is_adjoint();
1336 
1337  return std::unique_ptr<DiffContext>(fc);
1338 }
unsigned int get_mesh_x_var() const
Definition: diff_physics.h:636
void set_mesh_z_var(unsigned int z_var)
Definition: fem_context.h:859
void set_mesh_x_var(unsigned int x_var)
Definition: fem_context.h:831
const System * get_mesh_system() const
Definition: diff_physics.h:624
bool is_adjoint() const
Definition: diff_context.h:470
virtual void set_mesh_system(System *sys)
Definition: fem_context.h:805
unsigned int get_mesh_y_var() const
Definition: diff_physics.h:642
bool is_adjoint() const
Definition: time_solver.h:233
const DifferentiablePhysics * get_physics() const
Definition: diff_system.h:182
void set_mesh_y_var(unsigned int y_var)
Definition: fem_context.h:845
unsigned int get_mesh_z_var() const
Definition: diff_physics.h:648
void set_deltat_pointer(Real *dt)
Definition: diff_context.C:103
TimeSolver & get_time_solver()
Definition: diff_system.h:415

◆ calculate_norm() [1/2]

Real libMesh::System::calculate_norm ( const NumericVector< Number > &  v,
unsigned int  var,
FEMNormType  norm_type,
std::set< unsigned int > *  skip_dimensions = 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 1378 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(), and libMesh::UnsteadySolver::du().

1382 {
1383  //short circuit to save time
1384  if (norm_type == DISCRETE_L1 ||
1385  norm_type == DISCRETE_L2 ||
1386  norm_type == DISCRETE_L_INF)
1387  return discrete_var_norm(v,var,norm_type);
1388 
1389  // Not a discrete norm
1390  std::vector<FEMNormType> norms(this->n_vars(), L2);
1391  std::vector<Real> weights(this->n_vars(), 0.0);
1392  norms[var] = norm_type;
1393  weights[var] = 1.0;
1394  Real val = this->calculate_norm(v, SystemNorm(norms, weights), skip_dimensions);
1395  return val;
1396 }
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
Definition: system.C:1378
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real discrete_var_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type) const
Definition: system.C:1359
unsigned int n_vars() const
Definition: system.h:2105

◆ calculate_norm() [2/2]

Real libMesh::System::calculate_norm ( const NumericVector< Number > &  v,
const SystemNorm norm,
std::set< unsigned int > *  skip_dimensions = 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 1400 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(), 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::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().

1403 {
1404  // This function must be run on all processors at once
1405  parallel_object_only();
1406 
1407  LOG_SCOPE ("calculate_norm()", "System");
1408 
1409  // Zero the norm before summation
1410  Real v_norm = 0.;
1411 
1412  if (norm.is_discrete())
1413  {
1414  //Check to see if all weights are 1.0 and all types are equal
1415  FEMNormType norm_type0 = norm.type(0);
1416  unsigned int check_var = 0;
1417  for (; check_var != this->n_vars(); ++check_var)
1418  if ((norm.weight(check_var) != 1.0) || (norm.type(check_var) != norm_type0))
1419  break;
1420 
1421  //All weights were 1.0 so just do the full vector discrete norm
1422  if (check_var == this->n_vars())
1423  {
1424  if (norm_type0 == DISCRETE_L1)
1425  return v.l1_norm();
1426  if (norm_type0 == DISCRETE_L2)
1427  return v.l2_norm();
1428  if (norm_type0 == DISCRETE_L_INF)
1429  return v.linfty_norm();
1430  else
1431  libmesh_error_msg("Invalid norm_type0 = " << norm_type0);
1432  }
1433 
1434  for (unsigned int var=0; var != this->n_vars(); ++var)
1435  {
1436  // Skip any variables we don't need to integrate
1437  if (norm.weight(var) == 0.0)
1438  continue;
1439 
1440  v_norm += norm.weight(var) * discrete_var_norm(v, var, norm.type(var));
1441  }
1442 
1443  return v_norm;
1444  }
1445 
1446  // Localize the potentially parallel vector
1447  std::unique_ptr<NumericVector<Number>> local_v = NumericVector<Number>::build(this->comm());
1448  local_v->init(v.size(), true, SERIAL);
1449  v.localize (*local_v, _dof_map->get_send_list());
1450 
1451  // I'm not sure how best to mix Hilbert norms on some variables (for
1452  // which we'll want to square then sum then square root) with norms
1453  // like L_inf (for which we'll just want to take an absolute value
1454  // and then sum).
1455  bool using_hilbert_norm = true,
1456  using_nonhilbert_norm = true;
1457 
1458  // Loop over all variables
1459  for (unsigned int var=0; var != this->n_vars(); ++var)
1460  {
1461  // Skip any variables we don't need to integrate
1462  Real norm_weight_sq = norm.weight_sq(var);
1463  if (norm_weight_sq == 0.0)
1464  continue;
1465  Real norm_weight = norm.weight(var);
1466 
1467  // Check for unimplemented norms (rather than just returning 0).
1468  FEMNormType norm_type = norm.type(var);
1469  if ((norm_type==H1) ||
1470  (norm_type==H2) ||
1471  (norm_type==L2) ||
1472  (norm_type==H1_SEMINORM) ||
1473  (norm_type==H2_SEMINORM))
1474  {
1475  if (!using_hilbert_norm)
1476  libmesh_not_implemented();
1477  using_nonhilbert_norm = false;
1478  }
1479  else if ((norm_type==L1) ||
1480  (norm_type==L_INF) ||
1481  (norm_type==W1_INF_SEMINORM) ||
1482  (norm_type==W2_INF_SEMINORM))
1483  {
1484  if (!using_nonhilbert_norm)
1485  libmesh_not_implemented();
1486  using_hilbert_norm = false;
1487  }
1488  else
1489  libmesh_not_implemented();
1490 
1491  const FEType & fe_type = this->get_dof_map().variable_type(var);
1492 
1493  // Allow space for dims 0-3, even if we don't use them all
1494  std::vector<std::unique_ptr<FEBase>> fe_ptrs(4);
1495  std::vector<std::unique_ptr<QBase>> q_rules(4);
1496 
1497  const std::set<unsigned char> & elem_dims = _mesh.elem_dimensions();
1498 
1499  // Prepare finite elements for each dimension present in the mesh
1500  for (const auto & dim : elem_dims)
1501  {
1502  if (skip_dimensions && skip_dimensions->find(dim) != skip_dimensions->end())
1503  continue;
1504 
1505  // Construct quadrature and finite element objects
1506  q_rules[dim] = fe_type.default_quadrature_rule (dim);
1507  fe_ptrs[dim] = FEBase::build(dim, fe_type);
1508 
1509  // Attach quadrature rule to FE object
1510  fe_ptrs[dim]->attach_quadrature_rule (q_rules[dim].get());
1511  }
1512 
1513  std::vector<dof_id_type> dof_indices;
1514 
1515  // Begin the loop over the elements
1516  for (const auto & elem : this->get_mesh().active_local_element_ptr_range())
1517  {
1518  const unsigned int dim = elem->dim();
1519 
1520 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1521 
1522  // One way for implementing this would be to exchange the fe with the FEInterface- class.
1523  // However, it needs to be discussed whether integral-norms make sense for infinite elements.
1524  // or in which sense they could make sense.
1525  if (elem->infinite() )
1526  libmesh_not_implemented();
1527 
1528 #endif
1529 
1530  if (skip_dimensions && skip_dimensions->find(dim) != skip_dimensions->end())
1531  continue;
1532 
1533  FEBase * fe = fe_ptrs[dim].get();
1534  QBase * qrule = q_rules[dim].get();
1535  libmesh_assert(fe);
1536  libmesh_assert(qrule);
1537 
1538  const std::vector<Real> & JxW = fe->get_JxW();
1539  const std::vector<std::vector<Real>> * phi = nullptr;
1540  if (norm_type == H1 ||
1541  norm_type == H2 ||
1542  norm_type == L2 ||
1543  norm_type == L1 ||
1544  norm_type == L_INF)
1545  phi = &(fe->get_phi());
1546 
1547  const std::vector<std::vector<RealGradient>> * dphi = nullptr;
1548  if (norm_type == H1 ||
1549  norm_type == H2 ||
1550  norm_type == H1_SEMINORM ||
1551  norm_type == W1_INF_SEMINORM)
1552  dphi = &(fe->get_dphi());
1553 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
1554  const std::vector<std::vector<RealTensor>> * d2phi = nullptr;
1555  if (norm_type == H2 ||
1556  norm_type == H2_SEMINORM ||
1557  norm_type == W2_INF_SEMINORM)
1558  d2phi = &(fe->get_d2phi());
1559 #endif
1560 
1561  fe->reinit (elem);
1562 
1563  this->get_dof_map().dof_indices (elem, dof_indices, var);
1564 
1565  const unsigned int n_qp = qrule->n_points();
1566 
1567  const unsigned int n_sf = cast_int<unsigned int>
1568  (dof_indices.size());
1569 
1570  // Begin the loop over the Quadrature points.
1571  for (unsigned int qp=0; qp<n_qp; qp++)
1572  {
1573  if (norm_type == L1)
1574  {
1575  Number u_h = 0.;
1576  for (unsigned int i=0; i != n_sf; ++i)
1577  u_h += (*phi)[i][qp] * (*local_v)(dof_indices[i]);
1578  v_norm += norm_weight *
1579  JxW[qp] * std::abs(u_h);
1580  }
1581 
1582  if (norm_type == L_INF)
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 = std::max(v_norm, norm_weight * std::abs(u_h));
1588  }
1589 
1590  if (norm_type == H1 ||
1591  norm_type == H2 ||
1592  norm_type == L2)
1593  {
1594  Number u_h = 0.;
1595  for (unsigned int i=0; i != n_sf; ++i)
1596  u_h += (*phi)[i][qp] * (*local_v)(dof_indices[i]);
1597  v_norm += norm_weight_sq *
1598  JxW[qp] * TensorTools::norm_sq(u_h);
1599  }
1600 
1601  if (norm_type == H1 ||
1602  norm_type == H2 ||
1603  norm_type == H1_SEMINORM)
1604  {
1605  Gradient grad_u_h;
1606  for (unsigned int i=0; i != n_sf; ++i)
1607  grad_u_h.add_scaled((*dphi)[i][qp], (*local_v)(dof_indices[i]));
1608  v_norm += norm_weight_sq *
1609  JxW[qp] * grad_u_h.norm_sq();
1610  }
1611 
1612  if (norm_type == W1_INF_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 = std::max(v_norm, norm_weight * grad_u_h.norm());
1618  }
1619 
1620 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
1621  if (norm_type == H2 ||
1622  norm_type == H2_SEMINORM)
1623  {
1624  Tensor hess_u_h;
1625  for (unsigned int i=0; i != n_sf; ++i)
1626  hess_u_h.add_scaled((*d2phi)[i][qp], (*local_v)(dof_indices[i]));
1627  v_norm += norm_weight_sq *
1628  JxW[qp] * hess_u_h.norm_sq();
1629  }
1630 
1631  if (norm_type == W2_INF_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 = std::max(v_norm, norm_weight * hess_u_h.norm());
1637  }
1638 #endif
1639  }
1640  }
1641  }
1642 
1643  if (using_hilbert_norm)
1644  {
1645  this->comm().sum(v_norm);
1646  v_norm = std::sqrt(v_norm);
1647  }
1648  else
1649  {
1650  this->comm().max(v_norm);
1651  }
1652 
1653  return v_norm;
1654 }
double abs(double a)
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition: dof_map.C:1930
void add_scaled(const TypeTensor< T2 > &, const T)
Definition: type_tensor.h:808
void add_scaled(const TypeVector< T2 > &, const T)
Definition: type_vector.h:627
virtual numeric_index_type size() const =0
const FEType & variable_type(const unsigned int c) const
Definition: dof_map.h:1792
std::unique_ptr< DofMap > _dof_map
Definition: system.h:1884
const Parallel::Communicator & comm() const
long double max(long double a, double b)
const MeshBase & get_mesh() const
Definition: system.h:2033
virtual Real l2_norm() const =0
NumberVectorValue Gradient
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
const std::set< unsigned char > & elem_dimensions() const
Definition: mesh_base.h:220
FEGenericBase< Real > FEBase
virtual Real l1_norm() const =0
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
NumberTensorValue Tensor
Real discrete_var_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type) const
Definition: system.C:1359
unsigned int n_vars() const
Definition: system.h:2105
const DofMap & get_dof_map() const
Definition: system.h:2049
MeshBase & _mesh
Definition: system.h:1896
virtual Real linfty_norm() const =0
virtual void localize(std::vector< T > &v_local) const =0

◆ clear()

void libMesh::ContinuationSystem::clear ( )
overridevirtual

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() override
Definition: diff_system.C:69

◆ clear_physics()

virtual void libMesh::DifferentiablePhysics::clear_physics ( )
virtualinherited

Clear any data structures associated with the physics.

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

◆ clear_qoi()

virtual void libMesh::DifferentiableQoI::clear_qoi ( )
inlinevirtualinherited

Clear all the data structures associated with the QoI.

Definition at line 75 of file diff_qoi.h.

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

75 {}

◆ clone()

virtual std::unique_ptr<DifferentiableQoI> libMesh::DifferentiableSystem::clone ( )
inlineoverridevirtualinherited

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

Implements libMesh::DifferentiableQoI.

Definition at line 169 of file diff_system.h.

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

170  {
171  libmesh_not_implemented();
172  // dummy
173  return std::unique_ptr<DifferentiableQoI>(this);
174  }

◆ clone_physics()

virtual std::unique_ptr<DifferentiablePhysics> libMesh::DifferentiableSystem::clone_physics ( )
inlineoverridevirtualinherited

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

Implements libMesh::DifferentiablePhysics.

Definition at line 159 of file diff_system.h.

160  {
161  libmesh_not_implemented();
162  // dummy
163  return std::unique_ptr<DifferentiablePhysics>(this);
164  }

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 89 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_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::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< 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(), libMesh::PetscDMWrapper::add_dofs_helper(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::DofMap::attach_matrix(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::PetscDMWrapper::build_section(), libMesh::PetscDMWrapper::build_sf(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::PetscDMWrapper::check_section_n_dofs(), 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::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::EpetraVector< T >::EpetraVector(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::LocationMap< T >::init(), libMesh::TimeSolver::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::MeshTools::libmesh_assert_consistent_distributed(), libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids(), 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::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_postcheck(), libMesh::libmesh_petsc_snes_residual(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), 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::FEMSystem::mesh_position_set(), 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(), 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::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::CheckpointIO::select_split_config(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::PetscDiffSolver::setup_petsc_data(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::split_mesh(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

90  { return _communicator; }
const Parallel::Communicator & _communicator

◆ compare()

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 514 of file system.C.

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

Referenced by libMesh::EquationSystems::compare().

517 {
518  // we do not care for matrices, but for vectors
519  libmesh_assert (_is_initialized);
520  libmesh_assert (other_system._is_initialized);
521 
522  if (verbose)
523  {
524  libMesh::out << " Systems \"" << _sys_name << "\"" << std::endl;
525  libMesh::out << " comparing matrices not supported." << std::endl;
526  libMesh::out << " comparing names...";
527  }
528 
529  // compare the name: 0 means identical
530  const int name_result = _sys_name.compare(other_system.name());
531  if (verbose)
532  {
533  if (name_result == 0)
534  libMesh::out << " identical." << std::endl;
535  else
536  libMesh::out << " names not identical." << std::endl;
537  libMesh::out << " comparing solution vector...";
538  }
539 
540 
541  // compare the solution: -1 means identical
542  const int solu_result = solution->compare (*other_system.solution.get(),
543  threshold);
544 
545  if (verbose)
546  {
547  if (solu_result == -1)
548  libMesh::out << " identical up to threshold." << std::endl;
549  else
550  libMesh::out << " first difference occurred at index = "
551  << solu_result << "." << std::endl;
552  }
553 
554 
555  // safety check, whether we handle at least the same number
556  // of vectors
557  std::vector<int> ov_result;
558 
559  if (this->n_vectors() != other_system.n_vectors())
560  {
561  if (verbose)
562  {
563  libMesh::out << " Fatal difference. This system handles "
564  << this->n_vectors() << " add'l vectors," << std::endl
565  << " while the other system handles "
566  << other_system.n_vectors()
567  << " add'l vectors." << std::endl
568  << " Aborting comparison." << std::endl;
569  }
570  return false;
571  }
572  else if (this->n_vectors() == 0)
573  {
574  // there are no additional vectors...
575  ov_result.clear ();
576  }
577  else
578  {
579  // compare other vectors
580  for (auto & pr : _vectors)
581  {
582  if (verbose)
583  libMesh::out << " comparing vector \""
584  << pr.first << "\" ...";
585 
586  // assume they have the same name
587  const NumericVector<Number> & other_system_vector =
588  other_system.get_vector(pr.first);
589 
590  ov_result.push_back(pr.second->compare (other_system_vector,
591  threshold));
592 
593  if (verbose)
594  {
595  if (ov_result[ov_result.size()-1] == -1)
596  libMesh::out << " identical up to threshold." << std::endl;
597  else
598  libMesh::out << " first difference occurred at" << std::endl
599  << " index = " << ov_result[ov_result.size()-1] << "." << std::endl;
600  }
601  }
602  } // finished comparing additional vectors
603 
604 
605  bool overall_result;
606 
607  // sum up the results
608  if ((name_result==0) && (solu_result==-1))
609  {
610  if (ov_result.size()==0)
611  overall_result = true;
612  else
613  {
614  bool ov_identical;
615  unsigned int n = 0;
616  do
617  {
618  ov_identical = (ov_result[n]==-1);
619  n++;
620  }
621  while (ov_identical && n<ov_result.size());
622  overall_result = ov_identical;
623  }
624  }
625  else
626  overall_result = false;
627 
628  if (verbose)
629  {
630  libMesh::out << " finished comparisons, ";
631  if (overall_result)
632  libMesh::out << "found no differences." << std::endl << std::endl;
633  else
634  libMesh::out << "found differences." << std::endl << std::endl;
635  }
636 
637  return overall_result;
638 }
bool _is_initialized
Definition: system.h:1971
unsigned int n_vectors() const
Definition: system.h:2233
std::unique_ptr< NumericVector< Number > > solution
Definition: system.h:1523
std::map< std::string, NumericVector< Number > *> _vectors
Definition: system.h:1935
const std::string _sys_name
Definition: system.h:1901
OStreamProxy out(std::cout)

◆ continuation_solve()

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  //std::unique_ptr<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)
NumericVector< Number > * previous_u
std::streamsize precision() const
std::unique_ptr< LinearSolver< Number > > linear_solver
unsigned int max_nonlinear_iterations
Definition: diff_solver.h:157
std::unique_ptr< TimeSolver > time_solver
Definition: diff_system.h:234
NumericVector< Number > * delta_u
NumericVector< Number > * rhs
virtual T dot(const NumericVector< T > &v) const =0
virtual void zero()=0
virtual void scale(const T factor)=0
NumericVector< Number > * du_ds
virtual Real l2_norm() const =0
NumericVector< Number > * z
unsigned int max_linear_iterations
Definition: diff_solver.h:149
NumericVector< Number > * y_old
NumericVector< Number > * y
std::unique_ptr< NumericVector< Number > > solution
Definition: system.h:1523
void unsetf(std::ios_base::fmtflags mask)
double pow(double a, int b)
virtual void close()=0
virtual void close()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::ios_base::fmtflags setf(std::ios_base::fmtflags fmtfl)
SparseMatrix< Number > * matrix
virtual void add(const numeric_index_type i, const T value)=0
OStreamProxy out(std::cout)
long double min(long double a, double b)
virtual void assembly(bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) override
Definition: fem_system.C:854

◆ current_solution()

Number libMesh::System::current_solution ( const dof_id_type  global_dof_number) const
inherited

◆ damping_residual()

virtual bool libMesh::DifferentiablePhysics::damping_residual ( bool  request_jacobian,
DiffContext  
)
inlinevirtualinherited

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.

Definition at line 374 of file diff_physics.h.

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

375  {
376  return request_jacobian;
377  }

◆ deactivate()

void libMesh::System::deactivate ( )
inlineinherited

Deactivates the system. Only active systems are solved.

Definition at line 2081 of file system.h.

References libMesh::System::_active.

2082 {
2083  _active = false;
2084 }

◆ disable_cache()

void libMesh::ImplicitSystem::disable_cache ( )
overridevirtualinherited

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 306 of file implicit_system.C.

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

306  {
307  this->assemble_before_solve = true;
308  this->get_linear_solver()->reuse_preconditioner(false);
309 }
virtual LinearSolver< Number > * get_linear_solver() const
virtual void reuse_preconditioner(bool)
bool assemble_before_solve
Definition: system.h:1477

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::LibMeshInit::LibMeshInit().

107 {
108  _enable_print_counter = false;
109  return;
110 }

◆ element_constraint()

virtual bool libMesh::DifferentiablePhysics::element_constraint ( bool  request_jacobian,
DiffContext  
)
inlinevirtualinherited

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().

Definition at line 142 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().

143  {
144  return request_jacobian;
145  }

◆ element_postprocess()

virtual void libMesh::DifferentiableSystem::element_postprocess ( DiffContext )
inlinevirtualinherited

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

Definition at line 282 of file diff_system.h.

282 {}

◆ element_qoi()

virtual void libMesh::DifferentiableQoI::element_qoi ( DiffContext ,
const QoISet  
)
inlinevirtualinherited

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.

Definition at line 108 of file diff_qoi.h.

110  {}

◆ element_qoi_derivative()

virtual void libMesh::DifferentiableQoI::element_qoi_derivative ( DiffContext ,
const QoISet  
)
inlinevirtualinherited

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.

Definition at line 120 of file diff_qoi.h.

122  {}

◆ element_time_derivative()

virtual bool libMesh::DifferentiablePhysics::element_time_derivative ( bool  request_jacobian,
DiffContext  
)
inlinevirtualinherited

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().

Definition at line 124 of file diff_physics.h.

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

125  {
126  return request_jacobian;
127  }

◆ enable_print_counter_info()

void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = true;
103  return;
104 }

◆ eulerian_residual() [1/2]

virtual bool libMesh::FEMPhysics::eulerian_residual ( bool  request_jacobian,
DiffContext context 
)
overridevirtualinherited

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 eulerian_residual() with a blank function; ALE or stabilized formulations will require reimplementing eulerian_residual() entirely.

Reimplemented from libMesh::DifferentiablePhysics.

◆ eulerian_residual() [2/2]

virtual bool libMesh::DifferentiablePhysics::eulerian_residual ( bool  request_jacobian,
DiffContext  
)
inlinevirtualinherited

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

The library provides a basic implementation in FEMPhysics::eulerian_residual()

Reimplemented in libMesh::FEMPhysics.

Definition at line 294 of file diff_physics.h.

295  {
296  return request_jacobian;
297  }

◆ finalize_derivative()

virtual void libMesh::DifferentiableQoI::finalize_derivative ( NumericVector< Number > &  derivatives,
std::size_t  qoi_index 
)
virtualinherited

Method to finalize qoi derivatives which require more than just a simple sum of element contributions.

Referenced by libMesh::FEMSystem::assemble_qoi_derivative().

◆ forward_qoi_parameter_sensitivity()

void libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity ( const QoISet qoi_indices,
const ParameterVector parameters,
SensitivityData sensitivities 
)
overridevirtualinherited

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 the forward sensitivity method.

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

Reimplemented from libMesh::System.

Definition at line 807 of file implicit_system.C.

References std::abs(), libMesh::SensitivityData::allocate_data(), libMesh::ExplicitSystem::assemble_qoi(), libMesh::ExplicitSystem::assemble_qoi_derivative(), libMesh::ImplicitSystem::assembly(), libMesh::NumericVector< T >::close(), libMesh::SparseMatrix< T >::close(), libMesh::NumericVector< T >::dot(), libMesh::System::get_adjoint_rhs(), libMesh::System::get_sensitivity_solution(), libMesh::QoISet::has_index(), libMesh::ImplicitSystem::matrix, std::max(), libMesh::System::n_qois(), libMesh::System::qoi, libMesh::Real, libMesh::ExplicitSystem::rhs, libMesh::ImplicitSystem::sensitivity_solve(), libMesh::ParameterVector::size(), and libMesh::TOLERANCE.

810 {
811  ParameterVector & parameters =
812  const_cast<ParameterVector &>(parameters_in);
813 
814  const unsigned int Np = cast_int<unsigned int>
815  (parameters.size());
816  const unsigned int Nq = this->n_qois();
817 
818  // An introduction to the problem:
819  //
820  // Residual R(u(p),p) = 0
821  // partial R / partial u = J = system matrix
822  //
823  // This implies that:
824  // d/dp(R) = 0
825  // (partial R / partial p) +
826  // (partial R / partial u) * (partial u / partial p) = 0
827 
828  // We first solve for (partial u / partial p) for each parameter:
829  // J * (partial u / partial p) = - (partial R / partial p)
830 
831  this->sensitivity_solve(parameters);
832 
833  // Get ready to fill in sensitivities:
834  sensitivities.allocate_data(qoi_indices, *this, parameters);
835 
836  // We use the identity:
837  // dq/dp = (partial q / partial p) + (partial q / partial u) *
838  // (partial u / partial p)
839 
840  // We get (partial q / partial u) from the user
841  this->assemble_qoi_derivative(qoi_indices,
842  /* include_liftfunc = */ true,
843  /* apply_constraints = */ false);
844 
845  // We don't need these to be closed() in this function, but libMesh
846  // standard practice is to have them closed() by the time the
847  // function exits
848  for (unsigned int i=0; i != this->n_qois(); ++i)
849  if (qoi_indices.has_index(i))
850  this->get_adjoint_rhs(i).close();
851 
852  for (unsigned int j=0; j != Np; ++j)
853  {
854  // We currently get partial derivatives via central differencing
855 
856  // (partial q / partial p) ~= (q(p+dp)-q(p-dp))/(2*dp)
857 
858  Number old_parameter = *parameters[j];
859 
860  const Real delta_p =
861  TOLERANCE * std::max(std::abs(old_parameter), 1e-3);
862 
863  *parameters[j] = old_parameter - delta_p;
864  this->assemble_qoi(qoi_indices);
865  std::vector<Number> qoi_minus = this->qoi;
866 
867  *parameters[j] = old_parameter + delta_p;
868  this->assemble_qoi(qoi_indices);
869  std::vector<Number> & qoi_plus = this->qoi;
870 
871  std::vector<Number> partialq_partialp(Nq, 0);
872  for (unsigned int i=0; i != Nq; ++i)
873  if (qoi_indices.has_index(i))
874  partialq_partialp[i] = (qoi_plus[i] - qoi_minus[i]) / (2.*delta_p);
875 
876  // Don't leave the parameter changed
877  *parameters[j] = old_parameter;
878 
879  for (unsigned int i=0; i != Nq; ++i)
880  if (qoi_indices.has_index(i))
881  sensitivities[i][j] = partialq_partialp[i] +
882  this->get_adjoint_rhs(i).dot(this->get_sensitivity_solution(j));
883  }
884 
885  // All parameters have been reset.
886  // We didn't cache the original rhs or matrix for memory reasons,
887  // but we can restore them to a state consistent solution -
888  // principle of least surprise.
889  this->assembly(true, true);
890  this->rhs->close();
891  this->matrix->close();
892  this->assemble_qoi(qoi_indices);
893 }
double abs(double a)
unsigned int n_qois() const
Definition: system.h:2278
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition: system.C:916
NumericVector< Number > * rhs
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters) override
static const Real TOLERANCE
virtual T dot(const NumericVector< T > &v) const =0
long double max(long double a, double b)
virtual void assembly(bool, bool, bool=false, bool=false)
std::vector< Number > qoi
Definition: system.h:1558
virtual void close()=0
virtual void close()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SparseMatrix< Number > * matrix
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) override
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1031

◆ get_adjoint_rhs() [1/2]

NumericVector< Number > & libMesh::System::get_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. This what the user's QoI derivative code should assemble when setting up an adjoint problem

Definition at line 1031 of file system.C.

References libMesh::System::get_vector().

Referenced by libMesh::ImplicitSystem::adjoint_solve(), libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity(), libMesh::ImplicitSystem::qoi_parameter_hessian(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), and libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve().

1032 {
1033  std::ostringstream adjoint_rhs_name;
1034  adjoint_rhs_name << "adjoint_rhs" << i;
1035 
1036  return this->get_vector(adjoint_rhs_name.str());
1037 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:774

◆ get_adjoint_rhs() [2/2]

const NumericVector< Number > & libMesh::System::get_adjoint_rhs ( unsigned int  i = 0) const
inherited
Returns
A reference to one of the system's adjoint rhs vectors, by default the one corresponding to the first qoi.

Definition at line 1041 of file system.C.

References libMesh::System::get_vector().

1042 {
1043  std::ostringstream adjoint_rhs_name;
1044  adjoint_rhs_name << "adjoint_rhs" << i;
1045 
1046  return this->get_vector(adjoint_rhs_name.str());
1047 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:774

◆ get_adjoint_solution() [1/2]

NumericVector< Number > & libMesh::System::get_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.

Definition at line 969 of file system.C.

References libMesh::System::get_vector().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::ImplicitSystem::adjoint_solve(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::ImplicitSystem::qoi_parameter_hessian(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), and libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve().

970 {
971  std::ostringstream adjoint_name;
972  adjoint_name << "adjoint_solution" << i;
973 
974  return this->get_vector(adjoint_name.str());
975 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:774

◆ get_adjoint_solution() [2/2]

const NumericVector< Number > & libMesh::System::get_adjoint_solution ( unsigned int  i = 0) const
inherited
Returns
A reference to one of the system's adjoint solution vectors, by default the one corresponding to the first qoi.

Definition at line 979 of file system.C.

References libMesh::System::get_vector().

980 {
981  std::ostringstream adjoint_name;
982  adjoint_name << "adjoint_solution" << i;
983 
984  return this->get_vector(adjoint_name.str());
985 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:774

◆ get_all_variable_numbers()

void libMesh::System::get_all_variable_numbers ( std::vector< unsigned int > &  all_variable_numbers) const
inherited

Fills all_variable_numbers with all the variable numbers for the variables that have been added to this system.

Definition at line 1258 of file system.C.

References libMesh::System::_variable_numbers, and libMesh::System::n_vars().

1259 {
1260  all_variable_numbers.resize(n_vars());
1261 
1262  // Make sure the variable exists
1263  std::map<std::string, unsigned short int>::const_iterator
1264  it = _variable_numbers.begin();
1265  std::map<std::string, unsigned short int>::const_iterator
1266  it_end = _variable_numbers.end();
1267 
1268  unsigned int count = 0;
1269  for ( ; it != it_end; ++it)
1270  {
1271  all_variable_numbers[count] = it->second;
1272  count++;
1273  }
1274 }
std::map< std::string, unsigned short int > _variable_numbers
Definition: system.h:1922
unsigned int n_vars() const
Definition: system.h:2105

◆ get_dof_map() [1/2]

const DofMap & libMesh::System::get_dof_map ( ) const
inlineinherited
Returns
A constant reference to this system's _dof_map.

Definition at line 2049 of file system.h.

References libMesh::System::_dof_map.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::DifferentiableSystem::add_dot_var_dirichlet_bcs(), libMesh::HPCoarsenTest::add_projection(), libMesh::UnsteadySolver::adjoint_advance_timestep(), libMesh::ImplicitSystem::adjoint_solve(), libMesh::NewmarkSolver::advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), libMesh::EquationSystems::allgather(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::PetscDMWrapper::build_sf(), libMesh::System::calculate_norm(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), DMCreateDomainDecomposition_libMesh(), DMCreateFieldDecomposition_libMesh(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::System::get_info(), libMesh::SystemSubsetBySubdomain::init(), libMesh::SecondOrderUnsteadySolver::init_data(), libMesh::UnsteadySolver::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ImplicitSystem::init_matrices(), libMesh::CondensedEigenSystem::initialize_condensed_dofs(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_postcheck(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::System::local_dof_indices(), libMesh::DofMap::max_constraint_error(), libMesh::DGFEMContext::neighbor_side_fe_reinit(), libMesh::UnsteadySolver::old_nonlinear_solution(), libMesh::SecondOrderUnsteadySolver::old_solution_accel(), libMesh::SecondOrderUnsteadySolver::old_solution_rate(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::petsc_auto_fieldsplit(), libMesh::ErrorVector::plot_error(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::FEMContext::pre_fe_reinit(), libMesh::System::re_update(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::SecondOrderUnsteadySolver::reinit(), libMesh::UnsteadySolver::reinit(), libMesh::EigenSystem::reinit(), libMesh::ImplicitSystem::reinit(), libMesh::System::reinit_constraints(), libMesh::EquationSystems::reinit_solutions(), libMesh::UnsteadySolver::retrieve_timestep(), libMesh::HPCoarsenTest::select_refinement(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::NewtonSolver::solve(), libMesh::PetscDiffSolver::solve(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), libMesh::ImplicitSystem::weighted_sensitivity_solve(), libMesh::System::write_parallel_data(), libMesh::EnsightIO::write_scalar_ascii(), libMesh::System::write_SCALAR_dofs(), and libMesh::EnsightIO::write_vector_ascii().

2050 {
2051  return *_dof_map;
2052 }
std::unique_ptr< DofMap > _dof_map
Definition: system.h:1884

◆ get_dof_map() [2/2]

DofMap & libMesh::System::get_dof_map ( )
inlineinherited
Returns
A writable reference to this system's _dof_map.

Definition at line 2057 of file system.h.

References libMesh::System::_dof_map.

2058 {
2059  return *_dof_map;
2060 }
std::unique_ptr< DofMap > _dof_map
Definition: system.h:1884

◆ get_equation_systems() [1/2]

◆ get_equation_systems() [2/2]

EquationSystems& libMesh::System::get_equation_systems ( )
inlineinherited
Returns
A reference to this system's parent EquationSystems object.

Definition at line 717 of file system.h.

References libMesh::System::_equation_systems.

717 { return _equation_systems; }
EquationSystems & _equation_systems
Definition: system.h:1890

◆ get_first_order_vars()

const std::set<unsigned int>& libMesh::DifferentiablePhysics::get_first_order_vars ( ) const
inlineinherited
Returns
The set of first order in time variable indices. May be empty.

Definition at line 517 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_first_order_vars.

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

518  { return _first_order_vars; }
std::set< unsigned int > _first_order_vars
Definition: diff_physics.h:559

◆ get_info() [1/2]

std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

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

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (const auto & pr : _counts)
59  {
60  const std::string name(pr.first);
61  const unsigned int creations = pr.second.first;
62  const unsigned int destructions = pr.second.second;
63 
64  oss << "| " << name << " reference count information:\n"
65  << "| Creations: " << creations << '\n'
66  << "| Destructions: " << destructions << '\n';
67  }
68 
69  oss << " ---------------------------------------------------------------------------- \n";
70 
71  return oss.str();
72 
73 #else
74 
75  return "";
76 
77 #endif
78 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42

◆ get_info() [2/2]

std::string libMesh::System::get_info ( ) const
inherited
Returns
A string containing information about the system.

Definition at line 1658 of file system.C.

References libMesh::FEType::family, libMesh::System::get_dof_map(), libMesh::DofMap::get_info(), libMesh::FEType::inf_map, libMesh::System::n_constrained_dofs(), libMesh::System::n_dofs(), libMesh::System::n_local_constrained_dofs(), libMesh::System::n_local_dofs(), libMesh::System::n_matrices(), libMesh::System::n_variable_groups(), libMesh::VariableGroup::n_variables(), libMesh::System::n_vectors(), libMesh::VariableGroup::name(), libMesh::System::name(), libMesh::System::number(), libMesh::FEType::order, libMesh::FEType::radial_family, libMesh::FEType::radial_order, libMesh::System::system_type(), libMesh::Variable::type(), libMesh::DofMap::variable_group(), and libMesh::System::variable_group().

1659 {
1660  std::ostringstream oss;
1661 
1662 
1663  const std::string & sys_name = this->name();
1664 
1665  oss << " System #" << this->number() << ", \"" << sys_name << "\"\n"
1666  << " Type \"" << this->system_type() << "\"\n"
1667  << " Variables=";
1668 
1669  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1670  {
1671  const VariableGroup & vg_description (this->variable_group(vg));
1672 
1673  if (vg_description.n_variables() > 1) oss << "{ ";
1674  for (unsigned int vn=0; vn<vg_description.n_variables(); vn++)
1675  oss << "\"" << vg_description.name(vn) << "\" ";
1676  if (vg_description.n_variables() > 1) oss << "} ";
1677  }
1678 
1679  oss << '\n';
1680 
1681  oss << " Finite Element Types=";
1682 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
1683  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1684  oss << "\""
1685  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().family)
1686  << "\" ";
1687 #else
1688  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1689  {
1690  oss << "\""
1691  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().family)
1692  << "\", \""
1693  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().radial_family)
1694  << "\" ";
1695  }
1696 
1697  oss << '\n' << " Infinite Element Mapping=";
1698  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1699  oss << "\""
1700  << Utility::enum_to_string<InfMapType>(this->get_dof_map().variable_group(vg).type().inf_map)
1701  << "\" ";
1702 #endif
1703 
1704  oss << '\n';
1705 
1706  oss << " Approximation Orders=";
1707  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1708  {
1709 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
1710  oss << "\""
1711  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().order)
1712  << "\" ";
1713 #else
1714  oss << "\""
1715  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().order)
1716  << "\", \""
1717  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().radial_order)
1718  << "\" ";
1719 #endif
1720  }
1721 
1722  oss << '\n';
1723 
1724  oss << " n_dofs()=" << this->n_dofs() << '\n';
1725  oss << " n_local_dofs()=" << this->n_local_dofs() << '\n';
1726 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1727  oss << " n_constrained_dofs()=" << this->n_constrained_dofs() << '\n';
1728  oss << " n_local_constrained_dofs()=" << this->n_local_constrained_dofs() << '\n';
1729 #endif
1730 
1731  oss << " " << "n_vectors()=" << this->n_vectors() << '\n';
1732  oss << " " << "n_matrices()=" << this->n_matrices() << '\n';
1733  // oss << " " << "n_additional_matrices()=" << this->n_additional_matrices() << '\n';
1734 
1735  oss << this->get_dof_map().get_info();
1736 
1737  return oss.str();
1738 }
FEFamily family
Definition: fe_type.h:204
OrderWrapper radial_order
Definition: fe_type.h:237
unsigned int n_variable_groups() const
Definition: system.h:2113
OrderWrapper order
Definition: fe_type.h:198
dof_id_type n_local_dofs() const
Definition: system.C:187
std::string get_info() const
Definition: dof_map.C:2703
dof_id_type n_dofs() const
Definition: system.C:150
unsigned int number() const
Definition: system.h:2025
unsigned int n_vectors() const
Definition: system.h:2233
const VariableGroup & variable_group(const unsigned int c) const
Definition: dof_map.h:1752
InfMapType inf_map
Definition: fe_type.h:258
virtual unsigned int n_matrices() const
Definition: system.h:2239
FEFamily radial_family
Definition: fe_type.h:250
virtual std::string system_type() const
Definition: system.h:487
dof_id_type n_local_constrained_dofs() const
Definition: system.C:172
const std::string & name() const
Definition: system.h:2017
const DofMap & get_dof_map() const
Definition: system.h:2049
const VariableGroup & variable_group(unsigned int vg) const
Definition: system.h:2143
dof_id_type n_constrained_dofs() const
Definition: system.C:157
const FEType & type() const
Definition: variable.h:119

◆ get_linear_solve_parameters()

std::pair< unsigned int, Real > libMesh::DifferentiableSystem::get_linear_solve_parameters ( ) const
overridevirtualinherited
Returns
An integer corresponding to the upper iteration count limit and a Real corresponding to the convergence tolerance to be used in linear adjoint and/or sensitivity solves

Reimplemented from libMesh::ImplicitSystem.

Definition at line 184 of file diff_system.C.

References libMesh::DifferentiableSystem::time_solver.

185 {
186  libmesh_assert(time_solver.get());
187  libmesh_assert_equal_to (&(time_solver->system()), this);
188  return std::make_pair(this->time_solver->diff_solver()->max_linear_iterations,
189  this->time_solver->diff_solver()->relative_residual_tolerance);
190 }
std::unique_ptr< TimeSolver > time_solver
Definition: diff_system.h:234

◆ get_linear_solver()

LinearSolver< Number > * libMesh::DifferentiableSystem::get_linear_solver ( ) const
overridevirtualinherited
Returns
A pointer to a linear solver appropriate for use in adjoint and/or sensitivity solves

Reimplemented from libMesh::ImplicitSystem.

Definition at line 175 of file diff_system.C.

References libMesh::DifferentiableSystem::time_solver.

176 {
177  libmesh_assert(time_solver.get());
178  libmesh_assert_equal_to (&(time_solver->system()), this);
179  return this->time_solver->linear_solver().get();
180 }
std::unique_ptr< TimeSolver > time_solver
Definition: diff_system.h:234

◆ get_matrix() [1/2]

const SparseMatrix< Number > & libMesh::ImplicitSystem::get_matrix ( const std::string &  mat_name) const
inherited
Returns
A const reference to this system's additional matrix named mat_name.

None of these matrices is involved in the solution process. Access is only granted when the matrix is already properly initialized.

Definition at line 263 of file implicit_system.C.

References libMesh::ImplicitSystem::_matrices.

Referenced by libMesh::NewmarkSystem::compute_matrix(), libMesh::EigenTimeSolver::solve(), and libMesh::NewmarkSystem::update_rhs().

264 {
265  // Make sure the matrix exists
266  const_matrices_iterator pos = _matrices.find (mat_name);
267 
268  if (pos == _matrices.end())
269  libmesh_error_msg("ERROR: matrix " << mat_name << " does not exist in this system!");
270 
271  return *(pos->second);
272 }
std::map< std::string, SparseMatrix< Number > * > _matrices
std::map< std::string, SparseMatrix< Number > * >::const_iterator const_matrices_iterator

◆ get_matrix() [2/2]

SparseMatrix< Number > & libMesh::ImplicitSystem::get_matrix ( const std::string &  mat_name)
inherited
Returns
A writable reference to this system's additional matrix named mat_name.

None of these matrices is involved in the solution process. Access is only granted when the matrix is already properly initialized.

Definition at line 276 of file implicit_system.C.

References libMesh::ImplicitSystem::_matrices.

277 {
278  // Make sure the matrix exists
279  matrices_iterator pos = _matrices.find (mat_name);
280 
281  if (pos == _matrices.end())
282  libmesh_error_msg("ERROR: matrix " << mat_name << " does not exist in this system!");
283 
284  return *(pos->second);
285 }
std::map< std::string, SparseMatrix< Number > * > _matrices
std::map< std::string, SparseMatrix< Number > * >::iterator matrices_iterator

◆ get_mesh() [1/2]

const MeshBase & libMesh::System::get_mesh ( ) const
inlineinherited
Returns
A constant reference to this systems's _mesh.

Definition at line 2033 of file system.h.

References libMesh::System::_mesh.

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::HPCoarsenTest::add_projection(), libMesh::FEMSystem::assemble_qoi(), libMesh::FEMSystem::assemble_qoi_derivative(), libMesh::FEMSystem::assembly(), libMesh::System::calculate_norm(), DMCreateDomainDecomposition_libMesh(), DMCreateFieldDecomposition_libMesh(), DMlibMeshSetSystem_libMesh(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::SystemSubsetBySubdomain::init(), libMesh::System::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ImplicitSystem::init_matrices(), libMesh::System::local_dof_indices(), libMesh::DofMap::max_constraint_error(), libMesh::FEMSystem::mesh_position_get(), libMesh::FEMSystem::mesh_position_set(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::FEMSystem::postprocess(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::System::read_parallel_data(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::EigenSystem::reinit(), libMesh::ImplicitSystem::reinit(), libMesh::HPSingularity::select_refinement(), libMesh::HPCoarsenTest::select_refinement(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::System::write_header(), libMesh::System::write_parallel_data(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), and libMesh::System::zero_variable().

2034 {
2035  return _mesh;
2036 }
MeshBase & _mesh
Definition: system.h:1896

◆ get_mesh() [2/2]

MeshBase & libMesh::System::get_mesh ( )
inlineinherited
Returns
A reference to this systems's _mesh.

Definition at line 2041 of file system.h.

References libMesh::System::_mesh.

2042 {
2043  return _mesh;
2044 }
MeshBase & _mesh
Definition: system.h:1896

◆ get_mesh_system() [1/2]

const System * libMesh::DifferentiablePhysics::get_mesh_system ( ) const
inlineinherited
Returns
A const reference to the system with variables corresponding to mesh nodal coordinates, or nullptr if the mesh is fixed. Useful for ALE calculations.

Definition at line 624 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_sys.

Referenced by libMesh::FEMSystem::build_context().

625 {
626  return _mesh_sys;
627 }

◆ get_mesh_system() [2/2]

System * libMesh::DifferentiablePhysics::get_mesh_system ( )
inlineinherited
Returns
A reference to the system with variables corresponding to mesh nodal coordinates, or nullptr if the mesh is fixed.

Definition at line 630 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_sys.

631 {
632  return _mesh_sys;
633 }

◆ get_mesh_x_var()

unsigned int libMesh::DifferentiablePhysics::get_mesh_x_var ( ) const
inlineinherited
Returns
The variable number corresponding to the mesh x coordinate. Useful for ALE calculations.

Definition at line 636 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_x_var.

Referenced by libMesh::FEMSystem::build_context().

637 {
638  return _mesh_x_var;
639 }

◆ get_mesh_y_var()

unsigned int libMesh::DifferentiablePhysics::get_mesh_y_var ( ) const
inlineinherited
Returns
The variable number corresponding to the mesh y coordinate. Useful for ALE calculations.

Definition at line 642 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_y_var.

Referenced by libMesh::FEMSystem::build_context().

643 {
644  return _mesh_y_var;
645 }

◆ get_mesh_z_var()

unsigned int libMesh::DifferentiablePhysics::get_mesh_z_var ( ) const
inlineinherited
Returns
The variable number corresponding to the mesh z coordinate. Useful for ALE calculations.

Definition at line 648 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_z_var.

Referenced by libMesh::FEMSystem::build_context().

649 {
650  return _mesh_z_var;
651 }

◆ get_physics() [1/2]

◆ get_physics() [2/2]

DifferentiablePhysics* libMesh::DifferentiableSystem::get_physics ( )
inlineinherited
Returns
A reference to a DifferentiablePhysics object.
Note
If no external Physics object is attached, the default is this.

Definition at line 191 of file diff_system.h.

References libMesh::DifferentiableSystem::_diff_physics.

192  { return this->_diff_physics; }
DifferentiablePhysics * _diff_physics
Definition: diff_system.h:371

◆ get_qoi() [1/2]