- Thank you received: 1
How to define transpose of a gridfunction
4 years 4 months ago #3075
by dong
How to define transpose of a gridfunction was created 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.
Then I got an error.
Could you please tell me how to define the transpose of the grid function $u_h$ in this case?
Thank you so much.
[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
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
Thank you so much.
Attachments:
4 years 4 months ago #3076
by joachim
Replied by joachim on topic How to define transpose of a gridfunction
You have to reshape your CoefficientFunction to a matrix::
Joachim
Code:
uhmat = CoefficientFunction( uh, dims=(3,1) )
Joachim
4 years 4 months ago #3078
by dong
Replied by dong on topic How to define transpose of a gridfunction
I modified the code like this as you suggested.
But I got another error.
Could you please tell me how to fix this?
Thank you so much.
Code:
uh=SolveStokes()
print("uh",uh)
uhmat = CoefficientFunction( uh, dims=(3,1) )
I = Id(2)
K = uhmat*uhmat.trans()/(uh*uh)
Z = I + K
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.
4 years 4 months ago #3079
by joachim
Replied by joachim on topic How to define transpose of a gridfunction
it is just trans without brackets ()
Time to create page: 0.118 seconds