%% Battery Sizing and Automotive Electrical System Analysis

% Copyright 2019 The MathWorks, Inc.
%% Overview
% This example shows how to model a typical automotive electrical
% system as an architectural model and run primitive analysis. 
% The elements in the model can be broadly grouped as either source or load. 
% Various properties of the sources and loads are set as part of the stereotype.
% The example uses the iterate method of the specification API to iterate through each element
% of the model and run analysis using the stereotype properties.
%%
%% Structure of the Model
% The generator charges the battery while the engine is running. The
% battery, along with the generator supports the electrical loads in the vehicle, like ECU,
% radio, and body control. The inductive loads like motors
% and other coils have the InRushCurrent stereotype property defined.
% Based on the properties set on each component, the following analyses are performed:
%%
% * Total KeyOffLoad 
% * Number of days required for KeyOffLoad to discharge 30 percent of the battery
% * Total CrankingInRush current
% * Total Cranking current
% * Ability of the battery to start the vehicle at 0 degrees F based on the battery
% cold cranking amps (CCA).
% The discharge time is computed based on Puekert coefficient (k), which
% describes the relationship between the rate of discharge and the available capacity
% of the battery.
%%
%% Load the Model and Run the Analysis
archModel = systemcomposer.openModel('scExampleAutomotiveElectricalSystemAnalysis');
% Instantiate battery sizing class used by the analysis function to store
% analysis results.
objcomputeBatterySizing = computeBatterySizing;
% Run the analysis using the iterator.
archModel.iterate('Topdown',@computeLoad,objcomputeBatterySizing);
% Display analysis results.
objcomputeBatterySizing.displayResults;
%%
%% Close the Model
bdclose('scExampleAutomotiveElectricalSystemAnalysis');

