CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Workings of setValuesFromList (http://www.cfd-online.com/Forums/openfoam-programming-development/95743-workings-setvaluesfromlist.html)

lrunber December 30, 2011 20:48

Workings of setValuesFromList
 
Dear Foamers,

I am trying to understand the function setValuesFromList which is in fvMatrix.C lines 181-267 in OF 2.1.0.

As I understand the core is executed in lines 207 & 208:
Code:

        psi[celli] = value;
        source_[celli] = value*Diag[celli];

which sets the source vector equal to the diagonal times the value specified. This makes sense and I can understand.

However I fail to fully grasp lines 220-232, i.e.,

Code:

            if (symmetric())
                    {
                        if (celli == own[facei])
                        {
                            source_[nei[facei]] -= upper()[facei]*value;
                        }
                        else
                        {
                            source_[own[facei]] -= upper()[facei]*value;
                        }

                        upper()[facei] = 0.0;
                    }

* What is the meaning of upper()?
* What is the meaning of "source_[nei[facei]] -= upper()[facei]*value", does this set the source vector of the neighbor cells, and why does it only subtract and not set?
* Would it not be suffice to just set the neighbor matrix coefficients (a_N) to zero?

Thank you very much, all input is very much appreciated.

wyldckat December 31, 2011 11:17

Greetings lrunber,

I'm not familiar with this part of the code of OpenFOAM, but since we are near the end of 2011 and beginning of 2012 (and if will be like last year), the experts on this subject won't come back for a another few days.

So, based on the following information:
  • Source: http://foam.sourceforge.net/docs/cpp....html#_details
    Quote:

    lduMatrix is a general matrix class in which the coefficients are stored as three arrays, one for the upper triangle, one for the lower triangle and a third for the diagonal.
    Addressing arrays must be supplied for the upper and lower triangles.
  • The outer if block checks for symmetry, therefore the contents are meant to be related only to symmetry.

Quote:

Originally Posted by lrunber (Post 337444)
* What is the meaning of upper()?

Should be the reference to the Upper matrix of a symmetric matrix. This way only half of the matrix needs to be stored.

Quote:

Originally Posted by lrunber (Post 337444)
* What is the meaning of "source_[nei[facei]] -= upper()[facei]*value", does this set the source vector of the neighbor cells, and why does it only subtract and not set?

In OpenFOAM, operators sometimes don't do what we expect them to do. Check the source code when in doubt: http://foam.sourceforge.net/docs/cpp...ce.html#l00215

Quote:

Originally Posted by lrunber (Post 337444)
* Would it not be suffice to just set the neighbor matrix coefficients (a_N) to zero?

By what I can deduce from that set of code, for whatever reason, that "upper" matrix seems to only contain weights. That is why the set value is weighed-in with the upper value, then neutralized so it won't be used in future iterations.

This should get you going forward, at least until someone more experienced can answer you!

Best regards,
Bruno

lrunber December 31, 2011 13:30

Thank you very much Bruno!
May I also take this opportunity to wish you a fantastic 2012 :)

I think I may have figured it out, I will write out my understanding and if someone could please just comment on the correctness..

The discretized FVM equation for each cell can be written out as:

a_p \phi_p + \sum a_n \phi_n = r (Eq. 1)

In the ldumatrix these terms correspond to:
a_p = diag()
a_n = upper() and lower()
r = source_

and the solution variable corresponds to:
\phi = psi_

To "force" the solution in the specified cells (cellLabels) to the specified values (values), the following operations are performed on the matrix for each of the concerned equations:
\phi_p = value (line: 207)
r = value * a_p (line: 208)
a_n = 0.0 (line: 231 or 244 & 245, depending on matrix symmetry)

This results in the trivial solution of Eq. 1 i.e.,
a_p \phi_p + \sum 0.0 * \phi_n = a_p \phi_p

However, there remains the important aspect of the influence of the fixed cells on their neighbor cells and setting a_n = 0.0 removes this influence (since it is zero'd!). This is where I am very impressed with this code (if I understand it correctly), since before the zero'ing of a_n, the influence of the concerned cells is added to neighbors by modifying the source term for the neighboring cells (r^* ) using the old a_n value before setting it to zero.
r^* = r^* - \sum a_n * value (lines 224 & 228 or 237 & 241 depending on symmetry)

I hope my understanding is correct. Thanks again Bruno for putting me on track.


All times are GMT -4. The time now is 20:38.