CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Defining a Matrix in OpenFOAM-1.6-ext

Register Blogs Community New Posts Updated Threads Search

Like Tree8Likes
  • 3 Post By wyldckat
  • 4 Post By Daniel_Khazaei
  • 1 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 21, 2013, 12:33
Default Defining a Matrix in OpenFOAM-1.6-ext
  #1
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
Hello foamers


I am trying to define a Matrix in my OpenFOAM solver but I have a few problems.
I try to describe my problem with an example:

Assuming I want to define a Matrix in the solver, this is what I do:

Matrix<scalar> A(n, m, 0.0);

Now when I want to compile the solver, it gives me the following error:

Code:
setInterfaceDisplacement.H:98: error: wrong number of template arguments (1, should be 2)
/opt/OpenFOAM/OpenFOAM-1.6-ext/src/OpenFOAM/lnInclude/Matrix.H:54: error: provided for ‘template<class Form, class Type> class Foam::Matrix’
I can understand that I need to add one more argument in declaration, but I don't know what does "class Form" mean?


regards
Daniel_Khazaei is offline   Reply With Quote

Old   November 26, 2013, 11:45
Default
  #2
Member
 
Camille Bilger
Join Date: Jul 2013
Posts: 43
Rep Power: 13
kmou is on a distinguished road
Hi,

I am encountering the same problem and would be grateful if you could share how you resolved this problem. Thank you very much.
kmou is offline   Reply With Quote

Old   November 26, 2013, 18:11
Default
  #3
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

Actually, while I was tracking kmou's posts, this previous thread gave the hint: http://www.cfd-online.com/Forums/ope...t-compile.html
The solution seems to be to use "scalarSquareMatrix" instead of "Matrix<scalar>".

A bit more explanation:
  1. The definition of "scalarSquareMatrix" is made in the file "src/OpenFOAM/matrices/scalarMatrices/scalarSquareMatrix.H", where it defines the class based on the "SquareMatrix" template:
    Code:
    class scalarSquareMatrix
    :
        public SquareMatrix<scalar>
  2. The template class "SquareMatrix" is defined in the file "src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H", as follows:
    Code:
    template<class Type>
    class SquareMatrix
    :
        public Matrix<SquareMatrix<Type>, Type>
    Namely, said "class Form" is "SquareMatrix<Type>" in this case... pretty confusing template voodoo, isn't it?
Either way, the quick solution is indicated in the post #3 at the aforementioned thread .

Best regards,
Bruno
__________________

Last edited by wyldckat; March 27, 2016 at 05:25. Reason: repaired link
wyldckat is offline   Reply With Quote

Old   November 27, 2013, 12:46
Default
  #4
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
thanks for the suggestion...

I had resolved that issue a few weeks ago. I have changed the declaration as follow:

Matrix <scalarField,scalar> A (n,m)

---------


squareScalarMatrix is working fine on square matrices but how can I define a matrix with one column or one row?

like this one:

Matrix <scalarField,scalar> A (n,1) or A (1,n)

-------

OK I have fixed the last one by using rectangular matrix
Daniel_Khazaei is offline   Reply With Quote

Old   November 27, 2013, 14:26
Default
  #5
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
Quote:
Originally Posted by kmou View Post
Hi,

I am encountering the same problem and would be grateful if you could share how you resolved this problem. Thank you very much.
you need to add the following headers to your program:

#include "scalarSquareMatrix.H" --->> for square type matrix

if you want to define a square matrix: A (n,n) and initiate it with 0

scalarSquareMatrix A(n, 0.0);


#include "RectangularMatrix.H" ---->> for rectangular matrix

if you want to define a rectangular matrix: A (n,m)

RectangularMatrix <scalar> A(n,m);
Daniel_Khazaei is offline   Reply With Quote

Old   December 2, 2013, 06:06
Default
  #6
Member
 
Camille Bilger
Join Date: Jul 2013
Posts: 43
Rep Power: 13
kmou is on a distinguished road
Thank you Daniel and Bruno for your replies.
So new classes of matrices have been created, such as SquareMatrix and RectangularMatrix, which effectively correspond do the "Form" that is required. Thus, for each Matrix<scalar> that I have, I will need to make a decision as to if it is a Square matrix, or a Rectangular matrix or Diagonal matrix etc...
kmou is offline   Reply With Quote

Old   March 23, 2016, 11:19
Angry Matrix with different dimensions for different elements (kg,m,N,etc)
  #7
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
Hi guys i have a problem related to matrices. I have to define and write a matrix in which every element have different dimensions. for example 1st element has dimensions in kilogram 2nd in meters 3rd in second like that. Please guide me how can i do that.
13msmemusman is offline   Reply With Quote

Old   March 26, 2016, 07:41
Default
  #8
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by 13msmemusman View Post
Hi guys i have a problem related to matrices. I have to define and write a matrix in which every element have different dimensions. for example 1st element has dimensions in kilogram 2nd in meters 3rd in second like that. Please guide me how can i do that.
Quick answer: AFAIK, that's not possible. You should not include the dimensions in the matrix and instead you should only use the values.
13msmemusman likes this.
wyldckat is offline   Reply With Quote

Old   March 27, 2016, 03:50
Default
  #9
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
Thank you. but there should be a way...... coz..........
13msmemusman is offline   Reply With Quote

Old   March 27, 2016, 07:27
Default
  #10
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by 13msmemusman View Post
Thank you. but there should be a way...... coz..........
If you had provided an example I could have worked with, it would have be easier/faster for me to figure it out.

