Creating, populating and assigning a VEThermalTemplate

The VE Python API allows users create simple programs using the Python Programming Language, to interact with a VE Model and/or Vista Results File
Post Reply
TG359
VE Newbie
VE Newbie
Posts: 5
Joined: Thu Nov 07, 2013 1:01 pm

Creating, populating and assigning a VEThermalTemplate

Post by TG359 »

Hi VE Scripters,

I'm trying to create a new VEThermalTemplate (and some CasualGains to be attributed to it).

So far I've managed to instantiate a new VEThermalTemplate, but am stuck when trying to modify that template. It looks as though Boost.Python is enabling a get but no set for it, but I've got no experience with Boost so beyond that is a mystery to me. The method I've used to create a new VEThermalTemplate is shown below for context:

Code: Select all

>>> import iesve
>>> new_template = iesve.VEThermalTemplate.__new__(iesve.VEThermalTemplate)
>>> print(new_template)
<iesve.VEThermalTemplate object at 0x27F87770>
I've also tried to do the same with a CasualGain, to building some entirely new ones from scratch to attribute to an existing VEThermalTemplate object, but have come across the same issue there also.

Is there another method for instantiating and then passing new VEThermalTemplates and CasualGains to the project?
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Creating, populating and assigning a VEThermalTemplate

Post by Rhind »

Hi,

You can't create a valid VEThermalTemplate or CasualGains object from scratch. Also for CasualGains you can only read data, not set it.

However you can modify an existing VEThemalTemplate object. Here are the methods in VEThemalTemplate you can use for that:

set (room_conditions, system_data)
Set both System Data and Room Conditions settings by passing in dictionaries of settings.
See set_apache_systems and set_room_conditions for dictionary keys.

set_apache_systems(system_data)
Set System Data settings by passing in a dictionary of settings.
Dictionary keys are:

aux_vent_system
aux_vent_system_same
conditioned
cooling_capacity_units
cooling_capacity_value
cooling_plant_radiant_fraction
dhw_system
dhw_system_same
heating_capacity_units
heating_capacity_value
heating_plant_radiant_fraction
HVAC_methodology
HVAC_system
system_air_free_cooling
system_air_free_cooling_units
system_air_minimum_flowrate
system_air_minimum_flowrate_units
system_air_variation_profile


set_room_conditions(room_conditions)
Set Room Conditions settings by passing in a dictionary of settings.
Dictionary keys are:

cooling_profile
cooling_setpoint
cooling_setpoint_constant
cooling_setpoint_profile
dhw
dhw_profile
dhw_units
heating_profile
heating_setpoint
heating_setpoint_constant
heating_setpoint_profile
plant_profile
plant_profile_type
sat_perc_lower
sat_perc_upper

You can also add and remove air exchanges and casual gains from the template. Have a look at these methods:

add_air_exchange(airExchange)
Add an AirExchange object to the template.

add_gain(casualGain)
Add a CasualGain object to the template.

remove_air_exchange(airExchange)
Remove air exchange from template. Will throw exception if air exchange is not associated with template.

remove_gain(casualGain)
Remove casual gain from template. Will throw exception if gain is not associated with template.

If you want to apply the changes made to the template back to the model, you'll need to call apply_changes():

apply_changes()
Apply any changes made to the template to the model. Note: if this is not called, changes to the template will not be reflected in the model. This includes changes to gains and air exchanges for the template.
Note – this operation may take a significant amount of time on large models.

Here's an example of correct usage:

Code: Select all

import iesve   # the VE api

# Get the current VE project.  
# Getting the thermal templates is a project-level operation
proj = iesve.VEProject.get_current_project()

# Get a list of the known thermal templates
# Pass True to only get templates in use (assigned), False to get all templates
templates = proj.thermal_templates(False)
    
# the templates are returned as a dictionary
# for this sample we don't need the key (the template handle)
# so iterate over the dictionary values only
templates_iter = templates.values()
for template in templates_iter:
    
    # we can check the type of a template by checking its 'standard' attribute
    # this returns an enum that can represent: generic, NCM, or PRM
    # this allows filtering of templates similar to BTM's behaviour of not showing
    # NCM templates by default
    if template.standard != iesve.VEThermalTemplate_standard.generic:
        continue  # skip PRM and NCM templates
    
    sys_settings = { 'HVAC_system': 'SYST0000',
                     'HVAC_methodology': iesve.hvac_methodology.apache_system,
                     'conditioned': iesve.conditioned_flag.yes,
                     'aux_vent_system': 'SYST0000',
                     'aux_vent_system_same': False,
                     'cooling_capacity_units': iesve.heating_cooling_capacity_unit.unlimited,
                     'cooling_capacity_value': 0.0,
                     'cooling_plant_radiant_fraction': 0.0,
                     'dhw_system': 'SYST0000',
                     'dhw_system_same': False,
                     'heating_capacity_units': iesve.heating_cooling_capacity_unit.unlimited,
                     'heating_capacity_value': 0.0,
                     'heating_plant_radiant_fraction': 0.2,
                     'system_air_free_cooling': 0.0,
                     'system_air_free_cooling_units': 0,
                     'system_air_minimum_flowrate': 0.800000011920929,
                     'system_air_minimum_flowrate_units': 2,
                     'system_air_variation_profile': 'OFF'}
    
    room_settings = {'sat_perc_lower': 0.0,
                     'heating_setpoint': 19.0,
                     'cooling_setpoint': 23.0,
                     'dhw_units': 'l/h',
                     'cooling_setpoint_profile': '0',
                     'dhw_profile': '-', 
                     'plant_profile_type': 0, 
                     'dhw': 10.0,
                     'cooling_setpoint_constant': True,
                     'cooling_profile': 'ON',
                     'plant_profile': 'ON',
                     'sat_perc_upper': 100.0, 
                     'heating_setpoint_constant': True,
                     'heating_profile': 'ON', 
                     'heating_setpoint_profile': '0'}
    
    template.set(room_settings, sys_settings)
    template.apply_changes()
    
