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

Writing function in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By vishwesh

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 13, 2017, 03:50
Default Writing function in OpenFOAM
  #1
Member
 
Vishwesh Ravi Shrimali
Join Date: Aug 2017
Posts: 43
Rep Power: 8
vishwesh is on a distinguished road
Hi!

I want to write two functions for retrieving properties like velocity, volume, etc. of the cells given their global Cell ID. I have written the following codes in interFoam.C above the main function:

Code:
void returnNeighborsFromCell(const DynamicList<label>& Ln, label cellID) {

    globalIndex globalNumbering (mesh_.nCells());

    label localProcID = globalNumbering.whichProcID(cellID);
    label localCellIDagain = globalNumbering.toLocal(cellID);
    label neighborCelli;
    if (localProcID == Pstream::myProcNo()){
        label globalCellID_neighbor (0);
        forAll(mesh_.cellCells()[localCellIDagain],neighborCelli) {
            globalCellID_neighbor = globalNumbering.toGlobal(mesh_.cellCells()[localCellIDagain][neighborCelli]);
            Ln.append(globalCellID_neighbor);
        }
    }

}

void returnValuesFromCell (const DynamicList<label>& properties, label cellID) {

    globalIndex globalNumbering (mesh_.nCells());

    scalar alphaVal = 0;
    scalar volVal = 0;
    vector velocityVal (0,0,0);
    vector cellCentres (0,0,0);

    int properties[8]={0};

    label localProcID = globalNumbering.whichProcID(cellID);
    label localCellIDagain = globalNumbering.toLocal(cellID);

    if (localProcID == Pstream::myProcNo()){
        alphaVal = alpha1[localCellIDagain];
        velocityVal = U[localCellIDagain];
        volVal = mesh_.V()[localCellIDagain];
        cellCentres = mesh_.C()[localCellIDagain];
    }

        properties[0] = alphaVal;
        properties[1] = volVal;
        properties[2] = velocityVal[0];
        properties[3] = velocityVal[1];
        properties[4] = velocityVal[2];
        properties[5] = cellCentres[0];
        properties[6] = cellCentres[1];
        properties[7] = cellCentres[2];

}
Also, I am calling these functions from processor 0. When I try to compile my code, I get the following errors:

Code:
interFoam.C: In function ‘void returnNeighborsFromCell(const Foam::DynamicList<long int, 0u, 2u, 1u>&, Foam::label)’:
interFoam.C:64: error: ‘mesh_’ was not declared in this scope
interFoam.C:73: error: passing ‘const Foam::DynamicList<long int, 0u, 2u, 1u>’ as ‘this’ argument of ‘Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>& Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append(const T&) [with T = long int, unsigned int SizeInc = 0u, unsigned int SizeMult = 2u, unsigned int SizeDiv = 1u]’ discards qualifiers
interFoam.C:68: warning: unused variable ‘neighborCelli’
interFoam.C: In function ‘void returnValuesFromCell(const Foam::DynamicList<long int, 0u, 2u, 1u>&, Foam::label)’:
interFoam.C:81: error: ‘mesh_’ was not declared in this scope
interFoam.C:88: error: declaration of ‘int properties [8]’ shadows a parameter
interFoam.C:94: error: ‘alpha1’ was not declared in this scope
interFoam.C:95: error: ‘U’ was not declared in this scope
Can someone help me out with these errors? Also, is it actually okay to call a function like this from master processor? If not, is there any other alternative?

Thanks in advance
2vdba2 likes this.

Last edited by vishwesh; November 13, 2017 at 23:13.
vishwesh 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
Frequently Asked Questions about Installing OpenFOAM wyldckat OpenFOAM Installation 3 November 14, 2023 11:58
OpenFOAM 5.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 11 June 5, 2018 23:48
OpenFOAM 4.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 2 October 6, 2017 05:40
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 05:42
latest OpenFOAM-1.6.x from git failed to compile phsieh2005 OpenFOAM Bugs 25 February 9, 2010 04:37


All times are GMT -4. The time now is 08:27.