예제 #1
0
  def test_DLLM_MP_AoA_valid_grad(self):
      config_dict = self.__get_base_config_dict()
      config_dict['Case.AoA_id_list']=['AoA1','AoA2','AoA3']
      config_dict['Case.param.BCfilename']='input_parameters_AoA.par'
      
      MP=DLLMMP('Case')
      MP.configure(config_dict)
      MP.set_out_format('numpy')
      MP.set_grad_format('numpy')
 
      x0=MP.get_x0()
       
      Ref_list=MP.analysis()
       
      def f(x):
          func=MP.run(x)
          return func/Ref_list
         
      def df(x):
          func_grad=MP.run_grad(x)
          N = func_grad.shape[0]
          ndv = func_grad.shape[1]
          out_grad = np.zeros((N,ndv))
          for i in xrange(N):
              out_grad[i,:] = func_grad[i,:]/Ref_list[i]
          return out_grad
     
      val_grad=FDValidGrad(2,f,df,fd_step=1.e-8)
      ok,df_fd,df=val_grad.compare(x0,treshold=1.e-5,split_out=True,return_all=True)
      assert(ok)
    def test_DLLM_valid_grad_TLift(self):
        OC,wing_param = self.__init_wing_param()
        x0=wing_param.get_dv_array()
        DLLM = DLLMTargetLift('Simple',wing_param,OC)
        F_list_names = DLLM.get_DLLMPost().DEF_F_LIST_NAMES
#        F_list_names.remove('Lift')
  
        def f2(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMTargetLift('Simple',wing_param,OC)
            DLLM.set_target_Lift(769200.)
            DLLM.set_F_list_names(F_list_names)
            DLLM.run_direct()
            DLLM.run_post()
            func=DLLM.get_F_list()
            return func
          
        def df2(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMTargetLift('Simple',wing_param,OC)
            DLLM.set_target_Lift(769200.)
            DLLM.set_F_list_names(F_list_names)
            DLLM.run_direct()
            DLLM.run_post()
            DLLM.run_adjoint()
            func_grad=array(DLLM.get_dF_list_dchi())
            return func_grad
      
        val_grad2=FDValidGrad(2,f2,df2,fd_step=1.e-6)
        ok2,df_fd2,df2=val_grad2.compare(x0,treshold=1.e-2,split_out=True,return_all=True)
        assert(ok2)
 def test_DLLM_valid_grad_TCl(self):
     OC,wing_param = self.__init_wing_param()
     x0=wing_param.get_dv_array()
        
     def f1(x):
         wing_param.update_from_x_list(x)
         DLLM = DLLMTargetCl('Simple',wing_param,OC)
         DLLM.set_target_Cl(0.5)
         DLLM.run_direct()
         DLLM.run_post()
         func=DLLM.get_F_list()
         return func
        
     def df1(x):
         wing_param.update_from_x_list(x)
         DLLM = DLLMTargetCl('Simple',wing_param,OC)
         DLLM.set_target_Cl(0.5)
         DLLM.run_direct()
         DLLM.run_post()
         DLLM.run_adjoint()
         func_grad=array(DLLM.get_dF_list_dchi())
         return func_grad
        
     val_grad1=FDValidGrad(2,f1,df1,fd_step=1.e-8)
     ok1,df_fd1,df1=val_grad1.compare(x0,treshold=1.e-6,split_out=True,return_all=True)
     assert(ok1)
예제 #4
0
    def test_DLLM_valid_dpF_list_dpW(self):
        OC, wing_param = self.__init_wing_param()
        DLLM = DLLMSolver('test', wing_param, OC)
        print ''
        DLLM.run_direct()
        iAoA0 = DLLM.get_iAoA()

        def f1(x):
            DLLM.comp_R(x)
            DLLM.set_direct_computed()
            DLLM.run_post()
            func = DLLM.get_F_list()
            return func

        def df1(x):
            DLLM.comp_R(x)
            DLLM.set_direct_computed()
            DLLM.run_post()
            func_grad = DLLM.get_dpF_list_dpW()
            return func_grad

        val_grad1 = FDValidGrad(2, f1, df1, fd_step=1.e-8)
        ok1, df_fd1, df1 = val_grad1.compare(iAoA0,
                                             treshold=1.e-6,
                                             return_all=True)
        assert (ok1)
예제 #5
0
 def test_DLLM_valid_dpF_list_dpAoA(self):
     OC,wing_param = self.__init_wing_param()
     DLLM = DLLMSolver('test',wing_param,OC)
     print ''
     DLLM.run_direct()
     iAoA=DLLM.get_iAoA()
     AoA0=OC.get_AoA_rad()
     
     def f3(x):
         OC.set_AoA_rad(x[0])
         DLLM.comp_R(iAoA)
         DLLM.set_direct_computed()
         DLLM.run_post()
         func=DLLM.get_F_list()
         return func
     
     def df3(x):
         OC.set_AoA_rad(x[0])
         DLLM.comp_R(iAoA)
         DLLM.set_direct_computed()
         DLLM.run_post()
         func_grad=DLLM.get_dpF_list_dpAoA()
         N=len(func_grad)
         np_func_grad=zeros((N,1))
         np_func_grad[:,0]=func_grad[:]
         return np_func_grad
     
     val_grad3=FDValidGrad(2,f3,df3,fd_step=1.e-8)
     ok3,df_fd3,df3=val_grad3.compare([AoA0],treshold=1.e-6,split_out=True,return_all=True)
     assert(ok3)
예제 #6
0
    def test_DLLM_valid_dpF_list_dpchi(self):
        OC, wing_param = self.__init_wing_param()
        DLLM = DLLMSolver('test', wing_param, OC)
        print ''
        DLLM.run_direct()
        iAoA = DLLM.get_iAoA()
        x0 = wing_param.get_dv_array()

        def f2(x):
            wing_param.update_from_x_list(x)
            DLLM.set_wing_param(wing_param)
            DLLM.comp_R(iAoA)
            DLLM.set_direct_computed()
            DLLM.run_post()
            func = DLLM.get_F_list()
            return func

        def df2(x):
            wing_param.update_from_x_list(x)
            DLLM.set_wing_param(wing_param)
            DLLM.comp_R(iAoA)
            DLLM.set_direct_computed()
            DLLM.run_post()
            func_grad = DLLM.get_dpF_list_dpchi()
            return func_grad

        val_grad2 = FDValidGrad(2, f2, df2, fd_step=1.e-8)
        ok2, df_fd2, df2 = val_grad2.compare(x0,
                                             treshold=1.e-6,
                                             split_out=True,
                                             return_all=True)
        assert (ok2)
예제 #7
0
    def test_DLLM_valid_dpF_list_dpAoA(self):
        OC, wing_param = self.__init_wing_param()
        DLLM = DLLMSolver('test', wing_param, OC)
        print ''
        DLLM.run_direct()
        iAoA = DLLM.get_iAoA()
        AoA0 = OC.get_AoA_rad()

        def f3(x):
            OC.set_AoA_rad(x[0])
            DLLM.comp_R(iAoA)
            DLLM.set_direct_computed()
            DLLM.run_post()
            func = DLLM.get_F_list()
            return func

        def df3(x):
            OC.set_AoA_rad(x[0])
            DLLM.comp_R(iAoA)
            DLLM.set_direct_computed()
            DLLM.run_post()
            func_grad = DLLM.get_dpF_list_dpAoA()
            N = len(func_grad)
            np_func_grad = zeros((N, 1))
            np_func_grad[:, 0] = func_grad[:]
            return np_func_grad

        val_grad3 = FDValidGrad(2, f3, df3, fd_step=1.e-8)
        ok3, df_fd3, df3 = val_grad3.compare([AoA0],
                                             treshold=1.e-6,
                                             split_out=True,
                                             return_all=True)
        assert (ok3)
예제 #8
0
    def test_DLLM_valid_dF_list_dchi(self):
        OC, wing_param = self.__init_wing_param()
        x0 = wing_param.get_dv_array()

        def f4(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMSolver('test', wing_param, OC)
            DLLM.run_direct()
            DLLM.run_post()
            func = DLLM.get_F_list()
            return func

        def df4(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMSolver('test', wing_param, OC)
            DLLM.run_direct()
            DLLM.run_post()
            DLLM.run_adjoint()
            func_grad = array(DLLM.get_dF_list_dchi())
            return func_grad

        val_grad4 = FDValidGrad(2, f4, df4, fd_step=1.e-8)
        ok4, df_fd4, df4 = val_grad4.compare(x0,
                                             treshold=1.e-6,
                                             split_out=True,
                                             return_all=True)
        assert (ok4)
예제 #9
0
 def test_DLLM_valid_dpF_list_dpchi(self):
     OC,wing_param = self.__init_wing_param()
     DLLM = DLLMSolver('test',wing_param,OC)
     print ''
     DLLM.run_direct()
     iAoA=DLLM.get_iAoA()
     x0=wing_param.get_dv_array()
     def f2(x):
         wing_param.update_from_x_list(x)
         DLLM.set_wing_param(wing_param)
         DLLM.comp_R(iAoA)
         DLLM.set_direct_computed()
         DLLM.run_post()
         func=DLLM.get_F_list()
         return func
     
     def df2(x):
         wing_param.update_from_x_list(x)
         DLLM.set_wing_param(wing_param)
         DLLM.comp_R(iAoA)
         DLLM.set_direct_computed()
         DLLM.run_post()
         func_grad=DLLM.get_dpF_list_dpchi()
         return func_grad
     
     val_grad2=FDValidGrad(2,f2,df2,fd_step=1.e-8)
     ok2,df_fd2,df2=val_grad2.compare(x0,treshold=1.e-6,split_out=True,return_all=True)
     assert(ok2)
예제 #10
0
    def test_DLLM_valid_dpLoads_dpAoA(self):
        OC, wing_param = self.__init_wing_param()
        DLLM = DLLMSolver('test', wing_param, OC)
        print ''
        DLLM.run_direct()
        iAoA0 = DLLM.get_iAoA()
        AoA0 = OC.get_AoA_rad()

        def f2(x):
            OC.set_AoA_rad(x[0])
            R = DLLM.comp_R(iAoA0)
            Post = DLLM.get_DLLMPost()
            func = Post.comp_Lift_distrib()
            return func

        def df2(x):
            OC.set_AoA_rad(x[0])
            R = DLLM.comp_R(iAoA0)
            Post = DLLM.get_DLLMPost()
            func_grad = Post.comp_dpLift_distrib_dpAoA()
            N = len(func_grad)
            np_func_grad = zeros((N, 1))
            np_func_grad[:, 0] = func_grad[:]
            return np_func_grad

        val_grad2 = FDValidGrad(2, f2, df2, fd_step=1.e-8)
        ok2, df_fd2, df2 = val_grad2.compare([AoA0],
                                             treshold=1.e-5,
                                             return_all=True)
        assert (ok2)
예제 #11
0
    def test_DLLM_valid_grad_TCl(self):
        OC, wing_param = self.__init_wing_param()
        x0 = wing_param.get_dv_array()

        def f1(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMTargetCl('Simple', wing_param, OC)
            DLLM.set_target_Cl(0.5)
            DLLM.run_direct()
            DLLM.run_post()
            func = DLLM.get_F_list()
            return func

        def df1(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMTargetCl('Simple', wing_param, OC)
            DLLM.set_target_Cl(0.5)
            DLLM.run_direct()
            DLLM.run_post()
            DLLM.run_adjoint()
            func_grad = array(DLLM.get_dF_list_dchi())
            return func_grad

        val_grad1 = FDValidGrad(2, f1, df1, fd_step=1.e-8)
        ok1, df_fd1, df1 = val_grad1.compare(x0,
                                             treshold=1.e-6,
                                             split_out=True,
                                             return_all=True)
        assert (ok1)
예제 #12
0
  def test_DLLM_wrapper_json_valid_grad(self):
      DLLMWrap = DLLMWrapper('test', verbose=0)
      DLLMWrap.config_from_file('conf_file.json')
      DLLMWrap.set_out_format('numpy')
      DLLMWrap.set_grad_format('numpy')
 
      x0=DLLMWrap.get_x0()
       
      DLLMWrap.analysis()
       
      Ref_list=DLLMWrap.get_F_list()
       
      def f(x):
          DLLMWrap.run(x)
          func=DLLMWrap.get_F_list()
          return func/Ref_list
         
      def df(x):
          DLLMWrap.run_grad(x)
          func_grad=np.array(DLLMWrap.get_F_list_grad())
          N = func_grad.shape[0]
          ndv = func_grad.shape[1]
          out_grad = np.zeros((N,ndv))
          for i in xrange(N):
              out_grad[i,:] = func_grad[i,:]/Ref_list[i]
          return out_grad
     
      val_grad=FDValidGrad(2,f,df,fd_step=1.e-8)
      ok,df_fd,df=val_grad.compare(x0,treshold=1.e-5,split_out=True,return_all=True)
      assert(ok)
예제 #13
0
 def test_DLLM_wrapper_TLift_valid_grad(self):
     config_dict = self.__get_base_config_dict()
     config_dict['test.DLLM.type']='TargetLift'
     config_dict['test.DLLM.target_Lift']=769200.
     
     DLLMWrap = DLLMWrapper('test', verbose=0)
     DLLMWrap.configure(config_dict)
     DLLMWrap.set_out_format('numpy')
     DLLMWrap.set_grad_format('numpy')
     
     x0=DLLMWrap.get_x0()
      
     DLLMWrap.analysis()
      
     Ref_list=DLLMWrap.get_F_list()
      
     def f(x):
         DLLMWrap.run(x)
         func=DLLMWrap.get_F_list()
         return func/Ref_list
        
     def df(x):
         DLLMWrap.run_grad(x)
         func_grad=np.array(DLLMWrap.get_F_list_grad())
         N = func_grad.shape[0]
         ndv = func_grad.shape[1]
         out_grad = np.zeros((N,ndv))
         for i in xrange(N):
             out_grad[i,:] = func_grad[i,:]/Ref_list[i]
         return out_grad
    
     val_grad=FDValidGrad(2,f,df,fd_step=1.e-8)
     ok,df_fd,df=val_grad.compare(x0,treshold=1.e-5,split_out=True,return_all=True)
     assert(ok)
예제 #14
0
 def test_DLLM_valid_dpLoads_dpAoA(self):
     OC,wing_param = self.__init_wing_param()
     DLLM = DLLMSolver('test',wing_param,OC)
     print ''
     DLLM.run_direct()
     iAoA0=DLLM.get_iAoA()
     AoA0=OC.get_AoA_rad()
     
     def f2(x):
         OC.set_AoA_rad(x[0])
         R=DLLM.comp_R(iAoA0)
         Post=DLLM.get_DLLMPost()
         func=Post.comp_Lift_distrib()
         return func
     
     def df2(x):
         OC.set_AoA_rad(x[0])
         R=DLLM.comp_R(iAoA0)
         Post=DLLM.get_DLLMPost()
         func_grad=Post.comp_dpLift_distrib_dpAoA()
         N=len(func_grad)
         np_func_grad=zeros((N,1))
         np_func_grad[:,0]=func_grad[:]
         return np_func_grad
     
     val_grad2=FDValidGrad(2,f2,df2,fd_step=1.e-8)
     ok2,df_fd2,df2=val_grad2.compare([AoA0],treshold=1.e-5,return_all=True)
     assert(ok2)
예제 #15
0
    def test_DLLM_valid_grad_TLift(self):
        OC, wing_param = self.__init_wing_param()
        x0 = wing_param.get_dv_array()
        DLLM = DLLMTargetLift('Simple', wing_param, OC)
        F_list_names = DLLM.get_DLLMPost().DEF_F_LIST_NAMES
        F_list_names.remove('Lift')

        def f2(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMTargetLift('Simple', wing_param, OC)
            DLLM.set_target_Lift(769200.)
            DLLM.set_F_list_names(F_list_names)
            DLLM.run_direct()
            DLLM.run_post()
            func = DLLM.get_F_list()
            return func

        def df2(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMTargetLift('Simple', wing_param, OC)
            DLLM.set_target_Lift(769200.)
            DLLM.set_F_list_names(F_list_names)
            DLLM.run_direct()
            DLLM.run_post()
            DLLM.run_adjoint()
            func_grad = array(DLLM.get_dF_list_dchi())
            return func_grad

        val_grad2 = FDValidGrad(2, f2, df2, fd_step=1.e-8)
        ok2, df_fd2, df2 = val_grad2.compare(x0,
                                             treshold=1.e-6,
                                             split_out=True,
                                             return_all=True)
        assert (ok2)
예제 #16
0
    def test_DLLM_valid_dpLoads_distrib_dpAoA(self):
        OC,wing_param = self.__init_wing_param()
        DLLM = DLLMSolver('test',wing_param,OC)
        print ''
        DLLM.run_direct()
        iAoA0=DLLM.get_iAoA()
        AoA0=OC.get_AoA_rad()
        Post=DLLM.get_DLLMPost()

        def f1(x):
            OC.set_AoA_rad(x[0])
            R=DLLM.comp_R(iAoA0)
            DLLM.run_post()
            func=Post.Lift_distrib
            return func
        
        def df1(x):
            OC.set_AoA_rad(x[0])
            R=DLLM.comp_R(iAoA0)
            DLLM.run_post()
            func_grad=Post.dpLift_distrib_dpAoA
            N=len(func_grad)
            np_func_grad=np.zeros((N,1))
            np_func_grad[:,0]=func_grad[:]
            return np_func_grad

     	def f2(x):
            OC.set_AoA_rad(x[0])
            R=DLLM.comp_R(iAoA0)
            DLLM.run_post()
            func=Post.Drag_distrib
            return func
        
        def df2(x):
            OC.set_AoA_rad(x[0])
            R=DLLM.comp_R(iAoA0)
            DLLM.run_post()
            func_grad=Post.dpDrag_distrib_dpAoA
            N=len(func_grad)
            np_func_grad=np.zeros((N,1))
            np_func_grad[:,0]=func_grad[:]
            return np_func_grad
        
        val_grad1=FDValidGrad(2,f1,df1,fd_step=1.e-8)
        ok1,df_fd1,df1=val_grad1.compare([AoA0],treshold=1.e-6,return_all=True)
        val_grad2=FDValidGrad(2,f2,df2,fd_step=1.e-8)
        ok2,df_fd2,df2=val_grad2.compare([AoA0],treshold=1.e-6,return_all=True)
        norm1, norm2 = self.print_valid_FD([AoA0],'dpLift_distrib_dpAoA',df1,df_fd1,'dpDrag_distrib_dpAoA',df2,df_fd2)
        self.plot_valid_FD([AoA0],'dpLift_distrib_dpAoA',df1,df_fd1,'dpDrag_distrib_dpAoA',df2,df_fd2, norm1, norm2, 'Loads_distrib_dpAoA')
        if (ok1==True) and (ok2==True): 
            ok = True
        else : 	
            ok = False
        assert(ok)
예제 #17
0
    def test_jacobian(self):
        DLLMOpenMDAO, N = self.__init_DLLM()
        DLLMOpenMDAO.execute()
        out_dvid_tuple, F_list_names_tuple = DLLMOpenMDAO.list_deriv_vars()
        n_F = len(F_list_names_tuple)
        Jacobian = DLLMOpenMDAO.provideJ()
        n_dv = len(DLLMOpenMDAO.get_dv_id_list())
        self.assertEqual(n_dv, Jacobian.shape[0])
        self.assertEqual(n_F, Jacobian.shape[1])
        DLLMOpenMDAO.Mach = 0.666

        def d_obj(x):
            self.update_dllm_from_x(DLLMOpenMDAO, x)
            DLLMOpenMDAO.execute()
            return DLLMOpenMDAO.provideJ()

        def obj(x):
            self.update_dllm_from_x(DLLMOpenMDAO, x)
            DLLMOpenMDAO.execute()
            return DLLMOpenMDAO.get_F_list()

        treshold = 1e-2
        val_grad = FDValidGrad(2, obj, d_obj, fd_step=1.e-6)
        x0 = DLLMOpenMDAO.get_dv_array()
        ok, df_fd, df = val_grad.compare(
            x0, treshold=treshold, split_out=True, return_all=True, iprint=False)
        varnames, funcnames = DLLMOpenMDAO.list_deriv_vars()
        varnames = np.concatenate(
            (['tw0', 'tw1', 'tw2', 'tw3', 'tw4'], np.array(varnames[1:])))
        funcnames = np.array(funcnames)
        k = 0
        ok = True
        for fd, gr in zip(df_fd, df):
            err = np.where(((fd - gr) / fd > treshold) & (fd > 2e-5))[0]
            if err.size > 0:
                # Compute absolute error when gradient or fd is lower than
                # threshold
                inf_tol = err[np.where((np.abs(gr[err]) < treshold) | 
                                       (np.abs(fd[err]) < treshold))[0]]
                # Scale gradient by function value for the lift issue in
                # particular
                f_val = getattr(DLLMOpenMDAO, funcnames[k])
                actually_ok = np.where(
                    ((fd[inf_tol] - gr[inf_tol]) < treshold * f_val))[0]
                real_err = np.delete(err, actually_ok)
                if real_err.size > 0:
                    print "Errror in d", funcnames[k], " /d ", varnames[real_err]
                    print "df analytic = ", gr[real_err]
                    print "df finite d = ", fd[real_err]
                    print "Relative =", (fd[real_err] - gr[real_err]) / fd[real_err]
                    ok = False
            k = k + 1
        assert(ok)
예제 #18
0
    def test_DLLM_valid_dpLoads_distrib_dpchi(self):
        OC,wing_param = self.__init_wing_param()
        DLLM = DLLMSolver('test',wing_param,OC)
        print ''
        DLLM.run_direct()
        iAoA=DLLM.get_iAoA()
        x0=wing_param.get_dv_array()
    	Post=DLLM.get_DLLMPost()

        def f1(x):
            wing_param.update_from_x_list(x)
            DLLM.set_geom(wing_param)
            DLLM.comp_R(iAoA)
            Post.run()
            func=Post.Lift_distrib
            return func
        
        def df1(x):
            wing_param.update_from_x_list(x)
            DLLM.set_geom(wing_param)
            DLLM.comp_R(iAoA)
            Post.run()
            func_grad=Post.dpLift_distrib_dpchi
            return func_grad
        
        def f2(x):
            wing_param.update_from_x_list(x)
            DLLM.set_geom(wing_param)
            DLLM.comp_R(iAoA)
            Post.run()
            func=Post.Drag_distrib
            return func
        
        def df2(x):
            wing_param.update_from_x_list(x)
            DLLM.set_geom(wing_param)
            DLLM.comp_R(iAoA)
            Post.run()
            func_grad=Post.dpDrag_distrib_dpchi
            return func_grad

        val_grad1=FDValidGrad(2,f1,df1,fd_step=1.e-8)
        ok1,df_fd1,df1=val_grad1.compare(x0,treshold=1.e-6,return_all=True)
        val_grad2=FDValidGrad(2,f2,df2,fd_step=1.e-8)
        ok2,df_fd2,df2=val_grad2.compare(x0,treshold=1.e-6,return_all=True)
    	norm1, norm2 = self.print_valid_FD(x0,'dpLift_distrib_dpchi',df1,df_fd1,'dpDrag_distrib_dpchi',df2,df_fd2)
    	self.plot_valid_FD(x0,'dpLift_distrib_dpchi',df1,df_fd1,'dpDrag_distrib_dpchi',df2,df_fd2, norm1, norm2, 'Loads_distrib_dpchi')
    	if (ok1==True) and (ok2==True):
            ok = True
    	else : 
            ok = False
    	assert(ok)
예제 #19
0
 def test_Wing_param_valid_grad_XYZ(self):
     wing_param=self.__init_wing_param()
     x0=wing_param.get_dv_array()
     def f5(x):
         wing_param.update_from_x_list(x)
         func=wing_param.get_XYZ()
         return func
     
     def df5(x):
         wing_param.update_from_x_list(x)
         func_grad=wing_param.get_XYZ_grad()
         return func_grad
     
     val_grad5=FDValidGrad(2,f5,df5,fd_step=1.e-8)
     ok5,df_fd5,df5=val_grad5.compare(x0,treshold=1.e-6,return_all=True)
     assert(ok5)
예제 #20
0
 def test_Wing_param_valid_grad_twist(self):
     wing_param=self.__init_wing_param()
     x0=wing_param.get_dv_array()
     def f1(x):
         wing_param.update_from_x_list(x)
         func=wing_param.get_twist()
         return func
     
     def df1(x):
         wing_param.update_from_x_list(x)
         func_grad=wing_param.get_twist_grad()
         return func_grad
     
     val_grad1=FDValidGrad(2,f1,df1,fd_step=1.e-8)
     ok1,df_fd1,df1=val_grad1.compare(x0,treshold=1.e-6,return_all=True)
     assert(ok1)
예제 #21
0
 def test_Wing_param_valid_grad_eta(self):
     wing_param=self.__init_wing_param()
     x0=wing_param.get_dv_array()
     def f4(x):
         wing_param.update_from_x_list(x)
         func=wing_param.get_eta()
         return func
     
     def df4(x):
         wing_param.update_from_x_list(x)
         func_grad=wing_param.get_eta_grad()
         return func_grad
     
     val_grad4=FDValidGrad(2,f4,df4,fd_step=1.e-8)
     ok4,df_fd4,df4=val_grad4.compare(x0,treshold=1.e-6,return_all=True)
     assert(ok4)
예제 #22
0
 def test_Wing_param_valid_grad_chords(self):
     wing_param=self.__init_wing_param()
     x0=wing_param.get_dv_array()
     def f2(x):
         wing_param.update_from_x_list(x)
         func=wing_param.get_chords()
         return func
     
     def df2(x):
         wing_param.update_from_x_list(x)
         func_grad=wing_param.get_chords_grad()
         return func_grad
     
     val_grad2=FDValidGrad(2,f2,df2,fd_step=1.e-8)
     ok2,df_fd2,df2=val_grad2.compare(x0,treshold=1.e-6,return_all=True)
     assert(ok2)
예제 #23
0
 def test_Wing_param_valid_grad_rel_thicks(self):
     wing_param=self.__init_wing_param()
     x0=wing_param.get_dv_array()
     def f3(x):
         wing_param.update_from_x_list(x)
         func=wing_param.get_rel_thicks()
         return func
     
     def df3(x):
         wing_param.update_from_x_list(x)
         func_grad=wing_param.get_rel_thicks_grad()
         return func_grad
     
     val_grad3=FDValidGrad(2,f3,df3,fd_step=1.e-8)
     ok3,df_fd3,df3=val_grad3.compare(x0,treshold=1.e-6,return_all=True)
     assert(ok3)
예제 #24
0
 def test_DLLM_valid_dpR_dpiAoA(self):
     OC,wing_param = self.__init_wing_param()
     DLLM = DLLMSolver('test',wing_param,OC)
     print ''
     DLLM.run_direct()
     iAoA0=DLLM.get_iAoA()
     def f1(x):
         func=DLLM.comp_R(x)
         return func
     
     def df1(x):
         func_grad=DLLM.comp_dpR_dpiAoA(x)
         return func_grad
     
     val_grad1=FDValidGrad(2,f1,df1,fd_step=1.e-8)
     ok1,df_fd1,df1=val_grad1.compare(iAoA0,treshold=1.e-6,return_all=True)
     assert(ok1)
예제 #25
0
    def test_Wing_param_valid_grad_XYZ(self):
        wing_param = self.__init_wing_param()
        x0 = wing_param.get_dv_array()

        def f5(x):
            wing_param.update_from_x_list(x)
            func = wing_param.get_XYZ()
            return func

        def df5(x):
            wing_param.update_from_x_list(x)
            func_grad = wing_param.get_XYZ_grad()
            return func_grad

        val_grad5 = FDValidGrad(2, f5, df5, fd_step=1.e-8)
        ok5, df_fd5, df5 = val_grad5.compare(x0,
                                             treshold=1.e-6,
                                             return_all=True)
        assert (ok5)
예제 #26
0
    def test_Wing_param_valid_grad_chords(self):
        wing_param = self.__init_wing_param()
        x0 = wing_param.get_dv_array()

        def f2(x):
            wing_param.update_from_x_list(x)
            func = wing_param.get_chords()
            return func

        def df2(x):
            wing_param.update_from_x_list(x)
            func_grad = wing_param.get_chords_grad()
            return func_grad

        val_grad2 = FDValidGrad(2, f2, df2, fd_step=1.e-8)
        ok2, df_fd2, df2 = val_grad2.compare(x0,
                                             treshold=1.e-6,
                                             return_all=True)
        assert (ok2)
예제 #27
0
    def test_Wing_param_valid_grad_rel_thicks(self):
        wing_param = self.__init_wing_param()
        x0 = wing_param.get_dv_array()

        def f3(x):
            wing_param.update_from_x_list(x)
            func = wing_param.get_rel_thicks()
            return func

        def df3(x):
            wing_param.update_from_x_list(x)
            func_grad = wing_param.get_rel_thicks_grad()
            return func_grad

        val_grad3 = FDValidGrad(2, f3, df3, fd_step=1.e-8)
        ok3, df_fd3, df3 = val_grad3.compare(x0,
                                             treshold=1.e-6,
                                             return_all=True)
        assert (ok3)
예제 #28
0
    def test_Wing_param_valid_grad_eta(self):
        wing_param = self.__init_wing_param()
        x0 = wing_param.get_dv_array()

        def f4(x):
            wing_param.update_from_x_list(x)
            func = wing_param.get_eta()
            return func

        def df4(x):
            wing_param.update_from_x_list(x)
            func_grad = wing_param.get_eta_grad()
            return func_grad

        val_grad4 = FDValidGrad(2, f4, df4, fd_step=1.e-8)
        ok4, df_fd4, df4 = val_grad4.compare(x0,
                                             treshold=1.e-6,
                                             return_all=True)
        assert (ok4)
예제 #29
0
    def test_Wing_param_valid_grad_twist(self):
        wing_param = self.__init_wing_param()
        x0 = wing_param.get_dv_array()

        def f1(x):
            wing_param.update_from_x_list(x)
            func = wing_param.get_twist()
            return func

        def df1(x):
            wing_param.update_from_x_list(x)
            func_grad = wing_param.get_twist_grad()
            return func_grad

        val_grad1 = FDValidGrad(2, f1, df1, fd_step=1.e-8)
        ok1, df_fd1, df1 = val_grad1.compare(x0,
                                             treshold=1.e-6,
                                             return_all=True)
        assert (ok1)
예제 #30
0
 def test_DLLM_valid_dpR_dpthetaY(self):
     OC,wing_param = self.__init_wing_param()
     DLLM = DLLMSolver('test',wing_param,OC)
     print ''
     DLLM.run_direct()
     iAoA=DLLM.get_iAoA()
     thetaY0=wing_param.get_thetaY()
     def f3(x):
         wing_param.set_thetaY(x)
         func=DLLM.comp_R(iAoA)
         return func
     
     def df3(x):
         wing_param.set_thetaY(x)
         func_grad=DLLM.comp_dpR_dpthetaY()
         return func_grad
     
     val_grad3=FDValidGrad(2,f3,df3,fd_step=1.e-8)
     ok3,df_fd3,df3=val_grad3.compare(thetaY0,treshold=1.e-6,return_all=True)
     assert(ok3)
예제 #31
0
 def test_DLLM_valid_dpR_dpthetaY(self):
     OC,wing_param = self.__init_wing_param()
     DLLM = DLLMSolver('test',wing_param,OC)
     print ''
     DLLM.run_direct()
     iAoA=DLLM.get_iAoA()
     thetaY0=wing_param.get_thetaY()
     def f3(x):
         wing_param.set_thetaY(x)
         func=DLLM.comp_R(iAoA)
         return func
     
     def df3(x):
         wing_param.set_thetaY(x)
         func_grad=DLLM.comp_dpR_dpthetaY()
         return func_grad
     
     val_grad3=FDValidGrad(2,f3,df3,fd_step=1.e-8)
     ok3,df_fd3,df3=val_grad3.compare(thetaY0,treshold=1.e-6,return_all=True)
     assert(ok3)
예제 #32
0
 def test_DLLM_valid_dpR_dpAoA(self):
     OC,wing_param = self.__init_wing_param()
     DLLM = DLLMSolver('test',wing_param,OC)
     print ''
     DLLM.run_direct()
     iAoA = DLLM.get_iAoA()
     AoA0=OC.get_AoA_rad()
     def f4(x):
         OC.set_AoA_rad(x[0])
         func=DLLM.comp_R(iAoA)
         return func
     
     def df4(x):
         OC.set_AoA_rad(x[0])
         func_grad=DLLM.comp_dpR_dpAoA()
         N=len(func_grad)
         np_func_grad=zeros((N,1))
         np_func_grad[:,0]=func_grad[:]
         return np_func_grad
     
     val_grad4=FDValidGrad(2,f4,df4,fd_step=1.e-8)
     ok4,df_fd4,df4=val_grad4.compare([AoA0],treshold=1.e-6,return_all=True)
     assert(ok4)
예제 #33
0
    def test_DLLM_valid_dF_list_dchi(self):
        OC,wing_param = self.__init_wing_param()
        x0=wing_param.get_dv_array()
        def f4(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMSolver('test',wing_param,OC)
            DLLM.run_direct()
            DLLM.run_post()
            func=DLLM.get_F_list()
            return func
        
        def df4(x):
            wing_param.update_from_x_list(x)
            DLLM = DLLMSolver('test',wing_param,OC)
            DLLM.run_direct()
            DLLM.run_post()
            DLLM.run_adjoint()
            func_grad=array(DLLM.get_dF_list_dchi())
            return func_grad

        val_grad4=FDValidGrad(2,f4,df4,fd_step=1.e-8)
        ok4,df_fd4,df4=val_grad4.compare(x0,treshold=1.e-6,split_out=True,return_all=True)
        assert(ok4)
예제 #34
0
 def test_DLLM_valid_dpR_dpAoA(self):
     OC,wing_param = self.__init_wing_param()
     DLLM = DLLMSolver('test',wing_param,OC)
     print ''
     DLLM.run_direct()
     iAoA = DLLM.get_iAoA()
     AoA0=OC.get_AoA_rad()
     def f4(x):
         OC.set_AoA_rad(x[0])
         func=DLLM.comp_R(iAoA)
         return func
     
     def df4(x):
         OC.set_AoA_rad(x[0])
         func_grad=DLLM.comp_dpR_dpAoA()
         N=len(func_grad)
         np_func_grad=zeros((N,1))
         np_func_grad[:,0]=func_grad[:]
         return np_func_grad
     
     val_grad4=FDValidGrad(2,f4,df4,fd_step=1.e-8)
     ok4,df_fd4,df4=val_grad4.compare([AoA0],treshold=1.e-6,return_all=True)
     assert(ok4)
 def test_DLLM_valid_grad_TCl(self):
     OC,wing_param = self.__init_wing_param()
     x0=wing_param.get_dv_array()
     
     DLLM = DLLMTargetCl('Simple',wing_param,OC)
     DLLM.set_target_Cl(0.5)
     DLLM.run_direct()
     DLLM.run_post()
     Ref_list=DLLM.get_F_list()
     
     def f1(x):
         wing_param.update_from_x_list(x)
         DLLM = DLLMTargetCl('Simple',wing_param,OC)
         DLLM.set_target_Cl(0.5)
         DLLM.run_direct()
         DLLM.run_post()
         func=DLLM.get_F_list()
         return func/Ref_list
        
     def df1(x):
         wing_param.update_from_x_list(x)
         DLLM = DLLMTargetCl('Simple',wing_param,OC)
         DLLM.set_target_Cl(0.5)
         DLLM.run_direct()
         DLLM.run_post()
         DLLM.run_adjoint()
         func_grad=np.array(DLLM.get_dF_list_dchi())
         N = func_grad.shape[0]
         ndv = func_grad.shape[1]
         out_grad = np.zeros((N,ndv))
         for i in xrange(N):
             out_grad[i,:] = func_grad[i,:]/Ref_list[i]
         return out_grad
        
     val_grad1=FDValidGrad(2,f1,df1,fd_step=1.e-8)
     ok1,df_fd1,df1=val_grad1.compare(x0,treshold=1.e-5,split_out=True,return_all=True)
     assert(ok1)
예제 #36
0
    def test_DLLM_valid_dpLoads_dpiAoA(self):
        OC, wing_param = self.__init_wing_param()
        DLLM = DLLMSolver('test', wing_param, OC)
        print ''
        DLLM.run_direct()
        iAoA0 = DLLM.get_iAoA()

        def f1(x):
            R = DLLM.comp_R(x)
            Post = DLLM.get_DLLMPost()
            func = Post.comp_Lift_distrib()
            return func

        def df1(x):
            R = DLLM.comp_R(x)
            Post = DLLM.get_DLLMPost()
            func_grad = Post.comp_dpLift_distrib_dpiAoA()
            return func_grad

        val_grad1 = FDValidGrad(2, f1, df1, fd_step=1.e-8)
        ok1, df_fd1, df1 = val_grad1.compare(iAoA0,
                                             treshold=1.e-2,
                                             return_all=True)
        assert (ok1)
예제 #37
0
DLLM = DLLMSolver('Simple',wing_param,OC)
DLLM.run_direct()
DLLM.run_post()
iAoA0=DLLM.get_iAoA()

def f(x):
    R=DLLM.comp_R(x)
#     print 'x=',x
#     print 'R=',R
#     print 'iAoA updated?:',DLLM.get_iAoA()
    Post=DLLM.get_DLLMPost()
    func=Post.comp_Lift_distrib()
#     print 'func=',func
    return func

def df(x):
    R=DLLM.comp_R(x)
    Post=DLLM.get_DLLMPost()
    func_grad=Post.comp_dpLift_distrib_dpiAoA()
    return func_grad

val_grad=FDValidGrad(2,f,df,fd_step=1.e-8)
ok,df_fd,df=val_grad.compare(iAoA0,treshold=1.e-2,return_all=True,split_out=True)


print '\n****************************************************'
if ok:
    print 'dpLoads_dpiAoA is valid.'
else:
    print '!!!! dpLoads_dpiAoA is NOT valid !!!!'
print '****************************************************'
예제 #38
0
DLLM = DLLMSolver('Simple',wing_param,OC)
DLLM.run_direct()
iAoA=DLLM.get_iAoA()

def f(x):
    wing_param.set_thetaY(x)
    DLLM.comp_R(iAoA)
    DLLM.set_direct_computed()
    DLLM.run_post()
    func=DLLM.get_F_list()
    return func

def df(x):
    wing_param.set_thetaY(x)
    DLLM.set_direct_computed()
    DLLM.run_post()
    func_grad=DLLM.get_dpF_list_dpthetaY()
    return func_grad

val_grad=FDValidGrad(2,f,df,fd_step=1.e-8)
ok,df_fd,df=val_grad.compare(thetaY0,treshold=1.e-6,return_all=True)


print '\n****************************************************'
if ok:
    print 'dpF_list_dpthetaY is valid.'
else:
    print '!!!! dpF_list_dp is NOT valid !!!!'
print '****************************************************'

# DLLM configuration
config_dict['Case.DLLM.type']='Solver'
config_dict['Case.DLLM.method']='inhouse'
config_dict['Case.DLLM.relax_factor']=0.99
config_dict['Case.DLLM.stop_residual']=1e-9
config_dict['Case.DLLM.max_iterations']=100
config_dict['Case.cond1.DLLM.gamma_file_name']='cond1_gamma.dat'
config_dict['Case.cond2.DLLM.gamma_file_name']='cond2_gamma.dat'
config_dict['Case.cond3.DLLM.gamma_file_name']='cond3_gamma.dat'

list_log=glob('*.log')
for log in list_log:
    os.remove(log)

MP=DLLMMP('Case')
MP.configure(config_dict)
MP.set_out_format('numpy')
MP.set_grad_format('numpy')

x0=MP.get_x0()

val_grad=FDValidGrad(2,MP.run,MP.run_grad,fd_step=1.e-8)
ok,df_fd,df=val_grad.compare(x0,treshold=1.e-6,split_out=True,return_all=True)

print '\n****************************************************'
if ok:
    print 'DLLMMP gradients are valid.'
else:
    print 'DLLMMP gradients are not valid!'
print '****************************************************'
예제 #40
0
def f(x):
    OC.set_AoA_rad(x[0])
    R=DLLM.comp_R(iAoA0)
#     print 'x=',x
#     print 'R=',R
#     print 'iAoA updated?:',DLLM.get_iAoA()
    Post=DLLM.get_DLLMPost()
    func=Post.comp_Lift_distrib()
#     print 'func=',func
    return func

def df(x):
    OC.set_AoA_rad(x[0])
    R=DLLM.comp_R(iAoA0)
    Post=DLLM.get_DLLMPost()
    func_grad=Post.comp_dpLift_distrib_dpAoA()
    N=len(func_grad)
    np_func_grad=numpy.zeros((N,1))
    np_func_grad[:,0]=func_grad[:]
    return np_func_grad

val_grad=FDValidGrad(2,f,df,fd_step=1.e-8)
ok,df_fd,df=val_grad.compare([AoA0],treshold=1.e-5,return_all=True)


print '\n****************************************************'
if ok:
    print 'dpLoads_dpAoA is valid.'
else:
    print '!!!! dpLoads_dpAoA is NOT valid !!!!'
print '****************************************************'
예제 #41
0
x0=wing_param.get_dv_array()
x_id=wing_param.get_dv_id_list()
print 'dv array shape',x0.shape
print 'dv_array=',x0

def f1(x):
    wing_param.update_from_x_list(x)
    func=wing_param.get_twist()
    return func

def df1(x):
    wing_param.update_from_x_list(x)
    func_grad=wing_param.get_twist_grad()
    return func_grad

val_grad1=FDValidGrad(2,f1,df1,fd_step=1.e-8)
ok1,df_fd1,df1=val_grad1.compare(x0,treshold=1.e-6,return_all=True)

def f2(x):
    wing_param.update_from_x_list(x)
    func=wing_param.get_chords()
    return func

def df2(x):
    wing_param.update_from_x_list(x)
    func_grad=wing_param.get_chords_grad()
    return func_grad

val_grad2=FDValidGrad(2,f2,df2,fd_step=1.e-8)
ok2,df_fd2,df2=val_grad2.compare(x0,treshold=1.e-6,return_all=True)
예제 #42
0
print wing_param


DLLM = DLLMSolver("Simple", wing_param, OC)
DLLM.run_direct()
iAoA0 = DLLM.get_iAoA()
print "iAoA0 shape", iAoA0.shape
print "iAoA0=", iAoA0


def f(x):
    func = DLLM.comp_R(x)
    return func


def df(x):
    func_grad = DLLM.comp_dpR_dpiAoA(x)
    return func_grad


val_grad = FDValidGrad(2, f, df, fd_step=1.0e-8)
ok, df_fd, df = val_grad.compare(iAoA0, treshold=1.0e-6, return_all=True)


print "\n****************************************************"
if ok:
    print "dpR_dpiAoA is valid."
else:
    print "!!!! dpR_dpiAoA is NOT valid !!!!"
print "****************************************************"
예제 #43
0
    DLLM.run_direct()
    DLLM.run_post()
    func=DLLM.get_F_list()
    return func

def df(x):
    wing_param.update_from_x_list(x)
    DLLM = DLLMTargetCl('Simple',wing_param,OC)
    DLLM.set_target_Cl(0.5)
    DLLM.run_direct()
    DLLM.run_post()
    DLLM.run_adjoint()
    func_grad=numpy.array(DLLM.get_dF_list_dchi())
    return func_grad

val_grad=FDValidGrad(2,f,df,fd_step=1.e-8)
ok,df_fd,df=val_grad.compare(x0,treshold=1.e-6,split_out=True,return_all=True)

for j in xrange(len(df[:,0])):
    fid=open('gradient_file'+str(j)+'.dat','w')
    for i in xrange(len(x0)):
        fid.write(str(i)+' '+str(df_fd[j,i])+' '+str(df[j,i])+'\n')
    fid.close()

print '\n****************************************************'
if ok:
    print 'DLLMTargetCl gradients are valid.'
else:
    print 'DLLMTargetCl gradients are not valid!'
print '****************************************************'
예제 #44
0
print 'dv_array=', x0


def f1(x):
    wing_param.update_from_x_list(x)
    func = wing_param.get_twist()
    return func


def df1(x):
    wing_param.update_from_x_list(x)
    func_grad = wing_param.get_twist_grad()
    return func_grad


val_grad1 = FDValidGrad(2, f1, df1, fd_step=1.e-8)
ok1, df_fd1, df1 = val_grad1.compare(x0, treshold=1.e-6, return_all=True)


def f2(x):
    wing_param.update_from_x_list(x)
    func = wing_param.get_chords()
    return func


def df2(x):
    wing_param.update_from_x_list(x)
    func_grad = wing_param.get_chords_grad()
    return func_grad

예제 #45
0
DLLM = DLLMSolver('Simple', wing_param, OC)
DLLM.run_direct()
iAoA0 = DLLM.get_iAoA()
AoA0 = OC.get_AoA_rad()


def f(x):
    OC.set_AoA_rad(x[0])
    func = DLLM.comp_R(iAoA0)
    return func


def df(x):
    OC.set_AoA_rad(x[0])
    func_grad = DLLM.comp_dpR_dpAoA()
    N = len(func_grad)
    np_func_grad = numpy.zeros((N, 1))
    np_func_grad[:, 0] = func_grad[:]
    return np_func_grad


val_grad = FDValidGrad(2, f, df, fd_step=1.e-8)
ok, df_fd, df = val_grad.compare([AoA0], treshold=1.e-6, return_all=True)

print '\n****************************************************'
if ok:
    print 'dpR_dpAoA is valid.'
else:
    print '!!!! dpR_dpAoA is NOT valid !!!!'
print '****************************************************'
예제 #46
0
print wing_param

thetaY0=wing_param.get_thetaY()
print 'thetaY0 shape',thetaY0.shape
print 'thetaY0=',thetaY0

DLLM = DLLMSolver('Meta',wing_param,OC)
DLLM.run_direct()
iAoA=DLLM.get_iAoA()

def f(x):
    wing_param.set_thetaY(x)
    func=DLLM.comp_R(iAoA)
    return func

def df(x):
    wing_param.set_thetaY(x)
    func_grad=DLLM.comp_dpR_dpthetaY()
    return func_grad

val_grad=FDValidGrad(2,f,df,fd_step=1.e-9)
ok,df_fd,df=val_grad.compare(thetaY0,treshold=1.e-6,return_all=True)


print '\n****************************************************'
if ok:
    print 'dpR_dpthetaY is valid.'
else:
    print '!!!! dpR_dpthetaY is NOT valid !!!!'
print '****************************************************'