Class: CleanupSpaceOrigins

Inherits:
OpenStudio::Measure::ModelMeasure
  • Object
show all
Defined in:
lib/measures/CleanupSpaceOrigins/measure.rb

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input



24
25
26
27
28
# File 'lib/measures/CleanupSpaceOrigins/measure.rb', line 24

def arguments(model)
  args = OpenStudio::Measure::OSArgumentVector.new

  return args
end

#cleanup_group(group) ⇒ Object

assign the user inputs to variables



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/measures/CleanupSpaceOrigins/measure.rb', line 41

def cleanup_group(group)
  boundingBox = group.transformation * group.boundingBox

  if boundingBox.isEmpty
    return
  end

  matrix = OpenStudio::Matrix.new(4, 4, 0)
  matrix[0, 0] = 1
  matrix[1, 1] = 1
  matrix[2, 2] = 1
  matrix[3, 3] = 1
  matrix[0, 3] = boundingBox.minX.get
  matrix[1, 3] = boundingBox.minY.get
  matrix[2, 3] = boundingBox.minZ.get
  translation = OpenStudio::Transformation.new(matrix)
  group.changeTransformation(translation)
end

#nameObject

define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml



19
20
21
# File 'lib/measures/CleanupSpaceOrigins/measure.rb', line 19

def name
  return 'CleanupSpaceOrigins'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



31
32
33
34
35
36
37
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/measures/CleanupSpaceOrigins/measure.rb', line 31

def run(model, runner, user_arguments)
  super(model, runner, user_arguments)

  # use the built-in error checking
  if !runner.validateUserArguments(arguments(model), user_arguments)
    return false
  end

  # assign the user inputs to variables

  def cleanup_group(group)
    boundingBox = group.transformation * group.boundingBox

    if boundingBox.isEmpty
      return
    end

    matrix = OpenStudio::Matrix.new(4, 4, 0)
    matrix[0, 0] = 1
    matrix[1, 1] = 1
    matrix[2, 2] = 1
    matrix[3, 3] = 1
    matrix[0, 3] = boundingBox.minX.get
    matrix[1, 3] = boundingBox.minY.get
    matrix[2, 3] = boundingBox.minZ.get
    translation = OpenStudio::Transformation.new(matrix)
    group.changeTransformation(translation)
  end

  # reporting initial condition of model
  planarSurfaceGroups = model.getPlanarSurfaceGroups
  runner.registerInitialCondition("The building has #{planarSurfaceGroups.size} planar surface groups.")

  # do spaces first as these may contain other groups
  model.getSpaces.each do |space|
    next if !runner.inSelection(space)

    cleanup_group(space)

    space.shadingSurfaceGroups.each do |group|
      cleanup_group(group)
    end

    space.interiorPartitionSurfaceGroups.each do |group|
      cleanup_group(group)
    end
  end

  # now do shading surfaces
  model.getShadingSurfaceGroups.each do |group|
    next if !runner.inSelection(group)

    cleanup_group(group)
  end

  # now do interior partition surface groups
  model.getInteriorPartitionSurfaceGroups.each do |group|
    next if !runner.inSelection(group)

    cleanup_group(group)
  end

  # reporting final condition of model
  runner.registerFinalCondition('All planar surface group origins have been inspected, and adjusted as necessary.')

  return true
end