OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes | Private Attributes | List of all members
AppFrame::BlockMatrixApplication< dim > Class Template Reference

Application handling matrices and assembling linear systems of equations. More...

#include <block_matrix_application.h>

Inheritance diagram for AppFrame::BlockMatrixApplication< dim >:
Inheritance graph
[legend]
Collaboration diagram for AppFrame::BlockMatrixApplication< dim >:
Collaboration graph
[legend]

Public Member Functions

void do_assemble (const FEVectors &, typename DoFHandler< dim >::active_cell_iterator begin, typename DoFHandler< dim >::active_cell_iterator end, Threads::Mutex &mutex)
 Multithreaded assemble function called by assemble().
 
virtual void post_cell_assemble ()
 A call back function for assemble(), called after all cell matrices have been entered, but before the face matrices are computed.
 
Constructors and Initialization
 BlockMatrixApplication (boost::shared_ptr< ApplicationData > data=boost::shared_ptr< ApplicationData >())
 Constructor for an object, owning its own mesh and dof handler.
 
 BlockMatrixApplication (DoFApplication< dim > &, bool triangulation_only)
 Constructor for an object, borrowing mesh and dof handler from another object.
 
void _initialize (ParameterHandler &param)
 Initialize data of this class.
 
virtual void declare_parameters (ParameterHandler &param)
 Declare parameters related to matrices.
 
virtual void initialize (ParameterHandler &param)
 Initialize application.
 
Data management functions
void add_vector_for_cell_matrix (std::string name, unsigned int block, unsigned int components, bool values, bool derivatives)
 Add a named vector from data to be handed to the cell_matrix() function via CellInfo::values and CellInfo::derivatives.
 
void add_vector_for_flux_matrix (std::string name, unsigned int block, unsigned int components, bool values, bool derivatives)
 Add a named vector from data to be handed to the bdry_matrix() and face_matrix() functions via FaceInfo::values and FaceInfo::derivatives.
 
ApplicationBase interface
void remesh_matrices ()
 Initialize sparsity patterns and matrices for the new mesh.
 
virtual void remesh ()
 Refine grid accordingly to the Refinement options under "Grid Generation" in the parameter file.
 
void assemble (const FEVectors &)
 Loop over all cells and assemble the system #matrices by using the local matrix integration functions cell_matrix(), bdry_matrix() and face_matrix() provided by the derived class.
 
void assemble_numerically (const FEVectors &src, const double delta=1e-6)
 Compute the Jacobian of the system of equations,

\[ J(i,j) = \frac{\partial R_i}{\partial u_j} \]

by using forward differences.

 
void residual_constraints (FEVector &dst) const
 Redefinition of residual_constraints() in DoFHandler.
 
Local integrators
virtual void cell_matrix (MatrixVector &cell_matrices, const typename DoFApplication< dim >::CellInfo &cell)
 Integration of local bilinear form.
 
virtual void bdry_matrix (MatrixVector &face_matrices, const typename DoFApplication< dim >::FaceInfo &face)
 Integration of local bilinear form.
 
virtual void face_matrix (MatrixVector &matrices11, MatrixVector &matrices12, MatrixVector &matrices21, MatrixVector &matrices22, const typename DoFApplication< dim >::FaceInfo &face1, const typename DoFApplication< dim >::FaceInfo &face2)
 Integration of local bilinear form.
 
Dirichlet boundary conditions

Member function used to set dirichlet boundary conditions.

This function is application specific and it only computes the boundary_value values that are used to constraint the linear system of equations that is being solved

virtual void dirichlet_bc (std::map< unsigned int, double > &boundary_values) const
 
- Public Member Functions inherited from AppFrame::DoFApplication< dim >
 DoFApplication (boost::shared_ptr< ApplicationData > data=boost::shared_ptr< ApplicationData >(), bool multigrid=false)
 Constructor for an object, owning its own mesh and dof handler.
 
 DoFApplication (bool multigrid)
 Constructor for an object owning its own mesh and dof handler and creating new ApplicationData.
 
 DoFApplication (DoFApplication< dim > &, bool triangulation_only, bool multigrid=false)
 Constructor for an object, borrowing mesh and dof handler from another object.
 
 ~DoFApplication ()
 Destructor which deletes owned objects.
 
