[Dune] C++ question

Oliver Sander oliver.sander at tu-dresden.de
Tue Aug 19 16:41:51 CEST 2025


Hi Mike,

thanks for your interest in Dune.  Your specific matrix setup is unusual,
but it should work.  Your code looks like a decent start:

 >  typedef Matrix<double> occupy(np, np);

This would need to be

typedef Matrix<double> occupy;

or, in a more modern style:

using occupy = Matrix<double>;

Then

 >  BCRSMatrix<occupy> stiffns(4*numelement, 4*numelement, 9, .12,
 >                             BCRSMatrix<occupy>::implicit);

does set up a sparse matrix with 'Matrix<double>' entries as desired.
In the next step you have to tell the stiffns object the sparsity pattern:
At which (row,col) pairs you want to store entries.

Do you have a copy of the Dune book? It explains how to set up BCRSMatrix
objects in some detail.  Try to start from one of the examples there,
and modify it to get Matrix<double> matrix entries.  Feel free to ask
again if you get stuck there.

> In dune/istl/bcrsmatrix.hh it says " - VariableBCRSMatrix is not yet implemented."  Does that mean I can't do what I'm attempting: to create
> a BCRSMatrix with variable dimensions?

Yes and no.  A BCRSMatrix<Matrix<double> > and a (hypothetical) VariableBCRSMatrix
both implement the same matrix: A sparse matrix with dense blocks of sizes
specified at run-time. The difference is the internal memory allocation:
BCRSMatrix<Matrix<double> > stores each of its entries by a separate heap allocation,
while VariableBCRSMatrix will store its entire content in a single heap allocation.
This can have important performance benefits.

Hope this helps! :-)

Best,
Oliver


> 
> 
> On Mon, 18 Aug 2025, Mike Rosing wrote:
> 
>> Date: Mon, 18 Aug 2025 19:31:22 +0000 (UTC)
>> From: Mike Rosing <eresrch at sdf.org>
>> To: dune at lists.dune-project.org
>> Subject: [Dune] C++ question
>>
>> I'm trying to create a BCRSMatrix of runtime sized Matrix. I tried
>>
>>  typedef Matrix<double> occupy(np, np);
>>  BCRSMatrix<occupy> stiffns(4*numelement, 4*numelement, 9, .12,
>>                             BCRSMatrix<occupy>::implicit);
>>
>>
>> and several other iterations - but I obviously don't understand what I'm doing.  The "occupy" matrix is mostly full, the "stiffns" matrix is mostly
>> empty.
>>
>> In case it matters, the list of includes is
>> #include <iostream>
>> #include <fstream>
>> #include <dune/common/parallel/mpihelper.hh> // An initializer of MPI
>> // #include <dune/common/exceptions.hh> // We use exceptions
>> #include <dune/grid/uggrid.hh>
>> #include <dune/grid/io/file/gmshreader.hh>
>> #include <dune/geometry/affinegeometry.hh>
>> #include <dune/istl/matrix.hh>
>>
>> // { include_matrix_vector_begin }
>> #include <dune/istl/bcrsmatrix.hh>
>> #include <dune/istl/bvector.hh>
>> // { include_matrix_vector_end }
>>
>> #include <dune/istl/matrixindexset.hh>
>> #include <dune/istl/preconditioners.hh>
>> #include <dune/istl/solvers.hh>
>> #include <dune/istl/matrixmarket.hh>
>>
>> What's the correct way to set up this kind of structure?
>>
>> Mike Rosing
>> Engineering Research
>> Madison WI USA
>> Elliptic Curve Crypto:  http://mng.bz/D9NA
>>
>>
>> _______________________________________________
>> Dune mailing list
>> Dune at lists.dune-project.org
>> https://lists.dune-project.org/mailman/listinfo/dune
>>
>>
> 
> Mike Rosing
> Engineering Research
> Madison WI USA
> Elliptic Curve Crypto:  http://mng.bz/D9NA
> 
> 
> _______________________________________________
> Dune mailing list
> Dune at lists.dune-project.org
> https://lists.dune-project.org/mailman/listinfo/dune

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6050 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20250819/acc6c2c1/attachment.bin>


More information about the Dune mailing list