How to define transpose of a gridfunction

More
4 years 4 months ago #3075 by dong
After solving the Stokes equation, I got the approximated solution u_h. Now I want to create a matrix
[tex]K=\frac{u_hu_h^T}{|u_h|^2}[/tex]
where $u_h^T$ is the transpose of $u_h$ for another problem.
I did as follows. Please see the attached file.
Code:
uh=SolveStokes() print("uh",uh) I = Id(2) K = uh*uh.trans()/(uh*uh) Z = I + K
Then I got an error.
Code:
uh gridfunction 'gfu.1' on space 'CompoundFESpaces' nested = 0 --------------------------------------------------------------------------- NgException Traceback (most recent call last) <ipython-input-5-34ba77e77d8f> in <module> 95 96 I = Id(2) ---> 97 K = uh*uh.trans()/(uh*uh) 98 Z = I + K NgException: Transpose of non-matrix called
Could you please tell me how to define the transpose of the grid function $u_h$ in this case?
Thank you so much.
Attachments:
More
4 years 4 months ago #3076 by joachim
You have to reshape your CoefficientFunction to a matrix::
Code:
uhmat = CoefficientFunction( uh, dims=(3,1) )

Joachim
More
4 years 4 months ago #3078 by dong
I modified the code like this as you suggested.
Code:
uh=SolveStokes() print("uh",uh) uhmat = CoefficientFunction( uh, dims=(3,1) ) I = Id(2) K = uhmat*uhmat.trans()/(uh*uh) Z = I + K
But I got another error.
Code:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-13-01c2ddca7315> in <module> 96 97 I = Id(2) ---> 98 K = uhmat*uhmat.trans()/(uh*uh) 99 Z = I + K TypeError: __call__(): incompatible function arguments. The following argument types are supported: 1. (self: ngsolve.fem.CoefficientFunction, mip: ngsolve.fem.BaseMappedIntegrationPoint) -> object 2. (self: ngsolve.fem.CoefficientFunction, arg0: numpy.ndarray[ngsolve.fem.MeshPoint]) -> array Invoked with: <ngsolve.fem.CoefficientFunction object at 0x00000000080CA990>

Could you please tell me how to fix this?
Thank you so much.
More
4 years 4 months ago #3079 by joachim
it is just trans without brackets ()
More
4 years 4 months ago #3080 by dong
It worked well. Thank you so much for your clarification.
Time to create page: 0.118 seconds