CFD Online URL
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

Matrix addressing

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By chrisb2244
  • 1 Post By jherb
  • 1 Post By l_r_mcglashan

Reply
 
LinkBack Thread Tools Display Modes
Old   April 7, 2014, 18:39
Default Matrix addressing
  #1
Senior Member
 
Join Date: Jan 2012
Posts: 159
Rep Power: 4
maybee is on a distinguished road
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:
[A1 A2 A3] * [B1 B2 B3] = [A1B1 A2B2 A3B3]

Last edited by maybee; April 7, 2014 at 20:10.
maybee is offline   Reply With Quote

Old   April 7, 2014, 23:20
Default
  #2
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 3
chrisb2244 is on a distinguished road
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
In terms of your first question, I imagine what you want is D [0] [0] but I haven't tried explicitly using matrices in OF, so give me a minute to find relevant documentation.

However, your `pow' call is going to return 1 every time - you have x^0.

Last edited by chrisb2244; April 8, 2014 at 22:14. Reason: Turns out this isn't defined for matrices, only vectors
chrisb2244 is offline   Reply With Quote

Old   April 8, 2014, 07:00
Default
  #3
Senior Member
 
Join Date: Jan 2012
Posts: 159
Rep Power: 4
maybee is on a distinguished road
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();
where "D" and "Prod" are "Matrix<Field<double>,double>" and "T()" should return the transpose of "Prod".

and got:

Quote:
/home/USER/SolverNEW/NEW/NEW_TransportEqns.H:141: error:
no match for ‘operator*’ in ‘D * Foam::Matrix<Form, Type>::T() const [with Form = Foam::Field<double>, Type = double]()’
I really need to know which matrice methods OpenFoam provides otherwise I ll have to use armadillo.

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;
where Prod,SF and w are of type "Matrix<Field<double>,double>"

only getting:

Quote:
/home/USER/SolverNEW/NEW/NEW_TransportEqns.H:137: error: no match for ‘operator&’ in ‘SF & w’
greetings maybee

Last edited by maybee; April 8, 2014 at 18:12.
maybee is offline   Reply With Quote

Old   April 8, 2014, 22:25
Default
  #4
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 3
chrisb2244 is on a distinguished road
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
will work for A = \vec{A_1 A_2 A_3} and B = \vec{B_1 B_2 B_3}, as you asked, but not for matrices more generally. I have edited my answer earlier to reflect that.

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)
Does that fail in a way that
Code:
Matrix<scalarField, scalar> D(2,1)
does not?

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
sharonyue likes this.
chrisb2244 is offline   Reply With Quote

Old   April 9, 2014, 05:58
Default
  #5
Senior Member
 
Join Date: Jan 2012
Posts: 159
Rep Power: 4
maybee is on a distinguished road
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:

Defining a Matrix in OpenFOAM-1.6-ext

Quote:

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)
Does that fail in a way that
Code:
Matrix<scalarField, scalar> D(2,1)
does not?

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.
Same over here . Initially I had the same thoughts. I also tried "int" for the "Form" which does compile fine.
I ll use armadillo now, perhaps OpenFOAM s Matrix class is not finished yet (?)....

greetings maybee
maybee is offline   Reply With Quote

Old   April 9, 2014, 11:33
Default
  #6
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 249
Rep Power: 9
jherb is on a distinguished road
I guess this might help:
http://www.foamcfd.org/Nabla/guides/...sGuidese4.html
maybee likes this.
jherb is offline   Reply With Quote

Old   April 9, 2014, 12:41
Default
  #7
Senior Member
 
Join Date: Jan 2012
Posts: 159
Rep Power: 4
maybee is on a distinguished road
nice, but still I ll use armadillo since I am working with matrices and not tensors.
maybee is offline   Reply With Quote

Old   April 9, 2014, 13:00
Default
  #8
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 13
l_r_mcglashan will become famous soon enough
Of course the Matrix class works. It's not there for nothing.

Quote:
Originally Posted by maybee View Post
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?
What do you expect to happen with the first template parameter as 'scalarField'?

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.
maybee likes this.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   April 9, 2014, 13:13
Default
  #9
Senior Member
 
Join Date: Jan 2012
Posts: 159
Rep Power: 4
maybee is on a distinguished road
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:
A * B = AB
[A1 A2 A3] * [B1 B2 B3] = [A1B1 A2B2 A3B3]
Note, that I just used * here for the unknown method/operator.
maybee is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ldu matrix, ldu addressing maybee OpenFOAM Programming & Development 0 December 7, 2013 13:40
more equation in block matrix system yhaomin2007 OpenFOAM 1 September 6, 2012 09:33
Force can not converge colopolo CFX 13 October 4, 2011 23:03
OpenFOAM version 1.6 details lakeat OpenFOAM Running, Solving & CFD 42 August 26, 2009 22:47
Addressing matrix element and reuse of system matrix marziolettich OpenFOAM Running, Solving & CFD 2 February 19, 2008 06:04


All times are GMT -4. The time now is 16:47.