[deal.II] How to sum up several LinearAlgebraPETSc::MPI::Vector completely_distributed_solution ?

2019-08-01 Thread Phạm Ngọc Kiên
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

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/d2272747-cbc2-475a-85bc-7fb02f9cce57%40googlegroups.com.


Re: [deal.II] How to sum up several LinearAlgebraPETSc::MPI::Vector completely_distributed_solution ?

2019-08-02 Thread Wolfgang Bangerth
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: bange...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/2871cd63-7236-a03d-cb02-8dc49a98a8db%40colostate.edu.


Re: [deal.II] How to sum up several LinearAlgebraPETSc::MPI::Vector completely_distributed_solution ?

2019-08-02 Thread Phạm Ngọc Kiên
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 <
bange...@colostate.edu> đã viết:

> 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: bange...@colostate.edu
> www: http://www.math.colostate.edu/~bangerth/
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/dealii/2871cd63-7236-a03d-cb02-8dc49a98a8db%40colostate.edu
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/CAAo%2BSZeZDo0dLUfG-xtvi1XdRi-BkJb5N0wRCowK52ZrUAa9EA%40mail.gmail.com.


Re: [deal.II] How to sum up several LinearAlgebraPETSc::MPI::Vector completely_distributed_solution ?

2019-08-04 Thread Wolfgang Bangerth
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 :-)

Best
  W.

-- 

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

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/c099b71e-330c-c57d-cf4d-1af0cb7021a2%40colostate.edu.