#endif // DEAL_II_WITH_MUMPS
double *a;
- double *rhs;
+ std::vector<double> rhs;
int *irn;
int *jcn;
types::global_dof_index n;
*/
void copy_solution (Vector<double> &vector);
+ /**
+ *
+ */
+ void copy_rhs_to_mumps(const Vector<double> &rhs);
+
/**
* Flags storing whether the function <tt>initialize ()</tt> has already
* been called.
/**
* A function in which the linear system is solved and the solution
- * vector is copied into the given <tt>vector</tt>.
+ * vector is copied into the given <tt>vector</tt>. The right-hand side
+ * need to be supplied in initialize(matrix, vector);
*/
void solve (Vector<double> &vector);
#include <iostream>
#include <list>
#include <typeinfo>
+#include <vector>
DEAL_II_NAMESPACE_OPEN
template <class Matrix>
void SparseDirectMUMPS::initialize_matrix (const Matrix &matrix)
{
+ Assert(matrix.n() == matrix.m(), ExcMessage("Matrix needs to be square."));
+
+
// Check we haven't been here before:
Assert (initialize_called == false, ExcInitializeAlreadyCalled());
// Hand over matrix and right-hand side
initialize_matrix (matrix);
+ copy_rhs_to_mumps(vector);
+}
+
+void SparseDirectMUMPS::copy_rhs_to_mumps(const Vector<double> &new_rhs)
+{
+ Assert(n == new_rhs.size(), ExcMessage("Matrix size and rhs length must be equal."));
+
if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
{
- // Object denoting a MUMPS data structure
- rhs = new double[n];
-
+ rhs.resize(n);
for (size_type i = 0; i < n; ++i)
- rhs[i] = vector (i);
+ rhs[i] = new_rhs (i);
- id.rhs = rhs;
+ id.rhs = &rhs[0];
}
}
void SparseDirectMUMPS::copy_solution (Vector<double> &vector)
{
+ Assert(n == vector.size(), ExcMessage("Matrix size and solution vector length must be equal."));
+ Assert(n == rhs.size(), ExcMessage("Class not initialized with a rhs vector."));
+
// Copy solution into the given vector
if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
{
for (size_type i=0; i<n; ++i)
vector(i) = rhs[i];
- delete[] rhs;
+ rhs.resize(0); // remove rhs again
}
}
void SparseDirectMUMPS::solve (Vector<double> &vector)
{
+ //TODO: this could be implemented similar to SparseDirectUMFPACK where
+ // the given vector will be used as the RHS. Sadly, there is no easy
+ // way to do this without breaking the interface.
+
// Check that the solver has been initialized by the routine above:
Assert (initialize_called == true, ExcNotInitialized());
Assert (nz != 0, ExcNotInitialized());
// Start solver
- id.job = 6;
+ id.job = 6; // 6 = analysis, factorization, and solve
dmumps_c (&id);
copy_solution (vector);
}
// and that the matrix has at least one nonzero element:
Assert (nz != 0, ExcNotInitialized());
- // Hand over right-hand side
- if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
- {
- // Object denoting a MUMPS data structure:
- rhs = new double[n];
-
- for (size_type i = 0; i < n; ++i)
- rhs[i] = src (i);
+ Assert(n == dst.size(), ExcMessage("Destination vector has the wrong size."));
+ Assert(n == src.size(), ExcMessage("Source vector has the wrong size."));
- id.rhs = rhs;
- }
+ // Hand over right-hand side
+ copy_rhs_to_mumps(src);
// Start solver
id.job = 3;
#ifdef DEAL_II_WITH_MUMPS
#define InstantiateMUMPS(MATRIX) \
template \
- void SparseDirectMUMPS::initialize (const MATRIX &, const Vector<double> &);
+ void SparseDirectMUMPS::initialize (const MATRIX &, const Vector<double> &);\
+ template \
+ void SparseDirectMUMPS::initialize (const MATRIX &);
InstantiateMUMPS(SparseMatrix<double>)
InstantiateMUMPS(SparseMatrix<float>)