Measures/m_5_example_5_computed_schedule/resources/util.rb
# Creates (or returns an existing) OpenStudio Material from our own Material object
Creates (or returns an existing) OpenStudio Material from our own Material object
Creates ( or returns an existing ) OpenStudio Material from our own Material object
def create_os_material(model, runner, material, name=nil)
            if name.nil?
                name = material.name
            end
            tolerance = 0.0001
            if material.is_a? SimpleMaterial
                model.getMasslessOpaqueMaterials.each do |mat|
                    next if mat.name.to_s != name.to_s
                    next if mat.roughness.downcase.to_s != "rough"
                    next if (mat.thermalResistance - UnitConversions.convert(material.rvalue,"hr*ft^2*F/Btu","m^2*K/W")).abs > tolerance
                    return mat
                end
                mat = OpenStudio::Model::MasslessOpaqueMaterial.new(model)
                mat.setName(name)
                mat.setRoughness("Rough")
                mat.setThermalResistance(UnitConversions.convert(material.rvalue,"hr*ft^2*F/Btu","m^2*K/W"))
            elsif material.is_a? GlazingMaterial
                model.getSimpleGlazings.each do |mat|
                    next if mat.name.to_s != name.to_s
                    next if (mat.uFactor - material.ufactor).abs > tolerance
                    next if (mat.solarHeatGainCoefficient - material.shgc).abs > tolerance
                    return mat
                end
                mat = OpenStudio::Model::SimpleGlazing.new(model)
                mat.setName(name)
                mat.setUFactor(material.ufactor)
                mat.setSolarHeatGainCoefficient(material.shgc)
            else
                model.getStandardOpaqueMaterials.each do |mat|
                    next if mat.name.to_s != name.to_s
                    next if mat.roughness.downcase.to_s != "rough"
                    next if (mat.thickness - UnitConversions.convert(material.thick_in,"in","m")).abs > tolerance
                    next if (mat.conductivity - UnitConversions.convert(material.k,"Btu/(hr*ft*R)","W/(m*K)")).abs > tolerance
                    next if (mat.density - UnitConversions.convert(material.rho,"lbm/ft^3","kg/m^3")).abs > tolerance
                    next if (mat.specificHeat - UnitConversions.convert(material.cp,"Btu/(lbm*R)","J/(kg*K)")).abs > tolerance
                    next if not material.tAbs.nil? and (mat.thermalAbsorptance - material.tAbs).abs > tolerance
                    next if not material.sAbs.nil? and (mat.solarAbsorptance - material.sAbs).abs > tolerance
                    next if not material.vAbs.nil? and (mat.visibleAbsorptance - material.vAbs).abs > tolerance
                    return mat
                end
                mat = OpenStudio::Model::StandardOpaqueMaterial.new(model)
                mat.setName(name)
                mat.setRoughness("Rough")
                mat.setThickness(UnitConversions.convert(material.thick_in,"in","m"))
                mat.setConductivity(UnitConversions.convert(material.k,"Btu/(hr*ft*R)","W/(m*K)"))
                mat.setDensity(UnitConversions.convert(material.rho,"lbm/ft^3","kg/m^3"))
                mat.setSpecificHeat(UnitConversions.convert(material.cp,"Btu/(lbm*R)","J/(kg*K)"))
                if not material.tAbs.nil?
                    mat.setThermalAbsorptance(material.tAbs)
                end
                if not material.sAbs.nil?
                    mat.setSolarAbsorptance(material.sAbs)
                end
                if not material.vAbs.nil?
                    mat.setVisibleAbsorptance(material.vAbs)
                end
            end
            runner.registerInfo("Material '#{mat.name.to_s}' was created.")
            return mat
        end
def create_os_material ( model , runner , material , name = nil ) if name . nil? name = material . name end tolerance = 0.0001 if material . is_a? SimpleMaterial model . getMasslessOpaqueMaterials . each do | mat | next if mat . name . to_s != name . to_s next if mat . roughness . downcase . to_s != "rough" next if ( mat . thermalResistance - UnitConversions . convert ( material . rvalue , "hr*ft^2*F/Btu" , "m^2*K/W" ) ) . abs > tolerance return mat end mat = OpenStudio :: Model :: MasslessOpaqueMaterial . new ( model ) mat . setName ( name ) mat . setRoughness ( "Rough" ) mat . setThermalResistance ( UnitConversions . convert ( material . rvalue , "hr*ft^2*F/Btu" , "m^2*K/W" ) ) elsif material . is_a? GlazingMaterial model . getSimpleGlazings . each do | mat | next if mat . name . to_s != name . to_s next if ( mat . uFactor - material . ufactor ) . abs > tolerance next if ( mat . solarHeatGainCoefficient - material . shgc ) . abs > tolerance return mat end mat = OpenStudio :: Model :: SimpleGlazing . new ( model ) mat . setName ( name ) mat . setUFactor ( material . ufactor ) mat . setSolarHeatGainCoefficient ( material . shgc ) else model . getStandardOpaqueMaterials . each do | mat | next if mat . name . to_s != name . to_s next if mat . roughness . downcase . to_s != "rough" next if ( mat . thickness - UnitConversions . convert ( material . thick_in , "in" , "m" ) ) . abs > tolerance next if ( mat . conductivity - UnitConversions . convert ( material . k , "Btu/(hr*ft*R)" , "W/(m*K)" ) ) . abs > tolerance next if ( mat . density - UnitConversions . convert ( material . rho , "lbm/ft^3" , "kg/m^3" ) ) . abs > tolerance next if ( mat . specificHeat - UnitConversions . convert ( material . cp , "Btu/(lbm*R)" , "J/(kg*K)" ) ) . abs > tolerance next if not material . tAbs . nil? and ( mat . thermalAbsorptance - material . tAbs ) . abs > tolerance next if not material . sAbs . nil? and ( mat . solarAbsorptance - material . sAbs ) . abs > tolerance next if not material . vAbs . nil? and ( mat . visibleAbsorptance - material . vAbs ) . abs > tolerance return mat end mat = OpenStudio :: Model :: StandardOpaqueMaterial . new ( model ) mat . setName ( name ) mat . setRoughness ( "Rough" ) mat . setThickness ( UnitConversions . convert ( material . thick_in , "in" , "m" ) ) mat . setConductivity ( UnitConversions . convert ( material . k , "Btu/(hr*ft*R)" , "W/(m*K)" ) ) mat . setDensity ( UnitConversions . convert ( material . rho , "lbm/ft^3" , "kg/m^3" ) ) mat . setSpecificHeat ( UnitConversions . convert ( material . cp , "Btu/(lbm*R)" , "J/(kg*K)" ) ) if not material . tAbs . nil? mat . setThermalAbsorptance ( material . tAbs ) end if not material . sAbs . nil? mat . setSolarAbsorptance ( material . sAbs ) end if not material . vAbs . nil? mat . setVisibleAbsorptance ( material . vAbs ) end end runner . registerInfo ( "Material '#{mat.name.to_s}' was created." ) return mat end
Creates (or returns an existing) OpenStudio Material from our own Material object
Creates ( or returns an existing ) OpenStudio Material from our own Material object
# Material already exists? # New material # Material already exists? # New material # Material already exists? # New material
model
<not_specific>
runner
<not_specific>
material
<not_specific>
name
<not_specific>