CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Generating coefficient matrix

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 12, 2015, 22:48
Question Generating coefficient matrix
  #1
New Member
 
Mehdi
Join Date: Aug 2013
Location: Australia
Posts: 22
Rep Power: 12
mahdi_kh8 is on a distinguished road
Send a message via Yahoo to mahdi_kh8
Hello my friends,

I have a simple question but I have a difficulty solving that and need some help and advice.

I am using finite volume method to solve N-S equations.

Assume I have the coefficients: AP, AW, AWW, AE, AEE
(For 1D case)

How I can construct coefficient matrix using these coefficients?
For better understanding please apply your answer in the sample code.

Sample code:

Code:

// CONSTRUCT MATRIX OF COEFFICIENT ( X DIRECTION )
// U: ( 3 --> NIM1 , 2 --> NJM1 )
double[,] CoefAx = new double[NI, NI];

for (int JJ = 2; JJ <= NJM1; JJ++)
{
// matrix of coefficient
    for (int I = 3; I <= NIM1; I++)
{
    {
        for (int J = 3; J <= NIM1; J++)
        {
            // Inside matrix
            if (I == J && I >= 5 && I <= NIM1 - 2)
            {
                CoefAx[I, J] = AP[I, JJ];
                CoefAx[I, J + 1] = -AE[I, JJ];
                CoefAx[I, J - 1] = -AW[I, JJ];
                CoefAx[I, J + 2] = -AEE[I, JJ];
                CoefAx[I, J - 2] = -AWW[I, JJ];
            }
            // last raw of matrix
            if (I == J && I == NIM1)
            {
                CoefAx[I, J] = AP[I, JJ];
                CoefAx[I, J - 1] = -AW[I, JJ];
                CoefAx[I, J - 2] = -AWW[I, JJ];
            }
            if (I == J && I == NIM1 - 1)
            {
                CoefAx[I, J] = AP[I, JJ];
                CoefAx[I, J - 1] = -AW[I, JJ];
                CoefAx[I, J - 2] = -AWW[I, JJ];
                CoefAx[I, J + 1] = -AE[I, JJ];
            }
            // first raw of matrix
            if (I == J && I == 3)
            {
                CoefAx[I, J] = G.AP[I, JJ];
                CoefAx[I, J + 1] = -G.AE[I, JJ];
                CoefAx[I, J + 2] = -G.AEE[I, JJ];
            }
            if (I == J && I == 4)
            {
                CoefAx[I, J] = AP[I, JJ];
                CoefAx[I, J + 1] = -AE[I, JJ];
                CoefAx[I, J + 2] = -AEE[I, JJ];
                CoefAx[I, J - 1] = -AW[I, JJ];
            }
        }
    double[] Bx = new double[G.NI];
    }
    // RHS of equation
    for (int I = 3; I <= NIM1; I++)
    {
        Bx[I] = SU[I, JJ] + ANN[I, JJ] * U[I, JJ + 2] + ASS[I, JJ] * U[I, JJ - 2];
    }

    Matrix A = new Matrix(NI, NI);
    Matrix b = new Matrix(NI, 1);
    double temm;

    for (int i = 3; i <= NIM1; i++)
    {
        for (int j = 3; j <= NIM1; j++)
        {
            A[i, j] = CoefAx[i, j];
            temm = Bx[i];

            b[i, 0] = temm;       
        }
    }

     // Solving equation
    Matrix xx = (A).SolveWith(b);
    for (int i = 0; i <= NIM1; i++)    
        { 
            U[i, JJ] = xx[i, 0];    
        } 
}
mahdi_kh8 is offline   Reply With Quote

Old   July 13, 2015, 03:26
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,773
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
In 1D is very simple, AP is in the main diagonal, AE, AEE are in the next upper diagonals and AW, AWW in the next lower one. I see you already did that.
FMDenaro is offline   Reply With Quote

Old   July 13, 2015, 03:36
Question
  #3
New Member
 
Mehdi
Join Date: Aug 2013
Location: Australia
Posts: 22
Rep Power: 12
mahdi_kh8 is on a distinguished road
Send a message via Yahoo to mahdi_kh8
Quote:
Originally Posted by FMDenaro View Post
In 1D is very simple, AP is in the main diagonal, AE, AEE are in the next upper diagonals and AW, AWW in the next lower one. I see you already did that.
So my code is correct ?
What about boundary condition ?
I am a little bit confused about constructing matrix and applying BC.
mahdi_kh8 is offline   Reply With Quote

Old   July 13, 2015, 03:41
Default
  #4
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,773
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by mahdi_kh8 View Post
So my code is correct ?
What about boundary condition ?
I am a little bit confused about constructing matrix and applying BC.

you have to modify the corresponding term in the diagonal and, depending on either Neumann or Dirichlet BC.s add a term to the known terms vector
FMDenaro is offline   Reply With Quote

Old   July 13, 2015, 03:52
Default
  #5
New Member
 
Mehdi
Join Date: Aug 2013
Location: Australia
Posts: 22
Rep Power: 12
mahdi_kh8 is on a distinguished road
Send a message via Yahoo to mahdi_kh8
Quote:
Originally Posted by FMDenaro View Post
you have to modify the corresponding term in the diagonal and, depending on either Neumann or Dirichlet BC.s add a term to the known terms vector
If the variable was Pressure and BC was as follow:

Left: dP/dx = 0
Right: P=0

Could you please apply these BC in the code?

Thank you
mahdi_kh8 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
How to write the Coefficient Matrix in a file And901 OpenFOAM Programming & Development 1 October 9, 2014 10:28
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 06:28
Doxygen documentation Tanay OpenFOAM Installation 9 September 23, 2011 11:40
ParaView and Qt 4.3.5 on Mac OS X 10.6 Adrian OpenFOAM 3 August 8, 2010 03:16
Automotive test case vinz OpenFOAM Running, Solving & CFD 98 October 27, 2008 08:43


All times are GMT -4. The time now is 02:11.