Hello Dumuxers,

We found a crucial bug in the mpnc diffusion model in 
dumux/implicit/mpnc/diffusion/fluxvariables.hh which will cause memory leaks if 
a fluidsystem with more than 4 components is used in the 2D case. These are the 
pieces of code which are relevant:

>From line 81:
     const unsigned int i = face.i;
     const unsigned int j = face.j;

from line 119:
        // initialize the diffusion coefficients to zero
        for (int i = 0; i < numComponents; ++i) {
            porousDiffCoeffL_[i] = 0.0;
            for (int j = 0; j < numComponents; ++j)
                porousDiffCoeffG_[i][j] = 0.0;
        }

from line 150:
            if (phaseIdx == wPhaseIdx) {
                // Liquid phase diffusion coefficients in the porous medium
                for (int i = 0; i < numComponents; ++i) {
                    // -> arithmetic mean
                    porousDiffCoeffL_[i]
                        = 1./2*(red_i * elemVolVars[i].diffCoeff(wPhaseIdx, 0, 
i) +
                                red_j * elemVolVars[j].diffCoeff(wPhaseIdx, 0, 
i));
                }
            }
            else {
                // Gas phase diffusion coefficients in the porous medium
                for (int i = 0; i < numComponents; ++i) {
                    for (int j = 0; j < numComponents; ++j) {
                        // -> arithmetic mean
                        porousDiffCoeffG_[i][j]
                            = 1./2*(red_i * elemVolVars[i].diffCoeff(nPhaseIdx, 
i, j) +
                                    red_j * elemVolVars[j].diffCoeff(nPhaseIdx, 
i, j));
                    }
                }
            }

The problem here is that in each loop the variables for the  i and j for the 
scv corners (?) are reused as component indices. So if the number of components 
exceeds the number of corners, elemVolVars[i] and  elemVolVars[j] will not be 
defined and valgrind will complain. Therefore, we suggest to follow the naming 
convention used in dumux/implicit/mpnc/diffusion/volumevariables.hh. i should 
be renamed to compIIdx and j to compJIdx. Note that the indices of 
elemVolVars[i] and  elemVolVars[j] stay unchanged. Here is the code:

        // initialize the diffusion coefficients to zero
        for (int compIIdx = 0; compIIdx < numComponents; ++compIIdx) {
            porousDiffCoeffL_[compIIdx] = 0.0;
            for (int compJIdx = 0; compJIdx < numComponents; ++compJIdx)
                porousDiffCoeffG_[compIIdx][compJIdx] = 0.0;
        }

            if (phaseIdx == wPhaseIdx) {
                // Liquid phase diffusion coefficients in the porous medium
                for (int compIIdx = 0; compIIdx < numComponents; ++compIIdx) {
                    // -> arithmetic mean
                    porousDiffCoeffL_[compIIdx]
                        = 1./2*(red_i * elemVolVars[i].diffCoeff(wPhaseIdx, 0, 
compIIdx) +
                                red_j * elemVolVars[j].diffCoeff(wPhaseIdx, 0, 
compIIdx));
                }
            }
            else {
                // Gas phase diffusion coefficients in the porous medium
                for (int compIIdx = 0; compIIdx < numComponents; ++compIIdx) {
                    for (int compJIdx = 0; compJIdx < numComponents; 
++compJIdx) {
                        // -> arithmetic mean
                        porousDiffCoeffG_[compIIdx][compJIdx]
                            = 1./2*(red_i * elemVolVars[i].diffCoeff(nPhaseIdx, 
compIIdx, compJIdx) +
                                    red_j * elemVolVars[j].diffCoeff(nPhaseIdx, 
compIIdx, compJIdx));
                    }
                }
            }

Could someone please check and commit the code?


Best regards

Georg Futter

--------------------------
German Aerospace Center (DLR)
Institute of Engineering Thermodynamics | Computational Electrochemistry | 
Pfaffenwaldring 38-40 | 70569 Stuttgart

Dipl.-Ing. Georg Futter | Ph.D. student
Telefon 0711/6862-8135 | [email protected]<mailto:[email protected]>
www.DLR.de<http://www.dlr.de/>


_______________________________________________
Dumux mailing list
[email protected]
https://listserv.uni-stuttgart.de/mailman/listinfo/dumux

Reply via email to