November 9, 2023, 04:29
|
Inverse Distance Matrix Evaluation at the Boundary in an OpenFOAM Function
|
#1
|
|
New Member
Khoder Alshaar
Join Date: May 2021
Posts: 9
Rep Power: 6
|
Hello,
I'm following an open-source toolkit in OpenFoam explicitSolidDynamics, which has the following function in gradientSchemes.C :
This function takes a reference to a GeometricField, which represents the Inverse distance matrix.
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 rocessors).
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();
}
U.primitiveFieldRef() = inv(U.internalField());
}
My question is related to the last line of the function
Code:
U.primitiveFieldRef() = inv(U.internalField());
Could you please explain to me what it does besides the fact that it calculates the inverse of a tensor? what is the function of primitiveFieldRef() and .internalField() ?
Also, what happens to the faces at the boundary? For example, a boundary face does not have a neighboring cell, only an owner cell. So how these are evaluated:
Code:
const vector& dOwn = X_[neiCellID] - X_[ownCellID];
const vector& dNei = X_[ownCellID] - X_[neiCellID];
Thank you!
|
|
|