From 478ff7630b4b409d313c783e6220d4e93e82e496 Mon Sep 17 00:00:00 2001 From: David Schneider Date: Mon, 21 Nov 2022 13:51:58 +0100 Subject: [PATCH 01/14] Merge `initializeData` into `initialize` --- Adapter.C | 13 ++++--------- Adapter.H | 1 - 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Adapter.C b/Adapter.C index cab5ae92..dd9ba648 100644 --- a/Adapter.C +++ b/Adapter.C @@ -532,10 +532,6 @@ void preciceAdapter::Adapter::initialize() { DEBUG(adapterInfo("Initializing the preCICE solver interface...")); SETUP_TIMER(); - timestepPrecice_ = precice_->initialize(); - ACCUMULATE_TIMER(timeInInitialize_); - - preciceInitialized_ = true; if (precice_->isActionRequired(precice::constants::actionWriteInitialData())) { @@ -544,9 +540,9 @@ void preciceAdapter::Adapter::initialize() } DEBUG(adapterInfo("Initializing preCICE data...")); - REUSE_TIMER(); - precice_->initializeData(); - ACCUMULATE_TIMER(timeInInitializeData_); + timestepPrecice_ = precice_->initialize(); + preciceInitialized_ = true; + ACCUMULATE_TIMER(timeInInitialize_); adapterInfo("preCICE was configured and initialized", "info"); @@ -1660,9 +1656,8 @@ preciceAdapter::Adapter::~Adapter() Info << " (I) writing checkpoints: " << timeInCheckpointingWrite_.str() << nl; Info << " (I) reading checkpoints: " << timeInCheckpointingRead_.str() << nl; Info << " (I) writing OpenFOAM results: " << timeInWriteResults_.str() << " (at the end of converged time windows)" << nl << nl; - Info << "Time exclusively in preCICE: " << (timeInInitialize_ + timeInInitializeData_ + timeInAdvance_ + timeInFinalize_).str() << nl; + Info << "Time exclusively in preCICE: " << (timeInInitialize_ + timeInAdvance_ + timeInFinalize_).str() << nl; Info << " (S) initialize(): " << timeInInitialize_.str() << nl; - Info << " (S) initializeData(): " << timeInInitializeData_.str() << nl; Info << " (I) advance(): " << timeInAdvance_.str() << nl; Info << " (I) finalize(): " << timeInFinalize_.str() << nl; Info << " These times include time waiting for other participants." << nl; diff --git a/Adapter.H b/Adapter.H index f94fd9c5..5dacf841 100644 --- a/Adapter.H +++ b/Adapter.H @@ -54,7 +54,6 @@ private: clockValue timeInPreciceConstruct_; clockValue timeInMeshSetup_; clockValue timeInInitialize_; - clockValue timeInInitializeData_; clockValue timeInCheckpointingSetup_; clockValue timeInWrite_; clockValue timeInAdvance_; From 70be8913c00f851eed58641f7331b1ab7ac0abdd Mon Sep 17 00:00:00 2001 From: David Schneider Date: Mon, 21 Nov 2022 13:55:48 +0100 Subject: [PATCH 02/14] Add changelog --- docs/changelog-entries/262.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changelog-entries/262.md diff --git a/docs/changelog-entries/262.md b/docs/changelog-entries/262.md new file mode 100644 index 00000000..7609e361 --- /dev/null +++ b/docs/changelog-entries/262.md @@ -0,0 +1 @@ +- Merged `initializeData` into `initialize` [#262](https://github.com/precice/openfoam-adapter/pull/262). From 25bc3d4daaff57a8897aff6d4954ed42e8a718ef Mon Sep 17 00:00:00 2001 From: David Schneider Date: Fri, 9 Dec 2022 15:29:25 +0100 Subject: [PATCH 03/14] Replace actions by explicit calls --- Adapter.C | 35 ++++++++--------------------------- Adapter.H | 10 ++-------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/Adapter.C b/Adapter.C index dd9ba648..bd341dfb 100644 --- a/Adapter.C +++ b/Adapter.C @@ -350,7 +350,7 @@ void preciceAdapter::Adapter::configure() // If checkpointing is required, specify the checkpointed fields // and write the first checkpoint - if (isWriteCheckpointRequired()) + if (requiresWritingCheckpoint()) { checkpointing_ = true; @@ -359,7 +359,6 @@ void preciceAdapter::Adapter::configure() // Write checkpoint (for the first iteration) writeCheckpoint(); - fulfilledWriteCheckpoint(); } // Adjust the timestep for the first iteration, if it is fixed @@ -421,10 +420,9 @@ void preciceAdapter::Adapter::execute() advance(); // Read checkpoint if required - if (isReadCheckpointRequired()) + if (requiresReadingCheckpoint()) { readCheckpoint(); - fulfilledReadCheckpoint(); } // Adjust the timestep, if it is fixed @@ -434,10 +432,9 @@ void preciceAdapter::Adapter::execute() } // Write checkpoint if required - if (isWriteCheckpointRequired()) + if (requiresWritingCheckpoint()) { writeCheckpoint(); - fulfilledWriteCheckpoint(); } // As soon as OpenFOAM writes the results, it will not try to write again @@ -533,11 +530,8 @@ void preciceAdapter::Adapter::initialize() DEBUG(adapterInfo("Initializing the preCICE solver interface...")); SETUP_TIMER(); - if (precice_->isActionRequired(precice::constants::actionWriteInitialData())) - { + if (precice_->requiresInitialData()) writeCouplingData(); - precice_->markActionFulfilled(precice::constants::actionWriteInitialData()); - } DEBUG(adapterInfo("Initializing preCICE data...")); timestepPrecice_ = precice_->initialize(); @@ -704,29 +698,16 @@ bool preciceAdapter::Adapter::isCouplingTimeWindowComplete() return precice_->isTimeWindowComplete(); } -bool preciceAdapter::Adapter::isReadCheckpointRequired() +bool preciceAdapter::Adapter::requiresReadingCheckpoint() { - return precice_->isActionRequired(precice::constants::actionReadIterationCheckpoint()); + return precice_->requiresReadingCheckpoint(); } -bool preciceAdapter::Adapter::isWriteCheckpointRequired() +bool preciceAdapter::Adapter::requiresWritingCheckpoint() { - return precice_->isActionRequired(precice::constants::actionWriteIterationCheckpoint()); + return precice_->requiresWritingCheckpoint(); } -void preciceAdapter::Adapter::fulfilledReadCheckpoint() -{ - precice_->markActionFulfilled(precice::constants::actionReadIterationCheckpoint()); - - return; -} - -void preciceAdapter::Adapter::fulfilledWriteCheckpoint() -{ - precice_->markActionFulfilled(precice::constants::actionWriteIterationCheckpoint()); - - return; -} void preciceAdapter::Adapter::storeCheckpointTime() { diff --git a/Adapter.H b/Adapter.H index 5dacf841..73a05d94 100644 --- a/Adapter.H +++ b/Adapter.H @@ -279,16 +279,10 @@ private: bool isCouplingTimeWindowComplete(); //- Determine if a checkpoint must be read - bool isReadCheckpointRequired(); + bool requiresReadingCheckpoint(); //- Determine if a checkpoint must be written - bool isWriteCheckpointRequired(); - - //- Tell preCICE that the checkpoint has been read - void fulfilledReadCheckpoint(); - - //- Tell preCICE that the checkpoint has been written - void fulfilledWriteCheckpoint(); + bool requiresWritingCheckpoint(); // Methods for checkpointing From 2904355a49e173056b433addc455e3b60c161b9e Mon Sep 17 00:00:00 2001 From: David Schneider Date: Mon, 20 Mar 2023 15:08:59 +0100 Subject: [PATCH 04/14] Port data and mesh IDs to actual names --- CouplingDataUser.C | 10 ++++------ CouplingDataUser.H | 12 ++++++------ Interface.C | 25 +++++++++++++------------ 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/CouplingDataUser.C b/CouplingDataUser.C index 7e84250d..7aeaf8ad 100644 --- a/CouplingDataUser.C +++ b/CouplingDataUser.C @@ -14,16 +14,14 @@ bool preciceAdapter::CouplingDataUser::hasVectorData() return dataType_ == vector; } -void preciceAdapter::CouplingDataUser::setDataID(int dataID) +void preciceAdapter::CouplingDataUser::setDataName(std::string dataName) { - dataID_ = dataID; - - return; + dataName_ = std::move(dataName); } -int preciceAdapter::CouplingDataUser::dataID() +const std::string& preciceAdapter::CouplingDataUser::dataName() { - return dataID_; + return dataName_; } void preciceAdapter::CouplingDataUser::setPatchIDs(std::vector patchIDs) diff --git a/CouplingDataUser.H b/CouplingDataUser.H index 3c994790..ea69537b 100644 --- a/CouplingDataUser.H +++ b/CouplingDataUser.H @@ -32,8 +32,8 @@ protected: //- OpenFOAM patches that form the interface std::vector patchIDs_; - //- preCICE data ID - int dataID_; + //- data name + std::string dataName_; //- location type of the interface LocationType locationType_ = LocationType::none; @@ -48,11 +48,11 @@ public: //- Returns true if the data are vector bool hasVectorData(); - //- Set the preCICE data ID - void setDataID(int dataID); + //- Set the data name + void setDataName(std::string dataName); - //- Get the preCICE data ID - int dataID(); + //- Get the data name + const std::string& dataName(); //- Set the patch IDs that form the interface void setPatchIDs(std::vector patchIDs); diff --git a/Interface.C b/Interface.C index 694f2b54..34fe7669 100644 --- a/Interface.C +++ b/Interface.C @@ -21,9 +21,6 @@ preciceAdapter::Interface::Interface( meshConnectivity_(meshConnectivity), restartFromDeformed_(restartFromDeformed) { - // Get the meshID from preCICE - meshID_ = precice_.getMeshID(meshName_); - dim_ = precice_.getDimensions(); if (dim_ == 2 && meshConnectivity_ == true) @@ -181,7 +178,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str } // Pass the mesh vertices information to preCICE - precice_.setMeshVertices(meshID_, numDataLocations_, vertices, vertexIDs_); + precice_.setMeshVertices(meshName_, numDataLocations_, vertices, vertexIDs_); } else if (locationType_ == LocationType::faceNodes) { @@ -242,7 +239,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str } // Pass the mesh vertices information to preCICE - precice_.setMeshVertices(meshID_, numDataLocations_, vertices, vertexIDs_); + precice_.setMeshVertices(meshName_, numDataLocations_, vertices, vertexIDs_); // meshConnectivity for prototype neglected // Only set the triangles, if necessary @@ -325,8 +322,8 @@ void preciceAdapter::Interface::addCouplingDataWriter( std::string dataName, CouplingDataUser* couplingDataWriter) { - // Set the dataID (from preCICE) - couplingDataWriter->setDataID(precice_.getDataID(dataName, meshID_)); + // Set the data name (from preCICE) + couplingDataWriter->setDataName(dataName); // Set the patchIDs of the patches that form the interface couplingDataWriter->setPatchIDs(patchIDs_); @@ -350,7 +347,7 @@ void preciceAdapter::Interface::addCouplingDataReader( preciceAdapter::CouplingDataUser* couplingDataReader) { // Set the patchIDs of the patches that form the interface - couplingDataReader->setDataID(precice_.getDataID(dataName, meshID_)); + couplingDataReader->setDataName(dataName); // Add the CouplingDataUser to the list of readers couplingDataReader->setPatchIDs(patchIDs_); @@ -426,7 +423,8 @@ void preciceAdapter::Interface::readCouplingData() if (couplingDataReader->hasVectorData()) { precice_.readBlockVectorData( - couplingDataReader->dataID(), + meshName_, + couplingDataReader->dataName(), numDataLocations_, vertexIDs_, dataBuffer_); @@ -434,7 +432,8 @@ void preciceAdapter::Interface::readCouplingData() else { precice_.readBlockScalarData( - couplingDataReader->dataID(), + meshName_, + couplingDataReader->dataName(), numDataLocations_, vertexIDs_, dataBuffer_); @@ -465,7 +464,8 @@ void preciceAdapter::Interface::writeCouplingData() if (couplingDataWriter->hasVectorData()) { precice_.writeBlockVectorData( - couplingDataWriter->dataID(), + meshName_, + couplingDataWriter->dataName(), numDataLocations_, vertexIDs_, dataBuffer_); @@ -473,7 +473,8 @@ void preciceAdapter::Interface::writeCouplingData() else { precice_.writeBlockScalarData( - couplingDataWriter->dataID(), + meshName_, + couplingDataWriter->dataName(), numDataLocations_, vertexIDs_, dataBuffer_); From fca99c6e87a0415d55fb798b275e8b1e4518ea0d Mon Sep 17 00:00:00 2001 From: David Schneider Date: Mon, 3 Jul 2023 14:29:35 +0200 Subject: [PATCH 05/14] Latest changes from develop --- Adapter.C | 17 +++++++----- Adapter.H | 6 ++--- Interface.C | 77 ++++++++++++++++------------------------------------- Interface.H | 12 ++++----- 4 files changed, 42 insertions(+), 70 deletions(-) diff --git a/Adapter.C b/Adapter.C index bd341dfb..0835d62b 100644 --- a/Adapter.C +++ b/Adapter.C @@ -246,7 +246,7 @@ void preciceAdapter::Adapter::configure() DEBUG(adapterInfo("Creating the preCICE solver interface...")); DEBUG(adapterInfo(" Number of processes: " + std::to_string(Pstream::nProcs()))); DEBUG(adapterInfo(" MPI rank: " + std::to_string(Pstream::myProcNo()))); - precice_ = new precice::SolverInterface(participantName_, preciceConfigFilename_, Pstream::myProcNo(), Pstream::nProcs()); + precice_ = new precice::Participant(participantName_, preciceConfigFilename_, Pstream::myProcNo(), Pstream::nProcs()); DEBUG(adapterInfo(" preCICE solver interface was created.")); ACCUMULATE_TIMER(timeInPreciceConstruct_); @@ -346,7 +346,7 @@ void preciceAdapter::Adapter::configure() initialize(); // Read the received coupling data - readCouplingData(); + readCouplingData(runTime_.deltaT().value()); // If checkpointing is required, specify the checkpointed fields // and write the first checkpoint @@ -459,7 +459,8 @@ void preciceAdapter::Adapter::execute() ACCUMULATE_TIMER(timeInWriteResults_); // Read the received coupling data from the buffer - readCouplingData(); + // Fits to an implicit Euler + readCouplingData(runTime_.deltaT().value()); // If the coupling is not going to continue, tear down everything // and stop the simulation. @@ -495,14 +496,14 @@ void preciceAdapter::Adapter::adjustTimeStep() return; } -void preciceAdapter::Adapter::readCouplingData() +void preciceAdapter::Adapter::readCouplingData(double relativeReadTime) { SETUP_TIMER(); DEBUG(adapterInfo("Reading coupling data...")); for (uint i = 0; i < interfaces_.size(); i++) { - interfaces_.at(i)->readCouplingData(); + interfaces_.at(i)->readCouplingData(relativeReadTime); } ACCUMULATE_TIMER(timeInRead_); @@ -534,7 +535,8 @@ void preciceAdapter::Adapter::initialize() writeCouplingData(); DEBUG(adapterInfo("Initializing preCICE data...")); - timestepPrecice_ = precice_->initialize(); + precice_->initialize(); + timestepPrecice_ = precice_->getMaxTimeStepSize(); preciceInitialized_ = true; ACCUMULATE_TIMER(timeInInitialize_); @@ -572,7 +574,8 @@ void preciceAdapter::Adapter::advance() DEBUG(adapterInfo("Advancing preCICE...")); SETUP_TIMER(); - timestepPrecice_ = precice_->advance(timestepSolver_); + precice_->advance(timestepSolver_); + timestepPrecice_ = precice_->getMaxTimeStepSize(); ACCUMULATE_TIMER(timeInAdvance_); return; diff --git a/Adapter.H b/Adapter.H index 73a05d94..0f5ef548 100644 --- a/Adapter.H +++ b/Adapter.H @@ -22,7 +22,7 @@ #include "fvMesh.H" // preCICE Solver Interface -#include "precice/SolverInterface.hpp" +#include namespace preciceAdapter { @@ -105,7 +105,7 @@ private: std::vector interfaces_; //- preCICE solver interface - precice::SolverInterface* precice_ = NULL; + precice::Participant* precice_ = NULL; //- preCICE solver interface initialized bool preciceInitialized_ = false; @@ -264,7 +264,7 @@ private: void advance(); //- Read the coupling data at each interface - void readCouplingData(); + void readCouplingData(double relativeReadTime); //- Write the coupling data at each interface void writeCouplingData(); diff --git a/Interface.C b/Interface.C index 34fe7669..d070f63a 100644 --- a/Interface.C +++ b/Interface.C @@ -6,7 +6,7 @@ using namespace Foam; preciceAdapter::Interface::Interface( - precice::SolverInterface& precice, + precice::Participant& precice, const fvMesh& mesh, std::string meshName, std::string locationsType, @@ -21,7 +21,7 @@ preciceAdapter::Interface::Interface( meshConnectivity_(meshConnectivity), restartFromDeformed_(restartFromDeformed) { - dim_ = precice_.getDimensions(); + dim_ = precice_.getMeshDimensions(meshName); if (dim_ == 2 && meshConnectivity_ == true) { @@ -97,11 +97,11 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str // Array of the mesh vertices. // One mesh is used for all the patches and each vertex has 3D coordinates. - double vertices[dim_ * numDataLocations_]; + std::vector vertices(dim_ * numDataLocations_); // Array of the indices of the mesh vertices. // Each vertex has one index, but three coordinates. - vertexIDs_ = new int[numDataLocations_]; + vertexIDs_.resize(numDataLocations_); // Initialize the index of the vertices array int verticesIndex = 0; @@ -178,7 +178,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str } // Pass the mesh vertices information to preCICE - precice_.setMeshVertices(meshName_, numDataLocations_, vertices, vertexIDs_); + precice_.setMeshVertices(meshName_, vertices, vertexIDs_); } else if (locationType_ == LocationType::faceNodes) { @@ -198,11 +198,11 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str // Array of the mesh vertices. // One mesh is used for all the patches and each vertex has 3D coordinates. - double vertices[dim_ * numDataLocations_]; + std::vector vertices(dim_ * numDataLocations_); // Array of the indices of the mesh vertices. // Each vertex has one index, but three coordinates. - vertexIDs_ = new int[numDataLocations_]; + vertexIDs_.resize(numDataLocations_); // Initialize the index of the vertices array int verticesIndex = 0; @@ -239,7 +239,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str } // Pass the mesh vertices information to preCICE - precice_.setMeshVertices(meshName_, numDataLocations_, vertices, vertexIDs_); + precice_.setMeshVertices(meshName_, vertices, vertexIDs_); // meshConnectivity for prototype neglected // Only set the triangles, if necessary @@ -406,10 +406,10 @@ void preciceAdapter::Interface::createBuffer() // scalar and vector coupling data users in an interface. With the current // preCICE implementation, it should work as, when writing scalars, // it should only use the first 1/3 elements of the buffer. - dataBuffer_ = new double[dataBufferSize](); + dataBuffer_.resize(dataBufferSize); } -void preciceAdapter::Interface::readCouplingData() +void preciceAdapter::Interface::readCouplingData(double relativeReadTime) { // Make every coupling data reader read for (uint i = 0; i < couplingDataReaders_.size(); i++) @@ -420,27 +420,15 @@ void preciceAdapter::Interface::readCouplingData() // Make preCICE read vector or scalar data // and fill the adapter's buffer - if (couplingDataReader->hasVectorData()) - { - precice_.readBlockVectorData( - meshName_, - couplingDataReader->dataName(), - numDataLocations_, - vertexIDs_, - dataBuffer_); - } - else - { - precice_.readBlockScalarData( - meshName_, - couplingDataReader->dataName(), - numDataLocations_, - vertexIDs_, - dataBuffer_); - } + precice_.readData( + meshName_, + couplingDataReader->dataName(), + vertexIDs_, + relativeReadTime, + dataBuffer_); // Read the received data from the buffer - couplingDataReader->read(dataBuffer_, dim_); + couplingDataReader->read(dataBuffer_.data(), dim_); } } @@ -458,27 +446,14 @@ void preciceAdapter::Interface::writeCouplingData() couplingDataWriter = couplingDataWriters_.at(i); // Write the data into the adapter's buffer - couplingDataWriter->write(dataBuffer_, meshConnectivity_, dim_); + couplingDataWriter->write(dataBuffer_.data(), meshConnectivity_, dim_); // Make preCICE write vector or scalar data - if (couplingDataWriter->hasVectorData()) - { - precice_.writeBlockVectorData( - meshName_, - couplingDataWriter->dataName(), - numDataLocations_, - vertexIDs_, - dataBuffer_); - } - else - { - precice_.writeBlockScalarData( - meshName_, - couplingDataWriter->dataName(), - numDataLocations_, - vertexIDs_, - dataBuffer_); - } + precice_.writeData( + meshName_, + couplingDataWriter->dataName(), + vertexIDs_, + dataBuffer_); } // } } @@ -498,10 +473,4 @@ preciceAdapter::Interface::~Interface() delete couplingDataWriters_.at(i); } couplingDataWriters_.clear(); - - // Delete the vertexIDs_ - delete[] vertexIDs_; - - // Delete the shared data buffer - delete[] dataBuffer_; } diff --git a/Interface.H b/Interface.H index 3d05329e..27221030 100644 --- a/Interface.H +++ b/Interface.H @@ -5,7 +5,7 @@ #include #include "fvCFD.H" #include "CouplingDataUser.H" -#include "precice/SolverInterface.hpp" +#include #include "pointPatchField.H" @@ -16,7 +16,7 @@ class Interface { protected: //- preCICE solver interface - precice::SolverInterface& precice_; + precice::Participant& precice_; //- Mesh name used in the preCICE configuration std::string meshName_; @@ -37,10 +37,10 @@ protected: int numDataLocations_ = 0; //- Vertex IDs assigned by preCICE - int* vertexIDs_; + std::vector vertexIDs_; //- Buffer for the coupling data - double* dataBuffer_; + std::vector dataBuffer_; //- Vector of CouplingDataReaders std::vector couplingDataReaders_; @@ -66,7 +66,7 @@ protected: public: //- Constructor Interface( - precice::SolverInterface& precice, + precice::Participant& precice, const Foam::fvMesh& mesh, std::string meshName, std::string locationsType, @@ -94,7 +94,7 @@ public: //- Call read() on each registered couplingDataReader to read the coupling // data from the buffer and apply the boundary conditions - void readCouplingData(); + void readCouplingData(double relativeReadTime); //- Call write() on each registered couplingDataWriter to extract the boundary // data and write them into the buffer From 91f4f0f678cf8bf2cbdb422be5e1cee4fafdd9a0 Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Mon, 24 Jul 2023 07:10:47 +0200 Subject: [PATCH 06/14] Workaround: Remove the connectivity-related preCICE calls --- Interface.C | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Interface.C b/Interface.C index d070f63a..7a6f6566 100644 --- a/Interface.C +++ b/Interface.C @@ -301,7 +301,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str //Array to store the IDs we get from preCICE int triVertIDs[faceField.size() * (triaPerQuad * nodesPerTria)]; - + /* //Get preCICE IDs precice_.getMeshVertexIDsFromPositions(meshID_, faceField.size() * (triaPerQuad * nodesPerTria), triCoords, triVertIDs); @@ -311,7 +311,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str for (int facei = 0; facei < faceField.size() * triaPerQuad; facei++) { precice_.setMeshTriangleWithEdges(meshID_, triVertIDs[facei * nodesPerTria], triVertIDs[facei * nodesPerTria + 1], triVertIDs[facei * nodesPerTria + 2]); - } + }*/ } } } From 43e3f19808696cf54f333e8a14e809efcb51150a Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Tue, 25 Jul 2023 13:07:16 +0200 Subject: [PATCH 07/14] First attempt to connectivity with v3 --- Interface.C | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Interface.C b/Interface.C index 7a6f6566..59207921 100644 --- a/Interface.C +++ b/Interface.C @@ -207,6 +207,9 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str // Initialize the index of the vertices array int verticesIndex = 0; + // Map between OpenFOAM vertices and preCICE vertex IDs + std::map,int> verticesMap; + // Get the locations of the mesh vertices (here: face nodes) // for all the patches for (uint j = 0; j < patchIDs_.size(); j++) @@ -234,13 +237,30 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str // Assign the (x,y,z) locations to the vertices // TODO: Ensure consistent order when writing/reading for (int i = 0; i < faceNodes.size(); i++) + { for (unsigned int d = 0; d < dim_; ++d) + { vertices[verticesIndex++] = faceNodes[i][d]; + } + verticesMap.emplace(std::make_tuple(faceNodes[i][0], faceNodes[i][1], faceNodes[i][2]), -1); + } } // Pass the mesh vertices information to preCICE precice_.setMeshVertices(meshName_, vertices, vertexIDs_); + // Build the map between OpenFOAM vertices and preCICE vertex IDs + verticesIndex = 0; + for (auto & key : verticesMap) + { + key.second = vertexIDs_[verticesIndex++]; + adapterInfo("Map element: " + + std::to_string(std::get<0>(key.first)) + "," + + std::to_string(std::get<1>(key.first)) + "," + + std::to_string(std::get<2>(key.first)) + " - " + + std::to_string(key.second)); + } + // meshConnectivity for prototype neglected // Only set the triangles, if necessary if (meshConnectivity_) @@ -263,7 +283,6 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str // Define constants const int triaPerQuad = 2; const int nodesPerTria = 3; - const int componentsPerNode = 3; // Get the list of faces and coordinates at the interface patch const List faceField = mesh.boundaryMesh()[patchIDs_.at(j)].localFaces(); @@ -277,10 +296,8 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str pointCoords -= resetField; } - // Array to store coordinates in preCICE format - double triCoords[faceField.size() * triaPerQuad * nodesPerTria * componentsPerNode]; - - unsigned int coordIndex = 0; + //Array to store the IDs we get from preCICE + std::vector triVertIDs; // Iterate over faces forAll(faceField, facei) @@ -293,25 +310,16 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str { for (uint nodeIndex = 0; nodeIndex < nodesPerTria; nodeIndex++) { - for (uint xyz = 0; xyz < componentsPerNode; xyz++) - triCoords[coordIndex++] = pointCoords[faceTri[triIndex][nodeIndex]][xyz]; + triVertIDs.push_back(verticesMap.at(std::make_tuple(pointCoords[faceTri[triIndex][nodeIndex]][0], pointCoords[faceTri[triIndex][nodeIndex]][1], pointCoords[faceTri[triIndex][nodeIndex]][2]))); } } } - //Array to store the IDs we get from preCICE - int triVertIDs[faceField.size() * (triaPerQuad * nodesPerTria)]; - /* - //Get preCICE IDs - precice_.getMeshVertexIDsFromPositions(meshID_, faceField.size() * (triaPerQuad * nodesPerTria), triCoords, triVertIDs); - - DEBUG(adapterInfo("Number of triangles: " + std::to_string(faceField.size() * triaPerQuad))); + DEBUG(adapterInfo("Number of faces * triaPerQuad: " + std::to_string(faceField.size() * triaPerQuad))); + DEBUG(adapterInfo("Number of triangles: " + std::to_string(triVertIDs.size()))); //Set Triangles - for (int facei = 0; facei < faceField.size() * triaPerQuad; facei++) - { - precice_.setMeshTriangleWithEdges(meshID_, triVertIDs[facei * nodesPerTria], triVertIDs[facei * nodesPerTria + 1], triVertIDs[facei * nodesPerTria + 2]); - }*/ + precice_.setMeshTriangles(meshName_, triVertIDs); } } } From 7a3029308a69172aa5a04280c0f6fbbef50570db Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Tue, 25 Jul 2023 13:46:40 +0200 Subject: [PATCH 08/14] Remove debug messages --- Interface.C | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Interface.C b/Interface.C index 59207921..7cac8d3b 100644 --- a/Interface.C +++ b/Interface.C @@ -254,11 +254,6 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str for (auto & key : verticesMap) { key.second = vertexIDs_[verticesIndex++]; - adapterInfo("Map element: " - + std::to_string(std::get<0>(key.first)) + "," - + std::to_string(std::get<1>(key.first)) + "," - + std::to_string(std::get<2>(key.first)) + " - " - + std::to_string(key.second)); } // meshConnectivity for prototype neglected @@ -315,8 +310,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str } } - DEBUG(adapterInfo("Number of faces * triaPerQuad: " + std::to_string(faceField.size() * triaPerQuad))); - DEBUG(adapterInfo("Number of triangles: " + std::to_string(triVertIDs.size()))); + DEBUG(adapterInfo("Number of triangles: " + std::to_string(faceField.size() * triaPerQuad))); //Set Triangles precice_.setMeshTriangles(meshName_, triVertIDs); From 26d23b4ab937369afbe37356d84364d652d57984 Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Fri, 4 Aug 2023 10:54:40 +0200 Subject: [PATCH 09/14] Update Interface.C MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Frédéric Simonis --- Interface.C | 1 + 1 file changed, 1 insertion(+) diff --git a/Interface.C b/Interface.C index 7cac8d3b..d4e2ea93 100644 --- a/Interface.C +++ b/Interface.C @@ -293,6 +293,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str //Array to store the IDs we get from preCICE std::vector triVertIDs; + triVertIDs.reserve(faceField.size() * triaPerQuad * nodesPerTria); // Iterate over faces forAll(faceField, facei) From 861edddd240b34db91b3d4c22a46bde241ad1f6a Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Fri, 4 Aug 2023 11:31:26 +0200 Subject: [PATCH 10/14] Only generate verticesMap when needed --- Interface.C | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Interface.C b/Interface.C index d4e2ea93..14285b8e 100644 --- a/Interface.C +++ b/Interface.C @@ -242,24 +242,25 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str { vertices[verticesIndex++] = faceNodes[i][d]; } - verticesMap.emplace(std::make_tuple(faceNodes[i][0], faceNodes[i][1], faceNodes[i][2]), -1); + if (meshConnectivity_) + { + verticesMap.emplace(std::make_tuple(faceNodes[i][0], faceNodes[i][1], faceNodes[i][2]), -1); + } } } // Pass the mesh vertices information to preCICE precice_.setMeshVertices(meshName_, vertices, vertexIDs_); - // Build the map between OpenFOAM vertices and preCICE vertex IDs - verticesIndex = 0; - for (auto & key : verticesMap) - { - key.second = vertexIDs_[verticesIndex++]; - } - - // meshConnectivity for prototype neglected - // Only set the triangles, if necessary if (meshConnectivity_) { + // Build the map between OpenFOAM vertices and preCICE vertex IDs + verticesIndex = 0; + for (auto & key : verticesMap) + { + key.second = vertexIDs_[verticesIndex++]; + } + for (uint j = 0; j < patchIDs_.size(); j++) { // Define triangles From 0f5d637240e9f1002401794fafd2eb196f47ddc6 Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Fri, 4 Aug 2023 15:41:28 +0200 Subject: [PATCH 11/14] Add more comments --- Interface.C | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Interface.C b/Interface.C index 14285b8e..abca451f 100644 --- a/Interface.C +++ b/Interface.C @@ -296,15 +296,19 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str std::vector triVertIDs; triVertIDs.reserve(faceField.size() * triaPerQuad * nodesPerTria); - // Iterate over faces + // Triangulate all faces and collect set of nodes that form triangles, + // which are used to set mesh triangles in preCICE. forAll(faceField, facei) { const face& faceQuad = faceField[facei]; + // Triangulate the face faceTriangulation faceTri(pointCoords, faceQuad, false); + // Iterate over all triangles generated out of each (quad) face for (uint triIndex = 0; triIndex < triaPerQuad; triIndex++) { + // Get the vertex that corresponds to the x,y,z coordinates of each node of a triangle for (uint nodeIndex = 0; nodeIndex < nodesPerTria; nodeIndex++) { triVertIDs.push_back(verticesMap.at(std::make_tuple(pointCoords[faceTri[triIndex][nodeIndex]][0], pointCoords[faceTri[triIndex][nodeIndex]][1], pointCoords[faceTri[triIndex][nodeIndex]][2]))); From 2dec84274ed0ac7e60c64da109486fc20d7c71de Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Fri, 4 Aug 2023 15:43:33 +0200 Subject: [PATCH 12/14] Add changelog entry --- changelog-entries/297.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog-entries/297.md diff --git a/changelog-entries/297.md b/changelog-entries/297.md new file mode 100644 index 00000000..664eb17e --- /dev/null +++ b/changelog-entries/297.md @@ -0,0 +1 @@ +- Changed the way mesh connectivity (face triangles) are provided to preCICE, adapting to preCICE v3 [#297](https://github.com/precice/openfoam-adapter/pull/297) From 227e367ace8b66b997e63fc096c1922144870e22 Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Fri, 4 Aug 2023 15:46:32 +0200 Subject: [PATCH 13/14] Format code --- Interface.C | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Interface.C b/Interface.C index abca451f..69926525 100644 --- a/Interface.C +++ b/Interface.C @@ -208,7 +208,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str int verticesIndex = 0; // Map between OpenFOAM vertices and preCICE vertex IDs - std::map,int> verticesMap; + std::map, int> verticesMap; // Get the locations of the mesh vertices (here: face nodes) // for all the patches @@ -256,7 +256,7 @@ void preciceAdapter::Interface::configureMesh(const fvMesh& mesh, const std::str { // Build the map between OpenFOAM vertices and preCICE vertex IDs verticesIndex = 0; - for (auto & key : verticesMap) + for (auto& key : verticesMap) { key.second = vertexIDs_[verticesIndex++]; } From b8989b6b5add399802bdc2cb300823c666419c80 Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Mon, 7 Aug 2023 12:23:32 +0200 Subject: [PATCH 14/14] Remove stray changelog entry file --- docs/changelog-entries/262.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 docs/changelog-entries/262.md diff --git a/docs/changelog-entries/262.md b/docs/changelog-entries/262.md deleted file mode 100644 index 7609e361..00000000 --- a/docs/changelog-entries/262.md +++ /dev/null @@ -1 +0,0 @@ -- Merged `initializeData` into `initialize` [#262](https://github.com/precice/openfoam-adapter/pull/262).