How to change vector values of a Function

Asked by Xujun Zhao

a beginner's problem for C++ implementation:

I created two functions in the same function space, say
Function f1(V), f2(V)

We know there are two main components for a function, vector and functionspace. Here f1 and f2's vector should have the same length. Now I want to change the vector values of f2, for example, f2.vector() = 0.5*(f1.vector() + f2.vector()). what operations do I need to do?

Thank you for your answers.

Question information

English Edit question
FEniCS Project Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Xujun Zhao (xzhao99) said :

OK, I check the source codes and found the solution. Although I am not sure if this is optimal, it does work! Hope it helps to other ones who want to use the same functions.

using vector->get_local() to pick out each components of function vectors
do any operations: + - * / to get an intermediate variable w
using vector->set() to change the vector value into w
finally vector-apply() to finalize the assemble (I am not sure this is necessary, because I also tried not to use "apply" and found that the vector values were changed. Anyone can give me an explanation? )

Revision history for this message
Marie Rognes (meg-simula) said :

Can you help with this problem?

Provide an answer of your own, or ask Xujun Zhao for more information if necessary.

To post a message you must log in.