print("Templates set!")
You can also assign templates to the model by calling assign_thermal_template_to_rooms() in VEModel:

assign_thermal_template_to_rooms( template, [roomID] )
Assign the VEThermalTemplate template to the rooms, indicated by list of Room IDs (strings or VEBody objects).

Example usage for this:

Code: Select all

""""
This sample resets the selected rooms in the real model back to the "Default"
thermal template.

If no rooms are selected, it resets ALL rooms!

CAUTION: this script will modify your model !

"""

import iesve   # the VE api

# the list of models is accessed through the project API
project = iesve.VEProject.get_current_project()

# get the real building
real_building = project.models[0]

# build the list of room IDs to assign template to
room_id_list = []

# first we get only the selected rooms - if no rooms were selected
# (empty list returned), then we get all rooms
selected_rooms = real_building.get_bodies(True)
if len(selected_rooms) == 0:
    print("No rooms were selected - resetting all rooms back to default template")
    selected_rooms = real_building.get_bodies(False)

# now build a list of room IDs
for body in selected_rooms:
    if body.type == iesve.VEBody_type.room:
        room_id_list.append(body.id)

print("Assigning default template to {} room(s)".format(len(room_id_list)))

# find the default thermal template
# we start with getting the full list of thermal templates
templates = project.thermal_templates(False)

# the templates are returned as a dictionary
# for this sample we don't need the key (the template handle)
# so iterate over the dictionary values only
# and we look for a template with the name "default" - this should
# always exist in every project!
templates_iter = templates.values()
for template in templates_iter:
    if template.name == "default":
        real_building.assign_thermal_template_to_rooms(template, room_id_list)
        # no need to process further templates, so break out of the for loop
        break

# end of sample
Hope that helps.
tg358
VE Newbie
VE Newbie
Posts: 2
Joined: Mon Nov 19, 2018 4:21 pm

Re: Creating, populating and assigning a VEThermalTemplate

Post by tg358 »

Thanks for the response.

Are there plans for this functionality to be added to the API in the future (or are more pointedly, have set methods been enabled in the beta with read-write exposed by Boost)?

For the time being, is it also possible for changes to be made to a pre-existing VEThermalTemplate, without those changes being applied to all the spaces to which that template is assigned?

For example we'd have a model with 20 spaces, of which there are 4 different thermal templates. We can modify room and system conditions, and assign a template (using preconfigured internal gains that could be modified but not created), and then bypass the fact that we can't create a new VEThermalTemplate instance by modifying casual gains per space-type ... or would the changes made to the single existing VEThermalTemplate be carried across to all spaces to which it is assigned?
tg358
VE Newbie
VE Newbie
Posts: 2
Joined: Mon Nov 19, 2018 4:21 pm

Re: Creating, populating and assigning a VEThermalTemplate

Post by tg358 »

Thanks for your response Rhind.

In that case, is there a way to modify an instance of a VEThermalTemplate such that spaces that template is assigned to maintain those modificatons? For example, a model with three spaces and a single thermal template could have no internal gains in one space, while the remaining two spaces have lighting and equipment gains, set dynamically from some other external source.

If not, surely this would be a useful feature to enable the dynamic creation of specific thermal templates. As we're already able to modify conditions and system data get/set must be applied there, but is there much work involved in enabling write on top of the existing read for these instance attributes?
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Creating, populating and assigning a VEThermalTemplate

Post by Rhind »

I know this is not ideal but as a workaround you could create a number of templates in the normal way (i.e. through the user interface) before running your script. Your script could then edit (and assign) these pre-created templates.

Hope that helps.
DelD
VE Newbie
VE Newbie
Posts: 1
Joined: Wed Jul 10, 2019 8:39 am

Re: Creating, populating and assigning a VEThermalTemplate

Post by DelD »

Hi,

I'd like to use add_gain().
I wrote : Template.add_gain(casual_gain) after defined casual_gain as showed in the examples but it doesn't work. Would it be possible to have more information on this function ? maybe an example of how to use it ?
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Creating, populating and assigning a VEThermalTemplate

Post by Rhind »

DelD wrote: Wed Jul 10, 2019 8:42 am Hi,

I'd like to use add_gain().
I wrote : Template.add_gain(casual_gain) after defined casual_gain as showed in the examples but it doesn't work. Would it be possible to have more information on this function ? maybe an example of how to use it ?
Here's an example (bit contrived but you get the idea):

Code: Select all

import iesve

proj = iesve.VEProject.get_current_project()
templates = proj.thermal_templates(False)

if len(templates) > 1:
    write_to_next = False
    casual_gains = None
    
    templates_iter = templates.values()
    for template in templates_iter:
        if write_to_next:
            print("Before:")
            print(template.get_casual_gains())
            
            template.add_gain(casual_gains[0])
            
            print("After")
            print(template.get_casual_gains())
            exit()
        else:           
            casual_gains = template.get_casual_gains()
            
            if casual_gains:
                write_to_next = True
    
    print("Add casual gains")
else:
    print("Add thermal templates")
Post Reply