CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Custom definition for viscosity (https://www.cfd-online.com/Forums/openfoam-programming-development/227492-custom-definition-viscosity.html)

PositronCascade May 30, 2020 22:06

Custom definition for viscosity
 
Hello everyone. I try to define viscosity for multi phase problem, by considering a relation. To do that I wrote the code below:

Code:

    forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter)
    {
        phaseModel& phase = iter();
        const volScalarField& alpha = phase;
        phaseModel& phase2 = iter();
        const volScalarField& alpha2 = phase2;       


            dimensionedScalar ksi11a = 1 + sqrt(phase.eta()/phase.eta())*pow(phase.mol()/phase.mol(), 1.0/4.0);
            dimensionedScalar ksi12a = 1 + sqrt(phase.eta()/phase2.eta())*pow(phase2.mol()/phase.mol(), 1.0/4.0);
            dimensionedScalar ksi11 = pow(ksi11a,2)/sqrt(8* (1 + phase.mol()/phase.mol()));
            dimensionedScalar ksi12 = pow(ksi12a,2)/sqrt(8* (1 + phase.mol()/phase2.mol()));
           
            phase.nu() = alpha*phase.eta() / (alpha*ksi11 + alpha2*ksi12)/phase.rho();

        }

So, ksi11 must be 1 and ksi12 must be 0.331. However, both values become 1; so probably, I cannot obtain phase and phase2 values separately and both ksi values turn into 1. May you suggest me a way to obtain values of both phases at the same time?

superkelle May 31, 2020 01:48

Your phase and phase2 are the same phases since you set them with the same iterator in the same step. So you solve ksi12a = 1+1*1 = 2 and ksi12 =4/4 =1. And the same for ksi11a but there you even divide by its own valus, so i dont get the point for these.

PositronCascade May 31, 2020 05:11

Quote:

Originally Posted by superkelle (Post 772710)
Your phase and phase2 are the same phases since you set them with the same iterator in the same step. So you solve ksi12a = 1+1*1 = 2 and ksi12 =4/4 =1. And the same for ksi11a but there you even divide by its own valus, so i dont get the point for these.

Currently yes, ksi11 and ksi12 are same; because I cannot iterate through phases. I have two phases and I need to access their phase values under the same forAllIter loop at the same time. So, somehow phase2 must be something like iter++, but I couldn't do that. I need help at that point.

superkelle May 31, 2020 08:22

Well I am currently learning OF and c++ my self, so please don't be too harsh on me if I am wrong^^. So I dont have any knowledge about these phaseModel handling and so on, but I think you can just use something like *(iter-1). I tried it for a simple List of Lists:
Code:

List<List<int>> myListList({{1, 2, 3, 4},{5, 6, 7, 8, 9},{10, 11, 12}});
   
   
    forAllIter(List<List<int>>, myListList, iter)
    {   
       
        Info << "current List" << endl;
        Info << (*iter)<< endl << endl;
       
        if(iter != myListList.end()-1)
        {
            Info << "next List" << endl;
            Info << *(iter+1) << endl <<  endl;
        }
        else
        {
            Info << "no next List" << endl;
        }
    }

What resulted in:


Code:

current List
4(1 2 3 4)

next List
5(5 6 7 8 9)

current List
5(5 6 7 8 9)

next List
3(10 11 12)

current List
3(10 11 12)

no next List


PositronCascade May 31, 2020 08:47

Quote:

Originally Posted by superkelle (Post 772731)
Well I am currently learning OF and c++ my self, so please don't be too harsh on me if I am wrong^^. So I dont have any knowledge about these phaseModel handling and so on, but I think you can just use something like *(iter-1). I tried it for a simple List of Lists:
Code:

List<List<int>> myListList({{1, 2, 3, 4},{5, 6, 7, 8, 9},{10, 11, 12}});
   
   
    forAllIter(List<List<int>>, myListList, iter)
    {   
       
        Info << "current List" << endl;
        Info << (*iter)<< endl << endl;
       
        if(iter != myListList.end()-1)
        {
            Info << "next List" << endl;
            Info << *(iter+1) << endl <<  endl;
        }
        else
        {
            Info << "no next List" << endl;
        }
    }

What resulted in:


Code:

current List
4(1 2 3 4)

next List
5(5 6 7 8 9)

current List
5(5 6 7 8 9)

next List
3(10 11 12)

current List
3(10 11 12)

no next List


Thanks. I agree, I would do this way as well. But I just couldn't fınd a working way to express these in OpenFOAM.


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