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

Inverse Distance Matrix Evaluation at the Boundary in an OpenFOAM Function

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 9, 2023, 05:00
Default Inverse Distance Matrix Evaluation at the Boundary in an OpenFOAM Function
  #1
New Member
 
Khoder Alshaar
Join Date: May 2021
Posts: 8
Rep Power: 5
khoder Alshaar is on a distinguished road
Hello,
I'm using an opensource solver with OpenFOAM explicitSolidDynamics, which has the following function in gradientSchemes.C.

The function calculates the Inverse Distance Matrix for each domain's owner and neighbor cell of each face:

Code:
void gradientSchemes::distanceMatrix
(
    GeometricField<tensor, fvPatchField, volMesh>& U 
)
{
      //Loop through internal faces (finite volume faces within the computational domain):
     forAll(own_, faceID)
    {
	 // Get the cell IDs of the owner and neighbor cells for the current face
        const label& ownCellID = own_[faceID];
        const label& neiCellID = nei_[faceID];

        // Calculate the vector from the owner cell to the neighbor cell
        const vector& dOwn = X_[neiCellID] - X_[ownCellID];
        const vector& dNei  = X_[ownCellID] - X_[neiCellID];
	   
         // Update the field U for the owner and neighbor cells with the outer product of the vectors
        U[ownCellID] += dOwn*dOwn;
        U[neiCellID] += dNei*dNei;
        
    }

    //Check if the simulation is running in parallel (i.e., multiple processors).
    if (Pstream::parRun())
    {
        forAll(mesh_.boundary(), patchID)
        {
            if (mesh_.boundary()[patchID].coupled())
            {
                vectorField X_nei =
                  X_.boundaryField()[patchID].patchNeighbourField().ref();

                forAll(mesh_.boundary()[patchID], facei)
                {
                    const label& bCellID =
                        mesh_.boundaryMesh()[patchID].faceCells()[facei];

                    const vector& d = X_nei[facei] - X_[bCellID];
                    U[bCellID] += d*d;
                }
            }
        }

        U.correctBoundaryConditions();
    }
    
    //Compute the inverse of the internal field of `U` and assign it to the primitive field:
    U.primitiveFieldRef() = inv(U.internalField());
}
1- My first question is primarily related to the last line:
Code:
    U.primitiveFieldRef() = inv(U.internalField());
Could you please explain the function of primitiveFieldRef() and internalField() in this context?

2- I understand that a boundary face has only an owner cell and does not have a neighbor cell. In this case, how are these getting evaluated:
Code:
        const vector& dOwn = X_[neiCellID] - X_[ownCellID];
        const vector& dNei  = X_[ownCellID] - X_[neiCellID];
I would like to understand how openFoam deals with calculations related to boundary cells, for example, calculating the gradient.
khoder Alshaar is offline   Reply With Quote

Reply

Tags
boundary cells, boundary faces, gradient, invers


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
Table bounds warnings at: END OF TIME STEP CFXer CFX 4 July 17, 2020 00:44
OpenFOAM 4.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 2 October 6, 2017 06:40
Error - Solar absorber - Solar Thermal Radiation MichaelK CFX 12 September 1, 2016 06:15
Basic Nozzle-Expander Design karmavatar CFX 20 March 20, 2016 09:44
Error finding variable "THERMX" sunilpatil CFX 8 April 26, 2013 08:00


All times are GMT -4. The time now is 12:53.