void _initialize (ParameterHandler &param)
 Initialize from parameter values.
 
void add_vector_for_transfer (FEVector *)
 Add the vector to be transfered from one mesh to the next.
 
void delete_vector_for_transfer ()
 Delete the vector to be transfered from one mesh to the next.
 
virtual void remesh_dofs ()
 Initialize dof handler, count the dofs in each block and renumber the dofs.
 
virtual void init_vector (FEVector &dst) const
 Reinitialize the BlockVector dst such that it contains block_size.size() blocks.
 
virtual double evaluate (const FEVectors &)
 Evaluate a functional during postprocessing such as drag or lift on an aerodynamics problem.
 
virtual double estimate (const FEVectors &src)
 Estimate the error.
 
virtual double residual (FEVector &dst, const FEVectors &src, bool apply_boundaries=true)
 Loop over all cells to compute the residual.
 
unsigned int memory_consumption () const
 Compute the amount of memory needed by this object.
 
virtual double cell_estimate (const CellInfo &)
 Integration of estimate inside a cell.
 
virtual double bdry_estimate (const FaceInfo &)
 Integration of estimate on a boundary face.
 
virtual double face_estimate (const FaceInfo &, const FaceInfo &)
 Integration of estimate on an interior face.
 
virtual void cell_residual (FEVector &cell_vector, const CellInfo &cell)
 Integration of local linear form.
 
virtual void bdry_residual (FEVector &face_vector, const FaceInfo &face)
 Integration of local linear form.
 
virtual void face_residual (FEVector &face_vector1, FEVector &face_vector2, const FaceInfo &face1, const FaceInfo &face2)
 Integration of local linear form.
 
template<class BOX , class WORKER >
void integrate_1form (BOX &box, WORKER &local_forms, FEVector &dst, const FEVectors &src)
 The function integrating 1-forms as for instance used by residual().
 
void integrate_functional (LocalEstimate< dim > &local_forms, FEVectors &dst, const FEVectors &src)
 The function integrating functionals using local integrators.
 
void store_triangulation (Triangulation< dim > &new_tr)
 Function to copy a triangulation object for use after refinement.
 
void transfer_solution_to_coarse_mesh (Triangulation< dim > &tr_coarse, AppFrame::FEVector &coarse_solution, AppFrame::FEVector &refined_solution)
 Function to perform the transfer of a solution on a refined grid to the initial coarse grid.
 
void read_init_solution (AppFrame::FEVector &dst, bool &good_solution) const
 Function to transfer a solution on a refined grid to the initial coarse grid.
 
template<class INFO , typename TYPE >
void fill_local_data (const INFO &info, const std::vector< VectorSelector > &data_vector, std::vector< std::vector< std::vector< TYPE > > > &data) const
 Fill local data vector with values of the stored finite element function vectors.
 
virtual void grid_out (const std::string &basename)
 Output the grid used to solve the problem.
 
virtual void data_out (const std::string &basename, const FEVectors &src)
 
virtual void data_out (const std::string &basename, const FEVectors &src, const std::vector< std::string > &solution_names)
 
virtual void data_out (const std::string &basename, const FEVector &solution, const std::vector< std::string > &solution_names, const FEVector &postprocessing=FEVector(), const std::vector< std::string > &postprocessing_names=std::vector< std::string >())
 This function outputs the results of a computation.
 
- Public Member Functions inherited from AppFrame::ApplicationBase
 ApplicationBase (boost::shared_ptr< ApplicationData > ex_data=boost::shared_ptr< ApplicationData >())
 Constructor for an application.
 
 ApplicationBase (const ApplicationBase &other)
 Copy constructor.
 
virtual ~ApplicationBase ()
 Virtual destructor.
 
void print_parameters_to_file (ParameterHandler &param, const std::string &file_name, const ParameterHandler::OutputStyle &style)
 Print default parameters for the application to a file.
 
