Skip to content

Commit

Permalink
Write pressure gradient calculated from function objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun Chen committed Jun 24, 2024
1 parent 4e6d7ee commit befacca
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 47 deletions.
4 changes: 2 additions & 2 deletions FF/FF.C
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool preciceAdapter::FF::FluidFluid::addWriters(std::string dataName, Interface*
{
interface->addCouplingDataWriter(
dataName,
new PressureGradient(mesh_, nameP_));
new PressureGradient(mesh_, namePG_));
DEBUG(adapterInfo("Added writer: Pressure Gradient."));
}
else if (dataName.find("Pressure") == 0)
Expand Down Expand Up @@ -216,7 +216,7 @@ bool preciceAdapter::FF::FluidFluid::addReaders(std::string dataName, Interface*
{
interface->addCouplingDataReader(
dataName,
new PressureGradient(mesh_, nameP_));
new PressureGradient(mesh_, namePG_));
DEBUG(adapterInfo("Added reader: Pressure Gradient."));
}
else if (dataName.find("Pressure") == 0)
Expand Down
3 changes: 3 additions & 0 deletions FF/FF.H
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ protected:
//- Name of the pressure field
std::string nameP_ = "p";

//- Name of the pressure gradient field
std::string namePG_ = "gradp";

//- Name of the temperature field
std::string nameT_ = "T";

Expand Down
85 changes: 43 additions & 42 deletions FF/PressureGradient.C
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
#include "PressureGradient.H"
#include "PressureGradient.H"

using namespace Foam;

preciceAdapter::FF::PressureGradient::PressureGradient(
const Foam::fvMesh& mesh,
const std::string nameP)
: p_(
const_cast<volScalarField*>(
&mesh.lookupObject<volScalarField>(nameP)))
const std::string namePG)
{
dataType_ = scalar;
if (mesh.foundObject<volVectorField>(namePG))
{
adapterInfo("Using existing velocity object " + namePG, "debug");
gradp_ = const_cast<volVectorField*>(
&mesh.lookupObject<volVectorField>(namePG));
}
else
{
adapterInfo("Creating a new velocity object " + namePG, "debug");
gradp_ = new volVectorField(
IOobject(
namePG,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE),
mesh);
}
dataType_ = vector;
//dataType_ = scalar;
}

std::size_t preciceAdapter::FF::PressureGradient::write(double* buffer, bool meshConnectivity, const unsigned int dim)
{
int bufferIndex = 0;

// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);
if (this->locationType_ == LocationType::volumeCenters)
{
for (const auto& cellSetName : cellSetNames_)
{
cellSet overlapRegion(gradp_->mesh(), cellSetName);
const labelList& cells = overlapRegion.toc();

// Get the pressure gradient boundary patch
const scalarField gradientPatch((p_->boundaryFieldRef()[patchID])
.snGrad());
for (const auto& currentCell : cells)
{
// x-dimension
buffer[bufferIndex++] = gradp_->internalField()[currentCell].x();

// For every cell of the patch
forAll(gradientPatch, i)
{
// Copy the pressure gradient into the buffer
buffer[bufferIndex++] =
-gradientPatch[i];
// y-dimension
buffer[bufferIndex++] = gradp_->internalField()[currentCell].y();

if (dim == 3)
{
// z-dimension
buffer[bufferIndex++] = gradp_->internalField()[currentCell].z();
}
}
}
}
}
return bufferIndex;
}

void preciceAdapter::FF::PressureGradient::read(double* buffer, const unsigned int dim)
{
int bufferIndex = 0;

// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);

// Get the pressure gradient boundary patch
scalarField& gradientPatch =
refCast<fixedGradientFvPatchScalarField>(
p_->boundaryFieldRef()[patchID])
.gradient();

// For every cell of the patch
forAll(gradientPatch, i)
{
// Set the pressure gradient as the buffer value
gradientPatch[i] =
buffer[bufferIndex++];
}
}
}

bool preciceAdapter::FF::PressureGradient::isLocationTypeSupported(const bool meshConnectivity) const
{
return (this->locationType_ == LocationType::faceCenters);
return (this->locationType_ == LocationType::volumeCenters);
}

std::string preciceAdapter::FF::PressureGradient::getDataName() const
Expand Down
6 changes: 3 additions & 3 deletions FF/PressureGradient.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class PressureGradient : public CouplingDataUser
{

private:
//- Pressure field
Foam::volScalarField* p_;
//- Presure gradient field
Foam::volVectorField* gradp_;

public:
//- Constructor
PressureGradient(
const Foam::fvMesh& mesh,
const std::string nameP);
const std::string namePG);

//- Write the pressure gradient values into the buffer
std::size_t write(double* buffer, bool meshConnectivity, const unsigned int dim);
Expand Down

0 comments on commit befacca

Please sign in to comment.