Skip to content

Commit

Permalink
Latest changes from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
davidscn committed Jul 3, 2023
1 parent 2904355 commit fca99c6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 70 deletions.
17 changes: 10 additions & 7 deletions Adapter.C
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void preciceAdapter::Adapter::configure()
DEBUG(adapterInfo("Creating the preCICE solver interface..."));
DEBUG(adapterInfo(" Number of processes: " + std::to_string(Pstream::nProcs())));
DEBUG(adapterInfo(" MPI rank: " + std::to_string(Pstream::myProcNo())));
precice_ = new precice::SolverInterface(participantName_, preciceConfigFilename_, Pstream::myProcNo(), Pstream::nProcs());
precice_ = new precice::Participant(participantName_, preciceConfigFilename_, Pstream::myProcNo(), Pstream::nProcs());
DEBUG(adapterInfo(" preCICE solver interface was created."));

ACCUMULATE_TIMER(timeInPreciceConstruct_);
Expand Down Expand Up @@ -346,7 +346,7 @@ void preciceAdapter::Adapter::configure()
initialize();

// Read the received coupling data
readCouplingData();
readCouplingData(runTime_.deltaT().value());

// If checkpointing is required, specify the checkpointed fields
// and write the first checkpoint
Expand Down Expand Up @@ -459,7 +459,8 @@ void preciceAdapter::Adapter::execute()
ACCUMULATE_TIMER(timeInWriteResults_);

// Read the received coupling data from the buffer
readCouplingData();
// Fits to an implicit Euler
readCouplingData(runTime_.deltaT().value());

// If the coupling is not going to continue, tear down everything
// and stop the simulation.
Expand Down Expand Up @@ -495,14 +496,14 @@ void preciceAdapter::Adapter::adjustTimeStep()
return;
}

void preciceAdapter::Adapter::readCouplingData()
void preciceAdapter::Adapter::readCouplingData(double relativeReadTime)
{
SETUP_TIMER();
DEBUG(adapterInfo("Reading coupling data..."));

for (uint i = 0; i < interfaces_.size(); i++)
{
interfaces_.at(i)->readCouplingData();
interfaces_.at(i)->readCouplingData(relativeReadTime);
}

ACCUMULATE_TIMER(timeInRead_);
Expand Down Expand Up @@ -534,7 +535,8 @@ void preciceAdapter::Adapter::initialize()
writeCouplingData();

DEBUG(adapterInfo("Initializing preCICE data..."));
timestepPrecice_ = precice_->initialize();
precice_->initialize();
timestepPrecice_ = precice_->getMaxTimeStepSize();
preciceInitialized_ = true;
ACCUMULATE_TIMER(timeInInitialize_);

Expand Down Expand Up @@ -572,7 +574,8 @@ void preciceAdapter::Adapter::advance()
DEBUG(adapterInfo("Advancing preCICE..."));

SETUP_TIMER();
timestepPrecice_ = precice_->advance(timestepSolver_);
precice_->advance(timestepSolver_);
timestepPrecice_ = precice_->getMaxTimeStepSize();
ACCUMULATE_TIMER(timeInAdvance_);

return;
Expand Down
6 changes: 3 additions & 3 deletions Adapter.H
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "fvMesh.H"

// preCICE Solver Interface
#include "precice/SolverInterface.hpp"
#include <precice/precice.hpp>

namespace preciceAdapter
{
Expand Down Expand Up @@ -105,7 +105,7 @@ private:
std::vector<Interface*> interfaces_;

//- preCICE solver interface
precice::SolverInterface* precice_ = NULL;
precice::Participant* precice_ = NULL;

//- preCICE solver interface initialized
bool preciceInitialized_ = false;
Expand Down Expand Up @@ -264,7 +264,7 @@ private:
void advance();

//- Read the coupling data at each interface
void readCouplingData();
void readCouplingData(double relativeReadTime);

//- Write the coupling data at each interface
void writeCouplingData();
Expand Down
77 changes: 23 additions & 54 deletions Interface.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using namespace Foam;

preciceAdapter::Interface::Interface(
precice::SolverInterface& precice,
precice::Participant& precice,
const fvMesh& mesh,
std::string meshName,
std::string locationsType,
Expand All @@ -21,7 +21,7 @@ preciceAdapter::Interface::Interface(
meshConnectivity_(meshConnectivity),
restartFromDeformed_(restartFromDeformed)
{
dim_ = precice_.getDimensions();
dim_ = precice_.getMeshDimensions(meshName);

if (dim_ == 2 && meshConnectivity_ == true)
{
Expand Down Expand Up @@ -97,11 +97,11 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str

// Array of the mesh vertices.
// One mesh is used for all the patches and each vertex has 3D coordinates.
double vertices[dim_ * numDataLocations_];
std::vector<double> vertices(dim_ * numDataLocations_);

// Array of the indices of the mesh vertices.
// Each vertex has one index, but three coordinates.
vertexIDs_ = new int[numDataLocations_];
vertexIDs_.resize(numDataLocations_);

// Initialize the index of the vertices array
int verticesIndex = 0;
Expand Down Expand Up @@ -178,7 +178,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str
}

// Pass the mesh vertices information to preCICE
precice_.setMeshVertices(meshName_, numDataLocations_, vertices, vertexIDs_);
precice_.setMeshVertices(meshName_, vertices, vertexIDs_);
}
else if (locationType_ == LocationType::faceNodes)
{
Expand All @@ -198,11 +198,11 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str

// Array of the mesh vertices.
// One mesh is used for all the patches and each vertex has 3D coordinates.
double vertices[dim_ * numDataLocations_];
std::vector<double> vertices(dim_ * numDataLocations_);

// Array of the indices of the mesh vertices.
// Each vertex has one index, but three coordinates.
vertexIDs_ = new int[numDataLocations_];
vertexIDs_.resize(numDataLocations_);

// Initialize the index of the vertices array
int verticesIndex = 0;
Expand Down Expand Up @@ -239,7 +239,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str
}

// Pass the mesh vertices information to preCICE
precice_.setMeshVertices(meshName_, numDataLocations_, vertices, vertexIDs_);
precice_.setMeshVertices(meshName_, vertices, vertexIDs_);

// meshConnectivity for prototype neglected
// Only set the triangles, if necessary
Expand Down Expand Up @@ -406,10 +406,10 @@ void preciceAdapter::Interface::createBuffer()
// scalar and vector coupling data users in an interface. With the current
// preCICE implementation, it should work as, when writing scalars,
// it should only use the first 1/3 elements of the buffer.
dataBuffer_ = new double[dataBufferSize]();
dataBuffer_.resize(dataBufferSize);
}

void preciceAdapter::Interface::readCouplingData()
void preciceAdapter::Interface::readCouplingData(double relativeReadTime)
{
// Make every coupling data reader read
for (uint i = 0; i < couplingDataReaders_.size(); i++)
Expand All @@ -420,27 +420,15 @@ void preciceAdapter::Interface::readCouplingData()

// Make preCICE read vector or scalar data
// and fill the adapter's buffer
if (couplingDataReader->hasVectorData())
{
precice_.readBlockVectorData(
meshName_,
couplingDataReader->dataName(),
numDataLocations_,
vertexIDs_,
dataBuffer_);
}
else
{
precice_.readBlockScalarData(
meshName_,
couplingDataReader->dataName(),
numDataLocations_,
vertexIDs_,
dataBuffer_);
}
precice_.readData(
meshName_,
couplingDataReader->dataName(),
vertexIDs_,
relativeReadTime,
dataBuffer_);

// Read the received data from the buffer
couplingDataReader->read(dataBuffer_, dim_);
couplingDataReader->read(dataBuffer_.data(), dim_);
}
}

Expand All @@ -458,27 +446,14 @@ void preciceAdapter::Interface::writeCouplingData()
couplingDataWriter = couplingDataWriters_.at(i);

// Write the data into the adapter's buffer
couplingDataWriter->write(dataBuffer_, meshConnectivity_, dim_);
couplingDataWriter->write(dataBuffer_.data(), meshConnectivity_, dim_);

// Make preCICE write vector or scalar data
if (couplingDataWriter->hasVectorData())
{
precice_.writeBlockVectorData(
meshName_,
couplingDataWriter->dataName(),
numDataLocations_,
vertexIDs_,
dataBuffer_);
}
else
{
precice_.writeBlockScalarData(
meshName_,
couplingDataWriter->dataName(),
numDataLocations_,
vertexIDs_,
dataBuffer_);
}
precice_.writeData(
meshName_,
couplingDataWriter->dataName(),
vertexIDs_,
dataBuffer_);
}
// }
}
Expand All @@ -498,10 +473,4 @@ preciceAdapter::Interface::~Interface()
delete couplingDataWriters_.at(i);
}
couplingDataWriters_.clear();

// Delete the vertexIDs_
delete[] vertexIDs_;

// Delete the shared data buffer
delete[] dataBuffer_;
}
12 changes: 6 additions & 6 deletions Interface.H
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <vector>
#include "fvCFD.H"
#include "CouplingDataUser.H"
#include "precice/SolverInterface.hpp"
#include <precice/precice.hpp>

#include "pointPatchField.H"

Expand All @@ -16,7 +16,7 @@ class Interface
{
protected:
//- preCICE solver interface
precice::SolverInterface& precice_;
precice::Participant& precice_;

//- Mesh name used in the preCICE configuration
std::string meshName_;
Expand All @@ -37,10 +37,10 @@ protected:
int numDataLocations_ = 0;

//- Vertex IDs assigned by preCICE
int* vertexIDs_;
std::vector<int> vertexIDs_;

//- Buffer for the coupling data
double* dataBuffer_;
std::vector<double> dataBuffer_;

//- Vector of CouplingDataReaders
std::vector<CouplingDataUser*> couplingDataReaders_;
Expand All @@ -66,7 +66,7 @@ protected:
public:
//- Constructor
Interface(
precice::SolverInterface& precice,
precice::Participant& precice,
const Foam::fvMesh& mesh,
std::string meshName,
std::string locationsType,
Expand Down Expand Up @@ -94,7 +94,7 @@ public:

//- Call read() on each registered couplingDataReader to read the coupling
// data from the buffer and apply the boundary conditions
void readCouplingData();
void readCouplingData(double relativeReadTime);

//- Call write() on each registered couplingDataWriter to extract the boundary
// data and write them into the buffer
Expand Down

0 comments on commit fca99c6

Please sign in to comment.