Skip to content

Commit

Permalink
Revert to use standard library definitions in API functions and examp…
Browse files Browse the repository at this point in the history
…les (#30)

* Remove old .gitlab folder

* Revert to using std::string and std::vector in adapter API functions

* Correct mistake in std:vectpr

* Formatting

* Revert to using std::string and std:vector instead of precice::

* Use std::string instead of precice::string_view in the dummy solver

* Update dumux-precice/couplingadapter.cc

Co-authored-by: mathiskelm <[email protected]>

* Update examples/dummysolver/main_dummysolver.cc

Co-authored-by: mathiskelm <[email protected]>

* Clean up dummy solver

* Using the correct data types

* Further simplifying variable definitions in examples

* Formatting

* Formatting

* Update dumux-precice/couplingadapter.cc

Co-authored-by: mathiskelm <[email protected]>

* Update dumux-precice/couplingadapter.hh

Co-authored-by: mathiskelm <[email protected]>

* Update examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc

Co-authored-by: mathiskelm <[email protected]>

* Update examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc

Co-authored-by: mathiskelm <[email protected]>

* Removing last traces of _View variables from example codes

* Use string literals in adapter API of the problem files (*.hh)

---------

Co-authored-by: mathiskelm <[email protected]>
  • Loading branch information
IshaanDesai and mathiskelm authored Dec 19, 2023
1 parent d60b1f4 commit b2e120f
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 230 deletions.
54 changes: 24 additions & 30 deletions dumux-precice/couplingadapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void CouplingAdapter::announceSolver(const std::string &name,
wasCreated_ = true;
}

void CouplingAdapter::announceQuantity(const precice::string_view &meshName,
const precice::string_view &dataName)
void CouplingAdapter::announceQuantity(const std::string &meshName,
const std::string &dataName)
{
assert(meshWasCreated_);
const std::string key = meshAndDataKey(meshName, dataName);
Expand All @@ -48,15 +48,14 @@ void CouplingAdapter::announceQuantity(const precice::string_view &meshName,
dataMap_.insert(std::make_pair(key, dataValues));
}

int CouplingAdapter::getMeshDimensions(
const precice::string_view &meshName) const
int CouplingAdapter::getMeshDimensions(const std::string &meshName) const
{
assert(wasCreated_);
return precice_->getMeshDimensions(meshName);
}

void CouplingAdapter::setMesh(const precice::string_view &meshName,
precice::span<const double> positions)
void CouplingAdapter::setMesh(const std::string &meshName,
const std::vector<double> &positions)
{
assert(wasCreated_);
vertexIDs_ =
Expand Down Expand Up @@ -118,10 +117,9 @@ size_t CouplingAdapter::getNumberOfVertices()
return vertexIDs_.size();
}

double CouplingAdapter::getScalarQuantityOnFace(
const precice::string_view &meshName,
const precice::string_view &dataName,
const int faceID)
double CouplingAdapter::getScalarQuantityOnFace(const std::string &meshName,
const std::string &dataName,
const int faceID)
{
assert(wasCreated_);
assert(hasIndexMapper_);
Expand All @@ -136,11 +134,10 @@ double CouplingAdapter::getScalarQuantityOnFace(
return dataVector[idx];
}

void CouplingAdapter::writeScalarQuantityOnFace(
const precice::string_view &meshName,
const precice::string_view &dataName,
const int faceID,
const double value)
void CouplingAdapter::writeScalarQuantityOnFace(const std::string &meshName,
const std::string &dataName,
const int faceID,
const double value)
{
assert(wasCreated_);
assert(hasIndexMapper_);
Expand All @@ -156,17 +153,17 @@ void CouplingAdapter::writeScalarQuantityOnFace(
}

std::vector<double> &CouplingAdapter::getQuantityVector(
const precice::string_view &meshName,
const precice::string_view &dataName)
const std::string &meshName,
const std::string &dataName)
{
std::string key = meshAndDataKey(meshName, dataName);
assert(dataMap_.find(key) != dataMap_.end());
return dataMap_[key];
}

void CouplingAdapter::writeQuantityVector(const precice::string_view &meshName,
const precice::string_view &dataName,
std::vector<double> &values)
void CouplingAdapter::writeQuantityVector(const std::string &meshName,
const std::string &dataName,
const std::vector<double> &values)
{
std::vector<double> &dataVector = getQuantityVector(meshName, dataName);
assert(dataVector.size() == values.size());
Expand All @@ -179,9 +176,8 @@ bool CouplingAdapter::isCoupledEntity(const int faceID) const
return indexMapper_.isDumuxIdMapped(faceID);
}

std::string CouplingAdapter::meshAndDataKey(
const precice::string_view &meshName,
const precice::string_view &dataName) const
std::string CouplingAdapter::meshAndDataKey(const std::string &meshName,
const std::string &dataName) const
{
assert(wasCreated_);
std::string combinedKey;
Expand All @@ -202,19 +198,17 @@ void CouplingAdapter::print(std::ostream &os)
os << indexMapper_;
}

void CouplingAdapter::readQuantityFromOtherSolver(
const precice::string_view &meshName,
const precice::string_view &dataName,
double relativeReadTime)
void CouplingAdapter::readQuantityFromOtherSolver(const std::string &meshName,
const std::string &dataName,
double relativeReadTime)
{
precice::span<double> dataValuesSpan(getQuantityVector(meshName, dataName));
precice_->readData(meshName, dataName, vertexIDsSpan_, relativeReadTime,
dataValuesSpan);
}

void CouplingAdapter::writeQuantityToOtherSolver(
const precice::string_view &meshName,
const precice::string_view &dataName)
void CouplingAdapter::writeQuantityToOtherSolver(const std::string &meshName,
const std::string &dataName)
{
precice::span<const double> dataValuesSpan(
getQuantityVector(meshName, dataName));
Expand Down
41 changes: 20 additions & 21 deletions dumux-precice/couplingadapter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ public:
* @param[in] meshName Name of the mesh.
* @param[in] dataName Name of the data.
*/
void announceQuantity(const precice::string_view &meshName,
const precice::string_view &dataName);
void announceQuantity(const std::string &meshName,
const std::string &dataName);
/*!
* @brief Get the number of spatial dimensions
*
* @param[in] meshName Name of the mesh
* @return int Number of space dimensions.
*/
int getMeshDimensions(const precice::string_view &meshName) const;
int getMeshDimensions(const std::string &meshName) const;
/*!
* @brief Get the maximum time step size from preCICE
*
Expand Down Expand Up @@ -147,8 +147,8 @@ public:
* Example 3D:\n
* [x_1, y_1, z_1, x_2, y_2, z_2,...x_numPoints, y_numPoints, z_numPoints]
*/
void setMesh(const precice::string_view &meshName,
precice::span<const double> positions);
void setMesh(const std::string &meshName,
const std::vector<double> &positions);
/*!
* @brief Initializes the coupling
*
Expand Down Expand Up @@ -201,17 +201,17 @@ public:
* @param[in] dataName Name of the data.
* @param[in] relativeReadTime The relative time tagged to the data to be read.
*/
void readQuantityFromOtherSolver(const precice::string_view &meshName,
const precice::string_view &dataName,
void readQuantityFromOtherSolver(const std::string &meshName,
const std::string &dataName,
double relativeReadTime);
/*!
* @brief Writes full block of data to preCICE.
*
* @param[in] meshName Name of the mesh.
* @param[in] dataName Name of the data.
*/
void writeQuantityToOtherSolver(const precice::string_view &meshName,
const precice::string_view &dataName);
void writeQuantityToOtherSolver(const std::string &meshName,
const std::string &dataName);
/*!
* @brief Gets value of a scalar quantity on a finite volume face.
*
Expand All @@ -220,8 +220,8 @@ public:
* @param[in] faceID Identifier of the face according to DuMuX' numbering.
* @return double Value of scalar quantity.
*/
double getScalarQuantityOnFace(const precice::string_view &meshName,
const precice::string_view &dataName,
double getScalarQuantityOnFace(const std::string &meshName,
const std::string &dataName,
const int faceID);
/*!
* @brief Writes value of scalar quantity on a given finite volume face to data map.
Expand All @@ -231,8 +231,8 @@ public:
* @param[in] faceID Identifier of the face according to DuMuX' numbering.
* @param[in] value Value of scalar quantity.
*/
void writeScalarQuantityOnFace(const precice::string_view &meshName,
const precice::string_view &dataName,
void writeScalarQuantityOnFace(const std::string &meshName,
const std::string &dataName,
const int faceID,
const double value);
/*!
Expand All @@ -242,19 +242,18 @@ public:
* @param[in] dataName Name of the data.
* @return The value vector of the quantity.
*/
std::vector<double> &getQuantityVector(
const precice::string_view &meshName,
const precice::string_view &dataName);
std::vector<double> &getQuantityVector(const std::string &meshName,
const std::string &dataName);
/*!
* @brief Writes the quantity value vector into the data map.
*
* @param[in] meshName Name of the mesh.
* @param[in] dataName Name of the data.
* @param[in] values Value of the scalar or vector quantity.
*/
void writeQuantityVector(const precice::string_view &meshName,
const precice::string_view &dataName,
std::vector<double> &values);
void writeQuantityVector(const std::string &meshName,
const std::string &dataName,
const std::vector<double> &values);
/*!
* @brief Checks whether face with given identifier is part of coupling interface.
*
Expand All @@ -270,8 +269,8 @@ public:
* @param[in] dataName Name of the quantity.
* @return size_t Numeric identifier of quantity.
*/
std::string meshAndDataKey(const precice::string_view &meshName,
const precice::string_view &dataName) const;
std::string meshAndDataKey(const std::string &meshName,
const std::string &dataName) const;
/*!
* @brief Prints status of coupling adapter to given output stream.
*
Expand Down
75 changes: 33 additions & 42 deletions examples/dummysolver/main_dummysolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ try {
getParamFromGroup<std::string>("preCICE", "ConfigFileName");
const std::string meshName =
getParamFromGroup<std::string>("preCICE", "MeshName");
const precice::string_view meshNameView(meshName);

auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance();
couplingParticipant.announceSolver(solverName, preciceConfigFilename,
Expand All @@ -52,16 +51,16 @@ try {
<< preciceConfigFilename << "\", participant name \""
<< solverName << "\", and mesh name \"" << meshName << "\".\n";

const int dimensions = couplingParticipant.getMeshDimensions(meshNameView);
const int dimensions = couplingParticipant.getMeshDimensions(meshName);
assert(dimensions == 3);
const precice::string_view scalarDataWriteName = std::string(
(solverName == "SolverOne") ? "scalarDataOne" : "scalarDataTwo");
const precice::string_view scalarDataReadName = std::string(
(solverName == "SolverOne") ? "scalarDataTwo" : "scalarDataOne");
const precice::string_view vectorDataWriteName = std::string(
(solverName == "SolverOne") ? "vectorDataOne" : "vectorDataTwo");
const precice::string_view vectorDataReadName = std::string(
(solverName == "SolverOne") ? "vectorDataTwo" : "vectorDataOne");
const std::string scalarDataWriteName =
(solverName == "SolverOne") ? "scalarDataOne" : "scalarDataTwo";
const std::string scalarDataReadName =
(solverName == "SolverOne") ? "scalarDataTwo" : "scalarDataOne";
const std::string vectorDataWriteName =
(solverName == "SolverOne") ? "vectorDataOne" : "vectorDataTwo";
const std::string vectorDataReadName =
(solverName == "SolverOne") ? "vectorDataTwo" : "vectorDataOne";

const int numberOfVertices = 3;

Expand All @@ -82,35 +81,29 @@ try {
}
}

precice::span<double> writeScalarDataSpan(writeScalarData);
precice::span<double> readScalarDataSpan(readScalarData);
precice::span<double> writeVectorDataSpan(writeVectorData);
precice::span<double> readVectorDataSpan(readVectorData);
precice::span<precice::VertexID> dumuxVertexIDsSpan(dumuxVertexIDs);

std::cout << "DUMMY (" << mpiHelper.rank()
<< "): Initialize preCICE and set mesh\n";
couplingParticipant.setMesh(meshNameView, vertices);
couplingParticipant.setMesh(meshName, vertices);

// Create index mapping between DuMuX's index numbering and preCICE's numbering
std::cout << "DUMMY (" << mpiHelper.rank() << "): Create index mapping\n";
couplingParticipant.createIndexMapping(dumuxVertexIDs);

couplingParticipant.announceQuantity(meshNameView, scalarDataWriteName);
couplingParticipant.announceQuantity(meshNameView, scalarDataReadName);
couplingParticipant.announceQuantity(meshNameView, vectorDataWriteName);
couplingParticipant.announceQuantity(meshNameView, vectorDataReadName);
couplingParticipant.announceQuantity(meshName, scalarDataWriteName);
couplingParticipant.announceQuantity(meshName, scalarDataReadName);
couplingParticipant.announceQuantity(meshName, vectorDataWriteName);
couplingParticipant.announceQuantity(meshName, vectorDataReadName);

if (couplingParticipant.requiresToWriteInitialData()) {
std::cout << "DUMMY (" << mpiHelper.rank()
<< "): Writing initial data\n";
couplingParticipant.writeQuantityVector(
meshNameView, scalarDataWriteName, writeScalarData);
couplingParticipant.writeQuantityToOtherSolver(meshNameView,
couplingParticipant.writeQuantityVector(meshName, scalarDataWriteName,
writeScalarData);
couplingParticipant.writeQuantityToOtherSolver(meshName,
scalarDataWriteName);
couplingParticipant.writeQuantityVector(
meshNameView, vectorDataWriteName, writeVectorData);
couplingParticipant.writeQuantityToOtherSolver(meshNameView,
couplingParticipant.writeQuantityVector(meshName, vectorDataWriteName,
writeVectorData);
couplingParticipant.writeQuantityToOtherSolver(meshName,
vectorDataWriteName);
}
std::cout << "DUMMY (" << mpiHelper.rank() << "): Exchange initial\n";
Expand All @@ -122,22 +115,20 @@ try {
std::cout << "DUMMY (" << mpiHelper.rank()
<< "): Reading initial data\n";
couplingParticipant.readQuantityFromOtherSolver(
meshNameView, scalarDataReadName, preciceDt);
meshName, scalarDataReadName, preciceDt);
couplingParticipant.readQuantityFromOtherSolver(
meshNameView, vectorDataReadName, preciceDt);
meshName, vectorDataReadName, preciceDt);

const std::vector<double> &readScalarQuantity =
couplingParticipant.getQuantityVector(meshNameView,
scalarDataReadName);
couplingParticipant.getQuantityVector(meshName, scalarDataReadName);

std::cout << "DUMMY (" << mpiHelper.rank() << "): Scalar data\n";
for (const double &value : readScalarQuantity)
std::cout << value << ",";
std::cout << "\n";

const std::vector<double> &readVectorQuantity =
couplingParticipant.getQuantityVector(meshNameView,
vectorDataReadName);
couplingParticipant.getQuantityVector(meshName, vectorDataReadName);

std::cout << "DUMMY (" << mpiHelper.rank() << "): Vector data\n";
for (const double &value : readVectorQuantity)
Expand Down Expand Up @@ -181,19 +172,19 @@ try {
//Read data
std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading data\n";
couplingParticipant.readQuantityFromOtherSolver(
meshNameView, scalarDataReadName, preciceDt);
meshName, scalarDataReadName, preciceDt);
couplingParticipant.readQuantityFromOtherSolver(
meshNameView, vectorDataReadName, preciceDt);
meshName, vectorDataReadName, preciceDt);

// Check data
if (iter > 0) {
int offset = (solverName == "SolverOne") ? 0 : 1;

const std::vector<double> &readScalarQuantity =
couplingParticipant.getQuantityVector(meshNameView,
couplingParticipant.getQuantityVector(meshName,
scalarDataReadName);
const std::vector<double> &readVectorQuantity =
couplingParticipant.getQuantityVector(meshNameView,
couplingParticipant.getQuantityVector(meshName,
vectorDataReadName);

for (int i = 0; i < numberOfVertices; i++) {
Expand Down Expand Up @@ -240,15 +231,15 @@ try {
for (int i = 0; i < numberOfVertices; i++) {
const double value = i + iter;
couplingParticipant.writeScalarQuantityOnFace(
meshNameView, scalarDataWriteName, dumuxVertexIDs[i], value);
meshName, scalarDataWriteName, dumuxVertexIDs[i], value);
}
couplingParticipant.writeQuantityToOtherSolver(meshNameView,
couplingParticipant.writeQuantityToOtherSolver(meshName,
scalarDataWriteName);

// Write vector data
couplingParticipant.writeQuantityVector(
meshNameView, vectorDataWriteName, writeVectorData);
couplingParticipant.writeQuantityToOtherSolver(meshNameView,
couplingParticipant.writeQuantityVector(meshName, vectorDataWriteName,
writeVectorData);
couplingParticipant.writeQuantityToOtherSolver(meshName,
vectorDataWriteName);
preciceDt = couplingParticipant.getMaxTimeStepSize();
couplingParticipant.advance(preciceDt);
Expand Down
Loading

0 comments on commit b2e120f

Please sign in to comment.