Skip to content

Commit

Permalink
Pass the correct number of entries to writeData (#305)
Browse files Browse the repository at this point in the history
* Change signature of write function to consider size_t

* Implement return type for all CouplingDataUsers

* Read relevant buffer part only

* Indentation with clang-format 11
  • Loading branch information
davidscn authored Oct 16, 2023
1 parent 61e7f69 commit c396868
Show file tree
Hide file tree
Showing 32 changed files with 59 additions and 42 deletions.
3 changes: 2 additions & 1 deletion CHT/HeatFlux.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ preciceAdapter::CHT::HeatFlux::HeatFlux(
dataType_ = scalar;
}

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

Expand Down Expand Up @@ -68,6 +68,7 @@ void preciceAdapter::CHT::HeatFlux::write(double* buffer, bool meshConnectivity,
}
}
}
return bufferIndex;
}

void preciceAdapter::CHT::HeatFlux::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion CHT/HeatFlux.H
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public:

//- Compute heat flux values from the temperature field
// and write them into the buffer
void write(double* buffer, bool meshConnectivity, const unsigned int dim) final;
std::size_t write(double* buffer, bool meshConnectivity, const unsigned int dim) final;

//- Read heat flux values from the buffer and assign them to
// the gradient of the temperature field
Expand Down
3 changes: 2 additions & 1 deletion CHT/HeatTransferCoefficient.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ preciceAdapter::CHT::HeatTransferCoefficient::HeatTransferCoefficient(
}


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

Expand Down Expand Up @@ -69,6 +69,7 @@ void preciceAdapter::CHT::HeatTransferCoefficient::write(double* buffer, bool me
}
}
}
return bufferIndex;
}


Expand Down
2 changes: 1 addition & 1 deletion CHT/HeatTransferCoefficient.H
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public:
const std::string nameT);

//- Write the heat transfer coefficient values into the buffer
void write(double* buffer, bool meshConnectivity, const unsigned int dim) final;
std::size_t write(double* buffer, bool meshConnectivity, const unsigned int dim) final;

//- Read the heat transfer coefficient values from the buffer
void read(double* buffer, const unsigned int dim) final;
Expand Down
3 changes: 2 additions & 1 deletion CHT/SinkTemperature.C
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ preciceAdapter::CHT::SinkTemperature::SinkTemperature(
dataType_ = scalar;
}

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

Expand Down Expand Up @@ -63,6 +63,7 @@ void preciceAdapter::CHT::SinkTemperature::write(double* buffer, bool meshConnec
// Clear the temporary internal field object
patchInternalFieldTmp.clear();
}
return bufferIndex;
}

void preciceAdapter::CHT::SinkTemperature::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion CHT/SinkTemperature.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public:
const std::string nameT);

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

//- Read the sink temperature values from the buffer
void read(double* buffer, const unsigned int dim);
Expand Down
3 changes: 2 additions & 1 deletion CHT/Temperature.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ preciceAdapter::CHT::Temperature::Temperature(
dataType_ = scalar;
}

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

Expand Down Expand Up @@ -79,6 +79,7 @@ void preciceAdapter::CHT::Temperature::write(double* buffer, bool meshConnectivi
}
}
}
return bufferIndex;
}

void preciceAdapter::CHT::Temperature::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion CHT/Temperature.H
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public:
const std::string nameT);

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

//- Read the temperature values from the buffer
void read(double* buffer, const unsigned int dim);
Expand Down
3 changes: 2 additions & 1 deletion CouplingDataUser.H
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public:
virtual void initialize();

//- Write the coupling data to the buffer
virtual void write(double* dataBuffer, bool meshConnectivity, const unsigned int dim) = 0;
// Returns the number of entries that were filles in the buffer (nComp * vertices)
virtual std::size_t write(double* dataBuffer, bool meshConnectivity, const unsigned int dim) = 0;

//- Read the coupling data from the buffer
virtual void read(double* dataBuffer, const unsigned int dim) = 0;
Expand Down
3 changes: 2 additions & 1 deletion FF/Pressure.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ preciceAdapter::FF::Pressure::Pressure(
dataType_ = scalar;
}

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