Anyway, this is an example of how to do it:
Code:
    SquareMatrix<dimensionedScalar> hmm(3);

    hmm[0][0].dimensions().reset(dimLength);
    hmm[0][0] = dimensionedScalar("cookie1",dimLength,-3.0);
    hmm[0][1] = 10.0;
    hmm[0][2] = -4.0;
    hmm[1][0] = 2.0;
    hmm[1][1] = 3.0;
    hmm[1][2] = 10.0;
    hmm[2][0] = 2.0;
    hmm[2][1] = 6.0;
    hmm[2][2] = 1.0;
It's based on the test application "applications/test/Matrix" and it took me a while to figure out the details.
wyldckat is offline   Reply With Quote

Old   March 27, 2016, 07:54
Default
  #11
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
Screenshot from 2016-03-23 23:45:51.png

Please have a look on this file attached.
13msmemusman is offline   Reply With Quote

Old   March 27, 2016, 10:34
Default
  #12
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by 13msmemusman View Post
Please have a look on this file attached.
Quick questions:
  1. What is the calculation you're trying to perform?
    • I ask this because this matrix has to be multiplied by something!?
  2. How exactly is this matrix meant to be used?
wyldckat is offline   Reply With Quote

Old   March 27, 2016, 10:42
Default
  #13
Member
 
Muhammad Usman
Join Date: Feb 2014
Posts: 91
Rep Power: 0
13msmemusman is on a distinguished road
its matrix for mass in mass damper spring system. actually i am working with some kind of fluid and vehicle dynamics interface. Yes this matrix is gonna be multiplied by a vector
13msmemusman is offline   Reply With Quote

Old   March 27, 2016, 11:04
Default
  #14
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Muhammad,

Quote:
Originally Posted by 13msmemusman View Post
its matrix for mass in mass damper spring system. actually i am working with some kind of fluid and vehicle dynamics interface. Yes this matrix is gonna be multiplied by a vector
I don't know if you've noticed, but if you keep giving vague descriptions, then I'm only able to give vague answers as well

There is a thread explaining how to provide information, so that this kind of vague exchange of information doesn't happen: http://www.cfd-online.com/Forums/ope...-get-help.html

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   April 16, 2016, 21:55
Default
  #15
Senior Member
 
santiagomarquezd's Avatar
 
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24
santiagomarquezd will become famous soon enough
Quote:
Originally Posted by 13msmemusman View Post
Hi guys i have a problem related to matrices. I have to define and write a matrix in which every element have different dimensions. for example 1st element has dimensions in kilogram 2nd in meters 3rd in second like that. Please guide me how can i do that.
It is not possible in the present versions of FOAM.

Regards!
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D.
Research Scientist
Research Center for Computational Methods (CIMEC) - CONICET/UNL
Tel: 54-342-4511594 Int. 7032
Colectora Ruta Nac. 168 / Paraje El Pozo
(3000) Santa Fe - Argentina.
http://www.cimec.org.ar

Last edited by wyldckat; April 17, 2016 at 11:28. Reason: added quote, because this post was moved from another thread with the same question
santiagomarquezd is offline   Reply With Quote

Old   March 11, 2020, 08:58
Default
  #16
Member
 
Peng Liang
Join Date: Mar 2014
Posts: 60
Rep Power: 12
tjliang is on a distinguished road
Hello Everyone,


my problem is a litle bit related to the Matrix problem. I want to have one field value obtained from a two-dimensional lookup table, which means the value is dependent on two variables. Is it possible that I insert values into the Matrix and look up and interpolate among them? I know it may be quite wrong, any hints from you will be appreciated by me. Thank you.


Best regards,


Peng
tjliang is offline   Reply With Quote

Old   December 11, 2023, 15:44
Default I want to multiply two matrices E and F to obtain G so G = E*F.
  #17
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 281
Rep Power: 22
klausb will become famous soon enough
I want to multiply two matrices E and F to obtain G so G = E*F. I tried the following, I don't get compile errors but from the line //Compute G = E * F onwards, things don't work. Here's my code:

Code:
    // Set the size of the matrices
    const label N = 4; // matrix size
    
    // Declare and initialize lduMatrices E, F, and G
    RectangularMatrix <scalar> E(N,N);
    RectangularMatrix <scalar> F(N,N);
    RectangularMatrix <scalar> G(N,N);

    // Set coefficients for matrix E diagonal
    scalar diagonalValuesE[] = {1.0, 2.0, 3.0, 4.0};
    for (label i = 0; i < N; ++i)
    {
        E[i][i] = diagonalValuesE[i];
    }

    // Set coefficients for matrix F diagonal
    scalar diagonalValuesF[] = {5.0, 6.0, 7.0, 8.0};
    for (label i = 0; i < N; ++i)
    {
        F[i][i] = diagonalValuesF[i];
    }

    //Compute G = E * F
     G=E*F; // THIS DOESN'T WORK I THINK, THERE IS A FUNCTION CALLED 
                 //"multiply", too but I don't know how to use it
     
    // Print the diagonal element G[0][0]
     Info << "Diagonal element G[0][0]: " << G[0][0] << endl;
Regarding "multiply" see: // https://www.openfoam.com/documentati...trices_8H.html

Can someone tell me how to multiply two matrices?
klausb is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solver Compiling error - OF 1.6 ext. raditz OpenFOAM Programming & Development 8 November 4, 2012 10:53
[swak4Foam] OpenFOAM 1.6 and 1.7 with interFoam, groovyBC give different strange results Arnoldinho OpenFOAM Community Contributions 7 December 9, 2010 17:29
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 3 September 8, 2010 07:25
Cross-compiling OpenFOAM 1.6 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 7 January 19, 2010 16:39
OpenFOAM version 1.6 details lakeat OpenFOAM Running, Solving & CFD 42 August 26, 2009 22:47


All times are GMT -4. The time now is 04:56.