Skip to content

Add gradient data write functionality#233

Draft
davidscn wants to merge 2 commits intoprecice:developfrom
davidscn:gradient-mapping
Draft

Add gradient data write functionality#233
davidscn wants to merge 2 commits intoprecice:developfrom
davidscn:gradient-mapping

Conversation

@davidscn
Copy link
Member

@davidscn davidscn commented Jul 18, 2022

... in case gradient data is required for the mapping.

The current changes only implement the functionality for a simple CHT case. We need to go through all relevant fields and have a look, where it makes sense to support this feature. We also need to find a proper solution in order to avoid code duplication in all the fields, as the 'write' step looks similar for all fields (mainly depending on the number of data components).

TODO list:

  • I updated the documentation in docs/
  • I added a changelog entry in changelog-entries/ (create directory if missing)

Copy link
Member

@MakisH MakisH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We kind of forgot about this PR in the middle of other changes. @davidscn we can also include this into the next release, we just need use/test cases.

Additional fields that could be useful would be pressure and velocity gradients in the FF module.

The changes make sense to me, and it looks like the API calls already correspond to preCICE v3.

Still needs to be documented and I would say we also need some kind of test case, to be able to maintain the feature.

I have not tested anything yet.

Comment on lines +39 to +45
void preciceAdapter::CouplingDataUser::writeGradients(std::vector<double>& gradientBuffer, const unsigned int dim)
{
adapterInfo("Data \"" + getDataName() + "\" does not support writing gradients. Please select a different "
"data or a different mapping configuration, which does not require "
"additional gradient information.",
"error");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way to default to a "not implemented" error message!

Only typo: change "a data" to just "data" or make it also "a different data configuration". ("data" is not countable)

Comment on lines +59 to +72
void preciceAdapter::CHT::Temperature::writeGradients(std::vector<double>& gradientBuffer, const unsigned int dim)
{
for (const label patchID : patchIDs_)
{
const auto& TGrad = fvc::grad(*T_);
forAll(TGrad().boundaryField()[patchID], i)
{
for (unsigned int d = 0; d < dim; ++d)
{
gradientBuffer[i * dim + d] = TGrad().boundaryField()[patchID][i][d];
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This essentially addresses the same problem as @thesamriel implemented in FF/TemperatureGradient.C in https://github.com/precice/openfoam-adapter/pull/281/files#diff-90c837067b5e748c5bc1af9d24a5ab6f0a5f7801bd91685900c27491c259a830

The main difference is that:

  • This PR gives the gradient of (temperature) to preCICE, as gradient data
  • Updates to the FF module #281 gives the (gradient of temperature) to preCICE, as normal data values

Would these two PRs need to be aligned somehow? @thesamriel I assume that this still cannot be shaped as a replacement for the respective addition of #281.

Comment on lines +443 to +449
if (precice_.isGradientDataRequired(couplingDataWriter->dataID()))
{
couplingDataWriter->writeGradients(gradientBuffer_, dim_);
precice_.writeBlockVectorGradientData(couplingDataWriter->dataID(),
numDataLocations_,
vertexIDs_,
gradientBuffer_.data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One example for vector data would be velocity. We should also implement that (in this or in a follow-up PR), otherwise this case will be completely unused for now.

@MakisH
Copy link
Member

MakisH commented Feb 25, 2026

Regarding the "avoiding code duplication": We now have a generic reader/writer (implemented by @vidulejs in #346).

We also added some new features (e.g., new adapter config schema configuration) only to that, and in v2 we would make that (with a better architecture and naming) as the default, still allowing special case implementations, for anything that we cannot handle just with an operation field.

Therefore, if this PR is still relevant, we could directly port it to the generic module (anytime) and forget about all other fields (Temperature is already supported). The user would then need to decide if the operation makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants