mdolab / openconcept

OpenConcept: A toolkit for conceptual MDAO of aircraft with unconventional propulsion architectures
MIT License
36 stars 32 forks source link

Numpy array size error in MissionFlightConditions #10

Closed onodip closed 4 years ago

onodip commented 5 years ago

Hi!

When trying out the TBM850 example I got a vector size mismatch (see traceback at the end).

Some of the vars have a shape (n, 1), and some (n,).

I fixed with adding the two lines below to MissionFlightConditions to get the same shape for all vectors:

    def compute(self, inputs, outputs):

        n_int_per_seg = self.options['n_int_per_seg']
        nn = n_int_per_seg*2 + 1
        hvec_climb = np.linspace(inputs['mission|takeoff|h'],inputs['mission|cruise|h'],nn)
        hvec_desc = np.linspace(inputs['mission|cruise|h'],inputs['mission|takeoff|h'],nn)
        hvec_cruise = np.ones(nn)*inputs['mission|cruise|h']
        hvec_climb = np.reshape(hvec_climb, hvec_climb.size) 
        hvec_desc = np.reshape(hvec_desc, hvec_desc.size)
        ...

I did not modify anything in the code before trying. Package versions as in the reqs, I am running it on Windows, and I tried with Python 2.7 and 3.7.

Is this a known issue, or something wrong with my installation?

Traceback:

======Analyzing Fuel Burn for Given Mision============
Traceback (most recent call last):
  File "D:/Documents/GitHub/openconcept/examples/TBM850.py", line 318, in <module>
    prob.run_model()
  File "D:\Documents\GitHub\openconcept\venv37\lib\site-packages\openmdao\core\problem.py", line 461, in run_model
    return self.model.run_solve_nonlinear()
  File "D:\Documents\GitHub\openconcept\venv37\lib\site-packages\openmdao\core\system.py", line 2546, in run_solve_nonlinear
    result = self._solve_nonlinear()
  File "D:\Documents\GitHub\openconcept\venv37\lib\site-packages\openmdao\core\group.py", line 1592, in _solve_nonlinear
    result = self._nonlinear_solver.solve()
  File "D:\Documents\GitHub\openconcept\venv37\lib\site-packages\openmdao\solvers\solver.py", line 633, in solve
    fail, abs_err, rel_err = self._run_iterator()
  File "D:\Documents\GitHub\openconcept\venv37\lib\site-packages\openmdao\solvers\solver.py", line 361, in _run_iterator
    norm0, norm = self._iter_initialize()
  File "D:\Documents\GitHub\openconcept\venv37\lib\site-packages\openmdao\solvers\nonlinear\newton.py", line 216, in _iter_initialize
    subsys._solve_nonlinear()
  File "D:\Documents\GitHub\openconcept\venv37\lib\site-packages\openmdao\core\explicitcomponent.py", line 218, in _solve_nonlinear
    failed = self.compute(self._inputs, self._outputs)
  File "D:\Documents\GitHub\openconcept\openconcept\analysis\mission.py", line 143, in compute
    outputs['fltcond|mission|h'] = np.concatenate([hvec_climb,hvec_cruise,hvec_desc])
ValueError: all the input arrays must have same number of dimensions
onodip commented 5 years ago

Some update: i was looking into an older commit, but after updating I got the same vector issue, which was fixed by adding alts = np.reshape(alts, alts.size) line:

    def compute(self, inputs, outputs):

        n_int_per_seg = self.options['n_int_per_seg']
        mission_segment_names = self.options['mission_segments']
        nn = (n_int_per_seg * 2 + 1)
        nn_tot = nn * len(mission_segment_names)
        last_seg_index = len(mission_segment_names) - 1
        altitude_vecs = []
        Ueas_vecs = []
        vs_vecs = []
        for i, segment_name in enumerate(mission_segment_names):
            if i == last_seg_index:
                h0 = inputs[segment_name+'|h0']
                hf = inputs[segment_name+'|hf']
            else:
                next_seg_name = mission_segment_names[i+1]
                h0 = inputs[segment_name+'|h0']
                hf = inputs[next_seg_name+'|h0']
            vs = (hf - h0) / inputs[segment_name+'|time']

            alts = np.linspace(h0,hf,nn)
            alts = np.reshape(alts, alts.size)

            altitude_vecs.append(alts)
            Ueas_vecs.append(np.ones(nn)*inputs[segment_name+'|Ueas'])
            vs_vecs.append(np.ones(nn)*vs)
            outputs[segment_name+'|dt'] = inputs[segment_name+'|time'] / (nn-1)

        outputs['fltcond|h'] = np.concatenate(altitude_vecs)
        outputs['fltcond|Ueas'] = np.concatenate(Ueas_vecs)
        outputs['fltcond|vs'] = np.concatenate(vs_vecs)
bbrelje commented 5 years ago

Hi @onodip , can you tell me which version of numpy you're using?

onodip commented 5 years ago

I had numpy 1.16.2 (the newest), I just used the requirements file to install the packages in a clean virtual environment.

Now I tried with 1.15.0, and it suddenly works! Hmm, maybe something is messed up in the new numpy version?