-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,15 @@ void preciceAdapter::CouplingDataUser::setLocationsType(LocationType locationsTy | |
locationType_ = locationsType; | ||
} | ||
|
||
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"); | ||
} | ||
Comment on lines
+39
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
|
||
|
||
void preciceAdapter::CouplingDataUser::checkDataLocation(const bool meshConnectivity) const | ||
{ | ||
if (this->isLocationTypeSupported(meshConnectivity) == false) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,6 +330,7 @@ void preciceAdapter::Interface::createBuffer() | |
// Will the interface buffer need to store 3D vector data? | ||
bool needsVectorData = false; | ||
int dataBufferSize = 0; | ||
bool requiresGradientData = false; | ||
|
||
// Check all the coupling data readers | ||
for (uint i = 0; i < couplingDataReaders_.size(); i++) | ||
|
@@ -347,6 +348,10 @@ void preciceAdapter::Interface::createBuffer() | |
{ | ||
needsVectorData = true; | ||
} | ||
if (precice_.isGradientDataRequired(couplingDataWriters_.at(i)->dataID())) | ||
{ | ||
requiresGradientData = true; | ||
} | ||
} | ||
|
||
// Set the appropriate buffer size | ||
|
@@ -367,6 +372,10 @@ void preciceAdapter::Interface::createBuffer() | |
// 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](); | ||
if (requiresGradientData) | ||
{ | ||
gradientBuffer_.resize(dim_ * dataBufferSize); | ||
} | ||
} | ||
|
||
void preciceAdapter::Interface::readCouplingData() | ||
|
@@ -430,6 +439,15 @@ void preciceAdapter::Interface::writeCouplingData() | |
numDataLocations_, | ||
vertexIDs_, | ||
dataBuffer_); | ||
|
||
if (precice_.isGradientDataRequired(couplingDataWriter->dataID())) | ||
{ | ||
couplingDataWriter->writeGradients(gradientBuffer_, dim_); | ||
precice_.writeBlockVectorGradientData(couplingDataWriter->dataID(), | ||
numDataLocations_, | ||
vertexIDs_, | ||
gradientBuffer_.data()); | ||
Comment on lines
+443
to
+449
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
else | ||
{ | ||
|
@@ -438,6 +456,15 @@ void preciceAdapter::Interface::writeCouplingData() | |
numDataLocations_, | ||
vertexIDs_, | ||
dataBuffer_); | ||
|
||
if (precice_.isGradientDataRequired(couplingDataWriter->dataID())) | ||
{ | ||
couplingDataWriter->writeGradients(gradientBuffer_, dim_); | ||
precice_.writeBlockScalarGradientData(couplingDataWriter->dataID(), | ||
numDataLocations_, | ||
vertexIDs_, | ||
gradientBuffer_.data()); | ||
} | ||
} | ||
} | ||
// } | ||
|
There was a problem hiding this comment.
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-90c837067b5e748c5bc1af9d24a5ab6f0a5f7801bd91685900c27491c259a830The main difference is that:
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.