virtual void start_vector (FEVector &dst, std::string caller) const
 Initialize vector to problem size.
 
virtual void solve (FEVector &start, const FEVectors &rhs)
 Solve the system assembled with right hand side rhs and return the result in start.
 
virtual void Tsolve (FEVector &start, const FEVectors &rhs)
 Solve the dual system assembled with right hand side rhs and return the result in start.
 
virtual void grid_out (const std::string &filename) const
 Write the mesh in the format specified by the ParameterHandler.
 
virtual void data_out (const std::string &filename, const FEVectors &src, const std::vector< std::string >)
 
boost::shared_ptr
< ApplicationData
get_data ()
 Get access to the protected variable data.
 
const boost::shared_ptr
< ApplicationData
get_data () const
 Get read-only access to the protected variable data.
 
virtual std::string id () const
 Return a unique identification string for this application.
 
virtual void notify (const Event &reason)
 Add a reason for assembling.
 
virtual void clear ()
 Reset the application class such that a call to initialize() is possible again and will produce the same result as if the object was fresh.
 
void clear_events ()
 Clear all notifications.
 

Protected Attributes

Table< 2, DoFTools::Coupling > cell_couplings
 Couplings through cell bilinear forms.
 
Table< 2, DoFTools::Coupling > flux_couplings
 Couplings through flux bilinear forms.
 
boost::shared_ptr< Quadrature
< dim > > 
quadrature_assemble_cell
 Quadrature rule for matrix assembling on cells.
 
boost::shared_ptr< Quadrature
< dim-1 > > 
quadrature_assemble_face
 Quadrature rule for matrix assembling on faces.
 
BlockSparseMatrix< double > matrix
 Storage for the actual matrix.
 
FilteredMatrix< BlockVector
< double > > 
filtered_matrix
 Wrapper for the actual matrix that contains all the boundary conditions.
 
- Protected Attributes inherited from AppFrame::DoFApplication< dim >
std::map< unsigned int, double > boundary_constraints
 List of all nodes constrained by a strong boundary condition, together with a value to be assigned.
 
ConstraintMatrix hanging_node_constraints
 Constraint Matrix object.
 
boost::shared_ptr< Mapping< dim > > mapping
 The mapping used for the transformation of mesh cells.
 
unsigned int mapping_degree
 Degree used for polynomial mapping of arbitrary order.
 
boost::shared_ptr
< Triangulation< dim > > 
tr
 Pointer to the Triangulation object.
 
boost::shared_ptr
< FiniteElement< dim > > 
element
 The finite element used in dof.
 
boost::shared_ptr< DoFHandler
< dim > > 
dof
 Pointer to the DoFHandler object.
 
boost::shared_ptr
< MGDoFHandler< dim > > 
mg_dof
 Pointer to the MGDoFHandler object.
 
MeshWorker::BlockInfo block_info
 
Vector< float > cell_errors
 The result of error estimation by cell.
 
Vector< float > face_errors
 The result of error estimation by face.
 
GridOut g_out
 The object for writing grids.
 
DataOut< dim, DoFHandler< dim > > d_out
 The object for writing data.
 
std::vector
< DataComponentInterpretation::DataComponentInterpretation > 
data_interpretation
 Vector for adjusting output to vector data.
 
std::string refinement
 Refinement parameter from parameter file.
 
unsigned int initial_refinement
 Initial refinement from parameter file.
 
double refinement_threshold
 Refinement threshold for adaptive method from parameter file.
 
double coarsening_threshold
 Coarsening threshold for adaptive method from parameter file.
 
bool sort_cuthill
 Flag for sorting with Cuthill McKee algorithm.
 
Point< dimsort_direction
 Direction for downstream sorting.
 
std::vector< FEVector * > transfer_vectors
 List of vector names to be transfered from one grid to the next.
 
Quadrature< dimquadrature_residual_cell
 Quadrature rule for residual computation on cells.
 
Quadrature< dim-1 > quadrature_residual_bdry
 Quadrature rule for residual computation on boundary faces.
 
Quadrature< dim-1 > quadrature_residual_face
 Quadrature rule for residual computation on faces.
 
