From e7bb7fd2d1d07139dfea137e1da6568626e147e8 Mon Sep 17 00:00:00 2001 From: David Schneider Date: Fri, 19 May 2023 10:14:19 +0200 Subject: [PATCH 1/3] Fix iterator in FSI reader and writer for multiple patches (#289) * Fix iterator in FSI reader and writer for multiple patches * Add changelog entry --- FSI/Displacement.C | 12 +++++++----- FSI/DisplacementDelta.C | 5 +++-- FSI/Force.C | 3 ++- FSI/ForceBase.C | 3 ++- changelog-entries/289.md | 1 + 5 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 changelog-entries/289.md diff --git a/FSI/Displacement.C b/FSI/Displacement.C index a83c0a42..69baf676 100644 --- a/FSI/Displacement.C +++ b/FSI/Displacement.C @@ -48,6 +48,7 @@ void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectiv if (this->locationType_ == LocationType::faceCenters) { + int bufferIndex = 0; // For every boundary patch of the interface for (const label patchID : patchIDs_) { @@ -56,7 +57,7 @@ void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectiv forAll(cellDisplacement_->boundaryField()[patchID], i) { for (unsigned int d = 0; d < dim; ++d) - buffer[i * dim + d] = + buffer[bufferIndex++] = cellDisplacement_->boundaryField()[patchID][i][d]; } } @@ -69,6 +70,7 @@ void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectiv "See https://github.com/precice/openfoam-adapter/issues/153.", "warning")); + int bufferIndex = 0; // For every boundary patch of the interface for (const label patchID : patchIDs_) { @@ -80,7 +82,7 @@ void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectiv mesh_.boundaryMesh()[patchID].meshPoints(); for (unsigned int d = 0; d < dim; ++d) - buffer[i * dim + d] = + buffer[bufferIndex++] = pointDisplacement_->internalField()[meshPoints[i]][d]; } } @@ -91,6 +93,7 @@ void preciceAdapter::FSI::Displacement::write(double* buffer, bool meshConnectiv // return the displacement to use later in the velocity? void preciceAdapter::FSI::Displacement::read(double* buffer, const unsigned int dim) { + int bufferIndex = 0; for (unsigned int j = 0; j < patchIDs_.size(); j++) { // Get the ID of the current patch @@ -98,14 +101,13 @@ void preciceAdapter::FSI::Displacement::read(double* buffer, const unsigned int if (this->locationType_ == LocationType::faceCenters) { - // the boundaryCellDisplacement is a vector and ordered according to the iterator j // and not according to the patchID // First, copy the buffer data into the center based vectorFields on each interface patch forAll(cellDisplacement_->boundaryField()[patchID], i) { for (unsigned int d = 0; d < dim; ++d) - cellDisplacement_->boundaryFieldRef()[patchID][i][d] = buffer[i * dim + d]; + cellDisplacement_->boundaryFieldRef()[patchID][i][d] = buffer[bufferIndex++]; } if (pointDisplacement_ != nullptr) @@ -132,7 +134,7 @@ void preciceAdapter::FSI::Displacement::read(double* buffer, const unsigned int forAll(pointDisplacement_->boundaryFieldRef()[patchID], i) { for (unsigned int d = 0; d < dim; ++d) - pointDisplacementFluidPatch[i][d] = buffer[i * dim + d]; + pointDisplacementFluidPatch[i][d] = buffer[bufferIndex++]; } } } diff --git a/FSI/DisplacementDelta.C b/FSI/DisplacementDelta.C index 53b56240..19c93139 100644 --- a/FSI/DisplacementDelta.C +++ b/FSI/DisplacementDelta.C @@ -49,6 +49,7 @@ void preciceAdapter::FSI::DisplacementDelta::write(double* buffer, bool meshConn // return the displacement to use later in the velocity? void preciceAdapter::FSI::DisplacementDelta::read(double* buffer, const unsigned int dim) { + int bufferIndex = 0; for (unsigned int j = 0; j < patchIDs_.size(); j++) { // Get the ID of the current patch @@ -65,7 +66,7 @@ void preciceAdapter::FSI::DisplacementDelta::read(double* buffer, const unsigned forAll(cellDisplacement_->boundaryField()[patchID], i) { for (unsigned int d = 0; d < dim; ++d) - cellDisplacement_->boundaryFieldRef()[patchID][i][d] = buffer[i * dim + d]; + cellDisplacement_->boundaryFieldRef()[patchID][i][d] = buffer[bufferIndex++]; } // Get a reference to the displacement on the point patch in order to overwrite it vectorField& pointDisplacementFluidPatch( @@ -88,7 +89,7 @@ void preciceAdapter::FSI::DisplacementDelta::read(double* buffer, const unsigned forAll(pointDisplacement_->boundaryFieldRef()[patchID], i) { for (unsigned int d = 0; d < dim; ++d) - pointDisplacementFluidPatch[i][d] += buffer[i * dim + d]; + pointDisplacementFluidPatch[i][d] += buffer[bufferIndex++]; } } } diff --git a/FSI/Force.C b/FSI/Force.C index 5f829645..a1ab6651 100644 --- a/FSI/Force.C +++ b/FSI/Force.C @@ -48,6 +48,7 @@ void preciceAdapter::FSI::Force::read(double* buffer, const unsigned int dim) // Here we assume that a force volVectorField exists, which is used by // the OpenFOAM solver + int bufferIndex = 0; // Set boundary forces for (unsigned int j = 0; j < patchIDs_.size(); j++) { @@ -63,7 +64,7 @@ void preciceAdapter::FSI::Force::read(double* buffer, const unsigned int dim) forAll(force, i) { for (unsigned int d = 0; d < dim; ++d) - force[i][d] = buffer[i * dim + d]; + force[i][d] = buffer[bufferIndex++]; } } else if (this->locationType_ == LocationType::faceNodes) diff --git a/FSI/ForceBase.C b/FSI/ForceBase.C index 57f36875..4e9168b0 100644 --- a/FSI/ForceBase.C +++ b/FSI/ForceBase.C @@ -148,6 +148,7 @@ void preciceAdapter::FSI::ForceBase::writeToBuffer(double* buffer, // Pressure boundary field const auto& pb = mesh_.lookupObject("p").boundaryField(); + int bufferIndex = 0; // For every boundary patch of the interface for (const label patchID : patchIDs_) { @@ -183,7 +184,7 @@ void preciceAdapter::FSI::ForceBase::writeToBuffer(double* buffer, forAll(forceField.boundaryField()[patchID], i) { for (unsigned int d = 0; d < dim; ++d) - buffer[i * dim + d] = + buffer[bufferIndex++] = forceField.boundaryField()[patchID][i][d]; } } diff --git a/changelog-entries/289.md b/changelog-entries/289.md new file mode 100644 index 00000000..71486dd8 --- /dev/null +++ b/changelog-entries/289.md @@ -0,0 +1 @@ +- Fixed incorrect reading and writing of the FSI-related data buffers, if multiple patches are combined in an interface mesh. From 4e65b8b08c878cb4453d07ee628e64c8089a011b Mon Sep 17 00:00:00 2001 From: Gerasimos Chourdakis Date: Fri, 19 May 2023 12:15:13 +0300 Subject: [PATCH 2/3] Markdown-lint: Disable MD034 (#290) --- .markdownlint.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.markdownlint.json b/.markdownlint.json index 151ee39b..979cb285 100644 --- a/.markdownlint.json +++ b/.markdownlint.json @@ -1,4 +1,5 @@ { "MD013": false, - "MD033": false -} \ No newline at end of file + "MD033": false, + "MD034": false +} From 58146217c4294889592b95c772d75578ebb0465c Mon Sep 17 00:00:00 2001 From: David Schneider Date: Wed, 14 Jun 2023 14:33:28 +0200 Subject: [PATCH 3/3] Update changelog entries and bump version --- Adapter.C | 2 +- CHANGELOG.md | 6 ++++++ changelog-entries/289.md | 1 - 3 files changed, 7 insertions(+), 2 deletions(-) delete mode 100644 changelog-entries/289.md diff --git a/Adapter.C b/Adapter.C index b82a5bc2..c4c3e988 100644 --- a/Adapter.C +++ b/Adapter.C @@ -10,7 +10,7 @@ preciceAdapter::Adapter::Adapter(const Time& runTime, const fvMesh& mesh) : runTime_(runTime), mesh_(mesh) { - adapterInfo("Loaded the OpenFOAM-preCICE adapter - v1.2.2.", "info"); + adapterInfo("Loaded the OpenFOAM-preCICE adapter - v1.2.3.", "info"); return; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 7372bdf5..5fe99340 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ Read more details in the issue [#52: Releases and versioning](https://github.com +## [v1.2.3] 2023-06-14 + +### Fixed + +- Fixed incorrect reading and writing of the FSI-related data buffers, if multiple patches are combined in an interface mesh [commit 846affd](https://github.com/precice/openfoam-adapter/commit/846affdd00ea8024cee98f34d8ad4205fdc83c5f). + ## [v1.2.2] 2022-01-03 ### Changed diff --git a/changelog-entries/289.md b/changelog-entries/289.md deleted file mode 100644 index 71486dd8..00000000 --- a/changelog-entries/289.md +++ /dev/null @@ -1 +0,0 @@ -- Fixed incorrect reading and writing of the FSI-related data buffers, if multiple patches are combined in an interface mesh.