libMesh::OptimizationSystem Class Reference

#include <optimization_system.h>

Inheritance diagram for libMesh::OptimizationSystem:

Classes

class  ComputeEqualityConstraints
 
class  ComputeEqualityConstraintsJacobian
 
class  ComputeGradient
 
class  ComputeHessian
 
class  ComputeInequalityConstraints
 
class  ComputeInequalityConstraintsJacobian
 
class  ComputeLowerAndUpperBounds
 
class  ComputeObjective
 

Public Types

typedef OptimizationSystem sys_type
 
typedef ImplicitSystem Parent
 
typedef std::map< std::string, SparseMatrix< Number > * >::iterator matrices_iterator
 
typedef std::map< std::string, SparseMatrix< Number > * >::const_iterator const_matrices_iterator
 
typedef std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
 
typedef std::map< std::string, NumericVector< Number > * >::const_iterator const_vectors_iterator
 

Public Member Functions

 OptimizationSystem (EquationSystems &es, const std::string &name, const unsigned int number)
 
virtual ~OptimizationSystem ()
 
sys_typesystem ()
 
virtual void clear () libmesh_override
 
virtual void init_data () libmesh_override
 
virtual void reinit () libmesh_override
 
virtual void solve () libmesh_override
 
void initialize_equality_constraints_storage (const std::vector< std::set< numeric_index_type > > &constraint_jac_sparsity)
 
void initialize_inequality_constraints_storage (const std::vector< std::set< numeric_index_type > > &constraint_jac_sparsity)
 
virtual std::string system_type () const libmesh_override
 
virtual void assemble () libmesh_override
 
virtual void disable_cache () libmesh_override
 
virtual LinearSolver< Number > * get_linear_solver () const
 
virtual std::pair< unsigned int, Realget_linear_solve_parameters () const
 
virtual void release_linear_solver (LinearSolver< Number > *) const
 
virtual void assembly (bool, bool, bool=false, bool=false)
 
virtual void assemble_residual_derivatives (const ParameterVector &parameters) libmesh_override
 
virtual std::pair< unsigned int, Realsensitivity_solve (const ParameterVector &parameters) libmesh_override
 
virtual std::pair< unsigned int, Realweighted_sensitivity_solve (const ParameterVector &parameters, const ParameterVector &weights) libmesh_override
 
virtual std::pair< unsigned int, Realadjoint_solve (const QoISet &qoi_indices=QoISet()) libmesh_override
 
virtual std::pair< unsigned int, Realweighted_sensitivity_adjoint_solve (const ParameterVector &parameters, const ParameterVector &weights, const QoISet &qoi_indices=QoISet()) libmesh_override
 
virtual void adjoint_qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) libmesh_override
 
virtual void forward_qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities) libmesh_override
 
virtual void qoi_parameter_hessian (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &hessian) libmesh_override
 
virtual void qoi_parameter_hessian_vector_product (const QoISet &qoi_indices, const ParameterVector &parameters, const ParameterVector &vector, SensitivityData &product) libmesh_override
 
SparseMatrix< Number > & add_matrix (const std::string &mat_name)
 
void remove_matrix (const std::string &mat_name)
 
bool have_matrix (const std::string &mat_name) const
 
const SparseMatrix< Number > * request_matrix (const std::string &mat_name) const
 
SparseMatrix< Number > * request_matrix (const std::string &mat_name)
 
const SparseMatrix< Number > & get_matrix (const std::string &mat_name) const
 
SparseMatrix< Number > & get_matrix (const std::string &mat_name)
 
virtual unsigned int n_matrices () const libmesh_override
 
virtual void assemble_qoi (const QoISet &qoi_indices=QoISet()) libmesh_override
 
virtual void assemble_qoi_derivative (const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) libmesh_override
 
void init ()
 
virtual void reinit_constraints ()
 
bool is_initialized ()
 
virtual void update ()
 
virtual void restrict_solve_to (const SystemSubset *subset, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO)
 
bool is_adjoint_already_solved () const
 
void set_adjoint_already_solved (bool setting)
 
virtual void qoi_parameter_sensitivity (const QoISet &qoi_indices, const ParameterVector &parameters, SensitivityData &sensitivities)
 
virtual bool compare (const System &other_system, const Real threshold, const bool verbose) const
 
const std::string & name () const
 
void project_solution (FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr) const
 
void project_solution (FEMFunctionBase< Number > *f, FEMFunctionBase< Gradient > *g=libmesh_nullptr) const
 
void project_solution (Number fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), Gradient gptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), const Parameters &parameters) const
 
void project_vector (NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
 
void project_vector (NumericVector< Number > &new_vector, FEMFunctionBase< Number > *f, FEMFunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
 
void project_vector (Number fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), Gradient gptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), const Parameters &parameters, NumericVector< Number > &new_vector, int is_adjoint=-1) const
 
void boundary_project_solution (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr)
 
void boundary_project_solution (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, Number fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), Gradient gptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), const Parameters &parameters)
 
void boundary_project_vector (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
 
void boundary_project_vector (const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, Number fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), Gradient gptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name), const Parameters &parameters, NumericVector< Number > &new_vector, int is_adjoint=-1) const
 
unsigned int number () const
 
void update_global_solution (std::vector< Number > &global_soln) const
 
void update_global_solution (std::vector< Number > &global_soln, const processor_id_type dest_proc) const
 
const MeshBaseget_mesh () const
 
MeshBaseget_mesh ()
 
const DofMapget_dof_map () const
 
DofMapget_dof_map ()
 
const EquationSystemsget_equation_systems () const
 
EquationSystemsget_equation_systems ()
 
bool active () const
 
void activate ()
 
void deactivate ()
 
void set_basic_system_only ()
 
vectors_iterator vectors_begin ()
 
const_vectors_iterator vectors_begin () const
 
vectors_iterator vectors_end ()
 
const_vectors_iterator vectors_end () const
 
