pythontraceback

Traceback error and script can't read csv


I am getting a traceback most recent call last from a iteraction between dakota and python. I need to give a csv file for python and dakota read, but when i start running it shows the the error traceback most recent call last.

The code works as follows:

Here is the code for calculation which is imported (its the only part of it the real code have 3500 lines)

def ED0_takeOff(t, S):
        x, v = S
        dxdt = v
        T = self.trac_Available(v, rho)
        if fancy_way:
             Re = (self.c*v)/1.60E-5 # visc. cinemática do ar a 30°C
                try:
                    cl_perfil, cd_perfil = interp_coef(self.df_perfil, self.ao, Re)
                    #Cl_asa = Cl_correcao(self.df_perfil, Re, self.ao)
                    Cl_asa = cl_perfil*0.82 #perdas da asa finita.
                    Cd_asa = cd_perfil + self.K*(Cl_asa**2)
                    Cd_airplane = Cd_asa + self.C_D0
                    D = self.drag_Force(v, Cd_airplane, rho, Ground_Effect)  
                    R = self.mi * (self.W - self.lift_Force(v, Cl_asa, rho))    
                except:
                    print('Provide the aerodynamic profile dataframe in the class constructor.. Ex: zb.Airplane(df_perfil=df)')
        else:
             D = self.drag_Force(v, self.C_D, rho, Ground_Effect)  # Testar CLmax e CLn or CLLO
             R = self.mi * (self.W - self.lift_Force(v, self.CLLO, rho))
            dvdt = (T - D - R) / (self.M)
            return [dxdt, dvdt]


It is in the source.py where the error happens in cmd.

    # Compute the responses using the Dakota-provided variable values.
results[0].function = obj_1(params["Cr"], params["Af"], params["b"], params["L"])
results[1].function = obj_2(params["Cr"], params["Af"], params["b"], params["L"])

results[2].function = con_1(params["Cr"], params["Af"], params["b"], params["L"])
results[3].function = con_2(params["Cr"], params["Af"], params["b"], params["L"])
results[4].function = manouver_point(params["Cr"], params["Af"], params["b"], params["L"])

Here is the error :


Provide the aerodynamic profile dataframe in the class constructor. Ex: zb.Airplane(df_perfil=df)
Traceback (most recent call last): 

File "directory\source.py", line 143, in 

results[3].function = con_2(params["Cr"], params["Af"], params["b"], params["L"])

File "directory\source.py", line 96, in con_2
    return Zb.takeOff_Distance_EDO(fancy_way=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\zebraperformance.py", line 2360, in takeOff_Distance_EDO
    sol = solve_ivp(ED0_takeOff, t_span=(min(t), max(t)), y0=S_0, t_eval=t)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\ivp.py", line 555, in solve_ivp
    solver = method(fun, t0, y0, tf, vectorized=vectorized, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\rk.py", line 94, in __init__
    self.f = self.fun(self.t, self.y)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "directory\base.py", line 138, in fun
    return self.fun_single(t, y)
           ^^^^^^^^^^^^^^^^^^^^^
  File "directory\base.py", line 20, in fun_wrapped
    return np.asarray(fun(t, y), dtype=dtype)
                      ^^^^^^^^^
  File "directory\zebraperformance.py", line 2350, in ED0_takeOff
    dvdt = (T - D - R) / (self.M)
                ^
UnboundLocalError: cannot access local variable 'D' where it is not associated with a value

Solution

  • You had variable D in else, but you can't reference D because it isn't created. For starters, your indentation isn't proper, python requires proper indentation to work. Both your D and R need to be set back one space. Should be reachable code.