Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert to use standard library definitions in API functions and examples #30

Merged
merged 20 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
282e945
Remove old .gitlab folder
IshaanDesai Dec 18, 2023
b4dd453
Revert to using std::string and std::vector in adapter API functions
IshaanDesai Dec 18, 2023
82c09a4
Correct mistake in std:vectpr
IshaanDesai Dec 18, 2023
f4573df
Formatting
IshaanDesai Dec 18, 2023
43c6d01
Revert to using std::string and std:vector instead of precice::
IshaanDesai Dec 19, 2023
98727f5
Use std::string instead of precice::string_view in the dummy solver
IshaanDesai Dec 19, 2023
b3b4db5
Update dumux-precice/couplingadapter.cc
IshaanDesai Dec 19, 2023
fd69104
Update examples/dummysolver/main_dummysolver.cc
IshaanDesai Dec 19, 2023
35eafa1
Clean up dummy solver
IshaanDesai Dec 19, 2023
8468057
Using the correct data types
IshaanDesai Dec 19, 2023
d08cd9b
Further simplifying variable definitions in examples
IshaanDesai Dec 19, 2023
87f0aba
Formatting
IshaanDesai Dec 19, 2023
760ec0e
Formatting
IshaanDesai Dec 19, 2023
1c93893
Update dumux-precice/couplingadapter.cc
IshaanDesai Dec 19, 2023
16b0bd3
Update dumux-precice/couplingadapter.hh
IshaanDesai Dec 19, 2023
d436841
Update examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc
IshaanDesai Dec 19, 2023
7b82431
Update examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc
IshaanDesai Dec 19, 2023
2e79346
Removing last traces of _View variables from example codes
IshaanDesai Dec 19, 2023
60c2c38
Merge branch 'develop' into revert-to-std-lib
IshaanDesai Dec 19, 2023
48ad127
Use string literals in adapter API of the problem files (*.hh)
IshaanDesai Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading