Example #1
0
    def compute_values(self, DVGeo, handler, refDeriv):
        # Calculate updated point coordinates
        Xnew = DVGeo.update('X')
        handler.root_add_val(Xnew, 1e-12, 1e-12, msg='Updated points')

        # Need to get design variables so that we can reset the Jacobians
        # for each call
        x = DVGeo.getValues()

        # Calculate Jacobians
        DVGeo.setDesignVars(x)
        DVGeo.update('X')
        DVGeo.computeTotalJacobian('X')
        Jac = DVGeo.JT['X'].toarray()

        DVGeo.setDesignVars(x)
        DVGeo.update('X')
        DVGeo.computeTotalJacobianCS('X')
        JacCS = DVGeo.JT['X']

        DVGeo.setDesignVars(x)
        DVGeo.update('X')
        DVGeo.computeTotalJacobianFD('X')
        JacFD = DVGeo.JT['X']

        if refDeriv:
            handler.root_add_val(JacCS, 1e-12, 1e-12, msg='Check jacobian')
        else:
            handler.root_add_val(Jac, 1e-12, 1e-12, msg='Check jacobian')

        # Test that they are equal to eachother
        numpy.testing.assert_allclose(Jac, JacCS, rtol=1e-12, atol=1e-12,
                                        err_msg='Analytic vs complex-step')
        numpy.testing.assert_allclose(Jac, JacFD, rtol=1e-6, atol=1e-6,
                                        err_msg='Analytic vs finite difference')

        # Make sure we reset everything
        DVGeo.setDesignVars(x)
        DVGeo.update('X')

        # Create dIdPt with one function for each point coordinate
        Npt = 4
        dIdPt = numpy.zeros([Npt*3, Npt,3])
        for i in range(Npt):
            dIdPt[i*3:(i+1)*3,i] = numpy.eye(3)

        # Test sensitivity dictionaries
        if refDeriv:
            # Generate reference from finite differences
            sens = commonUtils.totalSensitivityFD(DVGeo, Npt*3, 'X', step=1e-6)
            handler.root_add_dict(sens, 1e-6, 1e-6, msg='Check sens dict')
        else:
            # Compute the analytic derivatives
            sens = DVGeo.totalSensitivity(dIdPt, 'X')
            handler.root_add_dict(sens, 1e-6, 1e-6, msg='Check sens dict')
Example #2
0
    def test_21(self, train=False, refDeriv=False):
        """
        Test 21
        """
        refFile = os.path.join(self.base_path, "ref/test_DVGeometry_21.ref")
        with BaseRegTest(refFile, train=train) as handler:
            handler.root_print("Test 21: Axisymmetric FFD, global and local DVs")

            # Test with a single point along the 45 ` degree theta direction
            DVGeo = commonUtils.setupDVGeoAxi(self.base_path)

            DVGeo.addGlobalDV("mainAxis", np.zeros(1), commonUtils.mainAxisPointAxi)

            DVGeo.addLocalDV("x_axis", lower=-2, upper=2, axis="x")
            DVGeo.addLocalDV("z_axis", lower=-2, upper=2, axis="z")
            DVGeo.addLocalDV("y_axis", lower=-2, upper=2, axis="y")

            ptName = "point"
            s_pts = np.array(
                [
                    [0, 0.5, 0.5],
                ],
                dtype="float",
            )
            DVGeo.addPointSet(points=s_pts, ptName=ptName)

            # generate dIdPt
            nPt = 3
            dIdPt = np.zeros([nPt, 1, 3])
            dIdPt[0, 0, 0] = 1.0
            dIdPt[1, 0, 1] = 1.0
            dIdPt[2, 0, 2] = 1.0

            if refDeriv:
                # Generate reference derivatives
                refPoints = DVGeo.update(ptName)
                nPt = 3 * refPoints.shape[0]
                step = 1e-5
                J_fd = commonUtils.totalSensitivityFD(DVGeo, nPt, ptName, step)
                handler.root_add_dict(J_fd, rtol=1e-7, atol=1e-7)

            else:
                # Compute the analytic derivatives
                dIdx = DVGeo.totalSensitivity(dIdPt, ptName)
                handler.root_add_dict("dIdx", dIdx, rtol=1e-7, atol=1e-7)