Repository: fast-aircraft-design/FAST-OAD (language: python)

Issue:
FastMissionFileMissingMissionNameError when using payload_range mission
**Describe the bug**
I get a FastMissionFileMissingMissionNameError when using payload_range mission when the mission file contains multiple mission names.

**Error message**
Traceback (most recent call last):
  File "d:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\main\ACAP\EtudeBaseline\ACAP_results\02_O239+\01_Base_config\01_payload_range\payload_range.py", line 22, in <module>    
    api_cs25.generate_inputs(CONFIGURATION_FILE, SOURCE_FILE, overwrite=True)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\cmd\api.py", line 328, in generate_inputs
    conf.write_needed_inputs(source_data_path)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\io\configuration\configuration.py", line 216, in write_needed_inputs
    problem.write_needed_inputs(source_file_path, source_formatter)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\openmdao\problem.py", line 114, in write_needed_inputs
    [variable for variable in self.analysis.problem_variables if variable.is_input]
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\openmdao\problem.py", line 175, in analysis
    self._analysis = ProblemAnalysis(self)
  File "<string>", line 8, in __init__
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\openmdao\problem.py", line 349, in __post_init__
    self.analyze()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\openmdao\problem.py", line 357, in analyze
    om.Problem.setup(problem_copy)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\problem.py", line 1025, in setup
    model._setup(model_comm, self._metadata)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\group.py", line 733, in _setup
    self._setup_procs(self.pathname, comm, self._problem_meta)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\group.py", line 638, in _setup_procs
    subsys._setup_procs(subsys.pathname, sub_comm, prob_meta)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\group.py", line 638, in _setup_procs
    subsys._setup_procs(subsys.pathname, sub_comm, prob_meta)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\group.py", line 583, in _setup_procs
    self.setup()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\module_management\service_registry.py", line 288, in setup
    self.options[name] = value
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 526, in __setitem__
    self._assert_valid(name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 311, in _assert_valid
    meta['check_valid'](name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu    self.options[name] = value
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 526, in __setitem__
    self._assert_valid(name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 311, in _assert_valid
    meta['check_valid'](name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu    self._assert_valid(name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 311, in _assert_valid
    meta['check_valid'](name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu    meta['check_valid'](name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fuel_usage
el_usage
    if self.mission_name:
    if self.mission_name:
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\mission_definition\mission_builder\mission_builder.py", line 
148, in mission_name
    self._mission_name = self.get_unique_mission_name()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\mission_definition\mission_builder\mission_builder.py", line 
282, in get_unique_mission_name
    raise FastMissionFileMissingMissionNameError(
fastoad.models.performances.mission.mission_definition.exceptions.FastMissionFileMissingMissionNameError: Mission name must be specified if several missions are defined in mission file. 
FastMissionFileMissingMissionNameError when using payload_range mission
**Describe the bug**
I get a FastMissionFileMissingMissionNameError when using payload_range mission when the mission file contains multiple mission names.

**Error message**
Traceback (most recent call last):
  File "d:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\main\ACAP\EtudeBaseline\ACAP_results\02_O239+\01_Base_config\01_payload_range\payload_range.py", line 22, in <module>    
    api_cs25.generate_inputs(CONFIGURATION_FILE, SOURCE_FILE, overwrite=True)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\cmd\api.py", line 328, in generate_inputs
    conf.write_needed_inputs(source_data_path)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\io\configuration\configuration.py", line 216, in write_needed_inputs
    problem.write_needed_inputs(source_file_path, source_formatter)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\openmdao\problem.py", line 114, in write_needed_inputs
    [variable for variable in self.analysis.problem_variables if variable.is_input]
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\openmdao\problem.py", line 175, in analysis
    self._analysis = ProblemAnalysis(self)
  File "<string>", line 8, in __init__
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\openmdao\problem.py", line 349, in __post_init__
    self.analyze()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\openmdao\problem.py", line 357, in analyze
    om.Problem.setup(problem_copy)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\problem.py", line 1025, in setup
    model._setup(model_comm, self._metadata)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\group.py", line 733, in _setup
    self._setup_procs(self.pathname, comm, self._problem_meta)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\group.py", line 638, in _setup_procs
    subsys._setup_procs(subsys.pathname, sub_comm, prob_meta)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\group.py", line 638, in _setup_procs
    subsys._setup_procs(subsys.pathname, sub_comm, prob_meta)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\core\group.py", line 583, in _setup_procs
    self.setup()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\module_management\service_registry.py", line 288, in setup
    self.options[name] = value
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 526, in __setitem__
    self._assert_valid(name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 311, in _assert_valid
    meta['check_valid'](name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu    self.options[name] = value
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 526, in __setitem__
    self._assert_valid(name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 311, in _assert_valid
    meta['check_valid'](name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu    self._assert_valid(name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\openmdao\utils\options_dictionary.py", line 311, in _assert_valid
    meta['check_valid'](name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu    meta['check_valid'](name, value)
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\payload_range.py", line 113, in _update_mission_wrapper
    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu    self._mission_wrapper.force_all_block_fuel_usage()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fu  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\openmdao\mission_wrapper.py", line 100, in force_all_block_fuel_usage
el_usage
    if self.mission_name:
    if self.mission_name:
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\mission_definition\mission_builder\mission_builder.py", line 
148, in mission_name
    self._mission_name = self.get_unique_mission_name()
  File "D:\estragio\CPOR\03_Projet\02_ACAP\01_Code\etude_cleanaviation\.venv\lib\site-packages\fastoad\models\performances\mission\mission_definition\mission_builder\mission_builder.py", line 
282, in get_unique_mission_name
    raise FastMissionFileMissingMissionNameError(
fastoad.models.performances.mission.mission_definition.exceptions.FastMissionFileMissingMissionNameError: Mission name must be specified if several missions are defined in mission file. 


Discussion / hints:
It turns out that the problem come from the order in which the yml file is given.
This
```  mission:
    payload_range:
      id: fastoad.performances.payload_range
      propulsion_id: fastoad.wrapper.propulsion.rubber_engine
      mission_name: MTOW_mission
      mission_file_path: ConfigFiles/missions.yml
      ...
```
works as expected, while
```  mission:
    payload_range:
      id: fastoad.performances.payload_range
      propulsion_id: fastoad.wrapper.propulsion.rubber_engine
      mission_file_path: ConfigFiles/missions.yml
      mission_name: MTOW_mission
      ...
```
doesn't. To investigate. the problem is only for payload_range mission.
It turns out that the problem come from the order in which the yml file is given.
This
```  mission:
    payload_range:
      id: fastoad.performances.payload_range
      propulsion_id: fastoad.wrapper.propulsion.rubber_engine
      mission_name: MTOW_mission
      mission_file_path: ConfigFiles/missions.yml
      ...
```
works as expected, while
```  mission:
    payload_range:
      id: fastoad.performances.payload_range
      propulsion_id: fastoad.wrapper.propulsion.rubber_engine
      mission_file_path: ConfigFiles/missions.yml
      mission_name: MTOW_mission
      ...
```
doesn't. To investigate. the problem is only for payload_range mission.

Fix patch:
diff --git a/src/fastoad/models/performances/mission/openmdao/mission_wrapper.py b/src/fastoad/models/performances/mission/openmdao/mission_wrapper.py
index 01e1b1451..0f19464d5 100644
--- a/src/fastoad/models/performances/mission/openmdao/mission_wrapper.py
+++ b/src/fastoad/models/performances/mission/openmdao/mission_wrapper.py
@@ -97,7 +97,7 @@ def __init__(
 
     def force_all_block_fuel_usage(self):
         """Modifies mission definition to set block fuel as target fuel consumption."""
-        if self.mission_name:
+        if self._mission_name:
             self.definition.force_all_block_fuel_usage(self.mission_name)
             self._update_structure_builders()
 


Test patch:
diff --git a/src/fastoad/models/performances/mission/openmdao/tests/data/test_payload_range.yml b/src/fastoad/models/performances/mission/openmdao/tests/data/test_payload_range.yml
index 5eef290c8..9527a1b3a 100644
--- a/src/fastoad/models/performances/mission/openmdao/tests/data/test_payload_range.yml
+++ b/src/fastoad/models/performances/mission/openmdao/tests/data/test_payload_range.yml
@@ -103,3 +103,9 @@ missions:
       - phase: takeoff
       - route: main_route
       - route: diversion
+  dummy:
+    parts:
+      - phase: start
+      - phase: taxi_out
+      - phase: takeoff
+      - route: main_route