Class: Honeybee::EnergyWindowMaterialGasMixture

Inherits:
ModelObject
  • Object
show all
Defined in:
lib/honeybee/material/window_gas_mixture.rb,
lib/to_openstudio/material/window_gas_mixture.rb,
lib/from_openstudio/material/window_gas_mixture.rb

Instance Attribute Summary

Attributes inherited from ModelObject

#errors, #openstudio_object, #warnings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModelObject

#allowable_types, clean_identifier, clean_name, #initialize, #method_missing, read_from_disk, truncate

Constructor Details

This class inherits a constructor from Honeybee::ModelObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Honeybee::ModelObject

Class Method Details

.from_material(material) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/from_openstudio/material/window_gas_mixture.rb', line 38

def self.from_material(material)
    # create an empty hash
    hash = {}
    hash[:type] = 'EnergyWindowMaterialGasMixture'
    # set hash values from OpenStudio Object
    hash[:identifier] = clean_name(material.nameString)
    unless material.displayName.empty?
        hash[:display_name] = (material.displayName.get).force_encoding("UTF-8")
    end
    hash[:thickness] = material.thickness
    hash[:gas_types] = []
    hash[:gas_fractions] = []
    number_of_gases = material.numberofGasesinMixture
    if number_of_gases > 1
        (1..number_of_gases).each do |n|
            hash[:gas_types] << material.send('gas' + n.to_s + 'Type')
        end
        hash[:gas_fractions] << material.gas1Fraction
        hash[:gas_fractions] << material.gas2Fraction
        if number_of_gases > 2
            unless material.gas3Fraction.empty?
                hash[:gas_fractions] << material.gas3Fraction.get
            end
            if number_of_gases > 3
                unless material.gas4Fraction.empty?
                    hash[:gas_fractions] << material.gas4Fraction.get
                end
            end
        end
    end

    hash
end

Instance Method Details

#defaultsObject



37
38
39
# File 'lib/honeybee/material/window_gas_mixture.rb', line 37

def defaults
  @@schema[:components][:schemas][:EnergyWindowMaterialGasMixture][:properties]
end

#find_existing_openstudio_object(openstudio_model) ⇒ Object



39
40
41
42
43
# File 'lib/to_openstudio/material/window_gas_mixture.rb', line 39

def find_existing_openstudio_object(openstudio_model)
  object = openstudio_model.getGasMixtureByName(@hash[:identifier])
  return object.get if object.is_initialized
  nil
end

#to_openstudio(openstudio_model) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/to_openstudio/material/window_gas_mixture.rb', line 45

def to_openstudio(openstudio_model)
  # create the gas mixture
  os_gas_mixture = OpenStudio::Model::GasMixture.new(openstudio_model)
  os_gas_mixture.setName(@hash[:identifier])
  unless @hash[:display_name].nil?
    os_gas_mixture.setDisplayName(@hash[:display_name])
  end
  # set the thickness
  if @hash[:thickness]
    os_gas_mixture.setThickness(@hash[:thickness])
  else
    os_gas_mixture.setThickness(defaults[:thickness][:default])
  end

  # set the gas types
  @hash[:gas_types].each_index do |i|
    os_gas_mixture.setGasType(i, @hash[:gas_types][i])
  end

  # set the gas fractions
  @hash[:gas_fractions].each_index do |i|
    os_gas_mixture.setGasFraction(i, @hash[:gas_fractions][i])
  end

  os_gas_mixture
end