NumericVector< Number > & add_vector (const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
 
void remove_vector (const std::string &vec_name)
 
bool & project_solution_on_reinit (void)
 
bool have_vector (const std::string &vec_name) const
 
const NumericVector< Number > * request_vector (const std::string &vec_name) const
 
NumericVector< Number > * request_vector (const std::string &vec_name)
 
const NumericVector< Number > * request_vector (const unsigned int vec_num) const
 
NumericVector< Number > * request_vector (const unsigned int vec_num)
 
const NumericVector< Number > & get_vector (const std::string &vec_name) const
 
NumericVector< Number > & get_vector (const std::string &vec_name)
 
const NumericVector< Number > & get_vector (const unsigned int vec_num) const
 
NumericVector< Number > & get_vector (const unsigned int vec_num)
 
const std::string & vector_name (const unsigned int vec_num) const
 
const std::string & vector_name (const NumericVector< Number > &vec_reference) const
 
void set_vector_as_adjoint (const std::string &vec_name, int qoi_num)
 
int vector_is_adjoint (const std::string &vec_name) const
 
void set_vector_preservation (const std::string &vec_name, bool preserve)
 
bool vector_preservation (const std::string &vec_name) const
 
NumericVector< Number > & add_adjoint_solution (unsigned int i=0)
 
NumericVector< Number > & get_adjoint_solution (unsigned int i=0)
 
const NumericVector< Number > & get_adjoint_solution (unsigned int i=0) const
 
NumericVector< Number > & add_sensitivity_solution (unsigned int i=0)
 
NumericVector< Number > & get_sensitivity_solution (unsigned int i=0)
 
const NumericVector< Number > & get_sensitivity_solution (unsigned int i=0) const
 
NumericVector< Number > & add_weighted_sensitivity_adjoint_solution (unsigned int i=0)
 
NumericVector< Number > & get_weighted_sensitivity_adjoint_solution (unsigned int i=0)
 
const NumericVector< Number > & get_weighted_sensitivity_adjoint_solution (unsigned int i=0) const
 
NumericVector< Number > & add_weighted_sensitivity_solution ()
 
NumericVector< Number > & get_weighted_sensitivity_solution ()
 
const NumericVector< Number > & get_weighted_sensitivity_solution () const
 
NumericVector< Number > & add_adjoint_rhs (unsigned int i=0)
 
NumericVector< Number > & get_adjoint_rhs (unsigned int i=0)
 
const NumericVector< Number > & get_adjoint_rhs (unsigned int i=0) const
 
NumericVector< Number > & add_sensitivity_rhs (unsigned int i=0)
 
NumericVector< Number > & get_sensitivity_rhs (unsigned int i=0)
 
const NumericVector< Number > & get_sensitivity_rhs (unsigned int i=0) const
 
unsigned int n_vectors () const
 
unsigned int n_vars () const
 
unsigned int n_variable_groups () const
 
unsigned int n_components () const
 
dof_id_type n_dofs () const
 
dof_id_type n_active_dofs () const
 
dof_id_type n_constrained_dofs () const
 
dof_id_type n_local_constrained_dofs () const
 
dof_id_type n_local_dofs () const
 
unsigned int add_variable (const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
 
unsigned int add_variable (const std::string &var, const Order order=FIRST, const FEFamily=LAGRANGE, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
 
unsigned int add_variables (const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
 
unsigned int add_variables (const std::vector< std::string > &vars, const Order order=FIRST, const FEFamily=LAGRANGE, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
 
const Variablevariable (unsigned int var) const
 
const VariableGroupvariable_group (unsigned int vg) const
 
bool has_variable (const std::string &var) const
 
const std::string & variable_name (const unsigned int i) const
 
unsigned short int variable_number (const std::string &var) const
 
void get_all_variable_numbers (std::vector< unsigned int > &all_variable_numbers) const
 
unsigned int variable_scalar_number (const std::string &var, unsigned int component) const
 
unsigned int variable_scalar_number (unsigned int var_num, unsigned int component) const
 
const FETypevariable_type (const unsigned int i) const
 
const FETypevariable_type (const std::string &var) const
 
bool identify_variable_groups () const
 
void identify_variable_groups (const bool)
 
Real calculate_norm (const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=libmesh_nullptr) const
 
Real calculate_norm (const NumericVector< Number > &v, const SystemNorm &norm, std::set< unsigned int > *skip_dimensions=libmesh_nullptr) const
 
void read_header (Xdr &io, const std::string &version, const bool read_header=true, const bool read_additional_data=true, const bool read_legacy_format=false)
 
void read_legacy_data (Xdr &io, const bool read_additional_data=true)
 
template<typename ValType >
void read_serialized_data (Xdr &io, const bool read_additional_data=true)
 
void read_serialized_data (Xdr &io, const bool read_additional_data=true)
 
template<typename InValType >
std::size_t read_serialized_vectors (Xdr &io, const std::vector< NumericVector< Number > * > &vectors) const
 
std::size_t read_serialized_vectors (Xdr &io, const std::vector< NumericVector< Number > * > &vectors) const
 
template<typename InValType >
void read_parallel_data (Xdr &io, const bool read_additional_data)
 
void read_parallel_data (Xdr &io, const bool read_additional_data)
 
void write_header (Xdr &io, const std::string &version, const bool write_additional_data) const
 
void write_serialized_data (Xdr &io, const bool write_additional_data=true) const
 
std::size_t write_serialized_vectors (Xdr &io, const std::vector< const NumericVector< Number > * > &vectors) const
 
void write_parallel_data (Xdr &io, const bool write_additional_data) const
 
std::string get_info () const
 
void attach_init_function (void fptr(EquationSystems &es, const std::string &name))
 
void attach_init_object (Initialization &init)
 
void attach_assemble_function (void fptr(EquationSystems &es, const std::string &name))
 
void attach_assemble_object (Assembly &assemble)
 
void attach_constraint_function (void fptr(EquationSystems &es, const std::string &name))
 
void attach_constraint_object (Constraint &constrain)
 
void attach_QOI_function (void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices))
 
void attach_QOI_object (QOI &qoi)
 
void attach_QOI_derivative (void fptr(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints))
 
void attach_QOI_derivative_object (QOIDerivative &qoi_derivative)
 
virtual void user_initialization ()
 
virtual void user_assembly ()
 
virtual void user_constrain ()
 
virtual void user_QOI (const QoISet &qoi_indices)
 
virtual void user_QOI_derivative (const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
 
virtual void re_update ()
 
virtual void restrict_vectors ()
 
virtual void prolong_vectors ()
 
Number current_solution (const dof_id_type global_dof_number) const
 
Number point_value (unsigned int var, const Point &p, const bool insist_on_success=true) const
 
Number point_value (unsigned int var, const Point &p, const Elem &e) const
 
Number point_value (unsigned int var, const Point &p, const Elem *e) const
 
Gradient point_gradient (unsigned int var, const Point &p, const bool insist_on_success=true) const
 
Gradient point_gradient (unsigned int var, const Point &p, const Elem &e) const
 
Gradient point_gradient (unsigned int var, const Point &p, const Elem *e) const
 
Tensor point_hessian (unsigned int var, const Point &p, const bool insist_on_success=true) const
 
Tensor point_hessian (unsigned int var, const Point &p, const Elem &e) const
 
Tensor point_hessian (unsigned int var, const Point &p, const Elem *e) const
 
void local_dof_indices (const unsigned int var, std::set< dof_id_type > &var_indices) const
 
void zero_variable (NumericVector< Number > &v, unsigned int var_num) const
 
bool & hide_output ()
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

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

Public Attributes

UniquePtr< OptimizationSolver< Number > > optimization_solver
 
UniquePtr< NumericVector< Number > > C_eq
 
UniquePtr< SparseMatrix< Number > > C_eq_jac
 
UniquePtr< NumericVector< Number > > C_ineq
 
UniquePtr< SparseMatrix< Number > > C_ineq_jac
 
UniquePtr< NumericVector< Number > > lambda_eq
 
UniquePtr< NumericVector< Number > > lambda_ineq
 
std::vector< std::set< numeric_index_type > > eq_constraint_jac_sparsity
 
std::vector< std::set< numeric_index_type > > ineq_constraint_jac_sparsity
 
SparseMatrix< Number > * matrix
 
bool zero_out_matrix_and_rhs
 
NumericVector< Number > * rhs
 
bool assemble_before_solve
 
bool use_fixed_solution
 
int extra_quadrature_order
 
UniquePtr< NumericVector< Number > > solution
 
UniquePtr< NumericVector< Number > > current_local_solution
 
Real time
 
std::vector< Numberqoi
 

Protected Types

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

Protected Member Functions

virtual void init_matrices ()
 
void project_vector (NumericVector< Number > &, int is_adjoint=-1) const
 
void project_vector (const NumericVector< Number > &, NumericVector< Number > &, int is_adjoint=-1) const
 
void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

const Parallel::Communicator_communicator
 

Static Protected Attributes

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

Detailed Description

This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for optimization problems.

Author
David Knezevic
Date
2015

Definition at line 43 of file optimization_system.h.

Member Typedef Documentation

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

Definition at line 283 of file implicit_system.h.

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

Definition at line 749 of file system.h.

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

Data structure to log the information. The log is identified by the class name.

Definition at line 119 of file reference_counter.h.

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

Matrix iterator typedefs.

Definition at line 282 of file implicit_system.h.

The type of the parent.

Definition at line 68 of file optimization_system.h.

The type of system.

Definition at line 63 of file optimization_system.h.

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

Vector iterator typedefs.

Definition at line 748 of file system.h.

Constructor & Destructor Documentation

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

Constructor. Optionally initializes required data structures.

Definition at line 36 of file optimization_system.C.

38  :
39 
40  Parent(es, name_in, number_in),
48 {
49 }
UniquePtr< NumericVector< Number > > lambda_ineq
static UniquePtr< OptimizationSolver< T > > build(sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
UniquePtr< OptimizationSolver< Number > > optimization_solver
static UniquePtr< SparseMatrix< Number > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
UniquePtr< NumericVector< Number > > lambda_eq
static UniquePtr< NumericVector< Number > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
UniquePtr< SparseMatrix< Number > > C_eq_jac
const Parallel::Communicator & comm() const
UniquePtr< NumericVector< Number > > C_eq
UniquePtr< SparseMatrix< Number > > C_ineq_jac
UniquePtr< NumericVector< Number > > C_ineq
libMesh::OptimizationSystem::~OptimizationSystem ( )
virtual

Destructor.

Definition at line 53 of file optimization_system.C.

References clear().

54 {
55  // Clear data
56  this->clear();
57 }
virtual void clear() libmesh_override

Member Function Documentation

void libMesh::System::activate ( )
inlineinherited

Activates the system. Only active systems are solved.

Definition at line 2052 of file system.h.

References libMesh::System::_active.

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

2053 {
2054  _active = true;
2055 }
bool libMesh::System::active ( ) const
inlineinherited
Returns
true if the system is active, false otherwise. An active system will be solved.

Definition at line 2044 of file system.h.

References libMesh::System::_active.

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

2045 {
2046  return _active;
2047 }
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 1039 of file system.C.

References libMesh::System::add_vector().

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

1040 {
1041  std::ostringstream adjoint_rhs_name;
1042  adjoint_rhs_name << "adjoint_rhs" << i;
1043 
1044  return this->add_vector(adjoint_rhs_name.str(), false);
1045 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:679
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 975 of file system.C.

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

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

976 {
977  std::ostringstream adjoint_name;
978  adjoint_name << "adjoint_solution" << i;
979 
980  NumericVector<Number> & returnval = this->add_vector(adjoint_name.str());
981  this->set_vector_as_adjoint(adjoint_name.str(), i);
982  return returnval;
983 }
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Definition: system.C:903
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:679
SparseMatrix< Number > & libMesh::ImplicitSystem::add_matrix ( const std::string &  mat_name)
inherited

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

Definition at line 210 of file implicit_system.C.

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

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

211 {
212  // only add matrices before initializing...
213  if (!_can_add_matrices)
214  libmesh_error_msg("ERROR: Too late. Cannot add matrices to the system after initialization"
215  << "\n any more. You should have done this earlier.");
216 
217  // Return the matrix if it is already there.
218  if (this->have_matrix(mat_name))
219  return *(_matrices[mat_name]);
220 
221  // Otherwise build the matrix and return it.
222  SparseMatrix<Number> * buf = SparseMatrix<Number>::build(this->comm()).release();
223  _matrices.insert (std::make_pair (mat_name, buf));
224 
225  return *buf;
226 }
static UniquePtr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
std::map< std::string, SparseMatrix< Number > * > _matrices
bool have_matrix(const std::string &mat_name) const
const Parallel::Communicator & comm() const
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 1069 of file system.C.

References libMesh::System::add_vector().

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

1070 {
1071  std::ostringstream sensitivity_rhs_name;
1072  sensitivity_rhs_name << "sensitivity_rhs" << i;
1073 
1074  return this->add_vector(sensitivity_rhs_name.str(), false);
1075 }
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:679
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 924 of file system.C.

References libMesh::System::add_vector().

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

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

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

Returns
The index number for the new variable.

Definition at line 1099 of file system.C.

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

Referenced by libMesh::DifferentiableSystem::add_second_order_dot_vars(), libMesh::System::add_variable(), libMesh::ErrorVector::plot_error(), and libMesh::System::project_solution_on_reinit().

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

Adds the variable var to the list of variables for this system. Same as before, but assumes LAGRANGE as default value for FEType.family.

Definition at line 1177 of file system.C.

References libMesh::System::add_variable().

1181 {
1182  return this->add_variable(var,
1183  FEType(order, family),
1184  active_subdomains);
1185 }
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Definition: system.C:1099
unsigned int libMesh::System::add_variables ( const std::vector< std::string > &  vars,
const FEType type,
const std::set< subdomain_id_type > *const  active_subdomains = libmesh_nullptr 
)
inherited

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

Returns
The index number for the new variable.

Definition at line 1189 of file system.C.

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

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

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

Adds the variable var to the list of variables for this system. Same as before, but assumes LAGRANGE as default value for FEType.family.

Definition at line 1242 of file system.C.

References libMesh::System::add_variables().

1246 {
1247  return this->add_variables(vars,
1248  FEType(order, family),
1249  active_subdomains);
1250 }
unsigned int add_variables(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Definition: system.C:1189
NumericVector< Number > & libMesh::System::add_vector ( const std::string &  vec_name,
const bool  projections = true,
const ParallelType  type = PARALLEL 
)
inherited

Adds the additional vector vec_name to this system. All the additional vectors are similarly distributed, like the solution, and initialized to zero.

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

Definition at line 679 of file system.C.

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

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

682 {
683  // Return the vector if it is already there.
684  if (this->have_vector(vec_name))
685  return *(_vectors[vec_name]);
686 
687  // Otherwise build the vector
688  NumericVector<Number> * buf = NumericVector<Number>::build(this->comm()).release();
689  _vectors.insert (std::make_pair (vec_name, buf));
690  _vector_projections.insert (std::make_pair (vec_name, projections));
691 
692  _vector_types.insert (std::make_pair (vec_name, type));
693 
694  // Vectors are primal by default
695  _vector_is_adjoint.insert (std::make_pair (vec_name, -1));
696 
697  // Initialize it if necessary
698  if (_is_initialized)
699  {
700  if (type == GHOSTED)
701  {
702 #ifdef LIBMESH_ENABLE_GHOSTED
703  buf->init (this->n_dofs(), this->n_local_dofs(),
704  _dof_map->get_send_list(), false,
705  GHOSTED);
706 #else
707  libmesh_error_msg("Cannot initialize ghosted vectors when they are not enabled.");
708 #endif
709  }
710  else
711  buf->init (this->n_dofs(), this->n_local_dofs(), false, type);
712  }
713 
714  return *buf;
715 }
std::map< std::string, ParallelType > _vector_types
Definition: system.h:1931
bool _is_initialized
Definition: system.h:1950
UniquePtr< DofMap > _dof_map
Definition: system.h:1863
static UniquePtr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
bool have_vector(const std::string &vec_name) const
Definition: system.h:2204
std::map< std::string, int > _vector_is_adjoint
Definition: system.h:1926
dof_id_type n_local_dofs() const
Definition: system.C:183
std::map< std::string, NumericVector< Number > * > _vectors
Definition: system.h:1914
const Parallel::Communicator & comm() const
std::map< std::string, bool > _vector_projections
Definition: system.h:1920
dof_id_type n_dofs() const
Definition: system.C:146
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 1007 of file system.C.

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

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

1008 {
1009  std::ostringstream adjoint_name;
1010  adjoint_name << "weighted_sensitivity_adjoint_solution" << i;
1011 
1012  NumericVector<Number> & returnval = this->add_vector(adjoint_name.str());
1013  this->set_vector_as_adjoint(adjoint_name.str(), i);
1014  return returnval;
1015 }
void set_vector_as_adjoint(const std::string &vec_name, int qoi_num)
Definition: system.C:903
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:679
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 954 of file system.C.

References libMesh::System::add_vector().

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

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

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

Uses adjoint_solve() and the adjoint sensitivity method.

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

Reimplemented from libMesh::System.

Definition at line 708 of file implicit_system.C.

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

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

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

Assembles & solves the linear system (dR/du)^T*z = dq/du, for those quantities of interest q specified by qoi_indices.

Leave qoi_indices empty to solve all adjoint problems.

Returns
A pair with the total number of linear iterations performed and the (sum of the) final residual norms

Reimplemented from libMesh::System.

Reimplemented in libMesh::DifferentiableSystem.

Definition at line 379 of file implicit_system.C.

References libMesh::System::add_adjoint_solution(), libMesh::LinearSolver< T >::adjoint_solve(), libMesh::System::assemble_before_solve, libMesh::ExplicitSystem::assemble_qoi_derivative(), libMesh::ImplicitSystem::assembly(), libMesh::DofMap::enforce_adjoint_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::QoISet::has_index(), libMesh::ImplicitSystem::matrix, libMesh::System::qoi, and libMesh::ImplicitSystem::release_linear_solver().

Referenced by libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity(), libMesh::DifferentiableSystem::adjoint_solve(), libMesh::ImplicitSystem::assembly(), libMesh::ImplicitSystem::qoi_parameter_hessian(), and libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product().

380 {
381  // Log how long the linear solve takes.
382  LOG_SCOPE("adjoint_solve()", "ImplicitSystem");
383 
384  if (this->assemble_before_solve)
385  // Assemble the linear system
386  this->assembly (/* get_residual = */ false,
387  /* get_jacobian = */ true);
388 
389  // The adjoint problem is linear
390  LinearSolver<Number> * linear_solver = this->get_linear_solver();
391 
392  // Reset and build the RHS from the QOI derivative
393  this->assemble_qoi_derivative(qoi_indices,
394  /* include_liftfunc = */ false,
395  /* apply_constraints = */ true);
396 
397  // Our iteration counts and residuals will be sums of the individual
398  // results
399  std::pair<unsigned int, Real> solver_params =
401  std::pair<unsigned int, Real> totalrval = std::make_pair(0,0.0);
402 
403  for (std::size_t i=0; i != this->qoi.size(); ++i)
404  if (qoi_indices.has_index(i))
405  {
406  const std::pair<unsigned int, Real> rval =
407  linear_solver->adjoint_solve (*matrix, this->add_adjoint_solution(i),
408  this->get_adjoint_rhs(i),
409  solver_params.second,
410  solver_params.first);
411 
412  totalrval.first += rval.first;
413  totalrval.second += rval.second;
414  }
415 
416  this->release_linear_solver(linear_solver);
417 
418  // The linear solver may not have fit our constraints exactly
419 #ifdef LIBMESH_ENABLE_CONSTRAINTS
420  for (std::size_t i=0; i != this->qoi.size(); ++i)
421  if (qoi_indices.has_index(i))
423  (this->get_adjoint_solution(i), i);
424 #endif
425 
426  return totalrval;
427 }
virtual LinearSolver< Number > * get_linear_solver() const
NumericVector< Number > & add_adjoint_solution(unsigned int i=0)
Definition: system.C:975
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true) libmesh_override
virtual void assembly(bool, bool, bool=false, bool=false)
const DofMap & get_dof_map() const
Definition: system.h:2028
std::vector< Number > qoi
Definition: system.h:1551
SparseMatrix< Number > * matrix
virtual void release_linear_solver(LinearSolver< Number > *) const
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
Definition: system.C:987
bool assemble_before_solve
Definition: system.h:1475
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
NumericVector< Number > & get_adjoint_rhs(unsigned int i=0)
Definition: system.C:1049
void libMesh::ImplicitSystem::assemble ( )
virtualinherited

Prepares matrix and rhs for system assembly, then calls user assembly function. Can be overridden in derived classes.

Reimplemented from libMesh::System.

Reimplemented in libMesh::LinearImplicitSystem, libMesh::DifferentiableSystem, libMesh::FrequencySystem, and libMesh::NewmarkSystem.

Definition at line 191 of file implicit_system.C.

References libMesh::System::assemble(), libMesh::SparseMatrix< T >::initialized(), libMesh::NumericVector< T >::initialized(), libMesh::libmesh_assert(), libMesh::ImplicitSystem::matrix, libMesh::ExplicitSystem::rhs, libMesh::SparseMatrix< T >::zero(), libMesh::NumericVector< T >::zero(), and libMesh::ImplicitSystem::zero_out_matrix_and_rhs.

Referenced by libMesh::LinearImplicitSystem::assemble().

192 {
197 
199  {
200  matrix->zero ();
201  rhs->zero ();
202  }
203 
204  // Call the base class assemble function
205  Parent::assemble ();
206 }
virtual void assemble()
Definition: system.C:477
NumericVector< Number > * rhs
virtual bool initialized() const
virtual void zero()=0
libmesh_assert(j)
virtual bool initialized() const
virtual void zero()=0
SparseMatrix< Number > * matrix
void libMesh::ExplicitSystem::assemble_qoi ( const QoISet qoi_indices = QoISet())
virtualinherited

Prepares qoi for quantity of interest assembly, then calls user qoi function. Can be overridden in derived classes.

Reimplemented from libMesh::System.

Reimplemented in libMesh::FEMSystem.

Definition at line 68 of file explicit_system.C.

References libMesh::System::assemble_qoi(), libMesh::QoISet::has_index(), and libMesh::System::qoi.

Referenced by libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity(), libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity(), libMesh::ImplicitSystem::qoi_parameter_hessian(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), and libMesh::ExplicitSystem::system().

69 {
70  // The user quantity of interest assembly gets to expect to
71  // accumulate on initially zero values
72  for (std::size_t i=0; i != qoi.size(); ++i)
73  if (qoi_indices.has_index(i))
74  qoi[i] = 0;
75 
76  Parent::assemble_qoi (qoi_indices);
77 }
std::vector< Number > qoi
Definition: system.h:1551
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet())
Definition: system.C:488
void libMesh::ExplicitSystem::assemble_qoi_derivative ( const QoISet qoi_indices = QoISet(),
bool  include_liftfunc = true,
bool  apply_constraints = true 
)
virtualinherited

Prepares adjoint_rhs for quantity of interest derivative assembly, then calls user qoi derivative function. Can be overridden in derived classes.

Reimplemented from libMesh::System.

Reimplemented in libMesh::FEMSystem.

Definition at line 81 of file explicit_system.C.

References libMesh::System::add_adjoint_rhs(), libMesh::System::assemble_qoi_derivative(), libMesh::QoISet::has_index(), libMesh::System::qoi, and libMesh::NumericVector< T >::zero().

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

84 {
85  // The user quantity of interest derivative assembly gets to expect
86  // to accumulate on initially zero vectors
87  for (std::size_t i=0; i != qoi.size(); ++i)
88  if (qoi_indices.has_index(i))
89  this->add_adjoint_rhs(i).zero();
90 
91  Parent::assemble_qoi_derivative (qoi_indices, include_liftfunc,
92  apply_constraints);
93 }
virtual void assemble_qoi_derivative(const QoISet &qoi_indices=QoISet(), bool include_liftfunc=true, bool apply_constraints=true)
Definition: system.C:499
virtual void zero()=0
std::vector< Number > qoi
Definition: system.h:1551
NumericVector< Number > & add_adjoint_rhs(unsigned int i=0)
Definition: system.C:1039
void libMesh::ImplicitSystem::assemble_residual_derivatives ( const ParameterVector parameters)
virtualinherited

Residual parameter derivative function.

Uses finite differences by default.

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

Can be overridden in derived classes.

Reimplemented from libMesh::System.

Definition at line 665 of file implicit_system.C.

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

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

666 {
667  ParameterVector & parameters =
668  const_cast<ParameterVector &>(parameters_in);
669 
670  const unsigned int Np = cast_int<unsigned int>
671  (parameters.size());
672 
673  for (unsigned int p=0; p != Np; ++p)
674  {
675  NumericVector<Number> & sensitivity_rhs = this->add_sensitivity_rhs(p);
676 
677  // Approximate -(partial R / partial p) by
678  // (R(p-dp) - R(p+dp)) / (2*dp)
679 
680  Number old_parameter = *parameters[p];
681 
682  const Real delta_p =
683  TOLERANCE * std::max(std::abs(old_parameter), 1e-3);
684 
685  *parameters[p] -= delta_p;
686 
687  // this->assembly(true, false, true);
688  this->assembly(true, false, false);
689  this->rhs->close();
690  sensitivity_rhs = *this->rhs;
691 
692  *parameters[p] = old_parameter + delta_p;
693 
694  // this->assembly(true, false, true);
695  this->assembly(true, false, false);
696  this->rhs->close();
697 
698  sensitivity_rhs -= *this->rhs;
699  sensitivity_rhs /= (2*delta_p);
700  sensitivity_rhs.close();
701 
702  *parameters[p] = old_parameter;
703  }
704 }
double abs(double a)
NumericVector< Number > * rhs
NumericVector< Number > & add_sensitivity_rhs(unsigned int i=0)
Definition: system.C:1069
static const Real TOLERANCE
long double max(long double a, double b)
virtual void assembly(bool, bool, bool=false, bool=false)
virtual void close()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void libMesh::ImplicitSystem::assembly ( bool  ,
bool  ,
bool  = false,
bool  = false 
)
inlinevirtualinherited
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 1805 of file system.C.

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

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

1807 {
1808  libmesh_assert(fptr);
1809 
1811  {
1812  libmesh_here();
1813  libMesh::out << "WARNING: Cannot specify both assembly function and object!"
1814  << std::endl;
1815 
1817  }
1818 
1820 }
Assembly * _assemble_system_object
Definition: system.h:1820
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1814
OStreamProxy out(std::cout)
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 1824 of file system.C.

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

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

1825 {
1827  {
1828  libmesh_here();
1829  libMesh::out << "WARNING: Cannot specify both assembly object and function!"
1830  << std::endl;
1831 
1833  }
1834 
1835  _assemble_system_object = &assemble_in;
1836 }
Assembly * _assemble_system_object
Definition: system.h:1820
const class libmesh_nullptr_t libmesh_nullptr
void(* _assemble_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1814
OStreamProxy out(std::cout)
void libMesh::System::attach_constraint_function ( void   fptrEquationSystems &es, const std::string &name)
inherited

Register a user function for imposing constraints.

Definition at line 1840 of file system.C.

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

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

1842 {
1843  libmesh_assert(fptr);
1844 
1846  {
1847  libmesh_here();
1848  libMesh::out << "WARNING: Cannot specify both constraint function and object!"
1849  << std::endl;
1850 
1852  }
1853 
1855 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1825
Constraint * _constrain_system_object
Definition: system.h:1831
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
OStreamProxy out(std::cout)
void libMesh::System::attach_constraint_object ( System::Constraint constrain)
inherited

Register a user object for imposing constraints.

Definition at line 1859 of file system.C.

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

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

1860 {
1862  {
1863  libmesh_here();
1864  libMesh::out << "WARNING: Cannot specify both constraint object and function!"
1865  << std::endl;
1866 
1868  }
1869 
1870  _constrain_system_object = &constrain;
1871 }
void(* _constrain_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1825
Constraint * _constrain_system_object
Definition: system.h:1831
const class libmesh_nullptr_t libmesh_nullptr
OStreamProxy out(std::cout)
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 1770 of file system.C.

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

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

1772 {
1773  libmesh_assert(fptr);
1774 
1776  {
1777  libmesh_here();
1778  libMesh::out << "WARNING: Cannot specify both initialization function and object!"
1779  << std::endl;
1780 
1782  }
1783 
1784  _init_system_function = fptr;
1785 }
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
Initialization * _init_system_object
Definition: system.h:1809
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1803
OStreamProxy out(std::cout)
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 1789 of file system.C.

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

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

1790 {
1792  {
1793  libmesh_here();
1794  libMesh::out << "WARNING: Cannot specify both initialization object and function!"
1795  << std::endl;
1796 
1798  }
1799 
1800  _init_system_object = &init_in;
1801 }
const class libmesh_nullptr_t libmesh_nullptr
Initialization * _init_system_object
Definition: system.h:1809
void(* _init_system_function)(EquationSystems &es, const std::string &name)
Definition: system.h:1803
OStreamProxy out(std::cout)
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 1911 of file system.C.

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

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

1913 {
1914  libmesh_assert(fptr);
1915 
1917  {
1918  libmesh_here();
1919  libMesh::out << "WARNING: Cannot specify both QOI derivative function and object!"
1920  << std::endl;
1921 
1923  }
1924 
1926 }
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
QOIDerivative * _qoi_evaluate_derivative_object
Definition: system.h:1857
OStreamProxy out(std::cout)
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Definition: system.h:1848
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 1930 of file system.C.

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

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

1931 {
1933  {
1934  libmesh_here();
1935  libMesh::out << "WARNING: Cannot specify both QOI derivative object and function!"
1936  << std::endl;
1937 
1939  }
1940 
1941  _qoi_evaluate_derivative_object = &qoi_derivative;
1942 }
const class libmesh_nullptr_t libmesh_nullptr
QOIDerivative * _qoi_evaluate_derivative_object
Definition: system.h:1857
OStreamProxy out(std::cout)
void(* _qoi_evaluate_derivative_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices, bool include_liftfunc, bool apply_constraints)
Definition: system.h:1848
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 1875 of file system.C.

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

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

1878 {
1879  libmesh_assert(fptr);
1880 
1882  {
1883  libmesh_here();
1884  libMesh::out << "WARNING: Cannot specify both QOI function and object!"
1885  << std::endl;
1886 
1888  }
1889 
1890  _qoi_evaluate_function = fptr;
1891 }
const class libmesh_nullptr_t libmesh_nullptr
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Definition: system.h:1836
libmesh_assert(j)
QOI * _qoi_evaluate_object
Definition: system.h:1843
OStreamProxy out(std::cout)
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 1895 of file system.C.

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

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

1896 {
1898  {
1899  libmesh_here();
1900  libMesh::out << "WARNING: Cannot specify both QOI object and function!"
1901  << std::endl;
1902 
1904  }
1905 
1906  _qoi_evaluate_object = &qoi_in;
1907 }
const class libmesh_nullptr_t libmesh_nullptr
void(* _qoi_evaluate_function)(EquationSystems &es, const std::string &name, const QoISet &qoi_indices)
Definition: system.h:1836
QOI * _qoi_evaluate_object
Definition: system.h:1843
OStreamProxy out(std::cout)
void libMesh::System::boundary_project_solution ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
FunctionBase< Number > *  f,
FunctionBase< Gradient > *  g = libmesh_nullptr 
)
inherited

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

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

Definition at line 999 of file system_projection.C.

References libMesh::System::boundary_project_vector().

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

1003 {
1004  this->boundary_project_vector(b, variables, *solution, f, g);
1005 
1006  solution->localize(*current_local_solution);
1007 }
void boundary_project_vector(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
UniquePtr< NumericVector< Number > > current_local_solution
Definition: system.h:1533
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1521
void libMesh::System::boundary_project_solution ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
Number   fptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
Gradient   gptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
const Parameters parameters 
)
inherited

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

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

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

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

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

Definition at line 1041 of file system_projection.C.

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

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

1047 {
1048  LOG_SCOPE ("boundary_project_vector()", "System");
1049 
1051  (ConstElemRange (this->get_mesh().active_local_elements_begin(),
1052  this->get_mesh().active_local_elements_end() ),
1053  BoundaryProjectSolution(b, variables, *this, f, g,
1054  this->get_equation_systems().parameters,
1055  new_vector)
1056  );
1057 
1058  // We don't do SCALAR dofs when just projecting the boundary, so
1059  // we're done here.
1060 
1061  new_vector.close();
1062 
1063 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1064  if (is_adjoint == -1)
1065  this->get_dof_map().enforce_constraints_exactly(*this, &new_vector);
1066  else if (is_adjoint >= 0)
1068  is_adjoint);
1069 #endif
1070 }
void parallel_for(const Range &range, const Body &body)
Definition: threads_none.h:73
StoredRange< MeshBase::const_element_iterator, const Elem * > ConstElemRange
Definition: elem_range.h:34
const MeshBase & get_mesh() const
Definition: system.h:2012
const DofMap & get_dof_map() const
Definition: system.h:2028
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
virtual void close()=0
const EquationSystems & get_equation_systems() const
Definition: system.h:712
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
void libMesh::System::boundary_project_vector ( const std::set< boundary_id_type > &  b,
const std::vector< unsigned int > &  variables,
Number   fptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
Gradient   gptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
const Parameters parameters,
NumericVector< Number > &  new_vector,
int  is_adjoint = -1 
) const
inherited

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

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

Real libMesh::System::calculate_norm ( const NumericVector< Number > &  v,
unsigned int  var,
FEMNormType  norm_type,
std::set< unsigned int > *  skip_dimensions = libmesh_nullptr 
) const
inherited
Returns
A norm of variable var in the vector v, in the specified norm (e.g. L2, L_INF, H1)

Definition at line 1397 of file system.C.

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

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

1401 {
1402  //short circuit to save time
1403  if (norm_type == DISCRETE_L1 ||
1404  norm_type == DISCRETE_L2 ||
1405  norm_type == DISCRETE_L_INF)
1406  return discrete_var_norm(v,var,norm_type);
1407 
1408  // Not a discrete norm
1409  std::vector<FEMNormType> norms(this->n_vars(), L2);
1410  std::vector<Real> weights(this->n_vars(), 0.0);
1411  norms[var] = norm_type;
1412  weights[var] = 1.0;
1413  Real val = this->calculate_norm(v, SystemNorm(norms, weights), skip_dimensions);
1414  return val;
1415 }
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=libmesh_nullptr) const
Definition: system.C:1397
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int n_vars() const
Definition: system.h:2084
Real discrete_var_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type) const
Definition: system.C:1378
Real libMesh::System::calculate_norm ( const NumericVector< Number > &  v,
const SystemNorm norm,
std::set< unsigned int > *  skip_dimensions = libmesh_nullptr 
) const
inherited
Returns
A norm of the vector v, using component_norm and component_scale to choose and weight the norms of each variable.

Definition at line 1419 of file system.C.

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

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

Clear all the data structures associated with the system.

Reimplemented from libMesh::ImplicitSystem.

Definition at line 61 of file optimization_system.C.

References libMesh::ImplicitSystem::clear(), and optimization_solver.

Referenced by system(), and ~OptimizationSystem().

62 {
63  // clear the optimization solver
64  optimization_solver->clear();
65 
66  // clear the parent data
67  Parent::clear();
68 }
UniquePtr< OptimizationSolver< Number > > optimization_solver
virtual void clear() libmesh_override
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::DistributedVector< T >::clone(), libMesh::EigenSparseVector< T >::clone(), libMesh::LaspackVector< T >::clone(), libMesh::EpetraVector< T >::clone(), libMesh::PetscVector< T >::clone(), libMesh::EpetraVector< T >::close(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::EpetraVector< T >::EpetraVector(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), libMesh::LocationMap< T >::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TopologyMap::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::DistributedVector< T >::init(), libMesh::EpetraVector< T >::init(), libMesh::PetscVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), initialize_equality_constraints_storage(), initialize_inequality_constraints_storage(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::DistributedVector< T >::max(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), libMesh::DistributedVector< T >::min(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::DistributedVector< T >::zero_clone(), libMesh::LaspackVector< T >::zero_clone(), libMesh::EigenSparseVector< T >::zero_clone(), libMesh::EpetraVector< T >::zero_clone(), and libMesh::PetscVector< T >::zero_clone().

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

Definition at line 529 of file system.C.

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

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

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

191 {
192  // Check the sizes
193  libmesh_assert_less (global_dof_number, _dof_map->n_dofs());
194  libmesh_assert_less (global_dof_number, current_local_solution->size());
195 
196  return (*current_local_solution)(global_dof_number);
197 }
UniquePtr< NumericVector< Number > > current_local_solution
Definition: system.h:1533
UniquePtr< DofMap > _dof_map
Definition: system.h:1863
void libMesh::System::deactivate ( )
inlineinherited

Deactivates the system. Only active systems are solved.

Definition at line 2060 of file system.h.

References libMesh::System::_active.

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

2061 {
2062  _active = false;
2063 }
void libMesh::ImplicitSystem::disable_cache ( )
virtualinherited

Avoids use of any cached data that might affect any solve result. Should be overridden in derived systems.

Reimplemented from libMesh::System.

Definition at line 313 of file implicit_system.C.

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

313  {
314  this->assemble_before_solve = true;
315  this->get_linear_solver()->reuse_preconditioner(false);
316 }
virtual LinearSolver< Number > * get_linear_solver() const
virtual void reuse_preconditioner(bool)
bool assemble_before_solve
Definition: system.h:1475
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

Definition at line 101 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

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

102 {
103  _enable_print_counter = true;
104  return;
105 }
void libMesh::ImplicitSystem::forward_qoi_parameter_sensitivity ( const QoISet qoi_indices,
const ParameterVector parameters,
SensitivityData sensitivities 
)
virtualinherited

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

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

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

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

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

References libMesh::System::get_vector().

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

1050 {
1051  std::ostringstream adjoint_rhs_name;
1052  adjoint_rhs_name << "adjoint_rhs" << i;
1053 
1054  return this->get_vector(adjoint_rhs_name.str());
1055 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
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 1059 of file system.C.

References libMesh::System::get_vector().

1060 {
1061  std::ostringstream adjoint_rhs_name;
1062  adjoint_rhs_name << "adjoint_rhs" << i;
1063 
1064  return this->get_vector(adjoint_rhs_name.str());
1065 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
NumericVector< Number > & libMesh::System::get_adjoint_solution ( unsigned int  i = 0)
inherited
Returns
A reference to one of the system's adjoint solution vectors, by default the one corresponding to the first qoi.

Definition at line 987 of file system.C.

References libMesh::System::get_vector().

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

988 {
989  std::ostringstream adjoint_name;
990  adjoint_name << "adjoint_solution" << i;
991 
992  return this->get_vector(adjoint_name.str());
993 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
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 997 of file system.C.

References libMesh::System::get_vector().

998 {
999  std::ostringstream adjoint_name;
1000  adjoint_name << "adjoint_solution" << i;
1001 
1002  return this->get_vector(adjoint_name.str());
1003 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
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 1276 of file system.C.

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

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

1277 {
1278  all_variable_numbers.resize(n_vars());
1279 
1280  // Make sure the variable exists
1281  std::map<std::string, unsigned short int>::const_iterator
1282  it = _variable_numbers.begin();
1283  std::map<std::string, unsigned short int>::const_iterator
1284  it_end = _variable_numbers.end();
1285 
1286  unsigned int count = 0;
1287  for ( ; it != it_end; ++it)
1288  {
1289  all_variable_numbers[count] = it->second;
1290  count++;
1291  }
1292 }
std::map< std::string, unsigned short int > _variable_numbers
Definition: system.h:1901
unsigned int n_vars() const
Definition: system.h:2084
const DofMap & libMesh::System::get_dof_map ( ) const
inlineinherited
Returns
A constant reference to this system's _dof_map.

Definition at line 2028 of file system.h.

References libMesh::System::_dof_map.

Referenced by libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::DifferentiableSystem::add_dot_var_dirichlet_bcs(), libMesh::HPCoarsenTest::add_projection(), libMesh::UnsteadySolver::adjoint_advance_timestep(), libMesh::ImplicitSystem::adjoint_solve(), libMesh::NewmarkSolver::advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), libMesh::EquationSystems::allgather(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::System::calculate_norm(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), DMCreateDomainDecomposition_libMesh(), DMCreateFieldDecomposition_libMesh(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::System::get_info(), libMesh::EquationSystems::get_solution(), libMesh::SystemSubsetBySubdomain::init(), libMesh::SecondOrderUnsteadySolver::init_data(), libMesh::UnsteadySolver::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ImplicitSystem::init_matrices(), libMesh::CondensedEigenSystem::initialize_condensed_dofs(), initialize_equality_constraints_storage(), initialize_inequality_constraints_storage(), libMesh::System::local_dof_indices(), libMesh::DofMap::max_constraint_error(), libMesh::DGFEMContext::neighbor_side_fe_reinit(), libMesh::UnsteadySolver::old_nonlinear_solution(), libMesh::SecondOrderUnsteadySolver::old_solution_accel(), libMesh::SecondOrderUnsteadySolver::old_solution_rate(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::operator()(), libMesh::BuildProjectionList::operator()(), libMesh::BoundaryProjectSolution::operator()(), libMesh::petsc_auto_fieldsplit(), libMesh::ErrorVector::plot_error(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::FEMContext::pre_fe_reinit(), libMesh::System::re_update(), libMesh::SecondOrderUnsteadySolver::reinit(), libMesh::UnsteadySolver::reinit(), libMesh::ImplicitSystem::reinit(), libMesh::EigenSystem::reinit(), libMesh::EquationSystems::reinit(), libMesh::System::reinit_constraints(), libMesh::UnsteadySolver::retrieve_timestep(), libMesh::HPCoarsenTest::select_refinement(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::NewtonSolver::solve(), libMesh::PetscDiffSolver::solve(), libMesh::PetscNonlinearSolver< T >::solve(), libMesh::System::system_type(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), libMesh::ImplicitSystem::weighted_sensitivity_solve(), libMesh::EnsightIO::write_scalar_ascii(), and libMesh::EnsightIO::write_vector_ascii().

2029 {
2030  return *_dof_map;
2031 }
UniquePtr< DofMap > _dof_map
Definition: system.h:1863
DofMap & libMesh::System::get_dof_map ( )
inlineinherited
Returns
A writable reference to this system's _dof_map.

Definition at line 2036 of file system.h.

References libMesh::System::_dof_map.

2037 {
2038  return *_dof_map;
2039 }
UniquePtr< DofMap > _dof_map
Definition: system.h:1863
EquationSystems& libMesh::System::get_equation_systems ( )
inlineinherited
Returns
A reference to this system's parent EquationSystems object.

Definition at line 717 of file system.h.

References libMesh::System::_equation_systems, libMesh::System::activate(), libMesh::System::active(), libMesh::System::deactivate(), and libMesh::System::set_basic_system_only().

717 { return _equation_systems; }
EquationSystems & _equation_systems
Definition: system.h:1869
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 (Counts::iterator it = _counts.begin();
59  it != _counts.end(); ++it)
60  {
61  const std::string name(it->first);
62  const unsigned int creations = it->second.first;
63  const unsigned int destructions = it->second.second;
64 
65  oss << "| " << name << " reference count information:\n"
66  << "| Creations: " << creations << '\n'
67  << "| Destructions: " << destructions << '\n';
68  }
69 
70  oss << " ---------------------------------------------------------------------------- \n";
71 
72  return oss.str();
73 
74 #else
75 
76  return "";
77 
78 #endif
79 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::string libMesh::System::get_info ( ) const
inherited
Returns
A string containing information about the system.

Definition at line 1686 of file system.C.

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

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

1687 {
1688  std::ostringstream oss;
1689 
1690 
1691  const std::string & sys_name = this->name();
1692 
1693  oss << " System #" << this->number() << ", \"" << sys_name << "\"\n"
1694  << " Type \"" << this->system_type() << "\"\n"
1695  << " Variables=";
1696 
1697  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1698  {
1699  const VariableGroup & vg_description (this->variable_group(vg));
1700 
1701  if (vg_description.n_variables() > 1) oss << "{ ";
1702  for (unsigned int vn=0; vn<vg_description.n_variables(); vn++)
1703  oss << "\"" << vg_description.name(vn) << "\" ";
1704  if (vg_description.n_variables() > 1) oss << "} ";
1705  }
1706 
1707  oss << '\n';
1708 
1709  oss << " Finite Element Types=";
1710 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
1711  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1712  oss << "\""
1713  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().family)
1714  << "\" ";
1715 #else
1716  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1717  {
1718  oss << "\""
1719  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().family)
1720  << "\", \""
1721  << Utility::enum_to_string<FEFamily>(this->get_dof_map().variable_group(vg).type().radial_family)
1722  << "\" ";
1723  }
1724 
1725  oss << '\n' << " Infinite Element Mapping=";
1726  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1727  oss << "\""
1728  << Utility::enum_to_string<InfMapType>(this->get_dof_map().variable_group(vg).type().inf_map)
1729  << "\" ";
1730 #endif
1731 
1732  oss << '\n';
1733 
1734  oss << " Approximation Orders=";
1735  for (unsigned int vg=0; vg<this->n_variable_groups(); vg++)
1736  {
1737 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
1738  oss << "\""
1739  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().order)
1740  << "\" ";
1741 #else
1742  oss << "\""
1743  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().order)
1744  << "\", \""
1745  << Utility::enum_to_string<Order>(this->get_dof_map().variable_group(vg).type().radial_order)
1746  << "\" ";
1747 #endif
1748  }
1749 
1750  oss << '\n';
1751 
1752  oss << " n_dofs()=" << this->n_dofs() << '\n';
1753  oss << " n_local_dofs()=" << this->n_local_dofs() << '\n';
1754 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1755  oss << " n_constrained_dofs()=" << this->n_constrained_dofs() << '\n';
1756  oss << " n_local_constrained_dofs()=" << this->n_local_constrained_dofs() << '\n';
1757 #endif
1758 
1759  oss << " " << "n_vectors()=" << this->n_vectors() << '\n';
1760  oss << " " << "n_matrices()=" << this->n_matrices() << '\n';
1761  // oss << " " << "n_additional_matrices()=" << this->n_additional_matrices() << '\n';
1762 
1763  oss << this->get_dof_map().get_info();
1764 
1765  return oss.str();
1766 }
FEFamily family
Definition: fe_type.h:203
dof_id_type n_constrained_dofs() const
Definition: system.C:153
const FEType & type() const
Definition: variable.h:119
std::string get_info() const
Definition: dof_map.C:2764
OrderWrapper radial_order
Definition: fe_type.h:236
OrderWrapper order
Definition: fe_type.h:197
const VariableGroup & variable_group(unsigned int vg) const
Definition: system.h:2122
const VariableGroup & variable_group(const unsigned int c) const
Definition: dof_map.h:1646
const std::string & name() const
Definition: system.h:1996
unsigned int n_variable_groups() const
Definition: system.h:2092
const DofMap & get_dof_map() const
Definition: system.h:2028
InfMapType inf_map
Definition: fe_type.h:257
virtual unsigned int n_matrices() const
Definition: system.h:2218
FEFamily radial_family
Definition: fe_type.h:249
dof_id_type n_local_dofs() const
Definition: system.C:183
virtual std::string system_type() const
Definition: system.h:471
dof_id_type n_local_constrained_dofs() const
Definition: system.C:168
unsigned int number() const
Definition: system.h:2004
dof_id_type n_dofs() const
Definition: system.C:146
unsigned int n_vectors() const
Definition: system.h:2212
std::pair< unsigned int, Real > libMesh::ImplicitSystem::get_linear_solve_parameters ( ) const
virtualinherited
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 in libMesh::NonlinearImplicitSystem, and libMesh::DifferentiableSystem.

Definition at line 1425 of file implicit_system.C.

References libMesh::Parameters::get(), libMesh::System::get_equation_systems(), libMesh::EquationSystems::parameters, and libMesh::Real.

Referenced by libMesh::ImplicitSystem::adjoint_solve(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::ImplicitSystem::system_type(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

1426 {
1427  return std::make_pair(this->get_equation_systems().parameters.get<unsigned int>("linear solver maximum iterations"),
1428  this->get_equation_systems().parameters.get<Real>("linear solver tolerance"));
1429 }
const T & get(const std::string &) const
Definition: parameters.h:430
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const EquationSystems & get_equation_systems() const
Definition: system.h:712
LinearSolver< Number > * libMesh::ImplicitSystem::get_linear_solver ( ) const
virtualinherited
Returns
A pointer to a linear solver appropriate for use in adjoint and/or sensitivity solves

This function must be overridden in derived classes, since this base class does not have a valid LinearSolver to hand back a pointer to.

Deprecated:
This function's current behavior, i.e. allocating a LinearSolver and handing it back to the user, makes it very easy to leak memory, and probably won't have the intended effect, i.e. of setting some parameters on a LinearSolver that the System would later use internally.

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

Definition at line 1399 of file implicit_system.C.

References libMesh::LinearSolver< T >::build(), libMesh::ParallelObject::comm(), libMesh::LinearSolver< T >::init(), libMesh::System::name(), and libMesh::on_command_line().

Referenced by libMesh::ImplicitSystem::adjoint_solve(), libMesh::ImplicitSystem::disable_cache(), libMesh::ImplicitSystem::sensitivity_solve(), libMesh::ImplicitSystem::system_type(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

1400 {
1401  // This function allocates memory and hands it back to the user as a
1402  // naked pointer. This makes it too easy to leak memory, and
1403  // therefore this function is deprecated. After a period of
1404  // deprecation, this function will eventually be marked with a
1405  // libmesh_error_msg().
1406  libmesh_deprecated();
1407  // libmesh_error_msg("This function should be overridden by derived classes. "
1408  // "It does not contain a valid LinearSolver to hand back to "
1409  // "the user, so it creates one, opening up the possibility "
1410  // "of a memory leak.");
1411 
1412  LinearSolver<Number> * new_solver =
1413  LinearSolver<Number>::build(this->comm()).release();
1414 
1415  if (libMesh::on_command_line("--solver_system_names"))
1416  new_solver->init((this->name()+"_").c_str());
1417  else
1418  new_solver->init();
1419 
1420  return new_solver;
1421 }
static UniquePtr< LinearSolver< T > > build(const libMesh::Parallel::Communicator &comm_in, const SolverPackage solver_package=libMesh::default_solver_package())
Definition: linear_solver.C:42
const std::string & name() const
Definition: system.h:1996
bool on_command_line(const std::string &arg)
Definition: libmesh.C:921
const Parallel::Communicator & comm() const
const SparseMatrix< Number > & libMesh::ImplicitSystem::get_matrix ( const std::string &  mat_name) const
inherited
Returns
A const reference to this system's additional matrix named mat_name.

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

Definition at line 270 of file implicit_system.C.

References libMesh::ImplicitSystem::_matrices.

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

271 {
272  // Make sure the matrix exists
273  const_matrices_iterator pos = _matrices.find (mat_name);
274 
275  if (pos == _matrices.end())
276  libmesh_error_msg("ERROR: matrix " << mat_name << " does not exist in this system!");
277 
278  return *(pos->second);
279 }
std::map< std::string, SparseMatrix< Number > * > _matrices
std::map< std::string, SparseMatrix< Number > * >::const_iterator const_matrices_iterator
SparseMatrix< Number > & libMesh::ImplicitSystem::get_matrix ( const std::string &  mat_name)
inherited
Returns
A writable reference to this system's additional matrix named mat_name.

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

Definition at line 283 of file implicit_system.C.

References libMesh::ImplicitSystem::_matrices.

284 {
285  // Make sure the matrix exists
286  matrices_iterator pos = _matrices.find (mat_name);
287 
288  if (pos == _matrices.end())
289  libmesh_error_msg("ERROR: matrix " << mat_name << " does not exist in this system!");
290 
291  return *(pos->second);
292 }
std::map< std::string, SparseMatrix< Number > * > _matrices
std::map< std::string, SparseMatrix< Number > * >::iterator matrices_iterator
const MeshBase & libMesh::System::get_mesh ( ) const
inlineinherited
Returns
A constant reference to this systems's _mesh.

Definition at line 2012 of file system.h.

References libMesh::System::_mesh.

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::HPCoarsenTest::add_projection(), libMesh::FEMSystem::assemble_qoi(), libMesh::FEMSystem::assemble_qoi_derivative(), libMesh::FEMSystem::assembly(), libMesh::System::calculate_norm(), DMCreateDomainDecomposition_libMesh(), DMCreateFieldDecomposition_libMesh(), DMlibMeshSetSystem_libMesh(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::SystemSubsetBySubdomain::init(), libMesh::System::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ImplicitSystem::init_matrices(), libMesh::System::local_dof_indices(), libMesh::DofMap::max_constraint_error(), libMesh::FEMSystem::mesh_position_get(), libMesh::FEMSystem::mesh_position_set(), libMesh::BoundaryProjectSolution::operator()(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::FEMSystem::postprocess(), libMesh::ImplicitSystem::reinit(), libMesh::EigenSystem::reinit(), libMesh::HPSingularity::select_refinement(), libMesh::HPCoarsenTest::select_refinement(), libMesh::System::system_type(), and libMesh::System::zero_variable().

2013 {
2014  return _mesh;
2015 }
MeshBase & _mesh
Definition: system.h:1875
MeshBase & libMesh::System::get_mesh ( )
inlineinherited
Returns
A reference to this systems's _mesh.

Definition at line 2020 of file system.h.

References libMesh::System::_mesh.

2021 {
2022  return _mesh;
2023 }
MeshBase & _mesh
Definition: system.h:1875
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 1079 of file system.C.

References libMesh::System::get_vector().

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

1080 {
1081  std::ostringstream sensitivity_rhs_name;
1082  sensitivity_rhs_name << "sensitivity_rhs" << i;
1083 
1084  return this->get_vector(sensitivity_rhs_name.str());
1085 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
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 1089 of file system.C.

References libMesh::System::get_vector().

1090 {
1091  std::ostringstream sensitivity_rhs_name;
1092  sensitivity_rhs_name << "sensitivity_rhs" << i;
1093 
1094  return this->get_vector(sensitivity_rhs_name.str());
1095 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
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 934 of file system.C.

References libMesh::System::get_vector().

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

935 {
936  std::ostringstream sensitivity_name;
937  sensitivity_name << "sensitivity_solution" << i;
938 
939  return this->get_vector(sensitivity_name.str());
940 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
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 944 of file system.C.

References libMesh::System::get_vector().

945 {
946  std::ostringstream sensitivity_name;
947  sensitivity_name << "sensitivity_solution" << i;
948 
949  return this->get_vector(sensitivity_name.str());
950 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
const NumericVector< Number > & libMesh::System::get_vector ( const std::string &  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 792 of file system.C.

References libMesh::System::_vectors.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::UnsteadySolver::adjoint_advance_timestep(), libMesh::NewmarkSolver::advance_timestep(), libMesh::AdaptiveTimeSolver::advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), 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(), libMesh::NewmarkSolver::project_initial_accel(), libMesh::SecondOrderUnsteadySolver::project_initial_rate(), libMesh::System::project_solution_on_reinit(), libMesh::SecondOrderUnsteadySolver::reinit(), libMesh::UnsteadySolver::reinit(), libMesh::MemorySolutionHistory::retrieve(), libMesh::UnsteadySolver::retrieve_timestep(), libMesh::TwostepTimeSolver::solve(), libMesh::TaoOptimizationSolver< T >::solve(), libMesh::NloptOptimizationSolver< T >::solve(), libMesh::FrequencySystem::solve(), libMesh::NewmarkSystem::update_rhs(), and libMesh::NewmarkSystem::update_u_v_a().

793 {
794  // Make sure the vector exists
795  const_vectors_iterator pos = _vectors.find(vec_name);
796 
797  if (pos == _vectors.end())
798  libmesh_error_msg("ERROR: vector " << vec_name << " does not exist in this system!");
799 
800  return *(pos->second);
801 }
std::map< std::string, NumericVector< Number > * >::const_iterator const_vectors_iterator
Definition: system.h:749
std::map< std::string, NumericVector< Number > * > _vectors
Definition: system.h:1914
NumericVector< Number > & libMesh::System::get_vector ( const std::string &  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 805 of file system.C.

References libMesh::System::_vectors.

806 {
807  // Make sure the vector exists
808  vectors_iterator pos = _vectors.find(vec_name);
809 
810  if (pos == _vectors.end())
811  libmesh_error_msg("ERROR: vector " << vec_name << " does not exist in this system!");
812 
813  return *(pos->second);
814 }
std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
Definition: system.h:748
std::map< std::string, NumericVector< Number > * > _vectors
Definition: system.h:1914
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 818 of file system.C.

References libMesh::libmesh_assert(), libMesh::System::vectors_begin(), and libMesh::System::vectors_end().

819 {
822  unsigned int num = 0;
823  while ((num<vec_num) && (v!=v_end))
824  {
825  num++;
826  ++v;
827  }
828  libmesh_assert (v != v_end);
829  return *(v->second);
830 }
vectors_iterator vectors_end()
Definition: system.h:2236
std::map< std::string, NumericVector< Number > * >::const_iterator const_vectors_iterator
Definition: system.h:749
vectors_iterator vectors_begin()
Definition: system.h:2224
libmesh_assert(j)
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 834 of file system.C.

References libMesh::libmesh_assert(), libMesh::System::vectors_begin(), and libMesh::System::vectors_end().

835 {
837  vectors_iterator v_end = vectors_end();
838  unsigned int num = 0;
839  while ((num<vec_num) && (v!=v_end))
840  {
841  num++;
842  ++v;
843  }
844  libmesh_assert (v != v_end);
845  return *(v->second);
846 }
vectors_iterator vectors_end()
Definition: system.h:2236
vectors_iterator vectors_begin()
Definition: system.h:2224
libmesh_assert(j)
std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
Definition: system.h:748
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 1019 of file system.C.

References libMesh::System::get_vector().

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

1020 {
1021  std::ostringstream adjoint_name;
1022  adjoint_name << "weighted_sensitivity_adjoint_solution" << i;
1023 
1024  return this->get_vector(adjoint_name.str());
1025 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
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 1029 of file system.C.

References libMesh::System::get_vector().

1030 {
1031  std::ostringstream adjoint_name;
1032  adjoint_name << "weighted_sensitivity_adjoint_solution" << i;
1033 
1034  return this->get_vector(adjoint_name.str());
1035 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
NumericVector< Number > & libMesh::System::get_weighted_sensitivity_solution ( )
inherited
Returns
A reference to the solution of the last weighted sensitivity solve

Definition at line 961 of file system.C.

References libMesh::System::get_vector().

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

962 {
963  return this->get_vector("weighted_sensitivity_solution");
964 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
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 968 of file system.C.

References libMesh::System::get_vector().

969 {
970  return this->get_vector("weighted_sensitivity_solution");
971 }
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
bool libMesh::System::has_variable ( const std::string &  var) const
inherited
Returns
true if a variable named var exists in this System

Definition at line 1254 of file system.C.

References libMesh::System::_variable_numbers.

Referenced by libMesh::GMVIO::copy_nodal_solution(), and libMesh::System::project_solution_on_reinit().

1255 {
1256  return _variable_numbers.count(var);
1257 }
std::map< std::string, unsigned short int > _variable_numbers
Definition: system.h:1901
bool libMesh::ImplicitSystem::have_matrix ( const std::string &  mat_name) const
inlineinherited
Returns
true if this System has a matrix associated with the given name, false otherwise.

Definition at line 396 of file implicit_system.h.

Referenced by libMesh::ImplicitSystem::add_matrix(), and libMesh::EigenTimeSolver::init().

397 {
398  return (_matrices.count(mat_name));
399 }
std::map< std::string, SparseMatrix< Number > * > _matrices
bool libMesh::System::have_vector ( const std::string &  vec_name) const
inlineinherited
Returns
true if this System has a vector associated with the given name, false otherwise.

Definition at line 2204 of file system.h.

References libMesh::System::_vectors.

Referenced by libMesh::System::add_vector(), and libMesh::System::project_solution_on_reinit().

2205 {
2206  return (_vectors.count(vec_name));
2207 }
std::map< std::string, NumericVector< Number > * > _vectors
Definition: system.h:1914
bool& libMesh::System::hide_output ( )
inlineinherited
bool libMesh::System::identify_variable_groups ( ) const
inlineinherited
Returns
true when VariableGroup structures should be automatically identified, false otherwise.

Definition at line 2180 of file system.h.

References libMesh::System::_identify_variable_groups.

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

2181 {
2183 }
bool _identify_variable_groups
Definition: system.h:1956
void libMesh::System::identify_variable_groups ( const bool  ivg)
inlineinherited

Toggle automatic VariableGroup identification.

Definition at line 2188 of file system.h.

References libMesh::System::_identify_variable_groups.

2189 {
2191 }
bool _identify_variable_groups
Definition: system.h:1956
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectedinherited

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

Definition at line 185 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

186 {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189 
190  p.first++;
191 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
spin_mutex spin_mtx
Definition: threads.C:29
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectedinherited

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

Definition at line 198 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

199 {
200  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
201  std::pair<unsigned int, unsigned int> & p = _counts[name];
202 
203  p.second++;
204 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
spin_mutex spin_mtx
Definition: threads.C:29
void libMesh::System::init ( )
inherited

Initializes degrees of freedom on the current mesh. Sets the

Definition at line 233 of file system.C.

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

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

234 {
235  // Calling init() twice on the same system currently works evil
236  // magic, whether done directly or via EquationSystems::read()
237  libmesh_assert(!this->is_initialized());
238 
239  // First initialize any required data:
240  // either only the basic System data
241  if (_basic_system_only)
243  // or all the derived class' data too
244  else
245  this->init_data();
246 
247  // If no variables have been added to this system
248  // don't do anything
249  if (!this->n_vars())
250  return;
251 
252  // Then call the user-provided initialization function
253  this->user_initialization();
254 }
bool _basic_system_only
Definition: system.h:1944
virtual void init_data()
Definition: system.C:258
virtual void user_initialization()
Definition: system.C:1946
libmesh_assert(j)
bool is_initialized()
Definition: system.h:2068
unsigned int n_vars() const
Definition: system.h:2084
void libMesh::OptimizationSystem::init_data ( )
virtual

Initializes new data members of the system.

Reimplemented from libMesh::ImplicitSystem.

Definition at line 71 of file optimization_system.C.

References libMesh::System::add_vector(), libMesh::ImplicitSystem::init_data(), and optimization_solver.

Referenced by system().

72 {
73  this->add_vector("lower_bounds");
74  this->add_vector("upper_bounds");
75 
77 
78  optimization_solver->clear();
79 }
UniquePtr< OptimizationSolver< Number > > optimization_solver
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Definition: system.C:679
virtual void init_data() libmesh_override
void libMesh::ImplicitSystem::init_matrices ( )
protectedvirtualinherited

Initializes the matrices associated with this system.

Definition at line 107 of file implicit_system.C.

References libMesh::ImplicitSystem::_can_add_matrices, libMesh::ImplicitSystem::_matrices, 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::ImplicitSystem::matrix.

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

108 {
110 
111  // Check for quick return in case the system matrix
112  // (and by extension all the matrices) has already
113  // been initialized
114  if (matrix->initialized())
115  return;
116 
117  // Get a reference to the DofMap
118  DofMap & dof_map = this->get_dof_map();
119 
120  // no chance to add other matrices
121  _can_add_matrices = false;
122 
123  // Tell the matrices about the dof map, and vice versa
124  for (matrices_iterator pos = _matrices.begin();
125  pos != _matrices.end(); ++pos)
126  {
127  SparseMatrix<Number> & m = *(pos->second);
128  libmesh_assert (!m.initialized());
129 
130  // We want to allow repeated init() on systems, but we don't
131  // want to attach the same matrix to the DofMap twice
132  if (!dof_map.is_attached(m))
133  dof_map.attach_matrix (m);
134  }
135 
136  // Compute the sparsity pattern for the current
137  // mesh and DOF distribution. This also updates
138  // additional matrices, \p DofMap now knows them
139  dof_map.compute_sparsity (this->get_mesh());
140 
141  // Initialize matrices
142  for (matrices_iterator pos = _matrices.begin();
143  pos != _matrices.end(); ++pos)
144  pos->second->init ();
145 
146  // Set the additional matrices to 0.
147  for (matrices_iterator pos = _matrices.begin();
148  pos != _matrices.end(); ++pos)
149  pos->second->zero ();
150 }
std::map< std::string, SparseMatrix< Number > * > _matrices
libmesh_assert(j)
virtual bool initialized() const
const MeshBase & get_mesh() const
Definition: system.h:2012
const DofMap & get_dof_map() const
Definition: system.h:2028
SparseMatrix< Number > * matrix
std::map< std::string, SparseMatrix< Number > * >::iterator matrices_iterator
void libMesh::OptimizationSystem::initialize_equality_constraints_storage ( const std::vector< std::set< numeric_index_type > > &  constraint_jac_sparsity)

Initialize storage for the equality constraints, and the corresponding Jacobian. The length of constraint_jac_sparsity indicates the number of constraints that will be imposed, and n_dofs_per_constraint[i] gives the indices that are non-zero in row i of the Jacobian.

Definition at line 91 of file optimization_system.C.

References C_eq, C_eq_jac, libMesh::ParallelObject::comm(), eq_constraint_jac_sparsity, libMesh::System::get_dof_map(), initialize_inequality_constraints_storage(), lambda_eq, libMesh::System::n_dofs(), libMesh::System::n_local_dofs(), libMesh::PARALLEL, and libMesh::Parallel::Communicator::size().

Referenced by reinit(), and system().

92 {
93  unsigned int n_eq_constraints = constraint_jac_sparsity.size();
94 
95  // Assign rows to each processor as evenly as possible
96  unsigned int n_procs = comm().size();
97  unsigned int n_local_rows = n_eq_constraints / n_procs;
98  if (comm().rank() < (n_eq_constraints % n_procs))
99  n_local_rows++;
100 
101  C_eq->init(n_eq_constraints, n_local_rows, false, PARALLEL);
102  lambda_eq->init(n_eq_constraints, n_local_rows, false, PARALLEL);
103 
104  // Get the maximum number of non-zeros per row
105  unsigned int max_nnz = 0;
106  for (unsigned int i=0; i<n_eq_constraints; i++)
107  {
108  unsigned int nnz = constraint_jac_sparsity[i].size();
109  if (nnz > max_nnz)
110  max_nnz = nnz;
111  }
112 
113  C_eq_jac->init(n_eq_constraints,
114  get_dof_map().n_dofs(),
115  n_local_rows,
117  max_nnz,
118  max_nnz);
119 
120  eq_constraint_jac_sparsity = constraint_jac_sparsity;
121 }
unsigned int size() const
Definition: parallel.h:722
std::vector< std::set< numeric_index_type > > eq_constraint_jac_sparsity
UniquePtr< NumericVector< Number > > lambda_eq
const DofMap & get_dof_map() const
Definition: system.h:2028
UniquePtr< SparseMatrix< Number > > C_eq_jac
dof_id_type n_local_dofs() const
Definition: system.C:183
const Parallel::Communicator & comm() const
dof_id_type n_dofs() const
Definition: system.C:146
UniquePtr< NumericVector< Number > > C_eq
void libMesh::OptimizationSystem::initialize_inequality_constraints_storage ( const std::vector< std::set< numeric_index_type > > &  constraint_jac_sparsity)

Initialize storage for the inequality constraints, as per initialize_equality_constraints_storage.

Definition at line 125 of file optimization_system.C.

References C_ineq, C_ineq_jac, libMesh::ParallelObject::comm(), libMesh::System::get_dof_map(), ineq_constraint_jac_sparsity, lambda_ineq, libMesh::System::n_dofs(), libMesh::System::n_local_dofs(), libMesh::PARALLEL, and libMesh::Parallel::Communicator::size().

Referenced by initialize_equality_constraints_storage(), and system().

126 {
127  unsigned int n_ineq_constraints = constraint_jac_sparsity.size();
128 
129  // Assign rows to each processor as evenly as possible
130  unsigned int n_procs = comm().size();
131  unsigned int n_local_rows = n_ineq_constraints / n_procs;
132  if (comm().rank() < (n_ineq_constraints % n_procs))
133  n_local_rows++;
134 
135  C_ineq->init(n_ineq_constraints, n_local_rows, false, PARALLEL);
136  lambda_ineq->init(n_ineq_constraints, n_local_rows, false, PARALLEL);
137 
138  // Get the maximum number of non-zeros per row
139  unsigned int max_nnz = 0;
140  for (unsigned int i=0; i<n_ineq_constraints; i++)
141  {
142  unsigned int nnz = constraint_jac_sparsity[i].size();
143  if (nnz > max_nnz)
144  max_nnz = nnz;
145  }
146 
147  C_ineq_jac->init(n_ineq_constraints,
148  get_dof_map().n_dofs(),
149  n_local_rows,
151  max_nnz,
152  max_nnz);
153 
154  ineq_constraint_jac_sparsity = constraint_jac_sparsity;
155 }
unsigned int size() const
Definition: parallel.h:722
UniquePtr< NumericVector< Number > > lambda_ineq
const DofMap & get_dof_map() const
Definition: system.h:2028
std::vector< std::set< numeric_index_type > > ineq_constraint_jac_sparsity
dof_id_type n_local_dofs() const
Definition: system.C:183
const Parallel::Communicator & comm() const
dof_id_type n_dofs() const
Definition: system.C:146
UniquePtr< SparseMatrix< Number > > C_ineq_jac
UniquePtr< NumericVector< Number > > C_ineq
bool libMesh::System::is_initialized ( )
inlineinherited
Returns
true iff this system has been initialized.

Definition at line 2068 of file system.h.

References libMesh::System::_is_initialized.

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

2069 {
2070  return _is_initialized;
2071 }
bool _is_initialized
Definition: system.h:1950
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 1295 of file system.C.

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::DofMap::dof_indices(), libMesh::DofMap::end_dof(), libMesh::DofMap::first_dof(), libMesh::System::get_dof_map(), and libMesh::System::get_mesh().

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

1297 {
1298  // Make sure the set is clear
1299  var_indices.clear();
1300 
1301  std::vector<dof_id_type> dof_indices;
1302 
1303  // Begin the loop over the elements
1304  MeshBase::const_element_iterator el =
1306  const MeshBase::const_element_iterator end_el =
1308 
1309  const dof_id_type
1310  first_local = this->get_dof_map().first_dof(),
1311  end_local = this->get_dof_map().end_dof();
1312 
1313  for ( ; el != end_el; ++el)
1314  {
1315  const Elem * elem = *el;
1316  this->get_dof_map().dof_indices (elem, dof_indices, var);
1317 
1318  for (std::size_t i=0; i<dof_indices.size(); i++)
1319  {
1320  dof_id_type dof = dof_indices[i];
1321 
1322  //If the dof is owned by the local processor
1323  if (first_local <= dof && dof < end_local)
1324  var_indices.insert(dof_indices[i]);
1325  }
1326  }
1327 }
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:535
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:575
const MeshBase & get_mesh() const
Definition: system.h:2012
const DofMap & get_dof_map() const
Definition: system.h:2028
virtual element_iterator active_local_elements_begin()=0
virtual element_iterator active_local_elements_end()=0
uint8_t dof_id_type
Definition: id_types.h:64
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition: dof_map.C:2005
dof_id_type libMesh::System::n_active_dofs ( ) const
inlineinherited
Returns
The number of active degrees of freedom for this System.

Definition at line 2196 of file system.h.

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

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

2197 {
2198  return this->n_dofs() - this->n_constrained_dofs();
2199 }
dof_id_type n_constrained_dofs() const
Definition: system.C:153
dof_id_type n_dofs() const
Definition: system.C:146
unsigned int libMesh::System::n_components ( ) const
inlineinherited
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 2100 of file system.h.

References libMesh::System::_variables, libMesh::Variable::first_scalar_number(), and libMesh::Variable::n_components().

Referenced by libMesh::System::add_variables(), libMesh::WrappedFunction< Output >::operator()(), and libMesh::System::project_solution_on_reinit().

2101 {
2102  if (_variables.empty())
2103  return 0;
2104 
2105  const Variable & last = _variables.back();
2106  return last.first_scalar_number() + last.n_components();
2107 }
std::vector< Variable > _variables
Definition: system.h:1890
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 153 of file system.C.

References libMesh::System::_dof_map.

Referenced by libMesh::System::get_info(), libMesh::System::n_active_dofs(), and libMesh::System::project_solution_on_reinit().

154 {
155 #ifdef LIBMESH_ENABLE_CONSTRAINTS
156 
157  return _dof_map->n_constrained_dofs();
158 
159 #else
160 
161  return 0;
162 
163 #endif
164 }
UniquePtr< DofMap > _dof_map
Definition: system.h:1863
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 168 of file system.C.

References libMesh::System::_dof_map.

Referenced by libMesh::System::get_info(), and libMesh::System::project_solution_on_reinit().

169 {
170 #ifdef LIBMESH_ENABLE_CONSTRAINTS
171 
172  return _dof_map->n_local_constrained_dofs();
173 
174 #else
175 
176  return 0;
177 
178 #endif
179 }
UniquePtr< DofMap > _dof_map
Definition: system.h:1863
unsigned int libMesh::ImplicitSystem::n_matrices ( ) const
inlinevirtualinherited
Returns
The number of matrices handled by this system

Reimplemented from libMesh::System.

Definition at line 403 of file implicit_system.h.

References libMesh::ImplicitSystem::_matrices.

404 {
405  return cast_int<unsigned int>(_matrices.size());
406 }
std::map< std::string, SparseMatrix< Number > * > _matrices
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

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

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::MeshCommunication::broadcast(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::get_solution(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), 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::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_nodes(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

94  { return cast_int<processor_id_type>(_communicator.size()); }
unsigned int size() const
Definition: parallel.h:722
const Parallel::Communicator & _communicator
unsigned int libMesh::System::n_variable_groups ( ) const
inlineinherited
Returns
The number of VariableGroup variable groups in the system

Definition at line 2092 of file system.h.

References libMesh::System::_variable_groups.

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

2093 {
2094  return cast_int<unsigned int>(_variable_groups.size());
2095 }
std::vector< VariableGroup > _variable_groups
Definition: system.h:1895
unsigned int libMesh::System::n_vars ( ) const
inlineinherited
Returns
The number of variables in the system

Definition at line 2084 of file system.h.

References libMesh::System::_variables.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::DiffContext::add_localized_vector(), libMesh::System::add_variable(), libMesh::System::add_variables(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::System::calculate_norm(), libMesh::WrappedFunction< Output >::component(), 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::System::get_all_variable_numbers(), libMesh::EquationSystems::get_solution(), libMesh::System::init(), libMesh::FEMSystem::init_context(), libMesh::OldSolutionValue< Output, point_output >::init_context(), libMesh::FEMContext::init_internal_data(), libMesh::DGFEMContext::neighbor_side_fe_reinit(), libMesh::WrappedFunction< Output >::operator()(), libMesh::petsc_auto_fieldsplit(), libMesh::FEMContext::pre_fe_reinit(), libMesh::System::project_solution_on_reinit(), libMesh::System::re_update(), libMesh::System::reinit(), libMesh::HPCoarsenTest::select_refinement(), libMesh::SystemSubsetBySubdomain::set_var_nums(), and libMesh::System::zero_variable().

2085 {
2086  return cast_int<unsigned int>(_variables.size());
2087 }
std::vector< Variable > _variables
Definition: system.h:1890
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 2212 of file system.h.

References libMesh::System::_vectors.

Referenced by libMesh::ExplicitSystem::add_system_rhs(), libMesh::System::compare(), libMesh::System::get_info(), and libMesh::System::project_solution_on_reinit().

2213 {
2214  return cast_int<unsigned int>(_vectors.size());
2215 }
std::map< std::string, NumericVector< Number > * > _vectors
Definition: system.h:1914
Gradient libMesh::System::point_gradient ( unsigned int  var,
const Point p,
const bool  insist_on_success = true 
) 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 2133 of file system.C.

References libMesh::Parallel::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::PointLocatorBase::enable_out_of_mesh_mode(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::MeshBase::is_serial(), libMesh::libmesh_assert(), mesh, libMesh::Parallel::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), libMesh::MeshBase::sub_point_locator(), and libMesh::Parallel::verify().

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

2134 {
2135  // This function must be called on every processor; there's no
2136  // telling where in the partition p falls.
2137  parallel_object_only();
2138 
2139  // And every processor had better agree about which point we're
2140  // looking for
2141 #ifndef NDEBUG
2142  libmesh_assert(this->comm().verify(p(0)));
2143 #if LIBMESH_DIM > 1
2144  libmesh_assert(this->comm().verify(p(1)));
2145 #endif
2146 #if LIBMESH_DIM > 2
2147  libmesh_assert(this->comm().verify(p(2)));
2148 #endif
2149 #endif // NDEBUG
2150 
2151  // Get a reference to the mesh object associated with the system object that calls this function
2152  const MeshBase & mesh = this->get_mesh();
2153 
2154  // Use an existing PointLocator or create a new one
2155  UniquePtr<PointLocatorBase> locator_ptr = mesh.sub_point_locator();
2156  PointLocatorBase & locator = *locator_ptr;
2157 
2158  if (!insist_on_success || !mesh.is_serial())
2159  locator.enable_out_of_mesh_mode();
2160 
2161  // Get a pointer to the element that contains P
2162  const Elem * e = locator(p);
2163 
2164  Gradient grad_u;
2165 
2166  if (e && this->get_dof_map().is_evaluable(*e, var))
2167  grad_u = point_gradient(var, p, *e);
2168 
2169  // If I have an element containing p, then let's let everyone know
2170  processor_id_type lowest_owner =
2171  (e && (e->processor_id() == this->processor_id())) ?
2172  this->processor_id() : this->n_processors();
2173  this->comm().min(lowest_owner);
2174 
2175  // Everybody should get their value from a processor that was able
2176  // to compute it.
2177  // If nobody admits owning the point, we may have a problem.
2178  if (lowest_owner != this->n_processors())
2179  this->comm().broadcast(grad_u, lowest_owner);
2180  else
2181  libmesh_assert(!insist_on_success);
2182 
2183  return grad_u;
2184 }
processor_id_type n_processors() const
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
libmesh_assert(j)
const MeshBase & get_mesh() const
Definition: system.h:2012
const DofMap & get_dof_map() const
Definition: system.h:2028
NumberVectorValue Gradient
void broadcast(T &data, const unsigned int root_id=0) const
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2133
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
processor_id_type processor_id() const
Gradient libMesh::System::point_gradient ( unsigned int  var,
const Point p,
const Elem e 
) 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 2187 of file system.C.

References libMesh::TypeVector< T >::add_scaled(), libMesh::FEGenericBase< OutputType >::build(), libMesh::Elem::contains_point(), libMesh::System::current_solution(), libMesh::Elem::dim(), libMesh::System::get_dof_map(), libMesh::FEInterface::inverse_map(), and libMesh::libmesh_assert().

2188 {
2189  // Ensuring that the given point is really in the element is an
2190  // expensive assert, but as long as debugging is turned on we might
2191  // as well try to catch a particularly nasty potential error
2192  libmesh_assert (e.contains_point(p));
2193 
2194  // Get the dof map to get the proper indices for our computation
2195  const DofMap & dof_map = this->get_dof_map();
2196 
2197  // Make sure we can evaluate on this element.
2198  libmesh_assert (dof_map.is_evaluable(e, var));
2199 
2200  // Need dof_indices for phi[i][j]
2201  std::vector<dof_id_type> dof_indices;
2202 
2203  // Fill in the dof_indices for our element
2204  dof_map.dof_indices (&e, dof_indices, var);
2205 
2206  // Get the no of dofs associated with this point
2207  const unsigned int num_dofs = cast_int<unsigned int>
2208  (dof_indices.size());
2209 
2210  FEType fe_type = dof_map.variable_type(var);
2211 
2212  // Build a FE again so we can calculate u(p)
2213  UniquePtr<FEBase> fe (FEBase::build(e.dim(), fe_type));
2214 
2215  // Map the physical co-ordinates to the master co-ordinates using the inverse_map from fe_interface.h
2216  // Build a vector of point co-ordinates to send to reinit
2217  std::vector<Point> coor(1, FEInterface::inverse_map(e.dim(), fe_type, &e, p));
2218 
2219  // Get the values of the shape function derivatives
2220  const std::vector<std::vector<RealGradient> > & dphi = fe->get_dphi();
2221 
2222  // Reinitialize the element and compute the shape function values at coor
2223  fe->reinit (&e, &coor);
2224 
2225  // Get ready to accumulate a gradient
2226  Gradient grad_u;
2227 
2228  for (unsigned int l=0; l<num_dofs; l++)
2229  {
2230  grad_u.add_scaled (dphi[l][0], this->current_solution (dof_indices[l]));
2231  }
2232 
2233  return grad_u;
2234 }
void add_scaled(const TypeVector< T2 > &, const T)
Definition: type_vector.h:620
libmesh_assert(j)
const DofMap & get_dof_map() const
Definition: system.h:2028
NumberVectorValue Gradient
static Point inverse_map(const unsigned int dim, const FEType &fe_t, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true)
Definition: fe_interface.C:556
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:190
static UniquePtr< FEGenericBase > build(const unsigned int dim, const FEType &type)
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 2238 of file system.C.

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

2239 {
2240  libmesh_assert(e);
2241  return this->point_gradient(var, p, *e);
2242 }
libmesh_assert(j)
Gradient point_gradient(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2133
Tensor libMesh::System::point_hessian ( unsigned int  var,
const Point p,
const bool  insist_on_success = true 
) 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 2248 of file system.C.

References libMesh::Parallel::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::PointLocatorBase::enable_out_of_mesh_mode(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::MeshBase::is_serial(), libMesh::libmesh_assert(), mesh, libMesh::Parallel::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), libMesh::MeshBase::sub_point_locator(), and libMesh::Parallel::verify().

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

2249 {
2250  // This function must be called on every processor; there's no
2251  // telling where in the partition p falls.
2252  parallel_object_only();
2253 
2254  // And every processor had better agree about which point we're
2255  // looking for
2256 #ifndef NDEBUG
2257  libmesh_assert(this->comm().verify(p(0)));
2258 #if LIBMESH_DIM > 1
2259  libmesh_assert(this->comm().verify(p(1)));
2260 #endif
2261 #if LIBMESH_DIM > 2
2262  libmesh_assert(this->comm().verify(p(2)));
2263 #endif
2264 #endif // NDEBUG
2265 
2266  // Get a reference to the mesh object associated with the system object that calls this function
2267  const MeshBase & mesh = this->get_mesh();
2268 
2269  // Use an existing PointLocator or create a new one
2270  UniquePtr<PointLocatorBase> locator_ptr = mesh.sub_point_locator();
2271  PointLocatorBase & locator = *locator_ptr;
2272 
2273  if (!insist_on_success || !mesh.is_serial())
2274  locator.enable_out_of_mesh_mode();
2275 
2276  // Get a pointer to the element that contains P
2277  const Elem * e = locator(p);
2278 
2279  Tensor hess_u;
2280 
2281  if (e && this->get_dof_map().is_evaluable(*e, var))
2282  hess_u = point_hessian(var, p, *e);
2283 
2284  // If I have an element containing p, then let's let everyone know
2285  processor_id_type lowest_owner =
2286  (e && (e->processor_id() == this->processor_id())) ?
2287  this->processor_id() : this->n_processors();
2288  this->comm().min(lowest_owner);
2289 
2290  // Everybody should get their value from a processor that was able
2291  // to compute it.
2292  // If nobody admits owning the point, we may have a problem.
2293  if (lowest_owner != this->n_processors())
2294  this->comm().broadcast(hess_u, lowest_owner);
2295  else
2296  libmesh_assert(!insist_on_success);
2297 
2298  return hess_u;
2299 }
processor_id_type n_processors() const
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
libmesh_assert(j)
const MeshBase & get_mesh() const
Definition: system.h:2012
const DofMap & get_dof_map() const
Definition: system.h:2028
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2248
void broadcast(T &data, const unsigned int root_id=0) const
bool verify(const T &r, const Communicator &comm=Communicator_World)
NumberTensorValue Tensor
const Parallel::Communicator & comm() const
processor_id_type processor_id() const
Tensor libMesh::System::point_hessian ( unsigned int  var,
const Point p,
const Elem e 
) 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 2301 of file system.C.

References libMesh::TypeTensor< T >::add_scaled(), libMesh::FEGenericBase< OutputType >::build(), libMesh::Elem::contains_point(), libMesh::System::current_solution(), libMesh::Elem::dim(), libMesh::System::get_dof_map(), libMesh::FEInterface::inverse_map(), and libMesh::libmesh_assert().

2302 {
2303  // Ensuring that the given point is really in the element is an
2304  // expensive assert, but as long as debugging is turned on we might
2305  // as well try to catch a particularly nasty potential error
2306  libmesh_assert (e.contains_point(p));
2307 
2308  // Get the dof map to get the proper indices for our computation
2309  const DofMap & dof_map = this->get_dof_map();
2310 
2311  // Make sure we can evaluate on this element.
2312  libmesh_assert (dof_map.is_evaluable(e, var));
2313 
2314  // Need dof_indices for phi[i][j]
2315  std::vector<dof_id_type> dof_indices;
2316 
2317  // Fill in the dof_indices for our element
2318  dof_map.dof_indices (&e, dof_indices, var);
2319 
2320  // Get the no of dofs associated with this point
2321  const unsigned int num_dofs = cast_int<unsigned int>
2322  (dof_indices.size());
2323 
2324  FEType fe_type = dof_map.variable_type(var);
2325 
2326  // Build a FE again so we can calculate u(p)
2327  UniquePtr<FEBase> fe (FEBase::build(e.dim(), fe_type));
2328 
2329  // Map the physical co-ordinates to the master co-ordinates using the inverse_map from fe_interface.h
2330  // Build a vector of point co-ordinates to send to reinit
2331  std::vector<Point> coor(1, FEInterface::inverse_map(e.dim(), fe_type, &e, p));
2332 
2333  // Get the values of the shape function derivatives
2334  const std::vector<std::vector<RealTensor> > & d2phi = fe->get_d2phi();
2335 
2336  // Reinitialize the element and compute the shape function values at coor
2337  fe->reinit (&e, &coor);
2338 
2339  // Get ready to accumulate a hessian
2340  Tensor hess_u;
2341 
2342  for (unsigned int l=0; l<num_dofs; l++)
2343  {
2344  hess_u.add_scaled (d2phi[l][0], this->current_solution (dof_indices[l]));
2345  }
2346 
2347  return hess_u;
2348 }
void add_scaled(const TypeTensor< T2 > &, const T)
Definition: type_tensor.h:773
libmesh_assert(j)
const DofMap & get_dof_map() const
Definition: system.h:2028
static Point inverse_map(const unsigned int dim, const FEType &fe_t, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true)
Definition: fe_interface.C:556
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:190
NumberTensorValue Tensor
static UniquePtr< FEGenericBase > build(const unsigned int dim, const FEType &type)
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 2352 of file system.C.

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

2353 {
2354  libmesh_assert(e);
2355  return this->point_hessian(var, p, *e);
2356 }
libmesh_assert(j)
Tensor point_hessian(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2248
Number libMesh::System::point_value ( unsigned int  var,
const Point p,
const bool  insist_on_success = true 
) 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.
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 2021 of file system.C.

References libMesh::Parallel::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::PointLocatorBase::enable_out_of_mesh_mode(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::MeshBase::is_serial(), libMesh::libmesh_assert(), mesh, libMesh::Parallel::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), libMesh::MeshBase::sub_point_locator(), and libMesh::Parallel::verify().

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

2022 {
2023  // This function must be called on every processor; there's no
2024  // telling where in the partition p falls.
2025  parallel_object_only();
2026 
2027  // And every processor had better agree about which point we're
2028  // looking for
2029 #ifndef NDEBUG
2030  libmesh_assert(this->comm().verify(p(0)));
2031 #if LIBMESH_DIM > 1
2032  libmesh_assert(this->comm().verify(p(1)));
2033 #endif
2034 #if LIBMESH_DIM > 2
2035  libmesh_assert(this->comm().verify(p(2)));
2036 #endif
2037 #endif // NDEBUG
2038 
2039  // Get a reference to the mesh object associated with the system object that calls this function
2040  const MeshBase & mesh = this->get_mesh();
2041 
2042  // Use an existing PointLocator or create a new one
2043  UniquePtr<PointLocatorBase> locator_ptr = mesh.sub_point_locator();
2044  PointLocatorBase & locator = *locator_ptr;
2045 
2046  if (!insist_on_success || !mesh.is_serial())
2047  locator.enable_out_of_mesh_mode();
2048 
2049  // Get a pointer to the element that contains P
2050  const Elem * e = locator(p);
2051 
2052  Number u = 0;
2053 
2054  if (e && this->get_dof_map().is_evaluable(*e, var))
2055  u = point_value(var, p, *e);
2056 
2057  // If I have an element containing p, then let's let everyone know
2058  processor_id_type lowest_owner =
2059  (e && (e->processor_id() == this->processor_id())) ?
2060  this->processor_id() : this->n_processors();
2061  this->comm().min(lowest_owner);
2062 
2063  // Everybody should get their value from a processor that was able
2064  // to compute it.
2065  // If nobody admits owning the point, we have a problem.
2066  if (lowest_owner != this->n_processors())
2067  this->comm().broadcast(u, lowest_owner);
2068  else
2069  libmesh_assert(!insist_on_success);
2070 
2071  return u;
2072 }
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2021
processor_id_type n_processors() const
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
libmesh_assert(j)
const MeshBase & get_mesh() const
Definition: system.h:2012
const DofMap & get_dof_map() const
Definition: system.h:2028
void broadcast(T &data, const unsigned int root_id=0) const
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
processor_id_type processor_id() const
Number libMesh::System::point_value ( unsigned int  var,
const Point p,
const Elem e 
) const
inherited
Returns
The value of the solution variable var at the physical point p contained in local Elem e

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

References libMesh::FEGenericBase< OutputType >::build(), libMesh::Elem::contains_point(), libMesh::System::current_solution(), libMesh::Elem::dim(), libMesh::System::get_dof_map(), libMesh::FEInterface::inverse_map(), and libMesh::libmesh_assert().

2075 {
2076  // Ensuring that the given point is really in the element is an
2077  // expensive assert, but as long as debugging is turned on we might
2078  // as well try to catch a particularly nasty potential error
2079  libmesh_assert (e.contains_point(p));
2080 
2081  // Get the dof map to get the proper indices for our computation
2082  const DofMap & dof_map = this->get_dof_map();
2083 
2084  // Make sure we can evaluate on this element.
2085  libmesh_assert (dof_map.is_evaluable(e, var));
2086 
2087  // Need dof_indices for phi[i][j]
2088  std::vector<dof_id_type> dof_indices;
2089 
2090  // Fill in the dof_indices for our element
2091  dof_map.dof_indices (&e, dof_indices, var);
2092 
2093  // Get the no of dofs associated with this point
2094  const unsigned int num_dofs = cast_int<unsigned int>
2095  (dof_indices.size());
2096 
2097  FEType fe_type = dof_map.variable_type(var);
2098 
2099  // Build a FE so we can calculate u(p)
2100  UniquePtr<FEBase> fe (FEBase::build(e.dim(), fe_type));
2101 
2102  // Map the physical co-ordinates to the master co-ordinates using the inverse_map from fe_interface.h
2103  // Build a vector of point co-ordinates to send to reinit
2104  std::vector<Point> coor(1, FEInterface::inverse_map(e.dim(), fe_type, &e, p));
2105 
2106  // Get the shape function values
2107  const std::vector<std::vector<Real> > & phi = fe->get_phi();
2108 
2109  // Reinitialize the element and compute the shape function values at coor
2110  fe->reinit (&e, &coor);
2111 
2112  // Get ready to accumulate a value
2113  Number u = 0;
2114 
2115  for (unsigned int l=0; l<num_dofs; l++)
2116  {
2117  u += phi[l][0]*this->current_solution (dof_indices[l]);
2118  }
2119 
2120  return u;
2121 }
libmesh_assert(j)
const DofMap & get_dof_map() const
Definition: system.h:2028
static Point inverse_map(const unsigned int dim, const FEType &fe_t, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true)
Definition: fe_interface.C:556
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:190
static UniquePtr< FEGenericBase > build(const unsigned int dim, const FEType &type)
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 2125 of file system.C.

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

2126 {
2127  libmesh_assert(e);
2128  return this->point_value(var, p, *e);
2129 }
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2021
libmesh_assert(j)
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

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

Definition at line 88 of file reference_counter.C.

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

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

89 {
91  out_stream << ReferenceCounter::get_info();
92 }
static std::string get_info()
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
The rank of this processor in the group.

Definition at line 99 of file parallel_object.h.

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

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshRefinement::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::MeshCommunication::broadcast(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::ParmetisPartitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DofMap::build_sparsity(), libMesh::DistributedMesh::clear(), 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::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::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), 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::Nemesis_IO_Helper::get_loadbal_param(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::EquationSystems::get_solution(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), 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::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MetisPartitioner::partition_range(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NumericVector< T >::print_global(), 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::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::CheckpointIO::read_header(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::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_elements(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), 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::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

100  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
unsigned int rank() const
Definition: parallel.h:720
void libMesh::System::project_solution ( FunctionBase< Number > *  f,
FunctionBase< Gradient > *  g = libmesh_nullptr 
) const
inherited

Projects arbitrary functions onto the current solution. The function value f and its gradient g are user-provided cloneable functors. A gradient g is only required/used for projecting onto finite element spaces with continuous derivatives. If non-default Parameters are to be used, they can be provided in the parameters argument.

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

Definition at line 811 of file system_projection.C.

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

813 {
814  this->project_vector(*solution, f, g);
815 
816  solution->localize(*current_local_solution, _dof_map->get_send_list());
817 }
UniquePtr< NumericVector< Number > > current_local_solution
Definition: system.h:1533
UniquePtr< DofMap > _dof_map
Definition: system.h:1863
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1521
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
void libMesh::System::project_solution ( FEMFunctionBase< Number > *  f,
FEMFunctionBase< Gradient > *  g = libmesh_nullptr 
) const
inherited

Projects arbitrary functions onto the current solution. The function value f and its gradient g are user-provided cloneable functors. A gradient g is only required/used for projecting onto finite element spaces with continuous derivatives. If non-default Parameters are to be used, they can be provided in the parameters argument.

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

Definition at line 824 of file system_projection.C.

References libMesh::System::project_vector().

826 {
827  this->project_vector(*solution, f, g);
828 
829  solution->localize(*current_local_solution, _dof_map->get_send_list());
830 }
UniquePtr< NumericVector< Number > > current_local_solution
Definition: system.h:1533
UniquePtr< DofMap > _dof_map
Definition: system.h:1863
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1521
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
void libMesh::System::project_solution ( Number   fptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
Gradient   gptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
const Parameters parameters 
) const
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.

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

References libMesh::System::_solution_projection, libMesh::System::add_adjoint_rhs(), libMesh::System::add_adjoint_solution(), libMesh::System::add_sensitivity_rhs(), libMesh::System::add_sensitivity_solution(), libMesh::System::add_variable(), libMesh::System::add_variables(), libMesh::System::add_weighted_sensitivity_adjoint_solution(), libMesh::System::add_weighted_sensitivity_solution(), libMesh::System::calculate_norm(), libMesh::FIRST, libMesh::System::get_adjoint_rhs(), libMesh::System::get_adjoint_solution(), libMesh::System::get_all_variable_numbers(), libMesh::System::get_sensitivity_rhs(), libMesh::System::get_sensitivity_solution(), libMesh::System::get_vector(), libMesh::System::get_weighted_sensitivity_adjoint_solution(), libMesh::System::get_weighted_sensitivity_solution(), libMesh::System::has_variable(), libMesh::System::have_vector(), libMesh::System::identify_variable_groups(), libMesh::LAGRANGE, libmesh_nullptr, libMesh::System::n_active_dofs(), libMesh::System::n_components(), libMesh::System::n_constrained_dofs(), libMesh::System::n_dofs(), libMesh::System::n_local_constrained_dofs(), libMesh::System::n_local_dofs(), libMesh::System::n_matrices(), libMesh::System::n_variable_groups(), libMesh::System::n_vars(), libMesh::System::n_vectors(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::System::read_serialized_data(), libMesh::Real, libMesh::System::request_vector(), libMesh::System::set_vector_as_adjoint(), libMesh::System::set_vector_preservation(), libMesh::System::variable(), libMesh::System::variable_group(), libMesh::System::variable_name(), libMesh::System::variable_number(), libMesh::System::variable_scalar_number(), libMesh::System::variable_type(), libMesh::System::vector_is_adjoint(), libMesh::System::vector_name(), and libMesh::System::vector_preservation().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), and libMesh::MemorySolutionHistory::store().

795  { return _solution_projection; }
bool _solution_projection
Definition: system.h:1938
void libMesh::System::project_vector ( NumericVector< Number > &  new_vector,
FunctionBase< Number > *  f,
FunctionBase< Gradient > *  g = libmesh_nullptr,
int  is_adjoint = -1 
) const
inherited

Projects arbitrary functions onto a vector of degree of freedom values for the current system. The function value f and its gradient g are user-provided cloneable functors. A gradient g is only required/used for projecting onto finite element spaces with continuous derivatives. If non-default Parameters are to be used, they can be provided in the parameters argument.

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

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

Definition at line 858 of file system_projection.C.

References libMesh::libmesh_assert(), and libmesh_nullptr.

Referenced by libMesh::System::hide_output(), libMesh::NewmarkSolver::project_initial_accel(), libMesh::SecondOrderUnsteadySolver::project_initial_rate(), libMesh::System::project_solution(), libMesh::System::project_vector(), libMesh::System::restrict_vectors(), and libMesh::System::system_type().

862 {
863  LOG_SCOPE ("project_vector(FunctionBase)", "System");
864 
865  libmesh_assert(f);
866 
867  WrappedFunctor<Number> f_fem(*f);
868 
869  if (g)
870  {
871  WrappedFunctor<Gradient> g_fem(*g);
872 
873  this->project_vector(new_vector, &f_fem, &g_fem, is_adjoint);
874  }
875  else
876  this->project_vector(new_vector, &f_fem, libmesh_nullptr, is_adjoint);
877 }
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
void libMesh::System::project_vector ( NumericVector< Number > &  new_vector,
FEMFunctionBase< Number > *  f,
FEMFunctionBase< Gradient > *  g = libmesh_nullptr,
int  is_adjoint = -1 
) const
inherited

Projects arbitrary functions onto a vector of degree of freedom values for the current system. The function value f and its gradient g are user-provided cloneable functors. A gradient g is only required/used for projecting onto finite element spaces with continuous derivatives. If non-default Parameters are to be used, they can be provided in the parameters argument.

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

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

Definition at line 884 of file system_projection.C.

References libMesh::System::boundary_project_solution(), libMesh::NumericVector< T >::close(), libMesh::FEMFunctionBase< Output >::component(), libMesh::get_dof_map(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::n_processors(), n_vars, libMesh::Threads::parallel_for(), libMesh::FEMContext::pre_fe_reinit(), libMesh::processor_id(), libMesh::SCALAR, libMesh::DofMap::SCALAR_dof_indices(), libMesh::NumericVector< T >::set(), and libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::variables.

888 {
889  LOG_SCOPE ("project_fem_vector()", "System");
890 
891  libmesh_assert (f);
892 
893  ConstElemRange active_local_range
894  (this->get_mesh().active_local_elements_begin(),
895  this->get_mesh().active_local_elements_end() );
896 
897  VectorSetAction<Number> setter(new_vector);
898 
899  const unsigned int n_variables = this->n_vars();
900 
901  std::vector<unsigned int> vars(n_variables);
902  for (unsigned int i=0; i != n_variables; ++i)
903  vars[i] = i;
904 
905  // Use a typedef to make the calling sequence for parallel_for() a bit more readable
906  typedef
907  GenericProjector<FEMFunctionWrapper<Number>, FEMFunctionWrapper<Gradient>,
908  Number, VectorSetAction<Number> > FEMProjector;
909 
910  FEMFunctionWrapper<Number> fw(*f);
911 
912  if (g)
913  {
914  FEMFunctionWrapper<Gradient> gw(*g);
915 
917  (active_local_range,
918  FEMProjector(*this, fw, &gw, setter, vars));
919  }
920  else
922  (active_local_range,
923  FEMProjector(*this, fw, libmesh_nullptr, setter, vars));
924 
925  // Also, load values into the SCALAR dofs
926  // Note: We assume that all SCALAR dofs are on the
927  // processor with highest ID
928  if (this->processor_id() == (this->n_processors()-1))
929  {
930  // FIXME: Do we want to first check for SCALAR vars before building this? [PB]
931  FEMContext context( *this );
932 
933  const DofMap & dof_map = this->get_dof_map();
934  for (unsigned int var=0; var<this->n_vars(); var++)
935  if (this->variable(var).type().family == SCALAR)
936  {
937  // FIXME: We reinit with an arbitrary element in case the user
938  // doesn't override FEMFunctionBase::component. Is there
939  // any use case we're missing? [PB]
940  Elem * el = const_cast<Elem *>(*(this->get_mesh().active_local_elements_begin()));
941  context.pre_fe_reinit(*this, el);
942 
943  std::vector<dof_id_type> SCALAR_indices;
944  dof_map.SCALAR_dof_indices (SCALAR_indices, var);
945  const unsigned int n_SCALAR_dofs =
946  cast_int<unsigned int>(SCALAR_indices.size());
947 
948  for (unsigned int i=0; i<n_SCALAR_dofs; i++)
949  {
950  const dof_id_type global_index = SCALAR_indices[i];
951  const unsigned int component_index =
952  this->variable_scalar_number(var,i);
953 
954  new_vector.set(global_index, f->component(context, component_index, Point(), this->time));
955  }
956  }
957  }
958 
959  new_vector.close();
960 
961 #ifdef LIBMESH_ENABLE_CONSTRAINTS
962  if (is_adjoint == -1)
963  this->get_dof_map().enforce_constraints_exactly(*this, &new_vector);
964  else if (is_adjoint >= 0)
966  is_adjoint);
967 #endif
968 }
FEFamily family
Definition: fe_type.h:203
const FEType & type() const
Definition: variable.h:119
void parallel_for(const Range &range, const Body &body)
Definition: threads_none.h:73
processor_id_type n_processors() const
const class libmesh_nullptr_t libmesh_nullptr
StoredRange< MeshBase::const_element_iterator, const Elem * > ConstElemRange
Definition: elem_range.h:34
libmesh_assert(j)
const MeshBase & get_mesh() const
Definition: system.h:2012
const DofMap & get_dof_map() const
Definition: system.h:2028
const Variable & variable(unsigned int var) const
Definition: system.h:2112
virtual element_iterator active_local_elements_begin()=0
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
virtual void close()=0
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
Definition: system.h:2143
unsigned int n_vars() const
Definition: system.h:2084
virtual void set(const numeric_index_type i, const T value)=0
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
uint8_t dof_id_type
Definition: id_types.h:64
processor_id_type processor_id() const
void libMesh::System::project_vector ( Number   fptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
Gradient   gptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name,
const Parameters parameters,
NumericVector< Number > &  new_vector,
int  is_adjoint = -1 
) const
inherited

Projects arbitrary functions onto a vector of degree of freedom values for the current system. The function value fptr and its gradient gptr are represented by function pointers. A gradient gptr is only required/used for projecting onto finite element spaces with continuous derivatives.

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

void libMesh::System::project_vector ( NumericVector< Number > &  vector,
int  is_adjoint = -1 
) 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 576 of file system_projection.C.

References libMesh::NumericVector< T >::build(), libMesh::NumericVector< T >::clear(), libMesh::NumericVector< T >::clone(), libMesh::NumericVector< T >::close(), libMesh::NumericVector< T >::get(), libMesh::get_dof_map(), libMesh::GHOSTED, libMesh::NumericVector< T >::init(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::NumericVector< T >::local_size(), libMesh::NumericVector< T >::localize(), libMesh::n_processors(), n_vars, libMesh::PARALLEL, libMesh::Threads::parallel_for(), libMesh::Threads::parallel_reduce(), libMesh::processor_id(), libMesh::System::project_solution(), libMesh::System::project_vector(), 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(), and libMesh::BuildProjectionList::unique().

578 {
579  // Create a copy of the vector, which currently
580  // contains the old data.
581  UniquePtr<NumericVector<Number> >
582  old_vector (vector.clone());
583 
584  // Project the old vector to the new vector
585  this->project_vector (*old_vector, vector, is_adjoint);
586 }
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr, int is_adjoint=-1) const
virtual UniquePtr< NumericVector< T > > clone() const =0
void libMesh::System::project_vector ( const NumericVector< Number > &  ,
NumericVector< Number > &  ,
int  is_adjoint = -1 
) const
protectedinherited

Projects the vector defined on the old mesh onto the new mesh. 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.

void libMesh::System::prolong_vectors ( )