mrtr_utils.H File Reference

A couple utility methods for the Moertel package. More...

#include <ctime>
#include <iostream>
#include "Teuchos_RefCountPtr.hpp"
#include <Epetra_Comm.h>
#include <Epetra_SerialComm.h>
#include "Epetra_SerialDenseMatrix.h"
#include "Epetra_SerialDenseSolver.h"
#include "Epetra_CrsMatrix.h"
#include "Epetra_Vector.h"
#include "Epetra_Export.h"
#include "ml_common.h"
#include "ml_include.h"
#include "ml_epetra_utils.h"
#include "ml_epetra.h"
#include "ml_epetra_operator.h"
#include "mrtr_segment.H"
#include "mrtr_functions.H"
#include "mrtr_node.H"
#include "mrtr_point.H"

Include dependency graph for mrtr_utils.H:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Namespaces

namespace  MOERTEL

Functions

MOERTEL::FunctionAllocateFunction (MOERTEL::Function::FunctionType type, int out)
 Allocate a function of the correct type.
MOERTEL::SegmentAllocateSegment (int type, int out)
 Allocate a Segment of the correct type.
bool cross (double *out, const double *g1, const double *g2)
 Cross product.
double dot (const double *g1, const double *g2, const int dim)
 Dot product.
double length (const double *g, const int dim)
 Length of a vector.
bool solve22 (const double A[][2], double *x, const double *b)
 Solve dense 2x2 system of equations.
bool solve33 (const double A[][3], double *x, const double *b)
 Solve dense 3x3 system of equations.
int digit_ten (int i)
 Return the '10' digit from an integer number.
void sort (double *dlist, int N, int *list2)
 Sort dlist of length N in ascending, sort list2 according to dlist.
template<typename kind>
void swap (kind &a, kind &b)
 Template to swap 2 <kind> instances.
int MatrixMatrixAdd (const Epetra_CrsMatrix &A, bool transposeA, double scalarA, Epetra_CrsMatrix &B, double scalarB)
 Add matrices A+B.
Epetra_CrsMatrix * MatMatMult (const Epetra_CrsMatrix &A, bool transA, const Epetra_CrsMatrix &B, bool transB, int outlevel)
 Multiply matrices A*B.
Epetra_CrsMatrix * PaddedMatrix (const Epetra_Map rowmap, double val, const int numentriesperrow)
 Allocate and return a matrix padded with val on the diagonal. FillComplete() is NOT called on exit.
Epetra_CrsMatrix * StripZeros (Epetra_CrsMatrix &A, double eps)
 Strip out values from a matrix below a certain tolerance.
bool SplitMatrix2x2 (RefCountPtr< Epetra_CrsMatrix > A, RefCountPtr< Epetra_Map > &A11rowmap, RefCountPtr< Epetra_Map > &A22rowmap, RefCountPtr< Epetra_CrsMatrix > &A11, RefCountPtr< Epetra_CrsMatrix > &A12, RefCountPtr< Epetra_CrsMatrix > &A21, RefCountPtr< Epetra_CrsMatrix > &A22)
 split a matrix into a 2x2 block system where the rowmap of one of the blocks is given
Epetra_Map * SplitMap (const Epetra_Map &Amap, const Epetra_Map &Agiven)
 split a rowmap of matrix A
bool SplitVector (const Epetra_Vector &x, const Epetra_Map &x1map, Epetra_Vector *&x1, const Epetra_Map &x2map, Epetra_Vector *&x2)
 split a vector into 2 non-overlapping pieces
bool MergeVector (const Epetra_Vector &x1, const Epetra_Vector &x2, Epetra_Vector &xresult)
 merge results from 2 vectors into one (assumes matching submaps)
bool Print_Matrix (string name, Epetra_CrsMatrix &A, int ibase)
 Print matrix to file.
bool Print_Graph (string name, Epetra_CrsGraph &A, int ibase)
 Print graph to file.
bool Print_Vector (string name, Epetra_Vector &v, int ibase)
 Print vector to file.

Detailed Description

A couple utility methods for the Moertel package.

Date:
Last update do Doxygen: 16-Dec-05

Function Documentation

MOERTEL::Function * MOERTEL::AllocateFunction MOERTEL::Function::FunctionType  type,
int  out
 

Allocate a function of the correct type.

For communication reasons, every single derived function class needs to have a unique typ-id. This type Id can be communicated easily. So when introducing a new derived Function class, one needs to add it's type to the enum FunctionType in the virtual base class in mrtr_function.H and one needs to add a case to this method MOERTEL::AllocateFunction in mrtr_utils.cpp

Parameters:
type : Type of Function to allocate and return pointer to

MOERTEL::Segment * MOERTEL::AllocateSegment int  type,
int  out
 

Allocate a Segment of the correct type.

For communication reasons, every single derived segment class needs to have a unique typ-id. This type Id can be communicated easily. So when introducing a new segment class, one needs to add it's type to the enum SegmentType in the virtual base class in mrtr_segment.H and one needs to add a case to this method MOERTEL::AllocateSegment in mrtr_utils.cpp

Parameters:
type : Type of segment to allocate and return pointer to
out : Level of output to be generated to stdout ( 0 - 10 )

bool MOERTEL::cross double *  out,
const double *  g1,
const double *  g2
 

Cross product.

Perform cross product out = g1 x g2 for vectors of dimension 3

double MOERTEL::dot const double *  g1,
const double *  g2,
const int  dim
 

Dot product.

Perform dot product g1 dot g2 for vectors of dimension dim and return result

double MOERTEL::length const double *  g,
const int  dim
 

Length of a vector.

Return L2 norm of a vector of dimension dim

