66 labelList activeVarsInCPs = volBSplinesBase_.getActiveDesignVariables();
71 constraint_().computeActiveDesignVariables(activeVarsInCPs);
80 scalarField cpsScalar(constraint_().designVariablesToControlPoints(dvs));
90 cpI.x() = cpsScalar[varID++];
91 cpI.y() = cpsScalar[varID++];
92 cpI.z() = cpsScalar[varID++];
94 boxI.setControlPoints(cps);
102 scalarField cpsScalar(3*volBSplinesBase_.getTotalControlPointsNumber());
108 for (
const vector& cpI : cps)
110 cpsScalar[varID++] = cpI.x();
111 cpsScalar[varID++] = cpI.y();
112 cpsScalar[varID++] = cpI.z();
117 scalarField::operator=
118 (
constraint_().controlPointsToDesignVariables(cpsScalar));
128 scalarField cpsScalar(3*volBSplinesBase_.getTotalControlPointsNumber());
133 const label nCPs(boxI.getControlPoints().size());
134 for (label cpI = 0; cpI < nCPs; ++cpI)
136 cpsScalar[varID++] = controlPoints[cpI].x();
137 cpsScalar[varID++] = controlPoints[cpI].y();
138 cpsScalar[varID++] = controlPoints[cpI].z();
143 scalarField::operator=
144 (
constraint_().controlPointsToDesignVariables(cpsScalar));
155 readBounds(lowerBounds_,
"lower", -1);
166 const word& boundsName,
171 if (dict_.found(boundsName +
"CPBounds"))
175 vector CPBounds(dict_.get<
vector>(boundsName +
"CPBounds"));
180 const label nCPs(boxI.getControlPoints().size());
181 for (label iCP = 0; iCP < nCPs; ++iCP)
183 bounds()[varID++] = CPBounds.x();
184 bounds()[varID++] = CPBounds.y();
185 bounds()[varID++] = CPBounds.z();
198 <<
"Reading " << boundsName <<
"Bounds from dict " <<
endl;
200 (
new scalarField(boundsName +
"Bounds", *
this, getVars().size()));
203 else if (nonOverlappingCPs_)
206 <<
"Setting " << boundsName <<
"Bounds from nonOverlappingCPs"
216 for (label idir = 0; idir < 3; ++idir)
219 (
max(cps.component(idir)) -
min(cps.component(idir)))
220 /scalar(nCPsDir[idir] - 1);
222 const label nCPs(boxI.getControlPoints().size());
223 for (label iCP = 0; iCP < nCPs; ++iCP)
249 word(
"optimisation")/
word(
"controlPoints")/boxI.name()
250 +
name + mesh_.time().timeName() +
".csv"
253 file<<
"\"Points : 0\", \"Points : 1\", \"Points : 2\","
254 <<
"\"i\", \"j\", \"k\""<<
endl;
257 const label nCPsU = boxI.basisU().nCPs();
258 const label nCPsV = boxI.basisV().nCPs();
261 const label
k = cpI/label(nCPsU*nCPsV);
262 const label j = (cpI -
k*nCPsU*nCPsV)/nCPsU;
263 const label i = (cpI -
k*nCPsU*nCPsV - j*nCPsU);
265 file<<
bounds[3*cpI + passed] <<
", "
266 <<
bounds[3*cpI + 1 + passed] <<
", "
267 <<
bounds[3*cpI + 2 + passed] <<
", "
272 passed += 3*cps.size();
288 displMethodPtr_->setControlField(cpMovement);
294 volBSplinesBase_.computeBoundaryDisplacement
297 parametertisedPatches_.toc()
306 mesh_.time().timeName(),
316 for (
const label pI : parametertisedPatches_)
318 dx.boundaryField()[pI].setInInternalField
320 dx.primitiveFieldRef(),
321 vectorField(newPoints, mesh_.boundaryMesh()[pI].meshPoints())
333Foam::volumetricBSplinesDesignVariables::volumetricBSplinesDesignVariables
344 "volumetricBSplinesDesignVariables",
348 IOobject::READ_IF_PRESENT,
353 volBSplinesBase_(const_cast<volBSplinesBase&>(volBSplinesBase::
New(
mesh))),
354 nonOverlappingCPs_(dict_.getOrDefault<bool>(
"nonOverlappingCPs", false)),
355 updateBounds_(dict_.getOrDefault<bool>(
"updateBounds", true)),
356 constraint_(morphingBoxConstraint::
New(
mesh,
dict, *this))
361 scalarField::operator=
389 volBSplinesBase_.getTotalControlPointsNumber(),
402 cpMovement[iCP].x() = correctionCPs[3*iCP];
403 cpMovement[iCP].y() = correctionCPs[3*iCP + 1];
404 cpMovement[iCP].z() = correctionCPs[3*iCP + 2];
406 volBSplinesBase_.boundControlPointMovement(cpMovement);
415 tmp<vectorField> tcpMovement = controlPointMovement(
correction);
419 setDisplacement(cpMovement);
457 constraint_().postProcessSens
476 lowerBounds_().writeEntry(
"lowerBounds",
os);
477 writeBounds(lowerBounds_(),
"lowerBounds");
484 return constraint_().writeData(
os);
493 const displacementMethod& dm = displMethodPtr_();
496 Vector<label> decomposed = volBSplinesBase_.decomposeDV(varID);
497 const label boxI = decomposed.x();
498 const label cpILocal = decomposed.y();
499 const label dir = decomposed.z();
514 Vector<label> decomposed = volBSplinesBase_.decomposeDV(varID);
515 const label boxI = decomposed.x();
516 const label cpILocal = decomposed.y();
517 const label dir = decomposed.z();
531 Vector<label> decomposed = volBSplinesBase_.decomposeDV(varID);
532 const label boxI = decomposed.
x();
533 const label cpILocal = decomposed.
y();
534 const label dir = decomposed.
z();
539 dndbBasedSensitivities(patchI, cpILocal,
false)
551 Vector<label> decomposed = volBSplinesBase_.decomposeDV(varID);
552 const label boxI = decomposed.
x();
553 const label cpILocal = decomposed.
y();
554 const label dir = decomposed.
z();
569 Vector<label> decomposed = volBSplinesBase_.decomposeDV(varID);
570 const label boxI = decomposed.
x();
571 const label cpILocal = decomposed.
y();
572 const label dir = decomposed.
z();
586 mesh_.time().timeName(),
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void operator+=(const UList< scalar > &)
void writeEntry(const word &keyword, Ostream &os) const
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const Time & time() const noexcept
Return Time associated with the objectRegistry.
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
NURBS3DVolume morpher. Includes support functions for gradient computations Base class providing supp...
tmp< pointTensorField > getDxDb(const label cpI)
Get dxCartesiandb for a certain control point.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
label size() const noexcept
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
const Cmpt & x() const noexcept
Access to the vector x component.
const Cmpt & z() const noexcept
Access to the vector z component.
const Cmpt & y() const noexcept
Access to the vector y component.
Abstract base class for adjoint-based sensitivities.
const adjointSolver & getAdjointSolver() const
Const access to adjoint solver.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
autoPtr< scalarField > upperBounds_
Upper bounds of the design variables.
autoPtr< scalar > maxInitChange_
Maximum design variables' change in the first optimisation cycle.
void readBounds(autoPtr< scalar > lowerBoundPtr=nullptr, autoPtr< scalar > upperBoundPtr=nullptr)
Read bounds for design variables, if present.
virtual const scalarField & getVars() const
Get the design variables.
autoPtr< scalarField > lowerBounds_
Lower bounds of the design variables.
labelList activeDesignVariables_
Which of the design variables will be updated.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Abstract base class for displacement methods, which are a set or wrapper classes allowing to change t...
A class for handling file names.
Mesh data needed to do the Finite Volume discretisation.
localIOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Abstract base class for defining constraints for the control points of volumetric B-Splines morphing ...
void interpolate(const GeometricField< Type, pointPatchField, pointMesh > &, GeometricField< Type, fvPatchField, volMesh > &) const
Interpolate from pointField to volField.
Abstract base class for defining design variables for shape optimisation.
virtual void resetDesignVariables()
Reset to starting point of line search.
virtual void moveMesh()
Move mesh based on displacementMethod.
autoPtr< displacementMethod > displMethodPtr_
Mesh movement mechanism.
static autoPtr< shapeDesignVariables > New(fvMesh &mesh, const dictionary &dict)
Construct and return the selected shapeDesignVariables.
labelHashSet parametertisedPatches_
Patches to be moved by the design variables.
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &adjointSens)
Add part of sensitivity derivatives related to geometry variations.
const word & solverName() const
Return the solver name.
A class for managing temporary objects.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Class constructing a number of volumetric B-Splines boxes, read from dynamicMeshDict....
Volumetric B-Splines design variables for shape optimisation.
virtual void update(scalarField &correction)
Update design variables based on a given correction.
virtual void evolveNumber()
For design variables with a dynamic character (i.e. changing.
virtual tmp< vectorField > dSdb(const label patchI, const label varID) const
Get dSdb for given design variable and patch.
virtual scalar computeEta(scalarField &correction)
Compute eta if not set in the first step.
virtual void resetDesignVariables()
Reset to starting point of line search.
void controlPointsToDesignVariables()
Set the design variables based on the current control points.
void setDisplacement(const vectorField &cpMovement)
Set the field driving the displacement method.
virtual bool writeData(Ostream &os) const
Write fields to support continuation.
void readBounds(autoPtr< scalar > lowerBoundPtr=nullptr, autoPtr< scalar > upperBoundPtr=nullptr)
Read bounds for design variables, if present.
void designVariablesToControlPoints()
Set control points based on current design variables values.
void setActiveDesignVariables()
Set IDs of active design variables.
virtual bool globalSum() const
Whether to use global sum when computing matrix-vector products in update methods.
void writeBounds(const scalarField &bounds, const word &name) const
Write current bounds to file.
bool updateBounds_
Should the bounds of the non-overlapping control points be updated in each optimisation cycle.
tmp< vectorField > controlPointMovement(const scalarField &correction)
Transform correction of design variables to control points movement.
virtual tmp< vectorField > dxdbVol(const label varID) const
Get dxdb for all mesh points.
virtual const labelList & activeSensitivities() const
Components of the active control points.
bool nonOverlappingCPs_
Should the control points be non-overlapping.
volBSplinesBase & volBSplinesBase_
Reference to underlaying volumetric B-Splines morpher.
virtual label sensSize() const
Size of the active control points.
autoPtr< morphingBoxConstraint > constraint_
Constraint imposed on the movement of the design variables.
virtual tmp< vectorField > dxdbFace(const label patchI, const label varID) const
Get dxdb for given design variable and patch.
virtual tmp< vectorField > dndb(const label patchI, const label varID) const
Get dndb for given design variable and patch.
virtual tmp< volVectorField > dCdb(const label varID) const
Get dCdb for given design variable.
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &adjointSens)
Assemble the sensitivity derivatives, by also applying possible constraints.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
OBJstream os(runTime.globalPath()/outputName)
#define DebugInfo
Report an information message using Foam::Info.
Namespace for bounding specifications. At the moment, mostly for tables.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
GeometricField< vector, fvPatchField, volMesh > volVectorField
const dimensionSet dimless
Dimensionless.
GeometricField< tensor, pointPatchField, pointMesh > pointTensorField
dimensionedScalar sign(const dimensionedScalar &ds)
List< label > labelList
A List of labels.
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
void unzipCol(const FieldField< Field, SymmTensor< Cmpt > > &input, const direction idx, FieldField< Field, Vector< Cmpt > > &result)
Extract a symmTensor field field column (x,y,z) == (0,1,2).
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Field< vector > vectorField
Specialisation of Field<T> for vector.
static constexpr const zero Zero
Global zero (0).
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
#define forAll(list, i)
Loop across all elements in list.