Expand Down Expand Up @@ -55,6 +55,7 @@ void preciceAdapter::FF::Pressure::write(double* buffer, bool meshConnectivity,
p_->boundaryFieldRef()[patchID][i];
}
}
return bufferIndex;
}

void preciceAdapter::FF::Pressure::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion FF/Pressure.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public:
const std::string nameP);

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

//- Read the pressure values from the buffer
void read(double* buffer, const unsigned int dim);
Expand Down
3 changes: 2 additions & 1 deletion FF/PressureGradient.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ preciceAdapter::FF::PressureGradient::PressureGradient(
dataType_ = scalar;
}

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

Expand All @@ -33,6 +33,7 @@ void preciceAdapter::FF::PressureGradient::write(double* buffer, bool meshConnec
-gradientPatch[i];
}
}
return bufferIndex;
}

void preciceAdapter::FF::PressureGradient::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion FF/PressureGradient.H
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public:
const std::string nameP);

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

//- Read the pressure gradient values from the buffer
void read(double* buffer, const unsigned int dim);
Expand Down
3 changes: 2 additions & 1 deletion FF/Temperature.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ preciceAdapter::FF::Temperature::Temperature(
dataType_ = scalar;
}

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

Expand All @@ -31,6 +31,7 @@ void preciceAdapter::FF::Temperature::write(double* buffer, bool meshConnectivit
T_->boundaryFieldRef()[patchID][i];
}
}
return bufferIndex;
}

void preciceAdapter::FF::Temperature::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion FF/Temperature.H
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public:
const std::string nameT);

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

//- Read the temperature values from the buffer
void read(double* buffer, const unsigned int dim);
Expand Down
3 changes: 2 additions & 1 deletion FF/TemperatureGradient.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ preciceAdapter::FF::TemperatureGradient::TemperatureGradient(
dataType_ = scalar;
}

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

Expand All @@ -34,6 +34,7 @@ void preciceAdapter::FF::TemperatureGradient::write(double* buffer, bool meshCon
gradientPatch[i];
}
}
return bufferIndex;
}

void preciceAdapter::FF::TemperatureGradient::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion FF/TemperatureGradient.H
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public:
const std::string nameT);

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

//- Read the Temperature gradient values from the buffer
void read(double* buffer, const unsigned int dim);
Expand Down
3 changes: 2 additions & 1 deletion FF/Velocity.C
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ preciceAdapter::FF::Velocity::Velocity(
dataType_ = vector;
}

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

Expand Down Expand Up @@ -118,6 +118,7 @@ void preciceAdapter::FF::Velocity::write(double* buffer, bool meshConnectivity,
}
}
}
return bufferIndex;
}

void preciceAdapter::FF::Velocity::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion FF/Velocity.H
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public:
bool fluxCorrection = false);

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

//- Read the velocity values from the buffer
void read(double* buffer, const unsigned int dim);
Expand Down
3 changes: 2 additions & 1 deletion FF/VelocityGradient.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ preciceAdapter::FF::VelocityGradient::VelocityGradient(
dataType_ = vector;
}

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

Expand Down Expand Up @@ -46,6 +46,7 @@ void preciceAdapter::FF::VelocityGradient::write(double* buffer, bool meshConnec
}
}
}
return bufferIndex;
}

void preciceAdapter::FF::VelocityGradient::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion FF/VelocityGradient.H
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public:
const std::string nameU);

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

//- Read the velocity gradient values from the buffer
void read(double* buffer, const unsigned int dim) final;
Expand Down
6 changes: 3 additions & 3 deletions FSI/Displacement.C
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void preciceAdapter::FSI::Displacement::initialize()
}


void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectivity, const unsigned int dim)
std::size_t preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectivity, const unsigned int dim)
{
/* TODO: Implement
* We need two nested for-loops for each patch,
Expand All @@ -46,9 +46,9 @@ void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectiv

// Copy the displacement field from OpenFOAM to the buffer

int bufferIndex = 0;
if (this->locationType_ == LocationType::faceCenters)
{
int bufferIndex = 0;
// For every boundary patch of the interface
for (const label patchID : patchIDs_)
{
Expand All @@ -70,7 +70,6 @@ void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectiv
"See https://github.com/precice/openfoam-adapter/issues/153.",
"warning"));

int bufferIndex = 0;
// For every boundary patch of the interface
for (const label patchID : patchIDs_)
{
Expand All @@ -87,6 +86,7 @@ void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectiv
}
}
}
return bufferIndex;
}


Expand Down
2 changes: 1 addition & 1 deletion FSI/Displacement.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public:
const std::string nameCellDisplacement);

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

//- Read the displacement values from the buffer
void read(double* buffer, const unsigned int dim) final;
Expand Down
3 changes: 2 additions & 1 deletion FSI/DisplacementDelta.C
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void preciceAdapter::FSI::DisplacementDelta::initialize()
}


void preciceAdapter::FSI::DisplacementDelta::write(double* buffer, bool meshConnectivity, const unsigned int dim)
std::size_t preciceAdapter::FSI::DisplacementDelta::write(double* buffer, bool meshConnectivity, const unsigned int dim)
{
/* TODO: Implement
* We need two nested for-loops for each patch,
Expand All @@ -44,6 +44,7 @@ void preciceAdapter::FSI::DisplacementDelta::write(double* buffer, bool meshConn
FatalErrorInFunction
<< "Writing displacementDeltas is not supported."
<< exit(FatalError);
return 0;
}

// return the displacement to use later in the velocity?
Expand Down
2 changes: 1 addition & 1 deletion FSI/DisplacementDelta.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public:
const std::string nameCellDisplacement);

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

//- Read the displacementDelta values from the buffer
void read(double* buffer, const unsigned int dim) final;
Expand Down
4 changes: 2 additions & 2 deletions FSI/Force.C
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ preciceAdapter::FSI::Force::Force(
}
}

void preciceAdapter::FSI::Force::write(double* buffer, bool meshConnectivity, const unsigned int dim)
std::size_t preciceAdapter::FSI::Force::write(double* buffer, bool meshConnectivity, const unsigned int dim)
{
this->writeToBuffer(buffer, *Force_, dim);
return this->writeToBuffer(buffer, *Force_, dim);
}

void preciceAdapter::FSI::Force::read(double* buffer, const unsigned int dim)
Expand Down
2 changes: 1 addition & 1 deletion FSI/Force.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public:
const std::string nameForce);

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

//- Read the forces values from the buffer
void read(double* buffer, const unsigned int dim) final;
Expand Down
7 changes: 4 additions & 3 deletions FSI/ForceBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ Foam::tmp<Foam::volScalarField> preciceAdapter::FSI::ForceBase::mu() const
}
}

void preciceAdapter::FSI::ForceBase::writeToBuffer(double* buffer,
volVectorField& forceField,
const unsigned int dim) const
std::size_t preciceAdapter::FSI::ForceBase::writeToBuffer(double* buffer,
volVectorField& forceField,
const unsigned int dim) const
{
// Compute forces. See the Forces function object.
// Stress tensor boundary field
Expand Down Expand Up @@ -188,6 +188,7 @@ void preciceAdapter::FSI::ForceBase::writeToBuffer(double* buffer,
forceField.boundaryField()[patchID][i][d];
}
}
return bufferIndex;
}

void preciceAdapter::FSI::ForceBase::readFromBuffer(double* buffer) const
Expand Down
6 changes: 3 additions & 3 deletions FSI/ForceBase.H
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public:
const Foam::fvMesh& mesh,
const std::string solverType);

void writeToBuffer(double* buffer,
Foam::volVectorField& forceField,
const unsigned int dim) const;
std::size_t writeToBuffer(double* buffer,
Foam::volVectorField& forceField,
const unsigned int dim) const;

void readFromBuffer(double* buffer) const;

Expand Down
Loading

0 comments on commit c396868

Please sign in to comment.