diff --git a/FF/FF.C b/FF/FF.C index 2c2144ee..63dcc9c8 100644 --- a/FF/FF.C +++ b/FF/FF.C @@ -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) @@ -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) diff --git a/FF/FF.H b/FF/FF.H index 77629442..e670c42d 100644 --- a/FF/FF.H +++ b/FF/FF.H @@ -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"; diff --git a/FF/PressureGradient.C b/FF/PressureGradient.C index ca125179..71920276 100644 --- a/FF/PressureGradient.C +++ b/FF/PressureGradient.C @@ -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( - &mesh.lookupObject(nameP))) + const std::string namePG) { - dataType_ = scalar; + if (mesh.foundObject(namePG)) + { + adapterInfo("Using existing velocity object " + namePG, "debug"); + gradp_ = const_cast( + &mesh.lookupObject(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( - 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 diff --git a/FF/PressureGradient.H b/FF/PressureGradient.H index 47db220e..a0ca82ea 100644 --- a/FF/PressureGradient.H +++ b/FF/PressureGradient.H @@ -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);