From 9b915a8e10533f9148c887e8eee941a0bdf5609b Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Thu, 10 Aug 2023 10:14:33 +0200 Subject: [PATCH 01/16] Update the adapter according to preCICE V3 --- CMakeLists.txt | 2 +- dumux-precice/couplingadapter.cc | 334 ++++-------------- dumux-precice/couplingadapter.hh | 284 ++++----------- examples/dummysolver/main_dummysolver.cc | 135 ++++--- .../precice-dummy-solver-config.xml | 71 ++-- examples/dummysolver/test.xml | 82 +++-- .../flow-over-cube-3d/ffproblem-reversed.hh | 39 +- .../flow-over-cube-3d/main_ff-reversed.cc | 122 +++---- .../flow-over-cube-3d/main_pm-reversed.cc | 134 +++---- .../flow-over-cube-3d/pmproblem-reversed.hh | 29 +- .../flow-over-cube-3d/precice-config.xml | 87 +++-- .../flow-over-square-2d/ffproblem-reversed.hh | 35 +- examples/ff-pm/flow-over-square-2d/main_ff.cc | 79 +++-- examples/ff-pm/flow-over-square-2d/main_pm.cc | 89 ++--- .../flow-over-square-2d/pmproblem-reversed.hh | 27 +- .../flow-over-square-2d/precice-config-pi.xml | 100 +++--- .../precice-config-si-free-flow-first.xml | 98 +++-- .../precice-config-si-free-flow-second.xml | 99 +++--- 18 files changed, 701 insertions(+), 1145 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bbabec..304b007 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ endif() #find dune-common and set the module path find_package(dune-common REQUIRED) # Find preCICE library -find_package(precice 2 REQUIRED CONFIG) +find_package(precice 3 REQUIRED CONFIG) list(APPEND CMAKE_MODULE_PATH ${dune-common_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules") diff --git a/dumux-precice/couplingadapter.cc b/dumux-precice/couplingadapter.cc index d8e70e2..2d2599d 100644 --- a/dumux-precice/couplingadapter.cc +++ b/dumux-precice/couplingadapter.cc @@ -5,6 +5,7 @@ #include #include + using namespace Dumux::Precice; CouplingAdapter::CouplingAdapter() @@ -13,12 +14,8 @@ CouplingAdapter::CouplingAdapter() meshWasCreated_(false), preciceWasInitialized_(false), hasIndexMapper_(false), - meshID_(0), timeStepSize_(0.) { - preciceDataID_.reserve(reserveSize_); - dataNames_.reserve(reserveSize_); - dataVectors_.reserve(reserveSize_); } CouplingAdapter &CouplingAdapter::getInstance() @@ -27,103 +24,71 @@ CouplingAdapter &CouplingAdapter::getInstance() return instance; } -void CouplingAdapter::announceSolver(const std::string &name, +void CouplingAdapter::announceSolver(const std::string &name, //TODO change string inout to string_like? const std::string configurationFileName, const int rank, const int size) { assert(precice_ == nullptr); - precice_ = std::make_unique( + precice_ = std::make_unique( name, configurationFileName, rank, size); wasCreated_ = true; } -size_t CouplingAdapter::announceQuantity(const std::string &name, - const QuantityType quantity_type) +void CouplingAdapter::announceQuantity(const precice::string_view &meshName, + const precice::string_view &dataName) { assert(meshWasCreated_); - auto it = std::find(dataNames_.begin(), dataNames_.end(), name); - if (it != dataNames_.end()) { + const std::string key = createKeyFromName(meshName, dataName); + if (dataMap_.find(key) != dataMap_.end()) { throw(std::runtime_error(" Error! Duplicate quantity announced! ")); } - dataNames_.push_back(name); - preciceDataID_.push_back(precice_->getDataID(name, meshID_)); - const int quantity_dimension = - (quantity_type == QuantityType::Scalar) ? 1 : getDimensions(); - dataVectors_.push_back( - std::vector(vertexIDs_.size() * quantity_dimension)); - - return getNumberOfQuantities() - 1; -} -size_t CouplingAdapter::announceScalarQuantity(const std::string &name) -{ - return announceQuantity(name, QuantityType::Scalar); + int dataDimension = precice_->getDataDimensions(meshName, dataName); + std::vector dataValues(vertexIDs_.size() * dataDimension); + dataMap_.insert(std::make_pair(key, dataValues)); } -size_t CouplingAdapter::announceVectorQuantity(const std::string &name) -{ - return announceQuantity(name, QuantityType::Vector); -} - -int CouplingAdapter::getDimensions() const +int CouplingAdapter::getMeshDimensions(const precice::string_view &meshName) const { assert(wasCreated_); - return precice_->getDimensions(); -} -/* -void CouplingAdapter::setMeshName(const std::string& meshName) -{ - assert( wasCreated_ ); - meshID_ = precice_->getMeshID(meshName); + return precice_->getMeshDimensions(meshName); } -*/ -void CouplingAdapter::setMesh(const std::string &meshName, - const size_t numPoints, - std::vector &coordinates) + +void CouplingAdapter::setMesh(const precice::string_view &meshName, + precice::span positions) { assert(wasCreated_); - assert(numPoints == coordinates.size() / getDimensions()); - meshID_ = precice_->getMeshID(meshName); - vertexIDs_.resize(numPoints); - precice_->setMeshVertices(meshID_, numPoints, coordinates.data(), - vertexIDs_.data()); + vertexIDsSpan_ = precice::span(vertexIDs_); + precice_->setMeshVertices(meshName, positions, vertexIDsSpan_); meshWasCreated_ = true; } -double CouplingAdapter::initialize() +void CouplingAdapter::initialize() { assert(wasCreated_); assert(meshWasCreated_); assert(!preciceWasInitialized_); - timeStepSize_ = precice_->initialize(); + precice_->initialize(); + timeStepSize_ = precice_->getMaxTimeStepSize(); assert(timeStepSize_ > 0); preciceWasInitialized_ = true; - return timeStepSize_; -} - -void CouplingAdapter::createIndexMapping(const std::vector &dumuxFaceIDs) -{ - assert(meshWasCreated_); - indexMapper_.createMapping(dumuxFaceIDs, vertexIDs_); - hasIndexMapper_ = true; + assert(preciceWasInitialized_); } - -double CouplingAdapter::setMeshAndInitialize(const std::string &meshName, - const size_t numPoints, - std::vector &coordinates) + +double CouplingAdapter::getMaxTimeStepSize() { - setMesh(meshName, numPoints, coordinates); - return initialize(); + return precice_->getMaxTimeStepSize(); } -void CouplingAdapter::initializeData() +void CouplingAdapter::createIndexMapping(const std::vector &dumuxFaceIndices)// TODO what does this do? { - assert(preciceWasInitialized_); - precice_->initializeData(); + assert(meshWasCreated_); + indexMapper_.createMapping(dumuxFaceIndices, vertexIDs_); + hasIndexMapper_ = true; } void CouplingAdapter::finalize() @@ -133,7 +98,7 @@ void CouplingAdapter::finalize() precice_->finalize(); } -double CouplingAdapter::advance(const double computedTimeStepLength) +void CouplingAdapter::advance(const double computedTimeStepLength) { assert(wasCreated_); return precice_->advance(computedTimeStepLength); @@ -151,8 +116,9 @@ size_t CouplingAdapter::getNumberOfVertices() return vertexIDs_.size(); } -double CouplingAdapter::getScalarQuantityOnFace(const size_t dataID, - const int faceID) const +double CouplingAdapter::getScalarQuantityOnFace(const precice::string_view &meshName, + const precice::string_view &dataName, + const int faceID) { assert(wasCreated_); assert(hasIndexMapper_); @@ -162,45 +128,13 @@ double CouplingAdapter::getScalarQuantityOnFace(const size_t dataID, "created!"); } const auto idx = indexMapper_.getPreciceId(faceID); - assert(dataID < dataVectors_.size()); - const std::vector &quantityVector = dataVectors_[dataID]; - assert(idx < quantityVector.size()); - return quantityVector[idx]; + std::vector &dataVector = getQuantityVector(meshName, dataName); + assert(idx < dataVector.size()); + return dataVector[idx]; } -// std::vector getVectorQuantityOnFace(const size_t dataID, const int faceID) const -// { -// assert(wasCreated_); -// assert(hasIndexMapper_); -// if (!hasIndexMapper_) { -// throw std::runtime_error( -// "Reading quantity using faceID, but index mapping was not " -// "created!"); -// } -// const auto idx = indexMapper_.getPreciceId(faceID); -// assert(dataID < dataVectors_.size()); -// const std::vector &quantityVector = dataVectors_[dataID]; -// assert(idx+getDimension()-1 < quantityVector.size()); -// std::vector vector_quantity( quantityVector.begin(), quantityVector.begin()+getDimension()-1 ); -// return vector_quantity; -// } -// void getQuantityVector(const size_t dataID, std::vector& quantity_vector) const -// { -// assert(wasCreated_); -// assert(hasIndexMapper_); -// if (!hasIndexMapper_) { -// throw std::runtime_error( -// "Reading quantity using faceID, but index mapping was not " -// "created!"); -// } -// const auto idx = indexMapper_.getPreciceId(faceID); -// const std::vector& data_vector = dataVectors_[dataID]; -// assert(dataID < data_vector.size()); -// quantity_vector.resize( data_vector.size() ); -// std::copy( data_vector.begin(), data_vector.end(), quantity_vector.begin() ); -// } - -void CouplingAdapter::writeScalarQuantityOnFace(const size_t dataID, +void CouplingAdapter::writeScalarQuantityOnFace(const precice::string_view &meshName, + const precice::string_view &dataName, const int faceID, const double value) { @@ -212,96 +146,26 @@ void CouplingAdapter::writeScalarQuantityOnFace(const size_t dataID, "created!"); } const auto idx = indexMapper_.getPreciceId(faceID); - assert(dataID < dataVectors_.size()); - std::vector &quantityVector = dataVectors_[dataID]; - assert(idx < quantityVector.size()); - quantityVector[idx] = value; + std::vector &dataVector = getQuantityVector(meshName, dataName); + assert(idx < dataVector.size()); + dataVector[idx] = value; } -//void CouplingAdapter::writeVectorQuantityOnFace(const size_t dataID, -// const int faceID, -// const double* value, -// const size_t size) -//{ -// assert( wasCreated_ ); -// assert( hasIndexMapper_ ); -// assert( size == getDimensions() ); -// if ( !hasIndexMapper_ ) -// { -// throw std::runtime_error("Writing quantity using faceID, but index mapping was not created!"); -// } -// const auto idx = indexMapper_.getPreciceId( faceID ) * size; -// assert( dataID < dataVectors_.size() ); -// std::vector& quantityVector = dataVectors_[ dataID ]; -// assert( idx < quantityVector.size() ); -// //quantityVector[idx] = value; -// std::copy_n( value, size, quantityVector[idx] ); -//} - -std::vector &CouplingAdapter::getQuantityVector(const size_t dataID) +std::vector &CouplingAdapter::getQuantityVector(const precice::string_view &meshName, + const precice::string_view &dataName) { - assert(wasCreated_); - assert(dataID < dataVectors_.size()); - return dataVectors_[dataID]; + std::string key = createKeyFromName(meshName, dataName); + assert(dataMap_.find(key) != dataMap_.end()); + return dataMap_[key]; } -const std::vector &CouplingAdapter::getQuantityVector( - const size_t dataID) const -{ - assert(wasCreated_); - return getQuantityVector(dataID); -} - -// void CouplingAdapter::writeScalarQuantityVector(const size_t dataID, -// std::vector &values) -// { -// assert(wasCreated_); -// assert(dataID < dataVectors_.size()); -// assert(dataVectors_[dataID].size() == values.size()); -// dataVectors_[dataID] = values; -// } - -void CouplingAdapter::writeQuantityVector(const size_t dataID, +void CouplingAdapter::writeQuantityVector(const precice::string_view &meshName, + const precice::string_view &dataName, std::vector &values) { - assert(wasCreated_); - assert(dataID < dataVectors_.size()); - assert(dataVectors_[dataID].size() == values.size()); - dataVectors_[dataID] = values; -} - -void CouplingAdapter::writeQuantityToOtherSolver( - const size_t dataID, - const QuantityType quantity_type) -{ - assert(wasCreated_); - assert(dataID < dataVectors_.size()); - assert(dataID < preciceDataID_.size()); - assert(dataID < std::numeric_limits::max()); - writeBlockDataToPrecice(preciceDataID_[dataID], dataVectors_[dataID], - quantity_type); -} - -void CouplingAdapter::readQuantityFromOtherSolver( - const size_t dataID, - const QuantityType quantity_type) -{ - assert(wasCreated_); - assert(dataID < dataVectors_.size()); - assert(dataID < preciceDataID_.size()); - assert(dataID < std::numeric_limits::max()); - readBlockDataFromPrecice(preciceDataID_[dataID], dataVectors_[dataID], - quantity_type); -} - -void CouplingAdapter::writeScalarQuantityToOtherSolver(const size_t dataID) -{ - writeQuantityToOtherSolver(dataID, QuantityType::Scalar); -} - -void CouplingAdapter::readScalarQuantityFromOtherSolver(const size_t dataID) -{ - readQuantityFromOtherSolver(dataID, QuantityType::Scalar); + std::vector &dataVector = getQuantityVector(meshName, dataName); + assert(dataVector.size() == values.size()); + dataVector = values; } bool CouplingAdapter::isCoupledEntity(const int faceID) const @@ -310,23 +174,20 @@ bool CouplingAdapter::isCoupledEntity(const int faceID) const return indexMapper_.isDumuxIdMapped(faceID); } -size_t CouplingAdapter::getIdFromName(const std::string &dataName) const +std::string CouplingAdapter::createKeyFromName(const precice::string_view meshName, + const precice::string_view dataName) const { assert(wasCreated_); - const auto it = std::find(dataNames_.begin(), dataNames_.end(), dataName); - if (it == dataNames_.end()) { - throw(std::runtime_error(" Error! Name of data not found! ")); + std::string combinedKey; + + for (int i = 0; i < (meshName.size() + 1 + dataName.size()); i++) + { + if (i < meshName.size()) combinedKey += meshName[i]; + else if (i == meshName.size()) combinedKey += ':'; + else combinedKey += dataName[i - meshName.size()]; } - const auto idx = std::distance(dataNames_.begin(), it); - assert(idx > -1); - return size_t(idx); -} -std::string CouplingAdapter::getNameFromId(const size_t dataID) const -{ - assert(wasCreated_); - assert(dataID < dataNames_.size()); - return dataNames_[dataID]; + return combinedKey; } void CouplingAdapter::print(std::ostream &os) @@ -334,87 +195,36 @@ void CouplingAdapter::print(std::ostream &os) os << indexMapper_; } -bool CouplingAdapter::checkIfActionIsRequired(const std::string &condition) -{ - assert(wasCreated_); - return precice_->isActionRequired(condition); -} - -void CouplingAdapter::actionIsFulfilled(const std::string &condition) -{ - assert(wasCreated_); - precice_->markActionFulfilled(condition); -} - -void CouplingAdapter::readBlockDataFromPrecice(const int dataID, - std::vector &data, - const QuantityType quantity_type) +void CouplingAdapter::readQuantityFromOtherSolver(const precice::string_view &meshName, + const precice::string_view &dataName, + double relativeReadTime) { - assert(wasCreated_); - if (quantity_type == QuantityType::Scalar) { - assert(vertexIDs_.size() == data.size()); - precice_->readBlockScalarData(dataID, vertexIDs_.size(), - vertexIDs_.data(), data.data()); - } else { - assert(vertexIDs_.size() * getDimensions() == data.size()); - precice_->readBlockVectorData(dataID, vertexIDs_.size(), - vertexIDs_.data(), data.data()); - } + precice::span dataValuesSpan(getQuantityVector(meshName,dataName)); + precice_->readData(meshName, dataName, vertexIDsSpan_, relativeReadTime, dataValuesSpan); } -void CouplingAdapter::writeBlockDataToPrecice(const int dataID, - std::vector &data, - const QuantityType quantity_type) +void CouplingAdapter::writeQuantityToOtherSolver(const precice::string_view &meshName, + const precice::string_view &dataName) { - assert(wasCreated_); - if (quantity_type == QuantityType::Scalar) { - assert(vertexIDs_.size() == data.size()); - precice_->writeBlockScalarData(dataID, vertexIDs_.size(), - vertexIDs_.data(), data.data()); - } else { - assert(vertexIDs_.size() * getDimensions() == data.size()); - precice_->writeBlockVectorData(dataID, vertexIDs_.size(), - vertexIDs_.data(), data.data()); - } + precice::span dataValuesSpan(getQuantityVector(meshName,dataName)); + precice_->writeData(meshName, dataName, vertexIDsSpan_, dataValuesSpan); } bool CouplingAdapter::hasToWriteInitialData() { assert(wasCreated_); - return checkIfActionIsRequired( - precice::constants::actionWriteInitialData()); -} - -void CouplingAdapter::announceInitialDataWritten() -{ - assert(wasCreated_); - precice_->markActionFulfilled(precice::constants::actionWriteInitialData()); + return precice_->requiresInitialData(); } bool CouplingAdapter::hasToReadIterationCheckpoint() { assert(wasCreated_); - return checkIfActionIsRequired( - precice::constants::actionReadIterationCheckpoint()); -} - -void CouplingAdapter::announceIterationCheckpointRead() -{ - assert(wasCreated_); - actionIsFulfilled(precice::constants::actionReadIterationCheckpoint()); + return precice_->requiresReadingCheckpoint(); } bool CouplingAdapter::hasToWriteIterationCheckpoint() { assert(wasCreated_); - return checkIfActionIsRequired( - precice::constants::actionWriteIterationCheckpoint()); -} - -void CouplingAdapter::announceIterationCheckpointWritten() -{ - assert(wasCreated_); - actionIsFulfilled(precice::constants::actionWriteIterationCheckpoint()); + return precice_->requiresWritingCheckpoint(); } - CouplingAdapter::~CouplingAdapter() {} diff --git a/dumux-precice/couplingadapter.hh b/dumux-precice/couplingadapter.hh index 946170d..6e856b6 100644 --- a/dumux-precice/couplingadapter.hh +++ b/dumux-precice/couplingadapter.hh @@ -2,7 +2,7 @@ #define PRECICEWRAPPER_HH #include -#include +#include #include #include "dumuxpreciceindexmapper.hh" @@ -13,8 +13,6 @@ */ namespace Dumux::Precice { -enum class QuantityType { Scalar, Vector }; - /*! * @brief A DuMuX-preCICE coupling adapter class * @@ -32,66 +30,23 @@ private: //! True if preCICE instance was initiated bool wasCreated_; //! Pointer to preCICE instance - std::unique_ptr precice_; - //! Constructor - CouplingAdapter(); - /*! - * @brief Checks whether an action predefined by preCICE - * needs to be carried out. - * - * @param[in] condition Name of the action. - * @return true Action must be carried out. - * @return false Action must not be carried out. - */ - bool checkIfActionIsRequired(const std::string &condition); - /*! - * @brief Announce to preCICE that an action was carried out. - * - * @param[in] condition Name of the action. - */ - void actionIsFulfilled(const std::string &condition); - /*! - * @brief Reads full block of data from preCICE. - * - * @param[in] dataID Identifier of dataset to read. - * @param[out] data Vector to store the read data to. - */ - void readBlockDataFromPrecice(const int dataID, - std::vector &data, - const QuantityType quantity_type); - /*! - * @brief Writes full block of data to preCICE. - * - * @param[in] dataID Identifier of dataset to read. - * @param[in] data Vector containing data to write into preCICE's buffer. - */ - void writeBlockDataToPrecice(const int dataID, - std::vector &data, - const QuantityType quantity_type); - /*! - * @brief Gives the number of quantities/datasets defined on coupling interface. - * - * @return size_t Number of quantities defined on the coupling interface. - */ - size_t numberOfQuantities() const { return dataNames_.size(); } + std::unique_ptr precice_; //! True if the coupling mesh was created. bool meshWasCreated_; - //! True if precice::SolverInterface.initialize() has been called. + //! True if precice::Participant.initialize() has been called. bool preciceWasInitialized_; //! True if instance owns an instance of DumuxPreciceIndexMapper. bool hasIndexMapper_; - //! Stores identifier of the coupling mesh provided by preCICE. - int meshID_; //! Time step size. double timeStepSize_; - //! Vector of names of data exchanged over coupling interface. - std::vector dataNames_; - //! Vector of identifiers of data exchanged over coupling interface. - std::vector preciceDataID_; - //! Vector storing data vectors of the data exchanged over the coupling interface. - std::vector > dataVectors_; - //! Vector of identifiers of the vertices of the coupling mesh. + //! Map storing meshName:dataName and data vectors + std::map> dataMap_; + //! Vector of identifiers (in preCICE) of the vertices of the coupling mesh. std::vector vertexIDs_; //should be size_t + //! Span of the precice vertex indices vector vertexIDs_ + precice::span vertexIDsSpan_; + //! Constructor + CouplingAdapter(); /*! * @brief Instance of DumuxPreciceIndexMapper that translates between * DuMuX' identifiers of vertices and preCICE's identifiers. @@ -99,13 +54,11 @@ private: */ Internal::DumuxPreciceIndexMapper indexMapper_; /*! - * @brief Get the of quantities exchanged. + * @brief Get the number of quantities exchanged. * * @return size_t Number of quantities defined on coupling interface. */ - size_t getNumberOfQuantities() const { return dataNames_.size(); } - //! Number of expected quantities on the coupling interface. - static constexpr size_t reserveSize_ = 4; + size_t getNumberOfQuantities() const { return dataMap_.size(); } /*! * @brief Destroy the CouplingAdapter object * @@ -115,7 +68,6 @@ private: public: CouplingAdapter(const CouplingAdapter &) = delete; void operator=(const CouplingAdapter &) = delete; - /*! * @brief Get the instance of the CouplingAdapter * @@ -135,44 +87,29 @@ public: const int rank, const int size); /*! - * @brief Announces an additional quantity on the coupling interface. + * @brief Announces a quantity on the coupling interface. * * Internally, the quantity is announced to preCICE and the corresponding * data structures are initilized to store information about the quantity. * - * @param[in] name Name of the scalar quantity. - * @param[in] quantity_type Type (Scalar or Vector) of the quantity - * @return size_t Number of currently announced quantities. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. */ - size_t announceQuantity(const std::string &name, - const QuantityType quantity_type); - + void announceQuantity(const precice::string_view &meshName, + const precice::string_view &dataName); /*! - * @brief Announces an additional scalar quantity on the coupling interface. - * - * Internally, the scalar quantity is announced to preCICE and the corresponding - * data structures are initilized to store information about the quantity. + * @brief Get the number of spatial dimensions * - * @param[in] name Name of the scalar quantity. - * @return size_t Number of currently announced quantities. + * @param[in] meshName Name of the mesh + * @return int Number of space dimensions. */ - size_t announceScalarQuantity(const std::string &name); + int getMeshDimensions(const precice::string_view &meshName) const; /*! - * @brief Announces an additional vector quantity on the coupling interface. + * @brief Get the maximum time step size from preCICE * - * Internally, the vector quantity is announced to preCICE and the corresponding - * data structures are initilized to store information about the quantity. - * - * @param[in] name Name of the vector quantity. - * @return size_t Number of currently announced quantities. + * @return double time step size */ - size_t announceVectorQuantity(const std::string &name); - /*! - * @brief Get the number of spatial dimensions - * - * @return int Number of space dimensions. Legal values are 2 and 3. - */ - int getDimensions() const; + double getMaxTimeStepSize(); /*! * @brief Checks if simulation checkpoint needs to be restored. * @@ -180,8 +117,7 @@ public: * @return false No further action is needed. */ bool hasToReadIterationCheckpoint(); - //! Announce that the simulation checkpoint was read. - void announceIterationCheckpointRead(); + /*! * @brief Checks if simulation checkpoint needs to be saved. * @@ -189,24 +125,21 @@ public: * @return false No further action is needed. */ bool hasToWriteIterationCheckpoint(); - //! Announce that the simulation checkpoint was written. - void announceIterationCheckpointWritten(); + /*! - * @brief Checks if initial coupling data has to be wrutten. + * @brief Checks if initial coupling data has to be written. * * @return true Initial coupling data has to be provided. * @return false No further action is needed. */ bool hasToWriteInitialData(); - //! Announce that the initial coupling data has been written. - void announceInitialDataWritten(); + /*! * @brief Adds mesh for coupling of solvers. * - * @param[in] meshName Name of the mesh. - * @param[in] numPoints Number of points/vertices. - * @param[in] coordinates Coordinates of the points. - * + * @param[in] meshName The name of the mesh to add the vertices to. + * @param[in] positions A span to the coordinates of the vertices + * * \note The coordinates need to be stored consecutively * according to their spatial coordinates as.\n * Example 2D:\n @@ -214,18 +147,16 @@ 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 std::string &meshName, - const size_t numPoints, - std::vector &coordinates); + void setMesh(const precice::string_view &meshName, + precice::span positions); /*! * @brief Initializes the coupling * * The coupling needs be initialized after all quantities/datasets and coupling meshes * are known. * - * @return double Maximum allowed time step size. */ - double initialize(); + void initialize(); /*! * @brief Creates mapping between DuMuX' face identifiers and preCICE's * vertex identifiers. @@ -236,29 +167,6 @@ public: * passed in setMesh. */ void createIndexMapping(const std::vector &dumuxFaceIDs); - /*! - * @brief Sets the coupling mesh and initializes coupling. - * - * This is a convenience function that sets the coupling mesh using setMesh. - * Afterwards, the coupling is initialized via initialzie. - * - * @param[in] meshName Name of the mesh. - * @param[in] numPoints Number of points/vertices. - * @param[in] coordinates Coordinates of the points. - * @return double Maximum allowed time step size. - */ - double setMeshAndInitialize(const std::string &meshName, - const size_t numPoints, - std::vector &coordinates); - - /*! - * @brief Initializes the coupling data. - * - * If one wants to set non-zero data, one has to write data to the - * corresponding quantities via one of the `write` functions first. - * - */ - void initializeData(); /*! * @brief Destroys the coupling. * @@ -272,7 +180,7 @@ public: * @param[in] computedTimeStepLength Time step lengths of the current simulation stel. * @return double Maximum time step length for successive time steps. */ - double advance(const double computedTimeStepLength); + void advance(const double computedTimeStepLength); /*! * @brief Checks whether the coupling is still ongoing. * @@ -287,96 +195,65 @@ public: */ size_t getNumberOfVertices(); /*! - * @brief Gets value of a scalar quantity. + * @brief Reads full block of data from preCICE. * - * @param[in] dataID Identifier of the quantity. - * @param[in] faceID Identifier of the face according to DuMuX' numbering. - * @return double Value of scalar quantity. + * @param[in] meshName Name of the mesh. + * @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, + double relativeReadTime); + /*! + * @brief Writes full block of data to preCICE. + * + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. */ - double getScalarQuantityOnFace(const size_t dataID, const int faceID) const; - // /*! - // * @brief Gets value of a vector quantity. - // * - // * @param[in] dataID Identifier of the quantity. - // * @param[in] faceID Identifier of the face according to DuMuX' numbering. - // * @return std::vector Value of vector quantity. - // */ - // std::vector getVectorQuantityOnFace(const size_t dataID, const int faceID) const; - // std::vector getVectorQuantity(const size_t dataID) const; + void writeQuantityToOtherSolver(const precice::string_view &meshName, + const precice::string_view &dataName); /*! - * @brief Gets value of a vector quantity. + * @brief Gets value of a scalar quantity on a finite volume face. * - * @param[in] dataID Identifier of the quantity. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. * @param[in] faceID Identifier of the face according to DuMuX' numbering. - * @return const std::vector& Value of vector quantity. + * @return double Value of scalar quantity. */ - const std::vector &getVectorScalarQuantityOnFace( - const size_t dataID, - const int faceID) const; + double getScalarQuantityOnFace(const precice::string_view &meshName, + const precice::string_view &dataName, + const int faceID); /*! - * @brief Writes value of scalar quantity on given face. + * @brief Writes value of scalar quantity on a given finite volume face to data map. * - * @param[in] dataID Identifier of the quantity. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. * @param[in] faceID Identifier of the face according to DuMuX' numbering. * @param[in] value Value of scalar quantity. */ - void writeScalarQuantityOnFace(const size_t dataID, + void writeScalarQuantityOnFace(const precice::string_view &meshName, + const precice::string_view &dataName, const int faceID, const double value); - /*! - * @brief Returns reference to data vector of quantity with given identifier. + * @brief Gets the quantity value vector from the data map according to the mesh and data name. * - * @param dataID Identifier of the quantity. - * @return[in] std::vector& Reference to data vector. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. + * @return The value vector of the quantity. */ - std::vector &getQuantityVector(const size_t dataID); + std::vector &getQuantityVector(const precice::string_view &meshName, + const precice::string_view &dataName); /*! - * @brief Returns const reference to data vector of quantity with given identifier. + * @brief Writes the quantity value vector into the data map. * - * @param[in] dataID Identifier of the quantity. - * @return std::vector& Const reference to data vector. - */ - const std::vector &getQuantityVector(const size_t dataID) const; - - /*! - * @brief Writes value of scalar or vector quantity on all vertices. - * - * @param[in] dataID Identifier of the quantity. + * @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 size_t dataID, std::vector &values); - /*! - * @brief Writes data from adapter's buffer into preCICE's communication buffer. - * - * @param[in] dataID Identifier of the quantity to write into communication buffer. - */ - void writeQuantityToOtherSolver(const size_t dataID, - const QuantityType quantity_type); - /*! - * @brief Reads data from preCICE's communication buffer and puts it into adapter's buffer. - * - * @param dataID Identifier of the quantity to read into adapter buffer. - */ - void readQuantityFromOtherSolver(const size_t dataID, - const QuantityType quantity_type); - /*! - * @brief Writes data from adapter's buffer into preCICE's communication buffer. - * - * @param[in] dataID Identifier of the quantity to write into communication buffer. - */ - void writeScalarQuantityToOtherSolver(const size_t dataID); - /*! - * @brief Reads data from preCICE's communication buffer and puts it into adapter's buffer. - * - * @param dataID Identifier of the quantity to read into adapter buffer. - */ - void readScalarQuantityFromOtherSolver(const size_t dataID); - /*! - * @brief Writes data from adapter's buffer into preCICE's communication buffer. - * - * @param[in] dataID Identifier of the quantity to write into communication buffer. - */ + void writeQuantityVector(const precice::string_view &meshName, + const precice::string_view &dataName, + std::vector &values); /*! * @brief Checks whether face with given identifier is part of coupling interface. * @@ -386,19 +263,14 @@ public: */ bool isCoupledEntity(const int faceID) const; /*! - * @brief Get a quantity's numeric identifier from its name. + * @brief Get a quantity's identifier from its name. * + * @param[in] meshName Name of the mesh. * @param[in] dataName Name of the quantity. * @return size_t Numeric identifier of quantity. */ - size_t getIdFromName(const std::string &dataName) const; - /*! - * @brief Get a quantitiy's name from its numeric identifier. - * - * @param dataID Identifier of the quantity to read into adapter buffer. - * @return std::string Name of the quantity. - */ - std::string getNameFromId(const size_t dataID) const; + std::string createKeyFromName(const precice::string_view meshName, + const precice::string_view dataName) const; /*! * @brief Prints status of coupling adapter to given output stream. * diff --git a/examples/dummysolver/main_dummysolver.cc b/examples/dummysolver/main_dummysolver.cc index 5e8808d..12f9e74 100644 --- a/examples/dummysolver/main_dummysolver.cc +++ b/examples/dummysolver/main_dummysolver.cc @@ -36,16 +36,16 @@ try { // - Name of solver // - Configuration file name // - Solver rank - const std::string solverName = getParamFromGroup("preCICE", "SolverName"); const std::string preciceConfigFilename = getParamFromGroup("preCICE", "ConfigFileName"); const std::string meshName = getParamFromGroup("preCICE", "MeshName"); + precice::string_view meshNameView(meshName); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver(solverName, preciceConfigFilename, + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver(solverName, preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); std::cout << "DUMMY (" << mpiHelper.rank() @@ -53,24 +53,21 @@ try { << preciceConfigFilename << "\", participant name \"" << solverName << "\", and mesh name \"" << meshName << "\".\n"; - const int dimensions = couplingInterface.getDimensions(); + const int dimensions = couplingParticipant.getMeshDimensions(meshNameView); assert(dimensions == 3); - 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 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 int numberOfVertices = 3; std::vector writeScalarData(numberOfVertices); + std::vector readScalarData(numberOfVertices); std::vector writeVectorData(numberOfVertices * dimensions); - std::vector vertices(numberOfVertices * dimensions); - std::vector preciceVertexIDs(numberOfVertices); + std::vector readVectorData(numberOfVertices * dimensions); + + std::vector vertices(numberOfVertices * dimensions); // coordinates std::vector dumuxVertexIDs(numberOfVertices); for (int i = 0; i < numberOfVertices; i++) { @@ -82,60 +79,55 @@ try { } } + precice::span writeScalarDataSpan(writeScalarData); + precice::span readScalarDataSpan(readScalarData); + precice::span writeVectorDataSpan(writeVectorData); + precice::span readVectorDataSpan(readVectorData); + precice::span dumuxVertexIDsSpan(dumuxVertexIDs); + std::cout << "DUMMY (" << mpiHelper.rank() << "): Initialize preCICE and set mesh\n"; - double preciceDt = couplingInterface.setMeshAndInitialize( - meshName, numberOfVertices, vertices); + couplingParticipant.setMesh(meshNameView, vertices); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); // Create index mapping between DuMuX's index numbering and preCICE's numbering std::cout << "DUMMY (" << mpiHelper.rank() << "): Create index mapping\n"; - couplingInterface.createIndexMapping(dumuxVertexIDs); - - const int readScalarDataID = - couplingInterface.announceScalarQuantity(scalarDataReadName); - const int writeScalarDataID = - couplingInterface.announceScalarQuantity(scalarDataWriteName); - const int readVectorDataID = - couplingInterface.announceVectorQuantity(vectorDataReadName); - const int writeVectorDataID = - couplingInterface.announceVectorQuantity(vectorDataWriteName); - - if (couplingInterface.hasToWriteInitialData()) { + couplingParticipant.createIndexMapping(dumuxVertexIDs); + + couplingParticipant.announceQuantity(meshNameView, scalarDataWriteName); + couplingParticipant.announceQuantity(meshNameView, scalarDataReadName); + couplingParticipant.announceQuantity(meshNameView, vectorDataWriteName); + couplingParticipant.announceQuantity(meshNameView, vectorDataReadName); + + if (couplingParticipant.hasToWriteInitialData()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Writing initial data\n"; - // Scalar data - couplingInterface.writeQuantityVector(writeScalarDataID, - writeScalarData); - couplingInterface.writeScalarQuantityToOtherSolver(writeScalarDataID); - // Vector data - couplingInterface.writeQuantityVector(writeVectorDataID, - writeVectorData); - couplingInterface.writeQuantityToOtherSolver( - writeVectorDataID, Dumux::Precice::QuantityType::Vector); - couplingInterface.announceInitialDataWritten(); + + couplingParticipant.writeQuantityVector(meshNameView, scalarDataWriteName, writeScalarData); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, scalarDataWriteName); + couplingParticipant.writeQuantityVector(meshNameView, vectorDataWriteName, writeVectorData); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, vectorDataWriteName); } std::cout << "DUMMY (" << mpiHelper.rank() << "): Exchange initial\n"; - couplingInterface.initializeData(); + couplingParticipant.initialize(); // Check exchanged initial data if (solverName == "SolverOne") { std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading initial data\n"; - couplingInterface.readQuantityFromOtherSolver( - readScalarDataID, Dumux::Precice::QuantityType::Scalar); - couplingInterface.readQuantityFromOtherSolver( - readVectorDataID, Dumux::Precice::QuantityType::Vector); + couplingParticipant.readQuantityFromOtherSolver( + meshNameView, scalarDataReadName, preciceDt); + couplingParticipant.readQuantityFromOtherSolver( + meshNameView, vectorDataReadName, preciceDt); - const std::vector &readScalarQuantity = - couplingInterface.getQuantityVector(readScalarDataID); + const std::vector &readScalarQuantity = readScalarData; std::cout << "DUMMY (" << mpiHelper.rank() << "): Scalar data\n"; for (const double &value : readScalarQuantity) std::cout << value << ","; std::cout << "\n"; - const std::vector &readVectorQuantity = - couplingInterface.getQuantityVector(readVectorDataID); + const std::vector &readVectorQuantity = readVectorData; std::cout << "DUMMY (" << mpiHelper.rank() << "): Vector data\n"; for (const double &value : readVectorQuantity) @@ -143,7 +135,7 @@ try { std::cout << "\n"; for (int i = 0; i < numberOfVertices; i++) { - if (readScalarQuantity.at(i) != writeScalarData.at(i)) { + if (readScalarQuantity.at(i) != writeScalarData.at(i)) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading initialized SCALAR data error\n" << "Index: " << i << ", Expected " @@ -153,7 +145,7 @@ try { } for (int j = 0; j < dimensions; j++) { - if (readVectorQuantity.at(j + dimensions * i) != + if (readVectorQuantity.at(j + dimensions * i)!= writeVectorData.at(j + dimensions * i)) { std::cout << "DUMMY (" << mpiHelper.rank() @@ -170,28 +162,25 @@ try { int iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.hasToWriteIterationCheckpoint()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Writing iteration checkpoint\n"; - couplingInterface.announceIterationCheckpointWritten(); } //Read data std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading data\n"; - couplingInterface.readQuantityFromOtherSolver( - readScalarDataID, Dumux::Precice::QuantityType::Scalar); - couplingInterface.readQuantityFromOtherSolver( - readVectorDataID, Dumux::Precice::QuantityType::Vector); + couplingParticipant.readQuantityFromOtherSolver( + meshNameView, scalarDataReadName, preciceDt); + couplingParticipant.readQuantityFromOtherSolver( + meshNameView, vectorDataReadName, preciceDt); // Check data if (iter > 0) { int offset = (solverName == "SolverOne") ? 0 : 1; - const std::vector &readScalarQuantity = - couplingInterface.getQuantityVector(readScalarDataID); - - const std::vector &readVectorQuantity = - couplingInterface.getQuantityVector(readVectorDataID); + + const std::vector &readScalarQuantity = readScalarData; + const std::vector &readVectorQuantity = readVectorData; for (int i = 0; i < numberOfVertices; i++) { if (readScalarQuantity.at(i) != @@ -236,24 +225,21 @@ try { // Write scalar data via DuMuX ID <-> preCICE ID mapping for (int i = 0; i < numberOfVertices; i++) { const double value = i + iter; - couplingInterface.writeScalarQuantityOnFace( - writeScalarDataID, dumuxVertexIDs[i], value); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, scalarDataWriteName, dumuxVertexIDs[i], value); } - couplingInterface.writeQuantityToOtherSolver( - writeScalarDataID, Dumux::Precice::QuantityType::Scalar); + couplingParticipant.writeQuantityToOtherSolver( + meshNameView, scalarDataWriteName); // Write vector data - couplingInterface.writeQuantityVector(writeVectorDataID, - writeVectorData); - couplingInterface.writeQuantityToOtherSolver( - writeVectorDataID, Dumux::Precice::QuantityType::Vector); + couplingParticipant.writeQuantityVector(meshNameView, vectorDataWriteName, writeVectorData); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, vectorDataWriteName); - preciceDt = couplingInterface.advance(preciceDt); + couplingParticipant.advance(preciceDt); - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.hasToReadIterationCheckpoint()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading iteration checkpoint\n"; - couplingInterface.announceIterationCheckpointRead(); } else { std::cout << "DUMMY (" << mpiHelper.rank() << "): Advancing in time\n"; @@ -263,7 +249,7 @@ try { // finalize, print dumux message to say goodbye //////////////////////////////////////////////////////////// - couplingInterface.finalize(); + couplingParticipant.finalize(); std::cout << "DUMMY (" << mpiHelper.rank() << "): Closing C++ solver dummy...\n"; @@ -275,6 +261,7 @@ try { return 0; } // end main + catch (Dumux::ParameterException &e) { std::cerr << std::endl << e << " ---> Abort!" << std::endl; return 1; diff --git a/examples/dummysolver/precice-dummy-solver-config.xml b/examples/dummysolver/precice-dummy-solver-config.xml index 4cd2a69..dd65dca 100644 --- a/examples/dummysolver/precice-dummy-solver-config.xml +++ b/examples/dummysolver/precice-dummy-solver-config.xml @@ -6,53 +6,51 @@ - + + - - + + - - + + + - - - + + + - - - + + + - - - + + + - - - + + - - + + + + + - - - - - + + + - - - + + - - + + + + + - - - - - - - + @@ -68,6 +66,5 @@ - diff --git a/examples/dummysolver/test.xml b/examples/dummysolver/test.xml index 4d46857..4f53212 100644 --- a/examples/dummysolver/test.xml +++ b/examples/dummysolver/test.xml @@ -6,47 +6,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh b/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh index 1687d6e..b8e05be 100644 --- a/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh +++ b/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh @@ -137,15 +137,12 @@ public: StokesSubProblem(std::shared_ptr gridGeometry) : ParentType(gridGeometry, "FreeFlow"), eps_(1e-6), - couplingInterface_(Dumux::Precice::CouplingAdapter::getInstance()), - pressureId_(0), - velocityId_(0), - dataIdsWereSet_(false) + couplingParticipant_(Dumux::Precice::CouplingAdapter::getInstance()) { deltaP_ = getParamFromGroup(this->paramGroup(), "Problem.PressureDifference"); - // pressureId_ = couplingInterface_.getIdFromName( "Pressure" ); - // velocityId_ = couplingInterface_.getIdFromName( "Velocity" ); + // pressureId_ = couplingParticipant_.getIdFromName( "Pressure" ); + // velocityId_ = couplingParticipant_.getIdFromName( "Velocity" ); } /*! @@ -202,9 +199,7 @@ public: values.setDirichlet(Indices::pressureIdx); } // coupling interface - else if (couplingInterface_.isCoupledEntity(faceId)) { - // // TODO do preCICE stuff in analogy to heat transfer - assert(dataIdsWereSet_); + else if (couplingParticipant_.isCoupledEntity(faceId)) { //TODO What do I want to do here? // values.setCouplingNeumann(Indices::conti0EqIdx); // values.setCouplingNeumann(Indices::momentumYBalanceIdx); @@ -232,13 +227,15 @@ public: PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const { + precice::string_view meshNameView_ = std::string("FreeFlowMesh"); + precice::string_view dataNameView_ = std::string("Velocity"); PrimaryVariables values(0.0); values = initialAtPos(scvf.center()); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { values[Indices::velocityYIdx] = - couplingInterface_.getScalarQuantityOnFace(velocityId_, faceId); + couplingParticipant_.getScalarQuantityOnFace(meshNameView_, dataNameView_, faceId); } return values; @@ -260,11 +257,12 @@ public: const ElementFaceVariables &elemFaceVars, const SubControlVolumeFace &scvf) const { + precice::string_view meshNameView = std::string("FreeFlowMesh"); + precice::string_view dataNameView = std::string("Pressure"); NumEqVector values(0.0); - assert(dataIdsWereSet_); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { const Scalar density = 1000; // TODO how to handle compressible fluids? values[Indices::conti0EqIdx] = density * @@ -272,7 +270,8 @@ public: scvf.directionSign(); values[Indices::momentumYBalanceIdx] = scvf.directionSign() * - (couplingInterface_.getScalarQuantityOnFace(pressureId_, + (couplingParticipant_.getScalarQuantityOnFace(meshNameView, + dataNameView, faceId) - initialAtPos(scvf.center())[Indices::pressureIdx]); } @@ -372,13 +371,6 @@ public: return analyticalVelocityX_; } - void updatePreciceDataIds() - { - pressureId_ = couplingInterface_.getIdFromName("Pressure"); - velocityId_ = couplingInterface_.getIdFromName("Velocity"); - dataIdsWereSet_ = true; - } - // \} private: @@ -405,10 +397,7 @@ private: Scalar eps_; Scalar deltaP_; - Dumux::Precice::CouplingAdapter &couplingInterface_; - size_t pressureId_; - size_t velocityId_; - bool dataIdsWereSet_; + Dumux::Precice::CouplingAdapter &couplingParticipant_; mutable std::vector analyticalVelocityX_; }; diff --git a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc index 8eb87eb..dd97c81 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc @@ -89,7 +89,9 @@ template void setInterfacePressures(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const precice::string_view meshNameView, + const precice::string_view dataNameView) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); @@ -97,8 +99,7 @@ void setInterfacePressures(const Problem &problem, auto elemFaceVars = localView(gridVars.curGridFaceVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto pressureId = couplingInterface.getIdFromName("Pressure"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bind(element); @@ -107,12 +108,13 @@ void setInterfacePressures(const Problem &problem, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const auto p = pressureAtInterface( problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(pressureId, + couplingParticipant.writeScalarQuantityOnFace(meshNameView, + dataNameView, scvf.index(), p); } } @@ -122,15 +124,16 @@ void setInterfacePressures(const Problem &problem, template void setInterfaceVelocities(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const precice::string_view meshNameView, + const precice::string_view dataNameView) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFaceVars = localView(gridVars.curGridFaceVars()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto velocityId = couplingInterface.getIdFromName("Velocity"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bindElement(element); @@ -138,11 +141,11 @@ void setInterfaceVelocities(const Problem &problem, elemFaceVars.bindElement(element, fvGeometry, sol); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const auto v = velocityAtInterface(elemFaceVars, scvf)[scvf.directionIndex()]; - couplingInterface.writeScalarQuantityOnFace(velocityId, + couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, scvf.index(), v); } } @@ -151,6 +154,7 @@ void setInterfaceVelocities(const Problem &problem, template std::tuple writeVelocitiesOnInterfaceToFile( + const precice::string_view &meshNameView, const std::string &filename, const Problem &problem, const GridVariables &gridVars, @@ -161,13 +165,13 @@ std::tuple writeVelocitiesOnInterfaceToFile( auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFaceVars = localView(gridVars.curGridFaceVars()); - const auto &couplingInterface = + const auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); std::ofstream ofs(filename + ".csv", std::ofstream::out | std::ofstream::trunc); ofs << "x,y,"; - if (couplingInterface.getDimensions() == 3) + if (couplingParticipant.getMeshDimensions(meshNameView) == 3) ofs << "z,"; ofs << "velocityY" << "\n"; @@ -181,9 +185,9 @@ std::tuple writeVelocitiesOnInterfaceToFile( elemFaceVars.bindElement(element, fvGeometry, sol); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingInterface.getDimensions(); ++i) { + for (int i = 0; i < couplingParticipant.getMeshDimensions(meshNameView); ++i) { ofs << pos[i] << ","; } const double v = problem.dirichlet(element, scvf)[1]; @@ -209,7 +213,8 @@ template -void writePressuresOnInterfaceToFile(const std::string &filename, +void writePressuresOnInterfaceToFile(const precice::string_view &meshNameView, + const std::string &filename, const Problem &problem, const GridVariables &gridVars, const SolutionVector &sol) @@ -220,13 +225,13 @@ void writePressuresOnInterfaceToFile(const std::string &filename, auto elemFaceVars = localView(gridVars.curGridFaceVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - const auto &couplingInterface = + const auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); std::ofstream ofs(filename + ".csv", std::ofstream::out | std::ofstream::trunc); ofs << "x,y,"; - if (couplingInterface.getDimensions() == 3) + if (couplingParticipant.getMeshDimensions(meshNameView) == 3) ofs << "z,"; ofs << "pressure" << "\n"; @@ -237,9 +242,9 @@ void writePressuresOnInterfaceToFile(const std::string &filename, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingInterface.getDimensions(); ++i) { + for (int i = 0; i < couplingParticipant.getMeshDimensions(meshNameView); ++i) { ofs << pos[i] << ","; } const double p = pressureAtInterface( @@ -251,7 +256,7 @@ void writePressuresOnInterfaceToFile(const std::string &filename, } ofs.close(); -} +} int main(int argc, char **argv) try { @@ -306,22 +311,23 @@ try { // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - //couplingInterface.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); + //couplingParticipant.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); std::string preciceConfigFilename = "precice-config.xml"; // if (argc == 3) // preciceConfigFilename = argv[2]; if (argc > 2) preciceConfigFilename = argv[argc - 1]; - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver("FreeFlow", preciceConfigFilename, + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver("FreeFlow", preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - const int dim = couplingInterface.getDimensions(); + const precice::string_view meshNameView = std::string("FreeFlowMesh"); + const int dim = couplingParticipant.getMeshDimensions(meshNameView); std::cout << dim << " " << int(FreeFlowGridGeometry::GridView::dimension) << std::endl; if (dim != int(FreeFlowGridGeometry::GridView::dimension)) - DUNE_THROW(Dune::InvalidStateException, "Dimensions do not match"); + DUNE_THROW(Dune::InvalidStateException, "Dimensions do not match"); // GET mesh corodinates const double xMin = @@ -330,6 +336,7 @@ try { getParamFromGroup>("Darcy", "Grid.UpperRight")[0]; std::vector coords; //( dim * vertexSize ); std::vector coupledScvfIndices; + precice::span coordsSpan(coords); for (const auto &element : elements(freeFlowGridView)) { auto fvGeometry = localView(*freeFlowGridGeometry); @@ -349,16 +356,14 @@ try { } const auto numberOfPoints = coords.size() / dim; - const double preciceDt = couplingInterface.setMeshAndInitialize( - "FreeFlowMesh", numberOfPoints, coords); - couplingInterface.createIndexMapping(coupledScvfIndices); - - const auto velocityId = - couplingInterface.announceScalarQuantity("Velocity"); - const auto pressureId = - couplingInterface.announceScalarQuantity("Pressure"); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); + couplingParticipant.setMesh(meshNameView, coordsSpan); + couplingParticipant.createIndexMapping(coupledScvfIndices); - freeFlowProblem->updatePreciceDataIds(); + const precice::string_view dataNameViewV = std::string("Velocity"); + const precice::string_view dataNameViewP = std::string("Pressure"); + couplingParticipant.announceQuantity(meshNameView, dataNameViewV); + couplingParticipant.announceQuantity(meshNameView, dataNameViewP); // apply initial solution for instationary problems freeFlowProblem->applyInitialSolution(sol); @@ -382,24 +387,15 @@ try { using FluxVariables = GetPropType; - if (couplingInterface.hasToWriteInitialData()) { + if (couplingParticipant.hasToWriteInitialData()) { //TODO - // couplingInterface.writeQuantityVector( pressureId ); + // couplingParticipant.writeQuantityVector( pressureId ); setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol); - //For testing - // { - // std::cout << "Pressures to be sent to pm" << std::endl; - // const auto p = couplingInterface.getQuantityVector( pressureId ); - // for (size_t i = 0; i < p.size(); ++i) { - // std::cout << "p[" << i << "]=" <(*freeFlowProblem, - *freeFlowGridVariables, sol); - // For testing - // { - // const auto p = couplingInterface.getQuantityVector( pressureId ); - // const double sum = std::accumulate( p.begin(), p.end(), 0. ); - // std::cout << "Pressures to be sent to pm" << std::endl; - //// for (size_t i = 0; i < p.size(); ++i) { - //// std::cout << "p[" << i << "]=" << p[i] << std::endl; - //// } - // std::cout << "Sum of pressures over boundary to pm: \n" << sum << std::endl; - // } - couplingInterface.writeScalarQuantityToOtherSolver(pressureId); + *freeFlowGridVariables, sol, meshNameView, dataNameViewP); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); //Read checkpoint freeFlowVtkWriter.write(vtkTime); vtkTime += 1.; - const double preciceDt = couplingInterface.advance(dt); + preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); ++iter; - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.hasToReadIterationCheckpoint()) { // //Read checkpoint // freeFlowVtkWriter.write(vtkTime); // vtkTime += 1.; @@ -471,7 +456,6 @@ try { freeFlowGridVariables->update(sol); freeFlowGridVariables->advanceTimeStep(); //freeFlowGridVariables->init(sol); - couplingInterface.announceIterationCheckpointRead(); } else // coupling successful { // write vtk output @@ -482,7 +466,7 @@ try { // finalize, print dumux message to say goodbye //////////////////////////////////////////////////////////// - couplingInterface.finalize(); + couplingParticipant.finalize(); // print dumux end message if (mpiHelper.rank() == 0) { diff --git a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc index 378ca1e..d4ed1f2 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc @@ -105,15 +105,16 @@ auto pressureAtInterface(const Problem &problem, template void setInterfacePressures(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const precice::string_view meshNameView, + const precice::string_view dataNameView) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto pressureId = couplingInterface.getIdFromName("Pressure"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bindElement(element); @@ -121,12 +122,12 @@ void setInterfacePressures(const Problem &problem, //sstd::cout << "Pressure by reconstruction" << std::endl; for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const double p = pressureAtInterface(problem, element, gridGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(pressureId, + couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, scvf.index(), p); } } @@ -168,15 +169,16 @@ template void setInterfaceVelocities(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const precice::string_view meshNameView, + const precice::string_view dataNameView) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto velocityId = couplingInterface.getIdFromName("Velocity"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bind(element); @@ -184,12 +186,12 @@ void setInterfaceVelocities(const Problem &problem, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const double v = velocityAtInterface( problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(velocityId, + couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, scvf.index(), v); } } @@ -201,6 +203,7 @@ template std::tuple writeVelocitiesOnInterfaceToFile( + const precice::string_view &meshName, const std::string &filename, const Problem &problem, const GridVariables &gridVars, @@ -211,13 +214,13 @@ std::tuple writeVelocitiesOnInterfaceToFile( auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - const auto &couplingInterface = + const auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); std::ofstream ofs(filename + ".csv", std::ofstream::out | std::ofstream::trunc); ofs << "x,y,"; - if (couplingInterface.getDimensions() == 3) + if (couplingParticipant.getMeshDimensions(meshName) == 3) ofs << "z,"; ofs << "velocityY" << "\n"; @@ -231,9 +234,9 @@ std::tuple writeVelocitiesOnInterfaceToFile( elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingInterface.getDimensions(); ++i) { + for (int i = 0; i < couplingParticipant.getMeshDimensions(meshName); ++i) { ofs << pos[i] << ","; } const double v = velocityAtInterface( @@ -253,10 +256,11 @@ std::tuple writeVelocitiesOnInterfaceToFile( ofs.close(); return std::make_tuple(min, max, sum); -} +} template -void writePressuresOnInterfaceToFile(const std::string &filename, +void writePressuresOnInterfaceToFile(const precice::string_view &meshName, + std::string &filename, const Problem &problem, const GridVariables &gridVars, const SolutionVector &sol) @@ -266,13 +270,13 @@ void writePressuresOnInterfaceToFile(const std::string &filename, auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - const auto &couplingInterface = + const auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); std::ofstream ofs(filename + ".csv", std::ofstream::out | std::ofstream::trunc); ofs << "x,y,"; - if (couplingInterface.getDimensions() == 3) + if (couplingParticipant.getMeshDimensions(meshName) == 3) ofs << "z,"; ofs << "pressure" << "\n"; @@ -282,9 +286,9 @@ void writePressuresOnInterfaceToFile(const std::string &filename, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingInterface.getDimensions(); ++i) { + for (int i = 0; i < couplingParticipant.getMeshDimensions(meshName); ++i) { ofs << pos[i] << ","; } const double p = @@ -343,18 +347,19 @@ try { // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - //couplingInterface.createInstance( "darcy", mpiHelper.rank(), mpiHelper.size() ); + //couplingParticipant.createInstance( "darcy", mpiHelper.rank(), mpiHelper.size() ); std::string preciceConfigFilename = "precice-config.xml"; // if (argc == 3) // preciceConfigFilename = argv[2]; if (argc > 2) preciceConfigFilename = argv[argc - 1]; - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver("Darcy", preciceConfigFilename, + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver("Darcy", preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - const int dim = couplingInterface.getDimensions(); + const precice::string_view meshNameView = std::string("DarcyMesh"); + const int dim = couplingParticipant.getMeshDimensions(meshNameView); std::cout << dim << " " << int(DarcyGridGeometry::GridView::dimension) << std::endl; if (dim != int(DarcyGridGeometry::GridView::dimension)) @@ -367,6 +372,7 @@ try { getParamFromGroup>("Darcy", "Grid.UpperRight")[0]; std::vector coords; //( dim * vertexSize ); std::vector coupledScvfIndices; + precice::span coordsSpan(coords); for (const auto &element : elements(darcyGridView)) { auto fvGeometry = localView(*darcyGridGeometry); @@ -386,16 +392,14 @@ try { } const auto numberOfPoints = coords.size() / dim; - const double preciceDt = couplingInterface.setMeshAndInitialize( - "DarcyMesh", numberOfPoints, coords); - couplingInterface.createIndexMapping(coupledScvfIndices); - - const auto velocityId = - couplingInterface.announceScalarQuantity("Velocity"); - const auto pressureId = - couplingInterface.announceScalarQuantity("Pressure"); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); + couplingParticipant.setMesh(meshNameView, coordsSpan); + couplingParticipant.createIndexMapping(coupledScvfIndices); - darcyProblem->updatePreciceDataIds(); + const precice::string_view dataNameViewV = std::string("Velocity"); + const precice::string_view dataNameViewP = std::string("Pressure"); + couplingParticipant.announceQuantity(meshNameView, dataNameViewP); + couplingParticipant.announceQuantity(meshNameView, dataNameViewV); darcyProblem->applyInitialSolution(sol); @@ -422,26 +426,14 @@ try { darcyVtkWriter.write(0.0); using FluxVariables = GetPropType; - if (couplingInterface.hasToWriteInitialData()) { + if (couplingParticipant.hasToWriteInitialData()) { //TODO - //couplingInterface.writeQuantityVector(velocityId); setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol); - // For testing - { - const auto v = couplingInterface.getQuantityVector(velocityId); - std::cout << "velocities to be sent to ff" << std::endl; - for (size_t i = 0; i < v.size(); ++i) { - for (size_t d = 0; d < dim; ++d) { - std::cout << coords[i * dim + d] << " "; - } - std::cout << "| v[" << i << "]=" << v[i] << std::endl; - } - } - couplingInterface.writeScalarQuantityToOtherSolver(velocityId); - couplingInterface.announceInitialDataWritten(); + *darcyGridVariables, sol, meshNameView, dataNameViewV); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); } - couplingInterface.initializeData(); + couplingParticipant.setMeshAndInitialize( + "DarcyMesh", numberOfPoints, coords);// couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = FVAssembler; @@ -462,40 +454,21 @@ try { double vtkTime = 1.0; size_t iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.hasToWriteIterationCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; - couplingInterface.announceIterationCheckpointWritten(); - } - - // TODO - couplingInterface.readScalarQuantityFromOtherSolver(pressureId); - // For testing - { - const auto p = couplingInterface.getQuantityVector(pressureId); - for (size_t i = 0; i < p.size(); ++i) { - for (size_t d = 0; d < dim; ++d) { - std::cout << coords[i * dim + d] << " "; - } - std::cout << "| p[" << i << "]=" << p[i] << std::endl; - } - const double sum = std::accumulate(p.begin(), p.end(), 0.); - std::cout << "Sum of pressures over boundary to ff: \n" - << sum << std::endl; - std::cout << "Pressure received from ff" << std::endl; - // for (size_t i = 0; i < p.size(); ++i) { - // std::cout << "p[" << i << "]=" << p[i] << std::endl; - // } } + couplingParticipant.readQuantityFromOtherSolver(meshNameView, dataNameViewP); + // solve the non-linear system nonLinearSolver.solve(sol); setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol); + *darcyGridVariables, sol, meshNameView, dataNameViewV); // For testing { - const auto v = couplingInterface.getQuantityVector(velocityId); + const auto v = couplingParticipant.getQuantityVector(velocityId); for (size_t i = 0; i < v.size(); ++i) { for (size_t d = 0; d < dim; ++d) { std::cout << coords[i * dim + d] << " "; @@ -511,22 +484,21 @@ try { std::cout << "Sum of velocities over boundary to ff: \n" << sum << std::endl; } - couplingInterface.writeScalarQuantityToOtherSolver(velocityId); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); - const double preciceDt = couplingInterface.advance(dt); + couplingParticipant.advance(dt); + preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); ++iter; - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.hasToReadIterationCheckpoint()) { //Read checkpoint darcyVtkWriter.write(vtkTime); vtkTime += 1.; sol = sol_checkpoint; darcyGridVariables->update(sol); darcyGridVariables->advanceTimeStep(); - //darcyGridVariables->init(sol); - couplingInterface.announceIterationCheckpointRead(); } else // coupling successful { // write vtk output @@ -536,7 +508,7 @@ try { // write vtk output darcyVtkWriter.write(1.0); - couplingInterface.finalize(); + couplingParticipant.finalize(); //////////////////////////////////////////////////////////// // finalize, print dumux message to say goodbye diff --git a/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh b/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh index 776eee9..f40d6d7 100644 --- a/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh +++ b/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh @@ -122,10 +122,7 @@ public: DarcySubProblem(std::shared_ptr fvGridGeometry) : ParentType(fvGridGeometry, "Darcy"), eps_(1e-7), - couplingInterface_(Dumux::Precice::CouplingAdapter::getInstance()), - pressureId_(0), - velocityId_(0), - dataIdsWereSet_(false) + couplingParticipant_(Dumux::Precice::CouplingAdapter::getInstance()) { } @@ -168,7 +165,7 @@ public: values.setAllNeumann(); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) + if (couplingParticipant_.isCoupledEntity(faceId)) values.setAllDirichlet(); return values; } @@ -184,14 +181,16 @@ public: PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const { + precice::string_view meshNameView_ = std::string("DarcyMesh"); + precice::string_view dataNameView_ = std::string("Pressure"); // set p = 0 at the bottom PrimaryVariables values(0.0); values = initial(element); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) + if (couplingParticipant_.isCoupledEntity(faceId)) values = - couplingInterface_.getScalarQuantityOnFace(pressureId_, faceId); + couplingParticipant_.getScalarQuantityOnFace(meshNameView_, dataNameView_, faceId); return values; } @@ -218,10 +217,10 @@ public: // assert( dataIdsWereSet_ ); // const auto faceId = scvf.index(); - // if ( couplingInterface_.isCoupledEntity(faceId) ) + // if ( couplingParticipant_.isCoupledEntity(faceId) ) // { // const Scalar density = 1000.; - // values[Indices::conti0EqIdx] = density * couplingInterface_.getScalarQuantityOnFace( velocityId_, faceId ); + // values[Indices::conti0EqIdx] = density * couplingParticipant_.getScalarQuantityOnFace( velocityId_, faceId ); // std::cout << "pm: values[Indices::conti0EqIdx] = " << values << std::endl; // } return values; @@ -280,13 +279,6 @@ public: // \} - void updatePreciceDataIds() - { - pressureId_ = couplingInterface_.getIdFromName("Pressure"); - velocityId_ = couplingInterface_.getIdFromName("Velocity"); - dataIdsWereSet_ = true; - } - private: bool onLeftBoundary_(const GlobalPosition &globalPos) const { @@ -310,10 +302,7 @@ private: Scalar eps_; - Dumux::Precice::CouplingAdapter &couplingInterface_; - size_t pressureId_; - size_t velocityId_; - bool dataIdsWereSet_; + Dumux::Precice::CouplingAdapter &couplingParticipant_; }; } // namespace Dumux diff --git a/examples/ff-pm/flow-over-cube-3d/precice-config.xml b/examples/ff-pm/flow-over-cube-3d/precice-config.xml index 6d4c872..4020d7d 100644 --- a/examples/ff-pm/flow-over-cube-3d/precice-config.xml +++ b/examples/ff-pm/flow-over-cube-3d/precice-config.xml @@ -6,55 +6,53 @@ - - - + + - - - - + + + + - - - - + + + + - - - + + + - - + + - - + + + - + + - - + + + - - - + - + + + + - - - - + + + - - - - - - + + - + - - - - - - - + + + + + + + - - + diff --git a/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh b/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh index b9d23c6..7227a8f 100644 --- a/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh +++ b/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh @@ -138,10 +138,7 @@ public: StokesSubProblem(std::shared_ptr gridGeometry) : ParentType(gridGeometry, "FreeFlow"), eps_(1e-6), - couplingInterface_(Dumux::Precice::CouplingAdapter::getInstance()), - pressureId_(0), - velocityId_(0), - dataIdsWereSet_(false) + couplingParticipant_(Dumux::Precice::CouplingAdapter::getInstance()) { deltaP_ = getParamFromGroup(this->paramGroup(), "Problem.PressureDifference"); @@ -201,9 +198,7 @@ public: values.setDirichlet(Indices::pressureIdx); } // coupling interface - else if (couplingInterface_.isCoupledEntity(faceId)) { - assert(dataIdsWereSet_); - + else if (couplingParticipant_.isCoupledEntity(faceId)) { values.setDirichlet(Indices::velocityYIdx); values.setBeaversJoseph(Indices::momentumXBalanceIdx); } else { @@ -223,13 +218,15 @@ public: PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const { + precice::string_view meshNameView_ = std::string("FreeFlowMesh"); + precice::string_view dataNameView_ = std::string("Velocity"); PrimaryVariables values(0.0); values = initialAtPos(scvf.center()); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { values[Indices::velocityYIdx] = - couplingInterface_.getScalarQuantityOnFace(velocityId_, faceId); + couplingParticipant_.getScalarQuantityOnFace(meshNameView_, dataNameView_, faceId); } return values; @@ -251,11 +248,12 @@ public: const ElementFaceVariables &elemFaceVars, const SubControlVolumeFace &scvf) const { + precice::string_view meshNameView_ = std::string("FreeFlowMesh"); + precice::string_view dataNameView_ = std::string("Pressure"); NumEqVector values(0.0); - assert(dataIdsWereSet_); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { const Scalar density = 1000; // TODO how to handle compressible fluids? values[Indices::conti0EqIdx] = density * @@ -263,7 +261,8 @@ public: scvf.directionSign(); values[Indices::momentumYBalanceIdx] = scvf.directionSign() * - (couplingInterface_.getScalarQuantityOnFace(pressureId_, + (couplingParticipant_.getScalarQuantityOnFace(meshNameView_, + dataNameView_, faceId) - initialAtPos(scvf.center())[Indices::pressureIdx]); } @@ -363,13 +362,6 @@ public: return analyticalVelocityX_; } - void updatePreciceDataIds() - { - pressureId_ = couplingInterface_.getIdFromName("Pressure"); - velocityId_ = couplingInterface_.getIdFromName("Velocity"); - dataIdsWereSet_ = true; - } - // \} private: @@ -396,10 +388,7 @@ private: Scalar eps_; Scalar deltaP_; - Dumux::Precice::CouplingAdapter &couplingInterface_; - size_t pressureId_; - size_t velocityId_; - bool dataIdsWereSet_; + Dumux::Precice::CouplingAdapter &couplingParticipant_; mutable std::vector analyticalVelocityX_; }; diff --git a/examples/ff-pm/flow-over-square-2d/main_ff.cc b/examples/ff-pm/flow-over-square-2d/main_ff.cc index 849e631..51fb12f 100644 --- a/examples/ff-pm/flow-over-square-2d/main_ff.cc +++ b/examples/ff-pm/flow-over-square-2d/main_ff.cc @@ -91,7 +91,9 @@ template void setInterfacePressures(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const precice::string_view meshNameView, + const precice::string_view dataNameView) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); @@ -99,8 +101,7 @@ void setInterfacePressures(const Problem &problem, auto elemFaceVars = localView(gridVars.curGridFaceVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto pressureId = couplingInterface.getIdFromName("Pressure"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bind(element); @@ -109,12 +110,13 @@ void setInterfacePressures(const Problem &problem, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const auto p = pressureAtInterface( problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(pressureId, + couplingParticipant.writeScalarQuantityOnFace(meshNameView, + dataNameView, scvf.index(), p); } } @@ -124,15 +126,16 @@ void setInterfacePressures(const Problem &problem, template void setInterfaceVelocities(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const precice::string_view meshNameView, + const precice::string_view dataNameView) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFaceVars = localView(gridVars.curGridFaceVars()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto velocityId = couplingInterface.getIdFromName("Velocity"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bindElement(element); @@ -140,11 +143,11 @@ void setInterfaceVelocities(const Problem &problem, elemFaceVars.bindElement(element, fvGeometry, sol); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const auto v = velocityAtInterface(elemFaceVars, scvf)[scvf.directionIndex()]; - couplingInterface.writeScalarQuantityOnFace(velocityId, + couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, scvf.index(), v); } } @@ -204,22 +207,23 @@ try { // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - //couplingInterface.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); + //couplingParticipant.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); std::string preciceConfigFilename = "precice-config.xml"; // if (argc == 3) // preciceConfigFilename = argv[2]; if (argc > 2) preciceConfigFilename = argv[argc - 1]; - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver("FreeFlow", preciceConfigFilename, + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver("FreeFlow", preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - const int dim = couplingInterface.getDimensions(); + const precice::string_view meshNameView = std::string("FreeFlowMesh"); + const int dim = couplingParticipant.getMeshDimensions(meshNameView); // mesh name std::cout << dim << " " << int(FreeFlowGridGeometry::GridView::dimension) << std::endl; if (dim != int(FreeFlowGridGeometry::GridView::dimension)) - DUNE_THROW(Dune::InvalidStateException, "Dimensions do not match"); + DUNE_THROW(Dune::InvalidStateException, "Dimensions do not match"); // GET mesh corodinates const double xMin = @@ -228,6 +232,7 @@ try { getParamFromGroup>("Darcy", "Grid.UpperRight")[0]; std::vector coords; //( dim * vertexSize ); std::vector coupledScvfIndices; + precice::span coordsSpan(coords); for (const auto &element : elements(freeFlowGridView)) { auto fvGeometry = localView(*freeFlowGridGeometry); @@ -247,16 +252,14 @@ try { } const auto numberOfPoints = coords.size() / dim; - const double preciceDt = couplingInterface.setMeshAndInitialize( - "FreeFlowMesh", numberOfPoints, coords); - couplingInterface.createIndexMapping(coupledScvfIndices); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); + couplingParticipant.setMesh(meshNameView, coordsSpan); + couplingParticipant.createIndexMapping(coupledScvfIndices); - const auto velocityId = - couplingInterface.announceScalarQuantity("Velocity"); - const auto pressureId = - couplingInterface.announceScalarQuantity("Pressure"); - - freeFlowProblem->updatePreciceDataIds(); + const precice::string_view dataNameViewV = std::string("Velocity"); + const precice::string_view dataNameViewP = std::string("Pressure"); + couplingParticipant.announceQuantity(meshNameView, dataNameViewV); + couplingParticipant.announceQuantity(meshNameView, dataNameViewP); // apply initial solution for instationary problems freeFlowProblem->applyInitialSolution(sol); @@ -280,13 +283,12 @@ try { using FluxVariables = GetPropType; - if (couplingInterface.hasToWriteInitialData()) { + if (couplingParticipant.hasToWriteInitialData()) { setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol); - couplingInterface.writeScalarQuantityToOtherSolver(pressureId); - couplingInterface.announceInitialDataWritten(); + *freeFlowGridVariables, sol, meshNameView, dataNameViewP); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); } - couplingInterface.initializeData(); + couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = @@ -308,31 +310,31 @@ try { double vtkTime = 1.0; size_t iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.hasToWriteIterationCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; - couplingInterface.announceIterationCheckpointWritten(); } - couplingInterface.readScalarQuantityFromOtherSolver(velocityId); + couplingParticipant.readQuantityFromOtherSolver(meshNameView, dataNameViewV, dt); // solve the non-linear system nonLinearSolver.solve(sol); // TODO setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol); - couplingInterface.writeScalarQuantityToOtherSolver(pressureId); + *freeFlowGridVariables, sol, meshNameView, dataNameViewP); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); //Read checkpoint freeFlowVtkWriter.write(vtkTime); vtkTime += 1.; - const double preciceDt = couplingInterface.advance(dt); + couplingParticipant.advance(dt); + preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); ++iter; - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.hasToReadIterationCheckpoint()) { // //Read checkpoint // freeFlowVtkWriter.write(vtkTime); // vtkTime += 1.; @@ -340,7 +342,6 @@ try { freeFlowGridVariables->update(sol); freeFlowGridVariables->advanceTimeStep(); //freeFlowGridVariables->init(sol); - couplingInterface.announceIterationCheckpointRead(); } else // coupling successful { // write vtk output @@ -351,7 +352,7 @@ try { // finalize, print dumux message to say goodbye //////////////////////////////////////////////////////////// - couplingInterface.finalize(); + couplingParticipant.finalize(); // print dumux end message if (mpiHelper.rank() == 0) { diff --git a/examples/ff-pm/flow-over-square-2d/main_pm.cc b/examples/ff-pm/flow-over-square-2d/main_pm.cc index 415111b..7f87548 100644 --- a/examples/ff-pm/flow-over-square-2d/main_pm.cc +++ b/examples/ff-pm/flow-over-square-2d/main_pm.cc @@ -107,15 +107,16 @@ auto pressureAtInterface(const Problem &problem, template void setInterfacePressures(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const precice::string_view meshNameView, + const precice::string_view dataNameView) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto pressureId = couplingInterface.getIdFromName("Pressure"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bindElement(element); @@ -123,12 +124,12 @@ void setInterfacePressures(const Problem &problem, //sstd::cout << "Pressure by reconstruction" << std::endl; for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const double p = pressureAtInterface(problem, element, gridGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(pressureId, + couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, scvf.index(), p); } } @@ -170,15 +171,16 @@ template void setInterfaceVelocities(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const precice::string_view meshNameView, + const precice::string_view dataNameView) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto velocityId = couplingInterface.getIdFromName("Velocity"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bind(element); @@ -186,12 +188,12 @@ void setInterfaceVelocities(const Problem &problem, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const double v = velocityAtInterface( problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(velocityId, + couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, scvf.index(), v); } } @@ -243,18 +245,19 @@ try { // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - //couplingInterface.createInstance( "darcy", mpiHelper.rank(), mpiHelper.size() ); + //couplingParticipant.createInstance( "darcy", mpiHelper.rank(), mpiHelper.size() ); std::string preciceConfigFilename = "precice-config.xml"; // if (argc == 3) // preciceConfigFilename = argv[2]; if (argc > 2) preciceConfigFilename = argv[argc - 1]; - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver("Darcy", preciceConfigFilename, + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver("Darcy", preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - const int dim = couplingInterface.getDimensions(); + const precice::string_view meshNameView = std::string("DarcyMesh"); + const int dim = couplingParticipant.getMeshDimensions(meshNameView); std::cout << dim << " " << int(DarcyGridGeometry::GridView::dimension) << std::endl; if (dim != int(DarcyGridGeometry::GridView::dimension)) @@ -267,6 +270,7 @@ try { getParamFromGroup>("Darcy", "Grid.UpperRight")[0]; std::vector coords; //( dim * vertexSize ); std::vector coupledScvfIndices; + precice::span coordsSpan(coords); for (const auto &element : elements(darcyGridView)) { auto fvGeometry = localView(*darcyGridGeometry); @@ -286,16 +290,14 @@ try { } const auto numberOfPoints = coords.size() / dim; - const double preciceDt = couplingInterface.setMeshAndInitialize( - "DarcyMesh", numberOfPoints, coords); - couplingInterface.createIndexMapping(coupledScvfIndices); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); + couplingParticipant.setMesh(meshNameView, coordsSpan); + couplingParticipant.createIndexMapping(coupledScvfIndices); - const auto velocityId = - couplingInterface.announceScalarQuantity("Velocity"); - const auto pressureId = - couplingInterface.announceScalarQuantity("Pressure"); - - darcyProblem->updatePreciceDataIds(); + const precice::string_view dataNameViewV = std::string("Velocity"); + const precice::string_view dataNameViewP = std::string("Pressure"); + couplingParticipant.announceQuantity(meshNameView, dataNameViewP); + couplingParticipant.announceQuantity(meshNameView, dataNameViewV); darcyProblem->applyInitialSolution(sol); @@ -322,25 +324,14 @@ try { darcyVtkWriter.write(0.0); using FluxVariables = GetPropType; - if (couplingInterface.hasToWriteInitialData()) { + if (couplingParticipant.hasToWriteInitialData()) { //TODO setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol); - // For testing - // { - // const auto v = couplingInterface.getQuantityVector(velocityId); - // std::cout << "velocities to be sent to ff" << std::endl; - // for (size_t i = 0; i < v.size(); ++i) { - // for (size_t d = 0; d < dim; ++d) { - // std::cout << coords[i * dim + d] << " "; - // } - // std::cout << "| v[" << i << "]=" << v[i] << std::endl; - // } - // } - couplingInterface.writeScalarQuantityToOtherSolver(velocityId); - couplingInterface.announceInitialDataWritten(); + *darcyGridVariables, sol, meshNameView, dataNameViewV); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); } - couplingInterface.initializeData(); + couplingParticipant.setMeshAndInitialize( + "DarcyMesh", numberOfPoints, coords);// couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = FVAssembler; @@ -361,35 +352,33 @@ try { double vtkTime = 1.0; size_t iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.hasToWriteIterationCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; - couplingInterface.announceIterationCheckpointWritten(); } - couplingInterface.readScalarQuantityFromOtherSolver(pressureId); + couplingParticipant.readQuantityFromOtherSolver(meshNameView, dataNameViewP); // solve the non-linear system nonLinearSolver.solve(sol); setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol); - couplingInterface.writeScalarQuantityToOtherSolver(velocityId); + *darcyGridVariables, sol, meshNameView, dataNameViewV); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); - const double preciceDt = couplingInterface.advance(dt); + couplingParticipant.advance(dt); + preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); ++iter; - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.hasToReadIterationCheckpoint()) { //Read checkpoint darcyVtkWriter.write(vtkTime); vtkTime += 1.; sol = sol_checkpoint; darcyGridVariables->update(sol); darcyGridVariables->advanceTimeStep(); - //darcyGridVariables->init(sol); - couplingInterface.announceIterationCheckpointRead(); } else // coupling successful { // write vtk output @@ -399,7 +388,7 @@ try { // write vtk output darcyVtkWriter.write(1.0); - couplingInterface.finalize(); + couplingParticipant.finalize(); //////////////////////////////////////////////////////////// // finalize, print dumux message to say goodbye diff --git a/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh b/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh index 81775b5..27793b1 100644 --- a/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh +++ b/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh @@ -122,10 +122,7 @@ public: DarcySubProblem(std::shared_ptr fvGridGeometry) : ParentType(fvGridGeometry, "Darcy"), eps_(1e-7), - couplingInterface_(Dumux::Precice::CouplingAdapter::getInstance()), - pressureId_(0), - velocityId_(0), - dataIdsWereSet_(false) + couplingParticipant_(Dumux::Precice::CouplingAdapter::getInstance()) { } @@ -167,7 +164,7 @@ public: values.setAllNeumann(); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) + if (couplingParticipant_.isCoupledEntity(faceId)) values.setAllDirichlet(); return values; } @@ -183,15 +180,17 @@ public: PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const { + precice::string_view meshNameView_ = std::string("DarcyMesh"); + precice::string_view dataNameView_ = std::string("Pressure"); // set p = 0 at the bottom PrimaryVariables values(0.0); values = initial(element); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { values = - couplingInterface_.getScalarQuantityOnFace(pressureId_, faceId); - //std::cout << "Pressure on face " << faceId << " is " << couplingInterface_.getScalarQuantityOnFace(pressureId_, faceId) << std::endl; + couplingParticipant_.getScalarQuantityOnFace(meshNameView_, dataNameView_, faceId); + //std::cout << "Pressure on face " << faceId << " is " << couplingParticipant_.getScalarQuantityOnFace(pressureId_, faceId) << std::endl; } return values; @@ -262,13 +261,6 @@ public: // \} - void updatePreciceDataIds() - { - pressureId_ = couplingInterface_.getIdFromName("Pressure"); - velocityId_ = couplingInterface_.getIdFromName("Velocity"); - dataIdsWereSet_ = true; - } - private: bool onLeftBoundary_(const GlobalPosition &globalPos) const { @@ -292,10 +284,7 @@ private: Scalar eps_; - Dumux::Precice::CouplingAdapter &couplingInterface_; - size_t pressureId_; - size_t velocityId_; - bool dataIdsWereSet_; + Dumux::Precice::CouplingAdapter &couplingParticipant_; }; } // namespace Dumux diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml b/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml index d72d2ad..3cfee2e 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml @@ -6,79 +6,77 @@ - - - + + - - - - + + + + - - - - + + + + - - - + + + - - + + - - + + - + - - + + - - - + + + - + - - - - + + + + - - - + + + - - + + - - + + - + - + - - - - - - - - - + + + + + + + + + - - + diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml index ad4fa10..df69b45 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml @@ -6,78 +6,76 @@ - - - + + - - - - + + + + - - - - + + + + - - - + + + - - + + - - + + - + - - + + - - - + + + - + - - - - + + + + - - - + + + - - + + - - + + - + - + - - - - - - - - + + + + + + + + - - + diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml index 6e325f9..6ed1aa9 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml @@ -6,78 +6,75 @@ - + + - - + + + + - - - - + + + + - - - - + + + - - - + + - - + + - - + - + + - - + + + - - - + - + + + + - - - - + + + - - - + + - - + + - - + - + - + + + + + + + + - - - - - - - - - - - + From 31a25dfc809697a9abc7650bdf0c427383a1d62d Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Thu, 10 Aug 2023 10:48:33 +0200 Subject: [PATCH 02/16] tweaking on the format --- dumux-precice/couplingadapter.cc | 28 ++++++++++++++-------------- dumux-precice/couplingadapter.hh | 24 ++++++++++++------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/dumux-precice/couplingadapter.cc b/dumux-precice/couplingadapter.cc index 2d2599d..0202e47 100644 --- a/dumux-precice/couplingadapter.cc +++ b/dumux-precice/couplingadapter.cc @@ -24,10 +24,10 @@ CouplingAdapter &CouplingAdapter::getInstance() return instance; } -void CouplingAdapter::announceSolver(const std::string &name, //TODO change string inout to string_like? - const std::string configurationFileName, - const int rank, - const int size) +void CouplingAdapter::announceSolver(const std::string &name, + const std::string configurationFileName, + const int rank, + const int size) { assert(precice_ == nullptr); precice_ = std::make_unique( @@ -56,8 +56,8 @@ int CouplingAdapter::getMeshDimensions(const precice::string_view &meshName) con } -void CouplingAdapter::setMesh(const precice::string_view &meshName, - precice::span positions) +void CouplingAdapter::setMesh(const precice::string_view &meshName, + precice::span positions) { assert(wasCreated_); vertexIDsSpan_ = precice::span(vertexIDs_); @@ -118,7 +118,7 @@ size_t CouplingAdapter::getNumberOfVertices() double CouplingAdapter::getScalarQuantityOnFace(const precice::string_view &meshName, const precice::string_view &dataName, - const int faceID) + const int faceID) { assert(wasCreated_); assert(hasIndexMapper_); @@ -135,8 +135,8 @@ double CouplingAdapter::getScalarQuantityOnFace(const precice::string_view &mesh void CouplingAdapter::writeScalarQuantityOnFace(const precice::string_view &meshName, const precice::string_view &dataName, - const int faceID, - const double value) + const int faceID, + const double value) { assert(wasCreated_); assert(hasIndexMapper_); @@ -161,7 +161,7 @@ std::vector &CouplingAdapter::getQuantityVector(const precice::string_vi void CouplingAdapter::writeQuantityVector(const precice::string_view &meshName, const precice::string_view &dataName, - std::vector &values) + std::vector &values) { std::vector &dataVector = getQuantityVector(meshName, dataName); assert(dataVector.size() == values.size()); @@ -182,9 +182,9 @@ std::string CouplingAdapter::createKeyFromName(const precice::string_view meshNa for (int i = 0; i < (meshName.size() + 1 + dataName.size()); i++) { - if (i < meshName.size()) combinedKey += meshName[i]; - else if (i == meshName.size()) combinedKey += ':'; - else combinedKey += dataName[i - meshName.size()]; + if (i < meshName.size()) combinedKey += meshName[i]; + else if (i == meshName.size()) combinedKey += ':'; + else combinedKey += dataName[i - meshName.size()]; } return combinedKey; @@ -197,7 +197,7 @@ void CouplingAdapter::print(std::ostream &os) void CouplingAdapter::readQuantityFromOtherSolver(const precice::string_view &meshName, const precice::string_view &dataName, - double relativeReadTime) + double relativeReadTime) { precice::span dataValuesSpan(getQuantityVector(meshName,dataName)); precice_->readData(meshName, dataName, vertexIDsSpan_, relativeReadTime, dataValuesSpan); diff --git a/dumux-precice/couplingadapter.hh b/dumux-precice/couplingadapter.hh index 6e856b6..2769767 100644 --- a/dumux-precice/couplingadapter.hh +++ b/dumux-precice/couplingadapter.hh @@ -83,9 +83,9 @@ public: * @param[in] size Total number of processes of the DuMuX solver. */ void announceSolver(const std::string &name, - const std::string configurationFileName, - const int rank, - const int size); + const std::string configurationFileName, + const int rank, + const int size); /*! * @brief Announces a quantity on the coupling interface. * @@ -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 precice::string_view &meshName, + const precice::string_view &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 precice::string_view &meshName) const; /*! * @brief Get the maximum time step size from preCICE * @@ -148,7 +148,7 @@ public: * [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 positions); + precice::span positions); /*! * @brief Initializes the coupling * @@ -203,7 +203,7 @@ public: */ void readQuantityFromOtherSolver(const precice::string_view &meshName, const precice::string_view &dataName, - double relativeReadTime); + double relativeReadTime); /*! * @brief Writes full block of data to preCICE. * @@ -222,7 +222,7 @@ public: */ double getScalarQuantityOnFace(const precice::string_view &meshName, const precice::string_view &dataName, - const int faceID); + const int faceID); /*! * @brief Writes value of scalar quantity on a given finite volume face to data map. * @@ -233,8 +233,8 @@ public: */ void writeScalarQuantityOnFace(const precice::string_view &meshName, const precice::string_view &dataName, - const int faceID, - const double value); + const int faceID, + const double value); /*! * @brief Gets the quantity value vector from the data map according to the mesh and data name. * @@ -253,7 +253,7 @@ public: */ void writeQuantityVector(const precice::string_view &meshName, const precice::string_view &dataName, - std::vector &values); + std::vector &values); /*! * @brief Checks whether face with given identifier is part of coupling interface. * From 6c1bafaf2dc98c2f561ed9a4d247868b733e8e6d Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Thu, 10 Aug 2023 14:52:06 +0200 Subject: [PATCH 03/16] improve formatting --- dumux-precice/couplingadapter.cc | 86 +++++++++++-------- dumux-precice/couplingadapter.hh | 43 +++++----- examples/dummysolver/main_dummysolver.cc | 44 ++++++---- .../precice-dummy-solver-config.xml | 2 +- examples/dummysolver/test.xml | 2 +- .../flow-over-cube-3d/ffproblem-reversed.hh | 8 +- .../flow-over-cube-3d/main_ff-reversed.cc | 38 ++++---- .../flow-over-cube-3d/main_pm-reversed.cc | 38 ++++---- .../flow-over-cube-3d/pmproblem-reversed.hh | 4 +- .../flow-over-square-2d/ffproblem-reversed.hh | 8 +- examples/ff-pm/flow-over-square-2d/main_ff.cc | 31 ++++--- examples/ff-pm/flow-over-square-2d/main_pm.cc | 28 +++--- .../flow-over-square-2d/pmproblem-reversed.hh | 4 +- 13 files changed, 192 insertions(+), 144 deletions(-) diff --git a/dumux-precice/couplingadapter.cc b/dumux-precice/couplingadapter.cc index 0202e47..48e56f0 100644 --- a/dumux-precice/couplingadapter.cc +++ b/dumux-precice/couplingadapter.cc @@ -5,7 +5,6 @@ #include #include - using namespace Dumux::Precice; CouplingAdapter::CouplingAdapter() @@ -24,10 +23,10 @@ CouplingAdapter &CouplingAdapter::getInstance() return instance; } -void CouplingAdapter::announceSolver(const std::string &name, - const std::string configurationFileName, - const int rank, - const int size) +void CouplingAdapter::announceSolver(const std::string &name, + const std::string configurationFileName, + const int rank, + const int size) { assert(precice_ == nullptr); precice_ = std::make_unique( @@ -35,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 precice::string_view &meshName, + const precice::string_view &dataName) { assert(meshWasCreated_); const std::string key = createKeyFromName(meshName, dataName); @@ -49,15 +48,15 @@ void CouplingAdapter::announceQuantity(const precice::string_view &meshN dataMap_.insert(std::make_pair(key, dataValues)); } -int CouplingAdapter::getMeshDimensions(const precice::string_view &meshName) const +int CouplingAdapter::getMeshDimensions( + const precice::string_view &meshName) const { assert(wasCreated_); return precice_->getMeshDimensions(meshName); } - -void CouplingAdapter::setMesh(const precice::string_view &meshName, - precice::span positions) +void CouplingAdapter::setMesh(const precice::string_view &meshName, + precice::span positions) { assert(wasCreated_); vertexIDsSpan_ = precice::span(vertexIDs_); @@ -78,13 +77,14 @@ void CouplingAdapter::initialize() preciceWasInitialized_ = true; assert(preciceWasInitialized_); } - + double CouplingAdapter::getMaxTimeStepSize() { return precice_->getMaxTimeStepSize(); } -void CouplingAdapter::createIndexMapping(const std::vector &dumuxFaceIndices)// TODO what does this do? +void CouplingAdapter::createIndexMapping( + const std::vector &dumuxFaceIndices) // TODO what does this do? { assert(meshWasCreated_); indexMapper_.createMapping(dumuxFaceIndices, vertexIDs_); @@ -116,9 +116,10 @@ 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 precice::string_view &meshName, + const precice::string_view &dataName, + const int faceID) { assert(wasCreated_); assert(hasIndexMapper_); @@ -133,10 +134,11 @@ double CouplingAdapter::getScalarQuantityOnFace(const precice::string_view &mesh 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 precice::string_view &meshName, + const precice::string_view &dataName, + const int faceID, + const double value) { assert(wasCreated_); assert(hasIndexMapper_); @@ -151,8 +153,9 @@ void CouplingAdapter::writeScalarQuantityOnFace(const precice::string_view &mesh dataVector[idx] = value; } -std::vector &CouplingAdapter::getQuantityVector(const precice::string_view &meshName, - const precice::string_view &dataName) +std::vector &CouplingAdapter::getQuantityVector( + const precice::string_view &meshName, + const precice::string_view &dataName) { std::string key = createKeyFromName(meshName, dataName); assert(dataMap_.find(key) != dataMap_.end()); @@ -161,7 +164,7 @@ std::vector &CouplingAdapter::getQuantityVector(const precice::string_vi void CouplingAdapter::writeQuantityVector(const precice::string_view &meshName, const precice::string_view &dataName, - std::vector &values) + std::vector &values) { std::vector &dataVector = getQuantityVector(meshName, dataName); assert(dataVector.size() == values.size()); @@ -174,17 +177,20 @@ bool CouplingAdapter::isCoupledEntity(const int faceID) const return indexMapper_.isDumuxIdMapped(faceID); } -std::string CouplingAdapter::createKeyFromName(const precice::string_view meshName, - const precice::string_view dataName) const +std::string CouplingAdapter::createKeyFromName( + const precice::string_view meshName, + const precice::string_view dataName) const { assert(wasCreated_); std::string combinedKey; - for (int i = 0; i < (meshName.size() + 1 + dataName.size()); i++) - { - if (i < meshName.size()) combinedKey += meshName[i]; - else if (i == meshName.size()) combinedKey += ':'; - else combinedKey += dataName[i - meshName.size()]; + for (int i = 0; i < (meshName.size() + 1 + dataName.size()); i++) { + if (i < meshName.size()) + combinedKey += meshName[i]; + else if (i == meshName.size()) + combinedKey += ':'; + else + combinedKey += dataName[i - meshName.size()]; } return combinedKey; @@ -195,18 +201,22 @@ 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 precice::string_view &meshName, + const precice::string_view &dataName, + double relativeReadTime) { - precice::span dataValuesSpan(getQuantityVector(meshName,dataName)); - precice_->readData(meshName, dataName, vertexIDsSpan_, relativeReadTime, dataValuesSpan); + precice::span 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 precice::string_view &meshName, + const precice::string_view &dataName) { - precice::span dataValuesSpan(getQuantityVector(meshName,dataName)); + precice::span dataValuesSpan( + getQuantityVector(meshName, dataName)); precice_->writeData(meshName, dataName, vertexIDsSpan_, dataValuesSpan); } diff --git a/dumux-precice/couplingadapter.hh b/dumux-precice/couplingadapter.hh index 2769767..e8adfd7 100644 --- a/dumux-precice/couplingadapter.hh +++ b/dumux-precice/couplingadapter.hh @@ -83,9 +83,9 @@ public: * @param[in] size Total number of processes of the DuMuX solver. */ void announceSolver(const std::string &name, - const std::string configurationFileName, - const int rank, - const int size); + const std::string configurationFileName, + const int rank, + const int size); /*! * @brief Announces a quantity on the coupling interface. * @@ -133,7 +133,7 @@ public: * @return false No further action is needed. */ bool hasToWriteInitialData(); - + /*! * @brief Adds mesh for coupling of solvers. * @@ -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 positions); + void setMesh(const precice::string_view &meshName, + precice::span positions); /*! * @brief Initializes the coupling * @@ -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, - double relativeReadTime); + void readQuantityFromOtherSolver(const precice::string_view &meshName, + const precice::string_view &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 precice::string_view &meshName, + const precice::string_view &dataName); /*! * @brief Gets value of a scalar quantity on a finite volume face. * @@ -220,9 +220,9 @@ 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, - const int faceID); + double getScalarQuantityOnFace(const precice::string_view &meshName, + const precice::string_view &dataName, + const int faceID); /*! * @brief Writes value of scalar quantity on a given finite volume face to data map. * @@ -233,8 +233,8 @@ public: */ void writeScalarQuantityOnFace(const precice::string_view &meshName, const precice::string_view &dataName, - const int faceID, - const double value); + const int faceID, + const double value); /*! * @brief Gets the quantity value vector from the data map according to the mesh and data name. * @@ -242,8 +242,9 @@ public: * @param[in] dataName Name of the data. * @return The value vector of the quantity. */ - std::vector &getQuantityVector(const precice::string_view &meshName, - const precice::string_view &dataName); + std::vector &getQuantityVector( + const precice::string_view &meshName, + const precice::string_view &dataName); /*! * @brief Writes the quantity value vector into the data map. * @@ -251,10 +252,10 @@ public: * @param[in] dataName Name of the data. * @param[in] values Value of the scalar or vector quantity. */ - void writeQuantityVector(const precice::string_view &meshName, + void writeQuantityVector(const precice::string_view &meshName, const precice::string_view &dataName, - std::vector &values); - /*! + std::vector &values); + /*! * @brief Checks whether face with given identifier is part of coupling interface. * * @param[in] faceID Identifier of the face according to DuMuX' numbering. diff --git a/examples/dummysolver/main_dummysolver.cc b/examples/dummysolver/main_dummysolver.cc index 12f9e74..352a26d 100644 --- a/examples/dummysolver/main_dummysolver.cc +++ b/examples/dummysolver/main_dummysolver.cc @@ -46,7 +46,7 @@ try { auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); couplingParticipant.announceSolver(solverName, preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + mpiHelper.rank(), mpiHelper.size()); std::cout << "DUMMY (" << mpiHelper.rank() << "): Running solver dummy with preCICE config file \"" @@ -55,10 +55,14 @@ try { const int dimensions = couplingParticipant.getMeshDimensions(meshNameView); 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 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 int numberOfVertices = 3; @@ -67,7 +71,7 @@ try { std::vector writeVectorData(numberOfVertices * dimensions); std::vector readVectorData(numberOfVertices * dimensions); - std::vector vertices(numberOfVertices * dimensions); // coordinates + std::vector vertices(numberOfVertices * dimensions); // coordinates std::vector dumuxVertexIDs(numberOfVertices); for (int i = 0; i < numberOfVertices; i++) { @@ -103,10 +107,14 @@ try { std::cout << "DUMMY (" << mpiHelper.rank() << "): Writing initial data\n"; - couplingParticipant.writeQuantityVector(meshNameView, scalarDataWriteName, writeScalarData); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, scalarDataWriteName); - couplingParticipant.writeQuantityVector(meshNameView, vectorDataWriteName, writeVectorData); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, vectorDataWriteName); + couplingParticipant.writeQuantityVector( + meshNameView, scalarDataWriteName, writeScalarData); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + scalarDataWriteName); + couplingParticipant.writeQuantityVector( + meshNameView, vectorDataWriteName, writeVectorData); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + vectorDataWriteName); } std::cout << "DUMMY (" << mpiHelper.rank() << "): Exchange initial\n"; couplingParticipant.initialize(); @@ -135,7 +143,7 @@ try { std::cout << "\n"; for (int i = 0; i < numberOfVertices; i++) { - if (readScalarQuantity.at(i) != writeScalarData.at(i)) { + if (readScalarQuantity.at(i) != writeScalarData.at(i)) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading initialized SCALAR data error\n" << "Index: " << i << ", Expected " @@ -145,7 +153,7 @@ try { } for (int j = 0; j < dimensions; j++) { - if (readVectorQuantity.at(j + dimensions * i)!= + if (readVectorQuantity.at(j + dimensions * i) != writeVectorData.at(j + dimensions * i)) { std::cout << "DUMMY (" << mpiHelper.rank() @@ -178,7 +186,7 @@ try { // Check data if (iter > 0) { int offset = (solverName == "SolverOne") ? 0 : 1; - + const std::vector &readScalarQuantity = readScalarData; const std::vector &readVectorQuantity = readVectorData; @@ -228,12 +236,14 @@ try { couplingParticipant.writeScalarQuantityOnFace( meshNameView, scalarDataWriteName, dumuxVertexIDs[i], value); } - couplingParticipant.writeQuantityToOtherSolver( - meshNameView, scalarDataWriteName); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + scalarDataWriteName); // Write vector data - couplingParticipant.writeQuantityVector(meshNameView, vectorDataWriteName, writeVectorData); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, vectorDataWriteName); + couplingParticipant.writeQuantityVector( + meshNameView, vectorDataWriteName, writeVectorData); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + vectorDataWriteName); couplingParticipant.advance(preciceDt); diff --git a/examples/dummysolver/precice-dummy-solver-config.xml b/examples/dummysolver/precice-dummy-solver-config.xml index dd65dca..fe5c354 100644 --- a/examples/dummysolver/precice-dummy-solver-config.xml +++ b/examples/dummysolver/precice-dummy-solver-config.xml @@ -19,7 +19,7 @@ - + diff --git a/examples/dummysolver/test.xml b/examples/dummysolver/test.xml index 4f53212..4416a93 100644 --- a/examples/dummysolver/test.xml +++ b/examples/dummysolver/test.xml @@ -36,7 +36,7 @@ - + diff --git a/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh b/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh index b8e05be..78e541a 100644 --- a/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh +++ b/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh @@ -235,7 +235,8 @@ public: const auto faceId = scvf.index(); if (couplingParticipant_.isCoupledEntity(faceId)) { values[Indices::velocityYIdx] = - couplingParticipant_.getScalarQuantityOnFace(meshNameView_, dataNameView_, faceId); + couplingParticipant_.getScalarQuantityOnFace( + meshNameView_, dataNameView_, faceId); } return values; @@ -270,9 +271,8 @@ public: scvf.directionSign(); values[Indices::momentumYBalanceIdx] = scvf.directionSign() * - (couplingParticipant_.getScalarQuantityOnFace(meshNameView, - dataNameView, - faceId) - + (couplingParticipant_.getScalarQuantityOnFace( + meshNameView, dataNameView, faceId) - initialAtPos(scvf.center())[Indices::pressureIdx]); } return values; diff --git a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc index dd97c81..3f294ab 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc @@ -113,9 +113,8 @@ void setInterfacePressures(const Problem &problem, const auto p = pressureAtInterface( problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, elemFluxVarsCache); - couplingParticipant.writeScalarQuantityOnFace(meshNameView, - dataNameView, - scvf.index(), p); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, dataNameView, scvf.index(), p); } } } @@ -145,8 +144,8 @@ void setInterfaceVelocities(const Problem &problem, //TODO: What to do here? const auto v = velocityAtInterface(elemFaceVars, scvf)[scvf.directionIndex()]; - couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, - scvf.index(), v); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, dataNameView, scvf.index(), v); } } } @@ -187,7 +186,9 @@ std::tuple writeVelocitiesOnInterfaceToFile( for (const auto &scvf : scvfs(fvGeometry)) { if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingParticipant.getMeshDimensions(meshNameView); ++i) { + for (int i = 0; + i < couplingParticipant.getMeshDimensions(meshNameView); + ++i) { ofs << pos[i] << ","; } const double v = problem.dirichlet(element, scvf)[1]; @@ -244,7 +245,9 @@ void writePressuresOnInterfaceToFile(const precice::string_view &meshNameView, for (const auto &scvf : scvfs(fvGeometry)) { if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingParticipant.getMeshDimensions(meshNameView); ++i) { + for (int i = 0; + i < couplingParticipant.getMeshDimensions(meshNameView); + ++i) { ofs << pos[i] << ","; } const double p = pressureAtInterface( @@ -256,7 +259,7 @@ void writePressuresOnInterfaceToFile(const precice::string_view &meshNameView, } ofs.close(); -} +} int main(int argc, char **argv) try { @@ -320,14 +323,14 @@ try { auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); couplingParticipant.announceSolver("FreeFlow", preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + mpiHelper.rank(), mpiHelper.size()); const precice::string_view meshNameView = std::string("FreeFlowMesh"); const int dim = couplingParticipant.getMeshDimensions(meshNameView); std::cout << dim << " " << int(FreeFlowGridGeometry::GridView::dimension) << std::endl; if (dim != int(FreeFlowGridGeometry::GridView::dimension)) - DUNE_THROW(Dune::InvalidStateException, "Dimensions do not match"); + DUNE_THROW(Dune::InvalidStateException, "Dimensions do not match"); // GET mesh corodinates const double xMin = @@ -392,8 +395,10 @@ try { // couplingParticipant.writeQuantityVector( pressureId ); setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol, meshNameView, dataNameViewP); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); + *freeFlowGridVariables, sol, + meshNameView, dataNameViewP); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + dataNameViewP); } couplingParticipant.initialize(); @@ -424,7 +429,8 @@ try { } // TODO - couplingParticipant.readQuantityFromOtherSolver(meshNameView, dataNameViewV, dt); + couplingParticipant.readQuantityFromOtherSolver(meshNameView, + dataNameViewV, dt); // // For testing // { // const auto v = couplingParticipant.getQuantityVector( velocityId ); @@ -437,8 +443,10 @@ try { // TODO setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol, meshNameView, dataNameViewP); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); + *freeFlowGridVariables, sol, + meshNameView, dataNameViewP); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + dataNameViewP); //Read checkpoint freeFlowVtkWriter.write(vtkTime); diff --git a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc index d4ed1f2..4379347 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc @@ -127,8 +127,8 @@ void setInterfacePressures(const Problem &problem, const double p = pressureAtInterface(problem, element, gridGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, - scvf.index(), p); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, dataNameView, scvf.index(), p); } } } @@ -191,8 +191,8 @@ void setInterfaceVelocities(const Problem &problem, const double v = velocityAtInterface( problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, - scvf.index(), v); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, dataNameView, scvf.index(), v); } } } @@ -236,7 +236,8 @@ std::tuple writeVelocitiesOnInterfaceToFile( for (const auto &scvf : scvfs(fvGeometry)) { if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingParticipant.getMeshDimensions(meshName); ++i) { + for (int i = 0; + i < couplingParticipant.getMeshDimensions(meshName); ++i) { ofs << pos[i] << ","; } const double v = velocityAtInterface( @@ -256,7 +257,7 @@ std::tuple writeVelocitiesOnInterfaceToFile( ofs.close(); return std::make_tuple(min, max, sum); -} +} template void writePressuresOnInterfaceToFile(const precice::string_view &meshName, @@ -288,7 +289,8 @@ void writePressuresOnInterfaceToFile(const precice::string_view &meshName, for (const auto &scvf : scvfs(fvGeometry)) { if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingParticipant.getMeshDimensions(meshName); ++i) { + for (int i = 0; + i < couplingParticipant.getMeshDimensions(meshName); ++i) { ofs << pos[i] << ","; } const double p = @@ -356,7 +358,7 @@ try { auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); couplingParticipant.announceSolver("Darcy", preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + mpiHelper.rank(), mpiHelper.size()); const precice::string_view meshNameView = std::string("DarcyMesh"); const int dim = couplingParticipant.getMeshDimensions(meshNameView); @@ -429,11 +431,14 @@ try { if (couplingParticipant.hasToWriteInitialData()) { //TODO setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol, meshNameView, dataNameViewV); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); + *darcyGridVariables, sol, + meshNameView, dataNameViewV); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + dataNameViewV); } couplingParticipant.setMeshAndInitialize( - "DarcyMesh", numberOfPoints, coords);// couplingParticipant.initialize(); + "DarcyMesh", numberOfPoints, + coords); // couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = FVAssembler; @@ -460,12 +465,14 @@ try { sol_checkpoint = sol; } - couplingParticipant.readQuantityFromOtherSolver(meshNameView, dataNameViewP); - + couplingParticipant.readQuantityFromOtherSolver(meshNameView, + dataNameViewP); + // solve the non-linear system nonLinearSolver.solve(sol); setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol, meshNameView, dataNameViewV); + *darcyGridVariables, sol, + meshNameView, dataNameViewV); // For testing { const auto v = couplingParticipant.getQuantityVector(velocityId); @@ -484,7 +491,8 @@ try { std::cout << "Sum of velocities over boundary to ff: \n" << sum << std::endl; } - couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + dataNameViewV); couplingParticipant.advance(dt); preciceDt = couplingParticipant.getMaxTimeStepSize(); diff --git a/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh b/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh index f40d6d7..5384cc7 100644 --- a/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh +++ b/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh @@ -189,8 +189,8 @@ public: const auto faceId = scvf.index(); if (couplingParticipant_.isCoupledEntity(faceId)) - values = - couplingParticipant_.getScalarQuantityOnFace(meshNameView_, dataNameView_, faceId); + values = couplingParticipant_.getScalarQuantityOnFace( + meshNameView_, dataNameView_, faceId); return values; } diff --git a/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh b/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh index 7227a8f..6fd979c 100644 --- a/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh +++ b/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh @@ -226,7 +226,8 @@ public: const auto faceId = scvf.index(); if (couplingParticipant_.isCoupledEntity(faceId)) { values[Indices::velocityYIdx] = - couplingParticipant_.getScalarQuantityOnFace(meshNameView_, dataNameView_, faceId); + couplingParticipant_.getScalarQuantityOnFace( + meshNameView_, dataNameView_, faceId); } return values; @@ -261,9 +262,8 @@ public: scvf.directionSign(); values[Indices::momentumYBalanceIdx] = scvf.directionSign() * - (couplingParticipant_.getScalarQuantityOnFace(meshNameView_, - dataNameView_, - faceId) - + (couplingParticipant_.getScalarQuantityOnFace( + meshNameView_, dataNameView_, faceId) - initialAtPos(scvf.center())[Indices::pressureIdx]); } return values; diff --git a/examples/ff-pm/flow-over-square-2d/main_ff.cc b/examples/ff-pm/flow-over-square-2d/main_ff.cc index 51fb12f..8f18400 100644 --- a/examples/ff-pm/flow-over-square-2d/main_ff.cc +++ b/examples/ff-pm/flow-over-square-2d/main_ff.cc @@ -115,9 +115,8 @@ void setInterfacePressures(const Problem &problem, const auto p = pressureAtInterface( problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, elemFluxVarsCache); - couplingParticipant.writeScalarQuantityOnFace(meshNameView, - dataNameView, - scvf.index(), p); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, dataNameView, scvf.index(), p); } } } @@ -147,8 +146,8 @@ void setInterfaceVelocities(const Problem &problem, //TODO: What to do here? const auto v = velocityAtInterface(elemFaceVars, scvf)[scvf.directionIndex()]; - couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, - scvf.index(), v); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, dataNameView, scvf.index(), v); } } } @@ -216,14 +215,15 @@ try { auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); couplingParticipant.announceSolver("FreeFlow", preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + mpiHelper.rank(), mpiHelper.size()); const precice::string_view meshNameView = std::string("FreeFlowMesh"); - const int dim = couplingParticipant.getMeshDimensions(meshNameView); // mesh name + const int dim = + couplingParticipant.getMeshDimensions(meshNameView); // mesh name std::cout << dim << " " << int(FreeFlowGridGeometry::GridView::dimension) << std::endl; if (dim != int(FreeFlowGridGeometry::GridView::dimension)) - DUNE_THROW(Dune::InvalidStateException, "Dimensions do not match"); + DUNE_THROW(Dune::InvalidStateException, "Dimensions do not match"); // GET mesh corodinates const double xMin = @@ -285,8 +285,10 @@ try { if (couplingParticipant.hasToWriteInitialData()) { setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol, meshNameView, dataNameViewP); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); + *freeFlowGridVariables, sol, + meshNameView, dataNameViewP); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + dataNameViewP); } couplingParticipant.initialize(); @@ -316,14 +318,17 @@ try { sol_checkpoint = sol; } - couplingParticipant.readQuantityFromOtherSolver(meshNameView, dataNameViewV, dt); + couplingParticipant.readQuantityFromOtherSolver(meshNameView, + dataNameViewV, dt); // solve the non-linear system nonLinearSolver.solve(sol); // TODO setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol, meshNameView, dataNameViewP); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); + *freeFlowGridVariables, sol, + meshNameView, dataNameViewP); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + dataNameViewP); //Read checkpoint freeFlowVtkWriter.write(vtkTime); diff --git a/examples/ff-pm/flow-over-square-2d/main_pm.cc b/examples/ff-pm/flow-over-square-2d/main_pm.cc index 7f87548..a39e973 100644 --- a/examples/ff-pm/flow-over-square-2d/main_pm.cc +++ b/examples/ff-pm/flow-over-square-2d/main_pm.cc @@ -129,8 +129,8 @@ void setInterfacePressures(const Problem &problem, const double p = pressureAtInterface(problem, element, gridGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, - scvf.index(), p); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, dataNameView, scvf.index(), p); } } } @@ -193,8 +193,8 @@ void setInterfaceVelocities(const Problem &problem, const double v = velocityAtInterface( problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingParticipant.writeScalarQuantityOnFace(meshNameView, dataNameView, - scvf.index(), v); + couplingParticipant.writeScalarQuantityOnFace( + meshNameView, dataNameView, scvf.index(), v); } } } @@ -254,7 +254,7 @@ try { auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); couplingParticipant.announceSolver("Darcy", preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + mpiHelper.rank(), mpiHelper.size()); const precice::string_view meshNameView = std::string("DarcyMesh"); const int dim = couplingParticipant.getMeshDimensions(meshNameView); @@ -327,11 +327,14 @@ try { if (couplingParticipant.hasToWriteInitialData()) { //TODO setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol, meshNameView, dataNameViewV); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); + *darcyGridVariables, sol, + meshNameView, dataNameViewV); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + dataNameViewV); } couplingParticipant.setMeshAndInitialize( - "DarcyMesh", numberOfPoints, coords);// couplingParticipant.initialize(); + "DarcyMesh", numberOfPoints, + coords); // couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = FVAssembler; @@ -358,13 +361,16 @@ try { sol_checkpoint = sol; } - couplingParticipant.readQuantityFromOtherSolver(meshNameView, dataNameViewP); + couplingParticipant.readQuantityFromOtherSolver(meshNameView, + dataNameViewP); // solve the non-linear system nonLinearSolver.solve(sol); setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol, meshNameView, dataNameViewV); - couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); + *darcyGridVariables, sol, + meshNameView, dataNameViewV); + couplingParticipant.writeQuantityToOtherSolver(meshNameView, + dataNameViewV); couplingParticipant.advance(dt); preciceDt = couplingParticipant.getMaxTimeStepSize(); diff --git a/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh b/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh index 27793b1..2d0b535 100644 --- a/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh +++ b/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh @@ -188,8 +188,8 @@ public: const auto faceId = scvf.index(); if (couplingParticipant_.isCoupledEntity(faceId)) { - values = - couplingParticipant_.getScalarQuantityOnFace(meshNameView_, dataNameView_, faceId); + values = couplingParticipant_.getScalarQuantityOnFace( + meshNameView_, dataNameView_, faceId); //std::cout << "Pressure on face " << faceId << " is " << couplingParticipant_.getScalarQuantityOnFace(pressureId_, faceId) << std::endl; } From 814043b2fb023e77605c8e47572ba189faa48849 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Thu, 10 Aug 2023 14:57:13 +0200 Subject: [PATCH 04/16] Add related item in changelog --- CHANGELOG.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fac7c03..9a08511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ## v1.0.0 +- 2023-08-10: Updated the adapter to align with preCICE V3. Updated the examples accordingly. - 2022-09-14: The solver dummy has been cleaned up. - 2022-09-14: Updated CI to use containers from `precice` namespace on DockerHub. Also makes sure that `dune-precice` containers are build for tests against DuMuX's master branch. - 2022-09-14: Updated and fixed GitHub to build Docker containers. @@ -41,12 +42,13 @@ - 2022-01-25: Added [description templates](https://docs.gitlab.com/ee/user/project/description_templates.html) for merge requests and issues. - 2022-01-12: The repository has been restructured. The main changes are: - - The adapter is now called `CouplingAdapter` and resides in `dumux-precice/`. The build process has been adapted accordingly. - - Tests case reside in `test/` directory and there in the corresponding subdirectory depending on whether it is a `monolithic`ly or `partitioned`ly coupled test case. - - Other example cases reside in the directory `examples/`. This is mainly the directory called `appl/` before, but with a new folder structure. - - The configuration of tests has been changed such that it is possible to build all tests using the `build_tests` target. + - The adapter is now called `CouplingAdapter` and resides in `dumux-precice/`. The build process has been adapted accordingly. + - Tests case reside in `test/` directory and there in the corresponding subdirectory depending on whether it is a `monolithic`ly or `partitioned`ly coupled test case. + - Other example cases reside in the directory `examples/`. This is mainly the directory called `appl/` before, but with a new folder structure. + - The configuration of tests has been changed such that it is possible to build all tests using the `build_tests` target. For details check out the merge request [!18 Restructure repository and tests](https://git.iws.uni-stuttgart.de/dumux-appl/dumux-precice/-/merge_requests/18) + - 2022-01-10: Add license file. The code is licensed under GPLv3 without template exception. - 2022-01-10: Tests run by the CI on DuMuX `master` are allowed to fail. - 2022-01-10: Added `CHANGELOG.md` to track changes of the adapter. From c859512da0ee357efb82d16e47cd07dd45c790f7 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Fri, 11 Aug 2023 09:43:53 +0200 Subject: [PATCH 05/16] Change the required preCICE version from 2.0.0 to 3.0.0 --- doc/user/docs/installation.md | 74 +++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/doc/user/docs/installation.md b/doc/user/docs/installation.md index 3450a8f..27bfe34 100644 --- a/doc/user/docs/installation.md +++ b/doc/user/docs/installation.md @@ -6,12 +6,12 @@ The DuMuX-preCICE adapter is a DUNE module named `dumux-precice` which can be bu - DuMuX **newer** than 3.2 - - Builds using the current `master` branch of DuMuX might fail. - - If you run into trouble with a new DuMuX release, please open an issue in the repository and add the error message that you receive. + - Builds using the current `master` branch of DuMuX might fail. + - If you run into trouble with a new DuMuX release, please open an issue in the repository and add the error message that you receive. -- preCICE >=2.0.0 +- preCICE >=3.0.0 - - The adapter is build via the DUNE build system that is based on CMake. Thus, the CMake [link instructions for preCICE](https://precice.org/installation-linking.html#cmake) apply. + - The adapter is build via the DUNE build system that is based on CMake. Thus, the CMake [link instructions for preCICE](https://precice.org/installation-linking.html#cmake) apply. - `wget` or `git` to download the DuMuX-preCICE adapter. - Optional: [`dune-subgrid`](https://www.dune-project.org/modules/dune-subgrid/) allows for modified grid geometries. @@ -22,63 +22,63 @@ The DuMuX-preCICE adapter should build fine if DuMuX, preCICE and their dependen 1. Install [DuMuX](https://dumux.org/) and the needed dependencies. The easiest way is to follow [DuMuX's installation instructions](https://dumux.org/installation/). The DuMuX project provides a script that installs and DuMuX and the DUNE modules required by DuMuX. This means, after installing DuMuX via the provided script you should be good to go to use the DuMuX-preCICE adapter. - After the installation you should have a root directory that contains the base DUNE modules, i.e. a number of directories named like `dune-common`, `dune-geometry` etc., and a directory called `dumux`. + After the installation you should have a root directory that contains the base DUNE modules, i.e. a number of directories named like `dune-common`, `dune-geometry` etc., and a directory called `dumux`. - - Note that extended features of DuMuX or the DuMuX-preCICE adapter may need additional DUNE modules. + - Note that extended features of DuMuX or the DuMuX-preCICE adapter may need additional DUNE modules. 2. Download the DuMuX-preCICE adapter to the same directory as the DUNE modules and the `dumux` folder. At the moment there are no adapter releases, besides an outdated `v0.1` release, such the best way is to checkout the `develop` branch of the adapter. - ```text - git clone -b develop https://github.com/precice/dumux-adapter.git - ``` + ```text + git clone -b develop https://github.com/precice/dumux-adapter.git + ``` - You can also try to clone the repository via SSH: + You can also try to clone the repository via SSH: - ```text - git clone -b develop git@github.com:precice/dumux-adapter.git - ``` + ```text + git clone -b develop git@github.com:precice/dumux-adapter.git + ``` 3. Verify that the `dumux-precice` folder is in the same directory as the DUNE module folders and the `dumux` folder. 4. Build and configure the adapter using `dunecontrol`. While being in the directory mentioned in the previous step via calling - ```text - dunecontrol --only=dumux-precice all - ``` + ```text + dunecontrol --only=dumux-precice all + ``` - After the build and configure step a new directory `build-cmake` was created inside the `dumux-precice` directory. + After the build and configure step a new directory `build-cmake` was created inside the `dumux-precice` directory. - You can configure the build and configuration process using advanced options by manipulating CMake variables. `dunecontrol` allows to pass an options file for that + You can configure the build and configuration process using advanced options by manipulating CMake variables. `dunecontrol` allows to pass an options file for that - ```bash - dunecontrol --opts=OPTSFILE.opts --only=dumux-precice all - ``` + ```bash + dunecontrol --opts=OPTSFILE.opts --only=dumux-precice all + ``` - There is an `opts`-file provided by the adapter that resides in `test/`. You can use it as + There is an `opts`-file provided by the adapter that resides in `test/`. You can use it as - ```bash - dunecontrol --opts=dumux-precice/test/cmake-test.opts --only=dumux-precice all - ``` + ```bash + dunecontrol --opts=dumux-precice/test/cmake-test.opts --only=dumux-precice all + ``` - This provided `cmake-test.opts` file turns off some system-dependent optimizations such that the tests create comparable results on different computers. + This provided `cmake-test.opts` file turns off some system-dependent optimizations such that the tests create comparable results on different computers. - For more ways do manipulate/adapt the build and configuration step, please consult the `dunecontrol` documentation. + For more ways do manipulate/adapt the build and configuration step, please consult the `dunecontrol` documentation. 5. Optional, but recommended: Build all tests to verify the installation. For this navigate in the `build-cmake/` directory and build the `build_tests` target. - ```bash - cd dumux-precice/build-cmake - make -j1 build_tests - ``` + ```bash + cd dumux-precice/build-cmake + make -j1 build_tests + ``` - You may speed up the build process by using more than one build job, e.g., use `make -j4` in order to build with for processes at the same time. + You may speed up the build process by using more than one build job, e.g., use `make -j4` in order to build with for processes at the same time. - Afterwards you can run the tests from the `build-cmake` directory using + Afterwards you can run the tests from the `build-cmake` directory using - ```bash - ctest - ``` + ```bash + ctest + ``` - If any tests fails, you should verify if something went wrong with the installation. + If any tests fails, you should verify if something went wrong with the installation. There are advanced ways of managing DUNE modules, e.g. using the environment variable `DUNE_CONTROL_PATH`, that are beyond the scope of this short documentation. You can find more information in the [DUNE FAQ](https://www.dune-project.org/doc/installation/#faq). From bc6f86ea10f6218a6169f7c8ba00e4035ee80ac8 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Fri, 11 Aug 2023 09:56:09 +0200 Subject: [PATCH 06/16] Tweak the formatting of markdown file --- doc/user/docs/installation.md | 72 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/doc/user/docs/installation.md b/doc/user/docs/installation.md index 27bfe34..ffd7e27 100644 --- a/doc/user/docs/installation.md +++ b/doc/user/docs/installation.md @@ -6,12 +6,12 @@ The DuMuX-preCICE adapter is a DUNE module named `dumux-precice` which can be bu - DuMuX **newer** than 3.2 - - Builds using the current `master` branch of DuMuX might fail. - - If you run into trouble with a new DuMuX release, please open an issue in the repository and add the error message that you receive. + - Builds using the current `master` branch of DuMuX might fail. + - If you run into trouble with a new DuMuX release, please open an issue in the repository and add the error message that you receive. - preCICE >=3.0.0 - - The adapter is build via the DUNE build system that is based on CMake. Thus, the CMake [link instructions for preCICE](https://precice.org/installation-linking.html#cmake) apply. + - The adapter is build via the DUNE build system that is based on CMake. Thus, the CMake [link instructions for preCICE](https://precice.org/installation-linking.html#cmake) apply. - `wget` or `git` to download the DuMuX-preCICE adapter. - Optional: [`dune-subgrid`](https://www.dune-project.org/modules/dune-subgrid/) allows for modified grid geometries. @@ -22,63 +22,63 @@ The DuMuX-preCICE adapter should build fine if DuMuX, preCICE and their dependen 1. Install [DuMuX](https://dumux.org/) and the needed dependencies. The easiest way is to follow [DuMuX's installation instructions](https://dumux.org/installation/). The DuMuX project provides a script that installs and DuMuX and the DUNE modules required by DuMuX. This means, after installing DuMuX via the provided script you should be good to go to use the DuMuX-preCICE adapter. - After the installation you should have a root directory that contains the base DUNE modules, i.e. a number of directories named like `dune-common`, `dune-geometry` etc., and a directory called `dumux`. + After the installation you should have a root directory that contains the base DUNE modules, i.e. a number of directories named like `dune-common`, `dune-geometry` etc., and a directory called `dumux`. - - Note that extended features of DuMuX or the DuMuX-preCICE adapter may need additional DUNE modules. + - Note that extended features of DuMuX or the DuMuX-preCICE adapter may need additional DUNE modules. 2. Download the DuMuX-preCICE adapter to the same directory as the DUNE modules and the `dumux` folder. At the moment there are no adapter releases, besides an outdated `v0.1` release, such the best way is to checkout the `develop` branch of the adapter. - ```text - git clone -b develop https://github.com/precice/dumux-adapter.git - ``` + ```text + git clone -b develop https://github.com/precice/dumux-adapter.git + ``` - You can also try to clone the repository via SSH: + You can also try to clone the repository via SSH: - ```text - git clone -b develop git@github.com:precice/dumux-adapter.git - ``` + ```text + git clone -b develop git@github.com:precice/dumux-adapter.git + ``` 3. Verify that the `dumux-precice` folder is in the same directory as the DUNE module folders and the `dumux` folder. 4. Build and configure the adapter using `dunecontrol`. While being in the directory mentioned in the previous step via calling - ```text - dunecontrol --only=dumux-precice all - ``` + ```text + dunecontrol --only=dumux-precice all + ``` - After the build and configure step a new directory `build-cmake` was created inside the `dumux-precice` directory. + After the build and configure step a new directory `build-cmake` was created inside the `dumux-precice` directory. - You can configure the build and configuration process using advanced options by manipulating CMake variables. `dunecontrol` allows to pass an options file for that + You can configure the build and configuration process using advanced options by manipulating CMake variables. `dunecontrol` allows to pass an options file for that - ```bash - dunecontrol --opts=OPTSFILE.opts --only=dumux-precice all - ``` + ```bash + dunecontrol --opts=OPTSFILE.opts --only=dumux-precice all + ``` - There is an `opts`-file provided by the adapter that resides in `test/`. You can use it as + There is an `opts`-file provided by the adapter that resides in `test/`. You can use it as - ```bash - dunecontrol --opts=dumux-precice/test/cmake-test.opts --only=dumux-precice all - ``` + ```bash + dunecontrol --opts=dumux-precice/test/cmake-test.opts --only=dumux-precice all + ``` - This provided `cmake-test.opts` file turns off some system-dependent optimizations such that the tests create comparable results on different computers. + This provided `cmake-test.opts` file turns off some system-dependent optimizations such that the tests create comparable results on different computers. - For more ways do manipulate/adapt the build and configuration step, please consult the `dunecontrol` documentation. + For more ways do manipulate/adapt the build and configuration step, please consult the `dunecontrol` documentation. 5. Optional, but recommended: Build all tests to verify the installation. For this navigate in the `build-cmake/` directory and build the `build_tests` target. - ```bash - cd dumux-precice/build-cmake - make -j1 build_tests - ``` + ```bash + cd dumux-precice/build-cmake + make -j1 build_tests + ``` - You may speed up the build process by using more than one build job, e.g., use `make -j4` in order to build with for processes at the same time. + You may speed up the build process by using more than one build job, e.g., use `make -j4` in order to build with for processes at the same time. - Afterwards you can run the tests from the `build-cmake` directory using + Afterwards you can run the tests from the `build-cmake` directory using - ```bash - ctest - ``` + ```bash + ctest + ``` - If any tests fails, you should verify if something went wrong with the installation. + If any tests fails, you should verify if something went wrong with the installation. There are advanced ways of managing DUNE modules, e.g. using the environment variable `DUNE_CONTROL_PATH`, that are beyond the scope of this short documentation. You can find more information in the [DUNE FAQ](https://www.dune-project.org/doc/installation/#faq). From 8d6b2d838f9c42cc95c405abe47b7b4c21ef6925 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Fri, 11 Aug 2023 10:08:06 +0200 Subject: [PATCH 07/16] Modify the indentation in changelog --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a08511..13c2e82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,10 +42,10 @@ - 2022-01-25: Added [description templates](https://docs.gitlab.com/ee/user/project/description_templates.html) for merge requests and issues. - 2022-01-12: The repository has been restructured. The main changes are: - - The adapter is now called `CouplingAdapter` and resides in `dumux-precice/`. The build process has been adapted accordingly. - - Tests case reside in `test/` directory and there in the corresponding subdirectory depending on whether it is a `monolithic`ly or `partitioned`ly coupled test case. - - Other example cases reside in the directory `examples/`. This is mainly the directory called `appl/` before, but with a new folder structure. - - The configuration of tests has been changed such that it is possible to build all tests using the `build_tests` target. + - The adapter is now called `CouplingAdapter` and resides in `dumux-precice/`. The build process has been adapted accordingly. + - Tests case reside in `test/` directory and there in the corresponding subdirectory depending on whether it is a `monolithic`ly or `partitioned`ly coupled test case. + - Other example cases reside in the directory `examples/`. This is mainly the directory called `appl/` before, but with a new folder structure. + - The configuration of tests has been changed such that it is possible to build all tests using the `build_tests` target. For details check out the merge request [!18 Restructure repository and tests](https://git.iws.uni-stuttgart.de/dumux-appl/dumux-precice/-/merge_requests/18) From db5e85cc1cc44159084549b1de100f60edfb3509 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Fri, 11 Aug 2023 10:11:03 +0200 Subject: [PATCH 08/16] Modify the indentation in changelog --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c2e82..861f030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,10 +42,10 @@ - 2022-01-25: Added [description templates](https://docs.gitlab.com/ee/user/project/description_templates.html) for merge requests and issues. - 2022-01-12: The repository has been restructured. The main changes are: - - The adapter is now called `CouplingAdapter` and resides in `dumux-precice/`. The build process has been adapted accordingly. - - Tests case reside in `test/` directory and there in the corresponding subdirectory depending on whether it is a `monolithic`ly or `partitioned`ly coupled test case. - - Other example cases reside in the directory `examples/`. This is mainly the directory called `appl/` before, but with a new folder structure. - - The configuration of tests has been changed such that it is possible to build all tests using the `build_tests` target. + - The adapter is now called `CouplingAdapter` and resides in `dumux-precice/`. The build process has been adapted accordingly. + - Tests case reside in `test/` directory and there in the corresponding subdirectory depending on whether it is a `monolithic`ly or `partitioned`ly coupled test case. + - Other example cases reside in the directory `examples/`. This is mainly the directory called `appl/` before, but with a new folder structure. + - The configuration of tests has been changed such that it is possible to build all tests using the `build_tests` target. For details check out the merge request [!18 Restructure repository and tests](https://git.iws.uni-stuttgart.de/dumux-appl/dumux-precice/-/merge_requests/18) From 3ee5bfb462e0320c4e88162f7cd09dfae41e41e3 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Mon, 14 Aug 2023 11:15:41 +0200 Subject: [PATCH 09/16] Modify the passed parameter to get rid of change to mesh- and dataName --- dumux-precice/couplingadapter.cc | 6 +++--- dumux-precice/couplingadapter.hh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dumux-precice/couplingadapter.cc b/dumux-precice/couplingadapter.cc index 48e56f0..5db6bdf 100644 --- a/dumux-precice/couplingadapter.cc +++ b/dumux-precice/couplingadapter.cc @@ -24,7 +24,7 @@ CouplingAdapter &CouplingAdapter::getInstance() } void CouplingAdapter::announceSolver(const std::string &name, - const std::string configurationFileName, + const std::string &configurationFileName, const int rank, const int size) { @@ -178,8 +178,8 @@ bool CouplingAdapter::isCoupledEntity(const int faceID) const } std::string CouplingAdapter::createKeyFromName( - const precice::string_view meshName, - const precice::string_view dataName) const + const precice::string_view &meshName, + const precice::string_view &dataName) const { assert(wasCreated_); std::string combinedKey; diff --git a/dumux-precice/couplingadapter.hh b/dumux-precice/couplingadapter.hh index e8adfd7..c005c50 100644 --- a/dumux-precice/couplingadapter.hh +++ b/dumux-precice/couplingadapter.hh @@ -83,7 +83,7 @@ public: * @param[in] size Total number of processes of the DuMuX solver. */ void announceSolver(const std::string &name, - const std::string configurationFileName, + const std::string &configurationFileName, const int rank, const int size); /*! @@ -270,8 +270,8 @@ public: * @param[in] dataName Name of the quantity. * @return size_t Numeric identifier of quantity. */ - std::string createKeyFromName(const precice::string_view meshName, - const precice::string_view dataName) const; + std::string createKeyFromName(const precice::string_view &meshName, + const precice::string_view &dataName) const; /*! * @brief Prints status of coupling adapter to given output stream. * From 7e315bb13a1dbafbf3a3c6264efb5a4a2cbd784d Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Wed, 16 Aug 2023 12:51:42 +0200 Subject: [PATCH 10/16] Modify the examples and an error in the adapter itself --- CMakeLists.txt | 2 +- dumux-precice/couplingadapter.cc | 15 ++++---- dumux-precice/couplingadapter.hh | 2 +- examples/dummysolver/main_dummysolver.cc | 24 ++++++++----- .../precice-dummy-solver-config.xml | 12 +++---- examples/dummysolver/test.xml | 8 ++--- .../flow-over-cube-3d/ffproblem-reversed.hh | 18 +++------- .../flow-over-cube-3d/main_ff-reversed.cc | 25 +++++-------- .../flow-over-cube-3d/main_pm-reversed.cc | 36 +++++-------------- .../flow-over-cube-3d/pmproblem-reversed.hh | 13 ++----- .../flow-over-cube-3d/precice-config.xml | 8 ++--- .../flow-over-square-2d/ffproblem-reversed.hh | 8 ++--- examples/ff-pm/flow-over-square-2d/main_ff.cc | 14 ++++---- examples/ff-pm/flow-over-square-2d/main_pm.cc | 16 ++++----- .../flow-over-square-2d/pmproblem-reversed.hh | 8 ++--- .../flow-over-square-2d/precice-config-pi.xml | 8 ++--- .../precice-config-si-free-flow-first.xml | 10 +++--- .../precice-config-si-free-flow-second.xml | 10 +++--- 18 files changed, 91 insertions(+), 146 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 304b007..bf9d28f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ endif() #find dune-common and set the module path find_package(dune-common REQUIRED) # Find preCICE library -find_package(precice 3 REQUIRED CONFIG) +find_package(precice 3.0.0 REQUIRED CONFIG) list(APPEND CMAKE_MODULE_PATH ${dune-common_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules") diff --git a/dumux-precice/couplingadapter.cc b/dumux-precice/couplingadapter.cc index 5db6bdf..489714a 100644 --- a/dumux-precice/couplingadapter.cc +++ b/dumux-precice/couplingadapter.cc @@ -59,6 +59,8 @@ void CouplingAdapter::setMesh(const precice::string_view &meshName, precice::span positions) { assert(wasCreated_); + vertexIDs_ = + std::vector(positions.size() / getMeshDimensions(meshName)); vertexIDsSpan_ = precice::span(vertexIDs_); precice_->setMeshVertices(meshName, positions, vertexIDsSpan_); meshWasCreated_ = true; @@ -78,13 +80,13 @@ void CouplingAdapter::initialize() assert(preciceWasInitialized_); } -double CouplingAdapter::getMaxTimeStepSize() +double CouplingAdapter::getMaxTimeStepSize() const { return precice_->getMaxTimeStepSize(); } void CouplingAdapter::createIndexMapping( - const std::vector &dumuxFaceIndices) // TODO what does this do? + const std::vector &dumuxFaceIndices) { assert(meshWasCreated_); indexMapper_.createMapping(dumuxFaceIndices, vertexIDs_); @@ -183,16 +185,15 @@ std::string CouplingAdapter::createKeyFromName( { assert(wasCreated_); std::string combinedKey; - - for (int i = 0; i < (meshName.size() + 1 + dataName.size()); i++) { + int length = meshName.size() + 1 + dataName.size(); + for (int i = 0; i < length; i++) { if (i < meshName.size()) combinedKey += meshName[i]; else if (i == meshName.size()) - combinedKey += ':'; + combinedKey += ":"; else - combinedKey += dataName[i - meshName.size()]; + combinedKey += dataName[i - meshName.size() - 1]; } - return combinedKey; } diff --git a/dumux-precice/couplingadapter.hh b/dumux-precice/couplingadapter.hh index c005c50..d05f001 100644 --- a/dumux-precice/couplingadapter.hh +++ b/dumux-precice/couplingadapter.hh @@ -109,7 +109,7 @@ public: * * @return double time step size */ - double getMaxTimeStepSize(); + double getMaxTimeStepSize() const; /*! * @brief Checks if simulation checkpoint needs to be restored. * diff --git a/examples/dummysolver/main_dummysolver.cc b/examples/dummysolver/main_dummysolver.cc index 352a26d..afbe4b0 100644 --- a/examples/dummysolver/main_dummysolver.cc +++ b/examples/dummysolver/main_dummysolver.cc @@ -42,12 +42,11 @@ try { getParamFromGroup("preCICE", "ConfigFileName"); const std::string meshName = getParamFromGroup("preCICE", "MeshName"); - precice::string_view meshNameView(meshName); + const precice::string_view meshNameView(meshName); auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); couplingParticipant.announceSolver(solverName, preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - std::cout << "DUMMY (" << mpiHelper.rank() << "): Running solver dummy with preCICE config file \"" << preciceConfigFilename << "\", participant name \"" @@ -92,7 +91,6 @@ try { std::cout << "DUMMY (" << mpiHelper.rank() << "): Initialize preCICE and set mesh\n"; couplingParticipant.setMesh(meshNameView, vertices); - double preciceDt = couplingParticipant.getMaxTimeStepSize(); // Create index mapping between DuMuX's index numbering and preCICE's numbering std::cout << "DUMMY (" << mpiHelper.rank() << "): Create index mapping\n"; @@ -106,7 +104,6 @@ try { if (couplingParticipant.hasToWriteInitialData()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Writing initial data\n"; - couplingParticipant.writeQuantityVector( meshNameView, scalarDataWriteName, writeScalarData); couplingParticipant.writeQuantityToOtherSolver(meshNameView, @@ -118,6 +115,7 @@ try { } std::cout << "DUMMY (" << mpiHelper.rank() << "): Exchange initial\n"; couplingParticipant.initialize(); + double preciceDt = 0; // Check exchanged initial data if (solverName == "SolverOne") { @@ -128,14 +126,18 @@ try { couplingParticipant.readQuantityFromOtherSolver( meshNameView, vectorDataReadName, preciceDt); - const std::vector &readScalarQuantity = readScalarData; + const std::vector &readScalarQuantity = + couplingParticipant.getQuantityVector(meshNameView, + scalarDataReadName); std::cout << "DUMMY (" << mpiHelper.rank() << "): Scalar data\n"; for (const double &value : readScalarQuantity) std::cout << value << ","; std::cout << "\n"; - const std::vector &readVectorQuantity = readVectorData; + const std::vector &readVectorQuantity = + couplingParticipant.getQuantityVector(meshNameView, + vectorDataReadName); std::cout << "DUMMY (" << mpiHelper.rank() << "): Vector data\n"; for (const double &value : readVectorQuantity) @@ -187,8 +189,12 @@ try { if (iter > 0) { int offset = (solverName == "SolverOne") ? 0 : 1; - const std::vector &readScalarQuantity = readScalarData; - const std::vector &readVectorQuantity = readVectorData; + const std::vector &readScalarQuantity = + couplingParticipant.getQuantityVector(meshNameView, + scalarDataReadName); + const std::vector &readVectorQuantity = + couplingParticipant.getQuantityVector(meshNameView, + vectorDataReadName); for (int i = 0; i < numberOfVertices; i++) { if (readScalarQuantity.at(i) != @@ -244,7 +250,7 @@ try { meshNameView, vectorDataWriteName, writeVectorData); couplingParticipant.writeQuantityToOtherSolver(meshNameView, vectorDataWriteName); - + preciceDt = couplingParticipant.getMaxTimeStepSize(); couplingParticipant.advance(preciceDt); if (couplingParticipant.hasToReadIterationCheckpoint()) { diff --git a/examples/dummysolver/precice-dummy-solver-config.xml b/examples/dummysolver/precice-dummy-solver-config.xml index fe5c354..52e5c97 100644 --- a/examples/dummysolver/precice-dummy-solver-config.xml +++ b/examples/dummysolver/precice-dummy-solver-config.xml @@ -1,11 +1,10 @@ - + - @@ -19,7 +18,7 @@ - + @@ -29,7 +28,7 @@ - + @@ -38,8 +37,8 @@ - - + + @@ -66,5 +65,4 @@ - diff --git a/examples/dummysolver/test.xml b/examples/dummysolver/test.xml index 4416a93..106fae0 100644 --- a/examples/dummysolver/test.xml +++ b/examples/dummysolver/test.xml @@ -6,7 +6,6 @@ - @@ -21,14 +20,14 @@ - + - - + + @@ -46,5 +45,4 @@ - diff --git a/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh b/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh index 78e541a..e27412b 100644 --- a/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh +++ b/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh @@ -141,8 +141,6 @@ public: { deltaP_ = getParamFromGroup(this->paramGroup(), "Problem.PressureDifference"); - // pressureId_ = couplingParticipant_.getIdFromName( "Pressure" ); - // velocityId_ = couplingParticipant_.getIdFromName( "Velocity" ); } /*! @@ -200,13 +198,7 @@ public: } // coupling interface else if (couplingParticipant_.isCoupledEntity(faceId)) { - //TODO What do I want to do here? - // values.setCouplingNeumann(Indices::conti0EqIdx); - // values.setCouplingNeumann(Indices::momentumYBalanceIdx); values.setDirichlet(Indices::velocityYIdx); - - // values.setNeumann(Indices::conti0EqIdx); - // values.setNeumann(Indices::momentumYBalanceIdx); values.setBeaversJoseph(Indices::momentumXBalanceIdx); values.setBeaversJoseph(Indices::momentumZBalanceIdx); } else { @@ -227,8 +219,8 @@ public: PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const { - precice::string_view meshNameView_ = std::string("FreeFlowMesh"); - precice::string_view dataNameView_ = std::string("Velocity"); + precice::string_view meshNameView_("FreeFlowMesh", 12); + precice::string_view dataNameView_("Velocity", 8); PrimaryVariables values(0.0); values = initialAtPos(scvf.center()); @@ -258,8 +250,8 @@ public: const ElementFaceVariables &elemFaceVars, const SubControlVolumeFace &scvf) const { - precice::string_view meshNameView = std::string("FreeFlowMesh"); - precice::string_view dataNameView = std::string("Pressure"); + precice::string_view meshNameView_("FreeFlowMesh", 12); + precice::string_view dataNameView_("Pressure", 8); NumEqVector values(0.0); const auto faceId = scvf.index(); @@ -272,7 +264,7 @@ public: values[Indices::momentumYBalanceIdx] = scvf.directionSign() * (couplingParticipant_.getScalarQuantityOnFace( - meshNameView, dataNameView, faceId) - + meshNameView_, dataNameView_, faceId) - initialAtPos(scvf.center())[Indices::pressureIdx]); } return values; diff --git a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc index 3f294ab..12a2b9e 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc @@ -47,6 +47,8 @@ #include "ffproblem-reversed.hh" +#include "dumux-precice/couplingadapter.hh" + //TODO // Helper function to put pressure on interface @@ -325,7 +327,7 @@ try { couplingParticipant.announceSolver("FreeFlow", preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - const precice::string_view meshNameView = std::string("FreeFlowMesh"); + const precice::string_view meshNameView("FreeFlowMesh", 12); const int dim = couplingParticipant.getMeshDimensions(meshNameView); std::cout << dim << " " << int(FreeFlowGridGeometry::GridView::dimension) << std::endl; @@ -339,7 +341,6 @@ try { getParamFromGroup>("Darcy", "Grid.UpperRight")[0]; std::vector coords; //( dim * vertexSize ); std::vector coupledScvfIndices; - precice::span coordsSpan(coords); for (const auto &element : elements(freeFlowGridView)) { auto fvGeometry = localView(*freeFlowGridGeometry); @@ -359,12 +360,12 @@ try { } const auto numberOfPoints = coords.size() / dim; - double preciceDt = couplingParticipant.getMaxTimeStepSize(); + precice::span coordsSpan(coords); couplingParticipant.setMesh(meshNameView, coordsSpan); couplingParticipant.createIndexMapping(coupledScvfIndices); - const precice::string_view dataNameViewV = std::string("Velocity"); - const precice::string_view dataNameViewP = std::string("Pressure"); + const precice::string_view dataNameViewV("Velocity", 8); + const precice::string_view dataNameViewP("Pressure", 8); couplingParticipant.announceQuantity(meshNameView, dataNameViewV); couplingParticipant.announceQuantity(meshNameView, dataNameViewP); @@ -391,9 +392,6 @@ try { GetPropType; if (couplingParticipant.hasToWriteInitialData()) { - //TODO - // couplingParticipant.writeQuantityVector( pressureId ); - setInterfacePressures(*freeFlowProblem, *freeFlowGridVariables, sol, meshNameView, dataNameViewP); @@ -416,6 +414,7 @@ try { using NewtonSolver = NewtonSolver; NewtonSolver nonLinearSolver(assembler, linearSolver); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); auto dt = preciceDt; auto sol_checkpoint = sol; @@ -428,16 +427,8 @@ try { sol_checkpoint = sol; } - // TODO couplingParticipant.readQuantityFromOtherSolver(meshNameView, dataNameViewV, dt); - // // For testing - // { - // const auto v = couplingParticipant.getQuantityVector( velocityId ); - // const double sum = std::accumulate( v.begin(), v.end(), 0. ); - // std::cout << "Sum of velocities over boundary to pm: \n" << sum << std::endl; - // } - // solve the non-linear system nonLinearSolver.solve(sol); @@ -447,10 +438,10 @@ try { meshNameView, dataNameViewP); couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); - //Read checkpoint freeFlowVtkWriter.write(vtkTime); vtkTime += 1.; + couplingParticipant.advance(dt); preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); diff --git a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc index 4379347..cb9e9ad 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc @@ -55,6 +55,8 @@ bool printstuff = false; #include "pmproblem-reversed.hh" +#include "dumux-precice/couplingadapter.hh" + /*! * \brief Returns the pressure at the interface using Darcy's law for reconstruction */ @@ -360,7 +362,7 @@ try { couplingParticipant.announceSolver("Darcy", preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - const precice::string_view meshNameView = std::string("DarcyMesh"); + const precice::string_view meshNameView("DarcyMesh", 9); const int dim = couplingParticipant.getMeshDimensions(meshNameView); std::cout << dim << " " << int(DarcyGridGeometry::GridView::dimension) << std::endl; @@ -374,7 +376,6 @@ try { getParamFromGroup>("Darcy", "Grid.UpperRight")[0]; std::vector coords; //( dim * vertexSize ); std::vector coupledScvfIndices; - precice::span coordsSpan(coords); for (const auto &element : elements(darcyGridView)) { auto fvGeometry = localView(*darcyGridGeometry); @@ -394,12 +395,12 @@ try { } const auto numberOfPoints = coords.size() / dim; - double preciceDt = couplingParticipant.getMaxTimeStepSize(); + precice::span coordsSpan(coords); couplingParticipant.setMesh(meshNameView, coordsSpan); couplingParticipant.createIndexMapping(coupledScvfIndices); - const precice::string_view dataNameViewV = std::string("Velocity"); - const precice::string_view dataNameViewP = std::string("Pressure"); + const precice::string_view dataNameViewV("Velocity", 8); + const precice::string_view dataNameViewP("Pressure", 8); couplingParticipant.announceQuantity(meshNameView, dataNameViewP); couplingParticipant.announceQuantity(meshNameView, dataNameViewV); @@ -436,9 +437,7 @@ try { couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); } - couplingParticipant.setMeshAndInitialize( - "DarcyMesh", numberOfPoints, - coords); // couplingParticipant.initialize(); + couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = FVAssembler; @@ -453,6 +452,7 @@ try { using NewtonSolver = Dumux::NewtonSolver; NewtonSolver nonLinearSolver(assembler, linearSolver); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); auto dt = preciceDt; auto sol_checkpoint = sol; @@ -466,31 +466,13 @@ try { } couplingParticipant.readQuantityFromOtherSolver(meshNameView, - dataNameViewP); + dataNameViewP, dt); // solve the non-linear system nonLinearSolver.solve(sol); setInterfaceVelocities(*darcyProblem, *darcyGridVariables, sol, meshNameView, dataNameViewV); - // For testing - { - const auto v = couplingParticipant.getQuantityVector(velocityId); - for (size_t i = 0; i < v.size(); ++i) { - for (size_t d = 0; d < dim; ++d) { - std::cout << coords[i * dim + d] << " "; - } - std::cout << "| v[" << i << "]=" << v[i] << std::endl; - } - - const double sum = std::accumulate(v.begin(), v.end(), 0.); - std::cout << "Velocities to be sent to ff" << std::endl; - // for (size_t i = 0; i < v.size(); ++i) { - // std::cout << "v[" << i << "]=" << v[i] << std::endl; - // } - std::cout << "Sum of velocities over boundary to ff: \n" - << sum << std::endl; - } couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); diff --git a/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh b/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh index 5384cc7..21d1c0b 100644 --- a/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh +++ b/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh @@ -181,8 +181,8 @@ public: PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const { - precice::string_view meshNameView_ = std::string("DarcyMesh"); - precice::string_view dataNameView_ = std::string("Pressure"); + precice::string_view meshNameView_("DarcyMesh", 9); + precice::string_view dataNameView_("Pressure", 8); // set p = 0 at the bottom PrimaryVariables values(0.0); values = initial(element); @@ -214,15 +214,6 @@ public: { // no-flow everywhere ... NumEqVector values(0.0); - - // assert( dataIdsWereSet_ ); - // const auto faceId = scvf.index(); - // if ( couplingParticipant_.isCoupledEntity(faceId) ) - // { - // const Scalar density = 1000.; - // values[Indices::conti0EqIdx] = density * couplingParticipant_.getScalarQuantityOnFace( velocityId_, faceId ); - // std::cout << "pm: values[Indices::conti0EqIdx] = " << values << std::endl; - // } return values; } diff --git a/examples/ff-pm/flow-over-cube-3d/precice-config.xml b/examples/ff-pm/flow-over-cube-3d/precice-config.xml index 4020d7d..d21621d 100644 --- a/examples/ff-pm/flow-over-cube-3d/precice-config.xml +++ b/examples/ff-pm/flow-over-cube-3d/precice-config.xml @@ -21,8 +21,8 @@ - - + + @@ -32,7 +32,7 @@ - + @@ -60,8 +60,6 @@ --> - - diff --git a/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh b/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh index 6fd979c..14540f2 100644 --- a/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh +++ b/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh @@ -218,8 +218,8 @@ public: PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const { - precice::string_view meshNameView_ = std::string("FreeFlowMesh"); - precice::string_view dataNameView_ = std::string("Velocity"); + precice::string_view meshNameView_("FreeFlowMesh", 12); + precice::string_view dataNameView_("Velocity", 8); PrimaryVariables values(0.0); values = initialAtPos(scvf.center()); @@ -249,8 +249,8 @@ public: const ElementFaceVariables &elemFaceVars, const SubControlVolumeFace &scvf) const { - precice::string_view meshNameView_ = std::string("FreeFlowMesh"); - precice::string_view dataNameView_ = std::string("Pressure"); + precice::string_view meshNameView_("FreeFlowMesh", 12); + precice::string_view dataNameView_("Pressure", 8); NumEqVector values(0.0); const auto faceId = scvf.index(); diff --git a/examples/ff-pm/flow-over-square-2d/main_ff.cc b/examples/ff-pm/flow-over-square-2d/main_ff.cc index 8f18400..7db830b 100644 --- a/examples/ff-pm/flow-over-square-2d/main_ff.cc +++ b/examples/ff-pm/flow-over-square-2d/main_ff.cc @@ -217,9 +217,8 @@ try { couplingParticipant.announceSolver("FreeFlow", preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - const precice::string_view meshNameView = std::string("FreeFlowMesh"); - const int dim = - couplingParticipant.getMeshDimensions(meshNameView); // mesh name + const precice::string_view meshNameView("FreeFlowMesh", 12); // mesh name + const int dim = couplingParticipant.getMeshDimensions(meshNameView); std::cout << dim << " " << int(FreeFlowGridGeometry::GridView::dimension) << std::endl; if (dim != int(FreeFlowGridGeometry::GridView::dimension)) @@ -232,7 +231,6 @@ try { getParamFromGroup>("Darcy", "Grid.UpperRight")[0]; std::vector coords; //( dim * vertexSize ); std::vector coupledScvfIndices; - precice::span coordsSpan(coords); for (const auto &element : elements(freeFlowGridView)) { auto fvGeometry = localView(*freeFlowGridGeometry); @@ -252,12 +250,12 @@ try { } const auto numberOfPoints = coords.size() / dim; - double preciceDt = couplingParticipant.getMaxTimeStepSize(); + precice::span coordsSpan(coords); couplingParticipant.setMesh(meshNameView, coordsSpan); couplingParticipant.createIndexMapping(coupledScvfIndices); - const precice::string_view dataNameViewV = std::string("Velocity"); - const precice::string_view dataNameViewP = std::string("Pressure"); + const precice::string_view dataNameViewV("Velocity", 8); + const precice::string_view dataNameViewP("Pressure", 8); couplingParticipant.announceQuantity(meshNameView, dataNameViewV); couplingParticipant.announceQuantity(meshNameView, dataNameViewP); @@ -306,6 +304,7 @@ try { using NewtonSolver = NewtonSolver; NewtonSolver nonLinearSolver(assembler, linearSolver); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); auto dt = preciceDt; auto sol_checkpoint = sol; @@ -329,7 +328,6 @@ try { meshNameView, dataNameViewP); couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewP); - //Read checkpoint freeFlowVtkWriter.write(vtkTime); vtkTime += 1.; diff --git a/examples/ff-pm/flow-over-square-2d/main_pm.cc b/examples/ff-pm/flow-over-square-2d/main_pm.cc index a39e973..6b1148e 100644 --- a/examples/ff-pm/flow-over-square-2d/main_pm.cc +++ b/examples/ff-pm/flow-over-square-2d/main_pm.cc @@ -256,7 +256,7 @@ try { couplingParticipant.announceSolver("Darcy", preciceConfigFilename, mpiHelper.rank(), mpiHelper.size()); - const precice::string_view meshNameView = std::string("DarcyMesh"); + const precice::string_view meshNameView("DarcyMesh", 9); const int dim = couplingParticipant.getMeshDimensions(meshNameView); std::cout << dim << " " << int(DarcyGridGeometry::GridView::dimension) << std::endl; @@ -270,7 +270,6 @@ try { getParamFromGroup>("Darcy", "Grid.UpperRight")[0]; std::vector coords; //( dim * vertexSize ); std::vector coupledScvfIndices; - precice::span coordsSpan(coords); for (const auto &element : elements(darcyGridView)) { auto fvGeometry = localView(*darcyGridGeometry); @@ -290,12 +289,12 @@ try { } const auto numberOfPoints = coords.size() / dim; - double preciceDt = couplingParticipant.getMaxTimeStepSize(); + precice::span coordsSpan(coords); couplingParticipant.setMesh(meshNameView, coordsSpan); couplingParticipant.createIndexMapping(coupledScvfIndices); - const precice::string_view dataNameViewV = std::string("Velocity"); - const precice::string_view dataNameViewP = std::string("Pressure"); + const precice::string_view dataNameViewV("Velocity", 8); + const precice::string_view dataNameViewP("Pressure", 8); couplingParticipant.announceQuantity(meshNameView, dataNameViewP); couplingParticipant.announceQuantity(meshNameView, dataNameViewV); @@ -332,9 +331,7 @@ try { couplingParticipant.writeQuantityToOtherSolver(meshNameView, dataNameViewV); } - couplingParticipant.setMeshAndInitialize( - "DarcyMesh", numberOfPoints, - coords); // couplingParticipant.initialize(); + couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = FVAssembler; @@ -349,6 +346,7 @@ try { using NewtonSolver = Dumux::NewtonSolver; NewtonSolver nonLinearSolver(assembler, linearSolver); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); auto dt = preciceDt; auto sol_checkpoint = sol; @@ -362,7 +360,7 @@ try { } couplingParticipant.readQuantityFromOtherSolver(meshNameView, - dataNameViewP); + dataNameViewP, dt); // solve the non-linear system nonLinearSolver.solve(sol); diff --git a/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh b/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh index 2d0b535..cfc59e0 100644 --- a/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh +++ b/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh @@ -180,18 +180,16 @@ public: PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const { - precice::string_view meshNameView_ = std::string("DarcyMesh"); - precice::string_view dataNameView_ = std::string("Pressure"); + precice::string_view meshNameView_("DarcyMesh", 9); + precice::string_view dataNameView_("Pressure", 8); // set p = 0 at the bottom PrimaryVariables values(0.0); values = initial(element); const auto faceId = scvf.index(); - if (couplingParticipant_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) values = couplingParticipant_.getScalarQuantityOnFace( meshNameView_, dataNameView_, faceId); - //std::cout << "Pressure on face " << faceId << " is " << couplingParticipant_.getScalarQuantityOnFace(pressureId_, faceId) << std::endl; - } return values; } diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml b/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml index 3cfee2e..853e4ae 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml @@ -21,8 +21,8 @@ - - + + @@ -33,7 +33,7 @@ - + @@ -64,8 +64,6 @@ --> - - diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml index df69b45..54197b5 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml @@ -10,7 +10,7 @@ - + @@ -21,8 +21,8 @@ - - + + @@ -33,7 +33,7 @@ - + @@ -64,8 +64,6 @@ --> - - diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml index 6ed1aa9..1d15bd7 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml @@ -9,7 +9,7 @@ - + @@ -20,8 +20,8 @@ - - + + @@ -32,7 +32,7 @@ - + @@ -63,8 +63,6 @@ --> - - From a982fdf4451a8fad6e465d884c57c29d022b05ce Mon Sep 17 00:00:00 2001 From: June <94080048+Fujikawas@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:49:00 +0200 Subject: [PATCH 11/16] Update the required preCICE version CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf9d28f..3bbabec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ endif() #find dune-common and set the module path find_package(dune-common REQUIRED) # Find preCICE library -find_package(precice 3.0.0 REQUIRED CONFIG) +find_package(precice 2 REQUIRED CONFIG) list(APPEND CMAKE_MODULE_PATH ${dune-common_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules") From 521a9d8b8ac84c4d812656df7ad06764653554f2 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Fri, 8 Sep 2023 10:27:07 +0200 Subject: [PATCH 12/16] rename some of the functions --- CHANGELOG.md | 3 ++- dumux-precice/couplingadapter.cc | 14 +++++++------- dumux-precice/couplingadapter.hh | 18 +++++++++--------- examples/dummysolver/main_dummysolver.cc | 6 +++--- .../flow-over-cube-3d/main_ff-reversed.cc | 6 +++--- .../flow-over-cube-3d/main_pm-reversed.cc | 6 +++--- examples/ff-pm/flow-over-square-2d/main_ff.cc | 6 +++--- examples/ff-pm/flow-over-square-2d/main_pm.cc | 6 +++--- 8 files changed, 33 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 861f030..cb7df87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ ## Not released yet +- 2023-08-10: Updated the adapter to align with preCICE V3. Updated the examples accordingly. + ## v1.0.0 -- 2023-08-10: Updated the adapter to align with preCICE V3. Updated the examples accordingly. - 2022-09-14: The solver dummy has been cleaned up. - 2022-09-14: Updated CI to use containers from `precice` namespace on DockerHub. Also makes sure that `dune-precice` containers are build for tests against DuMuX's master branch. - 2022-09-14: Updated and fixed GitHub to build Docker containers. diff --git a/dumux-precice/couplingadapter.cc b/dumux-precice/couplingadapter.cc index 489714a..e2db8c1 100644 --- a/dumux-precice/couplingadapter.cc +++ b/dumux-precice/couplingadapter.cc @@ -38,7 +38,7 @@ void CouplingAdapter::announceQuantity(const precice::string_view &meshName, const precice::string_view &dataName) { assert(meshWasCreated_); - const std::string key = createKeyFromName(meshName, dataName); + const std::string key = meshAndDataKey(meshName, dataName); if (dataMap_.find(key) != dataMap_.end()) { throw(std::runtime_error(" Error! Duplicate quantity announced! ")); } @@ -103,7 +103,7 @@ void CouplingAdapter::finalize() void CouplingAdapter::advance(const double computedTimeStepLength) { assert(wasCreated_); - return precice_->advance(computedTimeStepLength); + precice_->advance(computedTimeStepLength); } bool CouplingAdapter::isCouplingOngoing() @@ -159,7 +159,7 @@ std::vector &CouplingAdapter::getQuantityVector( const precice::string_view &meshName, const precice::string_view &dataName) { - std::string key = createKeyFromName(meshName, dataName); + std::string key = meshAndDataKey(meshName, dataName); assert(dataMap_.find(key) != dataMap_.end()); return dataMap_[key]; } @@ -179,7 +179,7 @@ bool CouplingAdapter::isCoupledEntity(const int faceID) const return indexMapper_.isDumuxIdMapped(faceID); } -std::string CouplingAdapter::createKeyFromName( +std::string CouplingAdapter::meshAndDataKey( const precice::string_view &meshName, const precice::string_view &dataName) const { @@ -221,19 +221,19 @@ void CouplingAdapter::writeQuantityToOtherSolver( precice_->writeData(meshName, dataName, vertexIDsSpan_, dataValuesSpan); } -bool CouplingAdapter::hasToWriteInitialData() +bool CouplingAdapter::requiresToWriteInitialData() { assert(wasCreated_); return precice_->requiresInitialData(); } -bool CouplingAdapter::hasToReadIterationCheckpoint() +bool CouplingAdapter::requiresToReadCheckpoint() { assert(wasCreated_); return precice_->requiresReadingCheckpoint(); } -bool CouplingAdapter::hasToWriteIterationCheckpoint() +bool CouplingAdapter::requiresToWriteCheckpoint() { assert(wasCreated_); return precice_->requiresWritingCheckpoint(); diff --git a/dumux-precice/couplingadapter.hh b/dumux-precice/couplingadapter.hh index d05f001..06c0630 100644 --- a/dumux-precice/couplingadapter.hh +++ b/dumux-precice/couplingadapter.hh @@ -111,34 +111,34 @@ public: */ double getMaxTimeStepSize() const; /*! - * @brief Checks if simulation checkpoint needs to be restored. + * @brief Checks if the participant is required to read an iteration checkpoint. If true, the participant is required to read an iteration checkpoint before calling advance(). * * @return true Simulation checkpoint has to be restored. * @return false No further action is needed. */ - bool hasToReadIterationCheckpoint(); + bool requiresToReadCheckpoint(); /*! - * @brief Checks if simulation checkpoint needs to be saved. + * @brief Checks if the participant is required to write an iteration checkpoint. If true, the participant is required to write an iteration checkpoint before calling advance(). * * @return true Simulation checkpoints needs to be stored. * @return false No further action is needed. */ - bool hasToWriteIterationCheckpoint(); + bool requiresToWriteCheckpoint(); /*! - * @brief Checks if initial coupling data has to be written. + * @brief Checks if the participant is required to provide initial data. If true, the participant needs to write initial data to defined vertices prior to calling initialize(). * * @return true Initial coupling data has to be provided. * @return false No further action is needed. */ - bool hasToWriteInitialData(); + bool requiresToWriteInitialData(); /*! * @brief Adds mesh for coupling of solvers. * * @param[in] meshName The name of the mesh to add the vertices to. - * @param[in] positions A span to the coordinates of the vertices + * @param[in] positions A span to the coordinates of the vertices. * * \note The coordinates need to be stored consecutively * according to their spatial coordinates as.\n @@ -270,8 +270,8 @@ public: * @param[in] dataName Name of the quantity. * @return size_t Numeric identifier of quantity. */ - std::string createKeyFromName(const precice::string_view &meshName, - const precice::string_view &dataName) const; + std::string meshAndDataKey(const precice::string_view &meshName, + const precice::string_view &dataName) const; /*! * @brief Prints status of coupling adapter to given output stream. * diff --git a/examples/dummysolver/main_dummysolver.cc b/examples/dummysolver/main_dummysolver.cc index afbe4b0..a2ff0ff 100644 --- a/examples/dummysolver/main_dummysolver.cc +++ b/examples/dummysolver/main_dummysolver.cc @@ -101,7 +101,7 @@ try { couplingParticipant.announceQuantity(meshNameView, vectorDataWriteName); couplingParticipant.announceQuantity(meshNameView, vectorDataReadName); - if (couplingParticipant.hasToWriteInitialData()) { + if (couplingParticipant.requiresToWriteInitialData()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Writing initial data\n"; couplingParticipant.writeQuantityVector( @@ -173,7 +173,7 @@ try { int iter = 0; while (couplingParticipant.isCouplingOngoing()) { - if (couplingParticipant.hasToWriteIterationCheckpoint()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Writing iteration checkpoint\n"; } @@ -253,7 +253,7 @@ try { preciceDt = couplingParticipant.getMaxTimeStepSize(); couplingParticipant.advance(preciceDt); - if (couplingParticipant.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading iteration checkpoint\n"; } else { diff --git a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc index 12a2b9e..3cc1a35 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc @@ -391,7 +391,7 @@ try { using FluxVariables = GetPropType; - if (couplingParticipant.hasToWriteInitialData()) { + if (couplingParticipant.requiresToWriteInitialData()) { setInterfacePressures(*freeFlowProblem, *freeFlowGridVariables, sol, meshNameView, dataNameViewP); @@ -422,7 +422,7 @@ try { size_t iter = 0; while (couplingParticipant.isCouplingOngoing()) { - if (couplingParticipant.hasToWriteIterationCheckpoint()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; } @@ -447,7 +447,7 @@ try { ++iter; - if (couplingParticipant.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { // //Read checkpoint // freeFlowVtkWriter.write(vtkTime); // vtkTime += 1.; diff --git a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc index cb9e9ad..b993c6c 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc @@ -429,7 +429,7 @@ try { darcyVtkWriter.write(0.0); using FluxVariables = GetPropType; - if (couplingParticipant.hasToWriteInitialData()) { + if (couplingParticipant.requiresToWriteInitialData()) { //TODO setInterfaceVelocities(*darcyProblem, *darcyGridVariables, sol, @@ -460,7 +460,7 @@ try { size_t iter = 0; while (couplingParticipant.isCouplingOngoing()) { - if (couplingParticipant.hasToWriteIterationCheckpoint()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; } @@ -482,7 +482,7 @@ try { ++iter; - if (couplingParticipant.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { //Read checkpoint darcyVtkWriter.write(vtkTime); vtkTime += 1.; diff --git a/examples/ff-pm/flow-over-square-2d/main_ff.cc b/examples/ff-pm/flow-over-square-2d/main_ff.cc index 7db830b..6e89ef2 100644 --- a/examples/ff-pm/flow-over-square-2d/main_ff.cc +++ b/examples/ff-pm/flow-over-square-2d/main_ff.cc @@ -281,7 +281,7 @@ try { using FluxVariables = GetPropType; - if (couplingParticipant.hasToWriteInitialData()) { + if (couplingParticipant.requiresToWriteInitialData()) { setInterfacePressures(*freeFlowProblem, *freeFlowGridVariables, sol, meshNameView, dataNameViewP); @@ -312,7 +312,7 @@ try { size_t iter = 0; while (couplingParticipant.isCouplingOngoing()) { - if (couplingParticipant.hasToWriteIterationCheckpoint()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; } @@ -337,7 +337,7 @@ try { ++iter; - if (couplingParticipant.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { // //Read checkpoint // freeFlowVtkWriter.write(vtkTime); // vtkTime += 1.; diff --git a/examples/ff-pm/flow-over-square-2d/main_pm.cc b/examples/ff-pm/flow-over-square-2d/main_pm.cc index 6b1148e..32b783b 100644 --- a/examples/ff-pm/flow-over-square-2d/main_pm.cc +++ b/examples/ff-pm/flow-over-square-2d/main_pm.cc @@ -323,7 +323,7 @@ try { darcyVtkWriter.write(0.0); using FluxVariables = GetPropType; - if (couplingParticipant.hasToWriteInitialData()) { + if (couplingParticipant.requiresToWriteInitialData()) { //TODO setInterfaceVelocities(*darcyProblem, *darcyGridVariables, sol, @@ -354,7 +354,7 @@ try { size_t iter = 0; while (couplingParticipant.isCouplingOngoing()) { - if (couplingParticipant.hasToWriteIterationCheckpoint()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; } @@ -376,7 +376,7 @@ try { ++iter; - if (couplingParticipant.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { //Read checkpoint darcyVtkWriter.write(vtkTime); vtkTime += 1.; From 2f265c7fdc7bedcf2698ca4266529be6a04368ea Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Fri, 8 Sep 2023 18:30:14 +0200 Subject: [PATCH 13/16] changed the preCICE version required and the test to be run --- .github/workflows/build-and-test.yml | 44 ++++++++++++++-------------- CMakeLists.txt | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 85cf3a2..210312d 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -12,29 +12,29 @@ jobs: max-parallel: 2 matrix: dumux_version: [3.4, 3.5] - precice_version: [2.3.0, 2.4.0, 2.5.0] + precice_version: [3.0.0] container: image: precice/dumux-precice:${{ matrix.dumux_version }}-${{ matrix.precice_version }} runs-on: ubuntu-latest steps: - - name: Print python3 version - run: python3 --version - - name: Print python3 version (/usr/bin/env python3) - run: /usr/bin/env python3 --version - - name: Check out code - uses: actions/checkout@v3 - with: - path: dumux-precice - - name: Build code - run: | - ls -lah - export DUNE_CONTROL_PATH=${PWD}/dumux-precice:${DUNE_CONTROL_PATH} - echo $DUNE_CONTROL_PATH - dunecontrol --only=dumux-precice --opts=./dumux-precice/test/cmake-test.opts all - cd dumux-precice/build-cmake/ - make -j2 build_tests - - name: Run tests - run: | - export DUNE_CONTROL_PATH=${PWD}/dumux-precice:${DUNE_CONTROL_PATH} - cd dumux-precice/build-cmake/ - CTEST_OUTPUT_ON_FAILURE=1 ctest -j1 + - name: Print python3 version + run: python3 --version + - name: Print python3 version (/usr/bin/env python3) + run: /usr/bin/env python3 --version + - name: Check out code + uses: actions/checkout@v3 + with: + path: dumux-precice + - name: Build code + run: | + ls -lah + export DUNE_CONTROL_PATH=${PWD}/dumux-precice:${DUNE_CONTROL_PATH} + echo $DUNE_CONTROL_PATH + dunecontrol --only=dumux-precice --opts=./dumux-precice/test/cmake-test.opts all + cd dumux-precice/build-cmake/ + make -j2 build_tests + - name: Run tests + run: | + export DUNE_CONTROL_PATH=${PWD}/dumux-precice:${DUNE_CONTROL_PATH} + cd dumux-precice/build-cmake/ + CTEST_OUTPUT_ON_FAILURE=1 ctest -j1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bbabec..bf9d28f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ endif() #find dune-common and set the module path find_package(dune-common REQUIRED) # Find preCICE library -find_package(precice 2 REQUIRED CONFIG) +find_package(precice 3.0.0 REQUIRED CONFIG) list(APPEND CMAKE_MODULE_PATH ${dune-common_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules") From ae597a474fce9659af2dea4baff5971433bd6800 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Fri, 8 Sep 2023 18:38:15 +0200 Subject: [PATCH 14/16] Changed the preCICE version for build-and-test-dumux-master --- .../workflows/build-and-test-dumux-master.yml | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build-and-test-dumux-master.yml b/.github/workflows/build-and-test-dumux-master.yml index 62f4b59..5759472 100644 --- a/.github/workflows/build-and-test-dumux-master.yml +++ b/.github/workflows/build-and-test-dumux-master.yml @@ -11,38 +11,38 @@ jobs: strategy: max-parallel: 1 matrix: - precice_version: [2.5.0] + precice_version: [3.0.0] dune_version: [2.9] container: image: precice/dune-precice:${{ matrix.dune_version }}-${{ matrix.precice_version }} runs-on: ubuntu-latest steps: - - name: Print python3 version - run: python3 --version - - name: Print python3 version (/usr/bin/env python3) - run: /usr/bin/env python3 --version - - name: Build DuMuX master - run: | - ls -lah - git clone --depth 1 https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git -b master - ls -lah - export DUNE_CONTROL_PATH=${DUNE_CONTROL_PATH}:${PWD}/dumux/dune.module - dunecontrol --opts=/opt/DUMUX/cmake-test.opts --only=dumux all - - name: Check out code - uses: actions/checkout@v3 - with: - path: dumux-precice - - name: Build code - run: | - ls -lah - export DUNE_CONTROL_PATH=${PWD}/dumux:${PWD}/dumux-precice:${DUNE_CONTROL_PATH} - echo $DUNE_CONTROL_PATH - dunecontrol --only=dumux-precice --opts=./dumux-precice/test/cmake-test.opts all - cd dumux-precice/build-cmake/ - make -j2 build_tests - - name: Run tests - run: | - export DUNE_CONTROL_PATH=${PWD}/dumux:${PWD}/dumux-precice:${DUNE_CONTROL_PATH} - cd dumux-precice/build-cmake/ - export PYTHONPATH=${PWD}/dumux/bin/testing:${PYTHONPATH} - CTEST_OUTPUT_ON_FAILURE=1 ctest -j1 + - name: Print python3 version + run: python3 --version + - name: Print python3 version (/usr/bin/env python3) + run: /usr/bin/env python3 --version + - name: Build DuMuX master + run: | + ls -lah + git clone --depth 1 https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git -b master + ls -lah + export DUNE_CONTROL_PATH=${DUNE_CONTROL_PATH}:${PWD}/dumux/dune.module + dunecontrol --opts=/opt/DUMUX/cmake-test.opts --only=dumux all + - name: Check out code + uses: actions/checkout@v3 + with: + path: dumux-precice + - name: Build code + run: | + ls -lah + export DUNE_CONTROL_PATH=${PWD}/dumux:${PWD}/dumux-precice:${DUNE_CONTROL_PATH} + echo $DUNE_CONTROL_PATH + dunecontrol --only=dumux-precice --opts=./dumux-precice/test/cmake-test.opts all + cd dumux-precice/build-cmake/ + make -j2 build_tests + - name: Run tests + run: | + export DUNE_CONTROL_PATH=${PWD}/dumux:${PWD}/dumux-precice:${DUNE_CONTROL_PATH} + cd dumux-precice/build-cmake/ + export PYTHONPATH=${PWD}/dumux/bin/testing:${PYTHONPATH} + CTEST_OUTPUT_ON_FAILURE=1 ctest -j1 From e0a2e3fe2fe7d1497f065de98a2f7c6167b69139 Mon Sep 17 00:00:00 2001 From: Ishaan Desai Date: Fri, 15 Sep 2023 14:04:55 -0400 Subject: [PATCH 15/16] Using develop version of preCICE in CI --- .github/workflows/build-docker-containers.yml | 4 ++-- docker/rebuild-docker-images.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-docker-containers.yml b/.github/workflows/build-docker-containers.yml index c9dc836..068ce5d 100644 --- a/.github/workflows/build-docker-containers.yml +++ b/.github/workflows/build-docker-containers.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: dumux_version: [3.4, 3.5] - precice_version: [2.3.0, 2.4.0, 2.5.0] + precice_version: [develop] steps: - name: Checkout Repository uses: actions/checkout@v3 @@ -49,7 +49,7 @@ jobs: strategy: matrix: dune_version: [2.9] - precice_version: [2.5.0] + precice_version: [develop] steps: - name: Checkout Repository uses: actions/checkout@v3 diff --git a/docker/rebuild-docker-images.sh b/docker/rebuild-docker-images.sh index 26e457d..3c87767 100755 --- a/docker/rebuild-docker-images.sh +++ b/docker/rebuild-docker-images.sh @@ -2,7 +2,7 @@ DUNE_VERSION="2.8" DUMUX_VERSIONS=("3.4" "3.5") -PRECICE_VERSIONS=("2.4.0" "2.3.0") +PRECICE_VERSIONS=("develop") for dumux_version in ${DUMUX_VERSIONS[@]}; do for precice_version in ${PRECICE_VERSIONS[@]}; do @@ -13,8 +13,8 @@ for dumux_version in ${DUMUX_VERSIONS[@]}; do done done -PRECICE_VERSION="2.4.0" +PRECICE_VERSION="develop" echo "Building dune-precice:${dumux_version}-${precice_version}" docker build --build-arg DUNEVERSION=${DUNE_VERSION} --build-arg PRECICEVERSION=${PRECICE_VERSION} -t precice/dune-precice:${DUNE_VERSION}-${PRECICE_VERSION} --file dockerfile_dune-precice.slim . docker push precice/dune-precice:${DUNE_VERSION}-${PRECICE_VERSION} -yes | docker image prune \ No newline at end of file +yes | docker image prune From c2b530a3fdfa246b2551ef5225eaed63535b5d2b Mon Sep 17 00:00:00 2001 From: Ishaan Desai Date: Fri, 15 Sep 2023 14:13:08 -0400 Subject: [PATCH 16/16] Use preCICE version develop in build-and-test CI --- .github/workflows/build-and-test-dumux-master.yml | 2 +- .github/workflows/build-and-test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-test-dumux-master.yml b/.github/workflows/build-and-test-dumux-master.yml index 5759472..57680d2 100644 --- a/.github/workflows/build-and-test-dumux-master.yml +++ b/.github/workflows/build-and-test-dumux-master.yml @@ -11,7 +11,7 @@ jobs: strategy: max-parallel: 1 matrix: - precice_version: [3.0.0] + precice_version: [develop] dune_version: [2.9] container: image: precice/dune-precice:${{ matrix.dune_version }}-${{ matrix.precice_version }} diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 210312d..d1637ca 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -12,7 +12,7 @@ jobs: max-parallel: 2 matrix: dumux_version: [3.4, 3.5] - precice_version: [3.0.0] + precice_version: [develop] container: image: precice/dumux-precice:${{ matrix.dumux_version }}-${{ matrix.precice_version }} runs-on: ubuntu-latest