-
-
Notifications
You must be signed in to change notification settings - Fork 105
Implement operation gradient in Generic module #398
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
base: develop
Are you sure you want to change the base?
Changes from all commits
dcbbe9e
5be1ad6
454d519
dd665eb
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 |
|---|---|---|
|
|
@@ -18,7 +18,14 @@ preciceAdapter::Generic::ScalarFieldCoupler::ScalarFieldCoupler( | |
| mesh_(mesh), | ||
| fieldConfig_(fieldConfig) | ||
| { | ||
| dataType_ = scalar; | ||
| if (fieldConfig_.operation == "gradient") | ||
| { | ||
| dataType_ = vector; | ||
| } | ||
| else | ||
| { | ||
| dataType_ = scalar; | ||
| } | ||
| } | ||
|
|
||
| void preciceAdapter::Generic::ScalarFieldCoupler::initialize() | ||
|
|
@@ -30,18 +37,92 @@ void preciceAdapter::Generic::ScalarFieldCoupler::initialize() | |
| adapterInfo("Generic module: The surface-normal-gradient operation is only supported for faceCenters location type.", "error"); | ||
| } | ||
| } | ||
|
|
||
| if (fieldConfig_.operation == "gradient") | ||
| { | ||
| adapterInfo("Generic module: The gradient operation is not yet supported for scalar fields. Maybe you meant surface-normal-gradient?", "error"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| std::size_t preciceAdapter::Generic::ScalarFieldCoupler::write(double* buffer, bool meshConnectivity, const unsigned int dim) | ||
| { | ||
| int bufferIndex = 0; | ||
|
|
||
| if (fieldConfig_.operation == "gradient") | ||
| { | ||
| // Calculate the full gradient (volVectorField) | ||
| // Temporary field discarded afterwards | ||
| Foam::tmp<volVectorField> tmpObject(fvc::grad(*scalarField_)); | ||
| const volVectorField& gradScalarField = tmpObject(); // dereference | ||
|
Comment on lines
+47
to
+52
Collaborator
Author
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. Unlike
Member
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. Discussed in a meeting: This should indeed have performance implications, better allocate in the constructor and reuse. |
||
|
|
||
| if (this->locationType_ == LocationType::volumeCenters) | ||
| { | ||
| if (cellSetNames_.empty()) | ||
| { | ||
| for (const auto& cell : gradScalarField.internalField()) | ||
| { | ||
| // x-dimension | ||
| buffer[bufferIndex++] = cell.x(); | ||
|
|
||
| // y-dimension | ||
| buffer[bufferIndex++] = cell.y(); | ||
|
|
||
| if (dim == 3) | ||
| { | ||
| // z-dimension | ||
| buffer[bufferIndex++] = cell.z(); | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| for (const auto& cellSetName : cellSetNames_) | ||
| { | ||
| cellSet overlapRegion(scalarField_->mesh(), cellSetName); | ||
| const labelList& cells = overlapRegion.toc(); | ||
|
|
||
| for (const auto& currentCell : cells) | ||
| { | ||
| // x-dimension | ||
| buffer[bufferIndex++] = gradScalarField.internalField()[currentCell].x(); | ||
|
|
||
| // y-dimension | ||
| buffer[bufferIndex++] = gradScalarField.internalField()[currentCell].y(); | ||
|
|
||
| if (dim == 3) | ||
| { | ||
| // z-dimension | ||
| buffer[bufferIndex++] = gradScalarField.internalField()[currentCell].z(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // For every boundary patch of the interface | ||
| for (uint j = 0; j < patchIDs_.size(); j++) | ||
| { | ||
| int patchID = patchIDs_.at(j); | ||
|
|
||
| // For every cell of the patch | ||
| forAll(gradScalarField.boundaryField()[patchID], i) | ||
| { | ||
| // Copy the velocity into the buffer | ||
| // x-dimension | ||
| buffer[bufferIndex++] = | ||
| gradScalarField.boundaryField()[patchID][i].x(); | ||
|
|
||
| // y-dimension | ||
| buffer[bufferIndex++] = | ||
| gradScalarField.boundaryField()[patchID][i].y(); | ||
|
|
||
| if (dim == 3) | ||
| { | ||
| // z-dimension | ||
| buffer[bufferIndex++] = | ||
| gradScalarField.boundaryField()[patchID][i].z(); | ||
| } | ||
| } | ||
| } | ||
| return bufferIndex; | ||
| } | ||
|
|
||
| if (fieldConfig_.operation == "surface-normal-gradient") | ||
| { | ||
| // For every boundary patch of the interface | ||
|
|
@@ -125,6 +206,11 @@ void preciceAdapter::Generic::ScalarFieldCoupler::read(double* buffer, const uns | |
| { | ||
| int bufferIndex = 0; | ||
|
|
||
| if (fieldConfig_.operation == "gradient" || fieldConfig_.operation == "surface-normal-gradient") | ||
| { | ||
| adapterInfo("Generic module: The gradient operation is only supported for writing.", "error"); | ||
| } | ||
|
|
||
MakisH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (this->locationType_ == LocationType::volumeCenters) | ||
| { | ||
| if (cellSetNames_.empty()) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.