本文整理汇总了Python中MDOTools.ValidGrad.FDValidGrad.FDValidGrad类的典型用法代码示例。如果您正苦于以下问题:Python FDValidGrad类的具体用法?Python FDValidGrad怎么用?Python FDValidGrad使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FDValidGrad类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_DLLM_MP_AoA_valid_grad
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)
示例2: test_DLLM_valid_dpLoads_dpAoA
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)
示例3: test_DLLM_valid_grad_TLift
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)
示例4: test_DLLM_valid_grad_TCl
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)
示例5: test_DLLM_valid_dpF_list_dpchi
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)
示例6: test_DLLM_wrapper_json_valid_grad
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)
示例7: test_DLLM_valid_dpF_list_dpAoA
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: test_DLLM_wrapper_TLift_valid_grad
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)
示例9: test_DLLM_valid_dpLoads_distrib_dpAoA
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)
示例10: test_jacobian
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)
示例11: test_DLLM_valid_dpLoads_distrib_dpchi
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)
示例12: test_Wing_param_valid_grad_XYZ
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)
示例13: test_Wing_param_valid_grad_eta
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)
示例14: test_Wing_param_valid_grad_rel_thicks
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)
示例15: test_Wing_param_valid_grad_chords
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)