|
[Sponsors] |
![]() |
![]() |
#1 | |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 ![]() |
hi,
I m currently have to make some matrix calculations and therefore created a matrix like Code:
Matrix<scalarField,scalar> D(2,1); D[1][1] = pow(phase.Size()[celli],0); //addressing of first row first element? The code compiles, but I don t think I am addressing the first element in the first row. Simple question: How can I address the different elements of the matrix? I ve already searched the forum, but could not find the answer. Additionally: How can I do a element/element multiplication with two matrices? Example: Quote:
Last edited by maybee; April 7, 2014 at 19:10. |
||
![]() |
![]() |
![]() |
![]() |
#2 |
Member
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 13 ![]() |
To answer the second question, what you have there is the dot product, right?
Openfoam implements the dot product of two vectors using Code:
VectorA & VectorB However, your `pow' call is going to return 1 every time - you have x^0. Last edited by chrisb2244; April 8, 2014 at 21:14. Reason: Turns out this isn't defined for matrices, only vectors |
|
![]() |
![]() |
![]() |
![]() |
#3 | ||
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 ![]() |
hi,
first of all thx. I really need to know which mathematical operations are available for objects of class "matrix" . Is there anywhere an overview? I already installed "armadillo", because I could not do Code:
Term[celli]= -(D*Prod.T()).value(); and got: Quote:
EDIT: I know about the pow returning always 1 - I implemented several similar functions which differ in the exponent - I ll probably change this one later for saving a little bit time when running the program. EDIT2: I also tried now Code:
Prod = SF & w; only getting: Quote:
Last edited by maybee; April 8, 2014 at 17:12. |
|||
![]() |
![]() |
![]() |
![]() |
#4 |
Member
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 13 ![]() |
Dear Maybee,
Firstly, sorry for the problems you're having with multiplication - I have checked the documentation more closely and noticed that the dot product is (unsurprisingly) not defined for matrices - only vectors. Hence Code:
A & B ![]() ![]() The documentation for OpenFOAM is available online at http://www.openfoam.org/docs/cpp/ There you will see a search bar in the top right - you can use this to search for functions, or classes, etc. In your case, you would want the class Matrix. (Classes are displayed in the dropdown list as eg Code:
Matrix Foam. I'm unsure what acceptable "Form" is for a matrix - if you or someone else can give a link to documentation explaining this, or alternatively, explain this, that'd be really useful I imagine. My initial guess is that Form describes eg SquareMatrix, SymmetricSquareMatrix, RectangularMatrix etc. As a result of this, part of me feels like you're getting undefined operators because your template substitution is messing you up. If you type Code:
Matrix<Banana<double>, double> D(2,1) Code:
Matrix<scalarField, scalar> D(2,1) I ask because GeometricField<scalar> (== scalarField via typeDef) is not listed as a Form as far as I can see, so I'm wondering if that is because I can't find a suitable list of "Form"s, or if it is not a valid construction. Best, Christian |
|
![]() |
![]() |
![]() |
![]() |
#5 | |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 ![]() |
Hi,
I ve already used the FOAM Docs to search for the matrix class: http://www.openfoam.org/docs/cpp/ But there is not much documentation about mathematical methods that can be used on matrices! I also could not find any list for valid "Forms", only: http://www.cfd-online.com/Forums/ope...m-1-6-ext.html Quote:
![]() I ll use armadillo now, perhaps OpenFOAM s Matrix class is not finished yet (?).... greetings maybee |
||
![]() |
![]() |
![]() |
![]() |
#6 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22 ![]() |
I guess this might help:
http://www.foamcfd.org/Nabla/guides/...sGuidese4.html |
|
![]() |
![]() |
![]() |
![]() |
#7 |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 ![]() |
nice, but still I ll use armadillo since I am working with matrices and not tensors.
|
|
![]() |
![]() |
![]() |
![]() |
#8 | |
Senior Member
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23 ![]() |
Of course the Matrix class works. It's not there for nothing.
Quote:
What is the form of you matrix? Rectangular/Square/Diagonal/Symmetric? You would then do: Matrix<RectangularMatrix<scalar>, scalar> D(2,1); or shorthand (see scalarMatrices.H): scalarRectangularMatrix D(2,1); Most standard matrix operations are available.
__________________
Laurence R. McGlashan :: Website |
||
![]() |
![]() |
![]() |
![]() |
#9 | |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 ![]() |
Ok,
I missread the translation of "rectangular" when translating it :/ . Is there anywhere a list/reference of the matrix operations in OpenFOAM? Furthermore is there defined a method for this operation Quote:
|
||
![]() |
![]() |
![]() |
![]() |
#10 |
New Member
|
for future help...
For [A1 A2 A3] * [B1 B2 B3] = [A1B1 A2B2 A3B3], use scale(A,B). See reference in: http://foam.sourceforge.net/docs/Gui...mmersGuide.pdf |
|
![]() |
![]() |
![]() |
![]() |
#11 | |
Member
Rishikesh
Join Date: Apr 2016
Posts: 63
Rep Power: 10 ![]() |
Quote:
For future reference, The scale(a,b) function has been replaced by cmptMultiply(a,b). See here: scale(a, b) function Last edited by mrishi; August 1, 2020 at 07:56. Reason: added link to relevant post |
||
![]() |
![]() |
![]() |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
ldu matrix, ldu addressing | maybee | OpenFOAM Programming & Development | 0 | December 7, 2013 12:40 |
more equation in block matrix system | yhaomin2007 | OpenFOAM | 1 | September 6, 2012 08:33 |
Force can not converge | colopolo | CFX | 13 | October 4, 2011 22:03 |
OpenFOAM version 1.6 details | lakeat | OpenFOAM Running, Solving & CFD | 42 | August 26, 2009 21:47 |
Addressing matrix element and reuse of system matrix | marziolettich | OpenFOAM Running, Solving & CFD | 2 | February 19, 2008 05:04 |