From f90c7b17fc9705fae032187a8f39e70423690e07 Mon Sep 17 00:00:00 2001 From: Vaggelis Papoutsis Date: Fri, 22 Nov 2024 16:56:43 +0200 Subject: [PATCH] ENH: Allow setting the initial values of the design variables in topology optimisation, through a volScalarfield named alpha. The order of precedence is (top to bottom): - values read from time/uniform/topOVars (used also for continuation) - values read from 0/alpha (can be easily set with topoSet + setFields) - uniform zero --- .../topODesignVariables/topODesignVariables.C | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.C index 5aa934df68..6af1794f14 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/designVariables/topODesignVariables/topODesignVariables.C @@ -223,26 +223,32 @@ void Foam::topODesignVariables::readField { SubField(*this, mesh_.nCells(), offset) = scalarField(name, *this, mesh_.nCells()); - - /* - // Set values next to IO boundaries if needed - if (setIOValues) + } + else + { + IOobject header + ( + name, + mesh_.time().timeName(), + mesh_, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ); + if (header.typeHeaderOk()) { - forAll(mesh_.boundary(), patchI) + Info<< "Setting design variables based on the alpha field " + << nl << endl; + volScalarField volField + ( + header, + mesh_ + ); + const scalarField& field = volField.primitiveField(); + forAll(field, cI) { - const fvPatch& patch = mesh_.boundary()[patchI]; - if (patch.type() == "patch") - { - const labelList& faceCells = patch.faceCells(); - const scalarField& pf = volField.boundaryField()[patchI]; - forAll(faceCells, fI) - { - scalarField::operator[](offset + faceCells[fI]) = pf[fI]; - } - } + scalarField::operator[](offset + cI) = field[cI]; } } - */ } }