Skip to content

Commit 3404b51

Browse files
authored
Added kwargs to MPhys APIs (#248)
* Added kwargs to Mphys APIs * Fixed a small issue * Style change. * Added **kwargs to the nom_addGlobalDV API too. * Explicitely added arguments into mphys_pygeo FFD-based APIs, instead of using **kwargs. * Fixed a minor bug in the argument.
1 parent 4c762ab commit 3404b51

1 file changed

Lines changed: 160 additions & 17 deletions

File tree

pygeo/mphys/mphys_dvgeo.py

Lines changed: 160 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def nom_getDVCon(self):
229229
"""
230230

231231
def nom_addGlobalDV(
232-
self, dvName, value, func, childName=None, isComposite=False, DVGeoName=None, prependName=False
232+
self, dvName, value, func, childName=None, isComposite=False, DVGeoName=None, prependName=False, config=None
233233
):
234234
"""
235235
Add a global design variable to the DVGeo object. This is a wrapper for the DVGeo.addGlobalDV method.
@@ -273,7 +273,7 @@ def nom_addGlobalDV(
273273
dvName = DVGeoName + "_" + dvName
274274

275275
# call the dvgeo object and add this dv
276-
DVGeo.addGlobalDV(dvName, value, func, prependName=False)
276+
DVGeo.addGlobalDV(dvName, value, func, prependName=False, config=config)
277277

278278
# define the input
279279
# When composite DVs are used, input is not required for the default DVs. Now the composite DVs are
@@ -282,7 +282,16 @@ def nom_addGlobalDV(
282282
self.add_input(dvName, distributed=False, shape=len(np.atleast_1d(value)))
283283

284284
def nom_addLocalDV(
285-
self, dvName, axis="y", pointSelect=None, childName=None, isComposite=False, DVGeoName=None, prependName=False
285+
self,
286+
dvName,
287+
axis="y",
288+
pointSelect=None,
289+
childName=None,
290+
isComposite=False,
291+
DVGeoName=None,
292+
prependName=False,
293+
volList=None,
294+
config=None,
286295
):
287296
# if we have multiple DVGeos use the one specified by name
288297
DVGeo = self.nom_getDVGeo(childName=childName, DVGeoName=DVGeoName)
@@ -297,7 +306,9 @@ def nom_addLocalDV(
297306
dvName = DVGeoName + "_" + dvName
298307

299308
# add the DV to DVGeo
300-
nVal = DVGeo.addLocalDV(dvName, axis=axis, pointSelect=pointSelect, prependName=False)
309+
nVal = DVGeo.addLocalDV(
310+
dvName, axis=axis, pointSelect=pointSelect, prependName=False, config=config, volList=volList
311+
)
301312

302313
# define the input
303314
# When composite DVs are used, input is not required for the default DVs. Now the composite DVs are
@@ -507,7 +518,29 @@ def nom_addESPVariable(self, desmptr_name, isComposite=False, DVGeoName=None, **
507518
if not isComposite:
508519
self.add_input(desmptr_name, distributed=False, shape=val.shape, val=val)
509520

510-
def nom_addRefAxis(self, childName=None, DVGeoName=None, **kwargs):
521+
def nom_addRefAxis(
522+
self,
523+
name,
524+
childName=None,
525+
DVGeoName=None,
526+
curve=None,
527+
xFraction=None,
528+
yFraction=None,
529+
zFraction=None,
530+
volumes=None,
531+
rotType=5,
532+
axis="x",
533+
alignIndex=None,
534+
rotAxisVar=None,
535+
rot0ang=None,
536+
rot0axis=[1, 0, 0],
537+
includeVols=[],
538+
ignoreInd=[],
539+
raySize=1.5,
540+
):
541+
# TODO: we should change `volume` to `volList`, to be consistent with other APIs.
542+
# But doing this may create backward incompatibility. So we will use `volumes` for now
543+
511544
# if we have multiple DVGeos use the one specified by name
512545
DVGeo = self.nom_getDVGeo(childName=childName, DVGeoName=DVGeoName)
513546

@@ -516,7 +549,23 @@ def nom_addRefAxis(self, childName=None, DVGeoName=None, **kwargs):
516549
raise RuntimeError(f"Only FFD-based DVGeo objects can use reference axes, not type: {type(DVGeo).__name__}")
517550

518551
# add ref axis to this DVGeo
519-
return DVGeo.addRefAxis(**kwargs)
552+
return DVGeo.addRefAxis(
553+
name=name,
554+
curve=curve,
555+
xFraction=xFraction,
556+
yFraction=yFraction,
557+
zFraction=zFraction,
558+
volumes=volumes,
559+
rotType=rotType,
560+
axis=axis,
561+
alignIndex=alignIndex,
562+
rotAxisVar=rotAxisVar,
563+
rot0ang=rot0ang,
564+
rot0axis=rot0axis,
565+
includeVols=includeVols,
566+
ignoreInd=ignoreInd,
567+
raySize=raySize,
568+
)
520569
# add ref axis to the specified child
521570

522571
"""
@@ -531,6 +580,7 @@ def nom_addThicknessConstraints2D(
531580
nSpan,
532581
nChord,
533582
scaled=True,
583+
addToPyOpt=True,
534584
surfaceName="default",
535585
DVGeoName="default",
536586
compNames=None,
@@ -543,6 +593,7 @@ def nom_addThicknessConstraints2D(
543593
nChord,
544594
name=name,
545595
scaled=scaled,
596+
addToPyOpt=addToPyOpt,
546597
surfaceName=surfaceName,
547598
DVGeoName=DVGeoName,
548599
compNames=compNames,
@@ -557,6 +608,7 @@ def nom_addThicknessConstraints1D(
557608
nCon,
558609
axis,
559610
scaled=True,
611+
addToPyOpt=True,
560612
surfaceName="default",
561613
DVGeoName="default",
562614
compNames=None,
@@ -568,6 +620,7 @@ def nom_addThicknessConstraints1D(
568620
axis,
569621
name=name,
570622
scaled=scaled,
623+
addToPyOpt=addToPyOpt,
571624
surfaceName=surfaceName,
572625
DVGeoName=DVGeoName,
573626
compNames=compNames,
@@ -583,6 +636,7 @@ def nom_addVolumeConstraint(
583636
nSpan=10,
584637
nChord=10,
585638
scaled=True,
639+
addToPyOpt=True,
586640
surfaceName="default",
587641
DVGeoName="default",
588642
compNames=None,
@@ -621,14 +675,15 @@ def nom_addVolumeConstraint(
621675
nChord=nChord,
622676
scaled=scaled,
623677
name=name,
678+
addToPyOpt=addToPyOpt,
624679
surfaceName=surfaceName,
625680
DVGeoName=DVGeoName,
626681
compNames=compNames,
627682
)
628683
self.add_output(name, distributed=False, val=1.0)
629684

630685
def nom_addSurfaceAreaConstraint(
631-
self, name, scaled=True, surfaceName="default", DVGeoName="default", compNames=None
686+
self, name, scaled=True, addToPyOpt=True, surfaceName="default", DVGeoName="default", compNames=None
632687
):
633688
"""
634689
Add a DVCon surface area constraint to the problem
@@ -650,12 +705,17 @@ def nom_addSurfaceAreaConstraint(
650705
"""
651706

652707
self.DVCon.addSurfaceAreaConstraint(
653-
name=name, scaled=scaled, surfaceName=surfaceName, DVGeoName=DVGeoName, compNames=compNames
708+
name=name,
709+
scaled=scaled,
710+
addToPyOpt=addToPyOpt,
711+
surfaceName=surfaceName,
712+
DVGeoName=DVGeoName,
713+
compNames=compNames,
654714
)
655715
self.add_output(name, distributed=False, val=1.0)
656716

657717
def nom_addProjectedAreaConstraint(
658-
self, name, axis, scaled=True, surface_name="default", DVGeoName="default", compNames=None
718+
self, name, axis, scaled=True, addToPyOpt=True, surface_name="default", DVGeoName="default", compNames=None
659719
):
660720
"""
661721
Add a DVCon projected area constraint to the problem
@@ -679,36 +739,117 @@ def nom_addProjectedAreaConstraint(
679739
"""
680740

681741
self.DVCon.addProjectedAreaConstraint(
682-
axis, name=name, scaled=scaled, surfaceName=surface_name, DVGeoName=DVGeoName, compNames=compNames
742+
axis,
743+
name=name,
744+
scaled=scaled,
745+
addToPyOpt=addToPyOpt,
746+
surfaceName=surface_name,
747+
DVGeoName=DVGeoName,
748+
compNames=compNames,
683749
)
684750
self.add_output(name, distributed=False, val=1.0)
685751

686-
def nom_add_LETEConstraint(self, name, volID, faceID, topID=None, childName=None):
687-
self.DVCon.addLeTeConstraints(volID, faceID, name=name, topID=topID, childName=childName)
752+
def nom_add_LETEConstraint(
753+
self,
754+
name,
755+
volID,
756+
faceID,
757+
topID=None,
758+
indSetA=None,
759+
indSetB=None,
760+
config=None,
761+
childName=None,
762+
comp=None,
763+
DVGeoName="default",
764+
):
765+
self.DVCon.addLeTeConstraints(
766+
volID=volID,
767+
faceID=faceID,
768+
topID=topID,
769+
indSetA=indSetA,
770+
indSetB=indSetB,
771+
name=name,
772+
config=config,
773+
childName=childName,
774+
comp=comp,
775+
DVGeoName=DVGeoName,
776+
)
688777
# how many are there?
689778
conobj = self.DVCon.linearCon[name]
690779
nCon = len(conobj.indSetA)
691780
self.add_output(name, distributed=False, val=np.zeros((nCon,)), shape=nCon)
692781
return nCon
693782

694-
def nom_addLERadiusConstraints(self, name, leList, nSpan, axis, chordDir):
695-
self.DVCon.addLERadiusConstraints(leList=leList, nSpan=nSpan, axis=axis, chordDir=chordDir, name=name)
783+
def nom_addLERadiusConstraints(
784+
self,
785+
name,
786+
leList,
787+
nSpan,
788+
axis,
789+
chordDir,
790+
scaled=True,
791+
addToPyOpt=True,
792+
surfaceName="default",
793+
DVGeoName="default",
794+
compNames=None,
795+
):
796+
self.DVCon.addLERadiusConstraints(
797+
leList=leList,
798+
nSpan=nSpan,
799+
axis=axis,
800+
chordDir=chordDir,
801+
name=name,
802+
scaled=scaled,
803+
addToPyOpt=addToPyOpt,
804+
surfaceName=surfaceName,
805+
DVGeoName=DVGeoName,
806+
compNames=compNames,
807+
)
696808
self.add_output(name, distributed=False, val=np.ones(nSpan), shape=nSpan)
697809

698-
def nom_addCurvatureConstraint1D(self, name, start, end, nPts, axis, **kwargs):
699-
self.DVCon.addCurvatureConstraint1D(start=start, end=end, nPts=nPts, axis=axis, name=name, **kwargs)
810+
def nom_addCurvatureConstraint1D(
811+
self,
812+
name,
813+
start,
814+
end,
815+
nPts,
816+
axis,
817+
curvatureType="mean",
818+
scaled=True,
819+
KSCoeff=1.0,
820+
addToPyOpt=True,
821+
surfaceName="default",
822+
DVGeoName="default",
823+
compNames=None,
824+
):
825+
self.DVCon.addCurvatureConstraint1D(
826+
start=start,
827+
end=end,
828+
nPts=nPts,
829+
axis=axis,
830+
name=name,
831+
curvatureType=curvatureType,
832+
scaled=scaled,
833+
KSCoeff=KSCoeff,
834+
addToPyOpt=addToPyOpt,
835+
surfaceName=surfaceName,
836+
DVGeoName=DVGeoName,
837+
compNames=compNames,
838+
)
700839
self.add_output(name, distributed=False, val=1.0)
701840

702841
def nom_addLinearConstraintsShape(
703-
self, name, indSetA, indSetB, factorA, factorB, childName=None, DVGeoName="default"
842+
self, name, indSetA, indSetB, factorA, factorB, config=None, childName=None, comp=None, DVGeoName="default"
704843
):
705844
self.DVCon.addLinearConstraintsShape(
706845
indSetA=indSetA,
707846
indSetB=indSetB,
708847
factorA=factorA,
709848
factorB=factorB,
710849
name=name,
850+
config=config,
711851
childName=childName,
852+
comp=comp,
712853
DVGeoName=DVGeoName,
713854
)
714855
lSize = len(indSetA)
@@ -724,6 +865,7 @@ def nom_addTriangulatedSurfaceConstraint(
724865
rho=50.0,
725866
heuristic_dist=None,
726867
max_perim=3.0,
868+
addToPyOpt=True,
727869
):
728870
self.DVCon.addTriangulatedSurfaceConstraint(
729871
comm=self.comm,
@@ -735,6 +877,7 @@ def nom_addTriangulatedSurfaceConstraint(
735877
heuristic_dist=heuristic_dist,
736878
max_perim=max_perim,
737879
name=name,
880+
addToPyOpt=addToPyOpt,
738881
)
739882

740883
self.add_output(f"{name}_KS", distributed=False, val=0)

0 commit comments

Comments
 (0)