ideas on making stiffness matrix time independent from sequential scheme

22 views
Skip to first unread message

Mark Simmons

unread,
Sep 5, 2024, 1:55:09 PM9/5/24
to deal.II User Group
I currently have a run function in my main .cc file that calls functions from different header files. Each header file specifies the variable that I want to solve for. for example, to solve for variable x, I have a x.hh file. I do this sequentially, so I first solve for unknown x, then y, then z.  For each variable I do the following:
  1. call constructor of variable
  2. assemble the matrix ( this function calls the setup system function)
  3. call the solve function
for example, here is how I solve for the last variable.

VaporSaturation::VaporSaturationProblem<dim> Sv_problem(
/* appropriate arguments for constructor.  */
);

timer.reset();
timer.start();
Sv_problem.assemble_system_matrix_vapor_saturation();
timer.stop();

assemble_time[index_time] += timer.cpu_time();
pcout << std::endl;
pcout << "Elapsed CPU time for Sv assemble: " << timer.cpu_time() << " seconds." << std::endl;

timer.reset();
timer.start();
Sv_problem.solve_vapor_saturation();
timer.stop();

solver_time[index_time] += timer.cpu_time();
pcout << "Elapsed CPU time for Sv solve: " << timer.cpu_time() << " seconds." << std::endl;
Sv_solution = Sv_problem.Sv_solution;




each variable is solved for implicitly, so each system matrix is getting recomputed at each time step so the above code is in a for loop in my run function.

 my question is:

Is there a way that for the second variable y, that I only assemble the system matrix once on the first time step and then use this matrix in subsequent calculations? I have a proof that shows stability of this new method but I am not sure how my matrix is being calculated.

Thanks for any help,

Mark

Wolfgang Bangerth

unread,
Sep 5, 2024, 3:59:09 PM9/5/24
to dea...@googlegroups.com

On 9/5/24 11:55, Mark Simmons wrote:
>
>  my question is:
>
> Is there a way that for the second variable y, that I only assemble the
> system matrix once on the first time step and then use this matrix in
> subsequent calculations? I have a proof that shows stability of this new
> method but I am not sure how my matrix is being calculated.

Mark:
you only assemble the matrix where your code says to assemble the
matrix. So if your run() function is essentially of the form...

void MyProblem::run()
{
for (iteration=0; ...)
{
x.assemble();
x.solve();

y.assemble();
y.solve();
}
}

...then your code is assembling the y matrix in every iteration. If
that's not what you want, you need to change your code -- perhaps to
something like this:

void MyProblem::run()
{
y.assemble(); // do it once before the iteration
for (iteration=0; ...)
{
x.assemble();
x.solve();

// no assembly any more here
y.solve();
}
}

I will note that if you write "I am not sure how my matrix is being
calculated" then apparently you do not actually understand how your
program is working. This is not something we can help you with: *You*
are the author of your program, and *you* need to be confident that you
understand how your program works or how else can you be confident that
it is actually computing things that are correct?

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