libMesh
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CoupledSystem Class Reference

#include <coupled_system.h>

Inheritance diagram for CoupledSystem:
[legend]

Public Types

typedef FEMSystem sys_type
 The type of system. More...
 
typedef DifferentiableSystem Parent
 The type of the parent. More...
 
typedef bool(TimeSolver::* TimeSolverResPtr) (bool, DiffContext &)
 Syntax sugar to make numerical_jacobian() declaration easier. More...
 
typedef Number(* ValueFunctionPointer) (const Point &p, const Parameters &Parameters, const std::string &sys_name, const std::string &unknown_name)
 Projects arbitrary functions onto the current solution. More...
 
typedef Gradient(* GradientFunctionPointer) (const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
 
typedef std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::iterator vectors_iterator
 Vector iterator typedefs. More...
 
typedef std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::const_iterator const_vectors_iterator
 
typedef std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::iterator matrices_iterator
 Matrix iterator typedefs. More...
 
typedef std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> >::const_iterator const_matrices_iterator
 

Public Member Functions

 CoupledSystem (EquationSystems &es, const std::string &name_in, const unsigned int number_in)
 
Number & get_QoI_value ()
 
Number & get_parameter_value (unsigned int parameter_index)
 
ParameterVectorget_parameter_vector ()
 
Real & get_Pe ()
 
virtual void assembly (bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) override
 Prepares matrix or rhs for matrix assembly. More...
 
virtual void solve () override
 Invokes the solver associated with the system. More...
 
void mesh_position_get ()
 Tells the FEMSystem to set the degree of freedom coefficients which should correspond to mesh nodal coordinates. More...
 
void mesh_position_set ()
 Tells the FEMSystem to set the mesh nodal coordinates which should correspond to degree of freedom coefficients. More...
 
virtual std::unique_ptr< DiffContextbuild_context () override
 Builds a FEMContext object with enough information to do evaluations on each element. More...
 
virtual void assemble_qoi (const QoISet &indices=QoISet()) override
 Runs a qoi assembly loop over all elements, and if assemble_qoi_sides is true over all sides. More...
 
virtual void assemble_qoi_derivative (const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
 Runs a qoi derivative assembly loop over all elements, and if assemble_qoi_sides is true over all sides. More...
 
Real numerical_jacobian_h_for_var (unsigned int var_num) const
 If numerical_jacobian_h_for_var(var_num) is changed from its default value (numerical_jacobian_h), the FEMSystem will perturb solution vector entries for variable var_num by that amount when calculating finite differences with respect to that variable. More...
 
void set_numerical_jacobian_h_for_var (unsigned int var_num, Real new_h)
 
void numerical_jacobian (TimeSolverResPtr res, FEMContext &context) const
 Uses the results of multiple res calls to numerically differentiate the corresponding jacobian. More...
 
void numerical_elem_jacobian (FEMContext &context) const
 Uses the results of multiple element_residual() calls to numerically differentiate the corresponding jacobian on an element. More...
 
void numerical_side_jacobian (FEMContext &context) const
 Uses the results of multiple side_residual() calls to numerically differentiate the corresponding jacobian on an element's side. More...
 
void numerical_nonlocal_jacobian (FEMContext &context) const
 Uses the results of multiple side_residual() calls to numerically differentiate the corresponding jacobian on nonlocal DoFs. More...
 
virtual void clear () override
 Clear all the data structures associated with the system. More...
 
virtual void reinit () override
 Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be used. More...
 
virtual void assemble () override
 Prepares matrix and rhs for matrix assembly. More...
 
virtual LinearSolver< Number > * get_linear_solver () const override
 
virtual std::pair< unsigned int, Real > get_linear_solve_parameters () const override
 
virtual std::pair< unsigned int, Real > adjoint_solve (const QoISet &qoi_indices=QoISet()) override
 This function sets the _is_adjoint boolean member of TimeSolver to true and then calls the adjoint_solve in implicit system. More...
 
virtual std::unique_ptr< DifferentiablePhysicsclone_physics () override
 We don't allow systems to be attached to each other. More...
 
virtual std::unique_ptr< DifferentiableQoIclone () override
 We don't allow systems to be attached to each other. More...
 
const DifferentiablePhysicsget_physics () const
 
DifferentiablePhysicsget_physics ()
 
void attach_physics (DifferentiablePhysics *physics_in)
 Attach external Physics object. More...
 
void push_physics (DifferentiablePhysics &new_physics)
 Push a clone of a new physics object onto our stack, overriding the current physics until the new physics is popped off again (or until something else is pushed on top of it). More...
 
void pop_physics ()
 Pop a physics object off of our stack. More...
 
const DifferentiableQoIget_qoi () const
 
DifferentiableQoIget_qoi ()
 
void attach_qoi (DifferentiableQoI *qoi_in)
 Attach external QoI object. More...
 
void set_time_solver (std::unique_ptr< TimeSolver > _time_solver)
 Sets the time_solver FIXME: This code is a little dangerous as it transfers ownership from the TimeSolver creator to this class. More...
 
TimeSolver & get_time_solver ()
 
const TimeSolver & get_time_solver () const
 Non-const version of the above. More...
 
virtual void element_postprocess (DiffContext &)
 Does any work that needs to be done on elem in a postprocessing loop. More...
 
virtual void side_postprocess (DiffContext &)
 Does any work that needs to be done on side of elem in a postprocessing loop. More...
 
unsigned int get_second_order_dot_var (unsigned int var) const
 For a given second order (in time) variable var, this method will return the index to the corresponding "dot" variable. More...
 
bool have_first_order_scalar_vars () const
 Check for any first order vars that are also belong to FEFamily::SCALAR. More...
 
bool have_second_order_scalar_vars () const
 Check for any second order vars that are also belong to FEFamily::SCALAR. More...
 
virtual void set_constrain_in_solver (bool enable)
 set_constrain_in_solver to false to apply constraints only via residual terms in the systems to be solved. More...
 
virtual bool get_constrain_in_solver ()
 
sys_typesystem ()
 
virtual void disable_cache () override
 Avoids use of any cached data that might affect any solve result. More...
 
virtual std::string system_type () const override
 
virtual void assemble_residual_derivatives (const ParameterVector &parameters) override
 Residual parameter derivative function. More...
 
virtual std::pair< unsigned int, Real > sensitivity_solve (const ParameterVector &parameters) override
 Assembles & solves the linear system(s) (dR/du)*u_p = -dR/dp, for those parameters contained within parameters. More...
 
virtual std::pair< unsigned int, Real > weighted_sensitivity_solve (const ParameterVector &parameters, const ParameterVector &weights) override
 Assembles & solves the linear system(s) (dR/du)*u_w = sum(w_p*-dR/dp), for those parameters p contained within parameters weighted by the values w_p found within weights. More...
 
virtual std::pair< unsigned int, Real > weighted_sensitivity_adjoint_solve (const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet()) override
 Assembles & solves the linear system(s) (dR/du)^T*z_w = sum(w_p*(d^2q/dudp - d^2R/dudp*z)), for those parameters p contained within parameters, weighted by the values w_p found within weights. More...
 
virtual void adjoint_qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) override
 Solves for the derivative of each of the system's quantities of interest q in qoi[qoi_indices] with respect to each parameter in parameters, placing the result for qoi i and parameter j into sensitivities[i][j]. More...
 
virtual void forward_qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) override
 Solves for the derivative of each of the system's quantities of interest q in qoi[qoi_indices] with respect to each parameter in parameters, placing the result for qoi i and parameter j into sensitivities[i][j]. More...
 
virtual void qoi_parameter_hessian (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian) override
 For each of the system's quantities of interest q in qoi[qoi_indices], and for a vector of parameters p, the parameter sensitivity Hessian H_ij is defined as H_ij = (d^2 q)/(d p_i d p_j) This Hessian is the output of this method, where for each q_i, H_jk is stored in hessian.second_derivative(i,j,k). More...
 
virtual void qoi_parameter_hessian_vector_product (const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product) override
 For each of the system's quantities of interest q in qoi[qoi_indices], and for a vector of parameters p, the parameter sensitivity Hessian H_ij is defined as H_ij = (d^2 q)/(d p_i d p_j) The Hessian-vector product, for a vector v_k in parameter space, is S_j = H_jk v_k This product is the output of this method, where for each q_i, S_j is stored in sensitivities[i][j]. More...
 
const SparseMatrix< Number > & get_system_matrix () const
 
SparseMatrix< Number > & get_system_matrix ()
 
virtual void create_static_condensation () override
 Request that static condensation be performed for this system. More...
 
StaticCondensation & get_static_condensation ()
 
void init ()
 Initializes degrees of freedom on the current mesh. More...
 
virtual void reinit_constraints ()
 Reinitializes the constraints for this system. More...
 
virtual void reinit_mesh ()
 Reinitializes the system with a new mesh. More...
 
bool is_initialized () const
 
virtual void update ()
 Update the local values to reflect the solution on neighboring processors. More...
 
virtual void restrict_solve_to (const SystemSubset *subset, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO)
 After calling this method, any solve will be restricted to the given subdomain. More...
 
bool is_adjoint_already_solved () const
 Accessor for the adjoint_already_solved boolean. More...
 
void set_adjoint_already_solved (bool setting)
 Setter for the adjoint_already_solved boolean. More...
 
virtual void qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
 Solves for the derivative of each of the system's quantities of interest q in qoi[qoi_indices] with respect to each parameter in parameters, placing the result for qoi i and parameter j into sensitivities[i][j]. More...
 
virtual bool compare (const System &other_system, const Real threshold, const bool verbose) const
 
const std::string & name () const
 
void project_solution (FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
 Projects arbitrary functions onto the current solution. More...
 
void project_solution (FEMFunctionBase< Number > *f, FEMFunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
 Projects arbitrary functions onto the current solution. More...
 
void project_solution (ValueFunctionPointer fptr, GradientFunctionPointer gptr, const Parameters &parameters, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
 This method projects an arbitrary function onto the solution via L2 projections and nodal interpolations on each element. More...
 
void project_vector (NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
 Projects arbitrary functions onto a vector of degree of freedom values for the current system. More...
 
void project_vector (NumericVector< Number > &new_vector, FEMFunctionBase< Number > *f, FEMFunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
 Projects arbitrary functions onto a vector of degree of freedom values for the current system. More...
 
void project_vector (ValueFunctionPointer fptr, GradientFunctionPointer gptr, const Parameters &parameters, NumericVector< Number > &new_vector, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
 Projects arbitrary functions onto a vector of degree of freedom values for the current system. More...
 
void boundary_project_solution (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt)
 Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system. More...
 
void boundary_project_solution (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, ValueFunctionPointer fptr, GradientFunctionPointer gptr, const Parameters &parameters, std::optional< ConstElemRange > active_local_range=std::nullopt)
 Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system. More...
 
void boundary_project_vector (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt) const
 Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system. More...
 
void boundary_project_vector (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, ValueFunctionPointer fptr, GradientFunctionPointer gptr, const Parameters &parameters, NumericVector< Number > &new_vector, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt) const
 Projects arbitrary boundary functions onto a vector of degree of freedom values for the current system. More...
 
unsigned int number () const
 
void update_global_solution (std::vector< Number > &global_soln) const
 Fill the input vector global_soln so that it contains the global solution on all processors. More...
 
void update_global_solution (std::vector< Number > &global_soln, const processor_id_type dest_proc) const
 Fill the input vector global_soln so that it contains the global solution on processor dest_proc. More...
 
const MeshBase & get_mesh () const
 
MeshBase & get_mesh ()
 
const DofMap & get_dof_map () const
 
DofMap & get_dof_map ()
 
const EquationSystems & get_equation_systems () const
 
EquationSystems & get_equation_systems ()
 
bool active () const
 
void activate ()
 Activates the system. More...
 
void deactivate ()
 Deactivates the system. More...
 
void set_basic_system_only ()
 Sets the system to be "basic only": i.e. More...
 
vectors_iterator vectors_begin ()
 Beginning of vectors container. More...
 
const_vectors_iterator vectors_begin () const
 Beginning of vectors container. More...
 
vectors_iterator vectors_end ()
 End of vectors container. More...
 
const_vectors_iterator vectors_end () const
 End of vectors container. More...
 
matrices_iterator matrices_begin ()
 Beginning of matrices container. More...
 
const_matrices_iterator matrices_begin () const
 Beginning of matrices container. More...
 
matrices_iterator matrices_end ()
 End of matrices container. More...
 
const_matrices_iterator matrices_end () const
 End of matrices container. More...
 
NumericVector< Number > & add_vector (std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
 Adds the additional vector vec_name to this system. More...
 
void remove_vector (std::string_view vec_name)
 Removes the additional vector vec_name from this system. More...
 
bool & project_solution_on_reinit (void)
 Tells the System whether or not to project the solution vector onto new grids when the system is reinitialized. More...
 
bool have_vector (std::string_view vec_name) const
 
const NumericVector< Number > * request_vector (std::string_view vec_name) const
 
NumericVector< Number > * request_vector (std::string_view 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 (std::string_view vec_name) const
 
NumericVector< Number > & get_vector (std::string_view vec_name)
 
const NumericVector< Number > & get_vector (const unsigned int vec_num) const
 
NumericVector< Number > & get_vector (const unsigned int vec_num)
 
const std::string & vector_name (const unsigned int vec_num) const
 
const std::string & vector_name (const NumericVector< Number > &vec_reference) const
 
void set_vector_as_adjoint (const std::string &vec_name, int qoi_num)
 Allows one to set the QoI index controlling whether the vector identified by vec_name represents a solution from the adjoint (qoi_num >= 0) or primal (qoi_num == -1) space. More...
 
int vector_is_adjoint (std::string_view vec_name) const
 
void set_vector_preservation (const std::string &vec_name, bool preserve)
 Allows one to set the boolean controlling whether the vector identified by vec_name should be "preserved": projected to new meshes, saved, etc. More...
 
bool vector_preservation (std::string_view 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_matrices () 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 (std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
 Adds the variable var to the list of variables for this system. More...
 
unsigned int add_variable (std::string_view var, const Order order=FIRST, const FEFamily=LAGRANGE, const std::set< subdomain_id_type > *const active_subdomains=nullptr, const bool p_refinement=true)
 Adds the variable var to the list of variables for this system. More...
 
unsigned int add_variables (const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
 Adds the variables vars to the list of variables for this system. More...
 
unsigned int add_variables (const std::vector< std::string > &vars, const Order order=FIRST, const FEFamily=LAGRANGE, const std::set< subdomain_id_type > *const active_subdomains=nullptr, const bool p_refinement=true)
 Adds the variable var to the list of variables for this system. More...
 
unsigned int add_variable_array (const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
 Adds variables vars to the list of variables for this system. More...
 
const Variable & variable (unsigned int var) const
 Return a constant reference to Variable var. More...
 
const VariableGroup & variable_group (unsigned int vg) const
 Return a constant reference to VariableGroup vg. More...
 
bool has_variable (std::string_view var) const
 
const std::string & variable_name (const unsigned int i) const
 
unsigned int variable_number (std::string_view var) const
 
void get_all_variable_numbers (std::vector< unsigned int > &all_variable_numbers) const
 Fills all_variable_numbers with all the variable numbers for the variables that have been added to this system. More...
 
unsigned int variable_scalar_number (std::string_view var, unsigned int component) const
 
unsigned int variable_scalar_number (unsigned int var_num, unsigned int component) const
 
const FEType & variable_type (const unsigned int i) const
 
const FEType & variable_type (std::string_view var) const
 
bool identify_variable_groups () const
 
void identify_variable_groups (const bool)
 Toggle automatic VariableGroup identification. More...
 
Real calculate_norm (const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=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, std::string_view version, const bool read_header=true, const bool read_additional_data=true, const bool read_legacy_format=false)
 Reads the basic data header for this System. More...
 
template<typename ValType >
void read_serialized_data (Xdr &io, const bool read_additional_data=true)
 Reads additional data, namely vectors, for this System. More...
 
void read_serialized_data (Xdr &io, const bool read_additional_data=true)
 Non-templated version for backward compatibility. More...
 
template<typename InValType >
std::size_t read_serialized_vectors (Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
 Read a number of identically distributed vectors. More...
 
std::size_t read_serialized_vectors (Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
 Non-templated version for backward compatibility. More...
 
template<typename InValType >
void read_parallel_data (Xdr &io, const bool read_additional_data)
 Reads additional data, namely vectors, for this System. More...
 
void read_parallel_data (Xdr &io, const bool read_additional_data)
 Non-templated version for backward compatibility. More...
 
void write_header (Xdr &io, std::string_view version, const bool write_additional_data) const
 Writes the basic data header for this System. More...
 
void write_serialized_data (Xdr &io, const bool write_additional_data=true) const
 Writes additional data, namely vectors, for this System. More...
 
std::size_t write_serialized_vectors (Xdr &io, const std::vector< const NumericVector< Number > *> &vectors) const
 Serialize & write a number of identically distributed vectors. More...
 
void write_parallel_data (Xdr &io, const bool write_additional_data) const
 Writes additional data, namely vectors, for this System. More...
 
std::string get_info () const
 
void attach_init_function (void fptr(EquationSystems &es, const std::string &name))
 Register a user function to use in initializing the system. More...
 
void attach_init_object (Initialization &init)
 Register a user class to use to initialize the system. More...
 
void attach_assemble_function (void fptr(EquationSystems &es, const std::string &name))
 Register a user function to use in assembling the system matrix and RHS. More...
 
void attach_assemble_object (Assembly &assemble)
 Register a user object to use in assembling the system matrix and RHS. More...
 
void attach_constraint_function (void fptr(EquationSystems &es, const std::string &name))
 Register a user function for imposing constraints. More...
 
void attach_constraint_object (Constraint &constrain)
 Register a user object for imposing constraints. More...
 
bool has_constraint_object () const
 
Constraintget_constraint_object ()
 Return the user object for imposing constraints. More...
 
void attach_QOI_function (void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices))
 Register a user function for evaluating the quantities of interest, whose values should be placed in System::qoi. More...
 
void attach_QOI_object (QOI &qoi)
 Register a user object for evaluating the quantities of interest, whose values should be placed in System::qoi. More...
 
void attach_QOI_derivative (void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints))
 Register a user function for evaluating derivatives of a quantity of interest with respect to test functions, whose values should be placed in System::rhs. More...
 
void attach_QOI_derivative_object (QOIDerivative &qoi_derivative)
 Register a user object for evaluating derivatives of a quantity of interest with respect to test functions, whose values should be placed in System::rhs. More...
 
virtual void user_initialization ()
 Calls user's attached initialization function, or is overridden by the user in derived classes. More...
 
virtual void user_assembly ()
 Calls user's attached assembly function, or is overridden by the user in derived classes. More...
 
virtual void user_constrain ()
 Calls user's attached constraint function, or is overridden by the user in derived classes. More...
 
virtual void user_QOI (const QoISet &qoi_indices)
 Calls user's attached quantity of interest function, or is overridden by the user in derived classes. More...
 
virtual void user_QOI_derivative (const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
 Calls user's attached quantity of interest derivative function, or is overridden by the user in derived classes. More...
 
virtual void re_update ()
 Re-update the local values when the mesh has changed. More...
 
virtual void restrict_vectors ()
 Restrict vectors after the mesh has coarsened. More...
 
virtual void prolong_vectors ()
 Prolong vectors after the mesh has refined. More...
 
Number current_solution (const dof_id_type global_dof_number) const
 
unsigned int n_qois () const
 Number of currently active quantities of interest. More...
 
void init_qois (unsigned int n_qois)
 Accessors for qoi and qoi_error_estimates vectors. More...
 
void set_qoi (unsigned int qoi_index, Number qoi_value)
 
void set_qoi (std::vector< Number > new_qoi)
 
Number get_qoi_value (unsigned int qoi_index) const
 
std::vector< Number > get_qoi_values () const
 Returns a copy of qoi, not a reference. More...
 
void set_qoi_error_estimate (unsigned int qoi_index, Number qoi_error_estimate)
 
Number get_qoi_error_estimate_value (unsigned int qoi_index) const
 
Number point_value (unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
 
Number point_value (unsigned int var, const Point &p, const Elem &e, const NumericVector< Number > *sol=nullptr) const
 
Number point_value (unsigned int var, const Point &p, const Elem *e) const
 Calls the version of point_value() which takes a reference. More...
 
Number point_value (unsigned int var, const Point &p, const NumericVector< Number > *sol) const
 Calls the parallel version of point_value(). More...
 
Gradient point_gradient (unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
 
Gradient point_gradient (unsigned int var, const Point &p, const Elem &e, const NumericVector< Number > *sol=nullptr) const
 
Gradient point_gradient (unsigned int var, const Point &p, const Elem *e) const
 Calls the version of point_gradient() which takes a reference. More...
 
Gradient point_gradient (unsigned int var, const Point &p, const NumericVector< Number > *sol) const
 Calls the parallel version of point_gradient(). More...
 
Tensor point_hessian (unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
 
Tensor point_hessian (unsigned int var, const Point &p, const Elem &e, const NumericVector< Number > *sol=nullptr) const
 
Tensor point_hessian (unsigned int var, const Point &p, const Elem *e) const
 Calls the version of point_hessian() which takes a reference. More...
 
Tensor point_hessian (unsigned int var, const Point &p, const NumericVector< Number > *sol) const
 Calls the parallel version of point_hessian(). More...
 
void local_dof_indices (const unsigned int var, std::set< dof_id_type > &var_indices) const
 Fills the std::set with the degrees of freedom on the local processor corresponding the the variable number passed in. More...
 
void zero_variable (NumericVector< Number > &v, unsigned int var_num) const
 Zeroes all dofs in v that correspond to variable number var_num. More...
 
bool get_project_with_constraints ()
 Setter and getter functions for project_with_constraints boolean. More...
 
void set_project_with_constraints (bool _project_with_constraints)
 
bool & hide_output ()
 
void projection_matrix (SparseMatrix< Number > &proj_mat) const
 This method creates a projection matrix which corresponds to the operation of project_vector between old and new solution spaces. More...
 
SparseMatrix< Number > & add_matrix (std::string_view mat_name, ParallelType type=PARALLEL, MatrixBuildType mat_build_type=MatrixBuildType::AUTOMATIC)
 Adds the additional matrix mat_name to this system. More...
 
template<template< typename > class>
SparseMatrix< Number > & add_matrix (std::string_view mat_name, ParallelType=PARALLEL)
 Adds the additional matrix mat_name to this system. More...
 
SparseMatrix< Number > & add_matrix (std::string_view mat_name, std::unique_ptr< SparseMatrix< Number >> matrix, ParallelType type=PARALLEL)
 Adds the additional matrix mat_name to this system. More...
 
void remove_matrix (std::string_view mat_name)
 Removes the additional matrix mat_name from this system. More...
 
bool have_matrix (std::string_view mat_name) const
 
const SparseMatrix< Number > * request_matrix (std::string_view mat_name) const
 
SparseMatrix< Number > * request_matrix (std::string_view mat_name)
 
const SparseMatrix< Number > & get_matrix (std::string_view mat_name) const
 
SparseMatrix< Number > & get_matrix (std::string_view mat_name)
 
void prefer_hash_table_matrix_assembly (bool preference)
 Sets whether to use hash table matrix assembly if the matrix sub-classes support it. More...
 
void prefix_with_name (bool value)
 Instructs this system to prefix solve options with its name for solvers that leverage prefixes. More...
 
bool prefix_with_name () const
 
std::string prefix () const
 
bool has_static_condensation () const
 
void solve_for_unconstrained_dofs (NumericVector< Number > &, int is_adjoint=-1) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
virtual void clear_physics ()
 Clear any data structures associated with the physics. More...
 
virtual void init_physics (const System &sys)
 Initialize any data structures associated with the physics. More...
 
virtual bool side_time_derivative (bool request_jacobian, DiffContext &)
 Adds the time derivative contribution on side of elem to elem_residual. More...
 
virtual bool side_constraint (bool request_jacobian, DiffContext &)
 Adds the constraint contribution on side of elem to elem_residual. More...
 
virtual bool nonlocal_time_derivative (bool request_jacobian, DiffContext &)
 Adds any nonlocal time derivative contributions (e.g. More...
 
virtual bool nonlocal_constraint (bool request_jacobian, DiffContext &)
 Adds any nonlocal constraint contributions (e.g. More...
 
virtual void time_evolving (unsigned int var, unsigned int order)
 Tells the DiffSystem that variable var is evolving with respect to time. More...
 
bool is_time_evolving (unsigned int var) const
 
virtual bool eulerian_residual (bool request_jacobian, DiffContext &)
 Adds a pseudo-convection contribution on elem to elem_residual, if the nodes of elem are being translated by a moving mesh. More...
 
virtual bool eulerian_residual (bool request_jacobian, DiffContext &context) override
 Adds a pseudo-convection contribution on elem to elem_residual, if the nodes of elem are being translated by a moving mesh. More...
 
virtual bool mass_residual (bool request_jacobian, DiffContext &)
 Subtracts a mass vector contribution on elem from elem_residual. More...
 
virtual bool mass_residual (bool request_jacobian, DiffContext &) override
 Subtracts a mass vector contribution on elem from elem_residual. More...
 
virtual bool side_mass_residual (bool request_jacobian, DiffContext &)
 Subtracts a mass vector contribution on side of elem from elem_residual. More...
 
virtual bool nonlocal_mass_residual (bool request_jacobian, DiffContext &c)
 Subtracts any nonlocal mass vector contributions (e.g. More...
 
virtual bool damping_residual (bool request_jacobian, DiffContext &)
 Subtracts a damping vector contribution on elem from elem_residual. More...
 
virtual bool side_damping_residual (bool request_jacobian, DiffContext &)
 Subtracts a damping vector contribution on side of elem from elem_residual. More...
 
virtual bool nonlocal_damping_residual (bool request_jacobian, DiffContext &)
 Subtracts any nonlocal damping vector contributions (e.g. More...
 
virtual void set_mesh_system (System *sys)
 Tells the DifferentiablePhysics that system sys contains the isoparametric Lagrangian variables which correspond to the coordinates of mesh nodes, in problems where the mesh itself is expected to move in time. More...
 
const Systemget_mesh_system () const
 
Systemget_mesh_system ()
 
virtual void set_mesh_x_var (unsigned int var)
 Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the x coordinate of mesh nodes, in problems where the mesh itself is expected to move in time. More...
 
unsigned int get_mesh_x_var () const
 
virtual void set_mesh_y_var (unsigned int var)
 Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the y coordinate of mesh nodes. More...
 
unsigned int get_mesh_y_var () const
 
virtual void set_mesh_z_var (unsigned int var)
 Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the z coordinate of mesh nodes. More...
 
unsigned int get_mesh_z_var () const
 
bool _eulerian_time_deriv (bool request_jacobian, DiffContext &)
 This method simply combines element_time_derivative() and eulerian_residual(), which makes its address useful as a pointer-to-member-function when refactoring. More...
 
bool have_first_order_vars () const
 
const std::set< unsigned int > & get_first_order_vars () const
 
bool is_first_order_var (unsigned int var) const
 
bool have_second_order_vars () const
 
const std::set< unsigned int > & get_second_order_vars () const
 
bool is_second_order_var (unsigned int var) const
 
virtual void init_qoi_count (System &)
 Initialize system qoi. More...
 
virtual void clear_qoi ()
 Clear all the data structures associated with the QoI. More...
 
virtual void element_qoi (DiffContext &, const QoISet &)
 Does any work that needs to be done on elem in a quantity of interest assembly loop, outputting to elem_qoi. More...
 
virtual void element_qoi_derivative (DiffContext &, const QoISet &)
 Does any work that needs to be done on elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative. More...
 
virtual void side_qoi (DiffContext &, const QoISet &)
 Does any work that needs to be done on side of elem in a quantity of interest assembly loop, outputting to elem_qoi. More...
 
virtual void side_qoi_derivative (DiffContext &, const QoISet &)
 Does any work that needs to be done on side of elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative. More...
 
virtual void thread_join (std::vector< Number > &qoi, const std::vector< Number > &other_qoi, const QoISet &qoi_indices)
 Method to combine thread-local qois. More...
 
virtual void parallel_op (const Parallel::Communicator &communicator, std::vector< Number > &sys_qoi, std::vector< Number > &local_qoi, const QoISet &qoi_indices)
 Method to populate system qoi data structure with process-local qoi. More...
 
virtual void finalize_derivative (NumericVector< Number > &derivatives, std::size_t qoi_index)
 Method to finalize qoi derivatives which require more than just a simple sum of element contributions. More...
 

Static Public Member Functions

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

Public Attributes

bool fe_reinit_during_postprocess
 If fe_reinit_during_postprocess is true (it is true by default), FE objects will be reinit()ed with their default quadrature rules. More...
 
Real numerical_jacobian_h
 If calculating numeric jacobians is required, the FEMSystem will perturb each solution vector entry by numerical_jacobian_h when calculating finite differences. More...
 
Real verify_analytic_jacobians
 If verify_analytic_jacobian is equal to zero (as it is by default), no numeric jacobians will be calculated unless an overridden element_time_derivative(), element_constraint(), side_time_derivative(), or side_constraint() function cannot provide an analytic jacobian upon request. More...
 
std::unique_ptr< TimeSolver > time_solver
 A pointer to the solver object we're going to use. More...
 
Real deltat
 For time-dependent problems, this is the amount delta t to advance the solution in time. More...
 
bool postprocess_sides
 If postprocess_sides is true (it is false by default), the postprocessing loop will loop over all sides as well as all elements. More...
 
bool print_solution_norms
 Set print_residual_norms to true to print |U| whenever it is used in an assembly() call. More...
 
bool print_solutions
 Set print_solutions to true to print U whenever it is used in an assembly() call. More...
 
bool print_residual_norms
 Set print_residual_norms to true to print |F| whenever it is assembled. More...
 
bool print_residuals
 Set print_residuals to true to print F whenever it is assembled. More...
 
bool print_jacobian_norms
 Set print_jacobian_norms to true to print |J| whenever it is assembled. More...
 
bool print_jacobians
 Set print_jacobians to true to print J whenever it is assembled. More...
 
bool print_element_solutions
 Set print_element_solutions to true to print each U_elem input. More...
 
bool print_element_residuals
 Set print_element_residuals to true to print each R_elem contribution. More...
 
bool print_element_jacobians
 Set print_element_jacobians to true to print each J_elem contribution. More...
 
SparseMatrix< Number > * matrix
 The system matrix. More...
 
bool zero_out_matrix_and_rhs
 By default, the system will zero out the matrix and the right hand side. More...
 
std::unique_ptr< LinearSolver< Number > > linear_solver
 This class handles all the details of interfacing with various linear algebra packages like PETSc or LASPACK. More...
 
NumericVector< Number > * rhs
 The system matrix. More...
 
bool assemble_before_solve
 Flag which tells the system to whether or not to call the user assembly function during each call to solve(). More...
 
bool use_fixed_solution
 A boolean to be set to true by systems using elem_fixed_solution, for optional use by e.g. More...
 
int extra_quadrature_order
 A member int that can be employed to indicate increased or reduced quadrature order. More...
 
std::unique_ptr< NumericVector< Number > > solution
 Data structure to hold solution values. More...
 
std::unique_ptr< NumericVector< Number > > current_local_solution
 All the values I need to compute my contribution to the simulation at hand. More...
 
Real time
 For time-dependent problems, this is the time t at the beginning of the current timestep. More...
 
bool compute_internal_sides
 compute_internal_sides is false by default, indicating that side_* computations will only be done on boundary sides. More...
 
bool assemble_qoi_sides
 If assemble_qoi_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over domain boundary sides. More...
 
bool assemble_qoi_internal_sides
 If assemble_qoi_internal_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over element sides which do not fall on domain boundaries. More...
 
bool assemble_qoi_elements
 If assemble_qoi_elements is false (it is true by default), the assembly loop for a quantity of interest or its derivatives will skip computing on mesh elements, and will only compute on mesh sides. More...
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

virtual void init_data ()
 Initializes the member data fields associated with the system, so that, e.g., assemble() may be used. More...
 
virtual void init_context (DiffContext &context)
 
virtual bool element_time_derivative (bool request_jacobian, DiffContext &context)
 Adds the time derivative contribution on elem to elem_residual. More...
 
virtual bool element_constraint (bool request_jacobian, DiffContext &context)
 Adds the constraint contribution on elem to elem_residual. More...
 
virtual void postprocess ()
 Runs a postprocessing loop over all elements, and if postprocess_sides is true over all sides. More...
 
void add_second_order_dot_vars ()
 Helper function to add "velocity" variables that are cousins to second order-in-time variables in the DifferentiableSystem. More...
 
void add_dot_var_dirichlet_bcs (unsigned int var_idx, unsigned int dot_var_idx)
 Helper function to and Dirichlet boundary conditions to "dot" variable cousins of second order variables in the system. More...
 
virtual void add_matrices () override
 Adds the system matrix. More...
 
template<typename T >
void setup_static_condensation_preconditioner (T &solver)
 Sets up the static condensation preconditioner for the supplied solver. More...
 
void project_vector (NumericVector< Number > &, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
 Projects the vector defined on the old mesh onto the new mesh. More...
 
void project_vector (const NumericVector< Number > &, NumericVector< Number > &, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
 Projects the vector defined on the old mesh onto the new mesh. More...
 
virtual void init_matrices ()
 Initializes the matrices associated with this system. More...
 
bool can_add_matrices () const
 
virtual bool condense_constrained_dofs () const
 Whether this object should condense out constrained degrees of freedom. More...
 
void increment_constructor_count (const std::string &name) noexcept
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name) noexcept
 Increments the destruction counter. More...
 

Protected Attributes

std::vector< Number > parameters
 
unsigned int p_var
 
unsigned int u_var
 
unsigned int v_var
 
unsigned int C_var
 
ParameterVector parameter_vector
 
Real Peclet
 
Number computed_QoI
 
bool _constrain_in_solver
 _constrain_in_solver defaults to true; if false then we apply constraints only via residual terms in the systems to be solved. More...
 
const Parallel::Communicator & _communicator
 
System_mesh_sys
 System from which to acquire moving mesh information. More...
 
unsigned int _mesh_x_var
 Variables from which to acquire moving mesh information. More...
 
unsigned int _mesh_y_var
 
unsigned int _mesh_z_var
 
std::vector< unsigned int_time_evolving
 Stores unsigned int to tell us which variables are evolving as first order in time (1), second order in time (2), or are not time evolving (0). More...
 
std::set< unsigned int_first_order_vars
 Variable indices for those variables that are first order in time. More...
 
std::set< unsigned int_second_order_vars
 Variable indices for those variables that are second order in time. More...
 
std::map< unsigned int, unsigned int_second_order_dot_vars
 If the user adds any second order variables, then we need to also cache the map to their corresponding dot variable that will be added by this TimeSolver class. More...
 

Static Protected Attributes

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

Detailed Description

Definition at line 35 of file coupled_system.h.

Member Typedef Documentation

◆ const_matrices_iterator

typedef std::map<std::string, std::unique_ptr<SparseMatrix<Number> >, std::less<> >::const_iterator libMesh::System::const_matrices_iterator
inherited

Definition at line 830 of file system.h.

◆ const_vectors_iterator

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

Definition at line 804 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 119 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 555 of file system.h.

◆ matrices_iterator

typedef std::map<std::string, std::unique_ptr<SparseMatrix<Number> >, std::less<> >::iterator libMesh::System::matrices_iterator
inherited

Matrix iterator typedefs.

Definition at line 829 of file system.h.

◆ Parent

The type of the parent.

Definition at line 85 of file fem_system.h.

◆ sys_type

The type of system.

Definition at line 80 of file fem_system.h.

◆ TimeSolverResPtr

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

Syntax sugar to make numerical_jacobian() declaration easier.

Definition at line 220 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 551 of file system.h.

◆ vectors_iterator

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

Vector iterator typedefs.

Definition at line 803 of file system.h.

Constructor & Destructor Documentation

◆ CoupledSystem()

CoupledSystem::CoupledSystem ( EquationSystems es,
const std::string &  name_in,
const unsigned int  number_in 
)
inline

Definition at line 39 of file coupled_system.h.

42  : FEMSystem(es, name_in, number_in), Peclet(1.) {this->init_qois(1);}
void init_qois(unsigned int n_qois)
Accessors for qoi and qoi_error_estimates vectors.
Definition: system.C:2164
FEMSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
Definition: fem_system.C:858

Member Function Documentation

◆ _eulerian_time_deriv()

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

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

Definition at line 97 of file diff_physics.C.

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

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

99 {
100  // For any problem we need time derivative terms
101  request_jacobian =
102  this->element_time_derivative(request_jacobian, context);
103 
104  // For a moving mesh problem we may need the pseudoconvection term too
105  return this->eulerian_residual(request_jacobian, context) &&
106  request_jacobian;
107 }
virtual bool element_time_derivative(bool request_jacobian, DiffContext &)
Adds the time derivative contribution on elem to elem_residual.
Definition: diff_physics.h:125
virtual bool eulerian_residual(bool request_jacobian, DiffContext &)
Adds a pseudo-convection contribution on elem to elem_residual, if the nodes of elem are being transl...
Definition: diff_physics.h:277

◆ activate()

void libMesh::System::activate ( )
inlineinherited

Activates the system.

Only active systems are solved.

Definition at line 2441 of file system.h.

References libMesh::System::_active.

2442 {
2443  _active = true;
2444 }
bool _active
Flag stating if the system is active or not.
Definition: system.h:2252

◆ 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 2433 of file system.h.

References libMesh::System::_active.

2434 {
2435  return _active;
2436 }
bool _active
Flag stating if the system is active or not.
Definition: system.h:2252

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

References libMesh::System::add_vector().

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

1285 {
1286  std::ostringstream adjoint_rhs_name;
1287  adjoint_rhs_name << "adjoint_rhs" << i;
1288 
1289  return this->add_vector(adjoint_rhs_name.str(), false);
1290 }
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:756

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

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

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

1221 {
1222  std::ostringstream adjoint_name;
1223  adjoint_name << "adjoint_solution" << i;
1224 
1225  NumericVector<Number> & returnval = this->add_vector(adjoint_name.str());
1226  this->set_vector_as_adjoint(adjoint_name.str(), i);
1227  return returnval;
1228 }
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Allows one to set the QoI index controlling whether the vector identified by vec_name represents a so...
Definition: system.C:1147
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:756
template class LIBMESH_EXPORT NumericVector< Number >

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

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

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

216 {
217  // We're assuming that there could be a lot more variables than
218  // boundary conditions, so we search each of the boundary conditions
219  // for this variable rather than looping over boundary conditions
220  // in a separate loop and searching through all the variables.
221  const DirichletBoundaries * all_dbcs =
223 
224  if (all_dbcs)
225  {
226  // We need to cache the DBCs to be added so that we add them
227  // after looping over the existing DBCs. Otherwise, we're polluting
228  // the thing we're looping over.
229  std::vector<DirichletBoundary> new_dbcs;
230 
231  for (const auto & dbc : *all_dbcs)
232  {
233  libmesh_assert(dbc);
234 
235  // Look for second order variable in the current
236  // DirichletBoundary object
237  std::vector<unsigned int>::const_iterator dbc_var_it =
238  std::find( dbc->variables.begin(), dbc->variables.end(), var_idx );
239 
240  // If we found it, then we also need to add it's corresponding
241  // "dot" variable to a DirichletBoundary
242  std::vector<unsigned int> vars_to_add;
243  if (dbc_var_it != dbc->variables.end())
244  vars_to_add.push_back(dot_var_idx);
245 
246  if (!vars_to_add.empty())
247  {
248  // We need to check if the boundary condition is time-dependent.
249  // Currently, we cannot automatically differentiate w.r.t. time
250  // so if the user supplies a time-dependent Dirichlet BC, then
251  // we can't automatically support the Dirichlet BC for the
252  // "velocity" boundary condition, so we error. Otherwise,
253  // the "velocity boundary condition will just be zero.
254  bool is_time_evolving_bc = false;
255  if (dbc->f)
256  is_time_evolving_bc = dbc->f->is_time_dependent();
257  else if (dbc->f_fem)
258  // We it's a FEMFunctionBase object, it will be implicitly
259  // time-dependent since it is assumed to depend on the solution.
260  is_time_evolving_bc = true;
261  else
262  libmesh_error_msg("Could not find valid boundary function!");
263 
264  libmesh_error_msg_if(is_time_evolving_bc, "Cannot currently support time-dependent Dirichlet BC for dot variables!");
265  libmesh_error_msg_if(!dbc->f, "Expected valid DirichletBoundary function");
266 
267  new_dbcs.emplace_back(dbc->b, vars_to_add, ZeroFunction<Number>());
268  }
269  }
270 
271  // Let the DofMap make its own deep copy of the DirichletBC objects
272  for (const auto & dbc : new_dbcs)
273  this->get_dof_map().add_dirichlet_boundary(dbc);
274 
275  } // if (all_dbcs)
276 }
libmesh_assert(ctx)
const DirichletBoundaries * get_dirichlet_boundaries() const
Definition: dof_map.h:1636
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ add_matrices()

void libMesh::ImplicitSystem::add_matrices ( )
overrideprotectedvirtualinherited

Adds the system matrix.

Reimplemented from libMesh::System.

Definition at line 113 of file implicit_system.C.

References libMesh::System::add_matrices(), libMesh::System::add_matrix(), libMesh::libmesh_assert(), libMesh::ImplicitSystem::matrix, and libMesh::System::n_matrices().

114 {
116 
117  // Possible that we cleared the _matrices but
118  // forgot to update the matrix pointer?
119  if (this->n_matrices() == 0)
120  matrix = nullptr;
121 
122  // Only need to add the matrix if it isn't there
123  // already!
124  if (matrix == nullptr)
125  matrix = &(this->add_matrix ("System Matrix"));
126 
128 }
virtual void add_matrices()
Insertion point for adding matrices in derived classes before init_matrices() is called.
Definition: system.h:2017
libmesh_assert(ctx)
unsigned int n_matrices() const
Definition: system.h:2638
SparseMatrix< Number > * matrix
The system matrix.
SparseMatrix< Number > & add_matrix(std::string_view mat_name, ParallelType type=PARALLEL, MatrixBuildType mat_build_type=MatrixBuildType::AUTOMATIC)
Adds the additional matrix mat_name to this system.
Definition: system.C:998

◆ add_matrix() [1/3]

SparseMatrix< Number > & libMesh::System::add_matrix ( std::string_view  mat_name,
ParallelType  type = PARALLEL,
MatrixBuildType  mat_build_type = MatrixBuildType::AUTOMATIC 
)
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 main/system matrix, then all the additional matrices, if existent, have to be initialized by the user, too.

This non-template method will add a derived matrix type corresponding to the solver package. If the user wishes to specify the matrix type to add, use the templated add_matrix method instead

Parameters
mat_nameA name for the matrix
typeThe serial/parallel/ghosted type of the matrix
mat_build_typeThe matrix type to build

Definition at line 998 of file system.C.

References libMesh::System::_matrices, libMesh::System::_matrix_types, libMesh::SparseMatrix< T >::build(), libMesh::ParallelObject::comm(), libMesh::default_solver_package(), libMesh::DIAGONAL, libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::DofMap::get_static_condensation(), libMesh::System::has_static_condensation(), libMesh::if(), libMesh::System::late_matrix_init(), and libMesh::libmesh_assert().

Referenced by libMesh::ImplicitSystem::add_matrices(), libMesh::EigenSystem::add_matrices(), alternative_fe_assembly(), libMesh::ClawSystem::assemble_boundary_condition_matrices(), libMesh::ImplicitSystem::create_static_condensation_system_matrix(), form_matrixA(), libMesh::EigenTimeSolver::init(), main(), and libMesh::NewmarkSystem::NewmarkSystem().

1001 {
1002  parallel_object_only();
1003 
1004  libmesh_assert(this->comm().verify(std::string(mat_name)));
1005  libmesh_assert(this->comm().verify(int(type)));
1006  libmesh_assert(this->comm().verify(int(mat_build_type)));
1007 
1008  // Return the matrix if it is already there.
1009  if (auto it = this->_matrices.find(mat_name);
1010  it != this->_matrices.end())
1011  return *it->second;
1012 
1013  // Otherwise build the matrix to return.
1014  std::unique_ptr<SparseMatrix<Number>> matrix;
1015  if (this->has_static_condensation())
1016  {
1017  if (mat_build_type == MatrixBuildType::DIAGONAL)
1018  libmesh_error_msg(
1019  "We do not currently support static condensation of the diagonal matrix type");
1020  matrix = std::make_unique<StaticCondensation>(this->get_mesh(),
1021  *this,
1022  this->get_dof_map(),
1024  }
1025  else
1027  auto & mat = *matrix;
1028 
1029  _matrices.emplace(mat_name, std::move(matrix));
1030 
1031  _matrix_types.emplace(mat_name, type);
1032 
1033  // Initialize it first if we've already initialized the others.
1034  this->late_matrix_init(mat, type);
1035 
1036  return mat;
1037 }
const Parallel::Communicator & comm() const
bool has_static_condensation() const
Definition: system.C:2664
const MeshBase & get_mesh() const
Definition: system.h:2401
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package(), const MatrixBuildType matrix_build_type=MatrixBuildType::AUTOMATIC)
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277
SolverPackage default_solver_package()
Definition: libmesh.C:1051
StaticCondensationDofMap & get_static_condensation()
Definition: dof_map.h:2859
libmesh_assert(ctx)
std::map< std::string, ParallelType, std::less<> > _matrix_types
Holds the types of the matrices.
Definition: system.h:2282
template class LIBMESH_EXPORT SparseMatrix< Number >
const DofMap & get_dof_map() const
Definition: system.h:2417
void late_matrix_init(SparseMatrix< Number > &mat, ParallelType type)
Helper function to keep DofMap forward declarable in system.h.
Definition: system.C:1063

◆ add_matrix() [2/3]

template<template< typename > class MatrixType>
SparseMatrix< Number > & libMesh::System::add_matrix ( std::string_view  mat_name,
ParallelType  type = PARALLEL 
)
inlineinherited

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 main/system matrix, then all the additional matrices, if existent, have to be initialized by the user, too.

This method will create add a derived matrix of type MatrixType<Number>. One can use the non-templated add_matrix method to add a matrix corresponding to the default solver package

Parameters
mat_nameA name for the matrix
typeThe serial/parallel/ghosted type of the matrix

Definition at line 2646 of file system.h.

References libMesh::System::_matrices, libMesh::System::_matrix_types, and libMesh::System::late_matrix_init().

2648 {
2649  // Return the matrix if it is already there.
2650  auto it = this->_matrices.find(mat_name);
2651  if (it != this->_matrices.end())
2652  return *it->second;
2653 
2654  // Otherwise build the matrix to return.
2655  auto pr = _matrices.emplace(mat_name, std::make_unique<MatrixType<Number>>(this->comm()));
2656  _matrix_types.emplace(mat_name, type);
2657 
2658  SparseMatrix<Number> & mat = *(pr.first->second);
2659 
2660  // Initialize it first if we've already initialized the others.
2661  this->late_matrix_init(mat, type);
2662 
2663  return mat;
2664 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277
std::map< std::string, ParallelType, std::less<> > _matrix_types
Holds the types of the matrices.
Definition: system.h:2282
template class LIBMESH_EXPORT SparseMatrix< Number >
void late_matrix_init(SparseMatrix< Number > &mat, ParallelType type)
Helper function to keep DofMap forward declarable in system.h.
Definition: system.C:1063

◆ add_matrix() [3/3]

SparseMatrix< Number > & libMesh::System::add_matrix ( std::string_view  mat_name,
std::unique_ptr< SparseMatrix< Number >>  matrix,
ParallelType  type = PARALLEL 
)
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 main/system matrix, then all the additional matrices, if existent, have to be initialized by the user, too.

Parameters
mat_nameA name for the matrix
matrixThe matrix we are handing over the System for ownership
typeThe serial/parallel/ghosted type of the matrix

Definition at line 1041 of file system.C.

References libMesh::System::_matrices, libMesh::System::_matrix_types, libMesh::ParallelObject::comm(), libMesh::System::late_matrix_init(), and libMesh::libmesh_assert().

1044 {
1045  parallel_object_only();
1046 
1047  const std::string namestr{mat_name};
1048 
1049  libmesh_assert(this->comm().verify(namestr));
1050  libmesh_assert(this->comm().verify(int(type)));
1051 
1052  SparseMatrix<Number> & mat = *matrix;
1053 
1054  _matrices[namestr] = std::move(matrix);
1055  _matrix_types[namestr] = type;
1056 
1057  // Initialize it first if we've already initialized the others.
1058  this->late_matrix_init(mat, type);
1059 
1060  return mat;
1061 }
const Parallel::Communicator & comm() const
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277
libmesh_assert(ctx)
std::map< std::string, ParallelType, std::less<> > _matrix_types
Holds the types of the matrices.
Definition: system.h:2282
template class LIBMESH_EXPORT SparseMatrix< Number >
void late_matrix_init(SparseMatrix< Number > &mat, ParallelType type)
Helper function to keep DofMap forward declarable in system.h.
Definition: system.C:1063

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

183 {
184  const std::set<unsigned int> & second_order_vars = this->get_second_order_vars();
185  if (!second_order_vars.empty())
186  {
187  for (const auto & var_id : second_order_vars)
188  {
189  const Variable & var = this->variable(var_id);
190  std::string new_var_name = std::string("dot_")+var.name();
191 
192  unsigned int v_var_idx;
193 
194  if (var.active_subdomains().empty())
195  v_var_idx = this->add_variable( new_var_name, var.type() );
196  else
197  v_var_idx = this->add_variable( new_var_name, var.type(), &var.active_subdomains() );
198 
199  _second_order_dot_vars.insert(std::pair<unsigned int, unsigned int>(var_id, v_var_idx));
200 
201  // The new velocities are time evolving variables of first order
202  this->time_evolving( v_var_idx, 1 );
203 
204 #ifdef LIBMESH_ENABLE_DIRICHLET
205  // And if there are any boundary conditions set on the second order
206  // variable, we also need to set it on its velocity variable.
207  this->add_dot_var_dirichlet_bcs(var_id, v_var_idx);
208 #endif
209  }
210  }
211 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
void add_dot_var_dirichlet_bcs(unsigned int var_idx, unsigned int dot_var_idx)
Helper function to and Dirichlet boundary conditions to "dot" variable cousins of second order variab...
Definition: diff_system.C:214
virtual void time_evolving(unsigned int var, unsigned int order)
Tells the DiffSystem that variable var is evolving with respect to time.
Definition: diff_physics.C:42
std::map< unsigned int, unsigned int > _second_order_dot_vars
If the user adds any second order variables, then we need to also cache the map to their correspondin...
Definition: diff_physics.h:560
const std::set< unsigned int > & get_second_order_vars() const
Definition: diff_physics.h:519
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1344

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

References libMesh::System::add_vector().

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

1315 {
1316  std::ostringstream sensitivity_rhs_name;
1317  sensitivity_rhs_name << "sensitivity_rhs" << i;
1318 
1319  return this->add_vector(sensitivity_rhs_name.str(), false);
1320 }
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:756

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

References libMesh::System::add_vector().

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

1170 {
1171  std::ostringstream sensitivity_name;
1172  sensitivity_name << "sensitivity_solution" << i;
1173 
1174  return this->add_vector(sensitivity_name.str());
1175 }
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:756

◆ add_variable() [1/2]

unsigned int libMesh::System::add_variable ( std::string_view  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.

If active_subdomains is either nullptr (the default) or points to an empty set, then it will be assumed that var has no subdomain restrictions

Returns
The index number for the new variable.

Definition at line 1344 of file system.C.

References libMesh::DofMap::add_variable(), and libMesh::System::get_dof_map().

Referenced by libMesh::DifferentiableSystem::add_second_order_dot_vars(), libMesh::System::add_variable(), assemble_and_solve(), OverlappingTestBase::init(), SolidSystem::init_data(), CurlCurlSystem::init_data(), SimpleEIMConstruction::init_data(), libMesh::AdvectionSystem::init_data(), HeatSystem::init_data(), SimpleRBConstruction::init_data(), libMesh::VariationalSmootherSystem::init_data(), NonManifoldCouplingTestBase::init_es(), main(), libMesh::ErrorVector::plot_error(), libMesh::System::read_header(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), libMesh::PetscPreconditioner< T >::set_hypre_ams_data(), RationalMapTest< elem_type >::setUp(), SlitMeshRefinedSystemTest::setUp(), FETestBase< order, family, elem_type, N_x >::setUp(), WriteVecAndScalar::setupTests(), SystemsTest::simpleSetup(), MultiEvaluablePredTest::test(), ConstraintOperatorTest::test1DCoarseningNewNodes(), ConstraintOperatorTest::test1DCoarseningOperator(), MeshFunctionTest::test_bad_gradient_var_with_out_of_mesh_value(), MeshFunctionTest::test_bad_hessian_var_with_out_of_mesh_value(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), ProjectSolutionTest::test_partial_project_solution(), MeshFunctionTest::test_subdomain_id_sets(), SystemsTest::testAssemblyWithDgFemContext(), DofMapTest::testBadElemFECombo(), EquationSystemsTest::testBadVarNames(), SystemsTest::testBlockRestrictedVarNDofs(), SystemsTest::testBoundaryProjectCube(), DofMapTest::testConstraintLoopDetection(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyElementVectorImpl(), MeshInputTest::testCopyNodalSolutionImpl(), ConstraintOperatorTest::testCoreform(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), SystemsTest::testDofCouplingWithVarGroups(), DofMapTest::testDofOwner(), MeshInputTest::testDynaReadPatch(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), SystemsTest::testFirstScalarNumber(), MeshAssignTest::testMeshMoveAssign(), PeriodicBCTest::testPeriodicBC(), EquationSystemsTest::testPostInitAddElem(), EquationSystemsTest::testPostInitAddRealSystem(), SystemsTest::testProjectCubeWithMeshFunction(), MeshInputTest::testProjectionRegression(), SystemsTest::testProjectMatrix1D(), SystemsTest::testProjectMatrix2D(), SystemsTest::testProjectMatrix3D(), InfFERadialTest::testRefinement(), EquationSystemsTest::testRefineThenReinitPreserveFlags(), EquationSystemsTest::testReinitWithNodeElem(), EquationSystemsTest::testRepartitionThenReinit(), EquationSystemsTest::testSelectivePRefine(), SystemsTest::testSetSystemParameterOverEquationSystem(), BoundaryInfoTest::testShellFaceConstraints(), MeshInputTest::testSingleElementImpl(), DisjointNeighborTest::testTempJump(), DisjointNeighborTest::testTempJumpRefine(), WriteVecAndScalar::testWriteExodus(), and WriteVecAndScalar::testWriteNemesis().

1347 {
1348  return this->get_dof_map().add_variable(*this, var, type, active_subdomains);
1349 }
unsigned int add_variable(System &sys, std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: dof_map.C:3137
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ add_variable() [2/2]

unsigned int libMesh::System::add_variable ( std::string_view  var,
const Order  order = FIRST,
const FEFamily  family = LAGRANGE,
const std::set< subdomain_id_type > *const  active_subdomains = nullptr,
const bool  p_refinement = true 
)
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. If active_subdomains is either nullptr (the default) or points to an empty set, then it will be assumed that var has no subdomain restrictions. If p_refinement is false, then even when on an Elem with non-zero p_level() this variable will not be p-refined.

Definition at line 1353 of file system.C.

References libMesh::System::add_variable().

1358 {
1359  return this->add_variable(var,
1360  FEType(order, family).set_p_refinement(p_refinement),
1361  active_subdomains);
1362 }
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1344

◆ add_variable_array()

unsigned int libMesh::System::add_variable_array ( const std::vector< std::string > &  vars,
const FEType type,
const std::set< subdomain_id_type > *const  active_subdomains = nullptr 
)
inherited

Adds variables vars to the list of variables for this system.

If active_subdomains is either nullptr (the default) or points to an empty set, then it will be assumed that the vars have no subdomain restrictions. This API will end up calling this->add_variables(). However, we will additionally store data that can be leveraged by the DofMap to build degrees of freedom containers corresponding to all the variables in this variable array

An 'array variable' is simply a sequence of contiguous variable numbers defined by pair where the first member of the pair is the first number in the variable sequence and the second member of the pair is the number of the last variable in the sequence plus one. Array variables may be used in tandem with variable grouping by downstream code to build optimized physics kernels since each variable in the array will have the same shape functions.

Returns
The index number for the last of the new variables.

Definition at line 1386 of file system.C.

References libMesh::DofMap::add_variable_array(), and libMesh::System::get_dof_map().

Referenced by DofMapTest::testArrayDofIndicesWithType().

1389 {
1390  return this->get_dof_map().add_variable_array(*this, vars, type, active_subdomains);
1391 }
unsigned int add_variable_array(System &sys, const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds variables vars to the list of variables for this system.
Definition: dof_map.C:3368
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ 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 variables vars to the list of variables for this system.

If active_subdomains is either nullptr (the default) or points to an empty set, then it will be assumed that the vars have no subdomain restrictions

Returns
The index number for the last of the new variables.

Definition at line 1366 of file system.C.

References libMesh::DofMap::add_variables(), and libMesh::System::get_dof_map().

Referenced by libMesh::System::add_variables(), and SystemsTest::test100KVariables().

1369 {
1370  return this->get_dof_map().add_variables(*this, vars, type, active_subdomains);
1371 }
unsigned int add_variables(System &sys, const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variables vars to the list of variables for this system.
Definition: dof_map.C:3244
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ 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,
const bool  p_refinement = true 
)
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. If active_subdomains is either nullptr (the default) or points to an empty set, then it will be assumed that var has no subdomain restrictions. If p_refinement is false, then even when on an Elem with non-zero p_level() this variable will not be p-refined.

Definition at line 1375 of file system.C.

References libMesh::System::add_variables().

1380 {
1381  return this->add_variables(vars,
1382  FEType(order, family).set_p_refinement(p_refinement),
1383  active_subdomains);
1384 }
unsigned int add_variables(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variables vars to the list of variables for this system.
Definition: system.C:1366

◆ add_vector()

NumericVector< Number > & libMesh::System::add_vector ( std::string_view  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

If the vector already exists, the existing vector is returned. after any upgrade to the projections or type has been made. We only handle upgrades (projections false->true, or type PARALLEL->GHOSTED) in this fashion, not downgrades, on the theory that if two codes have differing needs we want to support the union of those needs, not the intersection. Downgrades can only be accomplished manually, via set_vector_preservation() or by setting a vector type() and re-initializing.

Definition at line 756 of file system.C.

References libMesh::System::_dof_map, libMesh::System::_is_initialized, libMesh::System::_vector_is_adjoint, libMesh::System::_vector_projections, libMesh::System::_vectors, libMesh::NumericVector< T >::build(), libMesh::NumericVector< T >::close(), libMesh::NumericVector< T >::closed(), libMesh::ParallelObject::comm(), libMesh::default_solver_package(), libMesh::GHOSTED, libMesh::NumericVector< T >::initialized(), libMesh::libmesh_assert(), libMesh::System::n_dofs(), libMesh::System::n_local_dofs(), libMesh::ParallelObject::n_processors(), libMesh::PARALLEL, libMesh::SERIAL, libMesh::NumericVector< T >::set_type(), libMesh::NumericVector< T >::swap(), and libMesh::NumericVector< T >::type().

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(), alternative_fe_assembly(), libMesh::AdjointRefinementEstimator::estimate_error(), fe_assembly(), form_functionA(), form_functionB(), libMesh::SecondOrderUnsteadySolver::init(), libMesh::UnsteadySolver::init(), libMesh::UnsteadySolver::init_adjoints(), libMesh::TimeSolver::init_adjoints(), libMesh::OptimizationSystem::init_data(), libMesh::ContinuationSystem::init_data(), main(), libMesh::NewmarkSystem::NewmarkSystem(), libMesh::System::read_header(), libMesh::FrequencySystem::set_frequencies(), libMesh::FrequencySystem::set_frequencies_by_range(), libMesh::FrequencySystem::set_frequencies_by_steps(), SystemsTest::testAddVectorProjChange(), SystemsTest::testAddVectorTypeChange(), SystemsTest::testPostInitAddVector(), and SystemsTest::testPostInitAddVectorTypeChange().

759 {
760  parallel_object_only();
761 
762  libmesh_assert(this->comm().verify(std::string(vec_name)));
763  libmesh_assert(this->comm().verify(int(type)));
764  libmesh_assert(this->comm().verify(projections));
765 
766  // Return the vector if it is already there.
767  if (auto it = this->_vectors.find(vec_name);
768  it != this->_vectors.end())
769  {
770  // If the projection setting has *upgraded*, change it.
771  if (projections) // only do expensive lookup if needed
772  libmesh_map_find(_vector_projections, vec_name) = projections;
773 
774  NumericVector<Number> & vec = *it->second;
775 
776  // If we're in serial, our vectors are effectively SERIAL, so
777  // we'll ignore any type setting. If we're in parallel, we
778  // might have a type change to deal with.
779 
780  if (this->n_processors() > 1)
781  {
782  // If the type setting has changed in a way we can't
783  // perceive as an upgrade or a downgrade, scream.
784  libmesh_assert_equal_to(type == SERIAL,
785  vec.type() == SERIAL);
786 
787  // If the type setting has *upgraded*, change it.
788  if (type == GHOSTED && vec.type() == PARALLEL)
789  {
790  // A *really* late upgrade is expensive, but better not
791  // to risk zeroing data.
792  if (vec.initialized())
793  {
794  if (!vec.closed())
795  vec.close();
796 
797  // Ideally we'd move parallel coefficients and then
798  // add ghosted coefficients, but copy and swap is
799  // simpler. If anyone actually ever uses this case
800  // for real we can look into optimizing it.
801  auto new_vec = NumericVector<Number>::build(this->comm());
802 #ifdef LIBMESH_ENABLE_GHOSTED
803  new_vec->init (this->n_dofs(), this->n_local_dofs(),
804  _dof_map->get_send_list(), /*fast=*/false,
805  GHOSTED);
806 #else
807  libmesh_error_msg("Cannot initialize ghosted vectors when they are not enabled.");
808 #endif
809 
810  *new_vec = vec;
811  vec.swap(*new_vec);
812  }
813  else
814  // The PARALLEL vec is not yet initialized, so we can
815  // just "upgrade" it to GHOSTED.
816  vec.set_type(type);
817  }
818  }
819 
820  // Any upgrades are done; we're happy here.
821  return vec;
822  }
823 
824  // Otherwise, build the vector. The following emplace() is
825  // guaranteed to succeed because, if we made it here, we don't
826  // already have a vector named "vec_name". We pass the user's
827  // requested ParallelType directly to NumericVector::build() so
828  // that, even if the vector is not initialized now, it will get the
829  // right type when it is initialized later.
830  auto pr =
831  _vectors.emplace(vec_name,
834  type));
835  auto buf = pr.first->second.get();
836  _vector_projections.emplace(vec_name, projections);
837 
838  // Vectors are primal by default
839  _vector_is_adjoint.emplace(vec_name, -1);
840 
841  // Initialize it if necessary
842  if (_is_initialized)
843  {
844  if (type == GHOSTED)
845  {
846 #ifdef LIBMESH_ENABLE_GHOSTED
847  buf->init (this->n_dofs(), this->n_local_dofs(),
848  _dof_map->get_send_list(), /*fast=*/false,
849  GHOSTED);
850 #else
851  libmesh_error_msg("Cannot initialize ghosted vectors when they are not enabled.");
852 #endif
853  }
854  else
855  buf->init (this->n_dofs(), this->n_local_dofs(), false, type);
856  }
857 
858  return *buf;
859 }
bool _is_initialized
true when additional vectors and variables do not require immediate initialization, false otherwise.
Definition: system.h:2306
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225
const Parallel::Communicator & comm() const
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
dof_id_type n_local_dofs() const
Definition: system.C:155
dof_id_type n_dofs() const
Definition: system.C:118
SolverPackage default_solver_package()
Definition: libmesh.C:1051
processor_id_type n_processors() const
std::map< std::string, int, std::less<> > _vector_is_adjoint
Holds non-negative if a vector by that name should be projected using adjoint constraints/BCs, -1 if primal.
Definition: system.h:2272
libmesh_assert(ctx)
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
template class LIBMESH_EXPORT NumericVector< Number >
std::map< std::string, bool, std::less<> > _vector_projections
Holds true if a vector by that name should be projected onto a changed grid, false if it should be ze...
Definition: system.h:2266

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

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

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

1253 {
1254  std::ostringstream adjoint_name;
1255  adjoint_name << "weighted_sensitivity_adjoint_solution" << i;
1256 
1257  NumericVector<Number> & returnval = this->add_vector(adjoint_name.str());
1258  this->set_vector_as_adjoint(adjoint_name.str(), i);
1259  return returnval;
1260 }
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Allows one to set the QoI index controlling whether the vector identified by vec_name represents a so...
Definition: system.C:1147
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:756
template class LIBMESH_EXPORT NumericVector< Number >

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

References libMesh::System::add_vector().

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

1200 {
1201  return this->add_vector("weighted_sensitivity_solution");
1202 }
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:756

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

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

Referenced by libMesh::UnsteadySolver::integrate_adjoint_sensitivity(), and main().

520 {
521  ParameterVector & parameters_vec =
522  const_cast<ParameterVector &>(parameters_in);
523 
524  const unsigned int Np = cast_int<unsigned int>
525  (parameters_vec.size());
526  const unsigned int Nq = this->n_qois();
527 
528  // An introduction to the problem:
529  //
530  // Residual R(u(p),p) = 0
531  // partial R / partial u = J = system matrix
532  //
533  // This implies that:
534  // d/dp(R) = 0
535  // (partial R / partial p) +
536  // (partial R / partial u) * (partial u / partial p) = 0
537 
538  // We first do an adjoint solve:
539  // J^T * z = (partial q / partial u)
540  // if we haven't already or dont have an initial condition for the adjoint
541  if (!this->is_adjoint_already_solved())
542  {
543  this->adjoint_solve(qoi_indices);
544  }
545 
546  this->assemble_residual_derivatives(parameters_in);
547 
548  // Get ready to fill in sensitivities:
549  sensitivities.allocate_data(qoi_indices, *this, parameters_vec);
550 
551  // We use the identities:
552  // dq/dp = (partial q / partial p) + (partial q / partial u) *
553  // (partial u / partial p)
554  // dq/dp = (partial q / partial p) + (J^T * z) *
555  // (partial u / partial p)
556  // dq/dp = (partial q / partial p) + z * J *
557  // (partial u / partial p)
558 
559  // Leading to our final formula:
560  // dq/dp = (partial q / partial p) - z * (partial R / partial p)
561 
562  // In the case of adjoints with heterogenous Dirichlet boundary
563  // function phi, where
564  // q := S(u) - R(u,phi)
565  // the final formula works out to:
566  // dq/dp = (partial S / partial p) - z * (partial R / partial p)
567  // Because we currently have no direct access to
568  // (partial S / partial p), we use the identity
569  // (partial S / partial p) = (partial q / partial p) +
570  // phi * (partial R / partial p)
571  // to derive an equivalent equation:
572  // dq/dp = (partial q / partial p) - (z-phi) * (partial R / partial p)
573 
574  // Since z-phi degrees of freedom are zero for constrained indices,
575  // we can use the same constrained -(partial R / partial p) that we
576  // use for forward sensitivity solves, taking into account the
577  // differing sign convention.
578  //
579  // Since that vector is constrained, its constrained indices are
580  // zero, so its product with phi is zero, so we can neglect the
581  // evaluation of phi terms.
582 
583  for (unsigned int j=0; j != Np; ++j)
584  {
585  // We currently get partial derivatives via central differencing
586 
587  // (partial q / partial p) ~= (q(p+dp)-q(p-dp))/(2*dp)
588  // (partial R / partial p) ~= (rhs(p+dp) - rhs(p-dp))/(2*dp)
589 
590  Number old_parameter = *parameters_vec[j];
591 
592  const Real delta_p =
593  TOLERANCE * std::max(std::abs(old_parameter), 1e-3);
594 
595  *parameters_vec[j] = old_parameter - delta_p;
596  this->assemble_qoi(qoi_indices);
597  const std::vector<Number> qoi_minus = this->get_qoi_values();
598 
599  NumericVector<Number> & neg_partialR_partialp = this->get_sensitivity_rhs(j);
600 
601  *parameters_vec[j] = old_parameter + delta_p;
602  this->assemble_qoi(qoi_indices);
603  const std::vector<Number> qoi_plus = this->get_qoi_values();
604 
605  std::vector<Number> partialq_partialp(Nq, 0);
606  for (unsigned int i=0; i != Nq; ++i)
607  if (qoi_indices.has_index(i))
608  partialq_partialp[i] = (qoi_plus[i] - qoi_minus[i]) / (2.*delta_p);
609 
610  // Don't leave the parameter changed
611  *parameters_vec[j] = old_parameter;
612 
613  for (unsigned int i=0; i != Nq; ++i)
614  if (qoi_indices.has_index(i))
615  sensitivities[i][j] = partialq_partialp[i] +
616  neg_partialR_partialp.dot(this->get_adjoint_solution(i));
617  }
618 
619  // All parameters_vec have been reset.
620  // Reset the original qoi.
621 
622  this->assemble_qoi(qoi_indices);
623 }
static constexpr Real TOLERANCE
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
NumericVector< Number > & get_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1324
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) override
Assembles & solves the linear system (dR/du)^T*z = dq/du, for those quantities of interest q specifie...
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Definition: system.h:411
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) override
Prepares qoi for quantity of interest assembly, then calls user qoi function.
virtual void assemble_residual_derivatives(const ParameterVector &parameters) override
Residual parameter derivative function.
template class LIBMESH_EXPORT NumericVector< Number >
std::vector< Number > get_qoi_values() const
Returns a copy of qoi, not a reference.
Definition: system.C:2186

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

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

Referenced by main().

151 {
152  // Get the time solver object associated with the system, and tell it that
153  // we are solving the adjoint problem
154  this->get_time_solver().set_is_adjoint(true);
155 
156  return time_solver->adjoint_solve(qoi_indices);
157 
158  //return this->ImplicitSystem::adjoint_solve(qoi_indices);
159 }
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
void set_is_adjoint(bool _is_adjoint_value)
Accessor for setting whether we need to do a primal or adjoint solve.
Definition: time_solver.h:284
TimeSolver & get_time_solver()
Definition: diff_system.h:448

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

References libMesh::DifferentiableSystem::assembly().

132 {
133  this->assembly(true, true);
134 }
virtual void assembly(bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) override=0
Assembles a residual in rhs and/or a jacobian in matrix, as requested.

◆ assemble_qoi()

void 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 1147 of file fem_system.C.

References libMesh::ParallelObject::comm(), libMesh::System::get_mesh(), libMesh::DifferentiableSystem::get_qoi(), libMesh::System::get_qoi_values(), libMesh::QoISet::has_index(), mesh, libMesh::System::n_qois(), libMesh::DifferentiableQoI::parallel_op(), libMesh::Threads::parallel_reduce(), libMesh::StoredRange< iterator_type, object_type >::reset(), libMesh::System::set_qoi(), and libMesh::System::update().

1148 {
1149  LOG_SCOPE("assemble_qoi()", "FEMSystem");
1150 
1151  const MeshBase & mesh = this->get_mesh();
1152 
1153  this->update();
1154 
1155  const unsigned int Nq = this->n_qois();
1156 
1157  // the quantity of interest is assumed to be a sum of element and
1158  // side terms
1159  for (unsigned int i=0; i != Nq; ++i)
1160  if (qoi_indices.has_index(i))
1161  this->set_qoi(i, 0);
1162 
1163  // Create a non-temporary qoi_contributions object, so we can query
1164  // its results after the reduction
1165  QoIContributions qoi_contributions(*this, *(this->get_qoi()), qoi_indices);
1166 
1167  // Loop over every active mesh element on this processor
1168  Threads::parallel_reduce(elem_range.reset(mesh.active_local_elements_begin(),
1169  mesh.active_local_elements_end()),
1170  qoi_contributions);
1171 
1172  std::vector<Number> global_qoi = this->get_qoi_values();
1173  this->get_qoi()->parallel_op( this->comm(), global_qoi, qoi_contributions.qoi, qoi_indices );
1174  this->set_qoi(std::move(global_qoi));
1175 }
const DifferentiableQoI * get_qoi() const
Definition: diff_system.h:221
virtual void parallel_op(const Parallel::Communicator &communicator, std::vector< Number > &sys_qoi, std::vector< Number > &local_qoi, const QoISet &qoi_indices)
Method to populate system qoi data structure with process-local qoi.
Definition: diff_qoi.C:41
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
MeshBase & mesh
const Parallel::Communicator & comm() const
const MeshBase & get_mesh() const
Definition: system.h:2401
This is the MeshBase class.
Definition: mesh_base.h:85
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided reduction operation in parallel on the specified range.
Definition: threads_none.h:109
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:498
void set_qoi(unsigned int qoi_index, Number qoi_value)
Definition: system.C:2171
std::vector< Number > get_qoi_values() const
Returns a copy of qoi, not a reference.
Definition: system.C:2186

◆ assemble_qoi_derivative()

void 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 1179 of file fem_system.C.

References libMesh::System::add_adjoint_rhs(), libMesh::DifferentiableQoI::finalize_derivative(), libMesh::System::get_adjoint_rhs(), libMesh::System::get_mesh(), libMesh::DifferentiableSystem::get_qoi(), libMesh::QoISet::has_index(), libMesh::make_range(), mesh, libMesh::System::n_qois(), libMesh::Threads::parallel_for(), libMesh::StoredRange< iterator_type, object_type >::reset(), libMesh::System::update(), and libMesh::NumericVector< T >::zero().

1182 {
1183  LOG_SCOPE("assemble_qoi_derivative()", "FEMSystem");
1184 
1185  const MeshBase & mesh = this->get_mesh();
1186 
1187  this->update();
1188 
1189  // The quantity of interest derivative assembly accumulates on
1190  // initially zero vectors
1191  for (auto i : make_range(this->n_qois()))
1192  if (qoi_indices.has_index(i))
1193  this->add_adjoint_rhs(i).zero();
1194 
1195  // Loop over every active mesh element on this processor
1196  Threads::parallel_for (elem_range.reset(mesh.active_local_elements_begin(),
1197  mesh.active_local_elements_end()),
1198  QoIDerivativeContributions(*this, qoi_indices,
1199  *(this->get_qoi()),
1200  include_liftfunc,
1201  apply_constraints));
1202 
1203  for (auto i : make_range(this->n_qois()))
1204  if (qoi_indices.has_index(i))
1205  this->get_qoi()->finalize_derivative(this->get_adjoint_rhs(i),i);
1206 }
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
Definition: threads_none.h:73
const DifferentiableQoI * get_qoi() const
Definition: diff_system.h:221
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
MeshBase & mesh
const MeshBase & get_mesh() const
Definition: system.h:2401
This is the MeshBase class.
Definition: mesh_base.h:85
virtual void zero()=0
Set all entries to zero.
bool has_index(std::size_t) const
Return whether or not this index is in the set to be calculated.
Definition: qoi_set.h:224
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1284
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:498
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
virtual void finalize_derivative(NumericVector< Number > &derivatives, std::size_t qoi_index)
Method to finalize qoi derivatives which require more than just a simple sum of element contributions...
Definition: diff_qoi.C:53
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1294

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

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

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

475 {
476  ParameterVector & parameters_vec =
477  const_cast<ParameterVector &>(parameters_in);
478 
479  const unsigned int Np = cast_int<unsigned int>
480  (parameters_vec.size());
481 
482  for (unsigned int p=0; p != Np; ++p)
483  {
484  NumericVector<Number> & sensitivity_rhs = this->add_sensitivity_rhs(p);
485 
486  // Approximate -(partial R / partial p) by
487  // (R(p-dp) - R(p+dp)) / (2*dp)
488 
489  Number old_parameter = *parameters_vec[p];
490 
491  const Real delta_p =
492  TOLERANCE * std::max(std::abs(old_parameter), 1e-3);
493 
494  *parameters_vec[p] -= delta_p;
495 
496  // this->assembly(true, false, true);
497  this->assembly(true, false, false);
498  this->rhs->close();
499  sensitivity_rhs = *this->rhs;
500 
501  *parameters_vec[p] = old_parameter + delta_p;
502 
503  // this->assembly(true, false, true);
504  this->assembly(true, false, false);
505  this->rhs->close();
506 
507  sensitivity_rhs -= *this->rhs;
508  sensitivity_rhs /= (2*delta_p);
509  sensitivity_rhs.close();
510 
511  *parameters_vec[p] = old_parameter;
512  }
513 }
static constexpr Real TOLERANCE
NumericVector< Number > * rhs
The system matrix.
NumericVector< Number > & add_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1314
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
template class LIBMESH_EXPORT NumericVector< Number >

◆ assembly()

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

Reimplemented in libMesh::VariationalSmootherSystem.

Definition at line 880 of file fem_system.C.

References libMesh::DenseMatrix< T >::add(), libMesh::FEMSystem::build_context(), libMesh::NumericVector< T >::close(), libMesh::SparseMatrix< T >::close(), libMesh::err, libMesh::FEType::family, libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::System::get_mesh(), libMesh::FEMSystem::init_context(), libMesh::NumericVector< T >::l1_norm(), libMesh::DenseMatrix< T >::l1_norm(), libMesh::SparseMatrix< T >::l1_norm(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::ImplicitSystem::matrix, 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 libMesh::VariationalSmootherSystem::assembly(), libMesh::ContinuationSystem::continuation_solve(), HeatSystem::perturb_accumulate_residuals(), and libMesh::ContinuationSystem::solve_tangent().

883 {
884  libmesh_assert(get_residual || get_jacobian);
885 
886  // Log residual and jacobian and combined performance separately
887 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
888  const char * log_name;
889  if (get_residual && get_jacobian)
890  log_name = "assembly()";
891  else if (get_residual)
892  log_name = "assembly(get_residual)";
893  else
894  log_name = "assembly(get_jacobian)";
895 
896  LOG_SCOPE(log_name, "FEMSystem");
897 #endif
898 
899  const MeshBase & mesh = this->get_mesh();
900 
902  {
903  this->solution->close();
904 
905  std::streamsize old_precision = libMesh::out.precision();
907  libMesh::out << "|U| = "
908  << this->solution->l1_norm()
909  << std::endl;
910  libMesh::out.precision(old_precision);
911  }
912  if (print_solutions)
913  {
914  std::streamsize old_precision = libMesh::out.precision();
916  libMesh::out << "U = [" << *(this->solution)
917  << "];" << std::endl;
918  libMesh::out.precision(old_precision);
919  }
920 
921  // Is this definitely necessary? [RHS]
922  // Yes. [RHS 2012]
923  if (get_jacobian)
924  matrix->zero();
925  if (get_residual)
926  rhs->zero();
927 
928  // Stupid C++ lets you set *Real* verify_analytic_jacobians = true!
929  if (verify_analytic_jacobians > 0.5)
930  {
931  libMesh::err << "WARNING! verify_analytic_jacobians was set "
932  << "to absurdly large value of "
933  << verify_analytic_jacobians << std::endl;
934  libMesh::err << "Resetting to 1e-6!" << std::endl;
936  }
937 
938  // In time-dependent problems, the nonlinear function we're trying
939  // to solve at each timestep may depend on the particular solver
940  // we're using
942 
943  // Build the residual and jacobian contributions on every active
944  // mesh element on this processor
946  (elem_range.reset(mesh.active_local_elements_begin(),
947  mesh.active_local_elements_end()),
948  AssemblyContributions(*this, get_residual, get_jacobian,
949  apply_heterogeneous_constraints,
950  apply_no_constraints));
951 
952  // Check and see if we have SCALAR variables
953  bool have_scalar = false;
954  for (auto i : make_range(this->n_variable_groups()))
955  {
956  if (this->variable_group(i).type().family == SCALAR)
957  {
958  have_scalar = true;
959  break;
960  }
961  }
962 
963  // SCALAR dofs are stored on the last processor, so we'll evaluate
964  // their equation terms there and only if we have a SCALAR variable
965  if (this->processor_id() == (this->n_processors()-1) && have_scalar)
966  {
967  std::unique_ptr<DiffContext> con = this->build_context();
968  FEMContext & _femcontext = cast_ref<FEMContext &>(*con);
969  this->init_context(_femcontext);
970  _femcontext.pre_fe_reinit(*this, nullptr);
971 
972  bool jacobian_computed =
973  this->time_solver->nonlocal_residual(get_jacobian, _femcontext);
974 
975  // Nonlocal residuals are likely to be length 0, in which case we
976  // don't need to do any more. And we shouldn't try to do any
977  // more; lots of DenseVector/DenseMatrix code assumes rank>0.
978  if (_femcontext.get_elem_residual().size())
979  {
980  // Compute a numeric jacobian if we have to
981  if (get_jacobian && !jacobian_computed)
982  {
983  // Make sure we didn't compute a jacobian and lie about it
984  libmesh_assert_equal_to (_femcontext.get_elem_jacobian().l1_norm(), 0.0);
985  // Logging of numerical jacobians is done separately
986  this->numerical_nonlocal_jacobian(_femcontext);
987  }
988 
989  // Compute a numeric jacobian if we're asked to verify the
990  // analytic jacobian we got
991  if (get_jacobian && jacobian_computed &&
992  this->verify_analytic_jacobians != 0.0)
993  {
994  DenseMatrix<Number> analytic_jacobian(_femcontext.get_elem_jacobian());
995 
996  _femcontext.get_elem_jacobian().zero();
997  // Logging of numerical jacobians is done separately
998  this->numerical_nonlocal_jacobian(_femcontext);
999 
1000  Real analytic_norm = analytic_jacobian.l1_norm();
1001  Real numerical_norm = _femcontext.get_elem_jacobian().l1_norm();
1002 
1003  // If we can continue, we'll probably prefer the analytic jacobian
1004  analytic_jacobian.swap(_femcontext.get_elem_jacobian());
1005 
1006  // The matrix "analytic_jacobian" will now hold the error matrix
1007  analytic_jacobian.add(-1.0, _femcontext.get_elem_jacobian());
1008  Real error_norm = analytic_jacobian.l1_norm();
1009 
1010  Real relative_error = error_norm /
1011  std::max(analytic_norm, numerical_norm);
1012 
1013  if (relative_error > this->verify_analytic_jacobians)
1014  {
1015  libMesh::err << "Relative error " << relative_error
1016  << " detected in analytic jacobian on nonlocal dofs!"
1017  << std::endl;
1018 
1019  std::streamsize old_precision = libMesh::out.precision();
1020  libMesh::out.precision(16);
1021  libMesh::out << "J_analytic nonlocal = "
1022  << _femcontext.get_elem_jacobian() << std::endl;
1023  analytic_jacobian.add(1.0, _femcontext.get_elem_jacobian());
1024  libMesh::out << "J_numeric nonlocal = "
1025  << analytic_jacobian << std::endl;
1026 
1027  libMesh::out.precision(old_precision);
1028 
1029  libmesh_error_msg("Relative error too large, exiting!");
1030  }
1031  }
1032 
1033  add_element_system
1034  (*this, get_residual, get_jacobian,
1035  apply_heterogeneous_constraints, apply_no_constraints, _femcontext);
1036  }
1037  }
1038 
1039  if (get_residual && (print_residual_norms || print_residuals))
1040  this->rhs->close();
1041  if (get_residual && print_residual_norms)
1042  {
1043  std::streamsize old_precision = libMesh::out.precision();
1044  libMesh::out.precision(16);
1045  libMesh::out << "|F| = " << this->rhs->l1_norm() << std::endl;
1046  libMesh::out.precision(old_precision);
1047  }
1048  if (get_residual && print_residuals)
1049  {
1050  std::streamsize old_precision = libMesh::out.precision();
1051  libMesh::out.precision(16);
1052  libMesh::out << "F = [" << *(this->rhs) << "];" << std::endl;
1053  libMesh::out.precision(old_precision);
1054  }
1055 
1056  if (get_jacobian && (print_jacobian_norms || print_jacobians))
1057  this->matrix->close();
1058  if (get_jacobian && print_jacobian_norms)
1059  {
1060  std::streamsize old_precision = libMesh::out.precision();
1061  libMesh::out.precision(16);
1062  libMesh::out << "|J| = " << this->matrix->l1_norm() << std::endl;
1063  libMesh::out.precision(old_precision);
1064  }
1065  if (get_jacobian && print_jacobians)
1066  {
1067  std::streamsize old_precision = libMesh::out.precision();
1068  libMesh::out.precision(16);
1069  libMesh::out << "J = [" << *(this->matrix) << "];" << std::endl;
1070  libMesh::out.precision(old_precision);
1071  }
1072 }
OStreamProxy err
FEFamily family
The type of finite element.
Definition: fe_type.h:228
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
Definition: threads_none.h:73
virtual std::unique_ptr< DiffContext > build_context() override
Builds a FEMContext object with enough information to do evaluations on each element.
Definition: fem_system.C:1346
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:274
Real verify_analytic_jacobians
If verify_analytic_jacobian is equal to zero (as it is by default), no numeric jacobians will be calc...
Definition: fem_system.h:215
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
Definition: fem_context.C:1683
std::streamsize precision() const
Get the associated write precision.
virtual void zero() override final
Sets all elements of the matrix to 0 and resets any decomposition flag which may have been previously...
Definition: dense_matrix.h:911
bool print_jacobian_norms
Set print_jacobian_norms to true to print |J| whenever it is assembled.
Definition: diff_system.h:353
virtual void init_context(DiffContext &) override
Definition: fem_system.C:1370
unsigned int n_variable_groups() const
Definition: system.C:2694
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
MeshBase & mesh
NumericVector< Number > * rhs
The system matrix.
bool print_jacobians
Set print_jacobians to true to print J whenever it is assembled.
Definition: diff_system.h:358
const MeshBase & get_mesh() const
Definition: system.h:2401
This is the MeshBase class.
Definition: mesh_base.h:85
virtual void zero()=0
Set all entries to zero.
bool print_solution_norms
Set print_residual_norms to true to print |U| whenever it is used in an assembly() call...
Definition: diff_system.h:332
processor_id_type n_processors() const
virtual void zero()=0
Set all entries to 0.
bool print_residual_norms
Set print_residual_norms to true to print |F| whenever it is assembled.
Definition: diff_system.h:343
void numerical_nonlocal_jacobian(FEMContext &context) const
Uses the results of multiple side_residual() calls to numerically differentiate the corresponding jac...
Definition: fem_system.C:1338
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
bool print_residuals
Set print_residuals to true to print F whenever it is assembled.
Definition: diff_system.h:348
libmesh_assert(ctx)
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
virtual Real l1_norm() const =0
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
bool print_solutions
Set print_solutions to true to print U whenever it is used in an assembly() call. ...
Definition: diff_system.h:338
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:242
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
SparseMatrix< Number > * matrix
The system matrix.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
virtual unsigned int size() const override final
Definition: dense_vector.h:104
auto l1_norm() const
virtual Real l1_norm() const =0
processor_id_type processor_id() const
const VariableGroup & variable_group(unsigned int vg) const
Return a constant reference to VariableGroup vg.
Definition: system.C:2704
std::enable_if< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrix< T3 > &mat)
Adds factor times mat to this matrix.
const FEType & type() const
Definition: variable.h:144

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

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

Referenced by assemble_and_solve(), main(), ConstraintOperatorTest::test1DCoarseningNewNodes(), ConstraintOperatorTest::test1DCoarseningOperator(), SystemsTest::testAssemblyWithDgFemContext(), ConstraintOperatorTest::testCoreform(), SystemsTest::testDofCouplingWithVarGroups(), PeriodicBCTest::testPeriodicBC(), DisjointNeighborTest::testTempJump(), and DisjointNeighborTest::testTempJumpRefine().

1956 {
1958 
1959  if (_assemble_system_object != nullptr)
1960  {
1961  libmesh_warning("WARNING: Cannot specify both assembly function and object!");
1962 
1963  _assemble_system_object = nullptr;
1964  }
1965 
1967 }
Assembly * _assemble_system_object
Object that assembles the system.
Definition: system.h:2182
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
libmesh_assert(ctx)
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Function that assembles the system.
Definition: system.h:2176

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

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

Referenced by main().

1972 {
1973  if (_assemble_system_function != nullptr)
1974  {
1975  libmesh_warning("WARNING: Cannot specify both assembly object and function!");
1976 
1977  _assemble_system_function = nullptr;
1978  }
1979 
1980  _assemble_system_object = &assemble_in;
1981 }
Assembly * _assemble_system_object
Object that assembles the system.
Definition: system.h:2182
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Function that assembles the system.
Definition: system.h:2176

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

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

1987 {
1989 
1990  if (_constrain_system_object != nullptr)
1991  {
1992  libmesh_warning("WARNING: Cannot specify both constraint function and object!");
1993 
1994  _constrain_system_object = nullptr;
1995  }
1996 
1998 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition: system.h:2187
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:2193
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
libmesh_assert(ctx)

◆ attach_constraint_object()

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

Register a user object for imposing constraints.

Definition at line 2002 of file system.C.

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

Referenced by libMesh::VariationalMeshSmoother::setup(), and DofMapTest::testConstraintLoopDetection().

2003 {
2004  if (_constrain_system_function != nullptr)
2005  {
2006  libmesh_warning("WARNING: Cannot specify both constraint object and function!");
2007 
2008  _constrain_system_function = nullptr;
2009  }
2010 
2011  _constrain_system_object = &constrain;
2012 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition: system.h:2187
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:2193

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

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

Referenced by main().

1925 {
1927 
1928  if (_init_system_object != nullptr)
1929  {
1930  libmesh_warning("WARNING: Cannot specify both initialization function and object!");
1931 
1932  _init_system_object = nullptr;
1933  }
1934 
1936 }
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
libmesh_assert(ctx)
Initialization * _init_system_object
Object that initializes the system.
Definition: system.h:2171
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition: system.h:2165

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

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

1941 {
1942  if (_init_system_function != nullptr)
1943  {
1944  libmesh_warning("WARNING: Cannot specify both initialization object and function!");
1945 
1946  _init_system_function = nullptr;
1947  }
1948 
1949  _init_system_object = &init_in;
1950 }
Initialization * _init_system_object
Object that initializes the system.
Definition: system.h:2171
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition: system.h:2165

◆ attach_physics()

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

Attach external Physics object.

Definition at line 200 of file diff_system.h.

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

201  { this->_diff_physics.push(physics_in->clone_physics());
202  this->_diff_physics.top()->init_physics(*this);}
std::stack< std::unique_ptr< DifferentiablePhysics >, std::vector< std::unique_ptr< DifferentiablePhysics > > > _diff_physics
Stack of pointers to objects to use for physics assembly evaluations.
Definition: diff_system.h:434

◆ attach_qoi()

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

Attach external QoI object.

Definition at line 279 of file diff_system.C.

References libMesh::DifferentiableSystem::_diff_qoi, and libMesh::DifferentiableQoI::clone().

Referenced by main().

280 {
281  this->_diff_qoi = {};
282  this->_diff_qoi.push(qoi_in->clone());
283 
284  auto & dq = this->_diff_qoi.top();
285  dq->init_qoi_count( *this );
286 }
std::stack< std::unique_ptr< DifferentiableQoI >, std::vector< std::unique_ptr< DifferentiableQoI > > > _diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
Definition: diff_system.h:442

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

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

2061 {
2063 
2064  if (_qoi_evaluate_derivative_object != nullptr)
2065  {
2066  libmesh_warning("WARNING: Cannot specify both QOI derivative function and object!");
2067 
2069  }
2070 
2072 }
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition: system.h:2219
libmesh_assert(ctx)
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Function to evaluate quantity of interest derivative.
Definition: system.h:2210

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

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

2077 {
2078  if (_qoi_evaluate_derivative_function != nullptr)
2079  {
2080  libmesh_warning("WARNING: Cannot specify both QOI derivative object and function!");
2081 
2083  }
2084 
2085  _qoi_evaluate_derivative_object = &qoi_derivative;
2086 }
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition: system.h:2219
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Function to evaluate quantity of interest derivative.
Definition: system.h:2210

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

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

2030 {
2032 
2033  if (_qoi_evaluate_object != nullptr)
2034  {
2035  libmesh_warning("WARNING: Cannot specify both QOI function and object!");
2036 
2037  _qoi_evaluate_object = nullptr;
2038  }
2039 
2041 }
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition: system.h:2198
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
libmesh_assert(ctx)
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition: system.h:2205

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

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

2046 {
2047  if (_qoi_evaluate_function != nullptr)
2048  {
2049  libmesh_warning("WARNING: Cannot specify both QOI object and function!");
2050 
2051  _qoi_evaluate_function = nullptr;
2052  }
2053 
2054  _qoi_evaluate_object = &qoi_in;
2055 }
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition: system.h:2198
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition: system.h:2205

◆ 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,
std::optional< ConstElemRange active_local_range = std::nullopt 
)
inherited

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

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

Only degrees of freedom which affect the function's trace on a boundary in the set b are affected. Only degrees of freedom associated with the variables listed in the vector variables are projected. The function value f and its gradient g are user-provided cloneable functors. A gradient g is only required/used for projecting onto finite element spaces with continuous derivatives. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection.

Definition at line 1305 of file system_projection.C.

References b.

Referenced by SystemsTest::testBoundaryProjectCube().

1310 {
1311  this->boundary_project_vector(b, variables, *solution, f, g, -1 /*is_adjoint*/, active_local_range);
1312 
1313  solution->localize(*current_local_solution);
1314 }
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
static const Real b
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
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, std::optional< ConstElemRange > active_local_range=std::nullopt) const
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...

◆ 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,
std::optional< ConstElemRange active_local_range = std::nullopt 
)
inherited

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

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

Only degrees of freedom which affect the function's trace on a boundary in the set b are affected. Only degrees of freedom associated with the variables listed in the vector variables are projected. The function value 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. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection.

Definition at line 1286 of file system_projection.C.

References b, fptr(), and gptr().

1293 {
1294  WrappedFunction<Number> f(*this, fptr, &function_parameters);
1295  WrappedFunction<Gradient> g(*this, gptr, &function_parameters);
1296  this->boundary_project_solution(b, variables, &f, &g, active_local_range);
1297 }
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
void boundary_project_solution(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt)
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...
static const Real b
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:96

◆ 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,
std::optional< ConstElemRange active_local_range = std::nullopt 
) const
inherited

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

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

Only degrees of freedom which affect the function's trace on a boundary in the set b are affected. Only degrees of freedom associated with the variables listed in the vector variables are projected. The function value f and its gradient g are user-provided cloneable functors. A gradient g is only required/used for projecting onto finite element spaces with continuous derivatives. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection.

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

Definition at line 1343 of file system_projection.C.

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

1350 {
1351  LOG_SCOPE ("boundary_project_vector()", "System");
1352 
1353  if (!active_local_range)
1354  {
1355  active_local_range.emplace
1356  (this->get_mesh().active_local_elements_begin(),
1357  this->get_mesh().active_local_elements_end());
1358  }
1359 
1361  (active_local_range.value(),
1362  BoundaryProjectSolution(b, variables, *this, f, g,
1364  new_vector)
1365  );
1366 
1367  // We don't do SCALAR dofs when just projecting the boundary, so
1368  // we're done here.
1369 
1370  new_vector.close();
1371 
1372 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1373  if (is_adjoint == -1)
1374  this->get_dof_map().enforce_constraints_exactly(*this, &new_vector);
1375  else if (is_adjoint >= 0)
1377  is_adjoint);
1378 #else
1379  libmesh_ignore(is_adjoint);
1380 #endif
1381 }
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
Definition: threads_none.h:73
const EquationSystems & get_equation_systems() const
Definition: system.h:767
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
Definition: system.h:1588
const MeshBase & get_mesh() const
Definition: system.h:2401
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
Heterogeneously constrains the numeric vector v, which represents an adjoint solution defined on the ...
Definition: dof_map.h:2522
void libmesh_ignore(const Args &...)
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
static const Real b
const DofMap & get_dof_map() const
Definition: system.h:2417
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:2518

◆ 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,
std::optional< ConstElemRange active_local_range = std::nullopt 
) const
inherited

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

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

Only degrees of freedom which affect the function's trace on a boundary in the set b are affected. Only degrees of freedom associated with the variables listed in the vector variables are projected. The function value 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. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection.

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

Definition at line 1324 of file system_projection.C.

References b, fptr(), and gptr().

1332 {
1333  WrappedFunction<Number> f(*this, fptr, &function_parameters);
1334  WrappedFunction<Gradient> g(*this, gptr, &function_parameters);
1335  this->boundary_project_vector(b, variables, new_vector, &f, &g,
1336  is_adjoint, active_local_range);
1337 }
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
static const Real b
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:96
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, std::optional< ConstElemRange > active_local_range=std::nullopt) const
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...

◆ build_context()

std::unique_ptr< DiffContext > 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 1346 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(), and libMesh::libmesh_assert().

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

1347 {
1348  auto fc = std::make_unique<FEMContext>(*this);
1349 
1350  DifferentiablePhysics * phys = this->get_physics();
1351 
1352  libmesh_assert (phys);
1353 
1354  // If we are solving a moving mesh problem, tell that to the Context
1355  fc->set_mesh_system(phys->get_mesh_system());
1356  fc->set_mesh_x_var(phys->get_mesh_x_var());
1357  fc->set_mesh_y_var(phys->get_mesh_y_var());
1358  fc->set_mesh_z_var(phys->get_mesh_z_var());
1359 
1360  fc->set_deltat_pointer( &deltat );
1361 
1362  // If we are solving the adjoint problem, tell that to the Context
1363  fc->is_adjoint() = this->get_time_solver().is_adjoint();
1364 
1365  return fc;
1366 }
unsigned int get_mesh_x_var() const
Definition: diff_physics.h:625
const System * get_mesh_system() const
Definition: diff_physics.h:613
unsigned int get_mesh_y_var() const
Definition: diff_physics.h:631
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time...
Definition: diff_system.h:272
bool is_adjoint() const
Accessor for querying whether we need to do a primal or adjoint solve.
Definition: time_solver.h:277
libmesh_assert(ctx)
const DifferentiablePhysics * get_physics() const
Definition: diff_system.h:181
This class provides a specific system class.
Definition: diff_physics.h:76
unsigned int get_mesh_z_var() const
Definition: diff_physics.h:637
TimeSolver & get_time_solver()
Definition: diff_system.h:448

◆ 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 1506 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::TwostepTimeSolver::adjoint_solve(), libMesh::AdaptiveTimeSolver::calculate_norm(), libMesh::UnsteadySolver::du(), main(), output_norms(), ConstraintOperatorTest::testCoreform(), and MeshInputTest::testProjectionRegression().

1510 {
1511  //short circuit to save time
1512  if (norm_type == DISCRETE_L1 ||
1513  norm_type == DISCRETE_L2 ||
1514  norm_type == DISCRETE_L_INF)
1515  return discrete_var_norm(v,var,norm_type);
1516 
1517  // Not a discrete norm
1518  std::vector<FEMNormType> norms(this->n_vars(), L2);
1519  std::vector<Real> weights(this->n_vars(), 0.0);
1520  norms[var] = norm_type;
1521  weights[var] = 1.0;
1522  Real val = this->calculate_norm(v, SystemNorm(norms, weights), skip_dimensions);
1523  return val;
1524 }
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
Definition: system.C:1506
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
Finds the discrete norm for the entries in the vector corresponding to Dofs associated with var...
Definition: system.C:1487
unsigned int n_vars() const
Definition: system.C:2669

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

References libMesh::System::_dof_map, libMesh::System::_mesh, libMesh::FEGenericBase< OutputType >::build(), libMesh::NumericVector< T >::build(), libMesh::ParallelObject::comm(), libMesh::FEType::default_quadrature_rule(), dim, libMesh::DISCRETE_L1, libMesh::DISCRETE_L2, libMesh::DISCRETE_L_INF, libMesh::System::discrete_var_norm(), libMesh::DofMap::dof_indices(), libMesh::MeshBase::elem_dimensions(), libMesh::Utility::enum_to_string(), libMesh::FEInterface::field_type(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::GHOSTED, libMesh::H1, libMesh::H1_SEMINORM, libMesh::H2, libMesh::H2_SEMINORM, libMesh::L1, libMesh::NumericVector< T >::l1_norm(), libMesh::L2, libMesh::NumericVector< T >::l2_norm(), libMesh::L_INF, libMesh::libmesh_assert(), libMesh::NumericVector< T >::linfty_norm(), libMesh::NumericVector< T >::local_size(), libMesh::NumericVector< T >::localize(), libMesh::make_range(), TIMPI::Communicator::max(), libMesh::System::n_vars(), libMesh::TensorTools::norm(), libMesh::TensorTools::norm_sq(), libMesh::Real, libMesh::NumericVector< T >::size(), TIMPI::Communicator::sum(), libMesh::TYPE_SCALAR, libMesh::TYPE_VECTOR, libMesh::DofMap::variable_type(), libMesh::W1_INF_SEMINORM, libMesh::W2_INF_SEMINORM, and libMesh::SystemNorm::weight().

1531 {
1532  // This function must be run on all processors at once
1533  parallel_object_only();
1534 
1535  LOG_SCOPE ("calculate_norm()", "System");
1536 
1537  // Zero the norm before summation
1538  Real v_norm = 0.;
1539 
1540  if (norm.is_discrete())
1541  {
1542  //Check to see if all weights are 1.0 and all types are equal
1543  FEMNormType norm_type0 = norm.type(0);
1544  unsigned int check_var = 0, check_end = this->n_vars();
1545  for (; check_var != check_end; ++check_var)
1546  if ((norm.weight(check_var) != 1.0) || (norm.type(check_var) != norm_type0))
1547  break;
1548 
1549  //All weights were 1.0 so just do the full vector discrete norm
1550  if (check_var == this->n_vars())
1551  {
1552  if (norm_type0 == DISCRETE_L1)
1553  return v.l1_norm();
1554  if (norm_type0 == DISCRETE_L2)
1555  return v.l2_norm();
1556  if (norm_type0 == DISCRETE_L_INF)
1557  return v.linfty_norm();
1558  else
1559  libmesh_error_msg("Invalid norm_type0 = " << Utility::enum_to_string(norm_type0));
1560  }
1561 
1562  for (auto var : make_range(this->n_vars()))
1563  {
1564  // Skip any variables we don't need to integrate
1565  if (norm.weight(var) == 0.0)
1566  continue;
1567 
1568  v_norm += norm.weight(var) * discrete_var_norm(v, var, norm.type(var));
1569  }
1570 
1571  return v_norm;
1572  }
1573 
1574  // Localize the potentially parallel vector
1575  std::unique_ptr<NumericVector<Number>> local_v = NumericVector<Number>::build(this->comm());
1576  local_v->init(v.size(), v.local_size(), _dof_map->get_send_list(),
1577  true, GHOSTED);
1578  v.localize (*local_v, _dof_map->get_send_list());
1579 
1580  // I'm not sure how best to mix Hilbert norms on some variables (for
1581  // which we'll want to square then sum then square root) with norms
1582  // like L_inf (for which we'll just want to take an absolute value
1583  // and then sum).
1584  bool using_hilbert_norm = true,
1585  using_nonhilbert_norm = true;
1586 
1587  // Loop over all variables
1588  for (auto var : make_range(this->n_vars()))
1589  {
1590  // Skip any variables we don't need to integrate
1591  Real norm_weight_sq = norm.weight_sq(var);
1592  if (norm_weight_sq == 0.0)
1593  continue;
1594  Real norm_weight = norm.weight(var);
1595 
1596  // Check for unimplemented norms (rather than just returning 0).
1597  FEMNormType norm_type = norm.type(var);
1598  if ((norm_type==H1) ||
1599  (norm_type==H2) ||
1600  (norm_type==L2) ||
1601  (norm_type==H1_SEMINORM) ||
1602  (norm_type==H2_SEMINORM))
1603  {
1604  if (!using_hilbert_norm)
1605  libmesh_not_implemented();
1606  using_nonhilbert_norm = false;
1607  }
1608  else if ((norm_type==L1) ||
1609  (norm_type==L_INF) ||
1610  (norm_type==W1_INF_SEMINORM) ||
1611  (norm_type==W2_INF_SEMINORM))
1612  {
1613  if (!using_nonhilbert_norm)
1614  libmesh_not_implemented();
1615  using_hilbert_norm = false;
1616  }
1617  else
1618  libmesh_not_implemented();
1619 
1620  const FEType & fe_type = this->get_dof_map().variable_type(var);
1621 
1622  // Allow space for dims 0-3, and for both scalar and vector
1623  // elements, even if we don't use them all
1624  std::vector<std::unique_ptr<FEBase>> fe_ptrs(4);
1625  std::vector<std::unique_ptr<FEVectorBase>> vec_fe_ptrs(4);
1626  std::vector<std::unique_ptr<QBase>> q_rules(4);
1627 
1628  const std::set<unsigned char> & elem_dims = _mesh.elem_dimensions();
1629 
1630  // Prepare finite elements for each dimension present in the mesh
1631  for (const auto & dim : elem_dims)
1632  {
1633  if (skip_dimensions && skip_dimensions->find(dim) != skip_dimensions->end())
1634  continue;
1635 
1636  // Construct quadrature and finite element objects
1637  q_rules[dim] = fe_type.default_quadrature_rule (dim);
1638 
1639  const FEFieldType field_type = FEInterface::field_type(fe_type);
1640  if (field_type == TYPE_SCALAR)
1641  {
1642  fe_ptrs[dim] = FEBase::build(dim, fe_type);
1643  fe_ptrs[dim]->attach_quadrature_rule (q_rules[dim].get());
1644  }
1645  else
1646  {
1647  vec_fe_ptrs[dim] = FEVectorBase::build(dim, fe_type);
1648  vec_fe_ptrs[dim]->attach_quadrature_rule (q_rules[dim].get());
1649  libmesh_assert_equal_to(field_type, TYPE_VECTOR);
1650  }
1651 
1652  }
1653 
1654  std::vector<dof_id_type> dof_indices;
1655 
1656  // Begin the loop over the elements
1657  for (const auto & elem : this->get_mesh().active_local_element_ptr_range())
1658  {
1659  const unsigned int dim = elem->dim();
1660 
1661  // One way for implementing this would be to exchange the fe with the FEInterface- class.
1662  // However, it needs to be discussed whether integral-norms make sense for infinite elements.
1663  // or in which sense they could make sense.
1664  if (elem->infinite() )
1665  libmesh_not_implemented();
1666 
1667  if (skip_dimensions && skip_dimensions->find(dim) != skip_dimensions->end())
1668  continue;
1669 
1670  QBase * qrule = q_rules[dim].get();
1671  libmesh_assert(qrule);
1672 
1673  this->get_dof_map().dof_indices (elem, dof_indices, var);
1674 
1675  auto element_calculation = [&dof_indices, &elem,
1676  norm_type, norm_weight, norm_weight_sq, &qrule,
1677  &local_v, &v_norm](auto & fe) {
1678  typedef typename std::remove_reference<decltype(fe)>::type::OutputShape OutputShape;
1679  typedef typename TensorTools::MakeNumber<OutputShape>::type OutputNumberShape;
1680  typedef typename std::remove_reference<decltype(fe)>::type::OutputGradient OutputGradient;
1681  typedef typename TensorTools::MakeNumber<OutputGradient>::type OutputNumberGradient;
1682 
1683  const std::vector<Real> & JxW = fe.get_JxW();
1684  const std::vector<std::vector<OutputShape>> * phi = nullptr;
1685  if (norm_type == H1 ||
1686  norm_type == H2 ||
1687  norm_type == L2 ||
1688  norm_type == L1 ||
1689  norm_type == L_INF)
1690  phi = &(fe.get_phi());
1691 
1692  const std::vector<std::vector<OutputGradient>> * dphi = nullptr;
1693  if (norm_type == H1 ||
1694  norm_type == H2 ||
1695  norm_type == H1_SEMINORM ||
1696  norm_type == W1_INF_SEMINORM)
1697  dphi = &(fe.get_dphi());
1698 
1699 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
1700  typedef typename std::remove_reference<decltype(fe)>::type::OutputTensor OutputTensor;
1701 
1702  const std::vector<std::vector<OutputTensor>> * d2phi = nullptr;
1703  if (norm_type == H2 ||
1704  norm_type == H2_SEMINORM ||
1705  norm_type == W2_INF_SEMINORM)
1706  d2phi = &(fe.get_d2phi());
1707 #endif
1708 
1709  fe.reinit (elem);
1710 
1711  const unsigned int n_qp = qrule->n_points();
1712 
1713  const unsigned int n_sf = cast_int<unsigned int>
1714  (dof_indices.size());
1715 
1716  // Begin the loop over the Quadrature points.
1717  for (unsigned int qp=0; qp<n_qp; qp++)
1718  {
1719  if (norm_type == L1)
1720  {
1721  OutputNumberShape u_h = 0.;
1722  for (unsigned int i=0; i != n_sf; ++i)
1723  u_h += (*phi)[i][qp] * (*local_v)(dof_indices[i]);
1724  v_norm += norm_weight *
1725  JxW[qp] * TensorTools::norm(u_h);
1726  }
1727 
1728  if (norm_type == L_INF)
1729  {
1730  OutputNumberShape u_h = 0.;
1731  for (unsigned int i=0; i != n_sf; ++i)
1732  u_h += (*phi)[i][qp] * (*local_v)(dof_indices[i]);
1733  v_norm = std::max(v_norm, norm_weight * TensorTools::norm(u_h));
1734  }
1735 
1736  if (norm_type == H1 ||
1737  norm_type == H2 ||
1738  norm_type == L2)
1739  {
1740  OutputNumberShape u_h = 0.;
1741  for (unsigned int i=0; i != n_sf; ++i)
1742  u_h += (*phi)[i][qp] * (*local_v)(dof_indices[i]);
1743  v_norm += norm_weight_sq *
1744  JxW[qp] * TensorTools::norm_sq(u_h);
1745  }
1746 
1747  if (norm_type == H1 ||
1748  norm_type == H2 ||
1749  norm_type == H1_SEMINORM)
1750  {
1751  OutputNumberGradient grad_u_h;
1752  for (unsigned int i=0; i != n_sf; ++i)
1753  grad_u_h.add_scaled((*dphi)[i][qp], (*local_v)(dof_indices[i]));
1754  v_norm += norm_weight_sq *
1755  JxW[qp] * grad_u_h.norm_sq();
1756  }
1757 
1758  if (norm_type == W1_INF_SEMINORM)
1759  {
1760  OutputNumberGradient grad_u_h;
1761  for (unsigned int i=0; i != n_sf; ++i)
1762  grad_u_h.add_scaled((*dphi)[i][qp], (*local_v)(dof_indices[i]));
1763  v_norm = std::max(v_norm, norm_weight * grad_u_h.norm());
1764  }
1765 
1766 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
1767  typedef typename TensorTools::MakeNumber<OutputTensor>::type OutputNumberTensor;
1768 
1769  if (norm_type == H2 ||
1770  norm_type == H2_SEMINORM)
1771  {
1772  OutputNumberTensor hess_u_h;
1773  for (unsigned int i=0; i != n_sf; ++i)
1774  hess_u_h.add_scaled((*d2phi)[i][qp], (*local_v)(dof_indices[i]));
1775  v_norm += norm_weight_sq *
1776  JxW[qp] * hess_u_h.norm_sq();
1777  }
1778 
1779  if (norm_type == W2_INF_SEMINORM)
1780  {
1781  OutputNumberTensor hess_u_h;
1782  for (unsigned int i=0; i != n_sf; ++i)
1783  hess_u_h.add_scaled((*d2phi)[i][qp], (*local_v)(dof_indices[i]));
1784  v_norm = std::max(v_norm, norm_weight * hess_u_h.norm());
1785  }
1786 #endif
1787  }
1788  };
1789 
1790  FEBase * scalar_fe = fe_ptrs[dim].get();
1791  FEVectorBase * vec_fe = vec_fe_ptrs[dim].get();
1792 
1793  if (scalar_fe)
1794  {
1795  libmesh_assert(!vec_fe);
1796  element_calculation(*scalar_fe);
1797  }
1798 
1799  if (vec_fe)
1800  {
1801  libmesh_assert(!scalar_fe);
1802  element_calculation(*vec_fe);
1803  }
1804  }
1805  }
1806 
1807  if (using_hilbert_norm)
1808  {
1809  this->comm().sum(v_norm);
1810  v_norm = std::sqrt(v_norm);
1811  }
1812  else
1813  {
1814  this->comm().max(v_norm);
1815  }
1816 
1817  return v_norm;
1818 }
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition: dof_map.C:2192
auto norm_sq(const T &a)
Definition: tensor_tools.h:104
unsigned int dim
virtual numeric_index_type size() const =0
void sum(T &r) const
static FEFieldType field_type(const FEType &fe_type)
FEMNormType
defines an enum for norms defined on vectors of finite element coefficients
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225
const Parallel::Communicator & comm() const
FEGenericBase< RealGradient > FEVectorBase
Definition: fe_base.h:818
const MeshBase & get_mesh() const
Definition: system.h:2401
virtual Real l2_norm() const =0
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
libmesh_assert(ctx)
const FEType & variable_type(const unsigned int i) const
Definition: dof_map.h:2388
const std::set< unsigned char > & elem_dimensions() const
Definition: mesh_base.h:426
FEGenericBase< Real > FEBase
virtual Real l1_norm() const =0
std::string enum_to_string(const T e)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void max(const T &r, T &o, Request &req) const
auto norm(const T &a)
Definition: tensor_tools.h:74
virtual numeric_index_type local_size() const =0
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
Real discrete_var_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type) const
Finds the discrete norm for the entries in the vector corresponding to Dofs associated with var...
Definition: system.C:1487
unsigned int n_vars() const
Definition: system.C:2669
const DofMap & get_dof_map() const
Definition: system.h:2417
MeshBase & _mesh
Constant reference to the mesh data structure used for the simulation.
Definition: system.h:2237
virtual Real linfty_norm() const =0
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.
FEFieldType
defines an enum for finite element field types - i.e.

◆ can_add_matrices()

bool libMesh::System::can_add_matrices ( ) const
inlineprotectedinherited
Returns
Whether or not matrices can still be added without expensive per-matrix initialization.

Definition at line 2028 of file system.h.

References libMesh::System::_matrices_initialized.

Referenced by libMesh::EigenSystem::set_eigenproblem_type().

2028 { return !_matrices_initialized; }
bool _matrices_initialized
false when additional matrices being added require initialization, true otherwise.
Definition: system.h:2287

◆ clear()

void libMesh::DifferentiableSystem::clear ( )
overridevirtualinherited

Clear all the data structures associated with the system.

Reimplemented from libMesh::ImplicitSystem.

Reimplemented in libMesh::ContinuationSystem.

Definition at line 64 of file diff_system.C.

References libMesh::DifferentiableSystem::_diff_physics, libMesh::DifferentiableSystem::_diff_qoi, libMesh::DifferentiablePhysics::clear_physics(), libMesh::DifferentiableQoI::clear_qoi(), and libMesh::System::use_fixed_solution.

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

65 {
66  // If we had no attached Physics object, clear our own Physics data
67  if (this->_diff_physics.empty())
68  this->clear_physics();
69 
70  this->_diff_physics = {}; // No stack::clear
71  this->_diff_qoi = {};
72 
73  // If we had no attached QoI object, clear our own QoI data
74  if (this->_diff_qoi.empty())
75  this->clear_qoi();
76 
77  use_fixed_solution = false;
78 }
virtual void clear_physics()
Clear any data structures associated with the physics.
Definition: diff_physics.C:29
bool use_fixed_solution
A boolean to be set to true by systems using elem_fixed_solution, for optional use by e...
Definition: system.h:1625
std::stack< std::unique_ptr< DifferentiablePhysics >, std::vector< std::unique_ptr< DifferentiablePhysics > > > _diff_physics
Stack of pointers to objects to use for physics assembly evaluations.
Definition: diff_system.h:434
std::stack< std::unique_ptr< DifferentiableQoI >, std::vector< std::unique_ptr< DifferentiableQoI > > > _diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
Definition: diff_system.h:442
virtual void clear_qoi()
Clear all the data structures associated with the QoI.
Definition: diff_qoi.h:77

◆ clear_physics()

void libMesh::DifferentiablePhysics::clear_physics ( )
virtualinherited

Clear any data structures associated with the physics.

Definition at line 29 of file diff_physics.C.

References libMesh::DifferentiablePhysics::_time_evolving.

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

30 {
31  _time_evolving.resize(0);
32 }
std::vector< unsigned int > _time_evolving
Stores unsigned int to tell us which variables are evolving as first order in time (1)...
Definition: diff_physics.h:543

◆ clear_qoi()

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

Clear all the data structures associated with the QoI.

Definition at line 77 of file diff_qoi.h.

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

77 {}

◆ 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 168 of file diff_system.h.

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

169  {
170  libmesh_not_implemented();
171  // dummy to avoid compiler warnings, not a real implementation
172  return std::unique_ptr<DifferentiableQoI>(nullptr);
173  }

◆ 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 158 of file diff_system.h.

159  {
160  libmesh_not_implemented();
161  // dummy to avoid compiler warnings, not a real implementation
162  return std::unique_ptr<DifferentiablePhysics>(nullptr);
163  }

◆ comm()

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

Definition at line 97 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::Partitioner::_find_global_index_by_pid_map(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< libMesh::Number >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< libMesh::Number >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_mult_add(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::DofMap::add_constraints_to_send_list(), add_cube_convex_hull_to_mesh(), libMesh::PetscDMWrapper::add_dofs_helper(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::RBEIMEvaluation::add_interpolation_data(), libMesh::CondensedEigenSystem::add_matrices(), libMesh::EigenSystem::add_matrices(), libMesh::System::add_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::DofMap::add_variable(), libMesh::DofMap::add_variables(), libMesh::System::add_vector(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::AdvectionSystem::assemble_claw_rhs(), libMesh::FEMSystem::assemble_qoi(), libMesh::Nemesis_IO::assert_symmetric_cmaps(), libMesh::MeshCommunication::assign_global_indices(), libMesh::Partitioner::assign_partitioning(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Partitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), 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_data(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::MeshBase::complete_preparation(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::DofMap::computed_sparsity_already(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ContinuationSystem::ContinuationSystem(), libMesh::MeshBase::copy_constraint_rows(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::CondensedEigenSystem::copy_super_to_sub(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::DofMap::create_dof_constraints(), 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::PetscMatrix< T >::create_submatrix_nosort(), create_wrapped_function(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::RBEIMEvaluation::distribute_bfs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::DTKSolutionTransfer::DTKSolutionTransfer(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_interiors(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_nodes(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_sides(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::EpetraVector< T >::EpetraVector(), AssembleOptimization::equality_constraints(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::SmoothnessEstimator::estimate_smoothness(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_error_tolerance(), libMesh::MeshRefinement::flag_elements_by_mean_stddev(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::RBEIMEvaluation::gather_bfs(), libMesh::DofMap::gather_constraints(), libMesh::MeshfreeInterpolation::gather_remote_data(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::RBEIMEvaluation::get_eim_basis_function_node_value(), libMesh::RBEIMEvaluation::get_eim_basis_function_side_value(), libMesh::RBEIMEvaluation::get_eim_basis_function_value(), libMesh::System::get_info(), libMesh::MeshBase::get_info(), libMesh::DofMap::get_info(), libMesh::RBEIMEvaluation::get_interior_basis_functions_as_vecs(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::RBEIMConstruction::get_max_abs_value(), libMesh::RBEIMConstruction::get_node_max_abs_value(), libMesh::RBEIMEvaluation::get_parametrized_function_node_value(), libMesh::RBEIMEvaluation::get_parametrized_function_side_value(), libMesh::RBEIMEvaluation::get_parametrized_function_value(), libMesh::RBEIMConstruction::get_random_point(), libMesh::MeshTetInterface::improve_hull_integrity(), AssembleOptimization::inequality_constraints(), AssembleOptimization::inequality_constraints_jacobian(), libMesh::LocationMap< T >::init(), libMesh::TimeSolver::init(), libMesh::StaticCondensation::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::AdvectionSystem::init_data(), libMesh::ClawSystem::init_data(), libMesh::PetscDMWrapper::init_petscdm(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set(), libMesh::RBEIMConstruction::inner_product(), integrate_function(), libMesh::MeshTools::libmesh_assert_consistent_distributed(), libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_equal_connectivity(), libMesh::MeshTools::libmesh_assert_equal_points(), 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_constraint_rows(), 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_linesearch_shellfunc(), libMesh::libmesh_petsc_preconditioner_apply(), libMesh::libmesh_petsc_recalculate_monitor(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_interface(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_postcheck(), libMesh::libmesh_petsc_snes_precheck(), 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::LinearImplicitSystem::LinearImplicitSystem(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_bcids_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::FEMSystem::mesh_position_set(), libMesh::TriangulatorInterface::MeshedHole::MeshedHole(), LinearElasticityWithContact::move_mesh(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::MeshTools::n_connected_components(), libMesh::DofMap::n_constrained_dofs(), libMesh::MeshBase::n_constraint_rows(), libMesh::DofMap::n_dofs(), libMesh::DofMap::n_dofs_per_processor(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), MixedOrderTest::n_neighbor_links(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::SparsityPattern::Build::n_nonzeros(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::RBEIMEvaluation::node_distribute_bfs(), libMesh::RBEIMEvaluation::node_gather_bfs(), libMesh::RBEIMConstruction::node_inner_product(), libMesh::PetscVector< libMesh::Number >::operator=(), libMesh::MeshBase::operator==(), 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::BoundaryInfo::parallel_sync_node_ids(), libMesh::BoundaryInfo::parallel_sync_side_ids(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::print_constraint_rows(), libMesh::DofMap::print_dof_constraints(), libMesh::DofMap::process_mesh_constraint_rows(), libMesh::Partitioner::processor_pairs_to_interface_nodes(), libMesh::InterMeshProjection::project_system_vectors(), FEMParameters::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::EquationSystems::read(), libMesh::ExodusII_IO::read_header(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::RBEIMEvaluation::read_in_interior_basis_functions(), libMesh::RBEIMEvaluation::read_in_node_basis_functions(), libMesh::RBEIMEvaluation::read_in_side_basis_functions(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), 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::Nemesis_IO_Helper::read_var_names_impl(), MeshFunctionTest::read_variable_info_from_output_data(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::SimplexRefiner::refine_via_edges(), libMesh::StaticCondensationDofMap::reinit(), libMesh::BoundaryInfo::remove_edge_id(), libMesh::BoundaryInfo::remove_node_id(), libMesh::BoundaryInfo::remove_shellface_id(), libMesh::BoundaryInfo::remove_side_id(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::DistributedMesh::renumber_nodes_and_elements(), LinearElasticityWithContact::residual_and_jacobian(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), scale_mesh_and_plot(), libMesh::DofMap::scatter_constraints(), libMesh::CheckpointIO::select_split_config(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::send_and_insert_dof_values(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::Partitioner::set_interface_node_processor_ids_BFS(), libMesh::Partitioner::set_interface_node_processor_ids_linear(), libMesh::Partitioner::set_interface_node_processor_ids_petscpartitioner(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::PetscDiffSolver::setup_petsc_data(), libMesh::RBEIMEvaluation::side_distribute_bfs(), libMesh::RBEIMEvaluation::side_gather_bfs(), libMesh::RBEIMConstruction::side_inner_product(), libMesh::Partitioner::single_partition(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::VariationalMeshSmoother::smooth(), libMesh::ClawSystem::solve_conservation_law(), libMesh::split_mesh(), libMesh::RBEIMConstruction::store_eim_solutions_for_training_set(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::MeshBase::sync_subdomain_name_map(), ConstraintOperatorTest::test1DCoarseningNewNodes(), ConstraintOperatorTest::test1DCoarseningOperator(), MeshFunctionTest::test_bad_gradient_var_with_out_of_mesh_value(), MeshFunctionTest::test_bad_hessian_var_with_out_of_mesh_value(), libMesh::MeshRefinement::test_level_one(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), libMesh::MeshRefinement::test_unflagged(), DofMapTest::testBadElemFECombo(), SystemsTest::testBlockRestrictedVarNDofs(), BoundaryInfoTest::testBoundaryOnChildrenErrors(), VolumeTest::testC0PolygonMethods(), VolumeTest::testC0PolyhedronMethods(), ConstraintOperatorTest::testCoreform(), ConnectedComponentsTest::testEdge(), MeshInputTest::testExodusIGASidesets(), MeshTriangulationTest::testFoundCenters(), PointLocatorTest::testLocator(), BoundaryInfoTest::testMesh(), PointLocatorTest::testPlanar(), MeshTriangulationTest::testPoly2TriRefinementBase(), SystemsTest::testProjectCubeWithMeshFunction(), BoundaryInfoTest::testRenumber(), BoundaryInfoTest::testSelectiveRenumber(), CheckpointIOTest::testSplitter(), MeshInputTest::testTetgenIO(), MeshTriangulationTest::testTriangulatorInterp(), MeshTriangulationTest::testTriangulatorMeshedHoles(), MeshTriangulationTest::testTriangulatorRoundHole(), MeshSmootherTest::testVariationalSmoother(), libMesh::MeshTools::total_weight(), libMesh::RBConstruction::train_reduced_basis_with_POD(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::Poly2TriTriangulator::triangulate(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::MeshRefinement::uniformly_coarsen(), update_current_local_solution(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::MeshTools::volume(), libMesh::STLIO::write(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::VTKIO::write_nodal_data(), libMesh::RBEIMEvaluation::write_out_interior_basis_functions(), libMesh::RBEIMEvaluation::write_out_node_basis_functions(), libMesh::RBEIMEvaluation::write_out_side_basis_functions(), libMesh::RBEvaluation::write_out_vectors(), libMesh::TransientRBConstruction::write_riesz_representors_to_files(), libMesh::RBConstruction::write_riesz_representors_to_files(), 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(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::TransientRBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBSCMEvaluationSerialization::write_to_file().

98  { 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 606 of file system.C.

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

609 {
610  // we do not care for matrices, but for vectors
612  libmesh_assert (other_system._is_initialized);
613 
614  if (verbose)
615  {
616  libMesh::out << " Systems \"" << _sys_name << "\"" << std::endl;
617  libMesh::out << " comparing matrices not supported." << std::endl;
618  libMesh::out << " comparing names...";
619  }
620 
621  // compare the name: 0 means identical
622  const int name_result = _sys_name.compare(other_system.name());
623  if (verbose)
624  {
625  if (name_result == 0)
626  libMesh::out << " identical." << std::endl;
627  else
628  libMesh::out << " names not identical." << std::endl;
629  libMesh::out << " comparing solution vector...";
630  }
631 
632 
633  // compare the solution: -1 means identical
634  const int solu_result = solution->compare (*other_system.solution.get(),
635  threshold);
636 
637  if (verbose)
638  {
639  if (solu_result == -1)
640  libMesh::out << " identical up to threshold." << std::endl;
641  else
642  libMesh::out << " first difference occurred at index = "
643  << solu_result << "." << std::endl;
644  }
645 
646 
647  // safety check, whether we handle at least the same number
648  // of vectors
649  std::vector<int> ov_result;
650 
651  if (this->n_vectors() != other_system.n_vectors())
652  {
653  if (verbose)
654  {
655  libMesh::out << " Fatal difference. This system handles "
656  << this->n_vectors() << " add'l vectors," << std::endl
657  << " while the other system handles "
658  << other_system.n_vectors()
659  << " add'l vectors." << std::endl
660  << " Aborting comparison." << std::endl;
661  }
662  return false;
663  }
664  else if (this->n_vectors() == 0)
665  {
666  // there are no additional vectors...
667  ov_result.clear ();
668  }
669  else
670  {
671  // compare other vectors
672  for (auto & [vec_name, vec] : _vectors)
673  {
674  if (verbose)
675  libMesh::out << " comparing vector \""
676  << vec_name << "\" ...";
677 
678  // assume they have the same name
679  const NumericVector<Number> & other_system_vector =
680  other_system.get_vector(vec_name);
681 
682  ov_result.push_back(vec->compare(other_system_vector, threshold));
683 
684  if (verbose)
685  {
686  if (ov_result[ov_result.size()-1] == -1)
687  libMesh::out << " identical up to threshold." << std::endl;
688  else
689  libMesh::out << " first difference occurred at" << std::endl
690  << " index = " << ov_result[ov_result.size()-1] << "." << std::endl;
691  }
692  }
693  } // finished comparing additional vectors
694 
695 
696  bool overall_result;
697 
698  // sum up the results
699  if ((name_result==0) && (solu_result==-1))
700  {
701  if (ov_result.size()==0)
702  overall_result = true;
703  else
704  {
705  bool ov_identical;
706  unsigned int n = 0;
707  do
708  {
709  ov_identical = (ov_result[n]==-1);
710  n++;
711  }
712  while (ov_identical && n<ov_result.size());
713  overall_result = ov_identical;
714  }
715  }
716  else
717  overall_result = false;
718 
719  if (verbose)
720  {
721  libMesh::out << " finished comparisons, ";
722  if (overall_result)
723  libMesh::out << "found no differences." << std::endl << std::endl;
724  else
725  libMesh::out << "found differences." << std::endl << std::endl;
726  }
727 
728  return overall_result;
729 }
bool _is_initialized
true when additional vectors and variables do not require immediate initialization, false otherwise.
Definition: system.h:2306
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
unsigned int n_vectors() const
Definition: system.h:2499
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
libmesh_assert(ctx)
OStreamProxy out
const std::string _sys_name
A name associated with this system.
Definition: system.h:2242
template class LIBMESH_EXPORT NumericVector< Number >

◆ condense_constrained_dofs()

virtual bool libMesh::System::condense_constrained_dofs ( ) const
inlineprotectedvirtualinherited

Whether this object should condense out constrained degrees of freedom.

Reimplemented in libMesh::CondensedEigenSystem.

Definition at line 2059 of file system.h.

Referenced by libMesh::EigenSystem::init_matrices().

2059 { return false; }

◆ create_static_condensation()

void libMesh::ImplicitSystem::create_static_condensation ( )
overridevirtualinherited

Request that static condensation be performed for this system.

Reimplemented from libMesh::System.

Reimplemented in libMesh::NonlinearImplicitSystem, and libMesh::LinearImplicitSystem.

Definition at line 64 of file implicit_system.C.

References libMesh::System::create_static_condensation(), and libMesh::ImplicitSystem::create_static_condensation_system_matrix().

Referenced by libMesh::LinearImplicitSystem::create_static_condensation(), and libMesh::NonlinearImplicitSystem::create_static_condensation().

65 {
68 }
virtual void create_static_condensation()
Request that static condensation be performed for this system.
Definition: system.C:2659
void create_static_condensation_system_matrix()
Create the static condensation system matrix.

◆ current_solution()

Number libMesh::System::current_solution ( const dof_id_type  global_dof_number) const
inherited
Returns
The current solution for the specified global DOF.

Definition at line 162 of file system.C.

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

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::HPCoarsenTest::add_projection(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::ExactErrorEstimator::estimate_error(), main(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SmoothnessEstimator::EstimateSmoothness::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::HPCoarsenTest::select_refinement(), SolidSystem::side_time_derivative(), libMesh::EnsightIO::write_scalar_ascii(), and libMesh::EnsightIO::write_vector_ascii().

163 {
164  // Check the sizes
165  libmesh_assert_less (global_dof_number, _dof_map->n_dofs());
166  libmesh_assert_less (global_dof_number, current_local_solution->size());
167 
168  return (*current_local_solution)(global_dof_number);
169 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667

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

Reimplemented in SecondOrderScalarSystemFirstOrderTimeSolverBase, and SecondOrderScalarSystemSecondOrderTimeSolverBase.

Definition at line 360 of file diff_physics.h.

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

362  {
363  return request_jacobian;
364  }

◆ deactivate()

void libMesh::System::deactivate ( )
inlineinherited

Deactivates the system.

Only active systems are solved.

Definition at line 2449 of file system.h.

References libMesh::System::_active.

2450 {
2451  _active = false;
2452 }
bool _active
Flag stating if the system is active or not.
Definition: system.h:2252

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

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

Referenced by libMesh::DifferentiableSystem::pop_physics(), and libMesh::DifferentiableSystem::push_physics().

132  {
133  this->assemble_before_solve = true;
134  this->get_linear_solver()->reuse_preconditioner(false);
135 }
virtual LinearSolver< Number > * get_linear_solver() const
virtual void reuse_preconditioner(bool)
Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent ...
bool assemble_before_solve
Flag which tells the system to whether or not to call the user assembly function during each call to ...
Definition: system.h:1609

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = false;
103  return;
104 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ element_constraint()

bool CoupledSystem::element_constraint ( bool  request_jacobian,
DiffContext  
)
protectedvirtual

Adds the constraint contribution on elem to elem_residual.

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

Users may need to reimplement this for their particular PDE.

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

Reimplemented from libMesh::DifferentiablePhysics.

Definition at line 355 of file coupled_system.C.

References libMesh::DiffContext::elem_solution_derivative, libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::FEMContext::get_element_fe(), libMesh::FEMContext::get_element_qrule(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEMContext::interior_gradient(), libMesh::libmesh_assert(), libMesh::DiffContext::n_dof_indices(), and libMesh::QBase::n_points().

357 {
358  FEMContext & c = cast_ref<FEMContext &>(context);
359 
360  // Here we define some references to cell-specific data that
361  // will be used to assemble the linear system.
362  FEBase * u_elem_fe = nullptr;
363  c.get_element_fe(u_var, u_elem_fe);
364 
365  FEBase * p_elem_fe = nullptr;
366  c.get_element_fe(p_var, p_elem_fe);
367 
368  // Element Jacobian * quadrature weight for interior integration
369  const std::vector<Real> & JxW = u_elem_fe->get_JxW();
370 
371  // The velocity shape function gradients at interior
372  // quadrature points.
373  const std::vector<std::vector<RealGradient>> & dphi = u_elem_fe->get_dphi();
374 
375  // The pressure shape functions at interior
376  // quadrature points.
377  const std::vector<std::vector<Real>> & psi = p_elem_fe->get_phi();
378 
379  // The number of local degrees of freedom in each variable
380  const unsigned int n_u_dofs = c.n_dof_indices(u_var);
381  const unsigned int n_p_dofs = c.n_dof_indices(p_var);
382 
383  // pressure-velocity coupling blocks
384  // Kpu Kpv
385  std::reference_wrapper<DenseSubMatrix<Number>> B[2] =
386  {
389  };
390 
391  // The subvectors and submatrices we need to fill:
393 
394  // Add the constraint given by the continuity equation
395  unsigned int n_qpoints = c.get_element_qrule().n_points();
396 
397  // Store (grad_u, grad_v) at current Newton iterate
398  Gradient grad_uv[2];
399 
400  for (unsigned int qp=0; qp != n_qpoints; qp++)
401  {
402  // Compute the velocity gradient at the old Newton iterate
403  c.interior_gradient(u_var, qp, grad_uv[0]),
404  c.interior_gradient(v_var, qp, grad_uv[1]);
405 
406  // Now a loop over the pressure degrees of freedom. This
407  // computes the contributions of the continuity equation.
408  for (unsigned int i=0; i != n_p_dofs; i++)
409  {
410  for (unsigned int d=0; d<2; ++d)
411  Fp(i) += JxW[qp] * psi[i][qp] * grad_uv[d](d);
412 
413  if (request_jacobian && c.elem_solution_derivative)
414  {
416 
417  for (unsigned int j=0; j != n_u_dofs; j++)
418  for (unsigned int d=0; d<2; ++d)
419  B[d](i,j) += JxW[qp]*psi[i][qp]*dphi[j][qp](d);
420  }
421  }
422  } // end of the quadrature point qp-loop
423 
424  return request_jacobian;
425 }
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:274
unsigned int v_var
unsigned int n_dof_indices() const
Total number of dof indices on the element.
Definition: diff_context.h:395
unsigned int p_var
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
Defines a dense subvector for use in finite element computations.
unsigned int u_var
Definition: assembly.h:38
Gradient interior_gradient(unsigned int var, unsigned int qp) const
Definition: fem_context.C:466
Real elem_solution_derivative
The derivative of elem_solution with respect to the current nonlinear solution.
Definition: diff_context.h:496
libmesh_assert(ctx)
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
unsigned int n_points() const
Definition: quadrature.h:131
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:242
void get_element_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for interior finite element object for variable var for the largest dimension in the mesh...
Definition: fem_context.h:277
This class forms the foundation from which generic finite elements may be derived.
const QBase & get_element_qrule() const
Accessor for element interior quadrature rule for the dimension of the current _elem.
Definition: fem_context.h:802
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:207

◆ element_postprocess()

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

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

Reimplemented in LaplaceSystem, LaplaceSystem, and PoissonSystem.

Definition at line 293 of file diff_system.h.

293 {}

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

Reimplemented in HeatSystem, and LaplaceQoI.

Definition at line 110 of file diff_qoi.h.

112  {}

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

Reimplemented in HeatSystem, LaplaceSystem, HeatSystem, LaplaceSystem, and LaplaceQoI.

Definition at line 122 of file diff_qoi.h.

124  {}

◆ element_time_derivative()

bool CoupledSystem::element_time_derivative ( bool  request_jacobian,
DiffContext  
)
protectedvirtual

Adds the time derivative contribution on elem to elem_residual.

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

Users need to reimplement this for their particular PDE.

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

Reimplemented from libMesh::DifferentiablePhysics.

Definition at line 207 of file coupled_system.C.

References libMesh::DiffContext::elem_solution_derivative, libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::FEMContext::get_element_fe(), libMesh::FEMContext::get_element_qrule(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEMContext::interior_gradient(), libMesh::FEMContext::interior_value(), libMesh::libmesh_assert(), libMesh::DiffContext::n_dof_indices(), and libMesh::QBase::n_points().

209 {
210  FEMContext & c = cast_ref<FEMContext &>(context);
211 
212  // First we get some references to cell-specific data that
213  // will be used to assemble the linear system.
214  FEBase * u_elem_fe = nullptr;
215  c.get_element_fe(u_var, u_elem_fe);
216 
217  // Element Jacobian * quadrature weights for interior integration
218  const std::vector<Real> & JxW = u_elem_fe->get_JxW();
219 
220  // The velocity shape functions at interior quadrature points.
221  const std::vector<std::vector<Real>> & phi = u_elem_fe->get_phi();
222 
223  // The velocity shape function gradients at interior
224  // quadrature points.
225  const std::vector<std::vector<RealGradient>> & dphi = u_elem_fe->get_dphi();
226 
227  // The pressure shape functions at interior
228  // quadrature points.
229  FEBase * p_elem_fe = nullptr;
230  c.get_element_fe(p_var, p_elem_fe);
231 
232  const std::vector<std::vector<Real>> & psi = p_elem_fe->get_phi();
233 
234  // The number of local degrees of freedom in each variable
235  const unsigned int n_p_dofs = c.n_dof_indices(p_var);
236  const unsigned int n_u_dofs = c.n_dof_indices(u_var);
237  libmesh_assert_equal_to (n_u_dofs, c.n_dof_indices(v_var));
238 
239  // Stokes equation stiffness matrix diagonal blocks. There is no
240  // uv/vu coupling for linear Stokes.
241  std::reference_wrapper<DenseSubMatrix<Number>> Kdiag[2] =
242  {
245  };
246 
247  // Stokes equation velocity-pressure coupling blocks
248  // Kup
249  // Kvp
250  std::reference_wrapper<DenseSubMatrix<Number>> B[2] =
251  {
254  };
255 
256  // Stokes equation residuals
257  // Fu
258  // Fv
259  std::reference_wrapper<DenseSubVector<Number>> F[2] =
260  {
263  };
264 
265  // Concentration/velocity coupling blocks
266  // KCu
267  // KCv
268  std::reference_wrapper<DenseSubMatrix<Number>> C[2] =
269  {
272  };
273 
274  // Concentration diagonal block and residual
277 
278  // Now we will build the element Jacobian and residual.
279  // Constructing the residual requires the solution and its
280  // gradient from the previous timestep. This must be
281  // calculated at each quadrature point by summing the
282  // solution degree-of-freedom values by the appropriate
283  // weight functions.
284  unsigned int n_qpoints = c.get_element_qrule().n_points();
285 
286  // Store (grad_u, grad_v) at current Newton iterate
287  Gradient grad_uv[2];
288 
289  // Velocity at current Newton iterate
291 
292  for (unsigned int qp=0; qp != n_qpoints; qp++)
293  {
294  // Compute the solution & its gradient at the current Newton iterate
295  Number p = c.interior_value(p_var, qp);
296  Gradient grad_C = c.interior_gradient(C_var, qp);
297 
298  c.interior_value(u_var, qp, U(0));
299  c.interior_value(v_var, qp, U(1));
300  c.interior_gradient(u_var, qp, grad_uv[0]);
301  c.interior_gradient(v_var, qp, grad_uv[1]);
302 
303  // First, an i-loop over the velocity degrees of freedom.
304  // We know that n_u_dofs == n_v_dofs so we can compute contributions
305  // for both at the same time.
306  for (unsigned int i=0; i != n_u_dofs; i++)
307  {
308  // Stokes equations residuals
309  for (unsigned int d=0; d<2; ++d)
310  F[d](i) += JxW[qp] *
311  (p*dphi[i][qp](d) - // pressure term
312  (grad_uv[d]*dphi[i][qp])); // diffusion term
313 
314  // Concentration Equation Residual
315  FC(i) += JxW[qp] *
316  ((U*grad_C)*phi[i][qp] + // convection term
317  (1./Peclet)*(grad_C*dphi[i][qp])); // diffusion term
318 
319  // Note that the Fp block is identically zero unless we are using
320  // some kind of artificial compressibility scheme...
321 
322  if (request_jacobian && c.elem_solution_derivative)
323  {
325 
326  for (unsigned int j=0; j != n_u_dofs; j++)
327  {
328  for (unsigned int d=0; d<2; ++d)
329  {
330  // Matrix contributions for the uu and vv couplings.
331  Kdiag[d](i,j) += JxW[qp] * (-(dphi[i][qp]*dphi[j][qp]));
332 
333  // Matrix contributions for the Cu and Cv couplings.
334  C[d](i,j) += JxW[qp] * ((phi[j][qp]*grad_C(d))*phi[i][qp]);
335  }
336 
337  // Concentration equation Jacobian contribution
338  KCC(i,j) += JxW[qp]*
339  ((U*dphi[j][qp])*phi[i][qp] + // nonlinear term (convection)
340  (1./Peclet)*(dphi[j][qp]*dphi[i][qp])); // diffusion term
341  }
342 
343  // Matrix contributions for the up and vp couplings.
344  for (unsigned int j=0; j != n_p_dofs; j++)
345  for (unsigned int d=0; d<2; ++d)
346  B[d](i,j) += JxW[qp]*psi[j][qp]*dphi[i][qp](d);
347  }
348  }
349  } // end of the quadrature point qp-loop
350 
351  return request_jacobian;
352 }
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:274
Number interior_value(unsigned int var, unsigned int qp) const
Definition: fem_context.C:411
unsigned int v_var
unsigned int n_dof_indices() const
Total number of dof indices on the element.
Definition: diff_context.h:395
unsigned int p_var
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
Defines a dense subvector for use in finite element computations.
unsigned int u_var
Definition: assembly.h:38
Gradient interior_gradient(unsigned int var, unsigned int qp) const
Definition: fem_context.C:466
Defines a dense submatrix for use in Finite Element-type computations.
Real elem_solution_derivative
The derivative of elem_solution with respect to the current nonlinear solution.
Definition: diff_context.h:496
libmesh_assert(ctx)
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
unsigned int n_points() const
Definition: quadrature.h:131
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:242
void get_element_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for interior finite element object for variable var for the largest dimension in the mesh...
Definition: fem_context.h:277
unsigned int C_var
This class forms the foundation from which generic finite elements may be derived.
const QBase & get_element_qrule() const
Accessor for element interior quadrature rule for the dimension of the current _elem.
Definition: fem_context.h:802
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:207

◆ 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 94 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

95 {
96  _enable_print_counter = true;
97  return;
98 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ eulerian_residual() [1/2]

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.

Reimplemented in SolidSystem.

Definition at line 38 of file fem_physics.C.

References libMesh::DifferentiablePhysics::_mesh_sys, libMesh::DifferentiablePhysics::_mesh_x_var, libMesh::DifferentiablePhysics::_mesh_y_var, libMesh::DifferentiablePhysics::_mesh_z_var, libMesh::FEMContext::get_element_qrule(), libMesh::FEMContext::interior_gradient(), libMesh::invalid_uint, libMesh::DifferentiablePhysics::is_time_evolving(), libMesh::libmesh_assert(), libMesh::libmesh_real(), libMesh::make_range(), libMesh::DiffContext::n_vars(), and libMesh::UnsteadySolver::old_nonlinear_solution().

40 {
41  // Only calculate a mesh movement residual if it's necessary
42  if (!_mesh_sys)
43  return request_jacobian;
44 
45  libmesh_not_implemented();
46 
47 #if 0
48  FEMContext & context = cast_ref<FEMContext &>(c);
49 
50  // This function only supports fully coupled mesh motion for now
51  libmesh_assert_equal_to (_mesh_sys, this);
52 
53  unsigned int n_qpoints = (context.get_element_qrule())->n_points();
54 
55  const unsigned int n_x_dofs = (_mesh_x_var == libMesh::invalid_uint) ?
56  0 : context.dof_indices_var[_mesh_x_var].size();
57  const unsigned int n_y_dofs = (_mesh_y_var == libMesh::invalid_uint) ?
58  0 : context.dof_indices_var[_mesh_y_var].size();
59  const unsigned int n_z_dofs = (_mesh_z_var == libMesh::invalid_uint) ?
60  0 : context.dof_indices_var[_mesh_z_var].size();
61 
62  const unsigned int mesh_xyz_var = n_x_dofs ? _mesh_x_var :
63  (n_y_dofs ? _mesh_y_var :
64  (n_z_dofs ? _mesh_z_var :
66 
67  // If we're our own _mesh_sys, we'd better be in charge of
68  // at least one coordinate, and we'd better have the same
69  // FE type for all coordinates we are in charge of
70  libmesh_assert_not_equal_to (mesh_xyz_var, libMesh::invalid_uint);
71  libmesh_assert(!n_x_dofs || context.element_fe_var[_mesh_x_var] ==
72  context.element_fe_var[mesh_xyz_var]);
73  libmesh_assert(!n_y_dofs || context.element_fe_var[_mesh_y_var] ==
74  context.element_fe_var[mesh_xyz_var]);
75  libmesh_assert(!n_z_dofs || context.element_fe_var[_mesh_z_var] ==
76  context.element_fe_var[mesh_xyz_var]);
77 
78  const std::vector<std::vector<Real>> & psi =
79  context.element_fe_var[mesh_xyz_var]->get_phi();
80 
81  for (auto var : make_range(context.n_vars()))
82  {
83  // Mesh motion only affects time-evolving variables
84  if (this->is_time_evolving(var))
85  continue;
86 
87  // The mesh coordinate variables themselves are Lagrangian,
88  // not Eulerian, and no convective term is desired.
89  if (/*_mesh_sys == this && */
90  (var == _mesh_x_var ||
91  var == _mesh_y_var ||
92  var == _mesh_z_var))
93  continue;
94 
95  // Some of this code currently relies on the assumption that
96  // we can pull mesh coordinate data from our own system
97  if (_mesh_sys != this)
98  libmesh_not_implemented();
99 
100  // This residual should only be called by unsteady solvers:
101  // if the mesh is steady, there's no mesh convection term!
102  UnsteadySolver * unsteady;
103  if (this->time_solver->is_steady())
104  return request_jacobian;
105  else
106  unsteady = cast_ptr<UnsteadySolver*>(this->time_solver.get());
107 
108  const std::vector<Real> & JxW =
109  context.element_fe_var[var]->get_JxW();
110 
111  const std::vector<std::vector<Real>> & phi =
112  context.element_fe_var[var]->get_phi();
113 
114  const std::vector<std::vector<RealGradient>> & dphi =
115  context.element_fe_var[var]->get_dphi();
116 
117  const unsigned int n_u_dofs = context.dof_indices_var[var].size();
118 
119  DenseSubVector<Number> & Fu = *context.elem_subresiduals[var];
120  DenseSubMatrix<Number> & Kuu = *context.elem_subjacobians[var][var];
121 
122  DenseSubMatrix<Number> * Kux = n_x_dofs ?
123  context.elem_subjacobians[var][_mesh_x_var] : nullptr;
124  DenseSubMatrix<Number> * Kuy = n_y_dofs ?
125  context.elem_subjacobians[var][_mesh_y_var] : nullptr;
126  DenseSubMatrix<Number> * Kuz = n_z_dofs ?
127  context.elem_subjacobians[var][_mesh_z_var] : nullptr;
128 
129  std::vector<Real> delta_x(n_x_dofs, 0.);
130  std::vector<Real> delta_y(n_y_dofs, 0.);
131  std::vector<Real> delta_z(n_z_dofs, 0.);
132 
133  for (unsigned int i = 0; i != n_x_dofs; ++i)
134  {
135  unsigned int j = context.dof_indices_var[_mesh_x_var][i];
136  delta_x[i] = libmesh_real(this->current_solution(j)) -
137  libmesh_real(unsteady->old_nonlinear_solution(j));
138  }
139 
140  for (unsigned int i = 0; i != n_y_dofs; ++i)
141  {
142  unsigned int j = context.dof_indices_var[_mesh_y_var][i];
143  delta_y[i] = libmesh_real(this->current_solution(j)) -
144  libmesh_real(unsteady->old_nonlinear_solution(j));
145  }
146 
147  for (unsigned int i = 0; i != n_z_dofs; ++i)
148  {
149  unsigned int j = context.dof_indices_var[_mesh_z_var][i];
150  delta_z[i] = libmesh_real(this->current_solution(j)) -
151  libmesh_real(unsteady->old_nonlinear_solution(j));
152  }
153 
154  for (unsigned int qp = 0; qp != n_qpoints; ++qp)
155  {
156  Gradient grad_u = context.interior_gradient(var, qp);
157  RealGradient convection(0.);
158 
159  for (unsigned int i = 0; i != n_x_dofs; ++i)
160  convection(0) += delta_x[i] * psi[i][qp];
161  for (unsigned int i = 0; i != n_y_dofs; ++i)
162  convection(1) += delta_y[i] * psi[i][qp];
163  for (unsigned int i = 0; i != n_z_dofs; ++i)
164  convection(2) += delta_z[i] * psi[i][qp];
165 
166  for (unsigned int i = 0; i != n_u_dofs; ++i)
167  {
168  Number JxWxPhiI = JxW[qp] * phi[i][qp];
169  Fu(i) += (convection * grad_u) * JxWxPhiI;
170  if (request_jacobian)
171  {
172  Number JxWxPhiI = JxW[qp] * phi[i][qp];
173  for (unsigned int j = 0; j != n_u_dofs; ++j)
174  Kuu(i,j) += JxWxPhiI * (convection * dphi[j][qp]);
175 
176  Number JxWxPhiIoverDT = JxWxPhiI/this->deltat;
177 
178  Number JxWxPhiIxDUDXoverDT = JxWxPhiIoverDT * grad_u(0);
179  for (unsigned int j = 0; j != n_x_dofs; ++j)
180  (*Kux)(i,j) += JxWxPhiIxDUDXoverDT * psi[j][qp];
181 
182  Number JxWxPhiIxDUDYoverDT = JxWxPhiIoverDT * grad_u(1);
183  for (unsigned int j = 0; j != n_y_dofs; ++j)
184  (*Kuy)(i,j) += JxWxPhiIxDUDYoverDT * psi[j][qp];
185 
186  Number JxWxPhiIxDUDZoverDT = JxWxPhiIoverDT * grad_u(2);
187  for (unsigned int j = 0; j != n_z_dofs; ++j)
188  (*Kuz)(i,j) += JxWxPhiIxDUDZoverDT * psi[j][qp];
189  }
190  }
191  }
192  }
193 #endif // 0
194 
195  return request_jacobian;
196 }
T libmesh_real(T a)
RealVectorValue RealGradient
unsigned int _mesh_x_var
Variables from which to acquire moving mesh information.
Definition: diff_physics.h:536
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:303
System * _mesh_sys
System from which to acquire moving mesh information.
Definition: diff_physics.h:531
NumberVectorValue Gradient
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
bool is_time_evolving(unsigned int var) const
Definition: diff_physics.h:260

◆ 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, and SolidSystem.

Definition at line 277 of file diff_physics.h.

Referenced by libMesh::DifferentiablePhysics::_eulerian_time_deriv().

279  {
280  return request_jacobian;
281  }

◆ finalize_derivative()

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.

Definition at line 53 of file diff_qoi.C.

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

54 {
55  // by default, do nothing
56 }

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

References 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_qoi_values(), libMesh::System::get_sensitivity_solution(), libMesh::QoISet::has_index(), libMesh::make_range(), libMesh::ImplicitSystem::matrix, libMesh::System::n_qois(), libMesh::Real, libMesh::ExplicitSystem::rhs, libMesh::ImplicitSystem::sensitivity_solve(), libMesh::ParameterVector::size(), and libMesh::TOLERANCE.

Referenced by main().

630 {
631  ParameterVector & parameters_vec =
632  const_cast<ParameterVector &>(parameters_in);
633 
634  const unsigned int Np = cast_int<unsigned int>
635  (parameters_vec.size());
636  const unsigned int Nq = this->n_qois();
637 
638  // An introduction to the problem:
639  //
640  // Residual R(u(p),p) = 0
641  // partial R / partial u = J = system matrix
642  //
643  // This implies that:
644  // d/dp(R) = 0
645  // (partial R / partial p) +
646  // (partial R / partial u) * (partial u / partial p) = 0
647 
648  // We first solve for (partial u / partial p) for each parameter:
649  // J * (partial u / partial p) = - (partial R / partial p)
650 
651  this->sensitivity_solve(parameters_vec);
652 
653  // Get ready to fill in sensitivities:
654  sensitivities.allocate_data(qoi_indices, *this, parameters_vec);
655 
656  // We use the identity:
657  // dq/dp = (partial q / partial p) + (partial q / partial u) *
658  // (partial u / partial p)
659 
660  // We get (partial q / partial u) from the user
661  this->assemble_qoi_derivative(qoi_indices,
662  /* include_liftfunc = */ true,
663  /* apply_constraints = */ false);
664 
665  // We don't need these to be closed() in this function, but libMesh
666  // standard practice is to have them closed() by the time the
667  // function exits
668  for (auto i : make_range(this->n_qois()))
669  if (qoi_indices.has_index(i))
670  this->get_adjoint_rhs(i).close();
671 
672  for (unsigned int j=0; j != Np; ++j)
673  {
674  // We currently get partial derivatives via central differencing
675 
676  // (partial q / partial p) ~= (q(p+dp)-q(p-dp))/(2*dp)
677 
678  Number old_parameter = *parameters_vec[j];
679 
680  const Real delta_p =
681  TOLERANCE * std::max(std::abs(old_parameter), 1e-3);
682 
683  *parameters_vec[j] = old_parameter - delta_p;
684  this->assemble_qoi(qoi_indices);
685  const std::vector<Number> qoi_minus = this->get_qoi_values();
686 
687  *parameters_vec[j] = old_parameter + delta_p;
688  this->assemble_qoi(qoi_indices);
689  const std::vector<Number> qoi_plus = this->get_qoi_values();
690 
691  std::vector<Number> partialq_partialp(Nq, 0);
692  for (unsigned int i=0; i != Nq; ++i)
693  if (qoi_indices.has_index(i))
694  partialq_partialp[i] = (qoi_plus[i] - qoi_minus[i]) / (2.*delta_p);
695 
696  // Don't leave the parameter changed
697  *parameters_vec[j] = old_parameter;
698 
699  for (unsigned int i=0; i != Nq; ++i)
700  if (qoi_indices.has_index(i))
701  sensitivities[i][j] = partialq_partialp[i] +
702  this->get_adjoint_rhs(i).dot(this->get_sensitivity_solution(j));
703  }
704 
705  // All parameters_vec have been reset.
706  // We didn't cache the original rhs or matrix for memory reasons,
707  // but we can restore them to a state consistent solution -
708  // principle of least surprise.
709  this->assembly(true, true);
710  this->rhs->close();
711  this->matrix->close();
712  this->assemble_qoi(qoi_indices);
713 }
static constexpr Real TOLERANCE
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition: system.C:1179
NumericVector< Number > * rhs
The system matrix.
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters) override
Assembles & solves the linear system(s) (dR/du)*u_p = -dR/dp, for those parameters contained within p...
virtual T dot(const NumericVector< T > &v) const =0
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SparseMatrix< Number > * matrix
The system matrix.
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) override
Prepares qoi for quantity of interest assembly, then calls user qoi function.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
Prepares adjoint_rhs for quantity of interest derivative assembly, then calls user qoi derivative fun...
std::vector< Number > get_qoi_values() const
Returns a copy of qoi, not a reference.
Definition: system.C:2186
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1294

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

References libMesh::System::get_vector().

Referenced by libMesh::ImplicitSystem::adjoint_solve(), libMesh::FEMSystem::assemble_qoi_derivative(), 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().

1295 {
1296  std::ostringstream adjoint_rhs_name;
1297  adjoint_rhs_name << "adjoint_rhs" << i;
1298 
1299  return this->get_vector(adjoint_rhs_name.str());
1300 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

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

References libMesh::System::get_vector().

1305 {
1306  std::ostringstream adjoint_rhs_name;
1307  adjoint_rhs_name << "adjoint_rhs" << i;
1308 
1309  return this->get_vector(adjoint_rhs_name.str());
1310 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ get_adjoint_solution() [1/2]

NumericVector< Number > & libMesh::System::get_adjoint_solution ( unsigned int  i = 0)
inherited

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

References libMesh::System::get_vector().

1243 {
1244  std::ostringstream adjoint_name;
1245  adjoint_name << "adjoint_solution" << i;
1246 
1247  return this->get_vector(adjoint_name.str());
1248 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

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

References libMesh::DofMap::get_all_variable_numbers(), and libMesh::System::get_dof_map().

Referenced by MeshFunctionTest::read_variable_info_from_output_data(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), and SystemsTest::testProjectCubeWithMeshFunction().

1404 {
1405  this->get_dof_map().get_all_variable_numbers(all_variable_numbers);
1406 }
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
Fills all_variable_numbers with all the variable numbers for the variables that have been added to th...
Definition: dof_map.C:3380
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ get_constrain_in_solver()

virtual bool libMesh::DifferentiableSystem::get_constrain_in_solver ( )
inlinevirtualinherited

Definition at line 381 of file diff_system.h.

References libMesh::DifferentiableSystem::_constrain_in_solver.

382  {
383  return _constrain_in_solver;
384  }
bool _constrain_in_solver
_constrain_in_solver defaults to true; if false then we apply constraints only via residual terms in ...
Definition: diff_system.h:424

◆ get_constraint_object()

System::Constraint & libMesh::System::get_constraint_object ( )
inherited

Return the user object for imposing constraints.

Definition at line 2019 of file system.C.

References libMesh::System::_constrain_system_object.

2020 {
2021  libmesh_assert_msg(_constrain_system_object,"No constraint object available.");
2022  return *_constrain_system_object;
2023 }
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:2193

◆ 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 2417 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::System::add_matrix(), libMesh::HPCoarsenTest::add_projection(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::System::add_variable(), libMesh::System::add_variable_array(), libMesh::System::add_variables(), libMesh::AdaptiveTimeSolver::adjoint_advance_timestep(), libMesh::UnsteadySolver::adjoint_advance_timestep(), libMesh::ImplicitSystem::adjoint_solve(), libMesh::NewmarkSolver::advance_timestep(), libMesh::AdaptiveTimeSolver::advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), libMesh::EquationSystems::allgather(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), alternative_fe_assembly(), assemble(), LinearElasticity::assemble(), assemble_1D(), AssembleOptimization::assemble_A_and_F(), libMesh::ClawSystem::assemble_advection_matrices(), assemble_and_solve(), libMesh::ClawSystem::assemble_avg_coupling_matrices(), assemble_biharmonic(), libMesh::ClawSystem::assemble_boundary_condition_matrices(), assemble_divgrad(), assemble_elasticity(), assemble_ellipticdg(), assemble_func(), assemble_graddiv(), assemble_helmholtz(), libMesh::ClawSystem::assemble_jump_coupling_matrix(), assemble_laplace(), assemble_mass(), libMesh::ClawSystem::assemble_mass_matrix(), assemble_matrices(), assemble_matrix_and_rhs(), assemble_poisson(), assemble_SchroedingerEquation(), assemble_shell(), assemble_stokes(), assemble_temperature_jump(), assemble_wave(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::PetscDMWrapper::build_sf(), libMesh::System::calculate_norm(), compute_jacobian(), compute_residual(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), MyConstraint::constrain(), libMesh::VariationalSmootherConstraint::constrain_node_to_line(), libMesh::VariationalSmootherConstraint::constrain_node_to_plane(), libMesh::Nemesis_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::Nemesis_IO::copy_nodal_solution(), libMesh::Nemesis_IO::copy_scalar_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::CondensedEigenSystem::copy_sub_to_super(), libMesh::CondensedEigenSystem::copy_super_to_sub(), libMesh::System::create_static_condensation(), libMesh::ImplicitSystem::create_static_condensation_system_matrix(), create_wrapped_function(), DMCreateDomainDecomposition_libMesh(), DMCreateFieldDecomposition_libMesh(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), fe_assembly(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SubFunctor::find_dofs_to_send(), libMesh::VariationalSmootherConstraint::fix_node(), form_functionA(), form_functionB(), form_matrixA(), libMesh::System::get_all_variable_numbers(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::System::get_info(), libMesh::System::has_static_condensation(), libMesh::System::has_variable(), libMesh::System::identify_variable_groups(), libMesh::SystemSubsetBySubdomain::init(), libMesh::SecondOrderUnsteadySolver::init_data(), libMesh::UnsteadySolver::init_data(), HeatSystem::init_data(), SimpleRBConstruction::init_data(), libMesh::ClawSystem::init_data(), LaplaceSystem::init_dirichlet_bcs(), NonManifoldCouplingTestBase::init_es(), libMesh::EigenSystem::init_matrices(), libMesh::System::init_matrices(), libMesh::PetscDMWrapper::init_petscdm(), libMesh::CondensedEigenSystem::initialize_condensed_dofs(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), LaplaceYoung::jacobian(), LargeDeformationElasticity::jacobian(), libMesh::System::late_matrix_init(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_residual(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::System::local_dof_indices(), AssembleOptimization::lower_and_upper_bounds(), main(), libMesh::DofMap::max_constraint_error(), LinearElasticityWithContact::move_mesh(), libMesh::System::n_components(), libMesh::System::n_variable_groups(), libMesh::System::n_vars(), 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::SmoothnessEstimator::EstimateSmoothness::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::RBSCMConstruction::perform_SCM_greedy(), periodic_bc_test_poisson(), 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::InterMeshProjection::project_system_vectors(), libMesh::System::re_update(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), MeshFunctionTest::read_variable_info_from_output_data(), libMesh::SecondOrderUnsteadySolver::reinit(), libMesh::UnsteadySolver::reinit(), libMesh::System::reinit(), libMesh::System::reinit_constraints(), libMesh::EquationSystems::reinit_solutions(), LaplaceYoung::residual(), LargeDeformationElasticity::residual(), LinearElasticityWithContact::residual_and_jacobian(), libMesh::UnsteadySolver::retrieve_timestep(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), libMesh::HPCoarsenTest::select_refinement(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::RBConstruction::set_context_solution_vec(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), libMesh::PetscPreconditioner< T >::set_hypre_ams_data(), libMesh::PetscDMWrapper::set_point_range_in_section(), set_system_parameters(), SlitMeshRefinedSystemTest::setUp(), FETestBase< order, family, elem_type, N_x >::setUp(), SolidSystem::side_time_derivative(), libMesh::NewtonSolver::solve(), libMesh::PetscDiffSolver::solve(), libMesh::EigenSystem::solve(), libMesh::RBConstruction::solve_for_matrix_and_rhs(), SystemsTest::test100KVariables(), ConstraintOperatorTest::test1DCoarseningNewNodes(), ConstraintOperatorTest::test1DCoarseningOperator(), MeshFunctionTest::test_bad_gradient_var_with_out_of_mesh_value(), MeshFunctionTest::test_bad_hessian_var_with_out_of_mesh_value(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), ProjectSolutionTest::test_partial_project_solution(), MeshFunctionTest::test_subdomain_id_sets(), SystemsTest::testBlockRestrictedVarNDofs(), DofMapTest::testConstraintLoopDetection(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), EquationSystemsTest::testDisableDefaultGhosting(), SystemsTest::testDofCouplingWithVarGroups(), DofMapTest::testDofOwner(), MeshInputTest::testDynaReadPatch(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), MeshAssignTest::testMeshMoveAssign(), PeriodicBCTest::testPeriodicBC(), SystemsTest::testPostInitAddVectorTypeChange(), SystemsTest::testProjectCubeWithMeshFunction(), SystemsTest::testProjectMatrix1D(), SystemsTest::testProjectMatrix2D(), SystemsTest::testProjectMatrix3D(), InfFERadialTest::testRefinement(), EquationSystemsTest::testSelectivePRefine(), BoundaryInfoTest::testShellFaceConstraints(), DisjointNeighborTest::testTempJump(), DisjointNeighborTest::testTempJumpRefine(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::BoundaryVolumeSolutionTransfer::transfer_boundary_volume(), libMesh::UnsteadySolver::update(), update_current_local_solution(), libMesh::System::variable(), libMesh::System::variable_group(), libMesh::System::variable_name(), libMesh::System::variable_number(), libMesh::System::variable_scalar_number(), libMesh::System::variable_type(), NonManifoldGhostingFunctorTest::verify_send_list_entries_helper(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), libMesh::ImplicitSystem::weighted_sensitivity_solve(), libMesh::Nemesis_IO_Helper::write_nodal_solution(), libMesh::System::write_parallel_data(), libMesh::EnsightIO::write_scalar_ascii(), libMesh::System::write_SCALAR_dofs(), libMesh::EnsightIO::write_vector_ascii(), and libMesh::RBConstruction::zero_constrained_dofs_on_vector().

2418 {
2419  return *_dof_map;
2420 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225

◆ 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 2425 of file system.h.

References libMesh::System::_dof_map.

2426 {
2427  return *_dof_map;
2428 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225

◆ get_equation_systems() [1/2]

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

Definition at line 767 of file system.h.

References libMesh::System::_equation_systems.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::RBSCMConstruction::add_scaled_symm_Aq(), libMesh::NewmarkSystem::clear(), libMesh::FrequencySystem::clear_all(), compute_jacobian(), compute_residual(), LinearElasticityWithContact::compute_stresses(), SolidSystem::element_time_derivative(), libMesh::RBConstruction::enrich_basis_from_rhs_terms(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::ExactErrorEstimator::find_squared_element_error(), libMesh::ImplicitSystem::get_linear_solve_parameters(), SolidSystem::init_data(), HeatSystem::init_data(), libMesh::FrequencySystem::init_data(), LaplaceYoung::jacobian(), libMesh::RBSCMConstruction::load_matrix_B(), LinearElasticityWithContact::move_mesh(), libMesh::FrequencySystem::n_frequencies(), libMesh::RBSCMConstruction::perform_SCM_greedy(), libMesh::System::point_gradient(), libMesh::System::point_value(), libMesh::InterMeshProjection::project_system_vectors(), libMesh::StaticCondensationDofMap::reinit(), LaplaceYoung::residual(), LinearElasticityWithContact::residual_and_jacobian(), libMesh::FileHistoryData::retrieve_adjoint_solution(), libMesh::FileHistoryData::retrieve_primal_solution(), libMesh::FileHistoryData::rewrite_stored_solution(), SolidSystem::save_initial_mesh(), libMesh::FrequencySystem::set_current_frequency(), libMesh::FrequencySystem::set_frequencies(), libMesh::FrequencySystem::set_frequencies_by_range(), libMesh::FrequencySystem::set_frequencies_by_steps(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), libMesh::PetscPreconditioner< T >::set_hypre_ams_data(), libMesh::NewmarkSystem::set_newmark_parameters(), libMesh::NonlinearImplicitSystem::set_solver_parameters(), SolidSystem::side_time_derivative(), libMesh::EigenSystem::solve(), libMesh::CondensedEigenSystem::solve(), libMesh::FrequencySystem::solve(), libMesh::ClawSystem::solve_conservation_law(), libMesh::RBConstruction::solve_for_matrix_and_rhs(), libMesh::EigenSystem::solve_helper(), libMesh::FileHistoryData::store_adjoint_solution(), libMesh::FileHistoryData::store_initial_solution(), libMesh::FileHistoryData::store_primal_solution(), MeshFunctionTest::test_p_level(), MeshFunctionTest::test_subdomain_id_sets(), MeshAssignTest::testMeshMoveAssign(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::DirectSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::DTKSolutionTransfer::transfer(), libMesh::TransientRBConstruction::truth_solve(), libMesh::RBConstruction::truth_solve(), and libMesh::WrappedFunction< Output >::WrappedFunction().

767 { return _equation_systems; }
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2231

◆ 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 772 of file system.h.

References libMesh::System::_equation_systems.

772 { return _equation_systems; }
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2231

◆ 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 506 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_first_order_vars.

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

507  { return _first_order_vars; }
std::set< unsigned int > _first_order_vars
Variable indices for those variables that are first order in time.
Definition: diff_physics.h:548

◆ 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 & [name, cd] : _counts)
59  oss << "| " << name << " reference count information:\n"
60  << "| Creations: " << cd.first << '\n'
61  << "| Destructions: " << cd.second << '\n';
62 
63  oss << " ---------------------------------------------------------------------------- \n";
64 
65  return oss.str();
66 
67 #else
68 
69  return "";
70 
71 #endif
72 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
static Counts _counts
Actually holds the data.

◆ get_info() [2/2]

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

Definition at line 1822 of file system.C.

References libMesh::ParallelObject::comm(), libMesh::FEType::family, libMesh::System::get_dof_map(), libMesh::DofMap::get_info(), libMesh::DofMap::get_static_condensation(), libMesh::System::has_static_condensation(), libMesh::FEType::inf_map, libMesh::System::is_initialized(), libMesh::make_range(), TIMPI::Communicator::max(), libMesh::System::n_constrained_dofs(), libMesh::DofMapBase::n_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().

Referenced by SystemsTest::testUninitializedInfo().

1823 {
1824  std::ostringstream oss;
1825 
1826 
1827  const std::string & sys_name = this->name();
1828 
1829  oss << " System #" << this->number() << ", \"" << sys_name << "\"\n"
1830  << " Type \"" << this->system_type() << "\"\n"
1831  << " Variables=";
1832 
1833  for (auto vg : make_range(this->n_variable_groups()))
1834  {
1835  const VariableGroup & vg_description (this->variable_group(vg));
1836 
1837  if (vg_description.n_variables() > 1) oss << "{ ";
1838  for (auto vn : make_range(vg_description.n_variables()))
1839  oss << "\"" << vg_description.name(vn) << "\" ";
1840  if (vg_description.n_variables() > 1) oss << "} ";
1841  }
1842 
1843  oss << '\n';
1844 
1845  oss << " Finite Element Types=";
1846 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
1847  for (auto vg : make_range(this->n_variable_groups()))
1848  oss << "\""
1849  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().family)
1850  << "\" ";
1851 #else
1852  for (auto vg : make_range(this->n_variable_groups()))
1853  {
1854  oss << "\""
1855  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().family)
1856  << "\", \""
1857  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().radial_family)
1858  << "\" ";
1859  }
1860 
1861  oss << '\n' << " Infinite Element Mapping=";
1862  for (auto vg : make_range(this->n_variable_groups()))
1863  oss << "\""
1864  << Utility::enum_to_string<InfMapType>(this->get_dof_map().variable_group(vg).type().inf_map)
1865  << "\" ";
1866 #endif
1867 
1868  oss << '\n';
1869 
1870  oss << " Approximation Orders=";
1871  for (auto vg : make_range(this->n_variable_groups()))
1872  {
1873 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
1874  oss << "\""
1875  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().order)
1876  << "\" ";
1877 #else
1878  oss << "\""
1879  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().order)
1880  << "\", \""
1881  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().radial_order)
1882  << "\" ";
1883 #endif
1884  }
1885 
1886  oss << '\n';
1887 
1888  if (this->is_initialized())
1889  {
1890  oss << " n_dofs()=" << this->n_dofs() << '\n';
1891  dof_id_type local_dofs = this->n_local_dofs();
1892  oss << " n_local_dofs()=" << local_dofs << '\n';
1893  this->comm().max(local_dofs);
1894  oss << " max(n_local_dofs())=" << local_dofs << '\n';
1895 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1896  if (this->n_constrained_dofs())
1897  {
1898  oss << " n_constrained_dofs()=" << this->n_constrained_dofs() << '\n';
1899  oss << " n_local_constrained_dofs()=" << this->n_local_constrained_dofs() << '\n';
1900  dof_id_type local_unconstrained_dofs = this->n_local_dofs() - this->n_local_constrained_dofs();
1901  this->comm().max(local_unconstrained_dofs);
1902  oss << " max(local unconstrained dofs)=" << local_unconstrained_dofs << '\n';
1903  }
1904 #endif
1905  if (this->has_static_condensation())
1906  oss << " n uncondensed dofs="
1907  << this->get_dof_map().get_static_condensation().n_dofs() << '\n';
1908  }
1909  else
1910  oss << " (still uninitialized)\n";
1911 
1912  oss << " " << "n_vectors()=" << this->n_vectors() << '\n';
1913  oss << " " << "n_matrices()=" << this->n_matrices() << '\n';
1914  // oss << " " << "n_additional_matrices()=" << this->n_additional_matrices() << '\n';
1915 
1916  oss << this->get_dof_map().get_info();
1917 
1918  return oss.str();
1919 }
bool is_initialized() const
Definition: system.h:2457
FEFamily family
The type of finite element.
Definition: fe_type.h:228
dof_id_type n_dofs() const
Definition: dof_map_base.h:105
OrderWrapper radial_order
The approximation order in radial direction of the infinite element.
Definition: fe_type.h:263
unsigned int n_variable_groups() const
Definition: system.C:2694
const Parallel::Communicator & comm() const
OrderWrapper order
The approximation order of the element (at 0 p-refinement level).
Definition: fe_type.h:203
bool has_static_condensation() const
Definition: system.C:2664
dof_id_type n_local_dofs() const
Definition: system.C:155
std::string get_info() const
Gets summary info about the sparsity bandwidth and constraints.
Definition: dof_map.C:2976
dof_id_type n_dofs() const
Definition: system.C:118
unsigned int number() const
Definition: system.h:2393
StaticCondensationDofMap & get_static_condensation()
Definition: dof_map.h:2859
unsigned int n_vectors() const
Definition: system.h:2499
const VariableGroup & variable_group(const unsigned int c) const
Definition: dof_map.h:2348
InfMapType inf_map
The coordinate mapping type of the infinite element.
Definition: fe_type.h:284
unsigned int n_matrices() const
Definition: system.h:2638
FEFamily radial_family
The type of approximation in radial direction.
Definition: fe_type.h:276
virtual std::string system_type() const
Definition: system.h:510
void max(const T &r, T &o, Request &req) const
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
dof_id_type n_local_constrained_dofs() const
Definition: system.C:140
const std::string & name() const
Definition: system.h:2385
const DofMap & get_dof_map() const
Definition: system.h:2417
const VariableGroup & variable_group(unsigned int vg) const
Return a constant reference to VariableGroup vg.
Definition: system.C:2704
dof_id_type n_constrained_dofs() const
Definition: system.C:125
uint8_t dof_id_type
Definition: id_types.h:67
const FEType & type() const
Definition: variable.h:144

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

References libMesh::libmesh_assert(), and libMesh::DifferentiableSystem::time_solver.

173 {
175  libmesh_assert_equal_to (&(time_solver->system()), this);
176  return std::make_pair(this->time_solver->diff_solver()->max_linear_iterations,
177  this->time_solver->diff_solver()->relative_residual_tolerance);
178 }
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
libmesh_assert(ctx)

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

References libMesh::libmesh_assert(), and libMesh::DifferentiableSystem::time_solver.

Referenced by adjust_linear_solvers(), and main().

164 {
166  libmesh_assert_equal_to (&(time_solver->system()), this);
167  return this->time_solver->linear_solver().get();
168 }
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
libmesh_assert(ctx)

◆ get_matrix() [1/2]

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

Definition at line 1111 of file system.C.

References libMesh::System::_matrices.

Referenced by add_M_C_K_helmholtz(), assemble(), assemble_helmholtz(), assemble_poisson(), libMesh::NewmarkSystem::compute_matrix(), libMesh::ImplicitSystem::get_system_matrix(), main(), libMesh::EigenTimeSolver::solve(), and libMesh::NewmarkSystem::update_rhs().

1112 {
1113  return *libmesh_map_find(_matrices, mat_name);
1114 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ get_matrix() [2/2]

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

Definition at line 1118 of file system.C.

References libMesh::System::_matrices.

1119 {
1120  return *libmesh_map_find(_matrices, mat_name);
1121 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ get_mesh() [1/2]

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

Definition at line 2401 of file system.h.

References libMesh::System::_mesh.

Referenced by libMesh::ExactSolution::_compute_error(), LinearElasticityWithContact::add_contact_edge_elements(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::System::add_matrix(), libMesh::HPCoarsenTest::add_projection(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::DofMap::add_variables(), AssembleOptimization::assemble_A_and_F(), libMesh::ClawSystem::assemble_advection_matrices(), libMesh::ClawSystem::assemble_avg_coupling_matrices(), libMesh::ClawSystem::assemble_boundary_condition_matrices(), libMesh::ClawSystem::assemble_jump_coupling_matrix(), libMesh::ClawSystem::assemble_mass_matrix(), libMesh::FEMSystem::assemble_qoi(), libMesh::FEMSystem::assemble_qoi_derivative(), libMesh::FEMSystem::assembly(), libMesh::VariationalSmootherSystem::assembly(), AssemblyA0::boundary_assembly(), AssemblyA1::boundary_assembly(), AssemblyF0::boundary_assembly(), AssemblyF1::boundary_assembly(), AssemblyA2::boundary_assembly(), AssemblyF2::boundary_assembly(), libMesh::System::calculate_norm(), compute_jacobian(), libMesh::VariationalSmootherSystem::compute_mesh_quality_info(), compute_residual(), LinearElasticityWithContact::compute_stresses(), libMesh::VariationalSmootherConstraint::constrain(), libMesh::VariationalSmootherConstraint::constrain_node_to_line(), libMesh::VariationalSmootherConstraint::constrain_node_to_plane(), libMesh::System::create_static_condensation(), libMesh::ImplicitSystem::create_static_condensation_system_matrix(), libMesh::RBEIMEvaluation::distribute_bfs(), DMCreateDomainDecomposition_libMesh(), DMCreateFieldDecomposition_libMesh(), DMlibMeshSetSystem_libMesh(), SolidSystem::element_time_derivative(), HeatSystem::element_time_derivative(), libMesh::RBConstruction::enrich_basis_from_rhs_terms(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_interiors(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_sides(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::SmoothnessEstimator::estimate_smoothness(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SubFunctor::find_dofs_to_send(), libMesh::VariationalSmootherConstraint::fix_node(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::GenericProjector(), LinearElasticityWithContact::get_least_and_max_gap_function(), libMesh::SystemSubsetBySubdomain::init(), libMesh::RBEIMConstruction::init_context(), SolidSystem::init_data(), libMesh::VariationalSmootherSystem::init_data(), libMesh::System::init_data(), libMesh::System::init_matrices(), libMesh::PetscDMWrapper::init_petscdm(), LinearElasticityWithContact::initialize_contact_load_paths(), libMesh::RBEIMConstruction::initialize_qp_data(), libMesh::System::local_dof_indices(), libMesh::DofMap::max_constraint_error(), libMesh::FEMSystem::mesh_position_get(), libMesh::FEMSystem::mesh_position_set(), LinearElasticityWithContact::move_mesh(), libMesh::System::n_components(), libMesh::RBEIMEvaluation::node_distribute_bfs(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SmoothnessEstimator::EstimateSmoothness::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectVertices::operator()(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::FEMSystem::postprocess(), libMesh::RBParametrizedFunction::preevaluate_parametrized_function_on_mesh(), libMesh::RBParametrizedFunction::preevaluate_parametrized_function_on_mesh_sides(), libMesh::VariationalSmootherSystem::prepare_for_smoothing(), libMesh::System::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::System::read_parallel_data(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::System::reinit(), LinearElasticityWithContact::residual_and_jacobian(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), SolidSystem::save_initial_mesh(), libMesh::HPSingularity::select_refinement(), libMesh::HPCoarsenTest::select_refinement(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), libMesh::PetscPreconditioner< T >::set_hypre_ams_data(), libMesh::PetscPreconditioner< T >::set_petsc_aux_data(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::RBEIMEvaluation::side_distribute_bfs(), SolidSystem::side_time_derivative(), libMesh::PetscDiffSolver::solve(), libMesh::ClawSystem::solve_conservation_law(), MeshAssignTest::testMeshMoveAssign(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::BoundaryVolumeSolutionTransfer::transfer(), libMesh::BoundaryVolumeSolutionTransfer::transfer_boundary_volume(), libMesh::BoundaryVolumeSolutionTransfer::transfer_volume_boundary(), libMesh::TransientRBConstruction::truth_solve(), libMesh::RBConstruction::truth_solve(), libMesh::System::write_header(), libMesh::RBEvaluation::write_out_vectors(), libMesh::System::write_parallel_data(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), and libMesh::System::zero_variable().

2402 {
2403  return _mesh;
2404 }
MeshBase & _mesh
Constant reference to the mesh data structure used for the simulation.
Definition: system.h:2237

◆ get_mesh() [2/2]

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

Definition at line 2409 of file system.h.

References libMesh::System::_mesh.

2410 {
2411  return _mesh;
2412 }
MeshBase & _mesh
Constant reference to the mesh data structure used for the simulation.
Definition: system.h:2237

◆ 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 613 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_sys.

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

614 {
615  return _mesh_sys;
616 }
System * _mesh_sys
System from which to acquire moving mesh information.
Definition: diff_physics.h:531

◆ 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 619 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_sys.

620 {
621  return _mesh_sys;
622 }
System * _mesh_sys
System from which to acquire moving mesh information.
Definition: diff_physics.h:531

◆ 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 625 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_x_var.

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

626 {
627  return _mesh_x_var;
628 }
unsigned int _mesh_x_var
Variables from which to acquire moving mesh information.
Definition: diff_physics.h:536

◆ 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 631 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_y_var.

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

632 {
633  return _mesh_y_var;
634 }

◆ 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 637 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_z_var.

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

638 {
639  return _mesh_z_var;
640 }

◆ get_parameter_value()

Number& CoupledSystem::get_parameter_value ( unsigned int  parameter_index)
inline

Definition at line 51 of file coupled_system.h.

52  {
53  return parameters[parameter_index];
54  }
std::vector< Number > parameters

◆ get_parameter_vector()

ParameterVector& CoupledSystem::get_parameter_vector ( )
inline

Definition at line 56 of file coupled_system.h.

References libMesh::ParameterVector::push_back().

57  {
58  if (!parameter_vector.size())
59  for (std::size_t i = 0; i != parameters.size(); ++i)
61 
62  return parameter_vector;
63  }
std::size_t size() const
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
std::vector< Number > parameters
void push_back(std::unique_ptr< ParameterAccessor< Number >> new_accessor)
Adds an additional parameter accessor to the end of the vector.
ParameterVector parameter_vector

◆ get_Pe()

Real& CoupledSystem::get_Pe ( )
inline

Definition at line 65 of file coupled_system.h.

66  {
67  return Peclet;
68  }

◆ get_physics() [1/2]

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

Definition at line 181 of file diff_system.h.

References libMesh::DifferentiableSystem::_diff_physics.

Referenced by libMesh::EulerSolver::_general_residual(), libMesh::Euler2Solver::_general_residual(), libMesh::SteadySolver::_general_residual(), libMesh::NewmarkSolver::_general_residual(), libMesh::FEMSystem::build_context(), libMesh::EulerSolver::element_residual(), libMesh::Euler2Solver::element_residual(), libMesh::EigenTimeSolver::element_residual(), libMesh::FEMSystem::init_context(), libMesh::EigenTimeSolver::nonlocal_residual(), and libMesh::EigenTimeSolver::side_residual().

182  { if (this->_diff_physics.empty())
183  return this;
184  return this->_diff_physics.top().get(); }
std::stack< std::unique_ptr< DifferentiablePhysics >, std::vector< std::unique_ptr< DifferentiablePhysics > > > _diff_physics
Stack of pointers to objects to use for physics assembly evaluations.
Definition: diff_system.h:434

◆ 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 192 of file diff_system.h.

References libMesh::DifferentiableSystem::_diff_physics.

193  { if (this->_diff_physics.empty())
194  return this;
195  return this->_diff_physics.top().get(); }
std::stack< std::unique_ptr< DifferentiablePhysics >, std::vector< std::unique_ptr< DifferentiablePhysics > > > _diff_physics
Stack of pointers to objects to use for physics assembly evaluations.
Definition: diff_system.h:434

◆ get_project_with_constraints()

bool libMesh::System::get_project_with_constraints ( )
inlineinherited

Setter and getter functions for project_with_constraints boolean.

Definition at line 1837 of file system.h.

References libMesh::System::project_with_constraints.

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

1838  {
1839  return project_with_constraints;
1840  }
bool project_with_constraints
Do we want to apply constraints while projecting vectors ?
Definition: system.h:2343

◆ get_qoi() [1/2]

const DifferentiableQoI* libMesh::DifferentiableSystem::get_qoi ( ) const
inlineinherited
Returns
A const reference to a DifferentiableQoI object.
Note
If no external QoI object is attached, the default is this.

Definition at line 221 of file diff_system.h.

References libMesh::DifferentiableSystem::_diff_qoi.

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

222  { if (this->_diff_qoi.empty())
223  return this;
224  return this->_diff_qoi.top().get(); }
std::stack< std::unique_ptr< DifferentiableQoI >, std::vector< std::unique_ptr< DifferentiableQoI > > > _diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
Definition: diff_system.h:442

◆ get_qoi() [2/2]

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

Definition at line 231 of file diff_system.h.

References libMesh::DifferentiableSystem::_diff_qoi.

232  { if (this->_diff_qoi.empty())
233  return this;
234  return this->_diff_qoi.top().get(); }
std::stack< std::unique_ptr< DifferentiableQoI >, std::vector< std::unique_ptr< DifferentiableQoI > > > _diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
Definition: diff_system.h:442

◆ get_qoi_error_estimate_value()

Number libMesh::System::get_qoi_error_estimate_value ( unsigned int  qoi_index) const
inherited

Definition at line 2206 of file system.C.

References libMesh::System::_qoi_error_estimates, and libMesh::libmesh_assert().

Referenced by libMesh::TwostepTimeSolver::integrate_adjoint_refinement_error_estimate(), and main().

2207 {
2208  libmesh_assert(qoi_index < _qoi_error_estimates.size());
2209  return _qoi_error_estimates[qoi_index];
2210 }
libmesh_assert(ctx)
std::vector< Number > _qoi_error_estimates
Vector to hold error estimates for qois, either from a steady state calculation, or from a single uns...
Definition: system.h:2377

◆ get_QoI_value()

Number& CoupledSystem::get_QoI_value ( )
inline

Definition at line 46 of file coupled_system.h.

47  {
48  return computed_QoI;
49  }

◆ get_qoi_value()

Number libMesh::System::get_qoi_value ( unsigned int  qoi_index) const
inherited

◆ get_qoi_values()

std::vector< Number > libMesh::System::get_qoi_values ( ) const
inherited

Returns a copy of qoi, not a reference.

Definition at line 2186 of file system.C.

References libMesh::System::_qoi.

Referenced by libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity(), libMesh::FEMSystem::assemble_qoi(), libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity(), libMesh::ImplicitSystem::qoi_parameter_hessian(), and libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product().

2187 {
2188  return this->_qoi;
2189 }
std::vector< Number > _qoi
Values of the quantities of interest.
Definition: system.h:2367

◆ get_second_order_dot_var()

unsigned int libMesh::DifferentiableSystem::get_second_order_dot_var ( unsigned int  var) const
inherited

For a given second order (in time) variable var, this method will return the index to the corresponding "dot" variable.

For FirstOrderUnsteadySolver classes, the "dot" variable would automatically be added and the returned index will correspond to that variable. For SecondOrderUnsteadySolver classes, this method will return var as there this is no "dot" variable per se, but having this function allows one to use the interface to treat both FirstOrderUnsteadySolver and SecondOrderUnsteadySolver simultaneously.

Definition at line 288 of file diff_system.C.

References libMesh::DifferentiablePhysics::_second_order_dot_vars, libMesh::UnsteadySolver::time_order(), and libMesh::DifferentiableSystem::time_solver.

Referenced by libMesh::FirstOrderUnsteadySolver::compute_second_order_eqns().

289 {
290  // For SteadySolver or SecondOrderUnsteadySolvers, we just give back var
291  unsigned int dot_var = var;
292 
293  if (!time_solver->is_steady())
294  {
295  const UnsteadySolver & unsteady_solver =
296  cast_ref<const UnsteadySolver &>(*(time_solver.get()));
297 
298  if (unsteady_solver.time_order() == 1)
299  dot_var = this->_second_order_dot_vars.find(var)->second;
300  }
301 
302  return dot_var;
303 }
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
std::map< unsigned int, unsigned int > _second_order_dot_vars
If the user adds any second order variables, then we need to also cache the map to their correspondin...
Definition: diff_physics.h:560

◆ get_second_order_vars()

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

Definition at line 519 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_second_order_vars.

Referenced by libMesh::DifferentiableSystem::add_second_order_dot_vars(), libMesh::DiffContext::DiffContext(), libMesh::Euler2Solver::element_residual(), libMesh::DifferentiableSystem::have_second_order_scalar_vars(), and libMesh::FEMContext::pre_fe_reinit().

520  { return _second_order_vars; }
std::set< unsigned int > _second_order_vars
Variable indices for those variables that are second order in time.
Definition: diff_physics.h:553

◆ get_sensitivity_rhs() [1/2]

NumericVector< Number > & libMesh::System::get_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. By default these vectors are built by the library, using finite differences, when assemble_residual_derivatives() is called.

When assembled, this vector should hold -(partial R / partial p_i)

Definition at line 1324 of file system.C.

References libMesh::System::get_vector().

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

1325 {
1326  std::ostringstream sensitivity_rhs_name;
1327  sensitivity_rhs_name << "sensitivity_rhs" << i;
1328 
1329  return this->get_vector(sensitivity_rhs_name.str());
1330 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ get_sensitivity_rhs() [2/2]

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

Definition at line 1334 of file system.C.

References libMesh::System::get_vector().

1335 {
1336  std::ostringstream sensitivity_rhs_name;
1337  sensitivity_rhs_name << "sensitivity_rhs" << i;
1338 
1339  return this->get_vector(sensitivity_rhs_name.str());
1340 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ get_sensitivity_solution() [1/2]

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

Definition at line 1179 of file system.C.

References libMesh::System::get_vector().

Referenced by libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity(), libMesh::ImplicitSystem::qoi_parameter_hessian(), and libMesh::ImplicitSystem::sensitivity_solve().

1180 {
1181  std::ostringstream sensitivity_name;
1182  sensitivity_name << "sensitivity_solution" << i;
1183 
1184  return this->get_vector(sensitivity_name.str());
1185 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ get_sensitivity_solution() [2/2]

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

Definition at line 1189 of file system.C.

References libMesh::System::get_vector().

1190 {
1191  std::ostringstream sensitivity_name;
1192  sensitivity_name << "sensitivity_solution" << i;
1193 
1194  return this->get_vector(sensitivity_name.str());
1195 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ get_static_condensation()

StaticCondensation & libMesh::ImplicitSystem::get_static_condensation ( )
inlineinherited
Returns
The static condensation system matrix

Definition at line 362 of file implicit_system.h.

References libMesh::ImplicitSystem::_sc_system_matrix, and libMesh::libmesh_assert().

Referenced by assemble_poisson().

363 {
365  return *_sc_system_matrix;
366 }
StaticCondensation * _sc_system_matrix
The system matrix for static condensation problems.
libmesh_assert(ctx)

◆ get_system_matrix() [1/2]

const SparseMatrix< Number > & libMesh::ImplicitSystem::get_system_matrix ( ) const
inherited

◆ get_system_matrix() [2/2]

SparseMatrix< Number > & libMesh::ImplicitSystem::get_system_matrix ( )
inherited
Returns
A reference to the system's primary matrix.

Definition at line 1260 of file implicit_system.C.

References libMesh::System::get_matrix(), libMesh::libmesh_assert(), and libMesh::ImplicitSystem::matrix.

1261 {
1263  libmesh_assert_equal_to(&get_matrix("System Matrix"), matrix);
1264  return *matrix;
1265 }
libmesh_assert(ctx)
SparseMatrix< Number > * matrix
The system matrix.
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
Definition: system.C:1111

◆ get_time_solver() [1/2]

TimeSolver & libMesh::DifferentiableSystem::get_time_solver ( )
inlineinherited
Returns
A pointer to the time solver attached to the calling system

Definition at line 448 of file diff_system.h.

References libMesh::libmesh_assert(), and libMesh::DifferentiableSystem::time_solver.

Referenced by libMesh::DifferentiableSystem::adjoint_solve(), adjust_linear_solvers(), libMesh::FEMSystem::build_context(), libMesh::DiffContext::DiffContext(), libMesh::FEMSystem::postprocess(), libMesh::FEMContext::pre_fe_reinit(), and libMesh::DifferentiableSystem::solve().

449 {
451  libmesh_assert_equal_to (&(time_solver->system()), this);
452  return *time_solver;
453 }
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
libmesh_assert(ctx)

◆ get_time_solver() [2/2]

const TimeSolver & libMesh::DifferentiableSystem::get_time_solver ( ) const
inlineinherited

Non-const version of the above.

Definition at line 456 of file diff_system.h.

References libMesh::libmesh_assert(), and libMesh::DifferentiableSystem::time_solver.

457 {
459  libmesh_assert_equal_to (&(time_solver->system()), this);
460  return *time_solver;
461 }
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
libmesh_assert(ctx)

◆ get_vector() [1/4]

const NumericVector< Number > & libMesh::System::get_vector ( std::string_view  vec_name) const
inherited
Returns
A const reference to this system's additional vector named vec_name. Access is only granted when the vector is already properly initialized.

Definition at line 931 of file system.C.

References libMesh::System::_vectors.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), add_M_C_K_helmholtz(), libMesh::AdaptiveTimeSolver::adjoint_advance_timestep(), libMesh::UnsteadySolver::adjoint_advance_timestep(), libMesh::NewmarkSolver::advance_timestep(), libMesh::AdaptiveTimeSolver::advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), apply_initial(), assemble(), libMesh::System::compare(), libMesh::NewmarkSolver::compute_initial_accel(), libMesh::UnsteadySolver::du(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::System::get_adjoint_rhs(), libMesh::System::get_adjoint_solution(), libMesh::System::get_sensitivity_rhs(), libMesh::System::get_sensitivity_solution(), libMesh::System::get_weighted_sensitivity_adjoint_solution(), libMesh::System::get_weighted_sensitivity_solution(), libMesh::NewmarkSystem::initial_conditions(), AssembleOptimization::lower_and_upper_bounds(), main(), libMesh::NewmarkSolver::project_initial_accel(), libMesh::SecondOrderUnsteadySolver::project_initial_rate(), libMesh::InterMeshProjection::project_system_vectors(), libMesh::SecondOrderUnsteadySolver::reinit(), libMesh::UnsteadySolver::reinit(), libMesh::FileSolutionHistory::retrieve(), libMesh::UnsteadySolver::retrieve_timestep(), libMesh::MemoryHistoryData::retrieve_vectors(), libMesh::TwostepTimeSolver::solve(), libMesh::FrequencySystem::solve(), libMesh::UnsteadySolver::update(), libMesh::NewmarkSystem::update_rhs(), and libMesh::NewmarkSystem::update_u_v_a().

932 {
933  return *(libmesh_map_find(_vectors, vec_name));
934 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ get_vector() [2/4]

NumericVector< Number > & libMesh::System::get_vector ( std::string_view  vec_name)
inherited
Returns
A writable reference to this system's additional vector named vec_name. Access is only granted when the vector is already properly initialized.

Definition at line 938 of file system.C.

References libMesh::System::_vectors.

939 {
940  return *(libmesh_map_find(_vectors, vec_name));
941 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ get_vector() [3/4]

const NumericVector< Number > & libMesh::System::get_vector ( const unsigned int  vec_num) const
inherited
Returns
A const reference to this system's additional vector number vec_num (where the vectors are counted starting with 0).

Definition at line 945 of file system.C.

References libMesh::System::_vectors, and libMesh::System::vectors_begin().

946 {
947  // If we don't have that many vectors, throw an error
948  libmesh_assert_less(vec_num, _vectors.size());
949 
950  // Otherwise return a reference to the vec_num'th vector
951  auto it = vectors_begin();
952  std::advance(it, vec_num);
953  return *(it->second);
954 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2505

◆ get_vector() [4/4]

NumericVector< Number > & libMesh::System::get_vector ( const unsigned int  vec_num)
inherited
Returns
A writable reference to this system's additional vector number vec_num (where the vectors are counted starting with 0).

Definition at line 958 of file system.C.

References libMesh::System::_vectors, and libMesh::System::vectors_begin().

959 {
960  // If we don't have that many vectors, throw an error
961  libmesh_assert_less(vec_num, _vectors.size());
962 
963  // Otherwise return a reference to the vec_num'th vector
964  auto it = vectors_begin();
965  std::advance(it, vec_num);
966  return *(it->second);
967 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2505

◆ get_weighted_sensitivity_adjoint_solution() [1/2]

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

Definition at line 1264 of file system.C.

References libMesh::System::get_vector().

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

1265 {
1266  std::ostringstream adjoint_name;
1267  adjoint_name << "weighted_sensitivity_adjoint_solution" << i;
1268 
1269  return this->get_vector(adjoint_name.str());
1270 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ get_weighted_sensitivity_adjoint_solution() [2/2]

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

Definition at line 1274 of file system.C.

References libMesh::System::get_vector().

1275 {
1276  std::ostringstream adjoint_name;
1277  adjoint_name << "weighted_sensitivity_adjoint_solution" << i;
1278 
1279  return this->get_vector(adjoint_name.str());
1280 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ get_weighted_sensitivity_solution() [1/2]

NumericVector< Number > & libMesh::System::get_weighted_sensitivity_solution ( )
inherited
Returns
A reference to the solution of the last weighted sensitivity solve

Definition at line 1206 of file system.C.

References libMesh::System::get_vector().

Referenced by libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

1207 {
1208  return this->get_vector("weighted_sensitivity_solution");
1209 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ get_weighted_sensitivity_solution() [2/2]

const NumericVector< Number > & libMesh::System::get_weighted_sensitivity_solution ( ) const
inherited
Returns
A reference to the solution of the last weighted sensitivity solve

Definition at line 1213 of file system.C.

References libMesh::System::get_vector().

1214 {
1215  return this->get_vector("weighted_sensitivity_solution");
1216 }
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:931

◆ has_constraint_object()

bool libMesh::System::has_constraint_object ( ) const
inherited
Returns
true if there is a user-defined constraint object attached to this object, false otherwise. Calling System:: get_constraint_object() when there is no user-defined constraint object attached leads to either undefined behavior (dereferencing a nullptr) or an assert (in dbg mode) so you should call this function first unless you are sure there is a user-defined constraint object attached.

Definition at line 2014 of file system.C.

References libMesh::System::_constrain_system_object.

2015 {
2016  return _constrain_system_object != nullptr;
2017 }
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:2193

◆ has_static_condensation()

bool libMesh::System::has_static_condensation ( ) const
inherited

◆ has_variable()

bool libMesh::System::has_variable ( std::string_view  var) const
inherited
Returns
true if a variable named var exists in this System

Definition at line 1393 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::has_variable().

Referenced by libMesh::GMVIO::copy_nodal_solution(), and main().

1394 {
1395  return this->get_dof_map().has_variable(var);
1396 }
bool has_variable(std::string_view var) const
Definition: dof_map.h:2986
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ have_first_order_scalar_vars()

bool libMesh::DifferentiableSystem::have_first_order_scalar_vars ( ) const
inherited

Check for any first order vars that are also belong to FEFamily::SCALAR.

Definition at line 305 of file diff_system.C.

References libMesh::DifferentiablePhysics::get_first_order_vars(), libMesh::DifferentiablePhysics::have_first_order_vars(), libMesh::SCALAR, and libMesh::System::variable().

306 {
307  bool have_first_order_scalar_vars = false;
308 
309  if (this->have_first_order_vars())
310  for (const auto & var : this->get_first_order_vars())
311  if (this->variable(var).type().family == SCALAR)
313 
315 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
const std::set< unsigned int > & get_first_order_vars() const
Definition: diff_physics.h:506
bool have_first_order_scalar_vars() const
Check for any first order vars that are also belong to FEFamily::SCALAR.
Definition: diff_system.C:305

◆ have_first_order_vars()

bool libMesh::DifferentiablePhysics::have_first_order_vars ( ) const
inlineinherited

Definition at line 500 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_first_order_vars.

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

501  { return !_first_order_vars.empty(); }
std::set< unsigned int > _first_order_vars
Variable indices for those variables that are first order in time.
Definition: diff_physics.h:548

◆ have_matrix()

bool libMesh::System::have_matrix ( std::string_view  mat_name) const
inlineinherited
Returns
true if this System has a matrix associated with the given name, false otherwise.

Definition at line 1933 of file system.h.

References libMesh::System::_matrices.

Referenced by libMesh::EigenTimeSolver::init().

1933 { return _matrices.count(mat_name); }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ have_second_order_scalar_vars()

bool libMesh::DifferentiableSystem::have_second_order_scalar_vars ( ) const
inherited

Check for any second order vars that are also belong to FEFamily::SCALAR.

Definition at line 317 of file diff_system.C.

References libMesh::DifferentiablePhysics::get_second_order_vars(), libMesh::DifferentiablePhysics::have_second_order_vars(), libMesh::SCALAR, and libMesh::System::variable().

Referenced by libMesh::EulerSolver::nonlocal_residual(), and libMesh::Euler2Solver::nonlocal_residual().

318 {
319  bool have_second_order_scalar_vars = false;
320 
321  if (this->have_second_order_vars())
322  for (const auto & var : this->get_second_order_vars())
323  if (this->variable(var).type().family == SCALAR)
325 
327 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
const std::set< unsigned int > & get_second_order_vars() const
Definition: diff_physics.h:519
bool have_second_order_scalar_vars() const
Check for any second order vars that are also belong to FEFamily::SCALAR.
Definition: diff_system.C:317

◆ have_second_order_vars()

bool libMesh::DifferentiablePhysics::have_second_order_vars ( ) const
inlineinherited

Definition at line 513 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_second_order_vars.

Referenced by libMesh::EulerSolver::element_residual(), and libMesh::DifferentiableSystem::have_second_order_scalar_vars().

514  { return !_second_order_vars.empty(); }
std::set< unsigned int > _second_order_vars
Variable indices for those variables that are second order in time.
Definition: diff_physics.h:553

◆ have_vector()

bool libMesh::System::have_vector ( std::string_view  vec_name) const
inlineinherited
Returns
true if this System has a vector associated with the given name, false otherwise.

Definition at line 2491 of file system.h.

References libMesh::System::_vectors.

2492 {
2493  return (_vectors.count(vec_name));
2494 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ hide_output()

bool& libMesh::System::hide_output ( )
inlineinherited
Returns
A writable reference to a boolean that determines if this system can be written to file or not. If set to true, then EquationSystems::write will ignore this system.

Definition at line 1852 of file system.h.

References libMesh::System::_hide_output.

Referenced by libMesh::StaticCondensationDofMap::reinit(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), and libMesh::PetscPreconditioner< T >::set_hypre_ams_data().

1852 { return _hide_output; }
bool _hide_output
Are we allowed to write this system to file? If _hide_output is true, then EquationSystems::write wil...
Definition: system.h:2338

◆ identify_variable_groups() [1/2]

bool libMesh::System::identify_variable_groups ( ) const
inherited
Returns
true when VariableGroup structures should be automatically identified, false otherwise.

Definition at line 2679 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::identify_variable_groups().

2680 {
2681  return this->get_dof_map().identify_variable_groups();
2682 }
bool identify_variable_groups() const
Definition: dof_map.h:2951
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ identify_variable_groups() [2/2]

void libMesh::System::identify_variable_groups ( const bool  ivg)
inherited

Toggle automatic VariableGroup identification.

Definition at line 2684 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::identify_variable_groups().

2685 {
2687 }
bool identify_variable_groups() const
Definition: dof_map.h:2951
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 183 of file reference_counter.h.

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

184 {
185  libmesh_try
186  {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189  p.first++;
190  }
191  libmesh_catch (...)
192  {
193  auto stream = libMesh::err.get();
194  stream->exceptions(stream->goodbit); // stream must not throw
195  libMesh::err << "Encountered unrecoverable error while calling "
196  << "ReferenceCounter::increment_constructor_count() "
197  << "for a(n) " << name << " object." << std::endl;
198  std::terminate();
199  }
200 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static Counts _counts
Actually holds the data.
streamT * get()
Rather than implement every ostream/ios/ios_base function, we&#39;ll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:30

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 207 of file reference_counter.h.

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

208 {
209  libmesh_try
210  {
211  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
212  std::pair<unsigned int, unsigned int> & p = _counts[name];
213  p.second++;
214  }
215  libmesh_catch (...)
216  {
217  auto stream = libMesh::err.get();
218  stream->exceptions(stream->goodbit); // stream must not throw
219  libMesh::err << "Encountered unrecoverable error while calling "
220  << "ReferenceCounter::increment_destructor_count() "
221  << "for a(n) " << name << " object." << std::endl;
222  std::terminate();
223  }
224 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static Counts _counts
Actually holds the data.
streamT * get()
Rather than implement every ostream/ios/ios_base function, we&#39;ll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:30

◆ init()

void libMesh::System::init ( )
inherited

Initializes degrees of freedom on the current mesh.

Sets the

Definition at line 196 of file system.C.

References libMesh::System::is_initialized(), libMesh::libmesh_assert(), and libMesh::System::reinit_mesh().

Referenced by libMesh::StaticCondensationDofMap::reinit().

197 {
198  // Calling init() twice on the same system currently works evil
199  // magic, whether done directly or via EquationSystems::read()
200  libmesh_assert(!this->is_initialized());
201 
202  this->reinit_mesh();
203 }
bool is_initialized() const
Definition: system.h:2457
libmesh_assert(ctx)
virtual void reinit_mesh()
Reinitializes the system with a new mesh.
Definition: system.C:289

◆ init_context()

void CoupledSystem::init_context ( DiffContext context)
protectedvirtual

Reimplemented from libMesh::FEMSystem.

Definition at line 174 of file coupled_system.C.

References libMesh::FEMContext::get_element_fe(), libMesh::FEAbstract::get_JxW(), libMesh::FEAbstract::get_nothing(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEMContext::get_side_fe(), and libMesh::FEAbstract::get_xyz().

175 {
176  FEMContext & c = cast_ref<FEMContext &>(context);
177 
178  // We should prerequest all the data
179  // we will need to build the linear system.
180  // Note that the concentration and velocity components
181  // use the same basis.
182  FEBase * u_elem_fe = nullptr;
183  c.get_element_fe(u_var, u_elem_fe);
184  u_elem_fe->get_JxW();
185  u_elem_fe->get_phi();
186  u_elem_fe->get_dphi();
187  u_elem_fe->get_xyz();
188 
189  FEBase * p_elem_fe = nullptr;
190  c.get_element_fe(p_var, p_elem_fe);
191  p_elem_fe->get_phi();
192 
193  FEBase * side_fe = nullptr;
194  c.get_side_fe(u_var, side_fe);
195 
196  side_fe->get_JxW();
197  side_fe->get_phi();
198  side_fe->get_xyz();
199 
200  // Don't waste time on side computations for p
201  FEBase * p_side_fe = nullptr;
202  c.get_side_fe(p_var, p_side_fe);
203  p_side_fe->get_nothing();
204 }
void get_side_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for edge/face (2D/3D) finite element object for variable var for the largest dimension in th...
Definition: fem_context.h:317
unsigned int p_var
unsigned int u_var
virtual_for_inffe const std::vector< Real > & get_JxW() const
Definition: fe_abstract.h:303
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
virtual_for_inffe const std::vector< Point > & get_xyz() const
Definition: fe_abstract.h:280
void get_nothing() const
Definition: fe_abstract.h:269
void get_element_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for interior finite element object for variable var for the largest dimension in the mesh...
Definition: fem_context.h:277
This class forms the foundation from which generic finite elements may be derived.
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:207

◆ init_data()

void CoupledSystem::init_data ( )
protectedvirtual

Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.

Reimplemented from libMesh::FEMSystem.

Definition at line 79 of file coupled_system.C.

References libMesh::FEMSystem::init_data(), libMesh::libmesh_assert(), and libMesh::zero.

80 {
81  // Check the input file for Reynolds number, application type,
82  // approximation type
83  GetPot infile("coupled_system.in");
84  Peclet = infile("Peclet", 1.);
85  unsigned int pressure_p = infile("pressure_p", 1);
86  std::string fe_family = infile("fe_family", std::string("LAGRANGE"));
87 
88  // LBB needs better-than-quadratic velocities for better-than-linear
89  // pressures, and libMesh needs non-Lagrange elements for
90  // better-than-quadratic velocities.
91  libmesh_assert((pressure_p == 1) || (fe_family != "LAGRANGE"));
92 
93  FEFamily fefamily = Utility::string_to_enum<FEFamily>(fe_family);
94 
95  // Add the velocity components "u" & "v". They
96  // will be approximated using second-order approximation.
97  u_var = this->add_variable ("u", static_cast<Order>(pressure_p+1),
98  fefamily);
99  v_var = this->add_variable ("v", static_cast<Order>(pressure_p+1),
100  fefamily);
101 
102  // Add the pressure variable "p". This will
103  // be approximated with a first-order basis,
104  // providing an LBB-stable pressure-velocity pair.
105  p_var = this->add_variable ("p", static_cast<Order>(pressure_p),
106  fefamily);
107 
108  // Add the Concentration variable "C". They will
109  // be approximated using second-order approximation, the same as the velocity components
110  C_var = this->add_variable ("C", static_cast<Order>(pressure_p+1),
111  fefamily);
112 
113  // Tell the system to march velocity and concentration forward in
114  // time, with first order time derivatives, but leave pressure as a
115  // constraint only
116  this->time_evolving(u_var, 1);
117  this->time_evolving(v_var, 1);
118  this->time_evolving(C_var, 1);
119 
120  // Useful debugging options
121  this->verify_analytic_jacobians = infile("verify_analytic_jacobians", 0.);
122 
123  // Set Dirichlet boundary conditions
124  const boundary_id_type left_inlet_id = 0;
125 
126  const boundary_id_type right_inlet_id = 1;
127  std::set<boundary_id_type> right_inlet_bdy;
128  right_inlet_bdy.insert(right_inlet_id);
129 
130  const boundary_id_type outlets_id = 2;
131  std::set<boundary_id_type> outlets_bdy;
132  outlets_bdy.insert(outlets_id);
133 
134  const boundary_id_type wall_id = 3;
135 
136  // The zero and constant functions
138  ConstFunction<Number> one(1);
139 
140  // We need two boundary functions for the inlets, because the signs on the velocities
141  // will be different
142  int velocity_sign = 1;
143  BdyFunction inflow_left(u_var, v_var, -velocity_sign);
144  BdyFunction inflow_right(u_var, v_var, velocity_sign);
145 
146 #ifdef LIBMESH_ENABLE_DIRICHLET
147  // On the walls we will apply the no slip and no penetration boundary condition, u=0, v=0
149  (DirichletBoundary ({wall_id}, {u_var,v_var}, &zero));
150 
151  // On the inlet (left), we apply parabolic inflow boundary conditions for the velocity, u = - (y-2)*(y-3), v=0
152  // and set C = 1
154  (DirichletBoundary ({left_inlet_id}, {u_var,v_var}, &inflow_left));
156  (DirichletBoundary ({left_inlet_id}, {C_var}, &one));
157 
158  // On the inlet (right), we apply parabolic inflow boundary conditions for the velocity, u = (y-2)*(y-3), v=0
159  // and set C = 0
161  (DirichletBoundary (right_inlet_bdy, {u_var,v_var}, &inflow_right));
163  (DirichletBoundary (right_inlet_bdy, {C_var}, &zero));
164 #endif // LIBMESH_ENABLE_DIRICHLET
165 
166  // Note that the remaining boundary conditions are the natural boundary conditions for the concentration
167  // on the wall (grad(c) dot n = 0) and natural boundary conditions for the velocity and the concentration
168  // on the outlets ((grad(velocity) dot n - p n) dot t = 0, grad(C) dot n = 0)
169 
170  // Do the parent's initialization after variables and boundary constraints are defined
171  FEMSystem::init_data();
172 }
Real verify_analytic_jacobians
If verify_analytic_jacobian is equal to zero (as it is by default), no numeric jacobians will be calc...
Definition: fem_system.h:215
ConstFunction that simply returns 0.
Definition: zero_function.h:38
unsigned int v_var
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
unsigned int p_var
virtual void time_evolving(unsigned int var, unsigned int order)
Tells the DiffSystem that variable var is evolving with respect to time.
Definition: diff_physics.C:42
const Number zero
.
Definition: libmesh.h:297
unsigned int u_var
int8_t boundary_id_type
Definition: id_types.h:51
libmesh_assert(ctx)
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1344
Function that returns a single value that never changes.
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
unsigned int C_var
FEFamily
defines an enum for finite element families.
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ init_matrices()

void libMesh::System::init_matrices ( )
protectedvirtualinherited

Initializes the matrices associated with this system.

Reimplemented in libMesh::EigenSystem.

Definition at line 311 of file system.C.

References libMesh::System::_matrices, libMesh::System::_matrices_initialized, libMesh::System::_matrix_types, libMesh::System::_prefer_hash_table_matrix_assembly, libMesh::System::_require_sparsity_pattern, libMesh::DofMap::attach_matrix(), libMesh::DofMap::compute_sparsity(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::SparseMatrix< T >::initialized(), libMesh::DofMap::is_attached(), libMesh::libmesh_assert(), and libMesh::System::name().

Referenced by libMesh::System::init_data(), and libMesh::EigenSystem::init_matrices().

312 {
313  parallel_object_only();
314 
315  // No matrices to init
316  if (_matrices.empty())
317  {
318  // any future matrices to be added will need their own
319  // initialization
320  _matrices_initialized = true;
321 
322  return;
323  }
324 
325  // Check for quick return in case the first matrix
326  // (and by extension all the matrices) has already
327  // been initialized
328  if (_matrices.begin()->second->initialized())
329  {
331  return;
332  }
333 
334  _matrices_initialized = true;
335 
336  // Tell the matrices about the dof map, and vice versa
337  for (auto & pr : _matrices)
338  {
339  SparseMatrix<Number> & m = *(pr.second);
340  libmesh_assert (!m.initialized());
341 
342  // We want to allow repeated init() on systems, but we don't
343  // want to attach the same matrix to the DofMap twice
344  if (!this->get_dof_map().is_attached(m))
345  this->get_dof_map().attach_matrix(m);
346 
347  // If the user has already explicitly requested that this matrix use a hash table, then we
348  // always honor that
349  const bool use_hash =
350  pr.second->use_hash_table() ||
351  (this->_prefer_hash_table_matrix_assembly && pr.second->supports_hash_table());
352  pr.second->use_hash_table(use_hash);
353  // Make this call after we've determined whether the matrix is using a hash table
354  if (pr.second->require_sparsity_pattern())
355  this->_require_sparsity_pattern = true;
356  }
357 
358  // Compute the sparsity pattern for the current
359  // mesh and DOF distribution. This also updates
360  // additional matrices, \p DofMap now knows them
361  if (this->_require_sparsity_pattern)
362  this->get_dof_map().compute_sparsity(this->get_mesh());
363 
364  // Initialize matrices and set to zero
365  for (auto & [name, mat] : _matrices)
366  {
367  mat->init(_matrix_types[name]);
368  mat->zero();
369  }
370 }
bool is_attached(SparseMatrix< Number > &matrix)
Matrices should not be attached more than once.
Definition: dof_map.C:295
void attach_matrix(SparseMatrix< Number > &matrix)
Additional matrices may be attached to this DofMap.
Definition: dof_map.C:240
const MeshBase & get_mesh() const
Definition: system.h:2401
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277
bool _prefer_hash_table_matrix_assembly
Whether to use hash table matrix assembly if the matrix sub-classes support it.
Definition: system.h:2348
libmesh_assert(ctx)
std::map< std::string, ParallelType, std::less<> > _matrix_types
Holds the types of the matrices.
Definition: system.h:2282
template class LIBMESH_EXPORT SparseMatrix< Number >
bool _matrices_initialized
false when additional matrices being added require initialization, true otherwise.
Definition: system.h:2287
bool _require_sparsity_pattern
Whether any of our matrices require an initial sparsity pattern computation in order to determine pre...
Definition: system.h:2353
const std::string & name() const
Definition: system.h:2385
void compute_sparsity(const MeshBase &)
Computes the sparsity pattern for the matrices corresponding to proc_id and sends that data to Linear...
Definition: dof_map.C:1951
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ init_physics()

void libMesh::DifferentiablePhysics::init_physics ( const System sys)
virtualinherited

Initialize any data structures associated with the physics.

Definition at line 36 of file diff_physics.C.

References libMesh::DifferentiablePhysics::_time_evolving, and libMesh::System::n_vars().

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

37 {
38  // give us flags for every variable that might be time evolving
39  _time_evolving.resize(sys.n_vars(), false);
40 }
std::vector< unsigned int > _time_evolving
Stores unsigned int to tell us which variables are evolving as first order in time (1)...
Definition: diff_physics.h:543

◆ init_qoi_count()

virtual void libMesh::DifferentiableQoI::init_qoi_count ( System )
inlinevirtualinherited

Initialize system qoi.

Often this will just call sys.init_qois(some_desired_number_of_qois)

Reimplemented in LaplaceQoI, and CoupledSystemQoI.

Definition at line 71 of file diff_qoi.h.

71 {}

◆ init_qois()

void libMesh::System::init_qois ( unsigned int  n_qois)
inherited

Accessors for qoi and qoi_error_estimates vectors.

Definition at line 2164 of file system.C.

References libMesh::System::_qoi, libMesh::System::_qoi_error_estimates, and libMesh::System::n_qois().

Referenced by CoupledSystemQoI::init_qoi_count(), LaplaceQoI::init_qoi_count(), and main().

2165 {
2166  _qoi.resize(n_qois);
2167  _qoi_error_estimates.resize(n_qois);
2168 }
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
std::vector< Number > _qoi
Values of the quantities of interest.
Definition: system.h:2367
std::vector< Number > _qoi_error_estimates
Vector to hold error estimates for qois, either from a steady state calculation, or from a single uns...
Definition: system.h:2377

◆ is_adjoint_already_solved()

bool libMesh::System::is_adjoint_already_solved ( ) const
inlineinherited

Accessor for the adjoint_already_solved boolean.

Definition at line 411 of file system.h.

References libMesh::System::adjoint_already_solved.

Referenced by libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::ImplicitSystem::qoi_parameter_hessian(), and libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product().

412  { return adjoint_already_solved;}
bool adjoint_already_solved
Has the adjoint problem already been solved? If the user sets adjoint_already_solved to true...
Definition: system.h:2332

◆ is_first_order_var()

bool libMesh::DifferentiablePhysics::is_first_order_var ( unsigned int  var) const
inlineinherited

Definition at line 509 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_first_order_vars.

510  { return _first_order_vars.find(var) != _first_order_vars.end(); }
std::set< unsigned int > _first_order_vars
Variable indices for those variables that are first order in time.
Definition: diff_physics.h:548

◆ is_initialized()

bool libMesh::System::is_initialized ( ) const
inlineinherited
Returns
true iff this system has been initialized.

Definition at line 2457 of file system.h.

References libMesh::System::_is_initialized.

Referenced by libMesh::DofMap::add_variable(), libMesh::DofMap::add_variables(), libMesh::System::get_info(), libMesh::System::init(), and libMesh::StaticCondensationDofMap::reinit().

2458 {
2459  return _is_initialized;
2460 }
bool _is_initialized
true when additional vectors and variables do not require immediate initialization, false otherwise.
Definition: system.h:2306

◆ is_second_order_var()

bool libMesh::DifferentiablePhysics::is_second_order_var ( unsigned int  var) const
inlineinherited

Definition at line 522 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_second_order_vars.

Referenced by libMesh::FirstOrderUnsteadySolver::compute_second_order_eqns().

523  { return _second_order_vars.find(var) != _second_order_vars.end(); }
std::set< unsigned int > _second_order_vars
Variable indices for those variables that are second order in time.
Definition: diff_physics.h:553

◆ is_time_evolving()

bool libMesh::DifferentiablePhysics::is_time_evolving ( unsigned int  var) const
inlineinherited
Returns
true iff variable var is evolving with respect to time. In general, the user's init() function should have set time_evolving() for any variables which behave like du/dt = F(u), and should not call time_evolving() for any variables which behave like 0 = G(u).

Definition at line 260 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_time_evolving, and libMesh::libmesh_assert().

Referenced by libMesh::FEMPhysics::eulerian_residual(), libMesh::FEMSystem::init_context(), libMesh::FEMPhysics::mass_residual(), and libMesh::DifferentiablePhysics::nonlocal_mass_residual().

261  {
262  libmesh_assert_less(var,_time_evolving.size());
263  libmesh_assert( _time_evolving[var] == 0 ||
264  _time_evolving[var] == 1 ||
265  _time_evolving[var] == 2 );
266  return _time_evolving[var];
267  }
libmesh_assert(ctx)
std::vector< unsigned int > _time_evolving
Stores unsigned int to tell us which variables are evolving as first order in time (1)...
Definition: diff_physics.h:543

◆ local_dof_indices()

void libMesh::System::local_dof_indices ( const unsigned int  var,
std::set< dof_id_type > &  var_indices 
) const
inherited

Fills the std::set with the degrees of freedom on the local processor corresponding the the variable number passed in.

Definition at line 1409 of file system.C.

References libMesh::DofMap::dof_indices(), libMesh::DofMapBase::end_dof(), libMesh::DofMapBase::first_dof(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), and libMesh::libmesh_assert().

Referenced by libMesh::System::discrete_var_norm(), SystemsTest::testBlockRestrictedVarNDofs(), and libMesh::DirectSolutionTransfer::transfer().

1411 {
1412  // Make sure the set is clear
1413  var_indices.clear();
1414 
1415  std::vector<dof_id_type> dof_indices;
1416 
1417  const dof_id_type
1418  first_local = this->get_dof_map().first_dof(),
1419  end_local = this->get_dof_map().end_dof();
1420 
1421  // Begin the loop over the elements
1422  for (const auto & elem : this->get_mesh().active_local_element_ptr_range())
1423  {
1424  this->get_dof_map().dof_indices (elem, dof_indices, var);
1425 
1426  for (dof_id_type dof : dof_indices)
1427  //If the dof is owned by the local processor
1428  if (first_local <= dof && dof < end_local)
1429  var_indices.insert(dof);
1430  }
1431 
1432  // we may have missed assigning DOFs to nodes that we own
1433  // but to which we have no connected elements matching our
1434  // variable restriction criterion. this will happen, for example,
1435  // if variable V is restricted to subdomain S. We may not own
1436  // any elements which live in S, but we may own nodes which are
1437  // *connected* to elements which do.
1438  for (const auto & node : this->get_mesh().local_node_ptr_range())
1439  {
1440  libmesh_assert(node);
1441  this->get_dof_map().dof_indices (node, dof_indices, var);
1442  for (auto dof : dof_indices)
1443  if (first_local <= dof && dof < end_local)
1444  var_indices.insert(dof);
1445  }
1446 }
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map_base.h:191
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition: dof_map.C:2192
const MeshBase & get_mesh() const
Definition: system.h:2401
libmesh_assert(ctx)
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map_base.h:185
const DofMap & get_dof_map() const
Definition: system.h:2417
uint8_t dof_id_type
Definition: id_types.h:67

◆ mass_residual() [1/2]

bool libMesh::FEMPhysics::mass_residual ( bool  request_jacobian,
DiffContext c 
)
overridevirtualinherited

Subtracts a mass vector contribution on elem from 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.

Many problems can use the reimplementation in FEMPhysics::mass_residual which subtracts (du/dt,v) for each transient variable u; users with more complicated transient problems will need to reimplement this themselves.

Reimplemented from libMesh::DifferentiablePhysics.

Reimplemented in SecondOrderScalarSystemFirstOrderTimeSolverBase, SecondOrderScalarSystemSecondOrderTimeSolverBase, FirstOrderScalarSystemBase, ElasticitySystem, ElasticitySystem, and NavierSystem.

Definition at line 200 of file fem_physics.C.

References libMesh::DiffContext::elem_solution_rate_derivative, libMesh::DiffContext::get_dof_indices(), libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::FEMContext::get_element_fe(), libMesh::FEMContext::get_element_qrule(), libMesh::FEAbstract::get_JxW(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEMContext::interior_rate(), libMesh::DifferentiablePhysics::is_time_evolving(), libMesh::make_range(), libMesh::QBase::n_points(), and libMesh::DiffContext::n_vars().

202 {
203  FEMContext & context = cast_ref<FEMContext &>(c);
204 
205  unsigned int n_qpoints = context.get_element_qrule().n_points();
206 
207  for (auto var : make_range(context.n_vars()))
208  {
209  if (!this->is_time_evolving(var))
210  continue;
211 
212  FEBase * elem_fe = nullptr;
213  context.get_element_fe( var, elem_fe );
214 
215  const std::vector<Real> & JxW = elem_fe->get_JxW();
216 
217  const std::vector<std::vector<Real>> & phi = elem_fe->get_phi();
218 
219  const unsigned int n_dofs = cast_int<unsigned int>
220  (context.get_dof_indices(var).size());
221 
222  DenseSubVector<Number> & Fu = context.get_elem_residual(var);
223  DenseSubMatrix<Number> & Kuu = context.get_elem_jacobian( var, var );
224 
225  for (unsigned int qp = 0; qp != n_qpoints; ++qp)
226  {
227  Number uprime;
228  context.interior_rate(var, qp, uprime);
229  const Number JxWxU = JxW[qp] * uprime;
230  for (unsigned int i = 0; i != n_dofs; ++i)
231  {
232  Fu(i) -= JxWxU * phi[i][qp];
233  if (request_jacobian && context.elem_solution_rate_derivative)
234  {
235  const Number JxWxPhiIxDeriv = JxW[qp] * phi[i][qp] *
236  context.elem_solution_rate_derivative;
237  Kuu(i,i) -= JxWxPhiIxDeriv * phi[i][qp];
238  for (unsigned int j = i+1; j < n_dofs; ++j)
239  {
240  const Number Kij = JxWxPhiIxDeriv * phi[j][qp];
241  Kuu(i,j) -= Kij;
242  Kuu(j,i) -= Kij;
243  }
244  }
245  }
246  }
247  }
248 
249  return request_jacobian;
250 }
FEGenericBase< Real > FEBase
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
bool is_time_evolving(unsigned int var) const
Definition: diff_physics.h:260

◆ mass_residual() [2/2]

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

Subtracts a mass vector contribution on elem from elem_residual.

For first-order-in-time problems, this is the \( M(u,\dot{u})\dot{u} \) term. For second-order-in-time problems, this is the \( M(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.

Many first-order-in-time problems can use the reimplementation in FEMPhysics::mass_residual which subtracts (du/dt,v) for each transient variable u; users with more complicated transient problems or second-order-in-time problems will need to reimplement this themselves.

Reimplemented in SecondOrderScalarSystemFirstOrderTimeSolverBase, SecondOrderScalarSystemSecondOrderTimeSolverBase, FirstOrderScalarSystemBase, libMesh::FEMPhysics, ElasticitySystem, ElasticitySystem, and NavierSystem.

Definition at line 302 of file diff_physics.h.

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

304  {
305  return request_jacobian;
306  }

◆ matrices_begin() [1/2]

System::matrices_iterator libMesh::System::matrices_begin ( )
inlineinherited

Beginning of matrices container.

Definition at line 2529 of file system.h.

References libMesh::System::_matrices.

2530 {
2531  return _matrices.begin();
2532 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ matrices_begin() [2/2]

System::const_matrices_iterator libMesh::System::matrices_begin ( ) const
inlineinherited

Beginning of matrices container.

Definition at line 2535 of file system.h.

References libMesh::System::_matrices.

2536 {
2537  return _matrices.begin();
2538 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ matrices_end() [1/2]

System::matrices_iterator libMesh::System::matrices_end ( )
inlineinherited

End of matrices container.

Definition at line 2541 of file system.h.

References libMesh::System::_matrices.

2542 {
2543  return _matrices.end();
2544 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ matrices_end() [2/2]

System::const_matrices_iterator libMesh::System::matrices_end ( ) const
inlineinherited

End of matrices container.

Definition at line 2547 of file system.h.

References libMesh::System::_matrices.

2548 {
2549  return _matrices.end();
2550 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ mesh_position_get()

void FEMSystem::mesh_position_get ( )
inherited

Tells the FEMSystem to set the degree of freedom coefficients which should correspond to mesh nodal coordinates.

Definition at line 1423 of file fem_system.C.

References libMesh::DifferentiablePhysics::_mesh_sys, libMesh::DifferentiablePhysics::_mesh_x_var, libMesh::DifferentiablePhysics::_mesh_y_var, libMesh::DifferentiablePhysics::_mesh_z_var, libMesh::FEMSystem::build_context(), libMesh::FEMContext::elem_position_get(), libMesh::DiffContext::get_dof_indices(), libMesh::DiffContext::get_elem_solution(), libMesh::System::get_mesh(), libMesh::FEMSystem::init_context(), libMesh::invalid_uint, mesh, libMesh::FEMContext::pre_fe_reinit(), libMesh::System::solution, and libMesh::System::update().

Referenced by SolidSystem::init_data().

1424 {
1425  // This function makes no sense unless we've already picked out some
1426  // variable(s) to reflect mesh position coordinates
1427  libmesh_error_msg_if(!_mesh_sys, "_mesh_sys was nullptr!");
1428 
1429  // We currently assume mesh variables are in our own system
1430  if (_mesh_sys != this)
1431  libmesh_not_implemented();
1432 
1433  // Loop over every active mesh element on this processor
1434  const MeshBase & mesh = this->get_mesh();
1435 
1436  std::unique_ptr<DiffContext> con = this->build_context();
1437  FEMContext & _femcontext = cast_ref<FEMContext &>(*con);
1438  this->init_context(_femcontext);
1439 
1440  // Get the solution's mesh variables from every element
1441  for (const auto & elem : mesh.active_local_element_ptr_range())
1442  {
1443  _femcontext.pre_fe_reinit(*this, elem);
1444 
1445  _femcontext.elem_position_get();
1446 
1448  this->solution->insert(_femcontext.get_elem_solution(_mesh_x_var),
1449  _femcontext.get_dof_indices(_mesh_x_var) );
1451  this->solution->insert(_femcontext.get_elem_solution(_mesh_y_var),
1452  _femcontext.get_dof_indices(_mesh_y_var));
1454  this->solution->insert(_femcontext.get_elem_solution(_mesh_z_var),
1455  _femcontext.get_dof_indices(_mesh_z_var));
1456  }
1457 
1458  this->solution->close();
1459 
1460  // And make sure the current_local_solution is up to date too
1461  this->System::update();
1462 }
virtual std::unique_ptr< DiffContext > build_context() override
Builds a FEMContext object with enough information to do evaluations on each element.
Definition: fem_system.C:1346
unsigned int _mesh_x_var
Variables from which to acquire moving mesh information.
Definition: diff_physics.h:536
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
Definition: fem_context.C:1683
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:303
virtual void init_context(DiffContext &) override
Definition: fem_system.C:1370
MeshBase & mesh
void elem_position_get()
Uses the geometry of elem to set the coordinate data specified by mesh_*_position configuration...
Definition: fem_context.C:1526
const MeshBase & get_mesh() const
Definition: system.h:2401
This is the MeshBase class.
Definition: mesh_base.h:85
const DenseVector< Number > & get_elem_solution() const
Accessor for element solution.
Definition: diff_context.h:112
System * _mesh_sys
System from which to acquire moving mesh information.
Definition: diff_physics.h:531
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Definition: diff_context.h:363
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:498

◆ mesh_position_set()

void FEMSystem::mesh_position_set ( )
inherited

Tells the FEMSystem to set the mesh nodal coordinates which should correspond to degree of freedom coefficients.

Definition at line 1087 of file fem_system.C.

References libMesh::DifferentiablePhysics::_mesh_sys, libMesh::FEMSystem::build_context(), libMesh::ParallelObject::comm(), libMesh::FEMContext::elem_fe_reinit(), libMesh::FEMContext::elem_position_set(), libMesh::FEMContext::get_elem(), libMesh::System::get_mesh(), libMesh::Elem::has_children(), libMesh::FEMSystem::init_context(), libMesh::libmesh_assert(), mesh, libMesh::FEMContext::pre_fe_reinit(), and libMesh::Parallel::sync_dofobject_data_by_id().

Referenced by libMesh::FEMSystem::solve(), and SolidSystem::update().

1088 {
1089  // If we don't need to move the mesh, we're done
1090  if (_mesh_sys != this)
1091  return;
1092 
1093  MeshBase & mesh = this->get_mesh();
1094 
1095  std::unique_ptr<DiffContext> con = this->build_context();
1096  FEMContext & _femcontext = cast_ref<FEMContext &>(*con);
1097  this->init_context(_femcontext);
1098 
1099  // Move every mesh element we can
1100  for (const auto & elem : mesh.active_local_element_ptr_range())
1101  {
1102  // We need the algebraic data
1103  _femcontext.pre_fe_reinit(*this, elem);
1104  // And when asserts are on, we also need the FE so
1105  // we can assert that the mesh data is of the right type.
1106 #ifndef NDEBUG
1107  _femcontext.elem_fe_reinit();
1108 #endif
1109 
1110  // This code won't handle moving subactive elements
1111  libmesh_assert(!_femcontext.get_elem().has_children());
1112 
1113  _femcontext.elem_position_set(1.);
1114  }
1115 
1116  // We've now got positions set on all local nodes (and some
1117  // semilocal nodes); let's request positions for non-local nodes
1118  // from their processors.
1119 
1120  SyncNodalPositions sync_object(mesh);
1122  (this->comm(), mesh.nodes_begin(), mesh.nodes_end(), sync_object);
1123 }
virtual std::unique_ptr< DiffContext > build_context() override
Builds a FEMContext object with enough information to do evaluations on each element.
Definition: fem_system.C:1346
void elem_position_set(Real theta)
Uses the coordinate data specified by mesh_*_position configuration to set the geometry of elem to th...
Definition: fem_context.h:1270
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
Definition: fem_context.C:1683
const Elem & get_elem() const
Accessor for current Elem object.
Definition: fem_context.h:908
virtual void init_context(DiffContext &) override
Definition: fem_system.C:1370
MeshBase & mesh
const Parallel::Communicator & comm() const
const MeshBase & get_mesh() const
Definition: system.h:2401
This is the MeshBase class.
Definition: mesh_base.h:85
virtual void elem_fe_reinit(const std::vector< Point > *const pts=nullptr)
Reinitializes interior FE objects on the current geometric element.
Definition: fem_context.C:1476
System * _mesh_sys
System from which to acquire moving mesh information.
Definition: diff_physics.h:531
libmesh_assert(ctx)
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
Request data about a range of ghost dofobjects uniquely identified by their id.
bool has_children() const
Definition: elem.h:2993

◆ n_active_dofs()

dof_id_type libMesh::System::n_active_dofs ( ) const
inlineinherited
Returns
The number of active degrees of freedom for this System.

Definition at line 2483 of file system.h.

References libMesh::System::n_constrained_dofs(), and libMesh::System::n_dofs().

2484 {
2485  return this->n_dofs() - this->n_constrained_dofs();
2486 }
dof_id_type n_dofs() const
Definition: system.C:118
dof_id_type n_constrained_dofs() const
Definition: system.C:125

◆ n_components()

unsigned int libMesh::System::n_components ( ) const
inherited
Returns
The total number of scalar components in the system's variables. This will equal n_vars() in the case of all scalar-valued variables.

Definition at line 2689 of file system.C.

References libMesh::System::get_dof_map(), libMesh::System::get_mesh(), and libMesh::DofMap::n_components().

2690 {
2691  return this->get_dof_map().n_components(this->get_mesh());
2692 }
unsigned int n_components(const MeshBase &mesh) const
Definition: dof_map.h:2963
const MeshBase & get_mesh() const
Definition: system.h:2401
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ n_constrained_dofs()

dof_id_type libMesh::System::n_constrained_dofs ( ) const
inherited
Returns
The total number of constrained degrees of freedom in the system.

Definition at line 125 of file system.C.

References libMesh::System::_dof_map.

Referenced by form_functionA(), form_functionB(), form_matrixA(), libMesh::System::get_info(), libMesh::System::n_active_dofs(), libMesh::EigenSystem::solve(), and BoundaryInfoTest::testShellFaceConstraints().

126 {
127 #ifdef LIBMESH_ENABLE_CONSTRAINTS
128 
129  return _dof_map->n_constrained_dofs();
130 
131 #else
132 
133  return 0;
134 
135 #endif
136 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225

◆ n_dofs()

dof_id_type libMesh::System::n_dofs ( ) const
inherited
Returns
The number of degrees of freedom in the system

Definition at line 118 of file system.C.

References libMesh::System::_dof_map.

Referenced by libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::System::add_vector(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::ClawSystem::assemble_avg_coupling_matrices(), libMesh::ClawSystem::assemble_boundary_condition_matrices(), libMesh::AdvectionSystem::assemble_claw_rhs(), libMesh::ClawSystem::assemble_jump_coupling_matrix(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::System::get_info(), libMesh::SecondOrderUnsteadySolver::init_data(), libMesh::AdvectionSystem::init_data(), libMesh::UnsteadySolver::init_data(), libMesh::System::init_data(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), main(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::System::n_active_dofs(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::FEMSystem::numerical_jacobian(), libMesh::RBSCMConstruction::perform_SCM_greedy(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), MeshFunctionTest::read_variable_info_from_output_data(), libMesh::SecondOrderUnsteadySolver::reinit(), libMesh::UnsteadySolver::reinit(), libMesh::System::restrict_vectors(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), libMesh::PetscPreconditioner< T >::set_hypre_ams_data(), libMesh::ClawSystem::solve_conservation_law(), SystemsTest::test100KVariables(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), SystemsTest::testPostInitAddVector(), SystemsTest::testPostInitAddVectorTypeChange(), SystemsTest::testProjectCubeWithMeshFunction(), SystemsTest::testProjectMatrix1D(), SystemsTest::testProjectMatrix2D(), SystemsTest::testProjectMatrix3D(), libMesh::RBConstruction::train_reduced_basis_with_POD(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), and libMesh::RBConstruction::update_residual_terms().

119 {
120  return _dof_map->n_dofs();
121 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225

◆ n_local_constrained_dofs()

dof_id_type libMesh::System::n_local_constrained_dofs ( ) const
inherited
Returns
The number of constrained degrees of freedom on this processor.

Definition at line 140 of file system.C.

References libMesh::System::_dof_map.

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

141 {
142 #ifdef LIBMESH_ENABLE_CONSTRAINTS
143 
144  return _dof_map->n_local_constrained_dofs();
145 
146 #else
147 
148  return 0;
149 
150 #endif
151 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225

◆ n_local_dofs()

dof_id_type libMesh::System::n_local_dofs ( ) const
inherited
Returns
The number of degrees of freedom local to this processor

Definition at line 155 of file system.C.

References libMesh::System::_dof_map.

Referenced by libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::System::add_vector(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::AdvectionSystem::assemble_claw_rhs(), libMesh::PetscDMWrapper::build_section(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::System::get_info(), libMesh::SecondOrderUnsteadySolver::init_data(), libMesh::AdvectionSystem::init_data(), libMesh::UnsteadySolver::init_data(), libMesh::System::init_data(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), main(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::SecondOrderUnsteadySolver::reinit(), libMesh::UnsteadySolver::reinit(), libMesh::System::restrict_vectors(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), libMesh::PetscPreconditioner< T >::set_hypre_ams_data(), libMesh::ClawSystem::solve_conservation_law(), MeshFunctionTest::test_p_level(), libMesh::RBConstruction::train_reduced_basis_with_POD(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), and libMesh::RBConstruction::update_residual_terms().

156 {
157  return _dof_map->n_local_dofs();
158 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225

◆ n_matrices()

unsigned int libMesh::System::n_matrices ( ) const
inlineinherited
Returns
The number of matrices handled by this system. This is the size of the _matrices map

Definition at line 2638 of file system.h.

References libMesh::System::_matrices.

Referenced by libMesh::ImplicitSystem::add_matrices(), and libMesh::System::get_info().

2639 {
2640  return cast_int<unsigned int>(_matrices.size());
2641 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 85 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

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

86  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
Returns
The number of processors in the group.

Definition at line 103 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, libMesh::libmesh_assert(), and TIMPI::Communicator::size().

Referenced by libMesh::Partitioner::_find_global_index_by_pid_map(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DofMap::add_constraints_to_send_list(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::System::add_vector(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::FEMSystem::assembly(), libMesh::Nemesis_IO::assert_symmetric_cmaps(), libMesh::Partitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::Partitioner::build_graph(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::DistributedMesh::clear(), libMesh::DistributedMesh::clear_elems(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::UnstructuredMesh::copy_nodes_and_elements(), libMesh::Nemesis_IO::copy_scalar_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_scalar_dofs(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::RBEIMEvaluation::gather_bfs(), libMesh::MeshBase::get_info(), libMesh::StaticCondensation::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_petscdm(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::NumericVector< Number >::is_effectively_ghosted(), libMesh::NumericVector< Number >::is_effectively_serial(), 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::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::DofMap::n_dofs_per_processor(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::RBEIMEvaluation::node_gather_bfs(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::DofMap::prepare_send_list(), libMesh::MeshBase::print_constraint_rows(), libMesh::DofMap::print_dof_constraints(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::XdrIO::read_header(), libMesh::CheckpointIO::read_nodes(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::System::read_serialized_vector(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), OverlappingFunctorTest::run_partitioner_test(), libMesh::DofMap::scatter_constraints(), libMesh::DistributedMesh::set_next_unique_id(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), WriteVecAndScalar::setupTests(), libMesh::RBEIMEvaluation::side_gather_bfs(), DistributedMeshTest::testRemoteElemError(), CheckpointIOTest::testSplitter(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::VTKIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::System::write_parallel_data(), 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().

104  {
105  processor_id_type returnval =
106  cast_int<processor_id_type>(_communicator.size());
107  libmesh_assert(returnval); // We never have an empty comm
108  return returnval;
109  }
const Parallel::Communicator & _communicator
processor_id_type size() const
uint8_t processor_id_type
libmesh_assert(ctx)

◆ n_qois()

unsigned int libMesh::System::n_qois ( ) const
inlineinherited

Number of currently active quantities of interest.

Definition at line 2562 of file system.h.

References libMesh::System::_qoi, and libMesh::System::_qoi_error_estimates.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdaptiveTimeSolver::adjoint_advance_timestep(), libMesh::UnsteadySolver::adjoint_advance_timestep(), libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity(), libMesh::TwostepTimeSolver::adjoint_solve(), libMesh::ImplicitSystem::adjoint_solve(), libMesh::SensitivityData::allocate_data(), libMesh::SensitivityData::allocate_hessian_data(), libMesh::ExplicitSystem::assemble_qoi(), libMesh::FEMSystem::assemble_qoi(), libMesh::ExplicitSystem::assemble_qoi_derivative(), libMesh::FEMSystem::assemble_qoi_derivative(), libMesh::DiffContext::DiffContext(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::FileSolutionHistory::FileSolutionHistory(), libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity(), libMesh::UnsteadySolver::init_adjoints(), libMesh::TimeSolver::init_adjoints(), libMesh::System::init_qois(), libMesh::Euler2Solver::integrate_adjoint_refinement_error_estimate(), libMesh::TwostepTimeSolver::integrate_adjoint_refinement_error_estimate(), libMesh::EulerSolver::integrate_adjoint_refinement_error_estimate(), libMesh::Euler2Solver::integrate_qoi_timestep(), libMesh::TwostepTimeSolver::integrate_qoi_timestep(), libMesh::EulerSolver::integrate_qoi_timestep(), main(), libMesh::FEMContext::pre_fe_reinit(), libMesh::ImplicitSystem::qoi_parameter_hessian(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), libMesh::FileSolutionHistory::retrieve(), libMesh::QoISet::size(), libMesh::UnsteadySolver::UnsteadySolver(), and libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve().

2563 {
2564  libmesh_assert_equal_to(this->_qoi.size(), this->_qoi_error_estimates.size());
2565 
2566  return cast_int<unsigned int>(this->_qoi.size());
2567 }
std::vector< Number > _qoi
Values of the quantities of interest.
Definition: system.h:2367
std::vector< Number > _qoi_error_estimates
Vector to hold error estimates for qois, either from a steady state calculation, or from a single uns...
Definition: system.h:2377

◆ n_variable_groups()

unsigned int libMesh::System::n_variable_groups ( ) const
inherited
Returns
The number of VariableGroup variable groups in the system

Definition at line 2694 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::n_variable_groups().

Referenced by libMesh::FEMSystem::assembly(), and libMesh::System::get_info().

2695 {
2696  return this->get_dof_map().n_variable_groups();
2697 }
unsigned int n_variable_groups() const
Definition: dof_map.h:733
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ n_vars()

unsigned int libMesh::System::n_vars ( ) const
inherited
Returns
The number of variables in the system

Definition at line 2669 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::n_vars().

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::PetscDMWrapper::add_dofs_helper(), libMesh::DiffContext::add_localized_vector(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::TwostepTimeSolver::adjoint_solve(), libMesh::FEMContext::attach_quadrature_rules(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::PetscDMWrapper::build_section(), libMesh::System::calculate_norm(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::DGFEMContext::DGFEMContext(), libMesh::DiffContext::DiffContext(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::ErrorEstimator::estimate_errors(), libMesh::ExactSolution::ExactSolution(), libMesh::FEMContext::find_hardest_fe_type(), libMesh::EquationSystems::find_variable_numbers(), libMesh::FEMSystem::init_context(), libMesh::RBEIMConstruction::init_context(), libMesh::FEMContext::init_internal_data(), libMesh::PetscDMWrapper::init_petscdm(), libMesh::DifferentiablePhysics::init_physics(), AssemblyA0::interior_assembly(), AssemblyA1::interior_assembly(), AssemblyA2::interior_assembly(), InnerProductAssembly::interior_assembly(), main(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SmoothnessEstimator::EstimateSmoothness::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), output_norms(), libMesh::petsc_auto_fieldsplit(), libMesh::FEMContext::pre_fe_reinit(), libMesh::InterMeshProjection::project_system_vectors(), libMesh::System::re_update(), libMesh::System::read_parallel_data(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::System::reinit_mesh(), libMesh::HPCoarsenTest::select_refinement(), libMesh::PetscPreconditioner< T >::set_petsc_aux_data(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::SystemSubsetBySubdomain::set_var_nums(), OverlappingTestBase::setup_coupling_matrix(), SystemsTest::testDofCouplingWithVarGroups(), SlitMeshRefinedSystemTest::testRestart(), SlitMeshRefinedSystemTest::testSystem(), libMesh::System::write_header(), libMesh::System::write_parallel_data(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), and libMesh::System::zero_variable().

2670 {
2671  return this->get_dof_map().n_vars();
2672 }
unsigned int n_vars() const
Definition: dof_map.h:2937
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ n_vectors()

unsigned int libMesh::System::n_vectors ( ) const
inlineinherited
Returns
The number of vectors (in addition to the solution) handled by this system This is the size of the _vectors map

Definition at line 2499 of file system.h.

References libMesh::System::_vectors.

Referenced by libMesh::ExplicitSystem::add_system_rhs(), libMesh::System::compare(), libMesh::System::get_info(), main(), libMesh::InterMeshProjection::project_system_vectors(), and libMesh::System::write_header().

2500 {
2501  return cast_int<unsigned int>(_vectors.size());
2502 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ name()

const std::string & libMesh::System::name ( ) const
inlineinherited

◆ nonlocal_constraint()

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

Adds any nonlocal constraint contributions (e.g.

some components of constraints in scalar variable equations) to elem_residual

If this method receives request_jacobian = true, then it should also modify elem_jacobian and return true if possible. If the Jacobian changes have not been computed then the method should return false.

Users may need to reimplement this for PDEs on systems to which SCALAR variables with non-transient equations have been added.

Definition at line 233 of file diff_physics.h.

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

235  {
236  return request_jacobian;
237  }

◆ nonlocal_damping_residual()

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

Subtracts any nonlocal damping vector contributions (e.g.

any first time derivative coefficients in scalar variable equations) from elem_residual

If this method receives request_jacobian = true, then it should also modify elem_jacobian and return true if possible. If the Jacobian changes have not been computed then the method should return false.

Definition at line 394 of file diff_physics.h.

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

396  {
397  return request_jacobian;
398  }

◆ nonlocal_mass_residual()

bool libMesh::DifferentiablePhysics::nonlocal_mass_residual ( bool  request_jacobian,
DiffContext c 
)
virtualinherited

Subtracts any nonlocal mass vector contributions (e.g.

any time derivative coefficients in scalar variable equations) from elem_residual

If this method receives request_jacobian = true, then it should also modify elem_jacobian and return true if possible. If the Jacobian changes have not been computed then the method should return false.

Many problems can use the reimplementation in FEMPhysics::mass_residual which subtracts (du/dt,v) for each transient scalar variable u; users with more complicated transient scalar variable equations will need to reimplement this themselves.

Definition at line 58 of file diff_physics.C.

References libMesh::DiffContext::elem_solution_rate_derivative, libMesh::FEType::family, libMesh::DiffContext::get_dof_indices(), libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::DiffContext::get_elem_solution(), libMesh::DiffContext::get_system(), libMesh::DifferentiablePhysics::is_time_evolving(), libMesh::make_range(), libMesh::DiffContext::n_vars(), libMesh::SCALAR, libMesh::Variable::type(), and libMesh::System::variable().

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

60 {
61  FEMContext & context = cast_ref<FEMContext &>(c);
62 
63  for (auto var : make_range(context.n_vars()))
64  {
65  if (!this->is_time_evolving(var))
66  continue;
67 
68  if (c.get_system().variable(var).type().family != SCALAR)
69  continue;
70 
71  const std::vector<dof_id_type> & dof_indices =
72  context.get_dof_indices(var);
73 
74  const unsigned int n_dofs = cast_int<unsigned int>
75  (dof_indices.size());
76 
77  DenseSubVector<Number> & Fs = context.get_elem_residual(var);
78  DenseSubMatrix<Number> & Kss = context.get_elem_jacobian( var, var );
79 
81  context.get_elem_solution(var);
82 
83  for (unsigned int i=0; i != n_dofs; ++i)
84  {
85  Fs(i) -= Us(i);
86 
87  if (request_jacobian)
88  Kss(i,i) -= context.elem_solution_rate_derivative;
89  }
90  }
91 
92  return request_jacobian;
93 }
Defines a dense subvector for use in finite element computations.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
bool is_time_evolving(unsigned int var) const
Definition: diff_physics.h:260

◆ nonlocal_time_derivative()

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

Adds any nonlocal time derivative contributions (e.g.

some components of time derivatives in scalar variable equations) to elem_residual

If this method receives request_jacobian = true, then it should also modify elem_jacobian and return true if possible. If the Jacobian changes have not been computed then the method should return false.

Users may need to reimplement this for PDEs on systems to which SCALAR variables have been added.

Definition at line 214 of file diff_physics.h.

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

216  {
217  return request_jacobian;
218  }

◆ number()

unsigned int libMesh::System::number ( ) const
inlineinherited
Returns
The system number.

Definition at line 2393 of file system.h.

References libMesh::System::_sys_number.

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::PetscDMWrapper::add_dofs_helper(), assemble_matrix_and_rhs(), assemble_shell(), libMesh::VariationalSmootherSystem::assembly(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::VariationalSmootherConstraint::constrain_node_to_line(), libMesh::VariationalSmootherConstraint::constrain_node_to_plane(), libMesh::Nemesis_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::Nemesis_IO::copy_nodal_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::find_squared_element_error(), libMesh::EquationSystems::find_variable_numbers(), libMesh::VariationalSmootherConstraint::fix_node(), libMesh::System::get_info(), libMesh::VariationalSmootherSystem::init_data(), main(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SortAndCopy::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectVertices::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectEdges::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectSides::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectInteriors::operator()(), libMesh::System::read_parallel_data(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::StaticCondensationDofMap::reinit(), LinearElasticityWithContact::residual_and_jacobian(), SolidSystem::save_initial_mesh(), libMesh::HPCoarsenTest::select_refinement(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), libMesh::PetscPreconditioner< T >::set_hypre_ams_data(), libMesh::PetscDMWrapper::set_point_range_in_section(), MeshInputTest::testCopyElementVectorImpl(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::BoundaryVolumeSolutionTransfer::transfer_boundary_volume(), libMesh::BoundaryVolumeSolutionTransfer::transfer_volume_boundary(), libMesh::DTKAdapter::update_variable_values(), libMesh::System::write_parallel_data(), libMesh::System::write_serialized_blocked_dof_objects(), and libMesh::System::zero_variable().

2394 {
2395  return _sys_number;
2396 }
const unsigned int _sys_number
The number associated with this system.
Definition: system.h:2247

◆ numerical_elem_jacobian()

void FEMSystem::numerical_elem_jacobian ( FEMContext context) const
inherited

Uses the results of multiple element_residual() calls to numerically differentiate the corresponding jacobian on an element.

Definition at line 1322 of file fem_system.C.

References libMesh::TimeSolver::element_residual(), and libMesh::FEMSystem::numerical_jacobian().

1323 {
1324  LOG_SCOPE("numerical_elem_jacobian()", "FEMSystem");
1326 }
virtual bool element_residual(bool request_jacobian, DiffContext &)=0
This method uses the DifferentiablePhysics element_time_derivative(), element_constraint(), and mass_residual() to build a full residual on an element.
void numerical_jacobian(TimeSolverResPtr res, FEMContext &context) const
Uses the results of multiple res calls to numerically differentiate the corresponding jacobian...
Definition: fem_system.C:1210

◆ numerical_jacobian()

void FEMSystem::numerical_jacobian ( TimeSolverResPtr  res,
FEMContext context 
) const
inherited

Uses the results of multiple res calls to numerically differentiate the corresponding jacobian.

Definition at line 1210 of file fem_system.C.

References libMesh::DifferentiablePhysics::_mesh_sys, libMesh::DifferentiablePhysics::_mesh_x_var, libMesh::DifferentiablePhysics::_mesh_y_var, libMesh::DifferentiablePhysics::_mesh_z_var, libMesh::DiffContext::get_dof_indices(), libMesh::FEMContext::get_elem(), libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::DiffContext::get_elem_solution(), libMesh::Elem::hmin(), libMesh::invalid_uint, libMesh::libmesh_real(), libMesh::make_range(), libMesh::System::n_dofs(), libMesh::DiffContext::n_vars(), libMesh::FEMSystem::numerical_jacobian_h, libMesh::FEMSystem::numerical_jacobian_h_for_var(), libMesh::Elem::point(), libMesh::Real, and libMesh::DenseVector< T >::zero().

Referenced by libMesh::FEMSystem::numerical_elem_jacobian(), libMesh::FEMSystem::numerical_nonlocal_jacobian(), and libMesh::FEMSystem::numerical_side_jacobian().

1212 {
1213  // Logging is done by numerical_elem_jacobian
1214  // or numerical_side_jacobian
1215 
1216  DenseVector<Number> original_residual(context.get_elem_residual());
1217  DenseVector<Number> backwards_residual(context.get_elem_residual());
1218  DenseMatrix<Number> numeric_jacobian(context.get_elem_jacobian());
1219 #ifdef DEBUG
1220  DenseMatrix<Number> old_jacobian(context.get_elem_jacobian());
1221 #endif
1222 
1223  Real numerical_point_h = 0.;
1224  if (_mesh_sys == this)
1225  numerical_point_h = numerical_jacobian_h * context.get_elem().hmin();
1226 
1227  const unsigned int n_dofs =
1228  cast_int<unsigned int>(context.get_dof_indices().size());
1229 
1230  for (auto v : make_range(context.n_vars()))
1231  {
1232  const Real my_h = this->numerical_jacobian_h_for_var(v);
1233 
1234  unsigned int j_offset = libMesh::invalid_uint;
1235 
1236  if (!context.get_dof_indices(v).empty())
1237  {
1238  for (auto i : make_range(n_dofs))
1239  if (context.get_dof_indices()[i] ==
1240  context.get_dof_indices(v)[0])
1241  j_offset = i;
1242 
1243  libmesh_assert_not_equal_to(j_offset, libMesh::invalid_uint);
1244  }
1245 
1246  for (auto j : make_range(context.get_dof_indices(v).size()))
1247  {
1248  const unsigned int total_j = j + j_offset;
1249 
1250  // Take the "minus" side of a central differenced first derivative
1251  Number original_solution = context.get_elem_solution(v)(j);
1252  context.get_elem_solution(v)(j) -= my_h;
1253 
1254  // Make sure to catch any moving mesh terms
1255  Real * coord = nullptr;
1256  if (_mesh_sys == this)
1257  {
1258  if (_mesh_x_var == v)
1259  coord = &(context.get_elem().point(j)(0));
1260  else if (_mesh_y_var == v)
1261  coord = &(context.get_elem().point(j)(1));
1262  else if (_mesh_z_var == v)
1263  coord = &(context.get_elem().point(j)(2));
1264  }
1265  if (coord)
1266  {
1267  // We have enough information to scale the perturbations
1268  // here appropriately
1269  context.get_elem_solution(v)(j) = original_solution - numerical_point_h;
1270  *coord = libmesh_real(context.get_elem_solution(v)(j));
1271  }
1272 
1273  context.get_elem_residual().zero();
1274  ((*time_solver).*(res))(false, context);
1275 #ifdef DEBUG
1276  libmesh_assert_equal_to (old_jacobian, context.get_elem_jacobian());
1277 #endif
1278  backwards_residual = context.get_elem_residual();
1279 
1280  // Take the "plus" side of a central differenced first derivative
1281  context.get_elem_solution(v)(j) = original_solution + my_h;
1282  if (coord)
1283  {
1284  context.get_elem_solution()(j) = original_solution + numerical_point_h;
1285  *coord = libmesh_real(context.get_elem_solution(v)(j));
1286  }
1287  context.get_elem_residual().zero();
1288  ((*time_solver).*(res))(false, context);
1289 #ifdef DEBUG
1290  libmesh_assert_equal_to (old_jacobian, context.get_elem_jacobian());
1291 #endif
1292 
1293  context.get_elem_solution(v)(j) = original_solution;
1294  if (coord)
1295  {
1296  *coord = libmesh_real(context.get_elem_solution(v)(j));
1297  for (auto i : make_range(n_dofs))
1298  {
1299  numeric_jacobian(i,total_j) =
1300  (context.get_elem_residual()(i) - backwards_residual(i)) /
1301  2. / numerical_point_h;
1302  }
1303  }
1304  else
1305  {
1306  for (auto i : make_range(n_dofs))
1307  {
1308  numeric_jacobian(i,total_j) =
1309  (context.get_elem_residual()(i) - backwards_residual(i)) /
1310  2. / my_h;
1311  }
1312  }
1313  }
1314  }
1315 
1316  context.get_elem_residual() = original_residual;
1317  context.get_elem_jacobian() = numeric_jacobian;
1318 }
T libmesh_real(T a)
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:274
unsigned int _mesh_x_var
Variables from which to acquire moving mesh information.
Definition: diff_physics.h:536
virtual void zero() override final
Set every element in the vector to 0.
Definition: dense_vector.h:420
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:303
const Elem & get_elem() const
Accessor for current Elem object.
Definition: fem_context.h:908
Real numerical_jacobian_h
If calculating numeric jacobians is required, the FEMSystem will perturb each solution vector entry b...
Definition: fem_system.h:187
dof_id_type n_dofs() const
Definition: system.C:118
const DenseVector< Number > & get_elem_solution() const
Accessor for element solution.
Definition: diff_context.h:112
virtual Real hmin() const
Definition: elem.C:683
System * _mesh_sys
System from which to acquire moving mesh information.
Definition: diff_physics.h:531
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Definition: diff_context.h:363
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:242
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
Real numerical_jacobian_h_for_var(unsigned int var_num) const
If numerical_jacobian_h_for_var(var_num) is changed from its default value (numerical_jacobian_h), the FEMSystem will perturb solution vector entries for variable var_num by that amount when calculating finite differences with respect to that variable.
Definition: fem_system.h:265
unsigned int n_vars() const
Number of variables in solution.
Definition: diff_context.h:100
const Point & point(const unsigned int i) const
Definition: elem.h:2459

◆ numerical_jacobian_h_for_var()

Real FEMSystem::numerical_jacobian_h_for_var ( unsigned int  var_num) const
inlineinherited

If numerical_jacobian_h_for_var(var_num) is changed from its default value (numerical_jacobian_h), the FEMSystem will perturb solution vector entries for variable var_num by that amount when calculating finite differences with respect to that variable.

This is useful in multiphysics problems which have not been normalized.

Definition at line 265 of file fem_system.h.

References libMesh::FEMSystem::_numerical_jacobian_h_for_var, libMesh::FEMSystem::numerical_jacobian_h, and libMesh::Real.

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

266 {
267  if ((var_num >= _numerical_jacobian_h_for_var.size()) ||
268  _numerical_jacobian_h_for_var[var_num] == Real(0))
269  return numerical_jacobian_h;
270 
271  return _numerical_jacobian_h_for_var[var_num];
272 }
Real numerical_jacobian_h
If calculating numeric jacobians is required, the FEMSystem will perturb each solution vector entry b...
Definition: fem_system.h:187
std::vector< Real > _numerical_jacobian_h_for_var
Definition: fem_system.h:258
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ numerical_nonlocal_jacobian()

void FEMSystem::numerical_nonlocal_jacobian ( FEMContext context) const
inherited

Uses the results of multiple side_residual() calls to numerically differentiate the corresponding jacobian on nonlocal DoFs.

Definition at line 1338 of file fem_system.C.

References libMesh::TimeSolver::nonlocal_residual(), and libMesh::FEMSystem::numerical_jacobian().

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

1339 {
1340  LOG_SCOPE("numerical_nonlocal_jacobian()", "FEMSystem");
1342 }
virtual bool nonlocal_residual(bool request_jacobian, DiffContext &)=0
This method uses the DifferentiablePhysics nonlocal_time_derivative(), nonlocal_constraint(), and nonlocal_mass_residual() to build a full residual of non-local terms.
void numerical_jacobian(TimeSolverResPtr res, FEMContext &context) const
Uses the results of multiple res calls to numerically differentiate the corresponding jacobian...
Definition: fem_system.C:1210

◆ numerical_side_jacobian()

void FEMSystem::numerical_side_jacobian ( FEMContext context) const
inherited

Uses the results of multiple side_residual() calls to numerically differentiate the corresponding jacobian on an element's side.

Definition at line 1330 of file fem_system.C.

References libMesh::FEMSystem::numerical_jacobian(), and libMesh::TimeSolver::side_residual().

1331 {
1332  LOG_SCOPE("numerical_side_jacobian()", "FEMSystem");
1334 }
virtual bool side_residual(bool request_jacobian, DiffContext &)=0
This method uses the DifferentiablePhysics side_time_derivative(), side_constraint(), and side_mass_residual() to build a full residual on an element&#39;s side.
void numerical_jacobian(TimeSolverResPtr res, FEMContext &context) const
Uses the results of multiple res calls to numerically differentiate the corresponding jacobian...
Definition: fem_system.C:1210

◆ parallel_op()

void libMesh::DifferentiableQoI::parallel_op ( const Parallel::Communicator communicator,
std::vector< Number > &  sys_qoi,
std::vector< Number > &  local_qoi,
const QoISet qoi_indices 
)
virtualinherited

Method to populate system qoi data structure with process-local qoi.

By default, simply sums process qois into system qoi.

Definition at line 41 of file diff_qoi.C.

References communicator.

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

45 {
46  // Sum everything into local_qoi
47  communicator.sum(local_qoi);
48 
49  // Now put into system qoi
50  sys_qoi = local_qoi;
51 }
DIE A HORRIBLE DEATH HERE typedef MPI_Comm communicator

◆ point_gradient() [1/4]

Gradient libMesh::System::point_gradient ( unsigned int  var,
const Point p,
const bool  insist_on_success = true,
const NumericVector< Number > *  sol = nullptr 
) const
inherited
Returns
The gradient of the solution variable var at the physical point p in the mesh, similarly to point_value.

Definition at line 2343 of file system.C.

References libMesh::Variable::active_subdomains(), TIMPI::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::PointLocatorBase::enable_out_of_mesh_mode(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::libmesh_assert(), mesh, TIMPI::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), and libMesh::System::variable().

Referenced by line_print(), and libMesh::System::point_gradient().

2347 {
2348  // This function must be called on every processor; there's no
2349  // telling where in the partition p falls.
2350  parallel_object_only();
2351 
2352  // And every processor had better agree about which point we're
2353  // looking for
2354 #ifndef NDEBUG
2355  libmesh_assert(this->comm().verify(p(0)));
2356 #if LIBMESH_DIM > 1
2357  libmesh_assert(this->comm().verify(p(1)));
2358 #endif
2359 #if LIBMESH_DIM > 2
2360  libmesh_assert(this->comm().verify(p(2)));
2361 #endif
2362 #endif // NDEBUG
2363 
2364  // Get a reference to the mesh object associated with the system object that calls this function
2365  const MeshBase & mesh = this->get_mesh();
2366 
2367  // Use an existing PointLocator or create a new one
2368  std::unique_ptr<PointLocatorBase> locator_ptr = mesh.sub_point_locator();
2369  PointLocatorBase & locator = *locator_ptr;
2370 
2371  if (!insist_on_success || !mesh.is_serial())
2372  locator.enable_out_of_mesh_mode();
2373 
2374  // Get a pointer to an element that contains p and allows us to
2375  // evaluate var
2376  const std::set<subdomain_id_type> & raw_subdomains =
2377  this->variable(var).active_subdomains();
2378  const std::set<subdomain_id_type> * implicit_subdomains =
2379  raw_subdomains.empty() ? nullptr : &raw_subdomains;
2380  const Elem * e = locator(p, implicit_subdomains);
2381 
2382  Gradient grad_u;
2383 
2384  if (e && this->get_dof_map().is_evaluable(*e, var))
2385  grad_u = point_gradient(var, p, *e, sol);
2386 
2387  // If I have an element containing p, then let's let everyone know
2388  processor_id_type lowest_owner =
2389  (e && (e->processor_id() == this->processor_id())) ?
2390  this->processor_id() : this->n_processors();
2391  this->comm().min(lowest_owner);
2392 
2393  // Everybody should get their value from a processor that was able
2394  // to compute it.
2395  // If nobody admits owning the point, we may have a problem.
2396  if (lowest_owner != this->n_processors())
2397  this->comm().broadcast(grad_u, lowest_owner);
2398  else
2399  libmesh_assert(!insist_on_success);
2400 
2401  return grad_u;
2402 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2343
MeshBase & mesh
const Parallel::Communicator & comm() const
const MeshBase & get_mesh() const
Definition: system.h:2401
uint8_t processor_id_type
processor_id_type n_processors() const
const std::set< subdomain_id_type > & active_subdomains() const
Definition: variable.h:181
void min(const T &r, T &o, Request &req) const
NumberVectorValue Gradient
libmesh_assert(ctx)
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ point_gradient() [2/4]

Gradient libMesh::System::point_gradient ( unsigned int  var,
const Point p,
const Elem e,
const NumericVector< Number > *  sol = nullptr 
) const
inherited
Returns
The gradient of the solution variable var at the physical point p in local Elem e in the mesh, similarly to point_value.

Definition at line 2405 of file system.C.

References libMesh::FEInterface::compute_data(), libMesh::Elem::contains_point(), libMesh::System::current_local_solution, dim, libMesh::Elem::dim(), libMesh::DofMap::dof_indices(), libMesh::FEComputeData::dshape, libMesh::FEComputeData::enable_derivative(), libMesh::System::get_dof_map(), libMesh::System::get_equation_systems(), libMesh::FEMap::inverse_map(), libMesh::DofMap::is_evaluable(), libMesh::libmesh_assert(), libMesh::FEComputeData::local_transform, and libMesh::DofMap::variable_type().

2409 {
2410  // Ensuring that the given point is really in the element is an
2411  // expensive assert, but as long as debugging is turned on we might
2412  // as well try to catch a particularly nasty potential error
2413  libmesh_assert (e.contains_point(p));
2414 
2415  if (!sol)
2416  sol = this->current_local_solution.get();
2417 
2418  // Get the dof map to get the proper indices for our computation
2419  const DofMap & dof_map = this->get_dof_map();
2420 
2421  // write the element dimension into a separate variable.
2422  const unsigned int dim = e.dim();
2423 
2424  // Make sure we can evaluate on this element.
2425  libmesh_assert (dof_map.is_evaluable(e, var));
2426 
2427  // Need dof_indices for phi[i][j]
2428  std::vector<dof_id_type> dof_indices;
2429 
2430  // Fill in the dof_indices for our element
2431  dof_map.dof_indices (&e, dof_indices, var);
2432 
2433  // Get the no of dofs associated with this point
2434  const unsigned int num_dofs = cast_int<unsigned int>
2435  (dof_indices.size());
2436 
2437  FEType fe_type = dof_map.variable_type(var);
2438 
2439  // Map the physical co-ordinates to the master co-ordinates
2440  Point coor = FEMap::inverse_map(dim, &e, p);
2441 
2442  // get the shape function value via the FEInterface to also handle the case
2443  // of infinite elements correctly, the shape function is not fe->phi().
2444  FEComputeData fe_data(this->get_equation_systems(), coor);
2445  fe_data.enable_derivative();
2446  FEInterface::compute_data(dim, fe_type, &e, fe_data);
2447 
2448  // Get ready to accumulate a gradient
2449  Gradient grad_u;
2450 
2451  for (unsigned int l=0; l<num_dofs; l++)
2452  {
2453  // Chartesian coordinates have always LIBMESH_DIM entries,
2454  // local coordinates have as many coordinates as the element has.
2455  for (std::size_t v=0; v<dim; v++)
2456  for (std::size_t xyz=0; xyz<LIBMESH_DIM; xyz++)
2457  {
2458  // FIXME: this needs better syntax: It is matrix-vector multiplication.
2459  grad_u(xyz) += fe_data.local_transform[v][xyz]
2460  * fe_data.dshape[l](v)
2461  * (*sol)(dof_indices[l]);
2462  }
2463  }
2464 
2465  return grad_u;
2466 }
unsigned int dim
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true, const bool extra_checks=true)
Definition: fe_map.C:1512
const EquationSystems & get_equation_systems() const
Definition: system.h:767
static void compute_data(const unsigned int dim, const FEType &fe_t, const Elem *elem, FEComputeData &data)
Lets the appropriate child of FEBase compute the requested data for the input specified in data...
NumberVectorValue Gradient
libmesh_assert(ctx)
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ point_gradient() [3/4]

Gradient libMesh::System::point_gradient ( unsigned int  var,
const Point p,
const Elem e 
) const
inherited

Calls the version of point_gradient() which takes a reference.

This function exists only to prevent people from calling the version of point_gradient() that has a boolean third argument, which would result in unnecessary PointLocator calls.

Definition at line 2470 of file system.C.

References libMesh::libmesh_assert(), and libMesh::System::point_gradient().

2471 {
2472  libmesh_assert(e);
2473  return this->point_gradient(var, p, *e);
2474 }
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2343
libmesh_assert(ctx)

◆ point_gradient() [4/4]

Gradient libMesh::System::point_gradient ( unsigned int  var,
const Point p,
const NumericVector< Number > *  sol 
) const
inherited

Calls the parallel version of point_gradient().

This function exists only to prevent people from accidentally calling the version of point_gradient() that has a boolean third argument, which would result in incorrect output.

Definition at line 2478 of file system.C.

References libMesh::System::point_gradient().

2479 {
2480  return this->point_gradient(var, p, true, sol);
2481 }
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2343

◆ point_hessian() [1/4]

Tensor libMesh::System::point_hessian ( unsigned int  var,
const Point p,
const bool  insist_on_success = true,
const NumericVector< Number > *  sol = nullptr 
) const
inherited
Returns
The second derivative tensor of the solution variable var at the physical point p in the mesh, similarly to point_value.

Definition at line 2487 of file system.C.

References libMesh::Variable::active_subdomains(), TIMPI::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::PointLocatorBase::enable_out_of_mesh_mode(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::libmesh_assert(), mesh, TIMPI::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), and libMesh::System::variable().

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

2491 {
2492  // This function must be called on every processor; there's no
2493  // telling where in the partition p falls.
2494  parallel_object_only();
2495 
2496  // And every processor had better agree about which point we're
2497  // looking for
2498 #ifndef NDEBUG
2499  libmesh_assert(this->comm().verify(p(0)));
2500 #if LIBMESH_DIM > 1
2501  libmesh_assert(this->comm().verify(p(1)));
2502 #endif
2503 #if LIBMESH_DIM > 2
2504  libmesh_assert(this->comm().verify(p(2)));
2505 #endif
2506 #endif // NDEBUG
2507 
2508  // Get a reference to the mesh object associated with the system object that calls this function
2509  const MeshBase & mesh = this->get_mesh();
2510 
2511  // Use an existing PointLocator or create a new one
2512  std::unique_ptr<PointLocatorBase> locator_ptr = mesh.sub_point_locator();
2513  PointLocatorBase & locator = *locator_ptr;
2514 
2515  if (!insist_on_success || !mesh.is_serial())
2516  locator.enable_out_of_mesh_mode();
2517 
2518  // Get a pointer to an element that contains p and allows us to
2519  // evaluate var
2520  const std::set<subdomain_id_type> & raw_subdomains =
2521  this->variable(var).active_subdomains();
2522  const std::set<subdomain_id_type> * implicit_subdomains =
2523  raw_subdomains.empty() ? nullptr : &raw_subdomains;
2524  const Elem * e = locator(p, implicit_subdomains);
2525 
2526  Tensor hess_u;
2527 
2528  if (e && this->get_dof_map().is_evaluable(*e, var))
2529  hess_u = point_hessian(var, p, *e, sol);
2530 
2531  // If I have an element containing p, then let's let everyone know
2532  processor_id_type lowest_owner =
2533  (e && (e->processor_id() == this->processor_id())) ?
2534  this->processor_id() : this->n_processors();
2535  this->comm().min(lowest_owner);
2536 
2537  // Everybody should get their value from a processor that was able
2538  // to compute it.
2539  // If nobody admits owning the point, we may have a problem.
2540  if (lowest_owner != this->n_processors())
2541  this->comm().broadcast(hess_u, lowest_owner);
2542  else
2543  libmesh_assert(!insist_on_success);
2544 
2545  return hess_u;
2546 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
MeshBase & mesh
const Parallel::Communicator & comm() const
const MeshBase & get_mesh() const
Definition: system.h:2401
uint8_t processor_id_type
processor_id_type n_processors() const
const std::set< subdomain_id_type > & active_subdomains() const
Definition: variable.h:181
void min(const T &r, T &o, Request &req) const
libmesh_assert(ctx)
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
NumberTensorValue Tensor
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2487
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ point_hessian() [2/4]

Tensor libMesh::System::point_hessian ( unsigned int  var,
const Point p,
const Elem e,
const NumericVector< Number > *  sol = nullptr 
) const
inherited
Returns
The second derivative tensor of the solution variable var at the physical point p in local Elem e in the mesh, similarly to point_value.

Definition at line 2548 of file system.C.

References libMesh::TypeTensor< T >::add_scaled(), libMesh::FEGenericBase< OutputType >::build(), libMesh::Elem::contains_point(), libMesh::System::current_local_solution, libMesh::Elem::dim(), libMesh::DofMap::dof_indices(), libMesh::System::get_dof_map(), libMesh::Elem::infinite(), libMesh::FEMap::inverse_map(), libMesh::DofMap::is_evaluable(), libMesh::libmesh_assert(), and libMesh::DofMap::variable_type().

2552 {
2553  // Ensuring that the given point is really in the element is an
2554  // expensive assert, but as long as debugging is turned on we might
2555  // as well try to catch a particularly nasty potential error
2556  libmesh_assert (e.contains_point(p));
2557 
2558  if (!sol)
2559  sol = this->current_local_solution.get();
2560 
2561  if (e.infinite())
2562  libmesh_not_implemented();
2563 
2564  // Get the dof map to get the proper indices for our computation
2565  const DofMap & dof_map = this->get_dof_map();
2566 
2567  // Make sure we can evaluate on this element.
2568  libmesh_assert (dof_map.is_evaluable(e, var));
2569 
2570  // Need dof_indices for phi[i][j]
2571  std::vector<dof_id_type> dof_indices;
2572 
2573  // Fill in the dof_indices for our element
2574  dof_map.dof_indices (&e, dof_indices, var);
2575 
2576  // Get the no of dofs associated with this point
2577  const unsigned int num_dofs = cast_int<unsigned int>
2578  (dof_indices.size());
2579 
2580  FEType fe_type = dof_map.variable_type(var);
2581 
2582  // Build a FE again so we can calculate u(p)
2583  std::unique_ptr<FEBase> fe (FEBase::build(e.dim(), fe_type));
2584 
2585  // Map the physical co-ordinates to the master co-ordinates
2586  // Build a vector of point co-ordinates to send to reinit
2587  std::vector<Point> coor(1, FEMap::inverse_map(e.dim(), &e, p));
2588 
2589  // Get the values of the shape function derivatives
2590  const std::vector<std::vector<RealTensor>> & d2phi = fe->get_d2phi();
2591 
2592  // Reinitialize the element and compute the shape function values at coor
2593  fe->reinit (&e, &coor);
2594 
2595  // Get ready to accumulate a hessian
2596  Tensor hess_u;
2597 
2598  for (unsigned int l=0; l<num_dofs; l++)
2599  {
2600  hess_u.add_scaled (d2phi[l][0], (*sol)(dof_indices[l]));
2601  }
2602 
2603  return hess_u;
2604 }
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true, const bool extra_checks=true)
Definition: fe_map.C:1512
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
libmesh_assert(ctx)
void add_scaled(const TypeTensor< T2 > &, const T &)
Add a scaled tensor to this tensor without creating a temporary.
Definition: type_tensor.h:858
NumberTensorValue Tensor
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ point_hessian() [3/4]

Tensor libMesh::System::point_hessian ( unsigned int  var,
const Point p,
const Elem e 
) const
inherited

Calls the version of point_hessian() which takes a reference.

This function exists only to prevent people from calling the version of point_hessian() that has a boolean third argument, which would result in unnecessary PointLocator calls.

Definition at line 2608 of file system.C.

References libMesh::libmesh_assert(), and libMesh::System::point_hessian().

2609 {
2610  libmesh_assert(e);
2611  return this->point_hessian(var, p, *e);
2612 }
libmesh_assert(ctx)
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2487

◆ point_hessian() [4/4]

Tensor libMesh::System::point_hessian ( unsigned int  var,
const Point p,
const NumericVector< Number > *  sol 
) const
inherited

Calls the parallel version of point_hessian().

This function exists only to prevent people from accidentally calling the version of point_hessian() that has a boolean third argument, which would result in incorrect output.

Definition at line 2616 of file system.C.

References libMesh::System::point_hessian().

2617 {
2618  return this->point_hessian(var, p, true, sol);
2619 }
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2487

◆ point_value() [1/4]

Number libMesh::System::point_value ( unsigned int  var,
const Point p,
const bool  insist_on_success = true,
const NumericVector< Number > *  sol = nullptr 
) const
inherited
Returns
The value of the solution variable var at the physical point p in the mesh, without knowing a priori which element contains p, using the degree of freedom coefficients in sol (or in current_local_solution if sol is left null).
Note
This function uses MeshBase::sub_point_locator(); users may or may not want to call MeshBase::clear_point_locator() afterward. Also, point_locator() is expensive (N log N for initial construction, log N for evaluations). Avoid using this function in any context where you are already looping over elements.

Because the element containing p may lie on any processor, this function is parallel-only.

By default this method expects the point to reside inside the domain and will abort if no element can be found which contains p. The optional parameter insist_on_success can be set to false to allow the method to return 0 when the point is not located.

Definition at line 2214 of file system.C.

References libMesh::Variable::active_subdomains(), TIMPI::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::PointLocatorBase::enable_out_of_mesh_mode(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::libmesh_assert(), mesh, TIMPI::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), and libMesh::System::variable().

Referenced by line_print(), main(), libMesh::System::point_value(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyElementVectorImpl(), MeshInputTest::testCopyNodalSolutionImpl(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), PeriodicBCTest::testPeriodicBC(), SystemsTest::testProjectCubeWithMeshFunction(), EquationSystemsTest::testRepartitionThenReinit(), DisjointNeighborTest::testTempJump(), and DisjointNeighborTest::testTempJumpRefine().

2218 {
2219  // This function must be called on every processor; there's no
2220  // telling where in the partition p falls.
2221  parallel_object_only();
2222 
2223  // And every processor had better agree about which point we're
2224  // looking for
2225 #ifndef NDEBUG
2226  libmesh_assert(this->comm().verify(p(0)));
2227 #if LIBMESH_DIM > 1
2228  libmesh_assert(this->comm().verify(p(1)));
2229 #endif
2230 #if LIBMESH_DIM > 2
2231  libmesh_assert(this->comm().verify(p(2)));
2232 #endif
2233 #endif // NDEBUG
2234 
2235  // Get a reference to the mesh object associated with the system object that calls this function
2236  const MeshBase & mesh = this->get_mesh();
2237 
2238  // Use an existing PointLocator or create a new one
2239  std::unique_ptr<PointLocatorBase> locator_ptr = mesh.sub_point_locator();
2240  PointLocatorBase & locator = *locator_ptr;
2241 
2242  if (!insist_on_success || !mesh.is_serial())
2243  locator.enable_out_of_mesh_mode();
2244 
2245  // Get a pointer to an element that contains p and allows us to
2246  // evaluate var
2247  const std::set<subdomain_id_type> & raw_subdomains =
2248  this->variable(var).active_subdomains();
2249  const std::set<subdomain_id_type> * implicit_subdomains =
2250  raw_subdomains.empty() ? nullptr : &raw_subdomains;
2251  const Elem * e = locator(p, implicit_subdomains);
2252 
2253  Number u = 0;
2254 
2255  if (e && this->get_dof_map().is_evaluable(*e, var))
2256  u = point_value(var, p, *e, sol);
2257 
2258  // If I have an element containing p, then let's let everyone know
2259  processor_id_type lowest_owner =
2260  (e && (e->processor_id() == this->processor_id())) ?
2261  this->processor_id() : this->n_processors();
2262  this->comm().min(lowest_owner);
2263 
2264  // Everybody should get their value from a processor that was able
2265  // to compute it.
2266  // If nobody admits owning the point, we have a problem.
2267  if (lowest_owner != this->n_processors())
2268  this->comm().broadcast(u, lowest_owner);
2269  else
2270  libmesh_assert(!insist_on_success);
2271 
2272  return u;
2273 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
MeshBase & mesh
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2214
const Parallel::Communicator & comm() const
const MeshBase & get_mesh() const
Definition: system.h:2401
uint8_t processor_id_type
processor_id_type n_processors() const
const std::set< subdomain_id_type > & active_subdomains() const
Definition: variable.h:181
void min(const T &r, T &o, Request &req) const
libmesh_assert(ctx)
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ point_value() [2/4]

Number libMesh::System::point_value ( unsigned int  var,
const Point p,
const Elem e,
const NumericVector< Number > *  sol = nullptr 
) const
inherited
Returns
The value of the solution variable var at the physical point p contained in local Elem e, using the degree of freedom coefficients in sol (or in current_local_solution if sol is left null).

This version of point_value can be run in serial, but assumes e is in the local mesh partition or is algebraically ghosted.

Definition at line 2275 of file system.C.

References libMesh::FEInterface::compute_data(), libMesh::Elem::contains_point(), libMesh::System::current_local_solution, libMesh::Elem::dim(), libMesh::DofMap::dof_indices(), libMesh::System::get_dof_map(), libMesh::System::get_equation_systems(), libMesh::FEMap::inverse_map(), libMesh::DofMap::is_evaluable(), libMesh::libmesh_assert(), and libMesh::DofMap::variable_type().

2279 {
2280  // Ensuring that the given point is really in the element is an
2281  // expensive assert, but as long as debugging is turned on we might
2282  // as well try to catch a particularly nasty potential error
2283  libmesh_assert (e.contains_point(p));
2284 
2285  if (!sol)
2286  sol = this->current_local_solution.get();
2287 
2288  // Get the dof map to get the proper indices for our computation
2289  const DofMap & dof_map = this->get_dof_map();
2290 
2291  // Make sure we can evaluate on this element.
2292  libmesh_assert (dof_map.is_evaluable(e, var));
2293 
2294  // Need dof_indices for phi[i][j]
2295  std::vector<dof_id_type> dof_indices;
2296 
2297  // Fill in the dof_indices for our element
2298  dof_map.dof_indices (&e, dof_indices, var);
2299 
2300  // Get the no of dofs associated with this point
2301  const unsigned int num_dofs = cast_int<unsigned int>
2302  (dof_indices.size());
2303 
2304  FEType fe_type = dof_map.variable_type(var);
2305 
2306  // Map the physical co-ordinates to the master co-ordinates
2307  Point coor = FEMap::inverse_map(e.dim(), &e, p);
2308 
2309  // get the shape function value via the FEInterface to also handle the case
2310  // of infinite elements correctly, the shape function is not fe->phi().
2311  FEComputeData fe_data(this->get_equation_systems(), coor);
2312  FEInterface::compute_data(e.dim(), fe_type, &e, fe_data);
2313 
2314  // Get ready to accumulate a value
2315  Number u = 0;
2316 
2317  for (unsigned int l=0; l<num_dofs; l++)
2318  {
2319  u += fe_data.shape[l] * (*sol)(dof_indices[l]);
2320  }
2321 
2322  return u;
2323 }
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true, const bool extra_checks=true)
Definition: fe_map.C:1512
const EquationSystems & get_equation_systems() const
Definition: system.h:767
static void compute_data(const unsigned int dim, const FEType &fe_t, const Elem *elem, FEComputeData &data)
Lets the appropriate child of FEBase compute the requested data for the input specified in data...
libmesh_assert(ctx)
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ point_value() [3/4]

Number libMesh::System::point_value ( unsigned int  var,
const Point p,
const Elem e 
) const
inherited

Calls the version of point_value() which takes a reference.

This function exists only to prevent people from calling the version of point_value() that has a boolean third argument, which would result in unnecessary PointLocator calls.

Definition at line 2327 of file system.C.

References libMesh::libmesh_assert(), and libMesh::System::point_value().

2328 {
2329  libmesh_assert(e);
2330  return this->point_value(var, p, *e);
2331 }
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2214
libmesh_assert(ctx)

◆ point_value() [4/4]

Number libMesh::System::point_value ( unsigned int  var,
const Point p,
const NumericVector< Number > *  sol 
) const
inherited

Calls the parallel version of point_value().

This function exists only to prevent people from accidentally calling the version of point_value() that has a boolean third argument, which would result in incorrect output.

Definition at line 2335 of file system.C.

References libMesh::System::point_value().

2336 {
2337  return this->point_value(var, p, true, sol);
2338 }
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2214

◆ pop_physics()

void libMesh::DifferentiableSystem::pop_physics ( )
inherited

Pop a physics object off of our stack.

Definition at line 343 of file diff_system.C.

References libMesh::DifferentiableSystem::_diff_physics, libMesh::ImplicitSystem::disable_cache(), and libMesh::libmesh_assert().

Referenced by main().

344 {
345  libmesh_assert(!this->_diff_physics.empty());
346 
347  this->_diff_physics.pop();
348 
349  // If the physics has been changed, we will reassemble
350  // the matrix from scratch before doing an adjoint solve
351  // rather than just transposing
352  this->disable_cache();
353 }
std::stack< std::unique_ptr< DifferentiablePhysics >, std::vector< std::unique_ptr< DifferentiablePhysics > > > _diff_physics
Stack of pointers to objects to use for physics assembly evaluations.
Definition: diff_system.h:434
libmesh_assert(ctx)
virtual void disable_cache() override
Avoids use of any cached data that might affect any solve result.

◆ postprocess()

void CoupledSystem::postprocess ( void  )
protectedvirtual

Runs a postprocessing loop over all elements, and if postprocess_sides is true over all sides.

Reimplemented from libMesh::FEMSystem.

Definition at line 427 of file coupled_system.C.

428 {
429  // We need to overload the postprocess function to set the
430  // computed_QoI variable of the CoupledSystem class to the qoi value
431  // stored in System::qoi[0]
432  computed_QoI = this->get_qoi_value(0);
433 }
Number get_qoi_value(unsigned int qoi_index) const
Definition: system.C:2179

◆ prefer_hash_table_matrix_assembly()

void libMesh::System::prefer_hash_table_matrix_assembly ( bool  preference)
inlineinherited

Sets whether to use hash table matrix assembly if the matrix sub-classes support it.

Definition at line 2667 of file system.h.

References libMesh::System::_matrices_initialized, and libMesh::System::_prefer_hash_table_matrix_assembly.

Referenced by main().

2668 {
2669  libmesh_error_msg_if(
2671  "System::prefer_hash_table_matrix_assembly() should be called before matrices are initialized");
2673 }
bool _prefer_hash_table_matrix_assembly
Whether to use hash table matrix assembly if the matrix sub-classes support it.
Definition: system.h:2348
bool _matrices_initialized
false when additional matrices being added require initialization, true otherwise.
Definition: system.h:2287

◆ prefix()

std::string libMesh::System::prefix ( ) const
inlineinherited
Returns
A prefix that may be applied to solver options. Note that this prefix is only used if prefix_with_name()

Definition at line 1980 of file system.h.

References libMesh::System::name().

Referenced by libMesh::ImplicitSystem::get_linear_solver(), libMesh::LinearImplicitSystem::solve(), and libMesh::NonlinearImplicitSystem::solve().

1980 { return this->name() + "_"; }
const std::string & name() const
Definition: system.h:2385

◆ prefix_with_name() [1/2]

void libMesh::System::prefix_with_name ( bool  value)
inlineinherited

Instructs this system to prefix solve options with its name for solvers that leverage prefixes.

Definition at line 1969 of file system.h.

References libMesh::System::_prefix_with_name, and value.

1969 { _prefix_with_name = value; }
static const bool value
Definition: xdr_io.C:55
bool _prefix_with_name
Whether we are name prefixing solver options.
Definition: system.h:2358

◆ prefix_with_name() [2/2]

bool libMesh::System::prefix_with_name ( ) const
inlineinherited
Returns
Whether we are name prefixing

Definition at line 1974 of file system.h.

References libMesh::System::_prefix_with_name.

Referenced by libMesh::ContinuationSystem::ContinuationSystem(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::LinearImplicitSystem::solve(), libMesh::NonlinearImplicitSystem::solve(), and libMesh::System::System().

1974 { return _prefix_with_name; }
bool _prefix_with_name
Whether we are name prefixing solver options.
Definition: system.h:2358

◆ print_info()

void libMesh::ReferenceCounter::print_info ( std::ostream &  out_stream = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

Definition at line 81 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

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

82 {
84  out_stream << ReferenceCounter::get_info();
85 }
static std::string get_info()
Gets a string containing the reference information.
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
The rank of this processor in the group.

Definition at line 114 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and TIMPI::Communicator::rank().

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::FEMSystem::assembly(), libMesh::Nemesis_IO::assert_symmetric_cmaps(), libMesh::Partitioner::assign_partitioning(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::Partitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshFunction::check_found_elem(), libMesh::DistributedMesh::clear(), libMesh::DistributedMesh::clear_elems(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), 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::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::Nemesis_IO::copy_scalar_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_scalar_dofs(), libMesh::DistributedMesh::DistributedMesh(), libMesh::DofMapBase::end_dof(), libMesh::DofMapBase::end_old_dof(), libMesh::EnsightIO::EnsightIO(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SubFunctor::find_dofs_to_send(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::DofMapBase::first_dof(), libMesh::DofMapBase::first_old_dof(), libMesh::RBEIMEvaluation::gather_bfs(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::get_info(), libMesh::DofMap::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::RBEIMEvaluation::get_interior_basis_functions_as_vecs(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::DofMap::get_local_constraints(), libMesh::MeshBase::get_local_constraints(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::LaplaceMeshSmoother::init(), libMesh::SystemSubsetBySubdomain::init(), HeatSystem::init_data(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::TransientRBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), 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_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), AugmentSparsityOnInterface::mesh_reinit(), libMesh::TriangulatorInterface::MeshedHole::MeshedHole(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::MeshTools::n_connected_components(), libMesh::MeshBase::n_constraint_rows(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::DofMapBase::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::RBEIMEvaluation::node_gather_bfs(), libMesh::DistributedMesh::own_node(), libMesh::BoundaryInfo::parallel_sync_node_ids(), libMesh::BoundaryInfo::parallel_sync_side_ids(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::print_constraint_rows(), libMesh::DofMap::print_dof_constraints(), libMesh::DofMap::process_mesh_constraint_rows(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read(), libMesh::EquationSystems::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::ExodusII_IO_Helper::read_global_values(), libMesh::ExodusII_IO::read_header(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::DynaIO::read_mesh(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::System::read_parallel_data(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), 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::System::read_serialized_data(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::Nemesis_IO_Helper::read_var_names_impl(), libMesh::SimplexRefiner::refine_via_edges(), libMesh::StaticCondensationDofMap::reinit(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::DistributedMesh::renumber_nodes_and_elements(), libMesh::DofMap::scatter_constraints(), libMesh::CheckpointIO::select_split_config(), libMesh::DistributedMesh::set_next_unique_id(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::RBEIMEvaluation::side_gather_bfs(), MeshFunctionTest::test_bad_gradient_var_with_out_of_mesh_value(), MeshFunctionTest::test_bad_hessian_var_with_out_of_mesh_value(), ExodusTest< elem_type >::test_read_gold(), ExodusTest< elem_type >::test_write(), MeshInputTest::testAbaqusRead(), MeshInputTest::testBadGmsh(), BoundaryInfoTest::testBoundaryIDs(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyElementVectorImpl(), MeshInputTest::testCopyNodalSolutionImpl(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), MeshInputTest::testDynaFileMappings(), MeshInputTest::testDynaNoSplines(), MeshInputTest::testDynaReadElem(), MeshInputTest::testDynaReadPatch(), MeshInputTest::testExodusFileMappings(), MeshInputTest::testExodusIGASidesets(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), MeshInputTest::testGmshBCIDOverlap(), MeshInputTest::testGoodGmsh(), MeshInputTest::testGoodSTL(), MeshInputTest::testGoodSTLBinary(), BoundaryInfoTest::testInternalBoundary(), MeshInputTest::testLowOrderEdgeBlocks(), SystemsTest::testProjectMatrix3D(), BoundaryInfoTest::testShellFaceConstraints(), MeshInputTest::testSingleElementImpl(), WriteVecAndScalar::testSolution(), CheckpointIOTest::testSplitter(), MeshInputTest::testTetgenIO(), MeshSmootherTest::testVariationalSmoother(), libMesh::MeshTools::total_weight(), libMesh::NetGenMeshInterface::triangulate(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::DTKAdapter::update_variable_values(), libMesh::MeshTools::volume(), libMesh::STLIO::write(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_element_values_element_major(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO_Helper::write_elemset_data(), libMesh::ExodusII_IO_Helper::write_elemsets(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::System::write_header(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::UCDIO::write_nodal_data(), libMesh::VTKIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::ExodusII_IO_Helper::write_nodeset_data(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::RBEIMEvaluation::write_out_interior_basis_functions(), libMesh::RBEIMEvaluation::write_out_node_basis_functions(), libMesh::RBEIMEvaluation::write_out_side_basis_functions(), write_output_solvedata(), libMesh::System::write_parallel_data(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::System::write_serialized_data(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), libMesh::ExodusII_IO_Helper::write_sideset_data(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), libMesh::ExodusII_IO_Helper::write_timestep(), and libMesh::ExodusII_IO::write_timestep_discontinuous().

115  { return cast_int<processor_id_type>(_communicator.rank()); }
processor_id_type rank() const
const Parallel::Communicator & _communicator

◆ project_solution() [1/3]

void libMesh::System::project_solution ( FunctionBase< Number > *  f,
FunctionBase< Gradient > *  g = nullptr,
std::optional< ConstElemRange active_local_range = std::nullopt,
std::optional< std::vector< unsigned int >>  variable_numbers = std::nullopt 
) const
inherited

Projects arbitrary functions onto the current solution.

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

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. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection. variable_numbers variable_numbers, if provided, indicates the variable numbers onto which to project.

Definition at line 1064 of file system_projection.C.

Referenced by init_sys(), initialize(), main(), set_initial_condition(), SlitMeshRefinedSystemTest::setUp(), FETestBase< order, family, elem_type, N_x >::setUp(), MeshFunctionTest::test_bad_gradient_var_with_out_of_mesh_value(), MeshFunctionTest::test_bad_hessian_var_with_out_of_mesh_value(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), ProjectSolutionTest::test_partial_project_solution(), MeshFunctionTest::test_subdomain_id_sets(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyNodalSolutionImpl(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), SystemsTest::testProjectCubeWithMeshFunction(), MeshInputTest::testProjectionRegression(), EquationSystemsTest::testRepartitionThenReinit(), and libMesh::MeshfreeSolutionTransfer::transfer().

1068 {
1069  this->project_vector(*solution, f, g, /*is_adjoint=*/-1, active_local_range, variable_numbers);
1070 
1071  solution->localize(*current_local_solution, _dof_map->get_send_list());
1072 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...

◆ project_solution() [2/3]

void libMesh::System::project_solution ( FEMFunctionBase< Number > *  f,
FEMFunctionBase< Gradient > *  g = nullptr,
std::optional< ConstElemRange active_local_range = std::nullopt,
std::optional< std::vector< unsigned int >>  variable_numbers = std::nullopt 
) const
inherited

Projects arbitrary functions onto the current solution.

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

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. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection. variable_numbers variable_numbers, if provided, indicates the variable numbers onto which to project.

Definition at line 1079 of file system_projection.C.

1083 {
1084  this->project_vector(*solution, f, g, /*is_adjoint=*/-1, active_local_range, variable_numbers);
1085 
1086  solution->localize(*current_local_solution, _dof_map->get_send_list());
1087 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...

◆ project_solution() [3/3]

void libMesh::System::project_solution ( ValueFunctionPointer  fptr,
GradientFunctionPointer  gptr,
const Parameters parameters,
std::optional< ConstElemRange active_local_range = std::nullopt,
std::optional< std::vector< unsigned int >>  variable_numbers = std::nullopt 
) const
inherited

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

Definition at line 1048 of file system_projection.C.

References fptr(), and gptr().

1053 {
1054  WrappedFunction<Number> f(*this, fptr, &function_parameters);
1055  WrappedFunction<Gradient> g(*this, gptr, &function_parameters);
1056  this->project_solution(&f, &g, active_local_range, variable_numbers);
1057 }
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto the current solution.
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:96

◆ project_solution_on_reinit()

bool& libMesh::System::project_solution_on_reinit ( void  )
inlineinherited

Tells the System whether or not to project the solution vector onto new grids when the system is reinitialized.

The solution will be projected unless project_solution_on_reinit() = false is called.

Definition at line 884 of file system.h.

References libMesh::System::_solution_projection.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), and libMesh::MemoryHistoryData::store_vectors().

885  { return _solution_projection; }
bool _solution_projection
Holds true if the solution vector should be projected onto a changed grid, false if it should be zero...
Definition: system.h:2294

◆ project_vector() [1/5]

void libMesh::System::project_vector ( NumericVector< Number > &  new_vector,
FunctionBase< Number > *  f,
FunctionBase< Gradient > *  g = nullptr,
int  is_adjoint = -1,
std::optional< ConstElemRange active_local_range = std::nullopt,
std::optional< std::vector< unsigned int >>  variable_numbers = std::nullopt 
) const
inherited

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

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

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. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection. variable_numbers variable_numbers, if provided, indicates the variable numbers onto which to project.

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

Definition at line 1111 of file system_projection.C.

References libMesh::libmesh_assert().

Referenced by main(), libMesh::NewmarkSolver::project_initial_accel(), libMesh::SecondOrderUnsteadySolver::project_initial_rate(), libMesh::InterMeshProjection::project_system_vectors(), and libMesh::System::restrict_vectors().

1117 {
1118  LOG_SCOPE ("project_vector(FunctionBase)", "System");
1119 
1120  libmesh_assert(f);
1121 
1122  WrappedFunctor<Number> f_fem(*f);
1123 
1124  if (g)
1125  {
1126  WrappedFunctor<Gradient> g_fem(*g);
1127 
1128  this->project_vector(new_vector, &f_fem, &g_fem, is_adjoint, active_local_range, variable_numbers);
1129  }
1130  else
1131  this->project_vector(new_vector, &f_fem, nullptr, is_adjoint, active_local_range, variable_numbers);
1132 }
libmesh_assert(ctx)
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...

◆ project_vector() [2/5]

void libMesh::System::project_vector ( NumericVector< Number > &  new_vector,
FEMFunctionBase< Number > *  f,
FEMFunctionBase< Gradient > *  g = nullptr,
int  is_adjoint = -1,
std::optional< ConstElemRange active_local_range = std::nullopt,
std::optional< std::vector< unsigned int >>  variable_numbers = std::nullopt 
) const
inherited

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

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

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. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection. variable_numbers variable_numbers, if provided, indicates the variable numbers onto which to project.

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

Definition at line 1139 of file system_projection.C.

References libMesh::NumericVector< T >::close(), libMesh::FEMFunctionBase< Output >::component(), libMesh::FEType::family, libMesh::libmesh_assert(), libMesh::libmesh_ignore(), n_vars, libMesh::NODEELEM, libMesh::FEMContext::pre_fe_reinit(), libMesh::RATIONAL_BERNSTEIN, libMesh::SCALAR, libMesh::DofMap::SCALAR_dof_indices(), libMesh::NumericVector< T >::set(), and libMesh::Variable::type().

1145 {
1146  LOG_SCOPE ("project_fem_vector()", "System");
1147 
1148  libmesh_assert (f);
1149 
1150  if (!active_local_range)
1151  {
1152  active_local_range.emplace
1153  (this->get_mesh().active_local_elements_begin(),
1154  this->get_mesh().active_local_elements_end());
1155  }
1156 
1157  VectorSetAction<Number> setter(new_vector);
1158 
1159  const unsigned int n_variables = this->n_vars();
1160 
1161  std::vector<unsigned int> vars;
1162  if (variable_numbers)
1163  {
1164  vars = *variable_numbers;
1165  for (auto v : vars)
1166  if (v >= n_variables)
1167  libmesh_error_msg("ERROR: variable number " << v <<
1168  " out of range for system with " <<
1169  n_variables << " variables.");
1170  }
1171  else
1172  {
1173  vars.resize(n_variables);
1174  std::iota(vars.begin(), vars.end(), 0);
1175  }
1176 
1177 
1178  // Use a typedef to make the calling sequence for parallel_for() a bit more readable
1179  typedef
1180  GenericProjector<FEMFunctionWrapper<Number>, FEMFunctionWrapper<Gradient>,
1181  Number, VectorSetAction<Number>> FEMProjector;
1182 
1183  FEMFunctionWrapper<Number> fw(*f);
1184 
1185  if (g)
1186  {
1187  FEMFunctionWrapper<Gradient> gw(*g);
1188 
1189  FEMProjector projector(*this, fw, &gw, setter, vars);
1190  projector.project(active_local_range.value());
1191  }
1192  else
1193  {
1194  FEMProjector projector(*this, fw, nullptr, setter, vars);
1195  projector.project(active_local_range.value());
1196  }
1197 
1198  // Also, load values into the SCALAR dofs
1199  // Note: We assume that all SCALAR dofs are on the
1200  // processor with highest ID
1201  if (this->processor_id() == (this->n_processors()-1))
1202  {
1203  // FIXME: Do we want to first check for SCALAR vars before building this? [PB]
1204  FEMContext context( *this );
1205 
1206  const DofMap & dof_map = this->get_dof_map();
1207  for (auto var : vars)
1208  if (this->variable(var).type().family == SCALAR)
1209  {
1210  // FIXME: We reinit with an arbitrary element in case the user
1211  // doesn't override FEMFunctionBase::component. Is there
1212  // any use case we're missing? [PB]
1213  context.pre_fe_reinit(*this, *(this->get_mesh().active_local_elements_begin()));
1214 
1215  std::vector<dof_id_type> SCALAR_indices;
1216  dof_map.SCALAR_dof_indices (SCALAR_indices, var);
1217  const unsigned int n_SCALAR_dofs =
1218  cast_int<unsigned int>(SCALAR_indices.size());
1219 
1220  for (unsigned int i=0; i<n_SCALAR_dofs; i++)
1221  {
1222  const dof_id_type global_index = SCALAR_indices[i];
1223  const unsigned int component_index =
1224  this->variable_scalar_number(var,i);
1225 
1226  new_vector.set(global_index, f->component(context, component_index, Point(), this->time));
1227  }
1228  }
1229  }
1230 
1231  new_vector.close();
1232 
1233  // Look for spline bases, in which case we need to backtrack
1234  // to calculate the spline DoF values.
1235  std::vector<const Variable *> rational_vars;
1236  for (auto varnum : vars)
1237  {
1238  const Variable & var = this->get_dof_map().variable(varnum);
1239  if (var.type().family == RATIONAL_BERNSTEIN)
1240  rational_vars.push_back(&var);
1241  }
1242 
1243  // Okay, but are we really using any *spline* bases, or just
1244  // unconstrained rational bases?
1245  bool using_spline_bases = false;
1246  if (!rational_vars.empty())
1247  {
1248  // Look for a spline node: a NodeElem with a rational variable
1249  // on it.
1250  for (auto & elem : active_local_range.value())
1251  if (elem->type() == NODEELEM)
1252  for (auto rational_var : rational_vars)
1253  if (rational_var->active_on_subdomain(elem->subdomain_id()))
1254  {
1255  using_spline_bases = true;
1256  goto checked_on_splines;
1257  }
1258  }
1259 
1260 checked_on_splines:
1261 
1262  // Not every processor may have a NodeElem, especially while
1263  // we're not partitioning them efficiently yet.
1264  this->comm().max(using_spline_bases);
1265 
1266  if (using_spline_bases)
1267  this->solve_for_unconstrained_dofs(new_vector, is_adjoint);
1268 
1269 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1270  if (is_adjoint == -1)
1271  this->get_dof_map().enforce_constraints_exactly(*this, &new_vector);
1272  else if (is_adjoint >= 0)
1274  is_adjoint);
1275 #else
1276  libmesh_ignore(is_adjoint);
1277 #endif
1278 }
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
Definition: system.h:1677
unsigned int variable_scalar_number(std::string_view var, unsigned int component) const
Definition: system.h:2474
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
const Parallel::Communicator & comm() const
const MeshBase & get_mesh() const
Definition: system.h:2401
const Variable & variable(const unsigned int c) const override
Definition: dof_map.h:2358
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
Heterogeneously constrains the numeric vector v, which represents an adjoint solution defined on the ...
Definition: dof_map.h:2522
processor_id_type n_processors() const
void libmesh_ignore(const Args &...)
libmesh_assert(ctx)
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
void max(const T &r, T &o, Request &req) const
virtual Output component(const FEMContext &, unsigned int i, const Point &p, Real time=0.)
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
unsigned int n_vars() const
Definition: system.C:2669
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2417
void solve_for_unconstrained_dofs(NumericVector< Number > &, int is_adjoint=-1) const
uint8_t dof_id_type
Definition: id_types.h:67
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:2518

◆ project_vector() [3/5]

void libMesh::System::project_vector ( ValueFunctionPointer  fptr,
GradientFunctionPointer  gptr,
const Parameters parameters,
NumericVector< Number > &  new_vector,
int  is_adjoint = -1,
std::optional< ConstElemRange active_local_range = std::nullopt,
std::optional< std::vector< unsigned int >>  variable_numbers = std::nullopt 
) const
inherited

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

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

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. elem_range active_local_range, if provided, indicates the range of elements over which to perform the projection. variable_numbers variable_numbers, if provided, indicates the variable numbers onto which to project.

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

Definition at line 1094 of file system_projection.C.

References fptr(), and gptr().

1101 {
1102  WrappedFunction<Number> f(*this, fptr, &function_parameters);
1103  WrappedFunction<Gradient> g(*this, gptr, &function_parameters);
1104  this->project_vector(new_vector, &f, &g, is_adjoint, active_local_range, variable_numbers);
1105 }
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:81
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:96
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...

◆ project_vector() [4/5]

void libMesh::System::project_vector ( NumericVector< Number > &  vector,
int  is_adjoint = -1,
std::optional< ConstElemRange active_local_range = std::nullopt,
std::optional< std::vector< unsigned int >>  variable_numbers = std::nullopt 
) const
protectedinherited

Projects the vector defined on the old mesh onto the new mesh.

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

Definition at line 247 of file system_projection.C.

References libMesh::NumericVector< T >::clone().

251 {
252  // Create a copy of the vector, which currently
253  // contains the old data.
254  std::unique_ptr<NumericVector<Number>>
255  old_vector (vector.clone());
256 
257  // Project the old vector to the new vector
258  this->project_vector (*old_vector, vector, is_adjoint, active_local_range, variable_numbers);
259 }
virtual std::unique_ptr< NumericVector< T > > clone() const =0
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...

◆ project_vector() [5/5]

void libMesh::System::project_vector ( const NumericVector< Number > &  old_v,
NumericVector< Number > &  new_v,
int  is_adjoint = -1,
std::optional< ConstElemRange active_local_range = std::nullopt,
std::optional< std::vector< unsigned int >>  variable_numbers = std::nullopt 
) const
protectedinherited

Projects the vector defined on the old mesh onto the new mesh.

This method projects the vector via L2 projections or nodal interpolations on each element.

The original vector is unchanged and the new vector is passed through the second argument.

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

This method projects a solution from an old mesh to a current, refined mesh. The input vector old_v gives the solution on the old mesh, while the new_v gives the solution (to be computed) on the new mesh.

Definition at line 267 of file system_projection.C.

References libMesh::NumericVector< T >::clear(), libMesh::NumericVector< T >::close(), libMesh::NumericVector< T >::get(), libMesh::GHOSTED, libMesh::index_range(), libMesh::NumericVector< T >::init(), libMesh::libmesh_assert(), libMesh::libmesh_ignore(), libMesh::NumericVector< T >::local_size(), libMesh::NumericVector< T >::localize(), libMesh::make_range(), n_vars, libMesh::PARALLEL, libMesh::Threads::parallel_reduce(), libMesh::SCALAR, libMesh::DofMap::SCALAR_dof_indices(), libMesh::BuildProjectionList::send_list, libMesh::SERIAL, libMesh::NumericVector< T >::set(), libMesh::NumericVector< T >::size(), libMesh::NumericVector< T >::type(), libMesh::TYPE_SCALAR, and libMesh::BuildProjectionList::unique().

272 {
273  LOG_SCOPE ("project_vector(old,new)", "System");
274 
281  new_v.clear();
282 
283 #ifdef LIBMESH_ENABLE_AMR
284 
285  // Resize the new vector and get a serial version.
286  NumericVector<Number> * new_vector_ptr = nullptr;
287  std::unique_ptr<NumericVector<Number>> new_vector_built;
288  NumericVector<Number> * local_old_vector;
289  std::unique_ptr<NumericVector<Number>> local_old_vector_built;
290  const NumericVector<Number> * old_vector_ptr = nullptr;
291 
292  if (!active_local_range)
293  {
294  active_local_range.emplace
295  (this->get_mesh().active_local_elements_begin(),
296  this->get_mesh().active_local_elements_end());
297  }
298 
299  // If the old vector was uniprocessor, make the new
300  // vector uniprocessor
301  if (old_v.type() == SERIAL)
302  {
303  new_v.init (this->n_dofs(), false, SERIAL);
304  new_vector_ptr = &new_v;
305  old_vector_ptr = &old_v;
306  }
307 
308  // Otherwise it is a parallel, distributed vector, which
309  // we need to localize.
310  else if (old_v.type() == PARALLEL)
311  {
312  // Build a send list for efficient localization
313  BuildProjectionList projection_list(*this);
314  Threads::parallel_reduce (active_local_range.value(),
315  projection_list);
316 
317  // Create a sorted, unique send_list
318  projection_list.unique();
319 
320  new_v.init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
321  new_vector_built = NumericVector<Number>::build(this->comm());
322  local_old_vector_built = NumericVector<Number>::build(this->comm());
323  new_vector_ptr = new_vector_built.get();
324  local_old_vector = local_old_vector_built.get();
325  new_vector_ptr->init(this->n_dofs(), this->n_local_dofs(),
326  this->get_dof_map().get_send_list(), false,
327  GHOSTED);
328  local_old_vector->init(old_v.size(), old_v.local_size(),
329  projection_list.send_list, false, GHOSTED);
330  old_v.localize(*local_old_vector, projection_list.send_list);
331  local_old_vector->close();
332  old_vector_ptr = local_old_vector;
333  }
334  else if (old_v.type() == GHOSTED)
335  {
336  // Build a send list for efficient localization
337  BuildProjectionList projection_list(*this);
338  Threads::parallel_reduce (active_local_range.value(),
339  projection_list);
340 
341  // Create a sorted, unique send_list
342  projection_list.unique();
343 
344  new_v.init (this->n_dofs(), this->n_local_dofs(),
345  this->get_dof_map().get_send_list(), false, GHOSTED);
346 
347  local_old_vector_built = NumericVector<Number>::build(this->comm());
348  new_vector_ptr = &new_v;
349  local_old_vector = local_old_vector_built.get();
350  local_old_vector->init(old_v.size(), old_v.local_size(),
351  projection_list.send_list, false, GHOSTED);
352  old_v.localize(*local_old_vector, projection_list.send_list);
353  local_old_vector->close();
354  old_vector_ptr = local_old_vector;
355  }
356  else // unknown old_v.type()
357  libmesh_error_msg("ERROR: Unknown old_v.type() == " << old_v.type());
358 
359  // Note that the above will have zeroed the new_vector.
360  // Just to be sure, assert that new_vector_ptr and old_vector_ptr
361  // were successfully set before trying to deref them.
362  libmesh_assert(new_vector_ptr);
363  libmesh_assert(old_vector_ptr);
364 
365  NumericVector<Number> & new_vector = *new_vector_ptr;
366  const NumericVector<Number> & old_vector = *old_vector_ptr;
367 
368  const unsigned int n_variables = this->n_vars();
369 
370  if (n_variables)
371  {
372  std::vector<unsigned int> vars;
373  if (variable_numbers)
374  {
375  vars = *variable_numbers;
376  for (auto v : vars)
377  if (v >= n_variables)
378  libmesh_error_msg("ERROR: variable number " << v <<
379  " out of range for system with " <<
380  n_variables << " variables.");
381  }
382  else
383  {
384  vars.resize(n_variables);
385  std::iota(vars.begin(), vars.end(), 0);
386  }
387 
388  std::vector<unsigned int> regular_vars, vector_vars;
389  for (auto var : vars)
390  {
392  regular_vars.push_back(var);
393  else
394  vector_vars.push_back(var);
395  }
396 
397  VectorSetAction<Number> setter(new_vector);
398 
399  if (!regular_vars.empty())
400  {
401  // Use a typedef to make the calling sequence for parallel_for() a bit more readable
402  typedef
403  GenericProjector<OldSolutionValue<Number, &FEMContext::point_value>,
404  OldSolutionValue<Gradient, &FEMContext::point_gradient>,
405  Number, VectorSetAction<Number>> FEMProjector;
406 
407  OldSolutionValue<Number, &FEMContext::point_value>
408  f(*this, old_vector, &regular_vars);
409  OldSolutionValue<Gradient, &FEMContext::point_gradient>
410  g(*this, old_vector, &regular_vars);
411 
412  FEMProjector projector(*this, f, &g, setter, regular_vars);
413  projector.project(active_local_range.value());
414  }
415 
416  if (!vector_vars.empty())
417  {
418  typedef
419  GenericProjector<OldSolutionValue<Gradient, &FEMContext::point_value>,
420  OldSolutionValue<Tensor, &FEMContext::point_gradient>,
421  Gradient, VectorSetAction<Number>> FEMVectorProjector;
422 
423  OldSolutionValue<Gradient, &FEMContext::point_value> f_vector(*this, old_vector, &vector_vars);
424  OldSolutionValue<Tensor, &FEMContext::point_gradient> g_vector(*this, old_vector, &vector_vars);
425 
426  FEMVectorProjector vector_projector(*this, f_vector, &g_vector, setter, vector_vars);
427  vector_projector.project(active_local_range.value());
428  }
429 
430  // Copy the SCALAR dofs from old_vector to new_vector
431  // Note: We assume that all SCALAR dofs are on the
432  // processor with highest ID
433  if (this->processor_id() == (this->n_processors()-1))
434  {
435  const DofMap & dof_map = this->get_dof_map();
436  for (auto var : vars)
437  if (this->variable(var).type().family == SCALAR)
438  {
439  // We can just map SCALAR dofs directly across
440  std::vector<dof_id_type> new_SCALAR_indices, old_SCALAR_indices;
441  dof_map.SCALAR_dof_indices (new_SCALAR_indices, var, false);
442  dof_map.SCALAR_dof_indices (old_SCALAR_indices, var, true);
443  for (auto i : index_range(new_SCALAR_indices))
444  new_vector.set(new_SCALAR_indices[i], old_vector(old_SCALAR_indices[i]));
445  }
446  }
447  }
448 
449  new_vector.close();
450 
451  // If the old vector was serial, we probably need to send our values
452  // to other processors
453  //
454  // FIXME: I'm not sure how to make a NumericVector do that without
455  // creating a temporary parallel vector to use localize! - RHS
456  if (old_v.type() == SERIAL)
457  {
458  std::unique_ptr<NumericVector<Number>> dist_v = NumericVector<Number>::build(this->comm());
459  dist_v->init(this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
460  dist_v->close();
461 
462  for (auto i : make_range(dist_v->size()))
463  if (new_vector(i) != 0.0)
464  dist_v->set(i, new_vector(i));
465 
466  dist_v->close();
467 
468  dist_v->localize (new_v, this->get_dof_map().get_send_list());
469  new_v.close();
470  }
471  // If the old vector was parallel, we need to update it
472  // and free the localized copies
473  else if (old_v.type() == PARALLEL)
474  {
475  // We may have to set dof values that this processor doesn't
476  // own in certain special cases, like LAGRANGE FIRST or
477  // HERMITE THIRD elements on second-order meshes?
478  new_v = new_vector;
479  new_v.close();
480  }
481 
482 
483  // Apply constraints only if we we are asked to
484  if(this->project_with_constraints)
485  {
486  if (is_adjoint == -1)
487  {
488  this->get_dof_map().enforce_constraints_exactly(*this, &new_v);
489  }
490  else if (is_adjoint >= 0)
491  {
493  is_adjoint);
494  }
495  }
496 #else
497 
498  // AMR is disabled: simply copy the vector
499  new_v = old_v;
500 
501  libmesh_ignore(is_adjoint, active_local_range, variable_numbers);
502 
503 #endif // #ifdef LIBMESH_ENABLE_AMR
504 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
Access multiple components at once.
virtual numeric_index_type size() const =0
static FEFieldType field_type(const FEType &fe_type)
const Parallel::Communicator & comm() const
dof_id_type n_local_dofs() const
Definition: system.C:155
const MeshBase & get_mesh() const
Definition: system.h:2401
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
dof_id_type n_dofs() const
Definition: system.C:118
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
Heterogeneously constrains the numeric vector v, which represents an adjoint solution defined on the ...
Definition: dof_map.h:2522
processor_id_type n_processors() const
void libmesh_ignore(const Args &...)
NumberVectorValue Gradient
bool project_with_constraints
Do we want to apply constraints while projecting vectors ?
Definition: system.h:2343
libmesh_assert(ctx)
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided reduction operation in parallel on the specified range.
Definition: threads_none.h:109
ParallelType type() const
const FEType & variable_type(const unsigned int i) const
Definition: system.C:2716
virtual numeric_index_type local_size() const =0
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
virtual void clear()
Restores the NumericVector<T> to a pristine state.
unsigned int n_vars() const
Definition: system.C:2669
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2417
template class LIBMESH_EXPORT NumericVector< Number >
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:150
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:2518
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.

◆ projection_matrix()

void libMesh::System::projection_matrix ( SparseMatrix< Number > &  proj_mat) const
inherited

This method creates a projection matrix which corresponds to the operation of project_vector between old and new solution spaces.

Heterogeneous Dirichlet boundary conditions are not taken into account here; if this matrix is used for prolongation (mesh refinement) on a side with a heterogeneous BC, the newly created degrees of freedom on that side will still match the coarse grid approximation of the BC, not the fine grid approximation.

Definition at line 982 of file system_projection.C.

References libMesh::make_range(), n_vars, libMesh::SCALAR, libMesh::DofMap::SCALAR_dof_indices(), and libMesh::SparseMatrix< T >::set().

Referenced by libMesh::PetscDMWrapper::init_petscdm(), SystemsTest::testProjectMatrix1D(), SystemsTest::testProjectMatrix2D(), and SystemsTest::testProjectMatrix3D().

983 {
984  LOG_SCOPE ("projection_matrix()", "System");
985 
986  const unsigned int n_variables = this->n_vars();
987 
988  if (n_variables)
989  {
990  ConstElemRange active_local_elem_range
991  (this->get_mesh().active_local_elements_begin(),
992  this->get_mesh().active_local_elements_end());
993 
994  std::vector<unsigned int> vars(n_variables);
995  std::iota(vars.begin(), vars.end(), 0);
996 
997  // Use a typedef to make the calling sequence for parallel_for() a bit more readable
998  typedef OldSolutionCoefs<Real, &FEMContext::point_value> OldSolutionValueCoefs;
999  typedef OldSolutionCoefs<RealGradient, &FEMContext::point_gradient> OldSolutionGradientCoefs;
1000 
1001  typedef
1002  GenericProjector<OldSolutionValueCoefs,
1003  OldSolutionGradientCoefs,
1004  DynamicSparseNumberArray<Real,dof_id_type>,
1005  MatrixFillAction<Real, Number> > ProjMatFiller;
1006 
1007  OldSolutionValueCoefs f(*this, &vars);
1008  OldSolutionGradientCoefs g(*this, &vars);
1009  MatrixFillAction<Real, Number> setter(proj_mat);
1010 
1011  ProjMatFiller mat_filler(*this, f, &g, setter, vars);
1012  mat_filler.project(active_local_elem_range);
1013 
1014  // Set the SCALAR dof transfer entries too.
1015  // Note: We assume that all SCALAR dofs are on the
1016  // processor with highest ID
1017  if (this->processor_id() == (this->n_processors()-1))
1018  {
1019  const DofMap & dof_map = this->get_dof_map();
1020  for (auto var : make_range(this->n_vars()))
1021  if (this->variable(var).type().family == SCALAR)
1022  {
1023  // We can just map SCALAR dofs directly across
1024  std::vector<dof_id_type> new_SCALAR_indices, old_SCALAR_indices;
1025  dof_map.SCALAR_dof_indices (new_SCALAR_indices, var, false);
1026  dof_map.SCALAR_dof_indices (old_SCALAR_indices, var, true);
1027  const unsigned int new_n_dofs =
1028  cast_int<unsigned int>(new_SCALAR_indices.size());
1029 
1030  for (unsigned int i=0; i<new_n_dofs; i++)
1031  {
1032  proj_mat.set( new_SCALAR_indices[i],
1033  old_SCALAR_indices[i], 1);
1034  }
1035  }
1036  }
1037  }
1038 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
const MeshBase & get_mesh() const
Definition: system.h:2401
StoredRange< MeshBase::const_element_iterator, const Elem * > ConstElemRange
Definition: elem_range.h:34
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
processor_id_type n_processors() const
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
unsigned int n_vars() const
Definition: system.C:2669
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ prolong_vectors()

void libMesh::System::prolong_vectors ( )
virtualinherited

Prolong vectors after the mesh has refined.

Definition at line 432 of file system.C.

References libMesh::System::restrict_vectors().

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

433 {
434 #ifdef LIBMESH_ENABLE_AMR
435  // Currently project_vector handles both restriction and prolongation
436  this->restrict_vectors();
437 #endif
438 }
virtual void restrict_vectors()
Restrict vectors after the mesh has coarsened.
Definition: system.C:374

◆ push_physics()

void libMesh::DifferentiableSystem::push_physics ( DifferentiablePhysics new_physics)
inherited

Push a clone of a new physics object onto our stack, overriding the current physics until the new physics is popped off again (or until something else is pushed on top of it).

Definition at line 331 of file diff_system.C.

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

Referenced by main().

332 {
333  this->_diff_physics.push(new_physics.clone_physics());
334 
335  // If the physics has been changed, we will reassemble
336  // the matrix from scratch before doing an adjoint solve
337  // rather than just transposing
338  this->disable_cache();
339 }
std::stack< std::unique_ptr< DifferentiablePhysics >, std::vector< std::unique_ptr< DifferentiablePhysics > > > _diff_physics
Stack of pointers to objects to use for physics assembly evaluations.
Definition: diff_system.h:434
virtual void disable_cache() override
Avoids use of any cached data that might affect any solve result.

◆ qoi_parameter_hessian()

void libMesh::ImplicitSystem::qoi_parameter_hessian ( const QoISet qoi_indices,
const ParameterVector parameters,
SensitivityData hessian 
)
overridevirtualinherited

For each of the system's quantities of interest q in qoi[qoi_indices], and for a vector of parameters p, the parameter sensitivity Hessian H_ij is defined as H_ij = (d^2 q)/(d p_i d p_j) This Hessian is the output of this method, where for each q_i, H_jk is stored in hessian.second_derivative(i,j,k).

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::System.

Definition at line 922 of file implicit_system.C.

References libMesh::ImplicitSystem::adjoint_solve(), libMesh::SensitivityData::allocate_hessian_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_adjoint_solution(), libMesh::System::get_qoi_value(), libMesh::System::get_qoi_values(), libMesh::System::get_sensitivity_solution(), libMesh::QoISet::has_index(), libMesh::System::is_adjoint_already_solved(), libMesh::ImplicitSystem::matrix, libMesh::System::n_qois(), libMesh::Real, libMesh::ExplicitSystem::rhs, libMesh::SensitivityData::second_derivative(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::ParameterVector::size(), libMesh::System::solution, libMesh::TOLERANCE, libMesh::System::update(), and libMesh::SparseMatrix< T >::vector_mult().

925 {
926  // We currently get partial derivatives via finite differencing
927  const Real delta_p = TOLERANCE;
928 
929  ParameterVector & parameters_vec =
930  const_cast<ParameterVector &>(parameters_in);
931 
932  // We'll use one temporary vector for matrix-vector-vector products
933  std::unique_ptr<NumericVector<Number>> tempvec = this->solution->zero_clone();
934 
935  // And another temporary vector to hold a copy of the true solution
936  // so we can safely perturb this->solution.
937  std::unique_ptr<NumericVector<Number>> oldsolution = this->solution->clone();
938 
939  const unsigned int Np = cast_int<unsigned int>
940  (parameters_vec.size());
941  const unsigned int Nq = this->n_qois();
942 
943  // For each quantity of interest q, the parameter sensitivity
944  // Hessian is defined as q''_{kl} = {d^2 q}/{d p_k d p_l}.
945  //
946  // We calculate it from values and partial derivatives of the
947  // quantity of interest function Q, solution u, adjoint solution z,
948  // and residual R, as:
949  //
950  // q''_{kl} =
951  // Q''_{kl} + Q''_{uk}(u)*u'_l + Q''_{ul}(u) * u'_k +
952  // Q''_{uu}(u)*u'_k*u'_l -
953  // R''_{kl}(u,z) -
954  // R''_{uk}(u,z)*u'_l - R''_{ul}(u,z)*u'_k -
955  // R''_{uu}(u,z)*u'_k*u'_l
956  //
957  // See the adjoints model document for more details.
958 
959  // We first do an adjoint solve to get z for each quantity of
960  // interest
961  // if we haven't already or dont have an initial condition for the adjoint
962  if (!this->is_adjoint_already_solved())
963  {
964  this->adjoint_solve(qoi_indices);
965  }
966 
967  // And a sensitivity solve to get u_k for each parameter
968  this->sensitivity_solve(parameters_vec);
969 
970  // Get ready to fill in second derivatives:
971  sensitivities.allocate_hessian_data(qoi_indices, *this, parameters_vec);
972 
973  for (unsigned int k=0; k != Np; ++k)
974  {
975  Number old_parameterk = *parameters_vec[k];
976 
977  // The Hessian is symmetric, so we just calculate the lower
978  // triangle and the diagonal, and we get the upper triangle from
979  // the transpose of the lower
980 
981  for (unsigned int l=0; l != k+1; ++l)
982  {
983  // The second partial derivatives with respect to parameters_vec
984  // are all calculated via a central finite difference
985  // stencil:
986  // F''_{kl} ~= (F(p+dp*e_k+dp*e_l) - F(p+dp*e_k-dp*e_l) -
987  // F(p-dp*e_k+dp*e_l) + F(p-dp*e_k-dp*e_l))/(4*dp^2)
988  // We will add Q''_{kl}(u) and subtract R''_{kl}(u,z) at the
989  // same time.
990  //
991  // We have to be careful with the perturbations to handle
992  // the k=l case
993 
994  Number old_parameterl = *parameters_vec[l];
995 
996  *parameters_vec[k] += delta_p;
997  *parameters_vec[l] += delta_p;
998  this->assemble_qoi(qoi_indices);
999  this->assembly(true, false, true);
1000  this->rhs->close();
1001  std::vector<Number> partial2q_term = this->get_qoi_values();
1002  std::vector<Number> partial2R_term(this->n_qois());
1003  for (unsigned int i=0; i != Nq; ++i)
1004  if (qoi_indices.has_index(i))
1005  partial2R_term[i] = this->rhs->dot(this->get_adjoint_solution(i));
1006 
1007  *parameters_vec[l] -= 2.*delta_p;
1008  this->assemble_qoi(qoi_indices);
1009  this->assembly(true, false, true);
1010  this->rhs->close();
1011  for (unsigned int i=0; i != Nq; ++i)
1012  if (qoi_indices.has_index(i))
1013  {
1014  partial2q_term[i] -= this->get_qoi_value(i);
1015  partial2R_term[i] -= this->rhs->dot(this->get_adjoint_solution(i));
1016  }
1017 
1018  *parameters_vec[k] -= 2.*delta_p;
1019  this->assemble_qoi(qoi_indices);
1020  this->assembly(true, false, true);
1021  this->rhs->close();
1022  for (unsigned int i=0; i != Nq; ++i)
1023  if (qoi_indices.has_index(i))
1024  {
1025  partial2q_term[i] += this->get_qoi_value(i);
1026  partial2R_term[i] += this->rhs->dot(this->get_adjoint_solution(i));
1027  }
1028 
1029  *parameters_vec[l] += 2.*delta_p;
1030  this->assemble_qoi(qoi_indices);
1031  this->assembly(true, false, true);
1032  this->rhs->close();
1033  for (unsigned int i=0; i != Nq; ++i)
1034  if (qoi_indices.has_index(i))
1035  {
1036  partial2q_term[i] -= this->get_qoi_value(i);
1037  partial2R_term[i] -= this->rhs->dot(this->get_adjoint_solution(i));
1038  partial2q_term[i] /= (4. * delta_p * delta_p);
1039  partial2R_term[i] /= (4. * delta_p * delta_p);
1040  }
1041 
1042  for (unsigned int i=0; i != Nq; ++i)
1043  if (qoi_indices.has_index(i))
1044  {
1045  Number current_terms = partial2q_term[i] - partial2R_term[i];
1046  sensitivities.second_derivative(i,k,l) += current_terms;
1047  if (k != l)
1048  sensitivities.second_derivative(i,l,k) += current_terms;
1049  }
1050 
1051  // Don't leave the parameters_vec perturbed
1052  *parameters_vec[l] = old_parameterl;
1053  *parameters_vec[k] = old_parameterk;
1054  }
1055 
1056  // We get (partial q / partial u) and
1057  // (partial R / partial u) from the user, but centrally
1058  // difference to get q_uk and R_uk terms:
1059  // (partial^2 q / partial u partial k)
1060  // q_uk*u'_l = (q_u(p+dp*e_k)*u'_l - q_u(p-dp*e_k)*u'_l)/(2*dp)
1061  // R_uk*z*u'_l = (R_u(p+dp*e_k)*z*u'_l - R_u(p-dp*e_k)*z*u'_l)/(2*dp)
1062  //
1063  // To avoid creating Nq temporary vectors, we add these
1064  // subterms to the sensitivities output one by one.
1065  //
1066  // FIXME: this is probably a bad order of operations for
1067  // controlling floating point error.
1068 
1069  *parameters_vec[k] = old_parameterk + delta_p;
1070  this->assembly(false, true);
1071  this->matrix->close();
1072  this->assemble_qoi_derivative(qoi_indices,
1073  /* include_liftfunc = */ true,
1074  /* apply_constraints = */ false);
1075 
1076  for (unsigned int l=0; l != Np; ++l)
1077  {
1078  this->matrix->vector_mult(*tempvec, this->get_sensitivity_solution(l));
1079  for (unsigned int i=0; i != Nq; ++i)
1080  if (qoi_indices.has_index(i))
1081  {
1082  this->get_adjoint_rhs(i).close();
1083  Number current_terms =
1084  (this->get_adjoint_rhs(i).dot(this->get_sensitivity_solution(l)) -
1085  tempvec->dot(this->get_adjoint_solution(i))) / (2.*delta_p);
1086  sensitivities.second_derivative(i,k,l) += current_terms;
1087 
1088  // We use the _uk terms twice; symmetry lets us reuse
1089  // these calculations for the _ul terms.
1090 
1091  sensitivities.second_derivative(i,l,k) += current_terms;
1092  }
1093  }
1094 
1095  *parameters_vec[k] = old_parameterk - delta_p;
1096  this->assembly(false, true);
1097  this->matrix->close();
1098  this->assemble_qoi_derivative(qoi_indices,
1099  /* include_liftfunc = */ true,
1100  /* apply_constraints = */ false);
1101 
1102  for (unsigned int l=0; l != Np; ++l)
1103  {
1104  this->matrix->vector_mult(*tempvec, this->get_sensitivity_solution(l));
1105  for (unsigned int i=0; i != Nq; ++i)
1106  if (qoi_indices.has_index(i))
1107  {
1108  this->get_adjoint_rhs(i).close();
1109  Number current_terms =
1110  (-this->get_adjoint_rhs(i).dot(this->get_sensitivity_solution(l)) +
1111  tempvec->dot(this->get_adjoint_solution(i))) / (2.*delta_p);
1112  sensitivities.second_derivative(i,k,l) += current_terms;
1113 
1114  // We use the _uk terms twice; symmetry lets us reuse
1115  // these calculations for the _ul terms.
1116 
1117  sensitivities.second_derivative(i,l,k) += current_terms;
1118  }
1119  }
1120 
1121  // Don't leave the parameter perturbed
1122  *parameters_vec[k] = old_parameterk;
1123 
1124  // Our last remaining terms are -R_uu(u,z)*u_k*u_l and
1125  // Q_uu(u)*u_k*u_l
1126  //
1127  // We take directional central finite differences of R_u and Q_u
1128  // to approximate these terms, e.g.:
1129  //
1130  // Q_uu(u)*u_k ~= (Q_u(u+dp*u_k) - Q_u(u-dp*u_k))/(2*dp)
1131 
1132  *this->solution = this->get_sensitivity_solution(k);
1133  *this->solution *= delta_p;
1134  *this->solution += *oldsolution;
1135 
1136  // We've modified solution, so we need to update before calling
1137  // assembly since assembly may only use current_local_solution
1138  this->update();
1139  this->assembly(false, true);
1140  this->matrix->close();
1141  this->assemble_qoi_derivative(qoi_indices,
1142  /* include_liftfunc = */ true,
1143  /* apply_constraints = */ false);
1144 
1145  // The Hessian is symmetric, so we just calculate the lower
1146  // triangle and the diagonal, and we get the upper triangle from
1147  // the transpose of the lower
1148  //
1149  // Note that, because we took the directional finite difference
1150  // with respect to k and not l, we've added an O(delta_p^2)
1151  // error to any permutational symmetry in the Hessian...
1152  for (unsigned int l=0; l != k+1; ++l)
1153  {
1154  this->matrix->vector_mult(*tempvec, this->get_sensitivity_solution(l));
1155  for (unsigned int i=0; i != Nq; ++i)
1156  if (qoi_indices.has_index(i))
1157  {
1158  this->get_adjoint_rhs(i).close();
1159  Number current_terms =
1160  (this->get_adjoint_rhs(i).dot(this->get_sensitivity_solution(l)) -
1161  tempvec->dot(this->get_adjoint_solution(i))) / (2.*delta_p);
1162  sensitivities.second_derivative(i,k,l) += current_terms;
1163  if (k != l)
1164  sensitivities.second_derivative(i,l,k) += current_terms;
1165  }
1166  }
1167 
1168  *this->solution = this->get_sensitivity_solution(k);
1169  *this->solution *= -delta_p;
1170  *this->solution += *oldsolution;
1171 
1172  // We've modified solution, so we need to update before calling
1173  // assembly since assembly may only use current_local_solution
1174  this->update();
1175  this->assembly(false, true);
1176  this->matrix->close();
1177  this->assemble_qoi_derivative(qoi_indices,
1178  /* include_liftfunc = */ true,
1179  /* apply_constraints = */ false);
1180 
1181  for (unsigned int l=0; l != k+1; ++l)
1182  {
1183  this->matrix->vector_mult(*tempvec, this->get_sensitivity_solution(l));
1184  for (unsigned int i=0; i != Nq; ++i)
1185  if (qoi_indices.has_index(i))
1186  {
1187  this->get_adjoint_rhs(i).close();
1188  Number current_terms =
1189  (-this->get_adjoint_rhs(i).dot(this->get_sensitivity_solution(l)) +
1190  tempvec->dot(this->get_adjoint_solution(i))) / (2.*delta_p);
1191  sensitivities.second_derivative(i,k,l) += current_terms;
1192  if (k != l)
1193  sensitivities.second_derivative(i,l,k) += current_terms;
1194  }
1195  }
1196 
1197  // Don't leave the solution perturbed
1198  *this->solution = *oldsolution;
1199  }
1200 
1201  // All parameters_vec have been reset.
1202  // Don't leave the qoi or system changed - principle of least
1203  // surprise.
1204  // We've modified solution, so we need to update before calling
1205  // assembly since assembly may only use current_local_solution
1206  this->update();
1207  this->assembly(true, true);
1208  this->rhs->close();
1209  this->matrix->close();
1210  this->assemble_qoi(qoi_indices);
1211 }
static constexpr Real TOLERANCE
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest...
Number get_qoi_value(unsigned int qoi_index) const
Definition: system.C:2179
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition: system.C:1179
NumericVector< Number > * rhs
The system matrix.
virtual std::pair< unsigned int, Real > sensitivity_solve(const ParameterVector &parameters) override
Assembles & solves the linear system(s) (dR/du)*u_p = -dR/dp, for those parameters contained within p...
virtual T dot(const NumericVector< T > &v) const =0
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) override
Assembles & solves the linear system (dR/du)^T*z = dq/du, for those quantities of interest q specifie...
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Definition: system.h:411
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:498
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SparseMatrix< Number > * matrix
The system matrix.
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) override
Prepares qoi for quantity of interest assembly, then calls user qoi function.
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
Prepares adjoint_rhs for quantity of interest derivative assembly, then calls user qoi derivative fun...
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
Definition: system.C:1232
std::vector< Number > get_qoi_values() const
Returns a copy of qoi, not a reference.
Definition: system.C:2186
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1294

◆ qoi_parameter_hessian_vector_product()

void libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product ( const QoISet qoi_indices,
const ParameterVector parameters,
const ParameterVector vector,
SensitivityData product 
)
overridevirtualinherited

For each of the system's quantities of interest q in qoi[qoi_indices], and for a vector of parameters p, the parameter sensitivity Hessian H_ij is defined as H_ij = (d^2 q)/(d p_i d p_j) The Hessian-vector product, for a vector v_k in parameter space, is S_j = H_jk v_k This product is the output of this method, where for each q_i, S_j is stored in sensitivities[i][j].

Reimplemented from libMesh::System.

Definition at line 717 of file implicit_system.C.

References libMesh::ImplicitSystem::adjoint_solve(), 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::ParameterVector::deep_copy(), libMesh::NumericVector< T >::dot(), libMesh::System::get_adjoint_rhs(), libMesh::System::get_adjoint_solution(), libMesh::System::get_qoi_value(), libMesh::System::get_qoi_values(), libMesh::System::get_weighted_sensitivity_adjoint_solution(), libMesh::System::get_weighted_sensitivity_solution(), libMesh::QoISet::has_index(), libMesh::System::is_adjoint_already_solved(), libMesh::ImplicitSystem::matrix, libMesh::System::n_qois(), libMesh::Real, libMesh::ExplicitSystem::rhs, libMesh::ParameterVector::size(), libMesh::System::solution, libMesh::TOLERANCE, libMesh::ParameterVector::value_copy(), libMesh::SparseMatrix< T >::vector_mult(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

721 {
722  // We currently get partial derivatives via finite differencing
723  const Real delta_p = TOLERANCE;
724 
725  ParameterVector & parameters_vec =
726  const_cast<ParameterVector &>(parameters_in);
727 
728  // We'll use a single temporary vector for matrix-vector-vector products
729  std::unique_ptr<NumericVector<Number>> tempvec = this->solution->zero_clone();
730 
731  const unsigned int Np = cast_int<unsigned int>
732  (parameters_vec.size());
733  const unsigned int Nq = this->n_qois();
734 
735  // For each quantity of interest q, the parameter sensitivity
736  // Hessian is defined as q''_{kl} = {d^2 q}/{d p_k d p_l}.
737  // Given a vector of parameter perturbation weights w_l, this
738  // function evaluates the hessian-vector product sum_l(q''_{kl}*w_l)
739  //
740  // We calculate it from values and partial derivatives of the
741  // quantity of interest function Q, solution u, adjoint solution z,
742  // parameter sensitivity adjoint solutions z^l, and residual R, as:
743  //
744  // sum_l(q''_{kl}*w_l) =
745  // sum_l(w_l * Q''_{kl}) + Q''_{uk}(u)*(sum_l(w_l u'_l)) -
746  // R'_k(u, sum_l(w_l*z^l)) - R'_{uk}(u,z)*(sum_l(w_l u'_l) -
747  // sum_l(w_l*R''_{kl}(u,z))
748  //
749  // See the adjoints model document for more details.
750 
751  // We first do an adjoint solve to get z for each quantity of
752  // interest
753  // if we haven't already or dont have an initial condition for the adjoint
754  if (!this->is_adjoint_already_solved())
755  {
756  this->adjoint_solve(qoi_indices);
757  }
758 
759  // Get ready to fill in sensitivities:
760  sensitivities.allocate_data(qoi_indices, *this, parameters_vec);
761 
762  // We can't solve for all the solution sensitivities u'_l or for all
763  // of the parameter sensitivity adjoint solutions z^l without
764  // requiring O(Nq*Np) linear solves. So we'll solve directly for their
765  // weighted sum - this is just O(Nq) solves.
766 
767  // First solve for sum_l(w_l u'_l).
768  this->weighted_sensitivity_solve(parameters_vec, vector);
769 
770  // Then solve for sum_l(w_l z^l).
771  this->weighted_sensitivity_adjoint_solve(parameters_vec, vector, qoi_indices);
772 
773  for (unsigned int k=0; k != Np; ++k)
774  {
775  // We approximate sum_l(w_l * Q''_{kl}) with a central
776  // differencing perturbation:
777  // sum_l(w_l * Q''_{kl}) ~=
778  // (Q(p + dp*w_l*e_l + dp*e_k) - Q(p - dp*w_l*e_l + dp*e_k) -
779  // Q(p + dp*w_l*e_l - dp*e_k) + Q(p - dp*w_l*e_l - dp*e_k))/(4*dp^2)
780 
781  // The sum(w_l*R''_kl) term requires the same sort of perturbation,
782  // and so we subtract it in at the same time:
783  // sum_l(w_l * R''_{kl}) ~=
784  // (R(p + dp*w_l*e_l + dp*e_k) - R(p - dp*w_l*e_l + dp*e_k) -
785  // R(p + dp*w_l*e_l - dp*e_k) + R(p - dp*w_l*e_l - dp*e_k))/(4*dp^2)
786 
787  ParameterVector oldparameters, parameterperturbation;
788  parameters_vec.deep_copy(oldparameters);
789  vector.deep_copy(parameterperturbation);
790  parameterperturbation *= delta_p;
791  parameters_vec += parameterperturbation;
792 
793  Number old_parameter = *parameters_vec[k];
794 
795  *parameters_vec[k] = old_parameter + delta_p;
796  this->assemble_qoi(qoi_indices);
797  this->assembly(true, false, true);
798  this->rhs->close();
799  std::vector<Number> partial2q_term = this->get_qoi_values();
800  std::vector<Number> partial2R_term(this->n_qois());
801  for (unsigned int i=0; i != Nq; ++i)
802  if (qoi_indices.has_index(i))
803  partial2R_term[i] = this->rhs->dot(this->get_adjoint_solution(i));
804 
805  *parameters_vec[k] = old_parameter - delta_p;
806  this->assemble_qoi(qoi_indices);
807  this->assembly(true, false, true);
808  this->rhs->close();
809  for (unsigned int i=0; i != Nq; ++i)
810  if (qoi_indices.has_index(i))
811  {
812  partial2q_term[i] -= this->get_qoi_value(i);
813  partial2R_term[i] -= this->rhs->dot(this->get_adjoint_solution(i));
814  }
815 
816  oldparameters.value_copy(parameters_vec);
817  parameterperturbation *= -1.0;
818  parameters_vec += parameterperturbation;
819 
820  // Re-center old_parameter, which may be affected by vector
821  old_parameter = *parameters_vec[k];
822 
823  *parameters_vec[k] = old_parameter + delta_p;
824  this->assemble_qoi(qoi_indices);
825  this->assembly(true, false, true);
826  this->rhs->close();
827  for (unsigned int i=0; i != Nq; ++i)
828  if (qoi_indices.has_index(i))
829  {
830  partial2q_term[i] -= this->get_qoi_value(i);
831  partial2R_term[i] -= this->rhs->dot(this->get_adjoint_solution(i));
832  }
833 
834  *parameters_vec[k] = old_parameter - delta_p;
835  this->assemble_qoi(qoi_indices);
836  this->assembly(true, false, true);
837  this->rhs->close();
838  for (unsigned int i=0; i != Nq; ++i)
839  if (qoi_indices.has_index(i))
840  {
841  partial2q_term[i] += this->get_qoi_value(i);
842  partial2R_term[i] += this->rhs->dot(this->get_adjoint_solution(i));
843  }
844 
845  for (unsigned int i=0; i != Nq; ++i)
846  if (qoi_indices.has_index(i))
847  {
848  partial2q_term[i] /= (4. * delta_p * delta_p);
849  partial2R_term[i] /= (4. * delta_p * delta_p);
850  }
851 
852  for (unsigned int i=0; i != Nq; ++i)
853  if (qoi_indices.has_index(i))
854  sensitivities[i][k] = partial2q_term[i] - partial2R_term[i];
855 
856  // We get (partial q / partial u), R, and
857  // (partial R / partial u) from the user, but centrally
858  // difference to get q_uk, R_k, and R_uk terms:
859  // (partial R / partial k)
860  // R_k*sum(w_l*z^l) = (R(p+dp*e_k)*sum(w_l*z^l) - R(p-dp*e_k)*sum(w_l*z^l))/(2*dp)
861  // (partial^2 q / partial u partial k)
862  // q_uk = (q_u(p+dp*e_k) - q_u(p-dp*e_k))/(2*dp)
863  // (partial^2 R / partial u partial k)
864  // R_uk*z*sum(w_l*u'_l) = (R_u(p+dp*e_k)*z*sum(w_l*u'_l) - R_u(p-dp*e_k)*z*sum(w_l*u'_l))/(2*dp)
865 
866  // To avoid creating Nq temporary vectors for q_uk or R_uk, we add
867  // subterms to the sensitivities output one by one.
868  //
869  // FIXME: this is probably a bad order of operations for
870  // controlling floating point error.
871 
872  *parameters_vec[k] = old_parameter + delta_p;
873  this->assembly(true, true);
874  this->rhs->close();
875  this->matrix->close();
876  this->assemble_qoi_derivative(qoi_indices,
877  /* include_liftfunc = */ true,
878  /* apply_constraints = */ false);
879 
880  this->matrix->vector_mult(*tempvec, this->get_weighted_sensitivity_solution());
881 
882  for (unsigned int i=0; i != Nq; ++i)
883  if (qoi_indices.has_index(i))
884  {
885  this->get_adjoint_rhs(i).close();
886  sensitivities[i][k] += (this->get_adjoint_rhs(i).dot(this->get_weighted_sensitivity_solution()) -
888  this->get_adjoint_solution(i).dot(*tempvec)) / (2.*delta_p);
889  }
890 
891  *parameters_vec[k] = old_parameter - delta_p;
892  this->assembly(true, true);
893  this->rhs->close();
894  this->matrix->close();
895  this->assemble_qoi_derivative(qoi_indices,
896  /* include_liftfunc = */ true,
897  /* apply_constraints = */ false);
898 
899  this->matrix->vector_mult(*tempvec, this->get_weighted_sensitivity_solution());
900 
901  for (unsigned int i=0; i != Nq; ++i)
902  if (qoi_indices.has_index(i))
903  {
904  this->get_adjoint_rhs(i).close();
905  sensitivities[i][k] += (-this->get_adjoint_rhs(i).dot(this->get_weighted_sensitivity_solution()) +
907  this->get_adjoint_solution(i).dot(*tempvec)) / (2.*delta_p);
908  }
909  }
910 
911  // All parameters have been reset.
912  // Don't leave the qoi or system changed - principle of least
913  // surprise.
914  this->assembly(true, true);
915  this->rhs->close();
916  this->matrix->close();
917  this->assemble_qoi(qoi_indices);
918 }
static constexpr Real TOLERANCE
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest...
Number get_qoi_value(unsigned int qoi_index) const
Definition: system.C:2179
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
virtual std::pair< unsigned int, Real > weighted_sensitivity_solve(const ParameterVector &parameters, const ParameterVector &weights) override
Assembles & solves the linear system(s) (dR/du)*u_w = sum(w_p*-dR/dp), for those parameters p contain...
NumericVector< Number > * rhs
The system matrix.
virtual T dot(const NumericVector< T > &v) const =0
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) override
Assembles & solves the linear system (dR/du)^T*z = dq/du, for those quantities of interest q specifie...
NumericVector< Number > & get_weighted_sensitivity_solution()
Definition: system.C:1206
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Definition: system.h:411
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SparseMatrix< Number > * matrix
The system matrix.
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) override
Prepares qoi for quantity of interest assembly, then calls user qoi function.
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
Prepares adjoint_rhs for quantity of interest derivative assembly, then calls user qoi derivative fun...
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
Definition: system.C:1232
virtual std::pair< unsigned int, Real > weighted_sensitivity_adjoint_solve(const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet()) override
Assembles & solves the linear system(s) (dR/du)^T*z_w = sum(w_p*(d^2q/dudp - d^2R/dudp*z)), for those parameters p contained within parameters, weighted by the values w_p found within weights.
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1264
std::vector< Number > get_qoi_values() const
Returns a copy of qoi, not a reference.
Definition: system.C:2186
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1294

◆ qoi_parameter_sensitivity()

void libMesh::System::qoi_parameter_sensitivity ( const QoISet qoi_indices,
const ParameterVector parameters,
SensitivityData sensitivities 
)
virtualinherited

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

Note
parameters is a const vector, not a vector-of-const; parameter values in this vector need to be mutable for finite differencing to work.

Automatically chooses the forward method for problems with more quantities of interest than parameters, or the adjoint method otherwise.

This method is only usable in derived classes which override an implementation.

Definition at line 590 of file system.C.

References libMesh::System::adjoint_qoi_parameter_sensitivity(), libMesh::System::forward_qoi_parameter_sensitivity(), libMesh::ParameterVector::size(), and libMesh::QoISet::size().

593 {
594  // Forward sensitivities are more efficient for Nq > Np
595  if (qoi_indices.size(*this) > parameters_vec.size())
596  forward_qoi_parameter_sensitivity(qoi_indices, parameters_vec, sensitivities);
597  // Adjoint sensitivities are more efficient for Np > Nq,
598  // and an adjoint may be more reusable than a forward
599  // solution sensitivity in the Np == Nq case.
600  else
601  adjoint_qoi_parameter_sensitivity(qoi_indices, parameters_vec, sensitivities);
602 }
virtual void forward_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Solves for parameter sensitivities using the forward method.
Definition: system.h:2611
virtual void adjoint_qoi_parameter_sensitivity(const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
Solves for parameter sensitivities using the adjoint method.
Definition: system.h:2602

◆ re_update()

void libMesh::System::re_update ( )
virtualinherited

Re-update the local values when the mesh has changed.

This method takes the data updated by update() and makes it up-to-date on the current mesh.

Reimplemented in libMesh::TransientSystem< RBConstruction >.

Definition at line 521 of file system.C.

References libMesh::System::current_local_solution, libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), libMesh::System::n_vars(), and libMesh::System::solution.

522 {
523  parallel_object_only();
524 
525  // If this system is empty... don't do anything!
526  if (!this->n_vars())
527  return;
528 
529  const std::vector<dof_id_type> & send_list = this->get_dof_map().get_send_list ();
530 
531  // Check sizes
532  libmesh_assert_equal_to (current_local_solution->size(), solution->size());
533  // Not true with ghosted vectors
534  // libmesh_assert_equal_to (current_local_solution->local_size(), solution->size());
535  // libmesh_assert (!send_list.empty());
536  libmesh_assert_less_equal (send_list.size(), solution->size());
537 
538  // Create current_local_solution from solution. This will
539  // put a local copy of solution into current_local_solution.
540  solution->localize (*current_local_solution, send_list);
541 }
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
unsigned int n_vars() const
Definition: system.C:2669
const DofMap & get_dof_map() const
Definition: system.h:2417
const std::vector< dof_id_type > & get_send_list() const
Definition: dof_map.h:533

◆ read_header()

void libMesh::System::read_header ( Xdr io,
std::string_view  version,
const bool  read_header = true,
const bool  read_additional_data = true,
const bool  read_legacy_format = false 
)
inherited

Reads the basic data header for this System.

Definition at line 97 of file system_io.C.

References libMesh::System::_additional_data_written, libMesh::System::_written_var_indices, libMesh::System::add_variable(), libMesh::System::add_vector(), TIMPI::Communicator::broadcast(), libMesh::System::clear(), libMesh::ParallelObject::comm(), libMesh::Utility::contains(), libMesh::Xdr::data(), libMesh::FEType::family, libMesh::System::get_mesh(), libMesh::OrderWrapper::get_order(), libMesh::FEType::inf_map, libMesh::libmesh_assert(), libMesh::MeshBase::mesh_dimension(), libMesh::MONOMIAL, libMesh::on_command_line(), libMesh::FEType::order, libMesh::out, libMesh::ParallelObject::processor_id(), libMesh::FEType::radial_family, libMesh::FEType::radial_order, libMesh::Xdr::reading(), libMesh::System::variable_number(), libMesh::Xdr::version(), and libMesh::XYZ.

Referenced by libMesh::EquationSystems::read(), and libMesh::RBEvaluation::read_in_vectors_from_multiple_files().

102 {
103  // This method implements the input of a
104  // System object, embedded in the output of
105  // an EquationSystems<T_sys>. This warrants some
106  // documentation. The output file essentially
107  // consists of 5 sections:
108  //
109  // for this system
110  //
111  // 5.) The number of variables in the system (unsigned int)
112  //
113  // for each variable in the system
114  //
115  // 6.) The name of the variable (string)
116  //
117  // 6.1.) Variable subdomains
118  //
119  // 7.) Combined in an FEType:
120  // - The approximation order(s) of the variable
121  // (Order Enum, cast to int/s)
122  // - The finite element family/ies of the variable
123  // (FEFamily Enum, cast to int/s)
124  //
125  // end variable loop
126  //
127  // 8.) The number of additional vectors (unsigned int),
128  //
129  // for each additional vector in the system object
130  //
131  // 9.) the name of the additional vector (string)
132  //
133  // end system
134  libmesh_assert (io.reading());
135 
136  // Possibly clear data structures and start from scratch.
137  if (read_header_in)
138  this->clear ();
139 
140  // Figure out if we need to read infinite element information.
141  // This will be true if the version string contains " with infinite elements"
142  const bool read_ifem_info =
143  Utility::contains(version, " with infinite elements") ||
144  libMesh::on_command_line ("--read-ifem-systems");
145 
146 
147  {
148  // 5.)
149  // Read the number of variables in the system
150  unsigned int nv=0;
151  if (this->processor_id() == 0)
152  io.data (nv);
153  this->comm().broadcast(nv);
154 
155  _written_var_indices.clear();
156  _written_var_indices.resize(nv, 0);
157 
158  for (unsigned int var=0; var<nv; var++)
159  {
160  // 6.)
161  // Read the name of the var-th variable
162  std::string var_name;
163  if (this->processor_id() == 0)
164  io.data (var_name);
165  this->comm().broadcast(var_name);
166 
167  // 6.1.)
168  std::set<subdomain_id_type> domains;
169  if (io.version() >= LIBMESH_VERSION_ID(0,7,2))
170  {
171  std::vector<subdomain_id_type> domain_array;
172  if (this->processor_id() == 0)
173  io.data (domain_array);
174  for (const auto & id : domain_array)
175  domains.insert(id);
176  }
177  this->comm().broadcast(domains);
178 
179  // 7.)
180  // Read the approximation order(s) of the var-th variable
181  int order=0;
182  if (this->processor_id() == 0)
183  io.data (order);
184  this->comm().broadcast(order);
185 
186 
187  // do the same for infinite element radial_order
188  int rad_order=0;
189  if (read_ifem_info)
190  {
191  if (this->processor_id() == 0)
192  io.data(rad_order);
193  this->comm().broadcast(rad_order);
194  }
195 
196  // Read the finite element type of the var-th variable
197  int fam=0;
198  if (this->processor_id() == 0)
199  io.data (fam);
200  this->comm().broadcast(fam);
201  FEType type;
202  type.order = static_cast<Order>(order);
203  type.family = static_cast<FEFamily>(fam);
204 
205  // Check for incompatibilities. The shape function indexing was
206  // changed for the monomial and xyz finite element families to
207  // simplify extension to arbitrary p. The consequence is that
208  // old restart files will not be read correctly. This is expected
209  // to be an unlikely occurrence, but catch it anyway.
210  if (read_legacy_format)
211  if ((type.family == MONOMIAL || type.family == XYZ) &&
212  ((type.order.get_order() > 2 && this->get_mesh().mesh_dimension() == 2) ||
213  (type.order.get_order() > 1 && this->get_mesh().mesh_dimension() == 3)))
214  {
215  libmesh_here();
216  libMesh::out << "*****************************************************************\n"
217  << "* WARNING: reading a potentially incompatible restart file!!! *\n"
218  << "* contact [email protected] for more details *\n"
219  << "*****************************************************************"
220  << std::endl;
221  }
222 
223  // Read additional information for infinite elements
224  int radial_fam=0;
225  int i_map=0;
226  if (read_ifem_info)
227  {
228  if (this->processor_id() == 0)
229  io.data (radial_fam);
230  this->comm().broadcast(radial_fam);
231  if (this->processor_id() == 0)
232  io.data (i_map);
233  this->comm().broadcast(i_map);
234  }
235 
236 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
237 
238  type.radial_order = static_cast<Order>(rad_order);
239  type.radial_family = static_cast<FEFamily>(radial_fam);
240  type.inf_map = static_cast<InfMapType>(i_map);
241 
242 #endif
243 
244  if (read_header_in)
245  {
246  if (domains.empty())
247  _written_var_indices[var] = this->add_variable (var_name, type);
248  else
249  _written_var_indices[var] = this->add_variable (var_name, type, &domains);
250  }
251  else
252  _written_var_indices[var] = this->variable_number(var_name);
253  }
254  }
255 
256  // 8.)
257  // Read the number of additional vectors.
258  unsigned int nvecs=0;
259  if (this->processor_id() == 0)
260  io.data (nvecs);
261  this->comm().broadcast(nvecs);
262 
263  // If nvecs > 0, this means that write_additional_data
264  // was true when this file was written. We will need to
265  // make use of this fact later.
266  this->_additional_data_written = nvecs;
267 
268  for (unsigned int vec=0; vec<nvecs; vec++)
269  {
270  // 9.)
271  // Read the name of the vec-th additional vector
272  std::string vec_name;
273  if (this->processor_id() == 0)
274  io.data (vec_name);
275  this->comm().broadcast(vec_name);
276  if (io.version() >= LIBMESH_VERSION_ID(1,7,0))
277  {
278  int vec_projection = 0;
279  if (this->processor_id() == 0)
280  io.data (vec_projection);
281  this->comm().broadcast(vec_projection);
282  int vec_type;
283  if (this->processor_id() == 0)
284  io.data (vec_type);
285  this->comm().broadcast(vec_type);
286 
287  if (read_additional_data)
288  this->add_vector(vec_name, bool(vec_projection), ParallelType(vec_type));
289  }
290  else if (read_additional_data)
291  // Systems now can handle adding post-initialization vectors
292  // libmesh_assert(this->_can_add_vectors);
293  // Some systems may have added their own vectors already
294  // libmesh_assert_equal_to (this->_vectors.count(vec_name), 0);
295  this->add_vector(vec_name);
296  }
297 }
virtual void clear()
Clear all the data structures associated with the system.
Definition: system.C:173
Order
defines an enum for polynomial orders.
Definition: enum_order.h:40
const Parallel::Communicator & comm() const
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:756
const MeshBase & get_mesh() const
Definition: system.h:2401
unsigned int variable_number(std::string_view var) const
Definition: system.C:1398
libmesh_assert(ctx)
unsigned int _additional_data_written
This flag is used only when reading in a system from file.
Definition: system.h:2313
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1344
bool contains(std::string_view superstring, std::string_view substring)
Look for a substring within a string.
Definition: utility.C:205
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
InfMapType
defines an enum for the types of coordinate mappings available in infinite elements.
OStreamProxy out
unsigned int mesh_dimension() const
Definition: mesh_base.C:422
bool on_command_line(std::string arg)
Definition: libmesh.C:921
FEFamily
defines an enum for finite element families.
processor_id_type processor_id() const
std::vector< unsigned int > _written_var_indices
This vector is used only when reading in a system from file.
Definition: system.h:2325
ParallelType
Defines an enum for parallel data structure types.

◆ read_parallel_data() [1/2]

template<typename InValType >
void libMesh::System::read_parallel_data ( Xdr io,
const bool  read_additional_data 
)
inherited

Reads additional data, namely vectors, for this System.

This method may safely be called on a distributed-memory mesh. This method will read an individual file for each processor in the simulation where the local solution components for that processor are stored.

This method implements the output of the vectors contained in this System object, embedded in the output of an EquationSystems<T_sys>.

9.) The global solution vector, re-ordered to be node-major (More on this later.)

for each additional vector in the object

10.) The global additional vector, re-ordered to be node-major (More on this later.)

Note that the actual IO is handled through the Xdr class (to be renamed later?) which provides a uniform interface to both the XDR (eXternal Data Representation) interface and standard ASCII output. Thus this one section of code will read XDR or ASCII files with no changes.

Definition at line 302 of file system_io.C.

References libMesh::System::_additional_data_written, libMesh::System::_vectors, libMesh::System::_written_var_indices, libMesh::Xdr::data(), libMesh::FEType::family, libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::DofObject::invalid_id, libMesh::Xdr::is_open(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::ParallelObject::n_processors(), libMesh::System::n_vars(), libMesh::System::number(), libMesh::ParallelObject::processor_id(), libMesh::Xdr::reading(), libMesh::SCALAR, libMesh::DofMap::SCALAR_dof_indices(), libMesh::System::solution, libMesh::Variable::type(), and libMesh::System::variable().

304 {
324  // PerfLog pl("IO Performance",false);
325  // pl.push("read_parallel_data");
326  [[maybe_unused]] dof_id_type total_read_size = 0;
327 
328  libmesh_assert (io.reading());
329  libmesh_assert (io.is_open());
330 
331  // build the ordered nodes and element maps.
332  // when writing/reading parallel files we need to iterate
333  // over our nodes/elements in order of increasing global id().
334  // however, this is not guaranteed to be ordering we obtain
335  // by using the node_iterators/element_iterators directly.
336  // so build a set, sorted by id(), that provides the ordering.
337  // further, for memory economy build the set but then transfer
338  // its contents to vectors, which will be sorted.
339  std::vector<const DofObject *> ordered_nodes, ordered_elements;
340  {
341  std::set<const DofObject *, CompareDofObjectsByID>
342  ordered_nodes_set (this->get_mesh().local_nodes_begin(),
343  this->get_mesh().local_nodes_end());
344 
345  ordered_nodes.insert(ordered_nodes.end(),
346  ordered_nodes_set.begin(),
347  ordered_nodes_set.end());
348  }
349  {
350  std::set<const DofObject *, CompareDofObjectsByID>
351  ordered_elements_set (this->get_mesh().local_elements_begin(),
352  this->get_mesh().local_elements_end());
353 
354  ordered_elements.insert(ordered_elements.end(),
355  ordered_elements_set.begin(),
356  ordered_elements_set.end());
357  }
358 
359  // std::vector<Number> io_buffer;
360  std::vector<InValType> io_buffer;
361 
362  // 9.)
363  //
364  // Actually read the solution components
365  // for the ith system to disk
366  io.data(io_buffer);
367 
368  total_read_size += cast_int<dof_id_type>(io_buffer.size());
369 
370  const unsigned int sys_num = this->number();
371  const unsigned int nv = cast_int<unsigned int>
372  (this->_written_var_indices.size());
373  libmesh_assert_less_equal (nv, this->n_vars());
374 
375  dof_id_type cnt=0;
376 
377  // Loop over each non-SCALAR variable and each node, and read out the value.
378  for (unsigned int data_var=0; data_var<nv; data_var++)
379  {
380  const unsigned int var = _written_var_indices[data_var];
381  if (this->variable(var).type().family != SCALAR)
382  {
383  // First read the node DOF values
384  for (const auto & node : ordered_nodes)
385  for (auto comp : make_range(node->n_comp(sys_num,var)))
386  {
387  libmesh_assert_not_equal_to (node->dof_number(sys_num, var, comp),
389  libmesh_assert_less (cnt, io_buffer.size());
390  this->solution->set(node->dof_number(sys_num, var, comp), io_buffer[cnt++]);
391  }
392 
393  // Then read the element DOF values
394  for (const auto & elem : ordered_elements)
395  for (auto comp : make_range(elem->n_comp(sys_num,var)))
396  {
397  libmesh_assert_not_equal_to (elem->dof_number(sys_num, var, comp),
399  libmesh_assert_less (cnt, io_buffer.size());
400  this->solution->set(elem->dof_number(sys_num, var, comp), io_buffer[cnt++]);
401  }
402  }
403  }
404 
405  // Finally, read the SCALAR variables on the last processor
406  for (unsigned int data_var=0; data_var<nv; data_var++)
407  {
408  const unsigned int var = _written_var_indices[data_var];
409  if (this->variable(var).type().family == SCALAR)
410  {
411  if (this->processor_id() == (this->n_processors()-1))
412  {
413  const DofMap & dof_map = this->get_dof_map();
414  std::vector<dof_id_type> SCALAR_dofs;
415  dof_map.SCALAR_dof_indices(SCALAR_dofs, var);
416 
417  for (auto dof : SCALAR_dofs)
418  this->solution->set(dof, io_buffer[cnt++]);
419  }
420  }
421  }
422 
423  // And we're done setting solution entries
424  this->solution->close();
425 
426  // For each additional vector, simply go through the list.
427  // ONLY attempt to do this IF additional data was actually
428  // written to the file for this system (controlled by the
429  // _additional_data_written flag).
430  if (this->_additional_data_written)
431  {
432  const std::size_t nvecs = this->_vectors.size();
433 
434  // If the number of additional vectors written is non-zero, and
435  // the number of additional vectors we have is non-zero, and
436  // they don't match, then something is wrong and we can't be
437  // sure we're reading data into the correct places.
438  if (read_additional_data && nvecs &&
439  nvecs != this->_additional_data_written)
440  libmesh_error_msg
441  ("Additional vectors in file do not match system");
442 
443  auto pos = _vectors.begin();
444 
445  for (std::size_t i = 0; i != this->_additional_data_written; ++i)
446  {
447  cnt=0;
448  io_buffer.clear();
449 
450  // 10.)
451  //
452  // Actually read the additional vector components
453  // for the ith system from disk
454  io.data(io_buffer);
455 
456  total_read_size += cast_int<dof_id_type>(io_buffer.size());
457 
458  // If read_additional_data==true and we have additional vectors,
459  // then we will keep this vector data; otherwise we are going to
460  // throw it away.
461  if (read_additional_data && nvecs)
462  {
463  // Loop over each non-SCALAR variable and each node, and read out the value.
464  for (unsigned int data_var=0; data_var<nv; data_var++)
465  {
466  const unsigned int var = _written_var_indices[data_var];
467  if (this->variable(var).type().family != SCALAR)
468  {
469  // First read the node DOF values
470  for (const auto & node : ordered_nodes)
471  for (auto comp : make_range(node->n_comp(sys_num,var)))
472  {
473  libmesh_assert_not_equal_to (node->dof_number(sys_num, var, comp),
475  libmesh_assert_less (cnt, io_buffer.size());
476  pos->second->set(node->dof_number(sys_num, var, comp), io_buffer[cnt++]);
477  }
478 
479  // Then read the element DOF values
480  for (const auto & elem : ordered_elements)
481  for (auto comp : make_range(elem->n_comp(sys_num,var)))
482  {
483  libmesh_assert_not_equal_to (elem->dof_number(sys_num, var, comp),
485  libmesh_assert_less (cnt, io_buffer.size());
486  pos->second->set(elem->dof_number(sys_num, var, comp), io_buffer[cnt++]);
487  }
488  }
489  }
490 
491  // Finally, read the SCALAR variables on the last processor
492  for (unsigned int data_var=0; data_var<nv; data_var++)
493  {
494  const unsigned int var = _written_var_indices[data_var];
495  if (this->variable(var).type().family == SCALAR)
496  {
497  if (this->processor_id() == (this->n_processors()-1))
498  {
499  const DofMap & dof_map = this->get_dof_map();
500  std::vector<dof_id_type> SCALAR_dofs;
501  dof_map.SCALAR_dof_indices(SCALAR_dofs, var);
502 
503  for (auto dof : SCALAR_dofs)
504  pos->second->set(dof, io_buffer[cnt++]);
505  }
506  }
507  }
508 
509  // And we're done setting entries for this variable
510  pos->second->close();
511  }
512 
513  // If we've got vectors then we need to be iterating through
514  // those too
515  if (pos != this->_vectors.end())
516  ++pos;
517  }
518  }
519 
520  // const Real
521  // dt = pl.get_elapsed_time(),
522  // rate = total_read_size*sizeof(Number)/dt;
523 
524  // libMesh::err << "Read " << total_read_size << " \"Number\" values\n"
525  // << " Elapsed time = " << dt << '\n'
526  // << " Rate = " << rate/1.e6 << "(MB/sec)\n\n";
527 
528  // pl.pop("read_parallel_data");
529 }
FEFamily family
The type of finite element.
Definition: fe_type.h:228
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
const MeshBase & get_mesh() const
Definition: system.h:2401
processor_id_type n_processors() const
unsigned int number() const
Definition: system.h:2393
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:473
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
libmesh_assert(ctx)
unsigned int _additional_data_written
This flag is used only when reading in a system from file.
Definition: system.h:2313
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
unsigned int n_vars() const
Definition: system.C:2669
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2417
std::vector< unsigned int > _written_var_indices
This vector is used only when reading in a system from file.
Definition: system.h:2325
uint8_t dof_id_type
Definition: id_types.h:67
const FEType & type() const
Definition: variable.h:144

◆ read_parallel_data() [2/2]

template LIBMESH_EXPORT void libMesh::System::read_parallel_data< Real > ( Xdr io,
const bool  read_additional_data 
)
inlineinherited

Non-templated version for backward compatibility.

Reads additional data, namely vectors, for this System. This method may safely be called on a distributed-memory mesh. This method will read an individual file for each processor in the simulation where the local solution components for that processor are stored.

Definition at line 1412 of file system.h.

1414  { read_parallel_data<Number>(io, read_additional_data); }

◆ read_serialized_data() [1/2]

template<typename InValType >
void libMesh::System::read_serialized_data ( Xdr io,
const bool  read_additional_data = true 
)
inherited

Reads additional data, namely vectors, for this System.

This method may safely be called on a distributed-memory mesh.

Definition at line 533 of file system_io.C.

References libMesh::System::_additional_data_written, libMesh::System::_vectors, libMesh::ParallelObject::processor_id(), and libMesh::System::solution.

Referenced by libMesh::TransientRBConstruction::initialize_truth(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), and libMesh::RBConstruction::read_riesz_representors_from_files().

535 {
536  // This method implements the input of the vectors
537  // contained in this System object, embedded in the
538  // output of an EquationSystems<T_sys>.
539  //
540  // 10.) The global solution vector, re-ordered to be node-major
541  // (More on this later.)
542  //
543  // for each additional vector in the object
544  //
545  // 11.) The global additional vector, re-ordered to be
546  // node-major (More on this later.)
547  parallel_object_only();
548  std::string comment;
549 
550  // PerfLog pl("IO Performance",false);
551  // pl.push("read_serialized_data");
552  // std::size_t total_read_size = 0;
553 
554  // 10.)
555  // Read the global solution vector
556  {
557  // total_read_size +=
558  this->read_serialized_vector<InValType>(io, this->solution.get());
559 
560  // get the comment
561  if (this->processor_id() == 0)
562  io.comment (comment);
563  }
564 
565  // 11.)
566  // Only read additional vectors if data is available, and only use
567  // that data to fill our vectors if the user requested it.
568  if (this->_additional_data_written)
569  {
570  const std::size_t nvecs = this->_vectors.size();
571 
572  // If the number of additional vectors written is non-zero, and
573  // the number of additional vectors we have is non-zero, and
574  // they don't match, then we can't read additional vectors
575  // and be sure we're reading data into the correct places.
576  if (read_additional_data && nvecs &&
577  nvecs != this->_additional_data_written)
578  libmesh_error_msg
579  ("Additional vectors in file do not match system");
580 
581  auto pos = _vectors.begin();
582 
583  for (std::size_t i = 0; i != this->_additional_data_written; ++i)
584  {
585  // Read data, but only put it into a vector if we've been
586  // asked to and if we have a corresponding vector to read.
587 
588  // total_read_size +=
589  this->read_serialized_vector<InValType>
590  (io, (read_additional_data && nvecs) ? pos->second.get() : nullptr);
591 
592  // get the comment
593  if (this->processor_id() == 0)
594  io.comment (comment);
595 
596 
597  // If we've got vectors then we need to be iterating through
598  // those too
599  if (pos != this->_vectors.end())
600  ++pos;
601  }
602  }
603 
604  // const Real
605  // dt = pl.get_elapsed_time(),
606  // rate = total_read_size*sizeof(Number)/dt;
607 
608  // libMesh::out << "Read " << total_read_size << " \"Number\" values\n"
609  // << " Elapsed time = " << dt << '\n'
610  // << " Rate = " << rate/1.e6 << "(MB/sec)\n\n";
611 
612  // pl.pop("read_serialized_data");
613 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
unsigned int _additional_data_written
This flag is used only when reading in a system from file.
Definition: system.h:2313
processor_id_type processor_id() const

◆ read_serialized_data() [2/2]

template LIBMESH_EXPORT void libMesh::System::read_serialized_data< Real > ( Xdr io,
const bool  read_additional_data = true 
)
inlineinherited

Non-templated version for backward compatibility.

Reads additional data, namely vectors, for this System. This method may safely be called on a distributed-memory mesh.

Definition at line 1370 of file system.h.

1372  { read_serialized_data<Number>(io, read_additional_data); }

◆ read_serialized_vectors() [1/2]

template<typename InValType >
std::size_t libMesh::System::read_serialized_vectors ( Xdr io,
const std::vector< NumericVector< Number > *> &  vectors 
) const
inherited

Read a number of identically distributed vectors.

This method allows for optimization for the multiple vector case by only communicating the metadata once.

Definition at line 2018 of file system_io.C.

References libMesh::Xdr::data(), libMesh::System::get_mesh(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::MeshTools::n_elem(), libMesh::MeshBase::n_elem(), n_nodes, libMesh::MeshBase::n_nodes(), libMesh::System::n_vars(), libMesh::ParallelObject::processor_id(), libMesh::System::read_SCALAR_dofs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::Xdr::reading(), libMesh::SCALAR, and libMesh::System::variable().

Referenced by libMesh::RBEvaluation::read_in_vectors_from_multiple_files().

2020 {
2021  parallel_object_only();
2022 
2023  // Error checking
2024  // #ifndef NDEBUG
2025  // // In parallel we better be reading a parallel vector -- if not
2026  // // we will not set all of its components below!!
2027  // if (this->n_processors() > 1)
2028  // {
2029  // libmesh_assert (vec.type() == PARALLEL ||
2030  // vec.type() == GHOSTED);
2031  // }
2032  // #endif
2033 
2034  libmesh_assert (io.reading());
2035 
2036  if (this->processor_id() == 0)
2037  {
2038  // sizes
2039  unsigned int num_vecs=0;
2040  dof_id_type vector_length=0;
2041 
2042  // Get the number of vectors
2043  io.data(num_vecs);
2044  // Get the buffer size
2045  io.data(vector_length);
2046 
2047  libmesh_error_msg_if
2048  (num_vecs != vectors.size(),
2049  "Xdr file header declares " << num_vecs << " vectors, but we were asked to read " << vectors.size());
2050 
2051  if (num_vecs != 0)
2052  {
2053  libmesh_error_msg_if (vectors[0] == nullptr, "vectors[0] should not be null");
2054  libmesh_error_msg_if (vectors[0]->size() != vector_length, "Inconsistent vector sizes");
2055  }
2056  }
2057 
2058  // no need to actually communicate these.
2059  // this->comm().broadcast(num_vecs);
2060  // this->comm().broadcast(vector_length);
2061 
2062  // Cache these - they are not free!
2063  const dof_id_type
2064  n_nodes = this->get_mesh().n_nodes(),
2065  n_elem = this->get_mesh().n_elem();
2066 
2067  std::size_t read_length = 0;
2068 
2069  //---------------------------------
2070  // Collect the values for all nodes
2071  read_length +=
2072  this->read_serialized_blocked_dof_objects (n_nodes,
2073  this->get_mesh().local_nodes_begin(),
2074  this->get_mesh().local_nodes_end(),
2075  InValType(),
2076  io,
2077  vectors);
2078 
2079  //------------------------------------
2080  // Collect the values for all elements
2081  read_length +=
2083  this->get_mesh().local_elements_begin(),
2084  this->get_mesh().local_elements_end(),
2085  InValType(),
2086  io,
2087  vectors);
2088 
2089  //-------------------------------------------
2090  // Finally loop over all the SCALAR variables
2091  for (NumericVector<Number> * vec : vectors)
2092  for (auto var : make_range(this->n_vars()))
2093  if (this->variable(var).type().family == SCALAR)
2094  {
2095  libmesh_assert_not_equal_to (vec, 0);
2096 
2097  read_length +=
2098  this->read_SCALAR_dofs (var, io, vec);
2099  }
2100 
2101  //---------------------------------------
2102  // last step - must close all the vectors
2103  for (NumericVector<Number> * vec : vectors)
2104  {
2105  libmesh_assert_not_equal_to (vec, 0);
2106  vec->close();
2107  }
2108 
2109  return read_length;
2110 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:976
std::size_t read_serialized_blocked_dof_objects(const dof_id_type n_objects, const iterator_type begin, const iterator_type end, const InValType dummy, Xdr &io, const std::vector< NumericVector< Number > *> &vecs, const unsigned int var_to_read=libMesh::invalid_uint) const
Reads an input vector from the stream io and assigns the values to a set of DofObjects.
Definition: system_io.C:618
const MeshBase & get_mesh() const
Definition: system.h:2401
const dof_id_type n_nodes
Definition: tecplot_io.C:67
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
unsigned int read_SCALAR_dofs(const unsigned int var, Xdr &io, NumericVector< Number > *vec) const
Reads the SCALAR dofs from the stream io and assigns the values to the appropriate entries of vec...
Definition: system_io.C:942
unsigned int n_vars() const
Definition: system.C:2669
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
template class LIBMESH_EXPORT NumericVector< Number >
virtual dof_id_type n_nodes() const =0
uint8_t dof_id_type
Definition: id_types.h:67

◆ read_serialized_vectors() [2/2]

template LIBMESH_EXPORT std::size_t libMesh::System::read_serialized_vectors< Real > ( Xdr io,
const std::vector< NumericVector< Number > *> &  vectors 
) const
inlineinherited

Non-templated version for backward compatibility.

Read a number of identically distributed vectors. This method allows for optimization for the multiple vector case by only communicating the metadata once.

Definition at line 1390 of file system.h.

1392  { return read_serialized_vectors<Number>(io, vectors); }

◆ reinit()

void libMesh::DifferentiableSystem::reinit ( )
overridevirtualinherited

Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be used.

Reimplemented from libMesh::System.

Definition at line 82 of file diff_system.C.

References libMesh::libmesh_assert(), libMesh::System::reinit(), and libMesh::DifferentiableSystem::time_solver.

83 {
85 
87  libmesh_assert_equal_to (&(time_solver->system()), this);
88 
89  time_solver->reinit();
90 }
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
Definition: system.C:442
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
libmesh_assert(ctx)

◆ reinit_constraints()

void libMesh::System::reinit_constraints ( )
virtualinherited

Reinitializes the constraints for this system.

Also prepares the send_list, whether or not constraints have changed.

Definition at line 483 of file system.C.

References libMesh::System::_mesh, libMesh::DofMap::create_dof_constraints(), libMesh::System::get_dof_map(), libMesh::on_command_line(), libMesh::out, libMesh::DofMap::prepare_send_list(), libMesh::DofMap::print_dof_constraints(), libMesh::DofMap::process_constraints(), libMesh::System::time, and libMesh::System::user_constrain().

Referenced by libMesh::EquationSystems::allgather(), libMesh::System::init_data(), libMesh::PetscDMWrapper::init_petscdm(), and libMesh::EquationSystems::reinit_solutions().

484 {
485  parallel_object_only();
486 
487 #ifdef LIBMESH_ENABLE_CONSTRAINTS
489  user_constrain();
491  if (libMesh::on_command_line ("--print-constraints"))
493 #endif
495 }
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
Definition: system.h:1677
void print_dof_constraints(std::ostream &os=libMesh::out, bool print_nonlocal=false) const
Prints (from processor 0) all DoF and Node constraints.
void process_constraints(MeshBase &)
Postprocesses any constrained degrees of freedom to be constrained only in terms of unconstrained dof...
OStreamProxy out
void create_dof_constraints(const MeshBase &, Real time=0)
Rebuilds the raw degree of freedom and DofObject constraints, based on attached DirichletBoundary obj...
void prepare_send_list()
Takes the _send_list vector (which may have duplicate entries) and sorts it.
Definition: dof_map.C:1826
bool on_command_line(std::string arg)
Definition: libmesh.C:921
virtual void user_constrain()
Calls user&#39;s attached constraint function, or is overridden by the user in derived classes...
Definition: system.C:2118
const DofMap & get_dof_map() const
Definition: system.h:2417
MeshBase & _mesh
Constant reference to the mesh data structure used for the simulation.
Definition: system.h:2237

◆ reinit_mesh()

void libMesh::System::reinit_mesh ( )
virtualinherited

Reinitializes the system with a new mesh.

Definition at line 289 of file system.C.

References libMesh::System::_basic_system_only, libMesh::System::init_data(), libMesh::System::n_vars(), and libMesh::System::user_initialization().

Referenced by libMesh::System::init(), libMesh::PetscPreconditioner< T >::set_hypre_ads_data(), and libMesh::PetscPreconditioner< T >::set_hypre_ams_data().

290 {
291  parallel_object_only();
292 
293  // First initialize any required data:
294  // either only the basic System data
295  if (_basic_system_only)
297  // or all the derived class' data too
298  else
299  this->init_data();
300 
301  // If no variables have been added to this system
302  // don't do anything
303  if (!this->n_vars())
304  return;
305 
306  // Then call the user-provided initialization function
307  this->user_initialization();
308 
309 }
bool _basic_system_only
Holds true if the components of more advanced system types (e.g.
Definition: system.h:2300
virtual void init_data()
Initializes the data for the system.
Definition: system.C:207
virtual void user_initialization()
Calls user&#39;s attached initialization function, or is overridden by the user in derived classes...
Definition: system.C:2090
unsigned int n_vars() const
Definition: system.C:2669

◆ remove_matrix()

void libMesh::System::remove_matrix ( std::string_view  mat_name)
inherited

Removes the additional matrix mat_name from this system.

Definition at line 1076 of file system.C.

References libMesh::System::_matrices.

1077 {
1078  parallel_object_only(); // Not strictly needed, but the only safe way to keep in sync
1079 
1080  if (const auto pos = _matrices.find(mat_name);
1081  pos != _matrices.end())
1082  _matrices.erase(pos); // erase()'d entries are destroyed
1083 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ remove_vector()

void libMesh::System::remove_vector ( std::string_view  vec_name)
inherited

Removes the additional vector vec_name from this system.

Definition at line 861 of file system.C.

References libMesh::System::_vector_is_adjoint, libMesh::System::_vector_projections, libMesh::System::_vectors, and libMesh::libmesh_assert().

Referenced by libMesh::AdjointRefinementEstimator::estimate_error(), and libMesh::UnsteadySolver::integrate_adjoint_sensitivity().

862 {
863  parallel_object_only(); // Not strictly needed, but the only safe way to keep in sync
864 
865  if (const auto pos = _vectors.find(vec_name);
866  pos != _vectors.end())
867  {
868  _vectors.erase(pos);
869  auto proj_it = _vector_projections.find(vec_name);
870  libmesh_assert(proj_it != _vector_projections.end());
871  _vector_projections.erase(proj_it);
872 
873  auto adj_it = _vector_is_adjoint.find(vec_name);
874  libmesh_assert(adj_it != _vector_is_adjoint.end());
875  _vector_is_adjoint.erase(adj_it);
876  }
877 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
std::map< std::string, int, std::less<> > _vector_is_adjoint
Holds non-negative if a vector by that name should be projected using adjoint constraints/BCs, -1 if primal.
Definition: system.h:2272
libmesh_assert(ctx)
std::map< std::string, bool, std::less<> > _vector_projections
Holds true if a vector by that name should be projected onto a changed grid, false if it should be ze...
Definition: system.h:2266

◆ request_matrix() [1/2]

const SparseMatrix< Number > * libMesh::System::request_matrix ( std::string_view  mat_name) const
inherited
Returns
A const pointer to this system's additional matrix named mat_name, or nullptr if no matrix by that name exists.

Definition at line 1087 of file system.C.

References libMesh::System::_matrices.

Referenced by libMesh::EigenSystem::has_matrix_A(), libMesh::EigenSystem::has_matrix_B(), libMesh::EigenSystem::has_precond_matrix(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::NewtonSolver::solve(), and libMesh::LinearImplicitSystem::solve().

1088 {
1089  if (const auto pos = _matrices.find(mat_name);
1090  pos != _matrices.end())
1091  return pos->second.get();
1092 
1093  // Otherwise, mat_name does not exist
1094  return nullptr;
1095 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ request_matrix() [2/2]

SparseMatrix< Number > * libMesh::System::request_matrix ( std::string_view  mat_name)
inherited
Returns
A writable pointer to this system's additional matrix named mat_name, or nullptr if no matrix by that name exists.

Definition at line 1099 of file system.C.

References libMesh::System::_matrices.

1100 {
1101  if (auto pos = _matrices.find(mat_name);
1102  pos != _matrices.end())
1103  return pos->second.get();
1104 
1105  // Otherwise, mat_name does not exist
1106  return nullptr;
1107 }
std::map< std::string, std::unique_ptr< SparseMatrix< Number > >, std::less<> > _matrices
Some systems need an arbitrary number of matrices.
Definition: system.h:2277

◆ request_vector() [1/4]

const NumericVector< Number > * libMesh::System::request_vector ( std::string_view  vec_name) const
inherited
Returns
A const pointer to the vector if this System has a vector associated with the given name, nullptr otherwise.

Definition at line 879 of file system.C.

References libMesh::System::_vectors, and libMesh::NumericVector< T >::get().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error().

880 {
881  if (const auto pos = _vectors.find(vec_name);
882  pos != _vectors.end())
883  return pos->second.get();
884 
885  // Otherwise, vec_name was not found
886  return nullptr;
887 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ request_vector() [2/4]

NumericVector< Number > * libMesh::System::request_vector ( std::string_view  vec_name)
inherited
Returns
A pointer to the vector if this System has a vector associated with the given name, nullptr otherwise.

Definition at line 891 of file system.C.

References libMesh::System::_vectors, and libMesh::NumericVector< T >::get().

892 {
893  if (auto pos = _vectors.find(vec_name);
894  pos != _vectors.end())
895  return pos->second.get();
896 
897  // Otherwise, vec_name was not found
898  return nullptr;
899 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ request_vector() [3/4]

const NumericVector< Number > * libMesh::System::request_vector ( const unsigned int  vec_num) const
inherited
Returns
A const pointer to this system's additional vector number vec_num (where the vectors are counted starting with 0), or nullptr if the system has no such vector.

Definition at line 903 of file system.C.

References libMesh::System::_vectors, and libMesh::System::vectors_begin().

904 {
905  // If we don't have that many vectors, return nullptr
906  if (vec_num >= _vectors.size())
907  return nullptr;
908 
909  // Otherwise return a pointer to the vec_num'th vector
910  auto it = vectors_begin();
911  std::advance(it, vec_num);
912  return it->second.get();
913 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2505

◆ request_vector() [4/4]

NumericVector< Number > * libMesh::System::request_vector ( const unsigned int  vec_num)
inherited
Returns
A writable pointer to this system's additional vector number vec_num (where the vectors are counted starting with 0), or nullptr if the system has no such vector.

Definition at line 917 of file system.C.

References libMesh::System::_vectors, and libMesh::System::vectors_begin().

918 {
919  // If we don't have that many vectors, return nullptr
920  if (vec_num >= _vectors.size())
921  return nullptr;
922 
923  // Otherwise return a pointer to the vec_num'th vector
924  auto it = vectors_begin();
925  std::advance(it, vec_num);
926  return it->second.get();
927 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2505

◆ restrict_solve_to()

void libMesh::System::restrict_solve_to ( const SystemSubset subset,
const SubsetSolveMode  subset_solve_mode = SUBSET_ZERO 
)
virtualinherited

After calling this method, any solve will be restricted to the given subdomain.

To disable this mode, call this method with subset being a nullptr.

Reimplemented in libMesh::LinearImplicitSystem.

Definition at line 545 of file system.C.

547 {
548  if (subset != nullptr)
549  libmesh_not_implemented();
550 }

◆ restrict_vectors()

void libMesh::System::restrict_vectors ( )
virtualinherited

Restrict vectors after the mesh has coarsened.

Definition at line 374 of file system.C.

References libMesh::System::_dof_map, libMesh::System::_solution_projection, libMesh::System::_vector_projections, libMesh::System::_vectors, libMesh::System::current_local_solution, libMesh::NumericVector< T >::get(), libMesh::GHOSTED, libMesh::System::n_dofs(), libMesh::System::n_local_dofs(), libMesh::PARALLEL, libMesh::System::project_vector(), libMesh::System::solution, and libMesh::System::vector_is_adjoint().

Referenced by libMesh::System::prolong_vectors(), and libMesh::EquationSystems::reinit_solutions().

375 {
376  parallel_object_only();
377 
378 #ifdef LIBMESH_ENABLE_AMR
379  // Restrict the _vectors on the coarsened cells
380  for (auto & [vec_name, vec] : _vectors)
381  {
382  NumericVector<Number> * v = vec.get();
383 
384  if (_vector_projections[vec_name])
385  {
386  this->project_vector (*v, this->vector_is_adjoint(vec_name));
387  }
388  else
389  {
390  const ParallelType type = vec->type();
391 
392  if (type == GHOSTED)
393  {
394 #ifdef LIBMESH_ENABLE_GHOSTED
395  vec->init (this->n_dofs(), this->n_local_dofs(),
396  _dof_map->get_send_list(), /*fast=*/false,
397  GHOSTED);
398 #else
399  libmesh_error_msg("Cannot initialize ghosted vectors when they are not enabled.");
400 #endif
401  }
402  else
403  vec->init (this->n_dofs(), this->n_local_dofs(), false, type);
404  }
405  }
406 
407  const std::vector<dof_id_type> & send_list = _dof_map->get_send_list ();
408 
409  // Restrict the solution on the coarsened cells
411  this->project_vector (*solution);
412  // Or at least make sure the solution vector is the correct size
413  else
414  solution->init (this->n_dofs(), this->n_local_dofs(), true, PARALLEL);
415 
416 #ifdef LIBMESH_ENABLE_GHOSTED
417  current_local_solution->init(this->n_dofs(),
418  this->n_local_dofs(), send_list,
419  false, GHOSTED);
420 #else
421  current_local_solution->init(this->n_dofs());
422 #endif
423 
425  solution->localize (*current_local_solution, send_list);
426 
427 #endif // LIBMESH_ENABLE_AMR
428 }
int vector_is_adjoint(std::string_view vec_name) const
Definition: system.C:1160
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
dof_id_type n_local_dofs() const
Definition: system.C:155
dof_id_type n_dofs() const
Definition: system.C:118
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
bool _solution_projection
Holds true if the solution vector should be projected onto a changed grid, false if it should be zero...
Definition: system.h:2294
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
template class LIBMESH_EXPORT NumericVector< Number >
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...
std::map< std::string, bool, std::less<> > _vector_projections
Holds true if a vector by that name should be projected onto a changed grid, false if it should be ze...
Definition: system.h:2266
ParallelType
Defines an enum for parallel data structure types.

◆ sensitivity_solve()

std::pair< unsigned int, Real > libMesh::ImplicitSystem::sensitivity_solve ( const ParameterVector parameters)
overridevirtualinherited

Assembles & solves the linear system(s) (dR/du)*u_p = -dR/dp, for those parameters contained within parameters.

Returns
A pair with the total number of linear iterations performed and the (sum of the) final residual norms

Reimplemented from libMesh::System.

Definition at line 140 of file implicit_system.C.

References libMesh::System::add_sensitivity_solution(), libMesh::System::assemble_before_solve, libMesh::ImplicitSystem::assemble_residual_derivatives(), libMesh::ImplicitSystem::assembly(), libMesh::SparseMatrix< T >::close(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_dof_map(), libMesh::ImplicitSystem::get_linear_solve_parameters(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::System::get_sensitivity_rhs(), libMesh::System::get_sensitivity_solution(), libMesh::make_range(), libMesh::ImplicitSystem::matrix, libMesh::System::request_matrix(), libMesh::ParameterVector::size(), and libMesh::LinearSolver< T >::solve().

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

141 {
142  // Log how long the linear solve takes.
143  LOG_SCOPE("sensitivity_solve()", "ImplicitSystem");
144 
145  // The forward system should now already be solved.
146  // Now assemble the corresponding sensitivity system.
147 
148  if (this->assemble_before_solve)
149  {
150  // Build the Jacobian
151  this->assembly(false, true);
152  this->matrix->close();
153 
154  // Reset and build the RHS from the residual derivatives
155  this->assemble_residual_derivatives(parameters_vec);
156  }
157 
158  // The sensitivity problem is linear
159  LinearSolver<Number> * solver = this->get_linear_solver();
160 
161  // Our iteration counts and residuals will be sums of the individual
162  // results
163  std::pair<unsigned int, Real> solver_params =
165  std::pair<unsigned int, Real> totalrval = std::make_pair(0,0.0);
166 
167  // Solve the linear system.
168  SparseMatrix<Number> * pc = this->request_matrix("Preconditioner");
169  for (auto p : make_range(parameters_vec.size()))
170  {
171  std::pair<unsigned int, Real> rval =
172  solver->solve (*matrix, pc,
173  this->add_sensitivity_solution(p),
174  this->get_sensitivity_rhs(p),
175  double(solver_params.second),
176  solver_params.first);
177 
178  totalrval.first += rval.first;
179  totalrval.second += rval.second;
180  }
181 
182  // The linear solver may not have fit our constraints exactly
183 #ifdef LIBMESH_ENABLE_CONSTRAINTS
184  for (auto p : make_range(parameters_vec.size()))
186  (*this, &this->get_sensitivity_solution(p),
187  /* homogeneous = */ true);
188 #endif
189 
190  return totalrval;
191 }
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
NumericVector< Number > & get_sensitivity_solution(unsigned int i=0)
Definition: system.C:1179
NumericVector< Number > & get_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1324
virtual LinearSolver< Number > * get_linear_solver() const
const SparseMatrix< Number > * request_matrix(std::string_view mat_name) const
Definition: system.C:1087
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
template class LIBMESH_EXPORT LinearSolver< Number >
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
template class LIBMESH_EXPORT SparseMatrix< Number >
SparseMatrix< Number > * matrix
The system matrix.
virtual void assemble_residual_derivatives(const ParameterVector &parameters) override
Residual parameter derivative function.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
NumericVector< Number > & add_sensitivity_solution(unsigned int i=0)
Definition: system.C:1169
bool assemble_before_solve
Flag which tells the system to whether or not to call the user assembly function during each call to ...
Definition: system.h:1609
const DofMap & get_dof_map() const
Definition: system.h:2417
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:2518

◆ set_adjoint_already_solved()

void libMesh::System::set_adjoint_already_solved ( bool  setting)
inlineinherited

Setter for the adjoint_already_solved boolean.

Definition at line 417 of file system.h.

References libMesh::System::adjoint_already_solved.

Referenced by main().

418  { adjoint_already_solved = setting;}
bool adjoint_already_solved
Has the adjoint problem already been solved? If the user sets adjoint_already_solved to true...
Definition: system.h:2332

◆ set_basic_system_only()

void libMesh::System::set_basic_system_only ( )
inlineinherited

Sets the system to be "basic only": i.e.

advanced system components such as ImplicitSystem matrices may not be initialized. This is useful for efficiency in certain utility programs that never use System::solve(). This method must be called after the System or derived class is created but before it is initialized; e.g. from within EquationSystems::read()

Definition at line 2465 of file system.h.

References libMesh::System::_basic_system_only.

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

2466 {
2467  _basic_system_only = true;
2468 }
bool _basic_system_only
Holds true if the components of more advanced system types (e.g.
Definition: system.h:2300

◆ set_constrain_in_solver()

void libMesh::DifferentiableSystem::set_constrain_in_solver ( bool  enable)
virtualinherited

set_constrain_in_solver to false to apply constraints only via residual terms in the systems to be solved.

Definition at line 356 of file diff_system.C.

References libMesh::DifferentiableSystem::_constrain_in_solver, and libMesh::DifferentiableSystem::time_solver.

Referenced by main(), and set_system_parameters().

357 {
358  _constrain_in_solver = enable;
359  this->time_solver->diff_solver()->set_exact_constraint_enforcement(enable);
360 }
bool _constrain_in_solver
_constrain_in_solver defaults to true; if false then we apply constraints only via residual terms in ...
Definition: diff_system.h:424
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245

◆ set_mesh_system()

void libMesh::DifferentiablePhysics::set_mesh_system ( System sys)
inlinevirtualinherited

Tells the DifferentiablePhysics that system sys contains the isoparametric Lagrangian variables which correspond to the coordinates of mesh nodes, in problems where the mesh itself is expected to move in time.

The system with mesh coordinate data (which may be this system itself, for fully coupled moving mesh problems) is currently assumed to have new (end of time step) mesh coordinates stored in solution, old (beginning of time step) mesh coordinates stored in _old_nonlinear_solution, and constant velocity motion during each time step.

Activating this function ensures that local (but not neighbor!) element geometry is correctly repositioned when evaluating element residuals.

Currently sys must be *this for a tightly coupled moving mesh problem or nullptr to stop mesh movement; loosely coupled moving mesh problems are not implemented.

This code is experimental. "Trust but verify, and not in that order"

Definition at line 569 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_sys.

Referenced by SolidSystem::init_data().

570 {
571  // For now we assume that we're doing fully coupled mesh motion
572  // if (sys && sys != this)
573  // libmesh_not_implemented();
574 
575  // For the foreseeable future we'll assume that we keep these
576  // Systems in the same EquationSystems
577  // libmesh_assert_equal_to (&this->get_equation_systems(),
578  // &sys->get_equation_systems());
579 
580  // And for the immediate future this code may not even work
581  libmesh_experimental();
582 
583  _mesh_sys = sys;
584 }
System * _mesh_sys
System from which to acquire moving mesh information.
Definition: diff_physics.h:531

◆ set_mesh_x_var()

void libMesh::DifferentiablePhysics::set_mesh_x_var ( unsigned int  var)
inlinevirtualinherited

Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the x coordinate of mesh nodes, in problems where the mesh itself is expected to move in time.

The system with mesh coordinate data (which may be this system itself, for fully coupled moving mesh problems) is currently assumed to have new (end of time step) mesh coordinates stored in solution, old (beginning of time step) mesh coordinates stored in _old_nonlinear_solution, and constant velocity motion during each time step.

Activating this function ensures that local (but not neighbor!) element geometry is correctly repositioned when evaluating element residuals.

Definition at line 589 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_x_var.

Referenced by SolidSystem::init_data().

590 {
591  _mesh_x_var = var;
592 }
unsigned int _mesh_x_var
Variables from which to acquire moving mesh information.
Definition: diff_physics.h:536

◆ set_mesh_y_var()

void libMesh::DifferentiablePhysics::set_mesh_y_var ( unsigned int  var)
inlinevirtualinherited

Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the y coordinate of mesh nodes.

Definition at line 597 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_y_var.

Referenced by SolidSystem::init_data().

598 {
599  _mesh_y_var = var;
600 }

◆ set_mesh_z_var()

void libMesh::DifferentiablePhysics::set_mesh_z_var ( unsigned int  var)
inlinevirtualinherited

Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the z coordinate of mesh nodes.

Definition at line 605 of file diff_physics.h.

References libMesh::DifferentiablePhysics::_mesh_z_var.

Referenced by SolidSystem::init_data().

606 {
607  _mesh_z_var = var;
608 }

◆ set_numerical_jacobian_h_for_var()

void FEMSystem::set_numerical_jacobian_h_for_var ( unsigned int  var_num,
Real  new_h 
)
inlineinherited

Definition at line 275 of file fem_system.h.

References libMesh::FEMSystem::_numerical_jacobian_h_for_var, and libMesh::Real.

277 {
278  if (_numerical_jacobian_h_for_var.size() <= var_num)
279  _numerical_jacobian_h_for_var.resize(var_num+1,Real(0));
280 
281  libmesh_assert_greater(new_h, Real(0));
282 
283  _numerical_jacobian_h_for_var[var_num] = new_h;
284 }
std::vector< Real > _numerical_jacobian_h_for_var
Definition: fem_system.h:258
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ set_project_with_constraints()

void libMesh::System::set_project_with_constraints ( bool  _project_with_constraints)
inlineinherited

Definition at line 1842 of file system.h.

References libMesh::System::project_with_constraints.

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

1843  {
1844  project_with_constraints = _project_with_constraints;
1845  }
bool project_with_constraints
Do we want to apply constraints while projecting vectors ?
Definition: system.h:2343

◆ set_qoi() [1/2]

void libMesh::System::set_qoi ( unsigned int  qoi_index,
Number  qoi_value 
)
inherited

Definition at line 2171 of file system.C.

References libMesh::System::_qoi, and libMesh::libmesh_assert().

Referenced by libMesh::ExplicitSystem::assemble_qoi(), libMesh::FEMSystem::assemble_qoi(), libMesh::Euler2Solver::integrate_qoi_timestep(), libMesh::TwostepTimeSolver::integrate_qoi_timestep(), and libMesh::EulerSolver::integrate_qoi_timestep().

2172 {
2173  libmesh_assert(qoi_index < _qoi.size());
2174 
2175  _qoi[qoi_index] = qoi_value;
2176 }
std::vector< Number > _qoi
Values of the quantities of interest.
Definition: system.h:2367
libmesh_assert(ctx)

◆ set_qoi() [2/2]

void libMesh::System::set_qoi ( std::vector< Number new_qoi)
inherited

Definition at line 2192 of file system.C.

References libMesh::System::_qoi.

2193 {
2194  libmesh_assert_equal_to(this->_qoi.size(), new_qoi.size());
2195  this->_qoi = std::move(new_qoi);
2196 }
std::vector< Number > _qoi
Values of the quantities of interest.
Definition: system.h:2367

◆ set_qoi_error_estimate()

void libMesh::System::set_qoi_error_estimate ( unsigned int  qoi_index,
Number  qoi_error_estimate 
)
inherited

Definition at line 2199 of file system.C.

References libMesh::System::_qoi_error_estimates, and libMesh::libmesh_assert().

Referenced by libMesh::Euler2Solver::integrate_adjoint_refinement_error_estimate(), libMesh::TwostepTimeSolver::integrate_adjoint_refinement_error_estimate(), and libMesh::EulerSolver::integrate_adjoint_refinement_error_estimate().

2200 {
2201  libmesh_assert(qoi_index < _qoi_error_estimates.size());
2202 
2203  _qoi_error_estimates[qoi_index] = qoi_error_estimate;
2204 }
libmesh_assert(ctx)
std::vector< Number > _qoi_error_estimates
Vector to hold error estimates for qois, either from a steady state calculation, or from a single uns...
Definition: system.h:2377

◆ set_time_solver()

void libMesh::DifferentiableSystem::set_time_solver ( std::unique_ptr< TimeSolver _time_solver)
inlineinherited

Sets the time_solver FIXME: This code is a little dangerous as it transfers ownership from the TimeSolver creator to this class.

The user must no longer access his original TimeSolver object after calling this function.

Definition at line 253 of file diff_system.h.

References libMesh::DifferentiableSystem::time_solver.

254  {
255  time_solver.reset(_time_solver.release());
256  }
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245

◆ set_vector_as_adjoint()

void libMesh::System::set_vector_as_adjoint ( const std::string &  vec_name,
int  qoi_num 
)
inherited

Allows one to set the QoI index controlling whether the vector identified by vec_name represents a solution from the adjoint (qoi_num >= 0) or primal (qoi_num == -1) space.

This becomes significant if those spaces have differing heterogeneous Dirichlet constraints.

qoi_num == -2 can be used to indicate a vector which should not be affected by constraints during projection operations.

Definition at line 1147 of file system.C.

References libMesh::System::_vector_is_adjoint.

Referenced by libMesh::System::add_adjoint_solution(), and libMesh::System::add_weighted_sensitivity_adjoint_solution().

1149 {
1150  parallel_object_only(); // Not strictly needed, but the only safe way to keep in sync
1151 
1152  // We reserve -1 for vectors which get primal constraints, -2 for
1153  // vectors which get no constraints
1154  libmesh_assert_greater_equal(qoi_num, -2);
1155  _vector_is_adjoint[vec_name] = qoi_num;
1156 }
std::map< std::string, int, std::less<> > _vector_is_adjoint
Holds non-negative if a vector by that name should be projected using adjoint constraints/BCs, -1 if primal.
Definition: system.h:2272

◆ set_vector_preservation()

void libMesh::System::set_vector_preservation ( const std::string &  vec_name,
bool  preserve 
)
inherited

Allows one to set the boolean controlling whether the vector identified by vec_name should be "preserved": projected to new meshes, saved, etc.

Definition at line 1125 of file system.C.

References libMesh::System::_vector_projections.

Referenced by libMesh::AdjointRefinementEstimator::estimate_error(), and main().

1127 {
1128  parallel_object_only(); // Not strictly needed, but the only safe way to keep in sync
1129 
1130  _vector_projections[vec_name] = preserve;
1131 }
std::map< std::string, bool, std::less<> > _vector_projections
Holds true if a vector by that name should be projected onto a changed grid, false if it should be ze...
Definition: system.h:2266

◆ setup_static_condensation_preconditioner()

template<typename T >
template void libMesh::ImplicitSystem::setup_static_condensation_preconditioner ( T &  solver)
protectedinherited

◆ side_constraint()

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

Adds the constraint contribution on side of 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 depending on the boundary conditions.

To implement a weak form of the constraint 0 = G(u), the user should examine u = elem_solution and add (G(u), phi_i) boundary integral contributions to elem_residual in side_constraint().

Reimplemented in LaplaceSystem, LaplaceSystem, LaplaceSystem, and NavierSystem.

Definition at line 195 of file diff_physics.h.

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

197  {
198  return request_jacobian;
199  }

◆ side_damping_residual()

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

Subtracts a damping vector contribution on side of elem from 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.

For most problems, the default implementation of "do nothing" is correct; users with boundary conditions including first time derivatives may need to reimplement this themselves.

Definition at line 378 of file diff_physics.h.

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

380  {
381  return request_jacobian;
382  }

◆ side_mass_residual()

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

Subtracts a mass vector contribution on side of elem from 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.

For most problems, the default implementation of "do nothing" is correct; users with boundary conditions including time derivatives may need to reimplement this themselves.

Definition at line 320 of file diff_physics.h.

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

322  {
323  return request_jacobian;
324  }

◆ side_postprocess()

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

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

Reimplemented in LaplaceSystem, and LaplaceSystem.

Definition at line 299 of file diff_system.h.

299 {}

◆ side_qoi()

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

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

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

Reimplemented in CoupledSystemQoI.

Definition at line 133 of file diff_qoi.h.

135  {}

◆ side_qoi_derivative()

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

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

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

Reimplemented in LaplaceSystem, LaplaceSystem, and CoupledSystemQoI.

Definition at line 145 of file diff_qoi.h.

147  {}

◆ side_time_derivative()

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

Adds the time derivative contribution on side of 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 depending on the boundary conditions.

To implement a weak form of the source term du/dt = F(u) on sides, such as might arise in a flux boundary condition, the user should examine u = elem_solution and add (F(u), phi_i) boundary integral contributions to elem_residual in side_constraint().

Reimplemented in ElasticitySystem, ElasticitySystem, CurlCurlSystem, CurlCurlSystem, and SolidSystem.

Definition at line 174 of file diff_physics.h.

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

176  {
177  return request_jacobian;
178  }

◆ solve()

void FEMSystem::solve ( )
overridevirtualinherited

Invokes the solver associated with the system.

For steady state solvers, this will find a root x where F(x) = 0. For transient solvers, this will integrate dx/dt = F(x).

For moving mesh systems, this also translates the mesh to the solution position.

Reimplemented from libMesh::DifferentiableSystem.

Reimplemented in libMesh::VariationalSmootherSystem, and libMesh::ContinuationSystem.

Definition at line 1076 of file fem_system.C.

References libMesh::FEMSystem::mesh_position_set(), and libMesh::DifferentiableSystem::solve().

Referenced by main(), and libMesh::VariationalSmootherSystem::solve().

1077 {
1078  // We are solving the primal problem
1079  Parent::solve();
1080 
1081  // On a moving mesh we want the mesh to reflect the new solution
1082  this->mesh_position_set();
1083 }
void mesh_position_set()
Tells the FEMSystem to set the mesh nodal coordinates which should correspond to degree of freedom co...
Definition: fem_system.C:1087
virtual void solve() override
Invokes the solver associated with the system.
Definition: diff_system.C:138

◆ solve_for_unconstrained_dofs()

void libMesh::System::solve_for_unconstrained_dofs ( NumericVector< Number > &  vec,
int  is_adjoint = -1 
) const
inherited

Definition at line 2102 of file system_projection.C.

References libMesh::DofMap::build_sparsity(), libMesh::DofMap::computed_sparsity_already(), libMesh::DofMapBase::end_dof(), libMesh::DofMapBase::first_dof(), libMesh::NumericVector< T >::get(), libMesh::DofMap::heterogenously_constrain_element_matrix_and_vector(), libMesh::DofMap::is_constrained_dof(), libMesh::NumericVector< T >::local_size(), libMesh::DofMap::n_dofs(), libMesh::DofMap::n_local_dofs(), libMesh::PARALLEL, libMesh::Real, libMesh::NumericVector< T >::size(), and libMesh::DofMap::update_sparsity_pattern().

2104 {
2105  const DofMap & dof_map = this->get_dof_map();
2106 
2107  std::unique_ptr<SparseMatrix<Number>> mat =
2109 
2110  std::unique_ptr<SparsityPattern::Build> sp;
2111 
2112  if (dof_map.computed_sparsity_already())
2113  dof_map.update_sparsity_pattern(*mat);
2114  else
2115  {
2116  mat->attach_dof_map(dof_map);
2117  sp = dof_map.build_sparsity(this->get_mesh());
2118  mat->attach_sparsity_pattern(*sp);
2119  }
2120 
2121  mat->init();
2122 
2123  libmesh_assert_equal_to(vec.size(), dof_map.n_dofs());
2124  libmesh_assert_equal_to(vec.local_size(), dof_map.n_local_dofs());
2125 
2126  std::unique_ptr<NumericVector<Number>> rhs =
2128 
2129  rhs->init(dof_map.n_dofs(), dof_map.n_local_dofs(), false,
2130  PARALLEL);
2131 
2132  // Here we start with the unconstrained (and indeterminate) linear
2133  // system, K*u = f, where K is the identity matrix for constrained
2134  // DoFs and 0 elsewhere, and f is the current solution values for
2135  // constrained DoFs and 0 elsewhere.
2136  // We then apply the usual heterogeneous constraint matrix C and
2137  // offset h, where u = C*x + h,
2138  // to get C^T*K*C*x = C^T*f - C^T*K*h
2139  // - a constrained and no-longer-singular system that finds the
2140  // closest approximation for the unconstrained degrees of freedom.
2141  //
2142  // Here, though "closest" is in an algebraic sense; we're
2143  // effectively using a pseudoinverse that optimizes in a
2144  // discretization-dependent norm. That only seems to give ~0.1%
2145  // excess error even in coarse unit test cases, but at some point it
2146  // might be reasonable to weight K and f properly.
2147 
2148  for (dof_id_type d : IntRange<dof_id_type>(dof_map.first_dof(),
2149  dof_map.end_dof()))
2150  {
2151  if (dof_map.is_constrained_dof(d))
2152  {
2153  DenseMatrix<Number> K(1,1);
2154  DenseVector<Number> F(1);
2155  std::vector<dof_id_type> dof_indices(1, d);
2156  K(0,0) = 1;
2157  F(0) = (*this->solution)(d);
2158  dof_map.heterogenously_constrain_element_matrix_and_vector
2159  (K, F, dof_indices, false, is_adjoint);
2160  mat->add_matrix(K, dof_indices);
2161  rhs->add_vector(F, dof_indices);
2162  }
2163  }
2164 
2165  std::unique_ptr<LinearSolver<Number>> linear_solver =
2167 
2168  linear_solver->solve(*mat, vec, *rhs,
2169  double(this->get_equation_systems().parameters.get<Real>("linear solver tolerance")),
2170  this->get_equation_systems().parameters.get<unsigned int>("linear solver maximum iterations"));
2171 }
static std::unique_ptr< LinearSolver< T > > build(const libMesh::Parallel::Communicator &comm_in, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a LinearSolver using the linear solver package specified by solver_package.
Definition: linear_solver.C:59
virtual numeric_index_type size() const =0
const EquationSystems & get_equation_systems() const
Definition: system.h:767
const Parallel::Communicator & comm() const
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
Definition: system.h:1588
const MeshBase & get_mesh() const
Definition: system.h:2401
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package(), const MatrixBuildType matrix_build_type=MatrixBuildType::AUTOMATIC)
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
const T & get(std::string_view) const
Definition: parameters.h:451
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual numeric_index_type local_size() const =0
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
const DofMap & get_dof_map() const
Definition: system.h:2417
uint8_t dof_id_type
Definition: id_types.h:67

◆ system()

sys_type& libMesh::ImplicitSystem::system ( )
inlineinherited
Returns
A reference to *this.

Definition at line 87 of file implicit_system.h.

87 { return *this; }

◆ system_type()

virtual std::string libMesh::ImplicitSystem::system_type ( ) const
inlineoverridevirtualinherited
Returns
"Implicit". Helps in identifying the system type in an equation system file.

Reimplemented from libMesh::ExplicitSystem.

Reimplemented in libMesh::NonlinearImplicitSystem, libMesh::OptimizationSystem, libMesh::LinearImplicitSystem, libMesh::RBConstruction, libMesh::FrequencySystem, libMesh::TransientSystem< RBConstruction >, libMesh::NewmarkSystem, libMesh::ClawSystem, and SolidSystem.

Definition at line 117 of file implicit_system.h.

117 { return "Implicit"; }

◆ thread_join()

void libMesh::DifferentiableQoI::thread_join ( std::vector< Number > &  qoi,
const std::vector< Number > &  other_qoi,
const QoISet qoi_indices 
)
virtualinherited

Method to combine thread-local qois.

By default, simply sums thread qois.

Definition at line 33 of file diff_qoi.C.

References libMesh::index_range().

36 {
37  for (auto i : index_range(qoi))
38  qoi[i] += other_qoi[i];
39 }
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:150

◆ time_evolving()

void libMesh::DifferentiablePhysics::time_evolving ( unsigned int  var,
unsigned int  order 
)
virtualinherited

Tells the DiffSystem that variable var is evolving with respect to time.

In general, the user's init() function should call time_evolving() with order 1 for any variables which behave like du/dt = F(u), with order 2 for any variables that behave like d^2u/dt^2 = F(u), and should not call time_evolving() for any variables which behave like 0 = G(u).

Most derived systems will not have to reimplement this function; however any system which reimplements mass_residual() may have to reimplement time_evolving() to prepare data structures.

Definition at line 42 of file diff_physics.C.

References libMesh::DifferentiablePhysics::_first_order_vars, libMesh::DifferentiablePhysics::_second_order_vars, and libMesh::DifferentiablePhysics::_time_evolving.

Referenced by libMesh::DifferentiableSystem::add_second_order_dot_vars(), SigmaPhysics::init_data(), CurlCurlSystem::init_data(), and HeatSystem::init_data().

44 {
45  libmesh_error_msg_if(order != 1 && order != 2, "Input order must be 1 or 2!");
46 
47  if (_time_evolving.size() <= var)
48  _time_evolving.resize(var+1, 0);
49 
50  _time_evolving[var] = order;
51 
52  if (order == 1)
53  _first_order_vars.insert(var);
54  else
55  _second_order_vars.insert(var);
56 }
std::set< unsigned int > _second_order_vars
Variable indices for those variables that are second order in time.
Definition: diff_physics.h:553
std::set< unsigned int > _first_order_vars
Variable indices for those variables that are first order in time.
Definition: diff_physics.h:548
std::vector< unsigned int > _time_evolving
Stores unsigned int to tell us which variables are evolving as first order in time (1)...
Definition: diff_physics.h:543

◆ update()

void libMesh::System::update ( )
virtualinherited

Update the local values to reflect the solution on neighboring processors.

Reimplemented in SolidSystem.

Definition at line 498 of file system.C.

References libMesh::System::_dof_map, libMesh::System::current_local_solution, libMesh::libmesh_assert(), and libMesh::System::solution.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::FEMSystem::assemble_qoi(), libMesh::FEMSystem::assemble_qoi_derivative(), libMesh::NonlinearImplicitSystem::assembly(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::NewmarkSolver::compute_initial_accel(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::Nemesis_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::GMVIO::copy_nodal_solution(), libMesh::Nemesis_IO::copy_nodal_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::Nemesis_IO::copy_scalar_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), DMlibMeshFunction(), DMlibMeshJacobian(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::TransientRBConstruction::initialize_truth(), libMesh::Euler2Solver::integrate_adjoint_refinement_error_estimate(), libMesh::EulerSolver::integrate_adjoint_refinement_error_estimate(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_residual(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::NewtonSolver::line_search(), libMesh::RBConstruction::load_basis_function(), libMesh::TransientRBConstruction::load_rb_solution(), libMesh::RBConstruction::load_rb_solution(), main(), libMesh::FEMSystem::mesh_position_get(), HeatSystem::perturb_accumulate_residuals(), libMesh::ErrorVector::plot_error(), libMesh::FEMSystem::postprocess(), libMesh::ImplicitSystem::qoi_parameter_hessian(), libMesh::MemorySolutionHistory::retrieve(), libMesh::FileSolutionHistory::retrieve(), libMesh::NewtonSolver::solve(), libMesh::ExplicitSystem::solve(), libMesh::LinearImplicitSystem::solve(), libMesh::OptimizationSystem::solve(), libMesh::NonlinearImplicitSystem::solve(), libMesh::ClawSystem::solve_conservation_law(), libMesh::RBConstruction::solve_for_matrix_and_rhs(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::DirectSolutionTransfer::transfer(), and update_current_local_solution().

499 {
500  parallel_object_only();
501 
502  libmesh_assert(solution->closed());
503 
504  const std::vector<dof_id_type> & send_list = _dof_map->get_send_list ();
505 
506  // Check sizes
507  libmesh_assert_equal_to (current_local_solution->size(), solution->size());
508  // More processors than elements => empty send_list
509  // libmesh_assert (!send_list.empty());
510  libmesh_assert_less_equal (send_list.size(), solution->size());
511 
512  // Create current_local_solution from solution. This will
513  // put a local copy of solution into current_local_solution.
514  // Only the necessary values (specified by the send_list)
515  // are copied to minimize communication
516  solution->localize (*current_local_solution, send_list);
517 }
std::unique_ptr< DofMap > _dof_map
Data structure describing the relationship between nodes, variables, etc...
Definition: system.h:2225
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
libmesh_assert(ctx)
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667

◆ update_global_solution() [1/2]

void libMesh::System::update_global_solution ( std::vector< Number > &  global_soln) const
inherited

Fill the input vector global_soln so that it contains the global solution on all processors.

Requires communication with all other processors.

Definition at line 733 of file system.C.

References libMesh::System::solution.

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::ExactErrorEstimator::estimate_error(), main(), and libMesh::InterMeshProjection::project_system_vectors().

734 {
735  parallel_object_only();
736 
737  global_soln.resize (solution->size());
738 
739  solution->localize (global_soln);
740 }
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655

◆ update_global_solution() [2/2]

void libMesh::System::update_global_solution ( std::vector< Number > &  global_soln,
const processor_id_type  dest_proc 
) const
inherited

Fill the input vector global_soln so that it contains the global solution on processor dest_proc.

Requires communication with all other processors.

Definition at line 744 of file system.C.

References libMesh::System::solution.

746 {
747  parallel_object_only();
748 
749  global_soln.resize (solution->size());
750 
751  solution->localize_to_one (global_soln, dest_proc);
752 }
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655

◆ user_assembly()

void libMesh::System::user_assembly ( )
virtualinherited

Calls user's attached assembly function, or is overridden by the user in derived classes.

Definition at line 2104 of file system.C.

References libMesh::System::_assemble_system_function, libMesh::System::_assemble_system_object, libMesh::System::_equation_systems, libMesh::System::Assembly::assemble(), and libMesh::System::name().

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

2105 {
2106  // Call the user-provided assembly function,
2107  // if it was provided
2108  if (_assemble_system_function != nullptr)
2110 
2111  // ...or the user-provided assembly object.
2112  else if (_assemble_system_object != nullptr)
2114 }
Assembly * _assemble_system_object
Object that assembles the system.
Definition: system.h:2182
virtual void assemble()=0
Assembly function.
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2231
const std::string & name() const
Definition: system.h:2385
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Function that assembles the system.
Definition: system.h:2176

◆ user_constrain()

void libMesh::System::user_constrain ( )
virtualinherited

Calls user's attached constraint function, or is overridden by the user in derived classes.

Definition at line 2118 of file system.C.

References libMesh::System::_constrain_system_function, libMesh::System::_constrain_system_object, libMesh::System::_equation_systems, libMesh::System::Constraint::constrain(), and libMesh::System::name().

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

2119 {
2120  // Call the user-provided constraint function,
2121  // if it was provided
2122  if (_constrain_system_function!= nullptr)
2124 
2125  // ...or the user-provided constraint object.
2126  else if (_constrain_system_object != nullptr)
2128 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Function to impose constraints.
Definition: system.h:2187
Constraint * _constrain_system_object
Object that constrains the system.
Definition: system.h:2193
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2231
virtual void constrain()=0
Constraint function.
const std::string & name() const
Definition: system.h:2385

◆ user_initialization()

void libMesh::System::user_initialization ( )
virtualinherited

Calls user's attached initialization function, or is overridden by the user in derived classes.

Definition at line 2090 of file system.C.

References libMesh::System::_equation_systems, libMesh::System::_init_system_function, libMesh::System::_init_system_object, libMesh::System::Initialization::initialize(), and libMesh::System::name().

Referenced by libMesh::NewmarkSystem::initial_conditions(), and libMesh::System::reinit_mesh().

2091 {
2092  // Call the user-provided initialization function,
2093  // if it was provided
2094  if (_init_system_function != nullptr)
2095  this->_init_system_function (_equation_systems, this->name());
2096 
2097  // ...or the user-provided initialization object.
2098  else if (_init_system_object != nullptr)
2100 }
virtual void initialize()=0
Initialization function.
Initialization * _init_system_object
Object that initializes the system.
Definition: system.h:2171
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Function that initializes the system.
Definition: system.h:2165
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2231
const std::string & name() const
Definition: system.h:2385

◆ user_QOI()

void libMesh::System::user_QOI ( const QoISet qoi_indices)
virtualinherited

Calls user's attached quantity of interest function, or is overridden by the user in derived classes.

Definition at line 2132 of file system.C.

References libMesh::System::_equation_systems, libMesh::System::_qoi_evaluate_function, libMesh::System::_qoi_evaluate_object, libMesh::System::name(), and libMesh::System::QOI::qoi().

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

2133 {
2134  // Call the user-provided quantity of interest function,
2135  // if it was provided
2136  if (_qoi_evaluate_function != nullptr)
2137  this->_qoi_evaluate_function(_equation_systems, this->name(), qoi_indices);
2138 
2139  // ...or the user-provided QOI function object.
2140  else if (_qoi_evaluate_object != nullptr)
2141  this->_qoi_evaluate_object->qoi(qoi_indices);
2142 }
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Function to evaluate quantity of interest.
Definition: system.h:2198
virtual void qoi(const QoISet &qoi_indices)=0
Quantity of interest function.
QOI * _qoi_evaluate_object
Object to compute quantities of interest.
Definition: system.h:2205
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2231
const std::string & name() const
Definition: system.h:2385

◆ user_QOI_derivative()

void libMesh::System::user_QOI_derivative ( const QoISet qoi_indices = QoISet(),
bool  include_liftfunc = true,
bool  apply_constraints = true 
)
virtualinherited

Calls user's attached quantity of interest derivative function, or is overridden by the user in derived classes.

Definition at line 2146 of file system.C.

References libMesh::System::_equation_systems, libMesh::System::_qoi_evaluate_derivative_function, libMesh::System::_qoi_evaluate_derivative_object, libMesh::System::name(), and libMesh::System::QOIDerivative::qoi_derivative().

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

2149 {
2150  // Call the user-provided quantity of interest derivative,
2151  // if it was provided
2152  if (_qoi_evaluate_derivative_function != nullptr)
2154  (_equation_systems, this->name(), qoi_indices, include_liftfunc,
2155  apply_constraints);
2156 
2157  // ...or the user-provided QOI derivative function object.
2158  else if (_qoi_evaluate_derivative_object != nullptr)
2160  (qoi_indices, include_liftfunc, apply_constraints);
2161 }
QOIDerivative * _qoi_evaluate_derivative_object
Object to compute derivatives of quantities of interest.
Definition: system.h:2219
virtual void qoi_derivative(const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)=0
Quantity of interest derivative function.
EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: system.h:2231
const std::string & name() const
Definition: system.h:2385
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Function to evaluate quantity of interest derivative.
Definition: system.h:2210

◆ variable()

const Variable & libMesh::System::variable ( unsigned int  var) const
inherited

Return a constant reference to Variable var.

Definition at line 2699 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::variable().

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DifferentiableSystem::add_second_order_dot_vars(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::FirstOrderUnsteadySolver::compute_second_order_eqns(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SubFunctor::find_dofs_to_send(), libMesh::DifferentiableSystem::have_first_order_scalar_vars(), libMesh::DifferentiableSystem::have_second_order_scalar_vars(), main(), libMesh::DifferentiablePhysics::nonlocal_mass_residual(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SortAndCopy::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectVertices::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectEdges::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectSides::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectInteriors::operator()(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::PetscPreconditioner< T >::set_petsc_aux_data(), libMesh::PetscDMWrapper::set_point_range_in_section(), SystemsTest::testFirstScalarNumber(), libMesh::System::write_header(), libMesh::Nemesis_IO_Helper::write_nodal_solution(), libMesh::System::write_parallel_data(), libMesh::System::write_serialized_vector(), and libMesh::System::write_serialized_vectors().

2700 {
2701  return this->get_dof_map().variable(i);
2702 }
const Variable & variable(const unsigned int c) const override
Definition: dof_map.h:2358
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ variable_group()

const VariableGroup & libMesh::System::variable_group ( unsigned int  vg) const
inherited

Return a constant reference to VariableGroup vg.

Definition at line 2704 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::variable_group().

Referenced by libMesh::FEMSystem::assembly(), and libMesh::System::get_info().

2705 {
2706  return this->get_dof_map().variable_group(vg);
2707 }
const VariableGroup & variable_group(const unsigned int c) const
Definition: dof_map.h:2348
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ variable_name()

const std::string & libMesh::System::variable_name ( const unsigned int  i) const
inherited

◆ variable_number()

unsigned int libMesh::System::variable_number ( std::string_view  var) const
inherited
Returns
The variable number associated with the user-specified variable named var.

Definition at line 1398 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::variable_number().

Referenced by libMesh::ExactSolution::_compute_error(), alternative_fe_assembly(), LinearElasticity::assemble(), AssembleOptimization::assemble_A_and_F(), assemble_divgrad(), assemble_elasticity(), assemble_graddiv(), assemble_matrix_and_rhs(), assemble_shell(), assemble_stokes(), compute_enriched_soln(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::Nemesis_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::GMVIO::copy_nodal_solution(), libMesh::Nemesis_IO::copy_nodal_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::ExactErrorEstimator::estimate_error(), fe_assembly(), libMesh::ExactErrorEstimator::find_squared_element_error(), CoupledSystemQoI::init_context(), libMesh::HDGProblem::jacobian(), LargeDeformationElasticity::jacobian(), line_print(), main(), LinearElasticityWithContact::move_mesh(), libMesh::System::read_header(), libMesh::HDGProblem::residual(), LargeDeformationElasticity::residual(), LinearElasticityWithContact::residual_and_jacobian(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), OverlappingTestBase::setup_coupling_matrix(), libMesh::DTKAdapter::update_variable_values(), libMesh::System::variable_scalar_number(), libMesh::EnsightIO::write_scalar_ascii(), and libMesh::EnsightIO::write_vector_ascii().

1399 {
1400  return this->get_dof_map().variable_number(var);
1401 }
unsigned int variable_number(std::string_view var) const
Definition: dof_map.h:2991
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ variable_scalar_number() [1/2]

unsigned int libMesh::System::variable_scalar_number ( std::string_view  var,
unsigned int  component 
) const
inlineinherited
Returns
An index, starting from 0 for the first component of the first variable, and incrementing for each component of each (potentially vector-valued) variable in the system in order. For systems with only scalar-valued variables, this will be the same as variable_number(var)

Irony: currently our only non-scalar-valued variable type is SCALAR.

Definition at line 2474 of file system.h.

References libMesh::System::variable_number().

Referenced by libMesh::Nemesis_IO::copy_scalar_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::ExactErrorEstimator::find_squared_element_error(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectVertices::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectEdges::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectSides::operator()(), and libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectInteriors::operator()().

2476 {
2477  return variable_scalar_number(this->variable_number(var), component);
2478 }
unsigned int variable_scalar_number(std::string_view var, unsigned int component) const
Definition: system.h:2474
unsigned int variable_number(std::string_view var) const
Definition: system.C:1398

◆ variable_scalar_number() [2/2]

unsigned int libMesh::System::variable_scalar_number ( unsigned int  var_num,
unsigned int  component 
) const
inherited
Returns
An index, starting from 0 for the first component of the first variable, and incrementing for each component of each (potentially vector-valued) variable in the system in order. For systems with only scalar-valued variables, this will be the same as var_num

Irony: currently our only non-scalar-valued variable type is SCALAR.

Definition at line 2710 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::variable_scalar_number().

2712 {
2713  return this->get_dof_map().variable_scalar_number(var_num, component);
2714 }
unsigned int variable_scalar_number(unsigned int var_num, unsigned int component) const
Definition: dof_map.h:2974
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ variable_type() [1/2]

const FEType & libMesh::System::variable_type ( const unsigned int  i) const
inherited
Returns
The finite element type variable number i.

Definition at line 2716 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::variable_type().

Referenced by libMesh::ExactSolution::_compute_error(), alternative_fe_assembly(), assemble(), libMesh::ClawSystem::assemble_advection_matrices(), libMesh::ClawSystem::assemble_avg_coupling_matrices(), libMesh::ClawSystem::assemble_boundary_condition_matrices(), assemble_ellipticdg(), libMesh::ClawSystem::assemble_jump_coupling_matrix(), libMesh::ClawSystem::assemble_mass_matrix(), assemble_shell(), assemble_stokes(), libMesh::FEMContext::attach_quadrature_rules(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::Nemesis_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::GMVIO::copy_nodal_solution(), libMesh::DGFEMContext::DGFEMContext(), fe_assembly(), libMesh::FEMContext::find_hardest_fe_type(), libMesh::EquationSystems::find_variable_numbers(), form_functionA(), form_functionB(), form_matrixA(), libMesh::FEMSystem::init_context(), libMesh::FEMContext::init_internal_data(), RationalMapTest< elem_type >::setUp(), FETestBase< order, family, elem_type, N_x >::setUp(), EquationSystemsTest::testBadVarNames(), libMesh::Nemesis_IO_Helper::write_element_values(), libMesh::System::write_header(), libMesh::Nemesis_IO_Helper::write_nodal_solution(), libMesh::EnsightIO::write_scalar_ascii(), and libMesh::EnsightIO::write_vector_ascii().

2717 {
2718  return this->get_dof_map().variable_type(i);
2719 }
const FEType & variable_type(const unsigned int i) const
Definition: dof_map.h:2388
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ variable_type() [2/2]

const FEType & libMesh::System::variable_type ( std::string_view  var) const
inherited
Returns
The finite element type for variable var.

Definition at line 2721 of file system.C.

References libMesh::System::get_dof_map(), and libMesh::DofMap::variable_type().

2722 {
2723  return this->get_dof_map().variable_type(var);
2724 }
const FEType & variable_type(const unsigned int i) const
Definition: dof_map.h:2388
const DofMap & get_dof_map() const
Definition: system.h:2417

◆ vector_is_adjoint()

int libMesh::System::vector_is_adjoint ( std::string_view  vec_name) const
inherited
Returns
The integer describing whether the vector identified by vec_name represents a solution from an adjoint (non-negative) or the primal (-1) space.

Definition at line 1160 of file system.C.

References libMesh::System::_vector_is_adjoint, and libMesh::libmesh_assert().

Referenced by libMesh::InterMeshProjection::project_system_vectors(), and libMesh::System::restrict_vectors().

1161 {
1162  const auto it = _vector_is_adjoint.find(vec_name);
1163  libmesh_assert(it != _vector_is_adjoint.end());
1164  return it->second;
1165 }
std::map< std::string, int, std::less<> > _vector_is_adjoint
Holds non-negative if a vector by that name should be projected using adjoint constraints/BCs, -1 if primal.
Definition: system.h:2272
libmesh_assert(ctx)

◆ vector_name() [1/2]

const std::string & libMesh::System::vector_name ( const unsigned int  vec_num) const
inherited
Returns
The name of this system's additional vector number vec_num (where the vectors are counted starting with 0).

Definition at line 971 of file system.C.

References libMesh::System::_vectors, and libMesh::System::vectors_begin().

Referenced by libMesh::AdjointRefinementEstimator::estimate_error(), and main().

972 {
973  // If we don't have that many vectors, throw an error
974  libmesh_assert_less(vec_num, _vectors.size());
975 
976  // Otherwise return a reference to the vec_num'th vector name
977  auto it = vectors_begin();
978  std::advance(it, vec_num);
979  return it->first;
980 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2505

◆ vector_name() [2/2]

const std::string & libMesh::System::vector_name ( const NumericVector< Number > &  vec_reference) const
inherited
Returns
The name of a system vector, given a reference to that vector

Definition at line 982 of file system.C.

References libMesh::System::_vectors, libMesh::NumericVector< T >::get(), libMesh::libmesh_assert(), libMesh::System::vectors_begin(), and libMesh::System::vectors_end().

983 {
984  // Linear search for a vector whose pointer matches vec_reference
985  auto it = std::find_if(vectors_begin(), vectors_end(),
986  [&vec_reference](const decltype(_vectors)::value_type & pr)
987  { return &vec_reference == pr.second.get(); });
988 
989  // Before returning, make sure we didn't loop till the end and not find any match
990  libmesh_assert (it != vectors_end());
991 
992  // Return the string associated with the current vector
993  return it->first;
994 }
vectors_iterator vectors_end()
End of vectors container.
Definition: system.h:2517
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
Access multiple components at once.
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2505
libmesh_assert(ctx)

◆ vector_preservation()

bool libMesh::System::vector_preservation ( std::string_view  vec_name) const
inherited
Returns
The boolean describing whether the vector identified by vec_name should be "preserved": projected to new meshes, saved, etc.

Definition at line 1135 of file system.C.

References libMesh::System::_vector_projections.

Referenced by libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::MemoryHistoryData::store_vectors(), SystemsTest::testAddVectorProjChange(), SystemsTest::testAddVectorTypeChange(), and SystemsTest::testPostInitAddVectorTypeChange().

1136 {
1137  if (auto it = _vector_projections.find(vec_name);
1138  it != _vector_projections.end())
1139  return it->second;
1140 
1141  // vec_name was not in the map, return false
1142  return false;
1143 }
std::map< std::string, bool, std::less<> > _vector_projections
Holds true if a vector by that name should be projected onto a changed grid, false if it should be ze...
Definition: system.h:2266

◆ vectors_begin() [1/2]

System::vectors_iterator libMesh::System::vectors_begin ( )
inlineinherited

Beginning of vectors container.

Definition at line 2505 of file system.h.

References libMesh::System::_vectors.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::System::get_vector(), libMesh::InterMeshProjection::project_system_vectors(), libMesh::System::request_vector(), libMesh::MemoryHistoryData::store_vectors(), and libMesh::System::vector_name().

2506 {
2507  return _vectors.begin();
2508 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ vectors_begin() [2/2]

System::const_vectors_iterator libMesh::System::vectors_begin ( ) const
inlineinherited

Beginning of vectors container.

Definition at line 2511 of file system.h.

References libMesh::System::_vectors.

2512 {
2513  return _vectors.begin();
2514 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ vectors_end() [1/2]

System::vectors_iterator libMesh::System::vectors_end ( )
inlineinherited

End of vectors container.

Definition at line 2517 of file system.h.

References libMesh::System::_vectors.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::InterMeshProjection::project_system_vectors(), libMesh::MemoryHistoryData::store_vectors(), and libMesh::System::vector_name().

2518 {
2519  return _vectors.end();
2520 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ vectors_end() [2/2]

System::const_vectors_iterator libMesh::System::vectors_end ( ) const
inlineinherited

End of vectors container.

Definition at line 2523 of file system.h.

References libMesh::System::_vectors.

2524 {
2525  return _vectors.end();
2526 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260

◆ weighted_sensitivity_adjoint_solve()

std::pair< unsigned int, Real > libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve ( const ParameterVector parameters,
const ParameterVector weights,
const QoISet qoi_indices = QoISet() 
)
overridevirtualinherited

Assembles & solves the linear system(s) (dR/du)^T*z_w = sum(w_p*(d^2q/dudp - d^2R/dudp*z)), for those parameters p contained within parameters, weighted by the values w_p found within weights.

Assumes that adjoint_solve has already calculated z for each qoi in qoi_indices.

Returns
A pair with the total number of linear iterations performed and the (sum of the) final residual norms

Reimplemented from libMesh::System.

Definition at line 247 of file implicit_system.C.

References libMesh::System::add_weighted_sensitivity_adjoint_solution(), libMesh::ExplicitSystem::assemble_qoi_derivative(), libMesh::ImplicitSystem::assembly(), libMesh::NumericVector< T >::close(), libMesh::SparseMatrix< T >::close(), libMesh::ParameterVector::deep_copy(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_adjoint_rhs(), libMesh::System::get_adjoint_solution(), libMesh::System::get_dof_map(), libMesh::ImplicitSystem::get_linear_solve_parameters(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::SparseMatrix< T >::get_transpose(), libMesh::System::get_weighted_sensitivity_adjoint_solution(), libMesh::DofMap::has_adjoint_dirichlet_boundaries(), libMesh::QoISet::has_index(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::ImplicitSystem::matrix, libMesh::System::n_qois(), libMesh::Real, libMesh::ExplicitSystem::rhs, libMesh::LinearSolver< T >::solve(), libMesh::TOLERANCE, libMesh::ParameterVector::value_copy(), libMesh::SparseMatrix< T >::vector_mult_add(), and libMesh::NumericVector< T >::zero_clone().

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

250 {
251  // Log how long the linear solve takes.
252  LOG_SCOPE("weighted_sensitivity_adjoint_solve()", "ImplicitSystem");
253 
254  // We currently get partial derivatives via central differencing
255  const Real delta_p = TOLERANCE;
256 
257  ParameterVector & parameters_vec =
258  const_cast<ParameterVector &>(parameters_in);
259 
260  // The forward system should now already be solved.
261  // The adjoint system should now already be solved.
262  // Now we're assembling a weighted sum of adjoint-adjoint systems:
263  //
264  // dR/du (u, sum_l(w_l*z^l)) = sum_l(w_l*(Q''_ul - R''_ul (u, z)))
265 
266  // FIXME: The derivation here does not yet take adjoint boundary
267  // conditions into account.
268 #ifdef LIBMESH_ENABLE_DIRICHLET
269  for (auto i : make_range(this->n_qois()))
270  if (qoi_indices.has_index(i))
272 #endif
273 
274  // We'll assemble the rhs first, because the R'' term will require
275  // perturbing the jacobian
276 
277  // We'll use temporary rhs vectors, because we haven't (yet) found
278  // any good reasons why users might want to save these:
279 
280  std::vector<std::unique_ptr<NumericVector<Number>>> temprhs(this->n_qois());
281  for (auto i : make_range(this->n_qois()))
282  if (qoi_indices.has_index(i))
283  temprhs[i] = this->rhs->zero_clone();
284 
285  // We approximate the _l partial derivatives via a central
286  // differencing perturbation in the w_l direction:
287  //
288  // sum_l(w_l*v_l) ~= (v(p + dp*w_l*e_l) - v(p - dp*w_l*e_l))/(2*dp)
289 
290  // PETSc doesn't implement SGEMX, so neither does NumericVector,
291  // so we want to avoid calculating f -= R'*z. We'll thus evaluate
292  // the above equation by first adding -v(p+dp...), then multiplying
293  // the intermediate result vectors by -1, then adding -v(p-dp...),
294  // then finally dividing by 2*dp.
295 
296  ParameterVector oldparameters, parameterperturbation;
297  parameters_vec.deep_copy(oldparameters);
298  weights.deep_copy(parameterperturbation);
299  parameterperturbation *= delta_p;
300  parameters_vec += parameterperturbation;
301 
302  this->assembly(false, true);
303  this->matrix->close();
304 
305  // Take the discrete adjoint, so that we can calculate R_u(u,z) with
306  // a matrix-vector product of R_u and z.
308 
309  this->assemble_qoi_derivative(qoi_indices,
310  /* include_liftfunc = */ false,
311  /* apply_constraints = */ true);
312  for (auto i : make_range(this->n_qois()))
313  if (qoi_indices.has_index(i))
314  {
315  this->get_adjoint_rhs(i).close();
316  *(temprhs[i]) -= this->get_adjoint_rhs(i);
317  this->matrix->vector_mult_add(*(temprhs[i]), this->get_adjoint_solution(i));
318  *(temprhs[i]) *= -1.0;
319  }
320 
321  oldparameters.value_copy(parameters_vec);
322  parameterperturbation *= -1.0;
323  parameters_vec += parameterperturbation;
324 
325  this->assembly(false, true);
326  this->matrix->close();
328 
329  this->assemble_qoi_derivative(qoi_indices,
330  /* include_liftfunc = */ false,
331  /* apply_constraints = */ true);
332  for (auto i : make_range(this->n_qois()))
333  if (qoi_indices.has_index(i))
334  {
335  this->get_adjoint_rhs(i).close();
336  *(temprhs[i]) -= this->get_adjoint_rhs(i);
337  this->matrix->vector_mult_add(*(temprhs[i]), this->get_adjoint_solution(i));
338  *(temprhs[i]) /= (2.0*delta_p);
339  }
340 
341  // Finally, assemble the jacobian at the non-perturbed parameter
342  // values. Ignore assemble_before_solve; if we had a good
343  // non-perturbed matrix before we've already overwritten it.
344  oldparameters.value_copy(parameters_vec);
345 
346  // if (this->assemble_before_solve)
347  {
348  // Build the Jacobian
349  this->assembly(false, true);
350  this->matrix->close();
351 
352  // Take the discrete adjoint
354  }
355 
356  // The weighted adjoint-adjoint problem is linear
357  LinearSolver<Number> * solver = this->get_linear_solver();
358 
359  // Our iteration counts and residuals will be sums of the individual
360  // results
361  std::pair<unsigned int, Real> solver_params =
363  std::pair<unsigned int, Real> totalrval = std::make_pair(0,0.0);
364 
365  for (auto i : make_range(this->n_qois()))
366  if (qoi_indices.has_index(i))
367  {
368  const std::pair<unsigned int, Real> rval =
369  solver->solve (*matrix, this->add_weighted_sensitivity_adjoint_solution(i),
370  *(temprhs[i]),
371  double(solver_params.second),
372  solver_params.first);
373 
374  totalrval.first += rval.first;
375  totalrval.second += rval.second;
376  }
377 
378  // The linear solver may not have fit our constraints exactly
379 #ifdef LIBMESH_ENABLE_CONSTRAINTS
380  for (auto i : make_range(this->n_qois()))
381  if (qoi_indices.has_index(i))
384  /* homogeneous = */ true);
385 #endif
386 
387  return totalrval;
388 }
static constexpr Real TOLERANCE
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
unsigned int n_qois() const
Number of currently active quantities of interest.
Definition: system.h:2562
virtual std::unique_ptr< NumericVector< T > > zero_clone() const =0
NumericVector< Number > * rhs
The system matrix.
virtual LinearSolver< Number > * get_linear_solver() const
NumericVector< Number > & add_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1252
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
bool has_adjoint_dirichlet_boundaries(unsigned int q) const
libmesh_assert(ctx)
template class LIBMESH_EXPORT LinearSolver< Number >
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void vector_mult_add(NumericVector< T > &dest, const NumericVector< T > &arg) const
Multiplies the matrix by the NumericVector arg and adds the result to the NumericVector dest...
SparseMatrix< Number > * matrix
The system matrix.
virtual void get_transpose(SparseMatrix< T > &dest) const =0
Copies the transpose of the matrix into dest, which may be *this.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) override
Prepares adjoint_rhs for quantity of interest derivative assembly, then calls user qoi derivative fun...
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
Definition: system.C:1232
const DofMap & get_dof_map() const
Definition: system.h:2417
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution(unsigned int i=0)
Definition: system.C:1264
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:2518
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1294

◆ weighted_sensitivity_solve()

std::pair< unsigned int, Real > libMesh::ImplicitSystem::weighted_sensitivity_solve ( const ParameterVector parameters,
const ParameterVector weights 
)
overridevirtualinherited

Assembles & solves the linear system(s) (dR/du)*u_w = sum(w_p*-dR/dp), for those parameters p contained within parameters weighted by the values w_p found within weights.

Returns
A pair with the total number of linear iterations performed and the (sum of the) final residual norms

Reimplemented from libMesh::System.

Definition at line 393 of file implicit_system.C.

References libMesh::System::add_weighted_sensitivity_solution(), libMesh::ImplicitSystem::assembly(), libMesh::NumericVector< T >::clone(), libMesh::NumericVector< T >::close(), libMesh::SparseMatrix< T >::close(), libMesh::ParameterVector::deep_copy(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_dof_map(), libMesh::ImplicitSystem::get_linear_solve_parameters(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::System::get_weighted_sensitivity_solution(), libMesh::ImplicitSystem::matrix, libMesh::Real, libMesh::ExplicitSystem::rhs, libMesh::LinearSolver< T >::solve(), libMesh::TOLERANCE, and libMesh::ParameterVector::value_copy().

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

395 {
396  // Log how long the linear solve takes.
397  LOG_SCOPE("weighted_sensitivity_solve()", "ImplicitSystem");
398 
399  // We currently get partial derivatives via central differencing
400  const Real delta_p = TOLERANCE;
401 
402  ParameterVector & parameters_vec =
403  const_cast<ParameterVector &>(parameters_in);
404 
405  // The forward system should now already be solved.
406 
407  // Now we're assembling a weighted sum of sensitivity systems:
408  //
409  // dR/du (u, v)(sum(w_l*u'_l)) = -sum_l(w_l*R'_l (u, v)) forall v
410 
411  // We'll assemble the rhs first, because the R' term will require
412  // perturbing the system, and some applications may not be able to
413  // assemble a perturbed residual without simultaneously constructing
414  // a perturbed jacobian.
415 
416  // We approximate the _l partial derivatives via a central
417  // differencing perturbation in the w_l direction:
418  //
419  // sum_l(w_l*v_l) ~= (v(p + dp*w_l*e_l) - v(p - dp*w_l*e_l))/(2*dp)
420 
421  ParameterVector oldparameters, parameterperturbation;
422  parameters_vec.deep_copy(oldparameters);
423  weights.deep_copy(parameterperturbation);
424  parameterperturbation *= delta_p;
425  parameters_vec += parameterperturbation;
426 
427  this->assembly(true, false, true);
428  this->rhs->close();
429 
430  std::unique_ptr<NumericVector<Number>> temprhs = this->rhs->clone();
431 
432  oldparameters.value_copy(parameters_vec);
433  parameterperturbation *= -1.0;
434  parameters_vec += parameterperturbation;
435 
436  this->assembly(true, false, true);
437  this->rhs->close();
438 
439  *temprhs -= *(this->rhs);
440  *temprhs /= (2.0*delta_p);
441 
442  // Finally, assemble the jacobian at the non-perturbed parameter
443  // values
444  oldparameters.value_copy(parameters_vec);
445 
446  // Build the Jacobian
447  this->assembly(false, true);
448  this->matrix->close();
449 
450  // The weighted sensitivity problem is linear
451  LinearSolver<Number> * solver = this->get_linear_solver();
452 
453  std::pair<unsigned int, Real> solver_params =
455 
456  const std::pair<unsigned int, Real> rval =
457  solver->solve (*matrix, this->add_weighted_sensitivity_solution(),
458  *temprhs,
459  double(solver_params.second),
460  solver_params.first);
461 
462  // The linear solver may not have fit our constraints exactly
463 #ifdef LIBMESH_ENABLE_CONSTRAINTS
465  (*this, &this->get_weighted_sensitivity_solution(),
466  /* homogeneous = */ true);
467 #endif
468 
469  return rval;
470 }
static constexpr Real TOLERANCE
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
NumericVector< Number > * rhs
The system matrix.
virtual std::unique_ptr< NumericVector< T > > clone() const =0
virtual LinearSolver< Number > * get_linear_solver() const
NumericVector< Number > & add_weighted_sensitivity_solution()
Definition: system.C:1199
NumericVector< Number > & get_weighted_sensitivity_solution()
Definition: system.C:1206
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
template class LIBMESH_EXPORT LinearSolver< Number >
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SparseMatrix< Number > * matrix
The system matrix.
const DofMap & get_dof_map() const
Definition: system.h:2417
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:2518

◆ write_header()

void libMesh::System::write_header ( Xdr io,
std::string_view  version,
const bool  write_additional_data 
) const
inherited

Writes the basic data header for this System.

This method implements the output of a System object, embedded in the output of an EquationSystems<T_sys>. This warrants some documentation. The output of this part consists of 5 sections:

for this system

5.) The number of variables in the system (unsigned int)

for each variable in the system

6.) The name of the variable (string)

6.1.) subdomain where the variable lives

7.) Combined in an FEType:

  • The approximation order(s) of the variable (Order Enum, cast to int/s)
  • The finite element family/ies of the variable (FEFamily Enum, cast to int/s)

end variable loop

8.) The number of additional vectors (unsigned int),

for each additional vector in the system object

9.) the name of the additional vector (string)

end system

Definition at line 1120 of file system_io.C.

References libMesh::System::_vector_projections, libMesh::System::_vectors, libMesh::Variable::active_subdomains(), libMesh::Xdr::data(), libMesh::FEType::family, libMesh::System::get_mesh(), libMesh::FEType::inf_map, libMesh::libmesh_assert(), libMesh::make_range(), libMesh::System::n_vars(), libMesh::System::n_vectors(), libMesh::System::name(), libMesh::FEType::order, libMesh::ParallelObject::processor_id(), libMesh::FEType::radial_family, libMesh::FEType::radial_order, libMesh::System::variable(), libMesh::System::variable_name(), libMesh::System::variable_type(), and libMesh::Xdr::writing().

Referenced by libMesh::RBEvaluation::write_out_vectors().

1123 {
1157  libmesh_assert (io.writing());
1158 
1159 
1160  // Only write the header information
1161  // if we are processor 0.
1162  if (this->get_mesh().processor_id() != 0)
1163  return;
1164 
1165  std::string comment;
1166 
1167  // 5.)
1168  // Write the number of variables in the system
1169 
1170  {
1171  // set up the comment
1172  comment = "# No. of Variables in System \"";
1173  comment += this->name();
1174  comment += "\"";
1175 
1176  unsigned int nv = this->n_vars();
1177  io.data (nv, comment);
1178  }
1179 
1180 
1181  for (auto var : make_range(this->n_vars()))
1182  {
1183  // 6.)
1184  // Write the name of the var-th variable
1185  {
1186  // set up the comment
1187  comment = "# Name, Variable No. ";
1188  comment += std::to_string(var);
1189  comment += ", System \"";
1190  comment += this->name();
1191  comment += "\"";
1192 
1193  std::string var_name = this->variable_name(var);
1194  io.data (var_name, comment);
1195  }
1196 
1197  // 6.1.) Variable subdomains
1198  {
1199  // set up the comment
1200  comment = "# Subdomains, Variable \"";
1201  comment += this->variable_name(var);
1202  comment += "\", System \"";
1203  comment += this->name();
1204  comment += "\"";
1205 
1206  const std::set<subdomain_id_type> & domains = this->variable(var).active_subdomains();
1207  std::vector<subdomain_id_type> domain_array;
1208  domain_array.assign(domains.begin(), domains.end());
1209  io.data (domain_array, comment);
1210  }
1211 
1212  // 7.)
1213  // Write the approximation order of the var-th variable
1214  // in this system
1215  {
1216  // set up the comment
1217  comment = "# Approximation Order, Variable \"";
1218  comment += this->variable_name(var);
1219  comment += "\", System \"";
1220  comment += this->name();
1221  comment += "\"";
1222 
1223  int order = static_cast<int>(this->variable_type(var).order);
1224  io.data (order, comment);
1225  }
1226 
1227 
1228 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1229 
1230  // do the same for radial_order
1231  {
1232  comment = "# Radial Approximation Order, Variable \"";
1233  comment += this->variable_name(var);
1234  comment += "\", System \"";
1235  comment += this->name();
1236  comment += "\"";
1237 
1238  int rad_order = static_cast<int>(this->variable_type(var).radial_order);
1239  io.data (rad_order, comment);
1240  }
1241 
1242 #endif
1243 
1244  // Write the Finite Element type of the var-th variable
1245  // in this System
1246  {
1247  // set up the comment
1248  comment = "# FE Family, Variable \"";
1249  comment += this->variable_name(var);
1250  comment += "\", System \"";
1251  comment += this->name();
1252  comment += "\"";
1253 
1254  const FEType & type = this->variable_type(var);
1255  int fam = static_cast<int>(type.family);
1256  io.data (fam, comment);
1257 
1258 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1259 
1260  comment = "# Radial FE Family, Variable \"";
1261  comment += this->variable_name(var);
1262  comment += "\", System \"";
1263  comment += this->name();
1264  comment += "\"";
1265 
1266  int radial_fam = static_cast<int>(type.radial_family);
1267  io.data (radial_fam, comment);
1268 
1269  comment = "# Infinite Mapping Type, Variable \"";
1270  comment += this->variable_name(var);
1271  comment += "\", System \"";
1272  comment += this->name();
1273  comment += "\"";
1274 
1275  int i_map = static_cast<int>(type.inf_map);
1276  io.data (i_map, comment);
1277 #endif
1278  }
1279  } // end of the variable loop
1280 
1281  // 8.)
1282  // Write the number of additional vectors in the System.
1283  // If write_additional_data==false, then write zero for
1284  // the number of additional vectors.
1285  {
1286  {
1287  // set up the comment
1288  comment = "# No. of Additional Vectors, System \"";
1289  comment += this->name();
1290  comment += "\"";
1291 
1292  unsigned int nvecs = write_additional_data ? this->n_vectors () : 0;
1293  io.data (nvecs, comment);
1294  }
1295 
1296  if (write_additional_data)
1297  {
1298  unsigned int cnt=0;
1299  for (const auto & [vec_name, vec] : _vectors)
1300  {
1301  // 9.)
1302  // write the name of the cnt-th additional vector
1303  const std::string dth_vector = std::to_string(cnt++)+"th vector";
1304  comment = "# Name of " + dth_vector;
1305  std::string nonconst_vec_name = vec_name; // Stupid XDR API
1306 
1307  io.data (nonconst_vec_name, comment);
1308  int vec_projection = _vector_projections.at(vec_name);
1309  comment = "# Whether to do projections for " + dth_vector;
1310  io.data (vec_projection, comment);
1311  int vec_type = vec->type();
1312  comment = "# Parallel type of " + dth_vector;
1313  io.data (vec_type, comment);
1314  }
1315  }
1316  }
1317 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
OrderWrapper radial_order
The approximation order in radial direction of the infinite element.
Definition: fe_type.h:263
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
OrderWrapper order
The approximation order of the element (at 0 p-refinement level).
Definition: fe_type.h:203
const MeshBase & get_mesh() const
Definition: system.h:2401
const std::set< subdomain_id_type > & active_subdomains() const
Definition: variable.h:181
unsigned int n_vectors() const
Definition: system.h:2499
libmesh_assert(ctx)
const std::string & variable_name(const unsigned int i) const
Definition: system.C:2674
const FEType & variable_type(const unsigned int i) const
Definition: system.C:2716
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
const std::string & name() const
Definition: system.h:2385
unsigned int n_vars() const
Definition: system.C:2669
processor_id_type processor_id() const
std::map< std::string, bool, std::less<> > _vector_projections
Holds true if a vector by that name should be projected onto a changed grid, false if it should be ze...
Definition: system.h:2266

◆ write_parallel_data()

void libMesh::System::write_parallel_data ( Xdr io,
const bool  write_additional_data 
) const
inherited

Writes additional data, namely vectors, for this System.

This method may safely be called on a distributed-memory mesh. This method will create an individual file for each processor in the simulation where the local solution components for that processor will be stored.

This method implements the output of the vectors contained in this System object, embedded in the output of an EquationSystems<T_sys>.

9.) The global solution vector, re-ordered to be node-major (More on this later.)

for each additional vector in the object

10.) The global additional vector, re-ordered to be node-major (More on this later.)

Note that the actual IO is handled through the Xdr class (to be renamed later?) which provides a uniform interface to both the XDR (eXternal Data Representation) interface and standard ASCII output. Thus this one section of code will read XDR or ASCII files with no changes.

Definition at line 1321 of file system_io.C.

References libMesh::System::_vectors, libMesh::Xdr::data(), libMesh::FEType::family, libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::DofObject::invalid_id, libMesh::libmesh_assert(), libMesh::make_range(), libMesh::ParallelObject::n_processors(), libMesh::System::n_vars(), libMesh::System::name(), libMesh::System::number(), libMesh::ParallelObject::processor_id(), libMesh::SCALAR, libMesh::DofMap::SCALAR_dof_indices(), libMesh::System::solution, libMesh::Variable::type(), libMesh::System::variable(), and libMesh::Xdr::writing().

1323 {
1343  // PerfLog pl("IO Performance",false);
1344  // pl.push("write_parallel_data");
1345  // std::size_t total_written_size = 0;
1346 
1347  std::string comment;
1348 
1349  libmesh_assert (io.writing());
1350 
1351  std::vector<Number> io_buffer; io_buffer.reserve(this->solution->local_size());
1352 
1353  // build the ordered nodes and element maps.
1354  // when writing/reading parallel files we need to iterate
1355  // over our nodes/elements in order of increasing global id().
1356  // however, this is not guaranteed to be ordering we obtain
1357  // by using the node_iterators/element_iterators directly.
1358  // so build a set, sorted by id(), that provides the ordering.
1359  // further, for memory economy build the set but then transfer
1360  // its contents to vectors, which will be sorted.
1361  std::vector<const DofObject *> ordered_nodes, ordered_elements;
1362  {
1363  std::set<const DofObject *, CompareDofObjectsByID>
1364  ordered_nodes_set (this->get_mesh().local_nodes_begin(),
1365  this->get_mesh().local_nodes_end());
1366 
1367  ordered_nodes.insert(ordered_nodes.end(),
1368  ordered_nodes_set.begin(),
1369  ordered_nodes_set.end());
1370  }
1371  {
1372  std::set<const DofObject *, CompareDofObjectsByID>
1373  ordered_elements_set (this->get_mesh().local_elements_begin(),
1374  this->get_mesh().local_elements_end());
1375 
1376  ordered_elements.insert(ordered_elements.end(),
1377  ordered_elements_set.begin(),
1378  ordered_elements_set.end());
1379  }
1380 
1381  const unsigned int sys_num = this->number();
1382  const unsigned int nv = this->n_vars();
1383 
1384  // Loop over each non-SCALAR variable and each node, and write out the value.
1385  for (unsigned int var=0; var<nv; var++)
1386  if (this->variable(var).type().family != SCALAR)
1387  {
1388  // First write the node DOF values
1389  for (const auto & node : ordered_nodes)
1390  for (auto comp : make_range(node->n_comp(sys_num,var)))
1391  {
1392  libmesh_assert_not_equal_to (node->dof_number(sys_num, var, comp),
1394 
1395  io_buffer.push_back((*this->solution)(node->dof_number(sys_num, var, comp)));
1396  }
1397 
1398  // Then write the element DOF values
1399  for (const auto & elem : ordered_elements)
1400  for (auto comp : make_range(elem->n_comp(sys_num,var)))
1401  {
1402  libmesh_assert_not_equal_to (elem->dof_number(sys_num, var, comp),
1404 
1405  io_buffer.push_back((*this->solution)(elem->dof_number(sys_num, var, comp)));
1406  }
1407  }
1408 
1409  // Finally, write the SCALAR data on the last processor
1410  for (auto var : make_range(this->n_vars()))
1411  if (this->variable(var).type().family == SCALAR)
1412  {
1413  if (this->processor_id() == (this->n_processors()-1))
1414  {
1415  const DofMap & dof_map = this->get_dof_map();
1416  std::vector<dof_id_type> SCALAR_dofs;
1417  dof_map.SCALAR_dof_indices(SCALAR_dofs, var);
1418 
1419  for (auto dof : SCALAR_dofs)
1420  io_buffer.push_back((*this->solution)(dof));
1421  }
1422  }
1423 
1424  // 9.)
1425  //
1426  // Actually write the reordered solution vector
1427  // for the ith system to disk
1428 
1429  // set up the comment
1430  {
1431  comment = "# System \"";
1432  comment += this->name();
1433  comment += "\" Solution Vector";
1434  }
1435 
1436  io.data (io_buffer, comment);
1437 
1438  // total_written_size += io_buffer.size();
1439 
1440  // Only write additional vectors if wanted
1441  if (write_additional_data)
1442  {
1443  for (auto & [vec_name, vec] : _vectors)
1444  {
1445  io_buffer.clear();
1446  io_buffer.reserve(vec->local_size());
1447 
1448  // Loop over each non-SCALAR variable and each node, and write out the value.
1449  for (unsigned int var=0; var<nv; var++)
1450  if (this->variable(var).type().family != SCALAR)
1451  {
1452  // First write the node DOF values
1453  for (const auto & node : ordered_nodes)
1454  for (auto comp : make_range(node->n_comp(sys_num,var)))
1455  {
1456  libmesh_assert_not_equal_to (node->dof_number(sys_num, var, comp),
1458 
1459  io_buffer.push_back((*vec)(node->dof_number(sys_num, var, comp)));
1460  }
1461 
1462  // Then write the element DOF values
1463  for (const auto & elem : ordered_elements)
1464  for (auto comp : make_range(elem->n_comp(sys_num,var)))
1465  {
1466  libmesh_assert_not_equal_to (elem->dof_number(sys_num, var, comp),
1468 
1469  io_buffer.push_back((*vec)(elem->dof_number(sys_num, var, comp)));
1470  }
1471  }
1472 
1473  // Finally, write the SCALAR data on the last processor
1474  for (auto var : make_range(this->n_vars()))
1475  if (this->variable(var).type().family == SCALAR)
1476  {
1477  if (this->processor_id() == (this->n_processors()-1))
1478  {
1479  const DofMap & dof_map = this->get_dof_map();
1480  std::vector<dof_id_type> SCALAR_dofs;
1481  dof_map.SCALAR_dof_indices(SCALAR_dofs, var);
1482 
1483  for (auto dof : SCALAR_dofs)
1484  io_buffer.push_back((*vec)(dof));
1485  }
1486  }
1487 
1488  // 10.)
1489  //
1490  // Actually write the reordered additional vector
1491  // for this system to disk
1492 
1493  // set up the comment
1494  {
1495  comment = "# System \"";
1496  comment += this->name();
1497  comment += "\" Additional Vector \"";
1498  comment += vec_name;
1499  comment += "\"";
1500  }
1501 
1502  io.data (io_buffer, comment);
1503 
1504  // total_written_size += io_buffer.size();
1505  }
1506  }
1507 
1508  // const Real
1509  // dt = pl.get_elapsed_time(),
1510  // rate = total_written_size*sizeof(Number)/dt;
1511 
1512  // libMesh::err << "Write " << total_written_size << " \"Number\" values\n"
1513  // << " Elapsed time = " << dt << '\n'
1514  // << " Rate = " << rate/1.e6 << "(MB/sec)\n\n";
1515 
1516  // pl.pop("write_parallel_data");
1517 }
FEFamily family
The type of finite element.
Definition: fe_type.h:228
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
const MeshBase & get_mesh() const
Definition: system.h:2401
processor_id_type n_processors() const
unsigned int number() const
Definition: system.h:2393
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:473
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
const std::string & name() const
Definition: system.h:2385
unsigned int n_vars() const
Definition: system.C:2669
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2417
const FEType & type() const
Definition: variable.h:144

◆ write_serialized_data()

void libMesh::System::write_serialized_data ( Xdr io,
const bool  write_additional_data = true 
) const
inherited

Writes additional data, namely vectors, for this System.

This method may safely be called on a distributed-memory mesh.

This method implements the output of the vectors contained in this System object, embedded in the output of an EquationSystems<T_sys>.

9.) The global solution vector, re-ordered to be node-major (More on this later.)

for each additional vector in the object

10.) The global additional vector, re-ordered to be node-major (More on this later.)

Definition at line 1521 of file system_io.C.

References libMesh::System::_vectors, libMesh::Xdr::comment(), libMesh::System::name(), libMesh::ParallelObject::processor_id(), libMesh::System::solution, and libMesh::System::write_serialized_vector().

Referenced by libMesh::TransientRBConstruction::write_riesz_representors_to_files(), and libMesh::RBConstruction::write_riesz_representors_to_files().

1523 {
1537  parallel_object_only();
1538  std::string comment;
1539 
1540  // PerfLog pl("IO Performance",false);
1541  // pl.push("write_serialized_data");
1542  // std::size_t total_written_size = 0;
1543 
1544  // total_written_size +=
1545  this->write_serialized_vector(io, *this->solution);
1546 
1547  // set up the comment
1548  if (this->processor_id() == 0)
1549  {
1550  comment = "# System \"";
1551  comment += this->name();
1552  comment += "\" Solution Vector";
1553 
1554  io.comment (comment);
1555  }
1556 
1557  // Only write additional vectors if wanted
1558  if (write_additional_data)
1559  {
1560  for (auto & pair : this->_vectors)
1561  {
1562  // total_written_size +=
1563  this->write_serialized_vector(io, *pair.second);
1564 
1565  // set up the comment
1566  if (this->processor_id() == 0)
1567  {
1568  comment = "# System \"";
1569  comment += this->name();
1570  comment += "\" Additional Vector \"";
1571  comment += pair.first;
1572  comment += "\"";
1573  io.comment (comment);
1574  }
1575  }
1576  }
1577 
1578  // const Real
1579  // dt = pl.get_elapsed_time(),
1580  // rate = total_written_size*sizeof(Number)/dt;
1581 
1582  // libMesh::out << "Write " << total_written_size << " \"Number\" values\n"
1583  // << " Elapsed time = " << dt << '\n'
1584  // << " Rate = " << rate/1.e6 << "(MB/sec)\n\n";
1585 
1586  // pl.pop("write_serialized_data");
1587 
1588 
1589 
1590 
1591  // // test the new method
1592  // {
1593  // std::vector<std::string> names;
1594  // std::vector<NumericVector<Number> *> vectors_to_write;
1595 
1596  // names.push_back("Solution Vector");
1597  // vectors_to_write.push_back(this->solution.get());
1598 
1599  // // Only write additional vectors if wanted
1600  // if (write_additional_data)
1601  // {
1602  // std::map<std::string, NumericVector<Number> *>::const_iterator
1603  // pos = _vectors.begin();
1604 
1605  // for (; pos != this->_vectors.end(); ++pos)
1606  // {
1607  // names.push_back("Additional Vector " + pos->first);
1608  // vectors_to_write.push_back(pos->second);
1609  // }
1610  // }
1611 
1612  // total_written_size =
1613  // this->write_serialized_vectors (io, names, vectors_to_write);
1614 
1615  // const Real
1616  // dt2 = pl.get_elapsed_time(),
1617  // rate2 = total_written_size*sizeof(Number)/(dt2-dt);
1618 
1619  // libMesh::out << "Write (new) " << total_written_size << " \"Number\" values\n"
1620  // << " Elapsed time = " << (dt2-dt) << '\n'
1621  // << " Rate = " << rate2/1.e6 << "(MB/sec)\n\n";
1622 
1623  // }
1624 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> > _vectors
Some systems need an arbitrary number of vectors.
Definition: system.h:2260
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
const std::string & name() const
Definition: system.h:2385
processor_id_type processor_id() const
dof_id_type write_serialized_vector(Xdr &io, const NumericVector< Number > &vec) const
Writes a vector for this System.
Definition: system_io.C:1971

◆ write_serialized_vectors()

std::size_t libMesh::System::write_serialized_vectors ( Xdr io,
const std::vector< const NumericVector< Number > *> &  vectors 
) const
inherited

Serialize & write a number of identically distributed vectors.

This method allows for optimization for the multiple vector case by only communicating the metadata once.

Definition at line 2114 of file system_io.C.

References libMesh::Xdr::data(), libMesh::System::get_mesh(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::MeshTools::n_elem(), libMesh::MeshBase::n_elem(), n_nodes, libMesh::MeshBase::n_nodes(), libMesh::System::n_vars(), libMesh::ParallelObject::processor_id(), libMesh::SCALAR, libMesh::System::variable(), libMesh::System::write_SCALAR_dofs(), libMesh::System::write_serialized_blocked_dof_objects(), and libMesh::Xdr::writing().

Referenced by libMesh::RBEvaluation::write_out_vectors().

2116 {
2117  parallel_object_only();
2118 
2119  libmesh_assert (io.writing());
2120 
2121  // Cache these - they are not free!
2122  const dof_id_type
2123  n_nodes = this->get_mesh().n_nodes(),
2124  n_elem = this->get_mesh().n_elem();
2125 
2126  std::size_t written_length = 0;
2127 
2128  if (this->processor_id() == 0)
2129  {
2130  unsigned int
2131  n_vec = cast_int<unsigned int>(vectors.size());
2132  dof_id_type
2133  vec_size = vectors.empty() ? 0 : vectors[0]->size();
2134  // Set the number of vectors
2135  io.data(n_vec, "# number of vectors");
2136  // Set the buffer size
2137  io.data(vec_size, "# vector length");
2138  }
2139 
2140  //---------------------------------
2141  // Collect the values for all nodes
2142  written_length +=
2143  this->write_serialized_blocked_dof_objects (vectors,
2144  n_nodes,
2145  this->get_mesh().local_nodes_begin(),
2146  this->get_mesh().local_nodes_end(),
2147  io);
2148 
2149  //------------------------------------
2150  // Collect the values for all elements
2151  written_length +=
2152  this->write_serialized_blocked_dof_objects (vectors,
2153  n_elem,
2154  this->get_mesh().local_elements_begin(),
2155  this->get_mesh().local_elements_end(),
2156  io);
2157 
2158  //-------------------------------------------
2159  // Finally loop over all the SCALAR variables
2160  for (const NumericVector<Number> * vec : vectors)
2161  for (auto var : make_range(this->n_vars()))
2162  if (this->variable(var).type().family == SCALAR)
2163  {
2164  libmesh_assert_not_equal_to (vec, 0);
2165 
2166  written_length +=
2167  this->write_SCALAR_dofs (*vec, var, io);
2168  }
2169 
2170  return written_length;
2171 }
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.C:2699
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:976
unsigned int write_SCALAR_dofs(const NumericVector< Number > &vec, const unsigned int var, Xdr &io) const
Writes the SCALAR dofs associated with var to the stream io.
Definition: system_io.C:1915
const MeshBase & get_mesh() const
Definition: system.h:2401
const dof_id_type n_nodes
Definition: tecplot_io.C:67
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:173
unsigned int n_vars() const
Definition: system.C:2669
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
template class LIBMESH_EXPORT NumericVector< Number >
virtual dof_id_type n_nodes() const =0
std::size_t write_serialized_blocked_dof_objects(const std::vector< const NumericVector< Number > *> &vecs, const dof_id_type n_objects, const iterator_type begin, const iterator_type end, Xdr &io, const unsigned int var_to_write=libMesh::invalid_uint) const
Writes an output vector to the stream io for a set of DofObjects.
Definition: system_io.C:1629
uint8_t dof_id_type
Definition: id_types.h:67

◆ zero_variable()

void libMesh::System::zero_variable ( NumericVector< Number > &  v,
unsigned int  var_num 
) const
inherited

Zeroes all dofs in v that correspond to variable number var_num.

Definition at line 1450 of file system.C.

References libMesh::System::get_mesh(), mesh, libMesh::System::n_vars(), libMesh::System::number(), and libMesh::NumericVector< T >::set().

1452 {
1453  /* Make sure the call makes sense. */
1454  libmesh_assert_less (var_num, this->n_vars());
1455 
1456  /* Get a reference to the mesh. */
1457  const MeshBase & mesh = this->get_mesh();
1458 
1459  /* Check which system we are. */
1460  const unsigned int sys_num = this->number();
1461 
1462  // Loop over nodes.
1463  for (const auto & node : mesh.local_node_ptr_range())
1464  {
1465  unsigned int n_comp = node->n_comp(sys_num,var_num);
1466  for (unsigned int i=0; i<n_comp; i++)
1467  {
1468  const dof_id_type index = node->dof_number(sys_num,var_num,i);
1469  v.set(index,0.0);
1470  }
1471  }
1472 
1473  // Loop over elements.
1474  for (const auto & elem : mesh.active_local_element_ptr_range())
1475  {
1476  unsigned int n_comp = elem->n_comp(sys_num,var_num);
1477  for (unsigned int i=0; i<n_comp; i++)
1478  {
1479  const dof_id_type index = elem->dof_number(sys_num,var_num,i);
1480  v.set(index,0.0);
1481  }
1482  }
1483 }
MeshBase & mesh
const MeshBase & get_mesh() const
Definition: system.h:2401
unsigned int number() const
Definition: system.h:2393
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
unsigned int n_vars() const
Definition: system.C:2669
uint8_t dof_id_type
Definition: id_types.h:67

Member Data Documentation

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _constrain_in_solver

bool libMesh::DifferentiableSystem::_constrain_in_solver
protectedinherited

_constrain_in_solver defaults to true; if false then we apply constraints only via residual terms in the systems to be solved.

Definition at line 424 of file diff_system.h.

Referenced by libMesh::DifferentiableSystem::get_constrain_in_solver(), and libMesh::DifferentiableSystem::set_constrain_in_solver().

◆ _counts

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

Actually holds the data.

Definition at line 124 of file reference_counter.h.

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

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 143 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

◆ _first_order_vars

std::set<unsigned int> libMesh::DifferentiablePhysics::_first_order_vars
protectedinherited

◆ _mesh_sys

System* libMesh::DifferentiablePhysics::_mesh_sys
protectedinherited

◆ _mesh_x_var

unsigned int libMesh::DifferentiablePhysics::_mesh_x_var
protectedinherited

◆ _mesh_y_var

unsigned int libMesh::DifferentiablePhysics::_mesh_y_var
protectedinherited

◆ _mesh_z_var

unsigned int libMesh::DifferentiablePhysics::_mesh_z_var
protectedinherited

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 137 of file reference_counter.h.

◆ _n_objects

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 132 of file reference_counter.h.

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

◆ _second_order_dot_vars

std::map<unsigned int,unsigned int> libMesh::DifferentiablePhysics::_second_order_dot_vars
protectedinherited

If the user adds any second order variables, then we need to also cache the map to their corresponding dot variable that will be added by this TimeSolver class.

Definition at line 560 of file diff_physics.h.

Referenced by libMesh::DifferentiableSystem::add_second_order_dot_vars(), and libMesh::DifferentiableSystem::get_second_order_dot_var().

◆ _second_order_vars

std::set<unsigned int> libMesh::DifferentiablePhysics::_second_order_vars
protectedinherited

◆ _time_evolving

std::vector<unsigned int> libMesh::DifferentiablePhysics::_time_evolving
protectedinherited

Stores unsigned int to tell us which variables are evolving as first order in time (1), second order in time (2), or are not time evolving (0).

Definition at line 543 of file diff_physics.h.

Referenced by libMesh::DifferentiablePhysics::clear_physics(), libMesh::DifferentiablePhysics::init_physics(), libMesh::DifferentiablePhysics::is_time_evolving(), and libMesh::DifferentiablePhysics::time_evolving().

◆ assemble_before_solve

bool libMesh::System::assemble_before_solve
inherited

Flag which tells the system to whether or not to call the user assembly function during each call to solve().

By default, every call to solve() begins with a call to the user assemble, so this flag is true. (For explicit systems, "solving" the system occurs during the assembly step, so this flag is always true for explicit systems.)

You will only want to set this to false if you need direct control over when the system is assembled, and are willing to track the state of its assembly yourself. An example of such a case is an implicit system with multiple right hand sides. In this instance, a single assembly would likely be followed with multiple calls to solve.

The frequency system and Newmark system have their own versions of this flag, called _finished_assemble, which might be able to be replaced with this more general concept.

Definition at line 1609 of file system.h.

Referenced by libMesh::ImplicitSystem::adjoint_solve(), libMesh::ClawSystem::ClawSystem(), libMesh::ImplicitSystem::disable_cache(), libMesh::System::disable_cache(), main(), libMesh::RBConstruction::RBConstruction(), libMesh::RBSCMConstruction::RBSCMConstruction(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::EigenSystem::solve(), libMesh::CondensedEigenSystem::solve(), and libMesh::LinearImplicitSystem::solve().

◆ assemble_qoi_elements

bool libMesh::DifferentiableQoI::assemble_qoi_elements
inherited

If assemble_qoi_elements is false (it is true by default), the assembly loop for a quantity of interest or its derivatives will skip computing on mesh elements, and will only compute on mesh sides.

Definition at line 101 of file diff_qoi.h.

◆ assemble_qoi_internal_sides

bool libMesh::DifferentiableQoI::assemble_qoi_internal_sides
inherited

If assemble_qoi_internal_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over element sides which do not fall on domain boundaries.

Definition at line 93 of file diff_qoi.h.

◆ assemble_qoi_sides

bool libMesh::DifferentiableQoI::assemble_qoi_sides
inherited

If assemble_qoi_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over domain boundary sides.

To add domain interior sides, also set assemble_qoi_internal_sides to true.

Definition at line 85 of file diff_qoi.h.

Referenced by main().

◆ C_var

unsigned int CoupledSystem::C_var
protected

Definition at line 94 of file coupled_system.h.

◆ compute_internal_sides

bool libMesh::DifferentiablePhysics::compute_internal_sides
inherited

compute_internal_sides is false by default, indicating that side_* computations will only be done on boundary sides.

If compute_internal_sides is true, computations will be done on sides between elements as well.

Definition at line 156 of file diff_physics.h.

◆ computed_QoI

Number CoupledSystem::computed_QoI
protected

Definition at line 104 of file coupled_system.h.

◆ current_local_solution

std::unique_ptr<NumericVector<Number> > libMesh::System::current_local_solution
inherited

All the values I need to compute my contribution to the simulation at hand.

Think of this as the current solution with any ghost values needed from other processors. This vector is necessarily larger than the solution vector in the case of a parallel simulation. The update() member is used to synchronize the contents of the solution and current_local_solution vectors.

Definition at line 1667 of file system.h.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::UniformRefinementEstimator::_estimate_error(), alternative_fe_assembly(), libMesh::VariationalSmootherSystem::assembly(), libMesh::NonlinearImplicitSystem::assembly(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::System::clear(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::System::current_solution(), DMlibMeshFunction(), DMlibMeshJacobian(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), fe_assembly(), libMesh::StaticCondensation::init(), libMesh::System::init_data(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_residual(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::FEMContext::pre_fe_reinit(), libMesh::System::re_update(), libMesh::System::reinit(), libMesh::System::restrict_vectors(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), SolidSystem::save_initial_mesh(), libMesh::RBConstruction::set_context_solution_vec(), setup(), MeshFunctionTest::test_bad_gradient_var_with_out_of_mesh_value(), MeshFunctionTest::test_bad_hessian_var_with_out_of_mesh_value(), MeshFunctionTest::test_subdomain_id_sets(), MeshInputTest::testCopyElementVectorImpl(), libMesh::BoundaryVolumeSolutionTransfer::transfer_boundary_volume(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::TransientRBConstruction::truth_solve(), libMesh::System::update(), libMesh::Nemesis_IO_Helper::write_element_values(), and libMesh::Nemesis_IO_Helper::write_nodal_solution().

◆ deltat

Real libMesh::DifferentiableSystem::deltat
inherited

◆ extra_quadrature_order

int libMesh::System::extra_quadrature_order
inherited

A member int that can be employed to indicate increased or reduced quadrature order.

Note
For FEMSystem users, by default, when calling the user-defined residual functions, the FEMSystem will first set up an appropriate FEType::default_quadrature_rule() object for performing the integration. This rule will integrate elements of order up to 2*p+1 exactly (where p is the sum of the base FEType and local p refinement levels), but if additional (or reduced) quadrature accuracy is desired then this extra_quadrature_order (default 0) will be added.

Definition at line 1640 of file system.h.

Referenced by CurlCurlSystem::init_data(), and set_system_parameters().

◆ fe_reinit_during_postprocess

bool libMesh::FEMSystem::fe_reinit_during_postprocess
inherited

If fe_reinit_during_postprocess is true (it is true by default), FE objects will be reinit()ed with their default quadrature rules.

If false, FE objects will need to be reinit()ed by the user or will be in an undefined state.

Definition at line 176 of file fem_system.h.

◆ linear_solver

std::unique_ptr<LinearSolver<Number> > libMesh::ImplicitSystem::linear_solver
mutableinherited

◆ matrix

SparseMatrix<Number>* libMesh::ImplicitSystem::matrix
inherited

The system matrix.

Implicit systems are characterized by the need to solve the linear system Ax=b. This is the system matrix A.

Public access to this member variable will be deprecated in the future! Use get_system_matrix() instead.

Definition at line 311 of file implicit_system.h.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), add_M_C_K_helmholtz(), libMesh::ImplicitSystem::add_matrices(), libMesh::ImplicitSystem::adjoint_solve(), libMesh::ImplicitSystem::assemble(), assemble_func(), assemble_temperature_jump(), libMesh::FEMSystem::assembly(), libMesh::LinearImplicitSystem::assembly(), libMesh::NonlinearImplicitSystem::assembly(), libMesh::ImplicitSystem::clear(), libMesh::NewmarkSystem::compute_matrix(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), libMesh::ContinuationSystem::continuation_solve(), libMesh::ImplicitSystem::create_static_condensation_system_matrix(), DMCreateMatrix_libMesh(), DMlibMeshJacobian(), libMesh::RBConstruction::enrich_basis_from_rhs_terms(), fill_dirichlet_bc(), libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity(), libMesh::ImplicitSystem::get_system_matrix(), main(), periodic_bc_test_poisson(), libMesh::ImplicitSystem::qoi_parameter_hessian(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::NewtonSolver::solve(), libMesh::PetscDiffSolver::solve(), libMesh::NoxNonlinearSolver< Number >::solve(), libMesh::EigenTimeSolver::solve(), libMesh::FrequencySystem::solve(), libMesh::LinearImplicitSystem::solve(), libMesh::NonlinearImplicitSystem::solve(), libMesh::ClawSystem::solve_conservation_law(), libMesh::ContinuationSystem::solve_tangent(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::TransientRBConstruction::truth_solve(), libMesh::RBConstruction::truth_solve(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

◆ numerical_jacobian_h

Real libMesh::FEMSystem::numerical_jacobian_h
inherited

If calculating numeric jacobians is required, the FEMSystem will perturb each solution vector entry by numerical_jacobian_h when calculating finite differences.

This defaults to the libMesh TOLERANCE but can be set manually.

For ALE terms, the FEMSystem will perturb each mesh point in an element by numerical_jacobian_h * Elem::hmin()

Definition at line 187 of file fem_system.h.

Referenced by libMesh::FEMSystem::numerical_jacobian(), libMesh::FEMSystem::numerical_jacobian_h_for_var(), and set_system_parameters().

◆ p_var

unsigned int CoupledSystem::p_var
protected

Definition at line 94 of file coupled_system.h.

◆ parameter_vector

ParameterVector CoupledSystem::parameter_vector
protected

Definition at line 98 of file coupled_system.h.

◆ parameters

std::vector<Number> CoupledSystem::parameters
protected

Definition at line 91 of file coupled_system.h.

◆ Peclet

Real CoupledSystem::Peclet
protected

Definition at line 101 of file coupled_system.h.

◆ postprocess_sides

bool libMesh::DifferentiableSystem::postprocess_sides
inherited

If postprocess_sides is true (it is false by default), the postprocessing loop will loop over all sides as well as all elements.

Definition at line 326 of file diff_system.h.

Referenced by main().

◆ print_element_jacobians

bool libMesh::DifferentiableSystem::print_element_jacobians
inherited

Set print_element_jacobians to true to print each J_elem contribution.

Definition at line 373 of file diff_system.h.

Referenced by CurlCurlSystem::init_data(), main(), and set_system_parameters().

◆ print_element_residuals

bool libMesh::DifferentiableSystem::print_element_residuals
inherited

Set print_element_residuals to true to print each R_elem contribution.

Definition at line 368 of file diff_system.h.

Referenced by main(), and set_system_parameters().

◆ print_element_solutions

bool libMesh::DifferentiableSystem::print_element_solutions
inherited

Set print_element_solutions to true to print each U_elem input.

Definition at line 363 of file diff_system.h.

Referenced by main().

◆ print_jacobian_norms

bool libMesh::DifferentiableSystem::print_jacobian_norms
inherited

Set print_jacobian_norms to true to print |J| whenever it is assembled.

Definition at line 353 of file diff_system.h.

Referenced by libMesh::FEMSystem::assembly(), main(), and set_system_parameters().

◆ print_jacobians

bool libMesh::DifferentiableSystem::print_jacobians
inherited

Set print_jacobians to true to print J whenever it is assembled.

Definition at line 358 of file diff_system.h.

Referenced by libMesh::FEMSystem::assembly(), CurlCurlSystem::init_data(), main(), and set_system_parameters().

◆ print_residual_norms

bool libMesh::DifferentiableSystem::print_residual_norms
inherited

Set print_residual_norms to true to print |F| whenever it is assembled.

Definition at line 343 of file diff_system.h.

Referenced by libMesh::FEMSystem::assembly(), main(), and set_system_parameters().

◆ print_residuals

bool libMesh::DifferentiableSystem::print_residuals
inherited

Set print_residuals to true to print F whenever it is assembled.

Definition at line 348 of file diff_system.h.

Referenced by libMesh::FEMSystem::assembly(), main(), and set_system_parameters().

◆ print_solution_norms

bool libMesh::DifferentiableSystem::print_solution_norms
inherited

Set print_residual_norms to true to print |U| whenever it is used in an assembly() call.

Definition at line 332 of file diff_system.h.

Referenced by libMesh::FEMSystem::assembly(), main(), and set_system_parameters().

◆ print_solutions

bool libMesh::DifferentiableSystem::print_solutions
inherited

Set print_solutions to true to print U whenever it is used in an assembly() call.

Definition at line 338 of file diff_system.h.

Referenced by libMesh::FEMSystem::assembly(), main(), and set_system_parameters().

◆ rhs

NumericVector<Number>* libMesh::ExplicitSystem::rhs
inherited

The system matrix.

Implicit systems are characterized by the need to solve the linear system Ax=b. This is the right-hand-side vector b.

Definition at line 124 of file explicit_system.h.

Referenced by libMesh::__libmesh_petsc_diff_solver_residual(), add_M_C_K_helmholtz(), libMesh::ExplicitSystem::add_system_rhs(), assemble(), libMesh::ImplicitSystem::assemble(), LinearElasticity::assemble(), assemble_1D(), assemble_biharmonic(), libMesh::AdvectionSystem::assemble_claw_rhs(), assemble_divgrad(), assemble_elasticity(), assemble_ellipticdg(), assemble_func(), assemble_graddiv(), assemble_laplace(), assemble_matrix_and_rhs(), assemble_poisson(), libMesh::ImplicitSystem::assemble_residual_derivatives(), assemble_shell(), assemble_stokes(), assemble_temperature_jump(), assemble_wave(), libMesh::FEMSystem::assembly(), libMesh::VariationalSmootherSystem::assembly(), libMesh::LinearImplicitSystem::assembly(), libMesh::NonlinearImplicitSystem::assembly(), assembly_with_dg_fem_context(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), libMesh::Problem_Interface::computeF(), libMesh::ContinuationSystem::continuation_solve(), DMlibMeshFunction(), libMesh::RBConstruction::enrich_basis_from_rhs_terms(), fill_dirichlet_bc(), libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity(), libMesh::NewtonSolver::line_search(), periodic_bc_test_poisson(), HeatSystem::perturb_accumulate_residuals(), libMesh::ImplicitSystem::qoi_parameter_hessian(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), libMesh::NewtonSolver::solve(), libMesh::PetscDiffSolver::solve(), libMesh::FrequencySystem::solve(), libMesh::LinearImplicitSystem::solve(), libMesh::NonlinearImplicitSystem::solve(), libMesh::ContinuationSystem::solve_tangent(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::TransientRBConstruction::truth_solve(), libMesh::RBConstruction::truth_solve(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::NewmarkSystem::update_rhs(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

◆ solution

std::unique_ptr<NumericVector<Number> > libMesh::System::solution
inherited

Data structure to hold solution values.

Definition at line 1655 of file system.h.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::NewmarkSolver::advance_timestep(), libMesh::AdaptiveTimeSolver::advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), libMesh::ContinuationSystem::apply_predictor(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::FEMSystem::assembly(), libMesh::VariationalSmootherSystem::assembly(), libMesh::LinearImplicitSystem::assembly(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::RBConstruction::check_if_zero_truth_solve(), libMesh::System::clear(), libMesh::System::compare(), compute_enriched_soln(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::NewmarkSolver::compute_initial_accel(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ContinuationSystem::continuation_solve(), libMesh::Nemesis_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::GMVIO::copy_nodal_solution(), libMesh::Nemesis_IO::copy_nodal_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::Nemesis_IO::copy_scalar_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), create_wrapped_function(), DMCreateGlobalVector_libMesh(), DMlibMeshFunction(), DMlibMeshJacobian(), libMesh::UnsteadySolver::du(), libMesh::RBConstruction::enrich_RB_space(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::SmoothnessEstimator::estimate_smoothness(), libMesh::RBSCMConstruction::evaluate_stability_constant(), libMesh::EigenSystem::get_eigenpair(), libMesh::CondensedEigenSystem::get_eigenpair(), LinearElasticityWithContact::get_least_and_max_gap_function(), libMesh::VariationalSmootherSystem::init_data(), libMesh::System::init_data(), libMesh::ContinuationSystem::initialize_tangent(), libMesh::TransientRBConstruction::initialize_truth(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_residual(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::RBConstruction::load_basis_function(), libMesh::TransientRBConstruction::load_rb_solution(), libMesh::RBConstruction::load_rb_solution(), main(), libMesh::DofMap::max_constraint_error(), libMesh::FEMSystem::mesh_position_get(), libMesh::ErrorVector::plot_error(), libMesh::RBConstruction::print_basis_function_orthogonality(), libMesh::InterMeshProjection::project_system_vectors(), libMesh::ImplicitSystem::qoi_parameter_hessian(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), libMesh::System::re_update(), libMesh::System::read_parallel_data(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::System::read_serialized_data(), MeshFunctionTest::read_variable_info_from_output_data(), libMesh::System::reinit(), libMesh::System::restrict_vectors(), libMesh::MemoryHistoryData::retrieve_vectors(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), libMesh::ContinuationSystem::save_current_solution(), libMesh::TransientRBConstruction::set_error_temporal_data(), setup(), WriteVecAndScalar::setupTests(), libMesh::TwostepTimeSolver::solve(), libMesh::NewtonSolver::solve(), libMesh::PetscDiffSolver::solve(), libMesh::FrequencySystem::solve(), libMesh::LinearImplicitSystem::solve(), libMesh::NonlinearImplicitSystem::solve(), libMesh::ClawSystem::solve_conservation_law(), libMesh::RBConstruction::solve_for_matrix_and_rhs(), libMesh::ContinuationSystem::solve_tangent(), libMesh::MemoryHistoryData::store_vectors(), ConstraintOperatorTest::test1DCoarseningOperator(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), ProjectSolutionTest::test_partial_project_solution(), SystemsTest::testBoundaryProjectCube(), ConstraintOperatorTest::testCoreform(), SystemsTest::testDofCouplingWithVarGroups(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), SystemsTest::testPostInitAddVector(), SystemsTest::testProjectCubeWithMeshFunction(), MeshInputTest::testProjectionRegression(), WriteVecAndScalar::testSolution(), libMesh::RBConstruction::train_reduced_basis_with_POD(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::DirectSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::BoundaryVolumeSolutionTransfer::transfer_boundary_volume(), libMesh::BoundaryVolumeSolutionTransfer::transfer_volume_boundary(), libMesh::TransientRBConstruction::truth_solve(), libMesh::RBConstruction::truth_solve(), libMesh::System::update(), update_current_local_solution(), libMesh::System::update_global_solution(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::ContinuationSystem::update_solution(), libMesh::NewmarkSystem::update_u_v_a(), libMesh::DTKAdapter::update_variable_values(), libMesh::System::write_parallel_data(), libMesh::TransientRBConstruction::write_riesz_representors_to_files(), libMesh::RBConstruction::write_riesz_representors_to_files(), and libMesh::System::write_serialized_data().

◆ time

Real libMesh::System::time
inherited

For time-dependent problems, this is the time t at the beginning of the current timestep.

Note
For DifferentiableSystem users: do not access this time during an assembly! Use the DiffContext::time value instead to get correct results.

Definition at line 1677 of file system.h.

Referenced by libMesh::AdaptiveTimeSolver::adjoint_advance_timestep(), libMesh::UnsteadySolver::adjoint_advance_timestep(), libMesh::TwostepTimeSolver::adjoint_solve(), libMesh::AdaptiveTimeSolver::advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SubProjector::construct_projection(), HeatSystem::element_qoi(), fill_dirichlet_bc(), libMesh::ExactErrorEstimator::find_squared_element_error(), initialize(), libMesh::Euler2Solver::integrate_adjoint_refinement_error_estimate(), libMesh::EulerSolver::integrate_adjoint_refinement_error_estimate(), libMesh::UnsteadySolver::integrate_adjoint_sensitivity(), libMesh::Euler2Solver::integrate_qoi_timestep(), libMesh::EulerSolver::integrate_qoi_timestep(), main(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectVertices::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectEdges::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectSides::operator()(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::ProjectInteriors::operator()(), libMesh::System::reinit_constraints(), libMesh::UnsteadySolver::retrieve_timestep(), and libMesh::TwostepTimeSolver::solve().

◆ time_solver

std::unique_ptr<TimeSolver> libMesh::DifferentiableSystem::time_solver
inherited

◆ u_var

unsigned int CoupledSystem::u_var
protected

Definition at line 94 of file coupled_system.h.

◆ use_fixed_solution

bool libMesh::System::use_fixed_solution
inherited

A boolean to be set to true by systems using elem_fixed_solution, for optional use by e.g.

stabilized methods. False by default.

Note
For FEMSystem users, if this variable is set to true, it must be before init_data() is called.

Definition at line 1625 of file system.h.

Referenced by libMesh::EulerSolver::_general_residual(), libMesh::Euler2Solver::_general_residual(), libMesh::SteadySolver::_general_residual(), libMesh::NewmarkSolver::_general_residual(), libMesh::DifferentiableSystem::clear(), libMesh::DiffContext::DiffContext(), and libMesh::FEMContext::pre_fe_reinit().

◆ v_var

unsigned int CoupledSystem::v_var
protected

Definition at line 94 of file coupled_system.h.

◆ verify_analytic_jacobians

Real libMesh::FEMSystem::verify_analytic_jacobians
inherited

If verify_analytic_jacobian is equal to zero (as it is by default), no numeric jacobians will be calculated unless an overridden element_time_derivative(), element_constraint(), side_time_derivative(), or side_constraint() function cannot provide an analytic jacobian upon request.

If verify_analytic_jacobian is equal to the positive value tol, then any time a full analytic element jacobian can be calculated it will be tested against a numerical jacobian on the same element, and the program will abort if the relative error (in matrix l1 norms) exceeds tol.

Definition at line 215 of file fem_system.h.

Referenced by libMesh::FEMSystem::assembly(), CurlCurlSystem::init_data(), and set_system_parameters().

◆ zero_out_matrix_and_rhs

bool libMesh::ImplicitSystem::zero_out_matrix_and_rhs
inherited

By default, the system will zero out the matrix and the right hand side.

If this flag is false, it is the responsibility of the client code to take care of setting these to zero before assembly begins

Definition at line 318 of file implicit_system.h.

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


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