-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add phase variable and flux coupling for interFOAM in the FF module (#…
…308)
- Loading branch information
1 parent
a0e5263
commit 1ed787a
Showing
14 changed files
with
448 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include "Alpha.H" | ||
|
||
using namespace Foam; | ||
|
||
preciceAdapter::FF::Alpha::Alpha( | ||
const Foam::fvMesh& mesh, | ||
const std::string nameAlpha) | ||
: Alpha_( | ||
const_cast<volScalarField*>( | ||
&mesh.lookupObject<volScalarField>(nameAlpha))) | ||
{ | ||
dataType_ = scalar; | ||
} | ||
|
||
std::size_t preciceAdapter::FF::Alpha::write(double* buffer, bool meshConnectivity, const unsigned int dim) | ||
{ | ||
int bufferIndex = 0; | ||
|
||
if (this->locationType_ == LocationType::volumeCenters) | ||
{ | ||
if (cellSetNames_.empty()) | ||
{ | ||
for (const auto& cell : Alpha_->internalField()) | ||
{ | ||
buffer[bufferIndex++] = cell; | ||
} | ||
} | ||
else | ||
{ | ||
for (const auto& cellSetName : cellSetNames_) | ||
{ | ||
cellSet overlapRegion(Alpha_->mesh(), cellSetName); | ||
const labelList& cells = overlapRegion.toc(); | ||
|
||
for (const auto& currentCell : cells) | ||
{ | ||
// Copy the alpha valus into the buffer | ||
buffer[bufferIndex++] = Alpha_->internalField()[currentCell]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// 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(Alpha_->boundaryFieldRef()[patchID], i) | ||
{ | ||
// Copy the Alpha into the buffer | ||
buffer[bufferIndex++] = | ||
Alpha_->boundaryFieldRef()[patchID][i]; | ||
} | ||
} | ||
return bufferIndex; | ||
} | ||
|
||
void preciceAdapter::FF::Alpha::read(double* buffer, const unsigned int dim) | ||
{ | ||
int bufferIndex = 0; | ||
|
||
if (this->locationType_ == LocationType::volumeCenters) | ||
{ | ||
if (cellSetNames_.empty()) | ||
{ | ||
for (auto& cell : Alpha_->ref()) | ||
{ | ||
cell = buffer[bufferIndex++]; | ||
} | ||
} | ||
else | ||
{ | ||
for (const auto& cellSetName : cellSetNames_) | ||
{ | ||
cellSet overlapRegion(Alpha_->mesh(), cellSetName); | ||
const labelList& cells = overlapRegion.toc(); | ||
|
||
for (const auto& currentCell : cells) | ||
{ | ||
// Copy the pressure into the buffer | ||
Alpha_->ref()[currentCell] = buffer[bufferIndex++]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// 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(Alpha_->boundaryFieldRef()[patchID], i) | ||
{ | ||
Alpha_->boundaryFieldRef()[patchID][i] = buffer[bufferIndex++]; | ||
} | ||
} | ||
} | ||
|
||
bool preciceAdapter::FF::Alpha::isLocationTypeSupported(const bool meshConnectivity) const | ||
{ | ||
if (meshConnectivity) | ||
{ | ||
return (this->locationType_ == LocationType::faceCenters); | ||
} | ||
else | ||
{ | ||
return (this->locationType_ == LocationType::faceCenters || this->locationType_ == LocationType::volumeCenters); | ||
} | ||
} | ||
|
||
std::string preciceAdapter::FF::Alpha::getDataName() const | ||
{ | ||
return "Alpha"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef FF_ALPHA_H | ||
#define FF_ALPHA_H | ||
|
||
#include "CouplingDataUser.H" | ||
|
||
#include "fvCFD.H" | ||
#include "cellSet.H" | ||
|
||
namespace preciceAdapter | ||
{ | ||
namespace FF | ||
{ | ||
|
||
//- Class that writes and reads Alpha | ||
class Alpha : public CouplingDataUser | ||
{ | ||
|
||
private: | ||
//- Alpha field | ||
Foam::volScalarField* Alpha_; | ||
|
||
public: | ||
//- Constructor | ||
Alpha( | ||
const Foam::fvMesh& mesh, | ||
const std::string nameAlpha); | ||
|
||
//- Write the Alpha values into the buffer | ||
std::size_t write(double* buffer, bool meshConnectivity, const unsigned int dim); | ||
|
||
//- Read the Alpha 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "AlphaGradient.H" | ||
#include "mixedFvPatchFields.H" | ||
|
||
using namespace Foam; | ||
|
||
preciceAdapter::FF::AlphaGradient::AlphaGradient( | ||
const Foam::fvMesh& mesh, | ||
const std::string nameAlpha) | ||
: Alpha_( | ||
const_cast<volScalarField*>( | ||
&mesh.lookupObject<volScalarField>(nameAlpha))) | ||
{ | ||
dataType_ = scalar; | ||
} | ||
|
||
std::size_t preciceAdapter::FF::AlphaGradient::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); | ||
|
||
// Get the Alpha gradient boundary patch | ||
const scalarField gradientPatch((Alpha_->boundaryFieldRef()[patchID]) | ||
.snGrad()); | ||
|
||
// For every cell of the patch | ||
forAll(gradientPatch, i) | ||
{ | ||
// Copy the Alpha gradient into the buffer | ||
buffer[bufferIndex++] = | ||
-gradientPatch[i]; | ||
} | ||
} | ||
return bufferIndex; | ||
} | ||
|
||
void preciceAdapter::FF::AlphaGradient::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 Alpha gradient boundary patch | ||
scalarField& gradientPatch = | ||
refCast<fixedGradientFvPatchScalarField>( | ||
Alpha_->boundaryFieldRef()[patchID]) | ||
.gradient(); | ||
|
||
// For every cell of the patch | ||
forAll(gradientPatch, i) | ||
{ | ||
// Set the Alpha gradient as the buffer value | ||
gradientPatch[i] = | ||
buffer[bufferIndex++]; | ||
} | ||
} | ||
} | ||
|
||
bool preciceAdapter::FF::AlphaGradient::isLocationTypeSupported(const bool meshConnectivity) const | ||
{ | ||
return (this->locationType_ == LocationType::faceCenters); | ||
} | ||
|
||
std::string preciceAdapter::FF::AlphaGradient::getDataName() const | ||
{ | ||
return "AlphaGradient"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef FF_ALPHA_GRADIENT_H | ||
#define FF_ALPHA_GRADIENT_H | ||
|
||
#include "CouplingDataUser.H" | ||
|
||
#include "fvCFD.H" | ||
|
||
namespace preciceAdapter | ||
{ | ||
namespace FF | ||
{ | ||
|
||
//- Class that writes and reads Alpha gradient | ||
class AlphaGradient : public CouplingDataUser | ||
{ | ||
|
||
private: | ||
//- Alpha field | ||
Foam::volScalarField* Alpha_; | ||
|
||
public: | ||
//- Constructor | ||
AlphaGradient( | ||
const Foam::fvMesh& mesh, | ||
const std::string nameAlpha); | ||
|
||
//- Write the Alpha gradient values into the buffer | ||
std::size_t write(double* buffer, bool meshConnectivity, const unsigned int dim); | ||
|
||
//- Read the Alpha gradient 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,4 +175,4 @@ namespace Foam | |
makePatchTypeField( | ||
fvPatchVectorField, | ||
coupledVelocityFvPatchField); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.