Skip to content

Commit

Permalink
Add Coupling of face flux phi
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamriel committed Nov 20, 2023
1 parent 8509a3f commit 7627599
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
14 changes: 14 additions & 0 deletions FF/FF.C
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ bool preciceAdapter::FF::FluidFluid::addWriters(std::string dataName, Interface*
new Alpha(mesh_, nameAlpha_));
DEBUG(adapterInfo("Added writer: Alpha."));
}
else if (dataName.find("Phi") == 0)
{
interface->addCouplingDataWriter(
dataName,
new Phi(mesh_, namePhi_));
DEBUG(adapterInfo("Added writer: Phi."));
}
else
{
found = false;
Expand Down Expand Up @@ -247,6 +254,13 @@ bool preciceAdapter::FF::FluidFluid::addReaders(std::string dataName, Interface*
new Alpha(mesh_, nameAlpha_));
DEBUG(adapterInfo("Added reader: Alpha."));
}
else if (dataName.find("Phi") == 0)
{
interface->addCouplingDataReader(
dataName,
new Phi(mesh_, namePhi_));
DEBUG(adapterInfo("Added reader: Phi."));
}
else
{
found = false;
Expand Down
1 change: 1 addition & 0 deletions FF/FF.H
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "FF/VelocityGradient.H"
#include "FF/TemperatureGradient.H"
#include "FF/AlphaGradient.H"
#include "FF/Phi.H"

#include "fvCFD.H"

Expand Down
1 change: 1 addition & 0 deletions FF/ModuleFF.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
#include "TemperatureGradient.C"
#include "Alpha.C"
#include "AlphaGradient.C"
#include "Phi.C"
#include "BoundaryConditions/coupledPressure/coupledPressureFvPatchField.C"
#include "BoundaryConditions/coupledVelocity/coupledVelocityFvPatchField.C"
59 changes: 59 additions & 0 deletions FF/Phi.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "Phi.H"

using namespace Foam;

preciceAdapter::FF::Phi::Phi(
const Foam::fvMesh& mesh,
const std::string namePhi)
: phi_(
const_cast<surfaceScalarField*>(
&mesh.lookupObject<surfaceScalarField>(namePhi)))
{
dataType_ = scalar;
}

std::size_t preciceAdapter::FF::Phi::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);

// For every cell of the patch
forAll(phi_->boundaryFieldRef()[patchID], i)
{
// Copy the Phi into the buffer
buffer[bufferIndex++] =
phi_->boundaryFieldRef()[patchID][i];
}
}
return bufferIndex;
}

void preciceAdapter::FF::Phi::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);

forAll(phi_->boundaryFieldRef()[patchID], i)
{
phi_->boundaryFieldRef()[patchID][i] = -buffer[bufferIndex++];
}
}
}

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

std::string preciceAdapter::FF::Phi::getDataName() const
{
return "Phi";
}
42 changes: 42 additions & 0 deletions FF/Phi.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef FF_PHI_H
#define FF_PHI_H

#include "CouplingDataUser.H"

#include "fvCFD.H"

namespace preciceAdapter
{
namespace FF
{

//- Class that writes and reads the flux phi
class Phi : public CouplingDataUser
{

private:
//- Phi field
Foam::surfaceScalarField* phi_;

public:
//- Constructor
Phi(
const Foam::fvMesh& mesh,
const std::string namePhi);

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

//- Read the Phi values from the buffer
void read(double* buffer, const unsigned int dim);

bool isLocationTypeSupported(const bool meshConnectivity) const override;

//- Get the name of the current data field
std::string getDataName() const override;
};

}
}

#endif

0 comments on commit 7627599

Please sign in to comment.