bool boundary_fluxes
 Extend the integration loops in assemble() and residual() also to boundary faces.
 
bool interior_fluxes
 Extend the integration loops in assemble() and residual() also to interior faces.
 
- Protected Attributes inherited from AppFrame::ApplicationBase
boost::shared_ptr
< ApplicationData
data
 Object for auxiliary data.
 
Event notifications
 Accumulate reasons for reassembling here.
 

Private Attributes

BlockSparsityPattern sparsities
 Sparsity patterns.
 
MeshWorker::VectorSelector cell_matrix_values
 The set of all vector data to be used in cell_matrix().
 
MeshWorker::VectorSelector flux_matrix_values
 The set of all vector data to be used in bdry_matrix() and face_matrix().
 

Additional Inherited Members

- Public Types inherited from AppFrame::DoFApplication< dim >
typedef
MeshWorker::InfoObjects::IntegrationInfo
< dim, FEValuesBase< dim > > 
CellInfo
 This is a redefinition of CellInfo in order to call MeshWorker objects instead of the previous implementation in AppFrame.
 
typedef
MeshWorker::InfoObjects::IntegrationInfo
< dim, FEFaceValuesBase< dim > > 
FaceInfo
 This is a redefinition of CellInfo in order to call MeshWorker objects instead of the previous implementation in AppFrame.
 
- Public Attributes inherited from AppFrame::DoFApplication< dim >
unsigned int verbosity
 Controls verbosity of certain functions.
 
std::vector
< DataComponentInterpretation::DataComponentInterpretation > 
solution_interpretations
 solution_interpretations identifies whether some solution_names are scalars or parts of a vector.
 
std::vector
< DataComponentInterpretation::DataComponentInterpretation > 
postprocessing_interpretations
 postprocessing_interpretations identifies whether some postprocessing_names are scalars or parts of a vector.
 
bool output_materials_and_levels
 output_materials_and_levels if true then visualized, otherwise suppressed.
 
Vector< double > output_materials
 Vector that will be used by data_out to store the material ids.
 
Vector< double > output_levels
 Vector that will be used by data_out to store the refinement levels at each cell.
 
- Protected Member Functions inherited from AppFrame::DoFApplication< dim >
void constrain_boundary (FEVector &v, bool homogeneous) const
 Apply either homogeneous or inhomogeneous boundary_constraints.
 

Detailed Description

template<int dim>
class AppFrame::BlockMatrixApplication< dim >

Application handling matrices and assembling linear systems of equations.

This class inherits the information on Triangulation and DoFHandler from its base class DoFApplication. It adds information on the linear system, in particular the sparsities.

Additionally, it holds a BlockSparseMatrix as the system matrix of the finite element problem. Generic loops over mesh cells and faces are implemented in order to assemble() the system matrices and compute the residual(). These functions use the virtual local integration functions declared here and implemented by the derived actual application class.

Note
You probably miss functions for building the right hand side of a linear system. They are missing deliberately, since the linear case is very special and can be handled in the framework of nonlinear problems. So, if you have a linear problem, code the local matrices for residual() so they ignore the BlockVector src.

Deriving your own application

Author
Guido Kanschat, 2006

Constructor & Destructor Documentation

template<int dim>
AppFrame::BlockMatrixApplication< dim >::BlockMatrixApplication ( boost::shared_ptr< ApplicationData data = boost::shared_ptr< ApplicationData >())

Constructor for an object, owning its own mesh and dof handler.

If data is null, a new handler for application data is generated.

see constructor of DoFApplication.

template<int dim>
AppFrame::BlockMatrixApplication< dim >::BlockMatrixApplication ( DoFApplication< dim > &  ,
bool  triangulation_only 
)

Constructor for an object, borrowing mesh and dof handler from another object.

If triangulation_only is true, only the triangulation is borrowed.

see constructor of DoFApplication.

Member Function Documentation

template<int dim>
void AppFrame::BlockMatrixApplication< dim >::_initialize ( ParameterHandler &  param)

Initialize data of this class.