Epetra_CrsMatrix * MOERTEL::MatMatMult const Epetra_CrsMatrix &  A,
bool  transA,
const Epetra_CrsMatrix &  B,
bool  transB,
int  outlevel
 

Multiply matrices A*B.

matrices A and B are mutliplied and the result is allocated and returned. The method makes uses EpetraExt for multiplication The user is responsible for freeing the returned result.

Parameters:
A : Matrix A to multiply
transA : flag indicating whether A*T shall be used
B : Matrix B to multiply
transB : flag indicating whether B*T shall be used
Returns:
Result upon success and NULL upon failure

int MOERTEL::MatrixMatrixAdd const Epetra_CrsMatrix &  A,
bool  transposeA,
double  scalarA,
Epetra_CrsMatrix &  B,
double  scalarB
 

Add matrices A+B.

Perform B = scalarB * B + scalarA * A ^ transposeA If scalarB is 0.0, then B = scalarA * A ^ transposeA isperformed.

This is a modified version of EpetraExt's MatrixMatrixAdd. FillComplete() must not be called on B upon entry, FillComplete() will not be called on B upon exit by this method.

Parameters:
A : Matrix A to add to B
transposeA : flag indicating whether A*T shall be added
scalarA : scalar factor for A
B : Matrix B to be added to
scalarB : scalar factor for B
Returns:
Zero upon success

bool MOERTEL::Print_Graph string  name,
Epetra_CrsGraph &  A,
int  ibase
 

Print graph to file.

Prints an Epetra_CrsGraph to file in serial and parallel. Will create several files with process id appended to the name in parallel. Index base can either be 0 or 1. The first row of the file gives the global size of the range and domain map, the second row gives the local size of the row- and column map.

Parameters:
name : Name of file without appendix, appendix will be .mtx
A : Graph to print
ibase : Index base, should be either 1 or 0

bool MOERTEL::Print_Matrix string  name,
Epetra_CrsMatrix &  A,
int  ibase
 

Print matrix to file.

Prints an Epetra_CrsMatrix to file in serial and parallel. Will create several files with process id appended to the name in parallel. Index base can either be 0 or 1. The first row of the file gives the global size of the range and domain map, the sond row gives the local size of the row- and column map.

Parameters:
name : Name of file without appendix, appendix will be .mtx
A : Matrix to print
ibase : Index base, should be either 1 or 0

bool MOERTEL::Print_Vector string  name,
Epetra_Vector &  v,
int  ibase
 

Print vector to file.

Prints an Epetra_Vector to file in serial and parallel. Will create several files with process id appended to the name in parallel. Index base can either be 0 or 1.

Parameters:
name : Name of file without appendix, appendix will be .vec
v : Vector to print
ibase : Index base, should be either 1 or 0

bool MOERTEL::solve22 const double  A[][2],
double *  x,
const double *  b
 

Solve dense 2x2 system of equations.

Ax=b

bool MOERTEL::solve33 const double  A[][3],
double *  x,
const double *  b
 

Solve dense 3x3 system of equations.

Ax=b

void MOERTEL::sort double *  dlist,
int  N,
int *  list2
 

Sort dlist of length N in ascending, sort list2 according to dlist.

This piece of code was lend from the Trilinos package ML

Epetra_Map * MOERTEL::SplitMap const Epetra_Map &  Amap,
const Epetra_Map &  Agiven
 

split a rowmap of matrix A

splits A->RowMap() into 2 maps and returns them, where one of the rowmaps has to be given on input

Parameters:
Amap : Map to split on input
Agiven : on entry submap that is given and part of Amap
Returns:
the remainder map of Amap that is not overlapping with Agiven

bool MOERTEL::SplitMatrix2x2 RefCountPtr< Epetra_CrsMatrix >  A,
RefCountPtr< Epetra_Map > &  A11rowmap,
RefCountPtr< Epetra_Map > &  A22rowmap,
RefCountPtr< Epetra_CrsMatrix > &  A11,
RefCountPtr< Epetra_CrsMatrix > &  A12,
RefCountPtr< Epetra_CrsMatrix > &  A21,
RefCountPtr< Epetra_CrsMatrix > &  A22
 

split a matrix into a 2x2 block system where the rowmap of one of the blocks is given

Splits a given matrix into a 2x2 block system where the rowmap of one of the blocks is given on input. Blocks A11 and A22 are assumed to be square. All values on entry have to be Teuchos::null except the given rowmap and matrix A. Note that either A11rowmap or A22rowmap or both have to be nonzero. In case both rowmaps are supplied they have to be an exact and nonoverlapping split of A->RowMap(). Matrix blocks are FillComplete() on exit.

Parameters:
A : Matrix A on input
A11rowmap : rowmap of A11 or null
A22rowmap : rowmap of A22 or null
A11 : on exit matrix block A11
A12 : on exit matrix block A12
A21 : on exit matrix block A21
A22 : on exit matrix block A22

Epetra_CrsMatrix * MOERTEL::StripZeros Epetra_CrsMatrix &  A,
double  eps
 

Strip out values from a matrix below a certain tolerance.

Allocates and returns a new matrix and copies A to it where entries with an absoute value smaller then eps are negelected. The method calls FillComplete(A.OperatorDomainMap(),A.OperatorRangeMap()) on the result.

Parameters:
A : Matrix A to strip
eps : tolerance
Returns:
The new matrix upon success, NULL otherwise

template<typename kind>
void swap kind &  a,
kind &  b
 

Template to swap 2 <kind> instances.

<kind> has to implement the assignment operator =


Generated on Thu Sep 18 12:30:08 2008 for Moertel by doxygen 1.3.9.1