Implement operation gradient in Generic module#398
Conversation
…calar fields (like PressureGradientFull). Gradient operation will change dataType_ from scalar to vector.
…ter and preCICE config.
| 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 |
There was a problem hiding this comment.
Unlike PressureGradientFull, I don't store the resulting volVectorField as a member variable. I'm using Foam::tmp<volVectorField> to temporarily allocate it and automatically deallocate it once it's out of scope. Would this be a performance problem - allocating and deallocating memory for each write? Alternatively, we could create a shared buffer to store the scalar field gradients if configured.
There was a problem hiding this comment.
Discussed in a meeting: This should indeed have performance implications, better allocate in the constructor and reuse.
MakisH
left a comment
There was a problem hiding this comment.
Looks good overall, I have not tested it.
| 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 |
There was a problem hiding this comment.
Discussed in a meeting: This should indeed have performance implications, better allocate in the constructor and reuse.
Implemented
operation gradient;for volume & surface scalar fields in the new Generic module. The code closely followsPressureGradientFull.C. The gradient operation on a scalar field will result in a vector field. Therefore, whenoperation == 'gradient', thedataType_will become vector. The user has to make sure it's also the case in the preCICE config.For that reason I implemented a new check in
Interface::addCouplingDataWriter, where it will find if there's a vector/scalar data mismatch between the preCICE config and the adapter. If the user configured operation gradient, they will get a more specific error:Previously the error would be thrown by preCICE and say that the number of vertices is incorrect.
TODO list:
docs/changelog-entries/(create directory if missing)