Dear all,
I need to construct a sparse matrix from MatrixFree operator. I want to do it in a similar way to present in step-37 for computing diagonal. The only difference will be that the computed values from FEEValuation and FEFaceEvaluation have to be distributed to the specified row of a matrix. The code will look like, I need to get local_dof_indices somehow:
// Loop is executed without threads
for (unsigned int cell=0; cell<n_cells; ++cell)
{
phi.reinit (cell);
for (unsigned int i=0; i<phi.dofs_per_cell; ++i)
{
for (unsigned int j=0; j<phi.dofs_per_cell; ++j)
phi.submit_dof_value(make_vectorized_array<number>(1.), i);
// local integration operator:
integrate_cell(phi,cell);
phi.integrate (false, true);
// Here I have phi filled with a row of the matrix
// now I need to know global indices of dofs...
// And I have no clue how to obtain local_dof_indices needed below.
for (unsigned int j=0; j<phi.dofs_per_cell; ++j){
for (unsigned int v=0; v<this->data->n_components_filled(cell); ++v)
matrix(local_dof_indices[i][v],local_dof_indices[j][v] )+=phi.get_dof_value(j)[v];
}
}
}
The code for FEFaceVAlues will be very similar.
Moreover, I'm working with a vector-valued problem so local_dof_indices will need 3 indices ( local dof number, index in vectorization and component of the vector)
It would be great it FEEvaluation had a function for distributing to a matrix so that two loops are replaced with phi.distribute_local_to_global (matrix, i);
I only need to do that somehow, it does not have to be very efficient. There are three main purposes for having that function:
1) coarse matrix for direct solver
2) initialization of preconditioner based on sparse matrix
3) system matrix for validating code
Having this functionality would allow me to write a class for an arbitrary matrix-free operator that form local integration formula will be able to automatically:
1) compute matrix-vector product
2) compute diagonal
3) compute sparse matrix of operator.
The operator will be specyfied by defining a function :
void integrate_cell(FEEValuation & phi, unsigned int cell);
And similar ones for face and boundary in case of DG. I think it will be possible for both vector and scalar based 2nd order operators. Also non-square operator could be possible.
And using this, the block operators may be constructed (eg. Stokes).
Best,
Michał