Note
remesh_dofs() has to be called before this member function since remesh_dofs() initializes data that is used in this routine. In particular, dof and block_indices.
template<int dim>
void AppFrame::BlockMatrixApplication< dim >::add_vector_for_cell_matrix ( std::string  name,
unsigned int  block,
unsigned int  components,
bool  values,
bool  derivatives 
)

Add a named vector from data to be handed to the cell_matrix() function via CellInfo::values and CellInfo::derivatives.

template<int dim>
void AppFrame::BlockMatrixApplication< dim >::add_vector_for_flux_matrix ( std::string  name,
unsigned int  block,
unsigned int  components,
bool  values,
bool  derivatives 
)

Add a named vector from data to be handed to the bdry_matrix() and face_matrix() functions via FaceInfo::values and FaceInfo::derivatives.

template<int dim>
void AppFrame::BlockMatrixApplication< dim >::assemble ( const FEVectors )

Loop over all cells and assemble the system #matrices by using the local matrix integration functions cell_matrix(), bdry_matrix() and face_matrix() provided by the derived class.

template<int dim>
void AppFrame::BlockMatrixApplication< dim >::assemble_numerically ( const FEVectors src,
const double  delta = 1e-6 
)

Compute the Jacobian of the system of equations,

\[ J(i,j) = \frac{\partial R_i}{\partial u_j} \]

by using forward differences.

The solution is perturbed at each degree of freedom and the residual function is used to compute the residual for each perturbed solution. Forward differences are used to compute the Jacobian.

The Jacobian is stored in this->matrix and a version with the boundary conditions already applied is stored in this->filtered_matrix

Parameters
[in]srcA vector of BlockVectors containting the solution at the previous Newton step and the residual.
[in]deltaThe step size used for numerical differenciation.
Note
This routine is used in combination with a Netwon nonlinear solver since it requires src to contain a field named "Newton iterate" with the solution at the previous Newton step.
Author
M. Secanell, 2013
template<int dim>
virtual void AppFrame::BlockMatrixApplication< dim >::bdry_matrix ( MatrixVector face_matrices,
const typename DoFApplication< dim >::FaceInfo face 
)
virtual

Integration of local bilinear form.

Reimplemented in FuelCell::Application::AppCathode< dim >.

template<int dim>
virtual void AppFrame::BlockMatrixApplication< dim >::cell_matrix ( MatrixVector cell_matrices,
const typename DoFApplication< dim >::CellInfo cell 
)
virtual

Integration of local bilinear form.

Here we loop over the quadrature points and over degrees of freedom in order to compute the matrix for the cell.

Reimplemented in FuelCell::Application::AppCathode< dim >, FuelCell::Application::AppPemfc< dim >, and FuelCell::Application::AppLaplace< dim >.

template<int dim>
virtual void AppFrame::BlockMatrixApplication< dim >::declare_parameters ( ParameterHandler &  param)
virtual

Declare parameters related to matrices.

Note
The function declare_parameters of derived applications should always call the one of its base class.

Reimplemented from AppFrame::DoFApplication< dim >.

Reimplemented in FuelCell::Application::AppCathode< dim >, FuelCell::Application::AppPemfc< dim >, FuelCell::Application::AppReadMesh< dim >, FuelCell::Application::AppLaplace< dim >, and AppFrame::OptimizationBlockMatrixApplication< dim >.

template<int dim>
virtual void AppFrame::BlockMatrixApplication< dim >::dirichlet_bc ( std::map< unsigned int, double > &  boundary_values) const
virtual
template<int dim>
void AppFrame::BlockMatrixApplication< dim >::do_assemble ( const FEVectors ,
typename DoFHandler< dim >::active_cell_iterator  begin,
typename DoFHandler< dim >::active_cell_iterator  end,
Threads::Mutex &  mutex 
)

Multithreaded assemble function called by assemble().

template<int dim>
virtual void AppFrame::BlockMatrixApplication< dim >::face_matrix ( MatrixVector matrices11,
MatrixVector matrices12,
MatrixVector matrices21,
MatrixVector matrices22,
const typename DoFApplication< dim >::FaceInfo face1,
const typename DoFApplication< dim >::FaceInfo face2 
)
virtual

Integration of local bilinear form.

template<int dim>
virtual void AppFrame::BlockMatrixApplication< dim >::initialize ( ParameterHandler &  param)
virtual
template<int dim>
virtual void AppFrame::BlockMatrixApplication< dim >::post_cell_assemble ( )
virtual

A call back function for assemble(), called after all cell matrices have been entered, but before the face matrices are computed.

template<int dim>
virtual void AppFrame::BlockMatrixApplication< dim >::remesh ( )
virtual

Refine grid accordingly to the Refinement options under "Grid Generation" in the parameter file.

Reimplemented from AppFrame::DoFApplication< dim >.

template<int dim>
void AppFrame::BlockMatrixApplication< dim >::remesh_matrices ( )

Initialize sparsity patterns and matrices for the new mesh.

template<int dim>
void AppFrame::BlockMatrixApplication< dim >::residual_constraints ( FEVector dst) const
virtual

Redefinition of residual_constraints() in DoFHandler.

In this member function, I adjust the residual in order to account for hanging nodes and I apply Dirichlet boundary conditions given by dirichlet_bc().

Reimplemented from AppFrame::DoFApplication< dim >.

Member Data Documentation

template<int dim>
Table<2, DoFTools::Coupling> AppFrame::BlockMatrixApplication< dim >::cell_couplings
protected

Couplings through cell bilinear forms.

cell_coupling allows to specify which variables couple with which equations. This is used by DoFTools to generate a sparsity pattern that does not contain elements unless specified in the cell_coupings, therefore, reducing the amount of memory needed.

Note
cell_coupings is a two dimensional table (i.e. a matrix) of DoFTools::Coupling objects. DoFTools::Coulings takes the values: always (components couple), zero (no coupling) and nonzero

Example: For the 2D Stokes equations

\begin{eqnarray*} \frac{d^2u}{dx^2} +\frac{d^2u}{dy^2} + \frac{dp}{dx} = 0 \\ \frac{d^2v}{dx^2} +\frac{d^2v}{dy^2} + \frac{dp}{dy} = 0 \\ \frac{du}{dx} +\frac{dv}{dy} = 0 \end{eqnarray*}

we need to initialize cell_coupling to:

* cell_coupling.reinit(3,3);
* cell_coupling(0,0) = DoFTools::always;
* cell_coupling(0,1) = DoFTools::zero;
* cell_couplings(0,2) = DoFTools::always;
* cell_couplings(1,0) = DoFTools::zero; 
* ...
* 
template<int dim>
MeshWorker::VectorSelector AppFrame::BlockMatrixApplication< dim >::cell_matrix_values
private

The set of all vector data to be used in cell_matrix().

template<int dim>
FilteredMatrix<BlockVector<double> > AppFrame::BlockMatrixApplication< dim >::filtered_matrix
protected

Wrapper for the actual matrix that contains all the boundary conditions.

This is the matrix that should be used to solve the linear system of equations and NOT matrix.

template<int dim>
Table<2, DoFTools::Coupling> AppFrame::BlockMatrixApplication< dim >::flux_couplings
protected

Couplings through flux bilinear forms.

template<int dim>
MeshWorker::VectorSelector AppFrame::BlockMatrixApplication< dim >::flux_matrix_values
private

The set of all vector data to be used in bdry_matrix() and face_matrix().

template<int dim>
BlockSparseMatrix<double> AppFrame::BlockMatrixApplication< dim >::matrix
protected

Storage for the actual matrix.

template<int dim>
boost::shared_ptr<Quadrature<dim> > AppFrame::BlockMatrixApplication< dim >::quadrature_assemble_cell
protected

Quadrature rule for matrix assembling on cells.

template<int dim>
boost::shared_ptr<Quadrature<dim-1> > AppFrame::BlockMatrixApplication< dim >::quadrature_assemble_face
protected

Quadrature rule for matrix assembling on faces.

template<int dim>
BlockSparsityPattern AppFrame::BlockMatrixApplication< dim >::sparsities
private

Sparsity patterns.


The documentation for this class was generated from the following file: