diff --git a/pygeo/constraints/DVCon.py b/pygeo/constraints/DVCon.py index 0b66d7f4..3c87831e 100644 --- a/pygeo/constraints/DVCon.py +++ b/pygeo/constraints/DVCon.py @@ -24,6 +24,7 @@ ProximityConstraint, ThicknessConstraint, ThicknessToChordConstraint, + DistanceConstraint, ) from .volumeConstraint import CompositeVolumeConstraint, TriangulatedVolumeConstraint, VolumeConstraint @@ -3421,6 +3422,270 @@ def addMonotonicConstraints( config=config, ) + def addDistanceConstraints( + self, + anchored_pts, + moving_pts, + lower=1.0, + upper=3.0, + scaled=True, + scale=1.0, + name=None, + addToPyOpt=True, + DVGeoName="default", + compNames=None + ): + r""" + Add a set of distance constraints. + The values of the distance costraints is just the distance from each + element in the achored_pts to the same element in the moving_pts array. + Only the 'moving_pts' are embedded into the geometry and are updated. + + Parameters + ---------- + anchored_pts : list or array of size (N x 3) + The list of points used in the distance calculations that do not move + + moving_pts : list or array of size (N x 3) + The list of points used in the distance calculations that are + embbeded in the geometry and are updated. + + nCon : int + The number of thickness constraints to add + + axis : list or array of length 3 + The direction along which the projections will occur. + Typically this will be y or z axis ([0,1,0] or [0,0,1]) + + lower : float or array of size nCon + The lower bound for the constraint. A single float will + apply the same bounds to all constraints, while the array + option will use different bounds for each constraint. + + upper : float or array of size nCon + The upper bound for the constraint. A single float will + apply the same bounds to all constraints, while the array + option will use different bounds for each constraint. + + scaled : bool + Flag specifying whether or not the constraint is to be + implemented in a scaled fashion or not. + + * scaled=True: The initial length of each thickness + constraint is defined to be 1.0. In this case, the lower + and upper bounds are given in multiple of the initial + length. lower=0.85, upper=1.15, would allow for 15% + change in each direction from the original length. For + aerodynamic shape optimizations, this option is used + most often. + + * scaled=False: No scaling is applied and the physical lengths + must be specified for the lower and upper bounds. + + scale : float or array of size nCon + This is the optimization scaling of the + constraint. Typically this parameter will not need to be + changed. If the thickness constraints are scaled, this + already results in well-scaled constraint values, and + scale can be left at 1.0. If scaled=False, it may changed + to a more suitable value of the resulting physical + thickness have magnitudes vastly different than O(1). + + name : str + Normally this does not need to be set. Only use this if + you have multiple DVCon objects and the constraint names + need to be distinguished **or** you are using this set of + thickness constraints for something other than a direct + constraint in pyOptSparse. + + addToPyOpt : bool + Normally this should be left at the default of True. If + the values need to be processed (modified) *before* they are + given to the optimizer, set this flag to False. + + surfaceName : str + Name of the surface to project to. This should be the same + as the surfaceName provided when setSurface() was called. + For backward compatibility, the name is 'default' by default. + + DVGeoName : str + Name of the DVGeo object to compute the constraint with. You only + need to set this if you're using multiple DVGeo objects + for a problem. For backward compatibility, the name is 'default' by default + + compNames : list + If using DVGeometryMulti, the components to which the point set associated + with this constraint should be added. + If None, the point set is added to all components. + + """ + self._checkDVGeo(DVGeoName) + + typeName = "distCon" + if typeName not in self.constraints: + self.constraints[typeName] = OrderedDict() + + if name is None: + conName = "%s_distance_constraints_%d" % (self.name, len(self.constraints[typeName])) + else: + conName = name + + self.constraints[typeName][conName] = DistanceConstraint( + conName, moving_pts, anchored_pts, lower, upper, scaled, scale, self.DVGeometries[DVGeoName], addToPyOpt, compNames + ) + + def addDistanceConstraints1D( + self, + ptList, + nCon, + axis, + lower=1.0, + upper=3.0, + scaled=True, + scale=1.0, + name=None, + addToPyOpt=True, + surfaceName="default", + DVGeoName="default", + compNames=None + ): + r""" + Add a set of distance constraints oriented along a poly-line. + It is different from a thickness contraint becuase it does not project + in both direactions to define a thickness contstraint. + It always meassures the distance from a surface to a fixed point. + + See below for a schematic + + .. code-block:: text + + Planform view of the wing: The '+' are the (three dimensional) + points that are supplied in ptList: + + + Airfoil + \ + \ + ---------------------- ___ + / ---- + | -- + \ ____----- + -----x------x--------- + | | + --------------x | + \ | 2 distance constraints + \ | + \ | + x ---------- Ploy line + Parameters + ---------- + ptList : list or array of size (N x 3) where N >=2 + The list of points forming a poly-line along which the + thickness constraints will be added. + + nCon : int + The number of thickness constraints to add + + axis : list or array of length 3 + The direction along which the projections will occur. + Typically this will be y or z axis ([0,1,0] or [0,0,1]) + + lower : float or array of size nCon + The lower bound for the constraint. A single float will + apply the same bounds to all constraints, while the array + option will use different bounds for each constraint. + + upper : float or array of size nCon + The upper bound for the constraint. A single float will + apply the same bounds to all constraints, while the array + option will use different bounds for each constraint. + + scaled : bool + Flag specifying whether or not the constraint is to be + implemented in a scaled fashion or not. + + * scaled=True: The initial length of each thickness + constraint is defined to be 1.0. In this case, the lower + and upper bounds are given in multiple of the initial + length. lower=0.85, upper=1.15, would allow for 15% + change in each direction from the original length. For + aerodynamic shape optimizations, this option is used + most often. + + * scaled=False: No scaling is applied and the physical lengths + must be specified for the lower and upper bounds. + + scale : float or array of size nCon + This is the optimization scaling of the + constraint. Typically this parameter will not need to be + changed. If the thickness constraints are scaled, this + already results in well-scaled constraint values, and + scale can be left at 1.0. If scaled=False, it may changed + to a more suitable value of the resulting physical + thickness have magnitudes vastly different than O(1). + + name : str + Normally this does not need to be set. Only use this if + you have multiple DVCon objects and the constraint names + need to be distinguished **or** you are using this set of + thickness constraints for something other than a direct + constraint in pyOptSparse. + + addToPyOpt : bool + Normally this should be left at the default of True. If + the values need to be processed (modified) *before* they are + given to the optimizer, set this flag to False. + + surfaceName : str + Name of the surface to project to. This should be the same + as the surfaceName provided when setSurface() was called. + For backward compatibility, the name is 'default' by default. + + DVGeoName : str + Name of the DVGeo object to compute the constraint with. You only + need to set this if you're using multiple DVGeo objects + for a problem. For backward compatibility, the name is 'default' by default + + compNames : list + If using DVGeometryMulti, the components to which the point set associated + with this constraint should be added. + If None, the point set is added to all components. + + """ + self._checkDVGeo(DVGeoName) + + p0, p1, p2 = self._getSurfaceVertices(surfaceName=surfaceName) + + # Create mesh of intersections + constr_line = Curve(X=ptList, k=2) + s = np.linspace(0, 1, nCon) + anchored_pts = constr_line(s) + moving_pts = np.zeros((nCon, 3)) + # Project all the points + for i in range(nCon): + # Project actual node: + # we only take the up point + up, _, fail = geo_utils.projectNode(anchored_pts[i], axis, p0, p1 - p0, p2 - p0) + if fail > 0: + raise Error( + "There was an error projecting a node " + "at (%f, %f, %f) with normal (%f, %f, %f)." % (anchored_pts[i, 0], anchored_pts[i, 1], anchored_pts[i, 2], axis[0], axis[1], axis[2]) + ) + moving_pts[i] = up + + typeName = "distCon" + if typeName not in self.constraints: + self.constraints[typeName] = OrderedDict() + + if name is None: + conName = "%s_distance_constraints_%d" % (self.name, len(self.constraints[typeName])) + else: + conName = name + + self.constraints[typeName][conName] = DistanceConstraint( + conName, moving_pts, anchored_pts, lower, upper, scaled, scale, self.DVGeometries[DVGeoName], addToPyOpt, compNames + ) + def _checkDVGeo(self, name="default"): """check if DVGeo exists""" if name not in self.DVGeometries.keys(): diff --git a/pygeo/constraints/radiusConstraint.py b/pygeo/constraints/radiusConstraint.py index 7e758b7f..fd6e4594 100644 --- a/pygeo/constraints/radiusConstraint.py +++ b/pygeo/constraints/radiusConstraint.py @@ -182,6 +182,7 @@ def writeTecplot(self, handle): to the open file handle """ r, c = self.computeCircle(self.coords) + p1, p2, p3 = self.splitPointSets(self.coords) # Compute origin and unit vectors (xi, eta) of 2d space _, nxi, neta = self.computeReferenceFrames(self.coords) @@ -204,3 +205,22 @@ def writeTecplot(self, handle): for i in range(self.nCon): for j in range(nres): handle.write("%d %d\n" % (i * nres + j + 1, i * nres + (j + 1) % nres + 1)) + + handle.write("Zone T=%s_circ_points\n" % self.name) + handle.write("Nodes = %d, Elements = %d ZONETYPE=FELINESEG\n" % (self.nCon * 3*2, self.nCon * 3)) + handle.write("DATAPACKING=POINT\n") + + for i in range(self.nCon): + for pt_dir in [p1, p2, p3]: + # for each con plot the vecotrs from the center to the coord points defining the circle + pt1 = c[i] + pt2 = pt_dir[i] + handle.write(f"{pt1[0]:f} {pt1[1]:f} {pt1[2]:f}\n") + handle.write(f"{pt2[0]:f} {pt2[1]:f} {pt2[2]:f}\n") + + # write out the elements + for i in range(self.nCon*3): + handle.write("%d %d\n" % (2 * i + 1, 2 * i + 2)) + + + diff --git a/pygeo/constraints/thicknessConstraint.py b/pygeo/constraints/thicknessConstraint.py index a18b0b32..c78591ee 100644 --- a/pygeo/constraints/thicknessConstraint.py +++ b/pygeo/constraints/thicknessConstraint.py @@ -88,6 +88,90 @@ def writeTecplot(self, handle): handle.write("%d %d\n" % (2 * i + 1, 2 * i + 2)) +class DistanceConstraint(GeometricConstraint): + """ + DVConstraints representation of a set of distance + constraints. One of these objects is created each time a + addDistanceConstraints or addDistanceConstraints1D call is + made. The user should not have to deal with this class directly. + """ + + def __init__(self, name, moving_pts, anchor_pts, lower, upper, scaled, scale, DVGeo, addToPyOpt, compNames): + super().__init__(name, len(moving_pts), lower, upper, scale, DVGeo, addToPyOpt) + + self.moving_pts = moving_pts + self.scaled = scaled + self.anchored_pts = anchor_pts + + # First thing we can do is embed the coordinates into DVGeo + # with the name provided: + self.DVGeo.addPointSet(self.moving_pts, self.name, compNames=compNames) + + # Now get the reference lengths + self.D0 = np.zeros(self.nCon) + for i in range(self.nCon): + self.D0[i] = geo_utils.norm.euclideanNorm(self.moving_pts[i] - self.anchored_pts[i]) + + def evalFunctions(self, funcs, config): + """ + Evaluate the functions this object has and place in the funcs dictionary + + Parameters + ---------- + funcs : dict + Dictionary to place function values + """ + # Pull out the most recent set of coordinates: + self.moving_pts = self.DVGeo.update(self.name, config=config) + D = np.zeros(self.nCon) + for i in range(self.nCon): + dx = self.moving_pts[i] - self.anchored_pts[i] + D[i] = geo_utils.norm.euclideanNorm(dx) + if self.scaled: + D[i] /= self.D0[i] + funcs[self.name] = D + + def evalFunctionsSens(self, funcsSens, config): + """ + Evaluate the sensitivity of the functions this object has and + place in the funcsSens dictionary + + Parameters + ---------- + funcsSens : dict + Dictionary to place function values + """ + + nDV = self.DVGeo.getNDV() + if nDV > 0: + dDdPt = np.zeros((self.nCon, self.moving_pts.shape[0], self.moving_pts.shape[1])) + + for i in range(self.nCon): + p1b, _ = geo_utils.eDist_b(self.moving_pts[i, :], self.anchored_pts[i] ) + + if self.scaled: + p1b /= self.D0[i] + dDdPt[i, i, :] = p1b + + funcsSens[self.name] = self.DVGeo.totalSensitivity(dDdPt, self.name, config=config) + + + def writeTecplot(self, handle): + """ + Write the visualization of this set of thickness constraints + to the open file handle + """ + handle.write("Zone T=%s\n" % self.name) + handle.write("Nodes = %d, Elements = %d ZONETYPE=FELINESEG\n" % (len(self.moving_pts)*2, len(self.moving_pts))) + handle.write("DATAPACKING=POINT\n") + for i in range(self.nCon): + handle.write(f"{self.moving_pts[i, 0]:f} {self.moving_pts[i, 1]:f} {self.moving_pts[i, 2]:f}\n") + handle.write(f"{self.anchored_pts[i, 0]:f} {self.anchored_pts[i, 1]:f} {self.anchored_pts[i, 2]:f}\n") + + for i in range(len(self.moving_pts)): + handle.write("%d %d\n" % (2 * i + 1, 2 * i + 2)) + + class ProjectedThicknessConstraint(GeometricConstraint): """ DVConstraints representation of a set of projected thickness diff --git a/pygeo/mphys/mphys_dvgeo.py b/pygeo/mphys/mphys_dvgeo.py index c93c68c3..23ab3143 100644 --- a/pygeo/mphys/mphys_dvgeo.py +++ b/pygeo/mphys/mphys_dvgeo.py @@ -1,3 +1,4 @@ +import os # External modules from mpi4py import MPI import numpy as np @@ -31,6 +32,7 @@ def initialize(self): self.options.declare("type", default=None) self.options.declare("options", default=None) self.options.declare("DVGeoInfo", default=None) + self.options.declare("output_dir", default="./") def setup(self): # create a constraints object to go with this DVGeo(s) @@ -88,6 +90,7 @@ def setup(self): self.DVCon.setDVGeo(DVGeo, name=DVConName) self.omPtSetList = [] + self.call_counter = 0 def compute(self, inputs, outputs): # check for inputs that have been added but the points have not been added to dvgeo @@ -113,6 +116,8 @@ def compute(self, inputs, outputs): # compute the DVCon constraint values constraintfunc = dict() self.DVCon.evalFunctions(constraintfunc, includeLinear=True) + file_name = os.path.join(self.options['output_dir'], f"cons_{self.call_counter}.dat") + self.DVCon.writeTecplot(file_name) for constraintname in constraintfunc: # if any constraint returned a fail flag throw an error to OpenMDAO @@ -124,6 +129,7 @@ def compute(self, inputs, outputs): # we ran a compute so the inputs changed. update the dvcon jac # next time the jacvec product routine is called self.update_jac = True + self.call_counter += 1 def nom_addChild(self, ffd_file, DVGeoName=None, childName=None): # if we have multiple DVGeos use the one specified by name @@ -628,6 +634,31 @@ def nom_addThicknessConstraints1D( ) self.add_output(name, distributed=False, val=np.ones(nCon), shape=nCon) + def nom_addDistanceConstraints1D( + self, + name, + ptList, + nCon, + axis, + scaled=True, + surfaceName="default", + DVGeoName="default", + compNames=None, + addToPyOpt=True, + ): + self.DVCon.addDistanceConstraints1D( + ptList, + nCon, + axis, + name=name, + scaled=scaled, + surfaceName=surfaceName, + DVGeoName=DVGeoName, + compNames=compNames, + addToPyOpt=addToPyOpt + ) + self.add_output(name, distributed=False, val=np.ones(nCon), shape=nCon) + def nom_addVolumeConstraint( self, name, diff --git a/tests/reg_tests/ref/test_DVConstraints_distance_1D_c172.ref b/tests/reg_tests/ref/test_DVConstraints_distance_1D_c172.ref new file mode 100644 index 00000000..077ddd4b --- /dev/null +++ b/tests/reg_tests/ref/test_DVConstraints_distance_1D_c172.ref @@ -0,0 +1,820 @@ +{ + "derivs_base": { + "DVCon1_distance_constraints_0": { + "local": { + "__ndarray__": [ + [ + 0.08225918603911694, + 0.261929411288979, + 0.006215543459598648, + 0.01979151165487529, + 2.0574763024422184e-09, + 6.5514088163168116e-09, + 1.5546389395152374e-10, + 4.950275851264917e-10, + 0.10432872399880114, + 0.04410645252451236, + 0.3322031565513131, + 0.14044361122534202, + 2.609482145732552e-09, + 1.1031957064445457e-09, + 8.309103883860487e-09, + 3.512791894003661e-09, + 0.0007216985075641477, + 2.1106000877625894e-06, + 5.453188457711365e-05, + 1.594779525910067e-07, + 0.0022980298531585282, + 6.720565386961578e-06, + 0.00017364023535279885, + 5.078091365488366e-07, + 0.000915324938544881, + 2.676858654099958e-06, + 0.0003869666415827717, + 1.1316800840317625e-06, + 0.0029145744546654317, + 8.523643925175623e-06, + 0.0012321778210891813, + 3.603491749078872e-06 + ], + [ + 0.04193707724013709, + 0.1334395026989859, + 0.0031687856239017973, + 0.010082752677109777, + 0.0007008940657124783, + 0.00223017343430483, + 5.295989099550617e-05, + 0.0001685129718737105, + 0.05318848833031358, + 0.0224861902405565, + 0.16924034527888002, + 0.07154876402361421, + 0.000888938817110859, + 0.0003758115333083803, + 0.0028285126549441454, + 0.001195793970716156, + 0.032166525699049306, + 0.008224109734868252, + 0.0024305180740745863, + 0.0006214176669493659, + 0.10235060417437092, + 0.02616827841574973, + 0.007733660627999207, + 0.0019772876390805054, + 0.04079656927386348, + 0.01043057822450262, + 0.017247330139505166, + 0.004409675357167445, + 0.12981052266844328, + 0.03318903611643184, + 0.054879245482994894, + 0.014031137252484255 + ], + [ + 0.015815909174301424, + 0.049804458622760006, + 0.0011950576654039381, + 0.003763248725854644, + 0.006475706913486145, + 0.020392066840513264, + 0.0004893075131238993, + 0.0015408343284357049, + 0.0200592019261064, + 0.008480313029071315, + 0.06316663059482197, + 0.026704591858095945, + 0.00821309171419412, + 0.0034722013831562947, + 0.025863109223537975, + 0.010933997420665887, + 0.03523274044640878, + 0.026162390996803345, + 0.0026622027276233355, + 0.00197684278288768, + 0.11094825750395819, + 0.08238563496494748, + 0.008383303427712784, + 0.006225098000942452, + 0.04468542701123763, + 0.03318156914604349, + 0.01889140008106839, + 0.014027980484507875, + 0.14071486350198054, + 0.10448909824656771, + 0.05948921072412098, + 0.04417425301966027 + ], + [ + 0.0032491895184118594, + 0.008914429780873177, + 0.0002455103148061505, + 0.0006735785799559128, + 0.02824624906320042, + 0.07749600397887209, + 0.0021343000955477776, + 0.005855635143859244, + 0.004120923301198123, + 0.0017421789606430953, + 0.011306106089758175, + 0.004779817219759625, + 0.03582451109004028, + 0.015145321796755462, + 0.0982876150303387, + 0.041552487751436475, + 0.02004279164745479, + 0.04121166163099376, + 0.0015144429277138185, + 0.0031139728733506618, + 0.05498911582148572, + 0.11306772402188674, + 0.004155003904741007, + 0.008543451332009884, + 0.025420126050827066, + 0.0522684490190232, + 0.01074671998136206, + 0.02209723053081654, + 0.06974229339869452, + 0.14340296738460978, + 0.029484546871056137, + 0.06062564488851763 + ], + [ + 1.821996246815963e-05, + 4.410609331413835e-05, + 1.3767090826701077e-06, + 3.332677516366088e-06, + 0.0852764280543351, + 0.20643347097085557, + 0.0064435277100724775, + 0.0155982118486438, + 2.3108245135141715e-05, + 9.769339429375499e-06, + 5.593943555249779e-05, + 2.3649192320924147e-05, + 0.1081554699781935, + 0.04572426383662404, + 0.2618180613505146, + 0.11068731074626233, + 0.0009143151311526188, + 0.01529407027256573, + 6.908608882593736e-05, + 0.0011556272682795988, + 0.002213334333899943, + 0.0370232206445873, + 0.00016724060138930837, + 0.002797492268174315, + 0.001159619193418574, + 0.019397357463834055, + 0.0004902455138013324, + 0.008200508865510743, + 0.0028071557470640434, + 0.04695627995077752, + 0.0011867650340304653, + 0.019851435472367892 + ] + ], + "dtype": "float64", + "shape": [ + 5, + 32 + ] + }, + "local_x": { + "__ndarray__": [ + [ + -6.998017031376884e-17, + -2.2283061254060435e-16, + -5.287735155664017e-18, + -1.683718771197778e-17, + -1.750352136878444e-24, + -5.573465126958104e-24, + -1.322574450371515e-25, + -4.211336919951059e-25, + -8.875533816469384e-17, + -3.7522582075316985e-17, + -2.82614436072556e-16, + -1.194792740637685e-16, + -2.2199588128949508e-24, + -9.38519175107031e-25, + -7.068785055456855e-24, + -2.988429461267762e-24, + -6.13968930479269e-19, + -1.795546013981286e-21, + -4.63917861820623e-20, + -1.356723160171159e-22, + -1.954997712154427e-18, + -5.7173713117066945e-21, + -1.4772056263155088e-19, + -4.320073121763772e-22, + -7.786923038765629e-19, + -2.277277876670466e-21, + -3.292032511825741e-19, + -9.62751624889445e-22, + -2.4795092992125648e-18, + -7.251300217024547e-21, + -1.048247836243666e-18, + -3.065590342759819e-21 + ], + [ + -1.7847499375189465e-17, + -5.678892278087521e-17, + -1.3485655931350693e-18, + -4.290998179832105e-18, + -2.982851267447214e-19, + -9.49112851794664e-19, + -2.2538566911567364e-20, + -7.171542124897822e-20, + -2.2635852918572176e-17, + -9.569628898330249e-18, + -7.20249754012611e-17, + -3.0449583167061424e-17, + -3.7831284455330006e-19, + -1.599371379055215e-19, + -1.2037528879937297e-18, + -5.089036611446544e-19, + -1.3689367144698082e-17, + -3.500000548776225e-18, + -1.0343751320589428e-18, + -2.6446171627801906e-19, + -4.355817010309081e-17, + -1.1136644788108524e-17, + -3.291276176348336e-18, + -8.414902092720045e-19, + -1.73621242237713e-17, + -4.439025096544063e-18, + -7.340085054708945e-18, + -1.8766610207759223e-18, + -5.5244508551509303e-17, + -1.4124525129859087e-17, + -2.335540204340237e-17, + -5.97134397118257e-18 + ], + [ + -6.7801674175719595e-18, + -2.1350816060105716e-17, + -5.123126945023875e-19, + -1.6132778782466575e-18, + -2.776089350077059e-18, + -8.741933558498984e-18, + -2.0976263969993119e-19, + -6.605446828508092e-19, + -8.599236744661598e-18, + -3.635449689098252e-18, + -2.7079083846327968e-17, + -1.144806799409411e-17, + -3.520893818016555e-18, + -1.4885079590351424e-18, + -1.1087330392581261e-17, + -4.687326680901298e-18, + -1.5104024446135696e-17, + -1.121563035342475e-17, + -1.1412673146942371e-18, + -8.474583963832949e-19, + -4.756272638357175e-17, + -3.5318133893493765e-17, + -3.5938623651528476e-18, + -2.6686550973473585e-18, + -1.9156323732193248e-17, + -1.4224701944638737e-17, + -8.098608425881636e-18, + -6.013695145008736e-18, + -6.032345799218682e-17, + -4.4793730895596494e-17, + -2.5502600185902553e-17, + -1.8937187089196176e-17 + ], + [ + 1.549029736955095e-18, + 4.249895778723327e-18, + 1.1704542816259558e-19, + 3.211241586910216e-19, + 1.3466213499828007e-17, + 3.694571030043769e-17, + 1.0175135358695735e-18, + 2.791635549480291e-18, + 1.964623085570936e-18, + 8.305723633051544e-19, + 5.3901117318526735e-18, + 2.27874642850524e-18, + 1.707910008815798e-17, + 7.220432574334857e-18, + 4.68579741482135e-17, + 1.9809875295577805e-17, + 9.555269120983061e-18, + 1.964738868385352e-17, + 7.220007071476331e-19, + 1.484566090576759e-18, + 2.6215699371695463e-17, + 5.3904293919223916e-17, + 1.980870789203535e-18, + 4.073034242699538e-18, + 1.2118877937635502e-17, + 2.4918639364121363e-17, + 5.123428083073485e-18, + 1.053470934909252e-17, + 3.3249179768014636e-17, + 6.836642171458735e-17, + 1.4056563836952193e-17, + 2.890287753984116e-17 + ], + [ + 2.922210252915514e-20, + 7.07395958273026e-20, + 2.20803605039855e-21, + 5.345117710865237e-21, + 1.3677067273210527e-16, + 3.31088500577413e-16, + 1.0334457478836366e-17, + 2.5017205535363136e-17, + 3.706217890338881e-20, + 1.566856347515653e-20, + 8.971851198896964e-20, + 3.7929777514166234e-20, + 1.7346524386726531e-16, + 7.333490001634079e-17, + 4.1991712365707036e-16, + 1.7752593886821802e-16, + 1.4664251121917113e-18, + 2.4529407806083294e-17, + 1.1080378318769285e-19, + 1.853453791585387e-18, + 3.549858181626456e-18, + 5.937972438342482e-17, + 2.6822898287394636e-19, + 4.486760388665384e-18, + 1.8598562441647325e-18, + 3.1110468509109185e-17, + 7.862806904128559e-19, + 1.315239322133499e-17, + 4.502259167622665e-18, + 7.531087012430782e-17, + 1.9033941240581215e-18, + 3.1838741914984686e-17 + ] + ], + "dtype": "float64", + "shape": [ + 5, + 32 + ] + }, + "twist": { + "__ndarray__": [ + [ + 1.25227008666546e-05, + 3.662251379373479e-08, + 3.570072544933793e-11 + ], + [ + 0.0005578375196776408, + 0.00014262395071753842, + 1.2155027584635515e-05 + ], + [ + 0.0006062071454941717, + 0.00045014461448431345, + 0.0001114196555062881 + ], + [ + 0.0003111545213501197, + 0.0006397908572014391, + 0.00043850917885046787 + ], + [ + 1.2970245660517649e-05, + 0.00021695785383572051, + 0.001209710069570709 + ] + ], + "dtype": "float64", + "shape": [ + 5, + 3 + ] + } + }, + "DVCon1_distance_constraints_1": { + "local": { + "__ndarray__": [ + [ + 0.08225918603911683, + 0.2619294112889791, + 0.006215543459598639, + 0.019791511654875298, + 2.0574763024422142e-09, + 6.55140881631681e-09, + 1.5546389395152343e-10, + 4.950275851264915e-10, + 0.10432872399880098, + 0.0441064525245123, + 0.3322031565513133, + 0.14044361122534207, + 2.6094821457325465e-09, + 1.1031957064445434e-09, + 8.309103883860487e-09, + 3.5127918940036602e-09, + 0.0007216985075641466, + 2.1106000877625856e-06, + 5.453188457711356e-05, + 1.5947795259100644e-07, + 0.0022980298531585287, + 6.720565386961578e-06, + 0.00017364023535279888, + 5.078091365488366e-07, + 0.0009153249385448795, + 2.6768586540999527e-06, + 0.00038696664158277105, + 1.1316800840317606e-06, + 0.0029145744546654325, + 8.523643925175625e-06, + 0.0012321778210891816, + 3.603491749078872e-06 + ], + [ + 0.0419370772401372, + 0.13343950269898602, + 0.0031687856239017973, + 0.01008275267710976, + 0.0007008940657124789, + 0.0022301734343048284, + 5.295989099550609e-05, + 0.00016851297187370996, + 0.053188488330313685, + 0.022486190240556526, + 0.16924034527888004, + 0.07154876402361415, + 0.0008889388171108593, + 0.0003758115333083801, + 0.002828512654944141, + 0.001195793970716153, + 0.032166525699049375, + 0.008224109734868267, + 0.0024305180740745854, + 0.0006214176669493654, + 0.10235060417437096, + 0.02616827841574973, + 0.0077336606279991916, + 0.0019772876390805, + 0.04079656927386354, + 0.010430578224502631, + 0.017247330139505176, + 0.004409675357167446, + 0.12981052266844326, + 0.033189036116431814, + 0.05487924548299482, + 0.01403113725248423 + ], + [ + 0.015815909174301434, + 0.04980445862275994, + 0.0011950576654039407, + 0.003763248725854645, + 0.006475706913486158, + 0.020392066840513267, + 0.0004893075131239011, + 0.0015408343284357077, + 0.02005920192610642, + 0.008480313029071327, + 0.06316663059482192, + 0.026704591858095934, + 0.008213091714194142, + 0.003472201383156305, + 0.025863109223537992, + 0.0109339974206659, + 0.03523274044640881, + 0.026162390996803384, + 0.002662202727623342, + 0.001976842782887686, + 0.11094825750395808, + 0.08238563496494745, + 0.00838330342771279, + 0.006225098000942461, + 0.04468542701123769, + 0.03318156914604356, + 0.01889140008106843, + 0.01402798048450791, + 0.14071486350198048, + 0.10448909824656773, + 0.05948921072412098, + 0.0441742530196603 + ], + [ + 0.0032491895184118633, + 0.008914429780873173, + 0.00024551031480615076, + 0.0006735785799559126, + 0.028246249063200456, + 0.07749600397887205, + 0.00213430009554778, + 0.005855635143859241, + 0.004120923301198128, + 0.0017421789606430974, + 0.011306106089758168, + 0.004779817219759622, + 0.03582451109004032, + 0.01514532179675548, + 0.09828761503033864, + 0.04155248775143645, + 0.020042791647454813, + 0.04121166163099381, + 0.0015144429277138204, + 0.0031139728733506657, + 0.05498911582148569, + 0.1130677240218867, + 0.004155003904741005, + 0.00854345133200988, + 0.025420126050827097, + 0.052268449019023264, + 0.010746719981362072, + 0.022097230530816567, + 0.06974229339869449, + 0.1434029673846097, + 0.029484546871056116, + 0.06062564488851759 + ], + [ + 1.821996246815984e-05, + 4.410609331413889e-05, + 1.3767090826701236e-06, + 3.3326775163661288e-06, + 0.085276428054335, + 0.20643347097085546, + 0.00644352771007247, + 0.015598211848643793, + 2.3108245135141982e-05, + 9.76933942937561e-06, + 5.593943555249846e-05, + 2.3649192320924428e-05, + 0.10815546997819339, + 0.04572426383662399, + 0.2618180613505145, + 0.11068731074626226, + 0.0009143151311526255, + 0.015294070272565775, + 6.908608882593787e-05, + 0.001155627268279602, + 0.00221333433389996, + 0.037023220644587435, + 0.0001672406013893097, + 0.002797492268174325, + 0.0011596191934185826, + 0.01939735746383411, + 0.0004902455138013359, + 0.008200508865510768, + 0.0028071557470640655, + 0.04695627995077768, + 0.0011867650340304746, + 0.019851435472367958 + ] + ], + "dtype": "float64", + "shape": [ + 5, + 32 + ] + }, + "local_x": { + "__ndarray__": [ + [ + -8.078356539506974e-18, + -2.5723074521662918e-17, + -6.104044857623728e-19, + -1.9436478198053285e-18, + -2.0205679077362701e-25, + -6.433885235517553e-25, + -1.5267507798621924e-26, + -4.8614744712417686e-26, + -1.0245720512884141e-17, + -4.331524129310158e-18, + -3.262438727384195e-17, + -1.3792423920104209e-17, + -2.5626714986798977e-25, + -1.083405839352015e-25, + -8.160049585915867e-25, + -3.44977706871025e-25, + -7.087521939933654e-20, + -2.0727387228403862e-22, + -5.355365492866412e-21, + -1.5661712974014884e-23, + -2.2568062469542964e-19, + -6.600007361746582e-22, + -1.705253599417786e-20, + -4.986997144744331e-23, + -8.989052237341144e-20, + -2.6288393618921784e-22, + -3.800249735165982e-20, + -1.1113792450025474e-22, + -2.862290856431535e-19, + -8.370741063572852e-22, + -1.2100741860122244e-19, + -3.5388498887392184e-22 + ], + [ + -8.23743491384406e-18, + -2.621067777624219e-17, + -6.224245238491113e-19, + -1.9804913550481582e-18, + -1.37672189569766e-19, + -4.380588662980941e-19, + -1.0402576522481811e-20, + -3.309993755643948e-20, + -1.0447478451535503e-17, + -4.41682016861254e-18, + -3.324281091522985e-17, + -1.4053871313817406e-17, + -1.7460863107865634e-19, + -7.381828322878117e-20, + -5.55586856105149e-19, + -2.34882248654037e-19, + -6.3182672538946994e-18, + -1.6154098741161356e-18, + -4.774112971074928e-19, + -1.2206114309055927e-19, + -2.0104082014377375e-17, + -5.140069466996159e-18, + -1.5190740571670156e-18, + -3.883861085408517e-19, + -8.013412145468866e-18, + -2.0488125280191432e-18, + -3.3877840043125068e-18, + -8.6616464799992e-19, + -2.5497860174909083e-17, + -6.5191125098405286e-18, + -1.0779583188367219e-17, + -2.7560475715253613e-18 + ], + [ + 2.3319193122399827e-18, + 7.343237598176253e-18, + 1.7620093909770223e-19, + 5.548585467879409e-19, + 9.54787097317238e-19, + 3.0066342666628135e-18, + 7.214416995589135e-20, + 2.271827239169925e-19, + 2.9575562077464364e-18, + 1.2503489687753107e-18, + 9.31337453635195e-18, + 3.937361601732328e-18, + 1.2109494920878258e-18, + 5.119461279231958e-19, + 3.8132922494861325e-18, + 1.6121235563657785e-18, + 5.1947635108841816e-18, + 3.857418764072659e-18, + 3.9251881666910436e-19, + 2.914684076567882e-19, + 1.6358363055931106e-17, + 1.2147050865597808e-17, + 1.2360457402737052e-18, + 9.17836975984367e-19, + 6.588480565664214e-18, + 4.892336004800239e-18, + 2.7853739041367005e-18, + 2.068304657230964e-18, + 2.0747192216597607e-17, + 1.5406015767694513e-17, + 8.771170713530532e-18, + 6.5131123721738915e-18 + ], + [ + -1.6155506773529276e-19, + -4.432401677124707e-19, + -1.2207178225050844e-20, + -3.3491439170654703e-20, + -1.4044501420476568e-18, + -3.853229274893342e-18, + -1.06120924787483e-19, + -2.911518478496537e-19, + -2.048991107734515e-19, + -8.662401451155374e-20, + -5.621582627922765e-19, + -2.376604043330848e-19, + -1.7812538428241897e-18, + -7.53050406842253e-19, + -4.88702250631659e-18, + -2.066058300143237e-18, + -9.965606942470986e-19, + -2.0491118626818175e-18, + -7.530060292932035e-20, + -1.5483187288069463e-19, + -2.734149633594221e-18, + -5.621913929464989e-18, + -2.0659365465358818e-19, + -4.2479450669613913e-19, + -1.2639306395363316e-18, + -2.598873587963058e-18, + -5.343446618557929e-19, + -1.098710787702329e-18, + -3.4677019823540284e-18, + -7.13023231731536e-18, + -1.4660203536622653e-18, + -3.01440716552833e-18 + ], + [ + 2.748814261609532e-21, + 6.654210102663872e-21, + 2.077017209637104e-22, + 5.027952995151187e-22, + 1.2865507380957289e-17, + 3.1144261140487145e-17, + 9.72123894079145e-19, + 2.353275274857865e-18, + 3.486301022806811e-21, + 1.473883362652403e-21, + 8.439486003432204e-21, + 3.5679127902105505e-21, + 1.6317228911238577e-17, + 6.8983406939148896e-18, + 3.950003861121784e-17, + 1.6699203354026496e-17, + 1.3794114430860078e-19, + 2.307389960695849e-18, + 1.0422898871247823e-20, + 1.7434748955729664e-19, + 3.339219273017917e-19, + 5.585629339050819e-18, + 2.523130061450225e-20, + 4.220528256816232e-19, + 1.7494974440675e-19, + 2.926445810593946e-18, + 7.396249374180558e-20, + 1.2371966057210017e-18, + 4.2351073804754053e-19, + 7.084212836683383e-18, + 1.790451904839715e-19, + 2.9949517752973497e-18 + ] + ], + "dtype": "float64", + "shape": [ + 5, + 32 + ] + }, + "twist": { + "__ndarray__": [ + [ + 1.2522700866654582e-05, + 3.6622513793734746e-08, + 3.5700725449337875e-11 + ], + [ + 0.0005578375196776388, + 0.0001426239507175378, + 1.2155027584635457e-05 + ], + [ + 0.0006062071454941728, + 0.00045014461448431427, + 0.00011141965550628835 + ], + [ + 0.00031115452135012, + 0.0006397908572014393, + 0.0004385091788504681 + ], + [ + 1.2970245660517773e-05, + 0.00021695785383572152, + 0.0012097100695707098 + ] + ], + "dtype": "float64", + "shape": [ + 5, + 3 + ] + } + } + }, + "funcs_base": { + "DVCon1_distance_constraints_0": { + "__ndarray__": [ + 0.13050274373165272, + 0.13043706504399175, + 0.12948932850228792, + 0.11643821059892744, + 0.10383350318363548 + ], + "dtype": "float64", + "shape": [ + 5 + ] + }, + "DVCon1_distance_constraints_1": { + "__ndarray__": [ + 1.1305027437316528, + 1.1304370650439917, + 1.1294893285022878, + 1.1164382105989272, + 1.1038335031836355 + ], + "dtype": "float64", + "shape": [ + 5 + ] + } + } +} \ No newline at end of file diff --git a/tests/reg_tests/ref/test_DVConstraints_distance_box.ref b/tests/reg_tests/ref/test_DVConstraints_distance_box.ref new file mode 100644 index 00000000..715bc0c3 --- /dev/null +++ b/tests/reg_tests/ref/test_DVConstraints_distance_box.ref @@ -0,0 +1,524 @@ +{ + "derivs_base": { + "DVCon1_distance_constraints_0": { + "local": { + "__ndarray__": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + -3.5849408715365354e-19, + -1.3277558683886965e-20, + -3.5849408715365354e-19, + -1.3277558683886965e-20, + -6.943865603998734e-21, + -2.571802056266572e-22, + -6.943865603998734e-21, + -2.571802056266572e-22, + -3.584940862574183e-19, + -1.1949802845372774e-19, + -3.584940862574183e-19, + -1.1949802845372774e-19, + -6.943865586639071e-21, + -2.31462185642647e-21, + -6.943865586639071e-21, + -2.31462185642647e-21, + -2.8883047973825555e-19, + -7.756803530400122e-20, + -1.0697425095260261e-20, + -2.872890174897814e-21, + -2.8883047973825555e-19, + -7.756803530400122e-20, + -1.0697425095260261e-20, + -2.872890174897814e-21, + -2.8883047901617935e-19, + -7.756803511008112e-20, + -9.627682609803442e-20, + -2.5856011638720352e-20, + -2.8883047901617935e-19, + -7.756803511008112e-20, + -9.627682609803442e-20, + -2.5856011638720352e-20 + ], + [ + -1.8629479662828265e-22, + -5.0299595466883316e-21, + -2.7944219494242395e-22, + -7.544939320032497e-21, + -3.5800994175673906e-20, + -9.666268499928975e-19, + -5.370149126351085e-20, + -1.4499402749893463e-18, + -1.676653173846177e-21, + -5.029959534113431e-21, + -2.5149797607692655e-21, + -7.544939301170145e-21, + -3.2220894838658756e-19, + -9.6662684757633e-19, + -4.833134225798813e-19, + -1.4499402713644948e-18, + -3.225176105811169e-21, + -1.861165046251957e-20, + -8.707975550999979e-20, + -5.02514566256888e-19, + -4.837764158716753e-21, + -2.791747569377935e-20, + -1.3061963326499968e-19, + -7.53771849385332e-19, + -2.902658502486699e-20, + -1.675048545814383e-19, + -8.707975529230037e-20, + -5.025145650006014e-19, + -4.353987753730048e-20, + -2.5125728187215744e-19, + -1.3061963293845053e-19, + -7.53771847500902e-19 + ] + ], + "dtype": "float64", + "shape": [ + 3, + 32 + ] + }, + "local_x": { + "__ndarray__": [ + [ + -3.0357660829594124e-18, + -3.0357660829594113e-18, + -3.0357660829594124e-18, + -3.0357660829594113e-18, + 0.0, + 0.0, + 0.0, + 0.0, + -9.107298248878236e-18, + -9.107298248878234e-18, + -9.107298248878236e-18, + -9.107298248878234e-18, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 1.4339763486146142e-17, + 5.311023473554785e-19, + 1.4339763486146142e-17, + 5.311023473554785e-19, + 2.7775462415994935e-19, + 1.0287208225066288e-20, + 2.7775462415994935e-19, + 1.0287208225066288e-20, + 1.433976345029673e-17, + 4.77992113814911e-18, + 1.433976345029673e-17, + 4.77992113814911e-18, + 2.777546234655628e-19, + 9.258487425705879e-20, + 2.777546234655628e-19, + 9.258487425705879e-20, + 1.155321918953022e-17, + 3.1027214121600485e-18, + 4.2789700381041043e-19, + 1.1491560699591256e-19, + 1.155321918953022e-17, + 3.1027214121600485e-18, + 4.2789700381041043e-19, + 1.1491560699591256e-19, + 1.1553219160647172e-17, + 3.1027214044032447e-18, + 3.851073043921376e-18, + 1.0342404655488139e-18, + 1.1553219160647172e-17, + 3.1027214044032447e-18, + 3.851073043921376e-18, + 1.0342404655488139e-18 + ], + [ + 7.451791865131306e-22, + 2.0119838186753326e-20, + 1.1177687797696958e-21, + 3.017975728012999e-20, + 1.4320397670269562e-19, + 3.86650739997159e-18, + 2.148059650540434e-19, + 5.799761099957385e-18, + 6.706612695384708e-21, + 2.0119838136453724e-20, + 1.0059919043077062e-20, + 3.017975720468058e-20, + 1.2888357935463502e-18, + 3.86650739030532e-18, + 1.9332536903195254e-18, + 5.799761085457979e-18, + 1.2900704423244676e-20, + 7.444660185007828e-20, + 3.4831902203999916e-19, + 2.010058265027552e-18, + 1.935105663486701e-20, + 1.116699027751174e-19, + 5.224785330599987e-19, + 3.015087397541328e-18, + 1.1610634009946796e-19, + 6.700194183257532e-19, + 3.483190211692015e-19, + 2.0100582600024055e-18, + 1.741595101492019e-19, + 1.0050291274886297e-18, + 5.224785317538021e-19, + 3.015087390003608e-18 + ] + ], + "dtype": "float64", + "shape": [ + 3, + 32 + ] + }, + "twist": { + "__ndarray__": [ + [ + 0.0, + 0.0, + 0.0 + ], + [ + 1.1949138588670523e-20, + 3.209049144461304e-21, + 2.8727304860094854e-22 + ], + [ + -8.10575169403462e-21, + -4.6776179754502075e-20, + -8.997771274093116e-20 + ] + ], + "dtype": "float64", + "shape": [ + 3, + 3 + ] + } + }, + "DVCon1_distance_constraints_1": { + "local": { + "__ndarray__": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + -1.7924704357682677e-19, + -6.6387793419434826e-21, + -1.7924704357682677e-19, + -6.6387793419434826e-21, + -3.471932801999367e-21, + -1.285901028133286e-22, + -3.471932801999367e-21, + -1.285901028133286e-22, + -1.7924704312870914e-19, + -5.974901422686387e-20, + -1.7924704312870914e-19, + -5.974901422686387e-20, + -3.471932793319536e-21, + -1.157310928213235e-21, + -3.471932793319536e-21, + -1.157310928213235e-21, + -1.4441523986912778e-19, + -3.878401765200061e-20, + -5.348712547630131e-21, + -1.436445087448907e-21, + -1.4441523986912778e-19, + -3.878401765200061e-20, + -5.348712547630131e-21, + -1.436445087448907e-21, + -1.4441523950808968e-19, + -3.878401755504056e-20, + -4.813841304901721e-20, + -1.2928005819360176e-20, + -1.4441523950808968e-19, + -3.878401755504056e-20, + -4.813841304901721e-20, + -1.2928005819360176e-20 + ], + [ + -6.209826554276088e-23, + -1.6766531822294437e-21, + -9.314739831414132e-23, + -2.5149797733441654e-21, + -1.1933664725224635e-20, + -3.222089499976325e-19, + -1.790049708783695e-20, + -4.833134249964488e-19, + -5.58884391282059e-22, + -1.6766531780378104e-21, + -8.383265869230885e-22, + -2.5149797670567147e-21, + -1.0740298279552918e-19, + -3.2220894919210997e-19, + -1.6110447419329378e-19, + -4.833134237881649e-19, + -1.0750587019370562e-21, + -6.203883487506523e-21, + -2.902658516999993e-20, + -1.6750485541896265e-19, + -1.6125880529055843e-21, + -9.305825231259784e-21, + -4.3539877754999894e-20, + -2.51257283128444e-19, + -9.67552834162233e-21, + -5.58349515271461e-20, + -2.902658509743346e-20, + -1.6750485500020045e-19, + -1.451329251243349e-20, + -8.375242729071914e-20, + -4.3539877646150174e-20, + -2.5125728250030064e-19 + ] + ], + "dtype": "float64", + "shape": [ + 3, + 32 + ] + }, + "local_x": { + "__ndarray__": [ + [ + -3.0357660829594124e-18, + -3.0357660829594113e-18, + -3.0357660829594124e-18, + -3.0357660829594113e-18, + 0.0, + 0.0, + 0.0, + 0.0, + -9.107298248878236e-18, + -9.107298248878234e-18, + -9.107298248878236e-18, + -9.107298248878234e-18, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 7.169881743073071e-18, + 2.6555117367773927e-19, + 7.169881743073071e-18, + 2.6555117367773927e-19, + 1.3887731207997468e-19, + 5.143604112533144e-21, + 1.3887731207997468e-19, + 5.143604112533144e-21, + 7.169881725148365e-18, + 2.389960569074555e-18, + 7.169881725148365e-18, + 2.389960569074555e-18, + 1.388773117327814e-19, + 4.6292437128529394e-20, + 1.388773117327814e-19, + 4.6292437128529394e-20, + 5.77660959476511e-18, + 1.5513607060800243e-18, + 2.1394850190520522e-19, + 5.745780349795628e-20, + 5.77660959476511e-18, + 1.5513607060800243e-18, + 2.1394850190520522e-19, + 5.745780349795628e-20, + 5.776609580323586e-18, + 1.5513607022016224e-18, + 1.925536521960688e-18, + 5.171202327744069e-19, + 5.776609580323586e-18, + 1.5513607022016224e-18, + 1.925536521960688e-18, + 5.171202327744069e-19 + ], + [ + 2.4839306217104352e-22, + 6.706612728917775e-21, + 3.7258959325656526e-22, + 1.0059919093376662e-20, + 4.773465890089854e-20, + 1.28883579999053e-18, + 7.16019883513478e-20, + 1.933253699985795e-18, + 2.235537565128236e-21, + 6.706612712151242e-21, + 3.353306347692354e-21, + 1.0059919068226859e-20, + 4.2961193118211673e-19, + 1.2888357967684399e-18, + 6.444178967731751e-19, + 1.9332536951526596e-18, + 4.300234807748225e-21, + 2.4815533950026093e-20, + 1.1610634067999972e-19, + 6.700194216758506e-19, + 6.450352211622337e-21, + 3.7223300925039136e-20, + 1.7415951101999958e-19, + 1.005029132513776e-18, + 3.870211336648932e-20, + 2.233398061085844e-19, + 1.1610634038973384e-19, + 6.700194200008018e-19, + 5.805317004973397e-20, + 3.3500970916287657e-19, + 1.741595105846007e-19, + 1.0050291300012026e-18 + ] + ], + "dtype": "float64", + "shape": [ + 3, + 32 + ] + }, + "twist": { + "__ndarray__": [ + [ + 0.0, + 0.0, + 0.0 + ], + [ + 5.974569294335262e-21, + 1.604524572230652e-21, + 1.4363652430047427e-22 + ], + [ + -2.7019172313448734e-21, + -1.5592059918167357e-20, + -2.9992570913643716e-20 + ] + ], + "dtype": "float64", + "shape": [ + 3, + 3 + ] + } + } + }, + "funcs_base": { + "DVCon1_distance_constraints_0": { + "__ndarray__": [ + 1.0, + 1.9999999999999991, + 2.9999999999999982 + ], + "dtype": "float64", + "shape": [ + 3 + ] + }, + "DVCon1_distance_constraints_1": { + "__ndarray__": [ + 1.0, + 0.9999999999999996, + 0.9999999999999994 + ], + "dtype": "float64", + "shape": [ + 3 + ] + } + } +} \ No newline at end of file diff --git a/tests/reg_tests/test_DVConstraints.py b/tests/reg_tests/test_DVConstraints.py index 021b5dde..8bca3f2a 100644 --- a/tests/reg_tests/test_DVConstraints.py +++ b/tests/reg_tests/test_DVConstraints.py @@ -367,6 +367,94 @@ def test_projected_thickness1D_box(self, train=False, refDeriv=False): funcs["DVCon1_thickness_constraints_2"], 8.0 * np.ones(3), name="thickness_base", rtol=1e-7, atol=1e-7 ) + def test_distance_box(self, train=False, refDeriv=False): + refFile = os.path.join(self.base_path, "ref/test_DVConstraints_distance_box.ref") + with BaseRegTest(refFile, train=train) as handler: + DVGeo, DVCon = self.generate_dvgeo_dvcon("box") + DVGeo.addLocalDV("local_x", lower=-0.5, upper=0.5, axis="x", scale=1) + + moving_pts = np.array([ + [0.0, 0.0, 0.0], + [-0.5, 0.0, 2.0], + [0.5, 0.1, 7.0], + ]) + + anchored_pts = np.array([ + [0.0, 0.0, -1.0], # this point is outside the FFD, but it shouldn't matter + [-0.5, 0.0, 0.0], + [0.5, 0.1, 10.0], + ]) + + DVCon.addDistanceConstraints(anchored_pts, moving_pts, scaled=False) + DVCon.addDistanceConstraints(anchored_pts, moving_pts, scaled=True) + DVCon.writeTecplot('distCon0.dat') + funcs, funcsSens = generic_test_base(DVGeo, DVCon, handler) + print('funcs', funcs) + DVCon.writeTecplot('distCon1.dat') + + # Check that unscaled thicknesses are computed correctly at baseline + handler.assert_allclose( + funcs["DVCon1_distance_constraints_0"], np.arange(1,4), name="distance_0_base", rtol=1e-12, atol=1e-12 + ) + handler.assert_allclose( + funcs["DVCon1_distance_constraints_1"], np.ones(len(moving_pts)), name="distance_1_base", rtol=1e-7, atol=1e-7 + ) + DVs = DVGeo.getValues() + DVGeo.setDesignVars({"local_x": 0.5*np.ones_like(DVs["local_x"])}) + funcs = {} + DVCon.evalFunctions(funcs) + + handler.assert_allclose( + funcs["DVCon1_distance_constraints_0"], np.sqrt(np.arange(1,4)**2 + 0.5**2*np.ones(3)), name="distance_0_altered", rtol=1e-12, atol=1e-12 + ) + handler.assert_allclose( + funcs["DVCon1_distance_constraints_1"], np.sqrt(np.arange(1,4)**2 + 0.5**2*np.ones(3))/np.arange(1,4), name="distance_1_altered", rtol=1e-12, atol=1e-12 + ) + + def test_distance_1D_c172(self, train=True, refDeriv=False): + refFile = os.path.join(self.base_path, "ref/test_DVConstraints_distance_1D_c172.ref") + with BaseRegTest(refFile, train=train) as handler: + DVGeo, DVCon = self.generate_dvgeo_dvcon("c172") + DVGeo.addLocalDV("local_x", lower=-0.5, upper=0.5, axis="x", scale=1) + + # This line is below the geometry + + + anchored_pts = np.array([ + [0.47, 0.0, 1e-2], + [0.47, 0.0, 5.24], + ]) + + anchored_pts_1 = anchored_pts.copy() + anchored_pts_1[:,1] -= 1.0 + + nCon = 5 + + DVCon.addDistanceConstraints1D(anchored_pts, nCon, axis=[0, 1, 0], scaled=False) + DVCon.addDistanceConstraints1D(anchored_pts_1, nCon, axis=[0, 1, 0], scaled=False) + + DVCon.writeTecplot('distCon0.dat') + funcs, funcsSens = generic_test_base(DVGeo, DVCon, handler) + DVCon.writeTecplot('distCon1.dat') + + + # Check that unscaled thicknesses are computed correctly at baseline + base_dis = funcs["DVCon1_distance_constraints_0"] + handler.assert_allclose( + funcs["DVCon1_distance_constraints_1"], base_dis + 1.0, name="distance_1_base", rtol=1e-12, atol=1e-12 + ) + DVs = DVGeo.getValues() + DVGeo.setDesignVars({"local_x": 0.5*np.ones_like(DVs["local_x"])}) + funcs = {} + DVCon.evalFunctions(funcs) + handler.assert_allclose( + funcs["DVCon1_distance_constraints_0"], np.sqrt(base_dis**2 + 0.5**2*np.ones(5)), name="distance_altered", rtol=1e-12, atol=1e-12 + ) + handler.assert_allclose( + funcs["DVCon1_distance_constraints_1"], np.sqrt((base_dis+1)**2 + 0.5**2*np.ones(5)), name="distance_1_altered", rtol=1e-12, atol=1e-12 + ) + + def test_thickness2D(self, train=False, refDeriv=False): refFile = os.path.join(self.base_path, "ref/test_DVConstraints_thickness2D.ref") with BaseRegTest(refFile, train=train) as handler: