📄 system.h
字号:
// $Id: system.h 2789 2008-04-13 02:24:40Z roystgnr $// The libMesh Finite Element Library.// Copyright (C) 2002-2007 Benjamin S. Kirk, John W. Peterson // This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version. // This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details. // You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef __system_h__#define __system_h__// C++ includes#include <vector>// Local Includes#include "auto_ptr.h"#include "enum_xdr_mode.h"#include "fe_type.h"#include "libmesh_common.h"#include "reference_counted_object.h"#include "system_norm.h"#include "elem_range.h"// Forward Declarationsclass System;class EquationSystems;class MeshBase;class Xdr;class DofMap;class Parameters;class Point;template <typename T> class NumericVector;template <typename T> class VectorValue;typedef VectorValue<Number> NumberVectorValue;typedef NumberVectorValue Gradient;/** * This is the base class for classes which contain * information related to any physical process that might be simulated. * Such information may range from the actual solution values to * algorithmic flags that may be used to control the numerical methods * employed. In general, use an \p EqnSystems<T_sys> object to handle * one or more of the children of this class. * Note that templating \p EqnSystems relaxes the use of virtual members. * * @author Benjamin S. Kirk, 2003-2004. */// ------------------------------------------------------------// System class definitionclass System : public ReferenceCountedObject<System>{protected: /** * Constructor. Optionally initializes required * data structures. Protected so that this base class * cannot be explicitly instantiated. */ System (EquationSystems& es, const std::string& name, const unsigned int number); public: /** * Destructor. */ virtual ~System (); /** * The type of system. */ typedef System sys_type; /** * @returns a clever pointer to the system. */ sys_type & system () { return *this; } /** * Clear all the data structures associated with * the system. */ virtual void clear (); /** * Initializes degrees of freedom on the current mesh. * Sets the */ void init (); /** * Reinitializes degrees of freedom and other * required data on the current mesh. Note that the matrix * is not initialized at this time since it may not be required * for all applications. @e Should be overloaded in derived classes. */ virtual void reinit (); /** * Update the local values to reflect the solution * on neighboring processors. */ virtual void update (); /** * Prepares \p matrix and \p _dof_map for matrix assembly. * Does not actually assemble anything. For matrix assembly, * use the \p assemble() in derived classes. * @e Should be overloaded in derived classes. */ virtual void assemble (); /** * Solves the system. Must be overloaded in derived systems. */ virtual void solve () = 0; /** * @returns \p true when the other system contains * identical data, up to the given threshold. Outputs * some diagnostic info when \p verbose is set. */ virtual bool compare (const System& other_system, const Real threshold, const bool verbose) const; /** * @returns the system name. */ const std::string & name () const; /** * @returns the type of system, helpful in identifying * which system type to use when reading equation system * data from file. Should be overloaded in derived classes. */ virtual std::string system_type () const { return "BasicSystem"; } /** * Projects the continuous functions onto the current solution. */ 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), Parameters& parameters) const; /** * Projects the continuous functions onto the current mesh. */ 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), Parameters& parameters, NumericVector<Number>& new_vector) const; /** * @returns the system number. */ unsigned int number () const; /** * Fill the input vector \p global_soln so that it contains * the global solution on all processors. * Requires communication with all other processors. */ void update_global_solution (std::vector<Number>& global_soln) const; /** * Fill the input vector \p global_soln so that it contains * the global solution on processor \p dest_proc. * Requires communication with all other processors. */ void update_global_solution (std::vector<Number>& global_soln, const unsigned int dest_proc) const; /** * @returns a constant reference to this systems's \p _mesh. */ const MeshBase & get_mesh() const; /** * @returns a reference to this systems's \p _mesh. */ MeshBase & get_mesh(); /** * @returns a constant reference to this system's \p _dof_map. */ const DofMap & get_dof_map() const; /** * @returns a writeable reference to this system's \p _dof_map. */ DofMap & get_dof_map(); /** * @returns a constant reference to this system's parent EquationSystems object. */ const EquationSystems & get_equation_systems() const { return _equation_systems; } /** * @returns a reference to this system's parent EquationSystems object. */ EquationSystems & get_equation_systems() { return _equation_systems; } /** * @returns \p true if the system is active, \p false otherwise. * An active system will be solved. */ bool active () const; /** * Activates the system. Only active systems are solved. */ void activate (); /** * Deactivates the system. Only active systems are solved. */ void deactivate (); /** * Vector iterator typedefs. */ typedef std::map<std::string, NumericVector<Number>* >::iterator vectors_iterator; typedef std::map<std::string, NumericVector<Number>* >::const_iterator const_vectors_iterator; /** * Beginning of vectors container */ vectors_iterator vectors_begin (); /** * Beginning of vectors container */ const_vectors_iterator vectors_begin () const; /** * End of vectors container */ vectors_iterator vectors_end (); /** * End of vectors container */ const_vectors_iterator vectors_end () const; /** * Adds the additional vector \p vec_name to this system. Only * allowed @e prior to \p init(). All the additional vectors * are similarly distributed, like the \p solution, * and inititialized 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 */ NumericVector<Number> & add_vector (const std::string& vec_name, const bool projections=true); /** * 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. */ bool& project_solution_on_reinit (void) { return _solution_projection; } /** * @returns \p true if this \p System has a vector associated with the * given name, \p false otherwise. */ bool have_vector (const std::string& vec_name) const; /** * @returns a const reference to this system's @e additional vector * named \p vec_name. Access is only granted when the vector is already * properly initialized. */ const NumericVector<Number> & get_vector (const std::string& vec_name) const; /** * @returns a writeable reference to this system's @e additional vector * named \p vec_name. Access is only granted when the vector is already * properly initialized. */ NumericVector<Number> & get_vector (const std::string& vec_name); /** * @returns the number of vectors (in addition to the solution) * handled by this system * This is the size of the \p _vectors map */ unsigned int n_vectors () const; /** * @returns the number of variables in the system */ unsigned int n_vars() const; /** * @returns the number of degrees of freedom in the system */ unsigned int n_dofs() const; /** * Returns the number of active degrees of freedom * for this System. */ unsigned int n_active_dofs() const; /** * @returns the number of constrained degrees of freedom * in the system. */ unsigned int n_constrained_dofs() const; /** * @returns the number of degrees of freedom local * to this processor */ unsigned int n_local_dofs() const; /** * Adds the variable \p var to the list of variables * for this system. */ void add_variable (const std::string& var, const FEType& type); /** * Adds the variable \p var to the list of variables * for this system. Same as before, but assumes \p LAGRANGE * as default value for \p FEType.family. */ void add_variable (const std::string& var, const Order order = FIRST, const FEFamily = LAGRANGE); /** * @returns true if a variable named \p var exists in this System */ bool has_variable(const std::string& var) const; /** * @returns the name of variable \p i. */ const std::string & variable_name(const unsigned int i) const; /** * @returns the variable number assoicated with * the user-specified variable named \p var. */ unsigned short int variable_number (const std::string& var) const; /** * @returns the finite element type variable number \p i. */ const FEType & variable_type (const unsigned int i) const; /** * @returns the finite element type for variable \p var. */ const FEType & variable_type (const std::string& var) const; /** * @returns a norm of variable \p var in the vector \p v, in the specified * norm (e.g. L2, H0, H1) */ Real calculate_norm(NumericVector<Number>& v, unsigned int var = 0, FEMNormType norm_type = L2) const; /** * @returns a norm of the vector \p v, using \p component_norm and \p * component_scale to choose and weight the norms of each variable. */ Real calculate_norm(NumericVector<Number>& v, const SystemNorm &norm) const; /** * Reads the basic data header for this System. */ void read_header (Xdr& io, const bool read_header=true, const bool read_additional_data=true, const bool read_legacy_format=false); /** * Reads additional data, namely vectors, for this System. */ void read_legacy_data (Xdr& io, const bool read_additional_data=true); /** * Reads additional data, namely vectors, for this System. * This method may safely be called on a distributed-memory mesh. */ void read_serialized_data (Xdr& io, const bool read_additional_data=true); /** * Reads additional data, namely vectors, for this System. * This method may safely be called on a distributed-memory mesh. * This method will read an individual file for each processor in the simulation * where the local solution components for that processor are stored. */ void read_parallel_data (Xdr &io, const bool read_additional_data); /** * Writes the basic data header for this System. */ void write_header (Xdr& io, const bool write_additional_data) const; /** * Writes additional data, namely vectors, for this System. * This method may safely be called on a distributed-memory mesh. */ void write_serialized_data (Xdr& io, const bool write_additional_data = true) const; /** * Writes additional data, namely vectors, for this System. * This method may safely be called on a distributed-memory mesh. * This method will create an individual file for each processor in the simulation * where the local solution components for that processor will be stored. */ void write_parallel_data (Xdr &io, const bool write_additional_data) const; /** * @returns a string containing information about the * system. */ std::string get_info () const; /** * Register a user function to use in initializing the system. */ void attach_init_function (void fptr(EquationSystems& es, const std::string& name)); /** * Register a user function to use in assembling the system * matrix and RHS. */ void attach_assemble_function (void fptr(EquationSystems& es, const std::string& name)); /** * Register a user function for imposing constraints. */ void attach_constraint_function (void fptr(EquationSystems& es, const std::string& name)); /** * User-provided initialization function. Can be overloaded * in derived classes. */ virtual void user_initialization ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -