예제 #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)
# 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 '****************************************************'
예제 #3
0
config_dict['Case.param.desc.tip_height.value'] = 0.33
config_dict['Case.param.desc.tip_height.bounds'] = (0.2, 0.5)

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

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)

# 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()