Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add gradient data write functionality #233

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

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.

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.

None yet

2 participants