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

Improve simpleFoam convergence

Register Blogs Community New Posts Updated Threads Search

Like Tree8Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 5, 2010, 17:04
Default
  #41
Senior Member
 
Daniele
Join Date: Feb 2010
Posts: 134
Rep Power: 16
Daniele111 is on a distinguished road
Thanks you Martin, it works fine. I'll go to Germany and I'll offer you a good beer! Do you get correct syntax also for turbolent case this time in the code? For single core I wrote code coping it from OpenFoam utility.
Daniele
Daniele111 is offline   Reply With Quote

Old   November 5, 2010, 18:15
Default
  #42
Senior Member
 
Martin
Join Date: Oct 2009
Location: Aachen, Germany
Posts: 255
Rep Power: 22
MartinB will become famous soon enough
Beer is fine

If you need more data to be written, just post your single core code, I'll have a look at it. I don't use turbulence for my simulations here, so I'm not sure if it will work with turbulent flow. But if you can provide a simple test case for simpleFoam we can check it...

See you in Germany

Martin
MartinB is offline   Reply With Quote

Old   November 6, 2010, 10:02
Default
  #43
Senior Member
 
Daniele
Join Date: Feb 2010
Posts: 134
Rep Power: 16
Daniele111 is on a distinguished road
I changed fot single core your old code in this way:


#include "RASModel.H"
// write matlab file
{
Info << "Writing wall shear stress for matlab" << endl;

word wallPatchName = "bottom";
Info << "Searching for patch " << wallPatchName << endl;

// Check, if the patch name exists:
label patchID = mesh.boundaryMesh().findPatchID(wallPatchName);
if (patchID < 0)
{
Info << "No patch found with name \"" << wallPatchName << "\"!"
<< endl;
}
else
{
/* for laminar case:
Info<< "Reading viscosity nu\n" << endl;
dimensionedScalar nu_
(
laminarTransport.lookup("nu")
);
*/
// calculating wall shear rate


#include "createFields2.H"
mesh.readUpdate();
volSymmTensorField Reff(RASModel->devReff());
volVectorField tau
(
IOobject
(
"tau",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedVector
(
"tau",
Reff.dimensions(),
vector::zero
)
);

forAll(tau.boundaryField(), patchi)
{
tau.boundaryField()[patchi] =
(
-mesh.Sf().boundaryField()[patchi]
/mesh.magSf().boundaryField()[patchi]
) & Reff.boundaryField()[patchi];
}


// Pointer to the patch we want to have shear stress for:
const polyPatch& cPatch = mesh.boundaryMesh()[patchID];
label nFaces = cPatch.size();

pointField faceCenterCoords(nFaces, vector(0,0,0));
pointField faceAreas(nFaces, vector(0,0,0));
pointField wallShearStress(nFaces, vector(0,0,0));

label runFaces = 0;

// collecting the interesting data
for (int i=0; i<nFaces; i++)
{
faceCenterCoords[runFaces] = mesh.Cf().boundaryField()[patchID][i];
faceAreas[runFaces] = mesh.Sf().boundaryField()[patchID][i];
wallShearStress[runFaces] = tau.boundaryField()[patchID][i];
runFaces++;
}

// make a cute filename
fileName casePath = cwd();//casePath.name();
fileName caseName = casePath.name();
fileName myFile = "tau.dat";
Info << "Data is written to file " << myFile << endl;

// create a new file
OFstream *myStream = NULL;
myStream = new OFstream(myFile);

for (int i=0; i<nFaces; i++)
{
*myStream << i << " "
// coordinates on face centers:
<< mesh.Cf().boundaryField()[patchID][i].component(0) << " "
<< mesh.Cf().boundaryField()[patchID][i].component(1) << " "
<< mesh.Cf().boundaryField()[patchID][i].component(2) << " "

// wall shear stress as a vector:
<< tau.boundaryField()[patchID][i].component(0) << " "
<< tau.boundaryField()[patchID][i].component(1) << " "
<< tau.boundaryField()[patchID][i].component(2) << " "

// magnitude of wall shear stress:
<< mag(tau.boundaryField()[patchID][i]) << endl;
}

}
}
Daniele111 is offline   Reply With Quote

Old   November 6, 2010, 12:50
Default
  #44
Senior Member
 
Martin
Join Date: Oct 2009
Location: Aachen, Germany
Posts: 255
Rep Power: 22
MartinB will become famous soon enough
I merged your version and my parallel one, so can you try this:

Code:
#include "RASModel.H"
// write matlab file
{
    Info << "Writing wall shear stress for matlab!" << endl;

    word wallPatchName = "bottom";
    Info << "Searching for patch " << wallPatchName << endl;

    // Check, if the patch name exists:
    label patchID = mesh.boundaryMesh().findPatchID(wallPatchName);
    if (patchID < 0)
    {
        Info << "No patch found with name \"" << wallPatchName << "\"!"
             << endl;
    }
    else
    {
        // calculating tau

#       include "createFields2.H"
        mesh.readUpdate();
        volSymmTensorField Reff(RASModel->devReff());
        volVectorField tau
        (
            IOobject
            (
                "tau",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            mesh,
            dimensionedVector
            (
                "tau",
                Reff.dimensions(),
                vector::zero
            )
        );

        forAll(tau.boundaryField(), patchi)
        {
            tau.boundaryField()[patchi] =
            (
                -mesh.Sf().boundaryField()[patchi]
                /mesh.magSf().boundaryField()[patchi]
            ) & Reff.boundaryField()[patchi];
        }



        // Pointer to the patch we want to have shear stress for:
        const polyPatch& cPatch = mesh.boundaryMesh()[patchID];
        label nFaces = cPatch.size();

        pointField faceCenterCoords(nFaces, vector(0,0,0));
        pointField faceAreas(nFaces, vector(0,0,0));
        pointField wallShearStress(nFaces, vector(0,0,0));

        label runFaces = 0;

        // collecting the interesting data
        for (int i=0; i<nFaces; i++)
        {
            faceCenterCoords[runFaces] = mesh.Cf().boundaryField()[patchID][i];
            faceAreas[runFaces] = mesh.Sf().boundaryField()[patchID][i];
            wallShearStress[runFaces] = tau.boundaryField()[patchID][i];
            runFaces++;
        }

        // for parallel
        reduce(nFaces, sumOp<label>());
        Info << "Number of global faces: " << nFaces << endl;


        //  make a cute filename
        fileName casePath = cwd();//casePath.name();
        fileName caseName = casePath.name();
        fileName myFile = "tau.dat";
        Info << "Data is written to file " << myFile << endl;

        // create a new file
        OFstream *myStream = NULL;
        if (Pstream::master())
        {
            myStream = new OFstream(myFile);
        }

        // slaves send data to master, master writes data to file
        if (Pstream::parRun())
        {
            if (Pstream::myProcNo() != Pstream::masterNo())
            {
                OPstream toMaster(Pstream::blocking, Pstream::masterNo());
                toMaster << faceCenterCoords;
                toMaster << faceAreas;
                toMaster << wallShearStress;
            }
            else // master part
            {
                // first write own data
                for (int i=0; i<faceCenterCoords.size(); i++)
                {
                    *myStream << i << ";"
                        << faceCenterCoords[i].component(0) << "; "
                        << faceCenterCoords[i].component(1) << "; "
                        << faceCenterCoords[i].component(2) << "; "

                        << wallShearStress[i].component(0) << "; "
                        << wallShearStress[i].component(1) << "; "
                        << wallShearStress[i].component(2) << "; "

                        << mag(wallShearStress[i]) << endl;
                }

                label run = faceCenterCoords.size();

                // then receive slave data and write
                pointField bufferFaceCenterCoords;
                pointField bufferFaceAreas;
                pointField bufferWallShearStress;


                for (int slave=Pstream::firstSlave(); slave <= Pstream::lastSlave(); slave++)
                {
                    IPstream fromSlave(Pstream::blocking, slave);
                    fromSlave >> bufferFaceCenterCoords;
                    fromSlave >> bufferFaceAreas;
                    fromSlave >> bufferWallShearStress;

                    for (int i=0; i<bufferFaceCenterCoords.size(); i++)
                    {
                        *myStream << run << ";"
                            << bufferFaceCenterCoords[i].component(0) << "; "
                            << bufferFaceCenterCoords[i].component(1) << "; "
                            << bufferFaceCenterCoords[i].component(2) << "; "

                            << bufferWallShearStress[i].component(0) << "; "
                            << bufferWallShearStress[i].component(1) << "; "
                            << bufferWallShearStress[i].component(2) << "; "

                            << mag(bufferWallShearStress[i]) << endl;
                        run++;
                    }
                }
            }
        }
        else // single processor only
        {
            for (int i=0; i<nFaces; i++)
            {
                *myStream << i << "; "
                        // coordinates on face centers:
                        << mesh.Cf().boundaryField()[patchID][i].component(0) << "; "
                        << mesh.Cf().boundaryField()[patchID][i].component(1) << "; "
                        << mesh.Cf().boundaryField()[patchID][i].component(2) << "; "

                        // wall shear stress as a vector:
                        << tau.boundaryField()[patchID][i].component(0) << "; "
                        << tau.boundaryField()[patchID][i].component(1) << "; "
                        << tau.boundaryField()[patchID][i].component(2) << "; "

                        // magnitude of wall shear stress:
                        << mag(tau.boundaryField()[patchID][i]) << endl;
            }
        }

    }
}
Martin
MartinB 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
Convergence Problems SimpleFOAM Kutti OpenFOAM 16 June 14, 2010 09:12
Getting faster convergence in simpleFoam basneb OpenFOAM 8 February 9, 2010 05:20
Definition of convergence criterion in simpleFoam titio OpenFOAM Running, Solving & CFD 1 February 6, 2010 02:34
Convergence of CFX field in FSI analysis nasdak CFX 2 June 29, 2009 02:17
to improve convergence Mohamed FLUENT 0 May 14, 2003 06:43


All times are GMT -4. The time now is 18:59.