reassembling system matrix for a specific variable

49 views
Skip to first unread message

Mark Simmons

unread,
Aug 22, 2024, 5:42:47 PM8/22/24
to deal.II User Group
Hello,

I have currently implemented a new method that is supposed to save computational efficiency by assembling the system matrix at the beginning and then not reassembling it. Currently, we are solving for this specific variable and it is defined in  a separate header file and then when the main function calls the run function, the member functions are called like the constructor and then the assemble function and then finally the solve function to compute the solution to this variable. As of right now, I believe our method is NOT actually assembling the matrix at the beginning alone (meaning at every time step I'm reassembling it.) my question is two fold:

1.) can I check to see if deal.ii is actually reassembling my matrix at every time step?
2.) how can I make sure that my matrix is only assembled once at the beginning?

Thanks for your time.

Wolfgang Bangerth

unread,
Aug 22, 2024, 5:55:38 PM8/22/24
to dea...@googlegroups.com

On 8/22/24 15:42, Mark Simmons wrote:
>
> 1.) can I check to see if deal.ii is actually reassembling my matrix at
> every time step?
> 2.) how can I make sure that my matrix is only assembled once at the
> beginning?

deal.II is not calling functions behind your back. If your run()
function is not calling assemble_system(), then assemble_system() is not
called.

But if you want to make sure, why don't you just put something like
std::cout << "********* ASSEMBLING MATRIX ***********" << std::endl;
at the top of the function that assembles the matrix? Then you just have
to read through your program's output to see where that function is
apparently executed.

Best
W.

Mark Simmons

unread,
Aug 23, 2024, 12:04:22 PM8/23/24
to deal.II User Group
Hello,

My run function is calling the assemble_system_matrix.

I have implemented a new method that is supposedly allow us to assemble the system matrix only once at the beginning saving comp time. Our variables are solved sequentially and implicitly and I have a boolean that indicates whether we use this new method or not. in one of the variables, I have added stability term that, mathematically speaking, should make our method for solving one of the variables explicit rather than implicit. From what I know currently, dealii is assembling the matrix at every time step regardless if I say I am using the new method or not. Should I have to modifiy how the assemble_system_matrix function is called in the run function or should I modify the header file that actually computes the assembly of the matrix? Not sure on how to proceed.

Thanks,
Mark

Wolfgang Bangerth

unread,
Aug 23, 2024, 1:06:38 PM8/23/24
to dea...@googlegroups.com

On 8/23/24 10:04, Mark Simmons wrote:
>
> I have implemented a new method that is supposedly allow us to assemble
> the system matrix only once at the beginning saving comp time. Our
> variables are solved sequentially and implicitly and I have a boolean
> that indicates whether we use this new method or not. in one of the
> variables, I have added stability term that, mathematically speaking,
> should make our method for solving one of the variables explicit rather
> than implicit. From what I know currently, dealii is assembling the
> matrix at every time step regardless if I say I am using the new method
> or not. Should I have to modifiy how the assemble_system_matrix function
> is called in the run function or should I modify the header file that
> actually computes the assembly of the matrix? Not sure on how to proceed.

Mark:
deal.II is not assembling your matrix. If your run() function calls
assemble_matrix(), then the matrix is assembled. That is, if your run()
function looks like this:
void run() {
...
for (time_step=1...N) {
assemble_system()
solve()
postprocess()
}
}
then you are assembling the matrix in every step, not because *deal.II*
does it for you, but *because you have said that that's what is supposed
to happen in your code*.

On the contrary, if your run() function does not call assemble_matrix(),
then the matrix is not assembled. So, if the run() function looks like this,
void run() {
...
assemble_system()
for (time_step=1...N) {
solve()
postprocess()
}
}
then the matrix is assembled only once *because you have said that it
should only happen once before you start your loop over time steps*.

Of course, which it is we cannot know without seeing your code.

Best
W.
Reply all
Reply to author
Forward
0 new messages