Skip to content

Improve Emissions handling consistency #291

Description

@boulderdaze

These three tasks are related to the code in src/validate.cpp.

  • Build assembles species/phases/reactions/aerosol, but emissions is parsed separately. To unify mechanism construction, move ParseEmissionsSection(...) into Build so species, phases, reactions, aerosol, and emissions are all assembled in one place.

  • Separate emissions validation: Validate(const Mechanism&) currently validates gas and aerosol, with emissions handled inside ValidateGasModel. Since emissions are optional, consider introducing a dedicated ValidateEmissionsModel function.

  • Verify whether emissions are only semantically validated during parsing and not for in-code mechanisms. If so, add equivalent validation to the in-code mechanism validation path.

src/v1/parser.cpp

  std::expected<Mechanism, Errors> Parser::ValidateAndBuild(const YAML::Node& object)
  {
    try
    {
      Errors errors = CheckSchema(object);

      if (errors.empty()) {...}

      if (!errors.empty()){...}

      Mechanism mechanism = Build(object);

      Errors aerosol_errors = ValidateAerosolModel(mechanism);
      if (!aerosol_errors.empty())
      {
        AppendFilePath(config_path_, aerosol_errors);
        return std::unexpected(std::move(aerosol_errors));
      }

      /// 
      /// Asymmetry: Build assembles species/phases/reactions/aerosol, but emissions is parsed separately after.
      /// 
      if (object[std::string(keys::emissions)])
      {
        mechanism.emissions = ParseEmissionsSection(object[std::string(keys::emissions)]);
      }
      return mechanism;
    }
    catch (const std::exception& e){...}
  }

  Mechanism Parser::Build(const YAML::Node& object)
  {
    Mechanism mechanism;

    mechanism.version = Version(object[keys::version].as<std::string>());
    mechanism.species = ParseSpecies(object[keys::species]);
    mechanism.phases = ParsePhases(object[keys::phases]);
    
    if (object[keys::reactions])
    {
      mechanism.reactions = ParseReactions(object[keys::reactions]);
    }
    if (object[keys::aerosol_representations] && object[keys::aerosol_processes]) 
    {
      mechanism.aerosol = ParseAerosol(object, mechanism.species, mechanism.phases);
    }
    /// 
    /// Build assembles species/phases/reactions/aerosol, but emissions is parsed separately. 
    /// 
    if (object[keys::name])
    {
      mechanism.name = object[keys::name].as<std::string>();
    }

    return mechanism;
  }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions