How to sum up several LinearAlgebraPETSc::MPI::Vector completely_distributed_solution ?

24 views
Skip to first unread message

Phạm Ngọc Kiên

unread,
Aug 1, 2019, 11:24:46 PM8/1/19
to deal.II User Group
Dear colleagues,

I am trying to solve my problem with different right_hand_sides.

For each right hand side, we can solve by the codes:
    LinearAlgebraPETSc::MPI::Vector completely_distributed_solution(locally_owned_dofs, mpi_communicator);
    SolverControl solver_control;
    PETScWrappers::SparseDirectMUMPS solver(solver_control, mpi_communicator);
    solver.solve(system_matrix, completely_distributed_solution, system_rhs);
    constraints.distribute(completely_distributed_solution);
    locally_relevant_solution = completely_distributed_solution;

I think I can write the codes to assemble the different right hand sides to solve the system with the same system matrix.
This give me the different solutions.

However, I do not know if I can sum up all the completely_distributed_solution from the different right-hand-sides in order to get a vector of solution.
Could you please tell me how to do this?

I would like to thank you very much for your support.

Best regards,
Kien

Wolfgang Bangerth

unread,
Aug 2, 2019, 8:42:43 PM8/2/19
to dea...@googlegroups.com
On 8/1/19 9:24 PM, Phạm Ngọc Kiên wrote:
>
> However, I do not know if I can sum up all the completely_distributed_solution
> from the different right-hand-sides in order to get a vector of solution.
> Could you please tell me how to do this?

You could just sum them up:

AppropriateType sum_of_solutions (...);
for (unsigned int i=0; i<...; ++i)
sum_of_solutions += solution[i];

Of course, the sum of the solutions equals the solution of a single linear
system with the sum of the right hand sides and the same matrix -- which would
by substantially cheaper to compute.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Phạm Ngọc Kiên

unread,
Aug 3, 2019, 12:57:25 AM8/3/19
to dea...@googlegroups.com
Dear Prof. Wolfgang Bangerth,
I have tried with the sum of the right hand side, but as I think, it did not work for my problem.
I will try with your guidance.
Thank you very much.
Best regards,
Kien

Vào Th 7, 3 thg 8, 2019 vào lúc 09:42 Wolfgang Bangerth <bang...@colostate.edu> đã viết:
--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/2871cd63-7236-a03d-cb02-8dc49a98a8db%40colostate.edu.

Wolfgang Bangerth

unread,
Aug 4, 2019, 7:38:42 AM8/4/19
to dea...@googlegroups.com
On 8/2/19 10:57 PM, Phạm Ngọc Kiên wrote:
> I have tried with the sum of the right hand side, but as I think, it did not
> work for my problem.

I think I've made this kind of point on the mailing list before: You make it
sound like you tried something, but it didn't work even though it should have,
and you just moved on and tried something else instead. That's rarely a good
approach: If it *should* work, it should work. If it doesn't, it's indicative
of a bug somewhere, and you should try to find and *understand* the bug,
rather than just go a different route that might simply result in a different
way of exposing this kind of bug. Trust me: There is great power in
*understanding* why something doesn't work!

In your case, you've chosen an alternative route that also happens to be
vastly more inefficient :-)
Reply all
Reply to author
Forward
0 new messages