Retrieving the array from the solution in a coupled system

Asked by Yaakoub El Khamra on 2012-09-27

Greetings
Andy Terrel has been helping me with CBC and pointed out something interesting when I work with a system of coupled equations in CBC.

If my PDESys looks like this:
PDESystem([['Pw', 'Sw']], problem, solver_parameters)

retrieving the solution this way:
problem.pdesystems['Scalar'].Pw_.parent_vector.array()

returns the array for Pw and Sw (i.e. the whole system, not just Pw). This makes computing min/max values trickly. Is there a stable/easy/documented way of retrieving the solution in a coupled system?

Also is there a better way to plot? Right now I use something like this:
plot(problem.pdesystems['Scalar'].Pw_, interactive=True, title="Pw")

Many thanks in advance
Regards
Yaakoub

Question information

Language:
English Edit question
Status:
Solved
For:
CBC.PDESys Edit question
Assignee:
No assignee Edit question
Solved by:
Yaakoub El Khamra
Solved:
Last query:
Last reply:

Hi Yaakoub,

Den Sep 27, 2012 kl. 9:30 PM skrev Yaakoub El Khamra:

> New question #209756 on CBC.PDESys:
> https://answers.launchpad.net/cbcpdesys/+question/209756
>
>
> Greetings
> Andy Terrel has been helping me with CBC and pointed out something interesting when I work with a system of coupled equations in CBC.
>
> If my PDESys looks like this:
> PDESystem([['Pw', 'Sw']], problem, solver_parameters)
>
> retrieving the solution this way:
> problem.pdesystems['Scalar'].Pw_.parent_vector.array()
>
> returns the array for Pw and Sw (i.e. the whole system, not just Pw). This makes computing min/max values trickly. Is there a stable/easy/documented way of retrieving the solution in a coupled system?

This is a tricky problem. Using just one processor it is trivial, but otherwise there is no straightforward way of retrieving the subarrays. See, e.g., this thread https://answers.launchpad.net/dolfin/+question/209095

For one processor the dofs are laid out structured and you can retrieve the subarrays easily. You can use

sol = problem.pdesystems['Scalar']
sol.Pw_.get_array_slice(sol.Pw_)

which gives you an array of the Pw_ vector. See split_Function the top of PDESystem.py for how this works.

I can help you if you are using more processors as well, but that takes some more effort:-)

>
> Also is there a better way to plot? Right now I use something like this:
> plot(problem.pdesystems['Scalar'].Pw_, interactive=True, title="Pw")

It certainly helps to have a short form for problem.pdesystems['Scalar'] :-) To obtain better plots use VTK. You cannot dump coupled Functions to VTK, so do something like:

f = File("PwSw.pvd")
f << project(sol.Pw_, sol.V["Pw"])

Best regards

Mikael

>
> Many thanks in advance
> Regards
> Yaakoub
>
> --
> You received this question notification because you are an answer
> contact for CBC.PDESys.

Yaakoub El Khamra (yelkhamra) said : #2

Thank you very much Mikael! I will be using single processor for a good while to come, at least 3 months. Would the dumping to a pvd file work in parallel? If so, I am all set for a good while to come.

Regards
Yaakoub

The dumping works in parallel as well. Just not the numpy array extraction.

Mikael

Den Sep 27, 2012 kl. 11:01 PM skrev Yaakoub El Khamra:

> Question #209756 on CBC.PDESys changed:
> https://answers.launchpad.net/cbcpdesys/+question/209756
>
> Yaakoub El Khamra posted a new comment:
>
> Thank you very much Mikael! I will be using single processor for a good while to come, at least 3 months. Would the dumping to a pvd file work in parallel? If so, I am all set for a good while to come.
>
> Regards
> Yaakoub
>
> --
> You received this question notification because you are an answer
> contact for CBC.PDESys.

Yaakoub El Khamra (yelkhamra) said : #4

Perfect, thank you very much sir!