diff --git a/src/optimisation/adjointOptimisation/adjoint/global/createZeroField.H b/src/optimisation/adjointOptimisation/adjoint/global/createZeroField.H index 61b54f406d..fe16d4e97c 100644 --- a/src/optimisation/adjointOptimisation/adjoint/global/createZeroField.H +++ b/src/optimisation/adjointOptimisation/adjoint/global/createZeroField.H @@ -88,13 +88,30 @@ createZeroBoundaryPtr typedef typename GeometricField::Boundary Boundary; + // Make sure that the patchFields to be generated will be of type + // calculated, even if they are of constraint type + // Necessary to avoid unexpected behaviour when computing sensitivities + // on symmetry patches (not a good practice either way) + const fvBoundaryMesh& bm = mesh.boundary(); + wordList actualPatchTypes(bm.size(), word::null); + forAll(actualPatchTypes, pI) + { + auto patchTypeCstrIter = + fvPatchField::patchConstructorTablePtr_->cfind(bm[pI].type()); + if (patchTypeCstrIter.found()) + { + actualPatchTypes[pI] = bm[pI].type(); + } + } + autoPtr bPtr ( new Boundary ( mesh.boundary(), mesh.V()*pTraits::zero, // Dummy internal field, - calculatedFvPatchField::typeName + wordList(bm.size(), calculatedFvPatchField::typeName), + actualPatchTypes ) );