Home > matpower5.1 > runopf.m

runopf

PURPOSE ^

RUNOPF Runs an optimal power flow.

SYNOPSIS ^

function [MVAbase, bus, gen, gencost, branch, f, success, et] =runopf(casedata, mpopt, fname, solvedcase)

DESCRIPTION ^

RUNOPF  Runs an optimal power flow.
   [RESULTS, SUCCESS] = RUNOPF(CASEDATA, MPOPT, FNAME, SOLVEDCASE)

   Runs an optimal power flow (AC OPF by default), optionally returning
   a RESULTS struct and SUCCESS flag.

   Inputs (all are optional):
       CASEDATA : either a MATPOWER case struct or a string containing
           the name of the file with the case data (default is 'case9')
           (see also CASEFORMAT and LOADCASE)
       MPOPT : MATPOWER options struct to override default options
           can be used to specify the solution algorithm, output options
           termination tolerances, and more (see also MPOPTION).
       FNAME : name of a file to which the pretty-printed output will
           be appended
       SOLVEDCASE : name of file to which the solved case will be saved
           in MATPOWER case format (M-file will be assumed unless the
           specified name ends with '.mat')

   Outputs (all are optional):
       RESULTS : results struct, with the following fields:
           (all fields from the input MATPOWER case, i.e. bus, branch,
               gen, etc., but with solved voltages, power flows, etc.)
           order - info used in external <-> internal data conversion
           et - elapsed time in seconds
           success - success flag, 1 = succeeded, 0 = failed
           (additional OPF fields, see OPF for details)
       SUCCESS : the success flag can additionally be returned as
           a second output argument

   Calling syntax options:
       results = runopf;
       results = runopf(casedata);
       results = runopf(casedata, mpopt);
       results = runopf(casedata, mpopt, fname);
       results = runopf(casedata, mpopt, fname, solvedcase);
       [results, success] = runopf(...);

       Alternatively, for compatibility with previous versions of MATPOWER,
       some of the results can be returned as individual output arguments:

       [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(...);

   Example:
       results = runopf('case30');

   See also RUNDCOPF, RUNUOPF.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [MVAbase, bus, gen, gencost, branch, f, success, et] = ...
0002                 runopf(casedata, mpopt, fname, solvedcase)
0003 %RUNOPF  Runs an optimal power flow.
0004 %   [RESULTS, SUCCESS] = RUNOPF(CASEDATA, MPOPT, FNAME, SOLVEDCASE)
0005 %
0006 %   Runs an optimal power flow (AC OPF by default), optionally returning
0007 %   a RESULTS struct and SUCCESS flag.
0008 %
0009 %   Inputs (all are optional):
0010 %       CASEDATA : either a MATPOWER case struct or a string containing
0011 %           the name of the file with the case data (default is 'case9')
0012 %           (see also CASEFORMAT and LOADCASE)
0013 %       MPOPT : MATPOWER options struct to override default options
0014 %           can be used to specify the solution algorithm, output options
0015 %           termination tolerances, and more (see also MPOPTION).
0016 %       FNAME : name of a file to which the pretty-printed output will
0017 %           be appended
0018 %       SOLVEDCASE : name of file to which the solved case will be saved
0019 %           in MATPOWER case format (M-file will be assumed unless the
0020 %           specified name ends with '.mat')
0021 %
0022 %   Outputs (all are optional):
0023 %       RESULTS : results struct, with the following fields:
0024 %           (all fields from the input MATPOWER case, i.e. bus, branch,
0025 %               gen, etc., but with solved voltages, power flows, etc.)
0026 %           order - info used in external <-> internal data conversion
0027 %           et - elapsed time in seconds
0028 %           success - success flag, 1 = succeeded, 0 = failed
0029 %           (additional OPF fields, see OPF for details)
0030 %       SUCCESS : the success flag can additionally be returned as
0031 %           a second output argument
0032 %
0033 %   Calling syntax options:
0034 %       results = runopf;
0035 %       results = runopf(casedata);
0036 %       results = runopf(casedata, mpopt);
0037 %       results = runopf(casedata, mpopt, fname);
0038 %       results = runopf(casedata, mpopt, fname, solvedcase);
0039 %       [results, success] = runopf(...);
0040 %
0041 %       Alternatively, for compatibility with previous versions of MATPOWER,
0042 %       some of the results can be returned as individual output arguments:
0043 %
0044 %       [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(...);
0045 %
0046 %   Example:
0047 %       results = runopf('case30');
0048 %
0049 %   See also RUNDCOPF, RUNUOPF.
0050 
0051 %   MATPOWER
0052 %   Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC)
0053 %   by Ray Zimmerman, PSERC Cornell
0054 %
0055 %   $Id: runopf.m 2644 2015-03-11 19:34:22Z ray $
0056 %
0057 %   This file is part of MATPOWER.
0058 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0059 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0060 
0061 %%-----  initialize  -----
0062 %% default arguments
0063 if nargin < 4
0064     solvedcase = '';                %% don't save solved case
0065     if nargin < 3
0066         fname = '';                 %% don't print results to a file
0067         if nargin < 2
0068             mpopt = mpoption;       %% use default options
0069             if nargin < 1
0070                 casedata = 'case9'; %% default data file is 'case9.m'
0071             end
0072         end
0073     end
0074 end
0075 
0076 %%-----  run the optimal power flow  -----
0077 [r, success] = opf(casedata, mpopt);
0078 
0079 %%-----  output results  -----
0080 if fname
0081     [fd, msg] = fopen(fname, 'at');
0082     if fd == -1
0083         error(msg);
0084     else
0085         if mpopt.out.all == 0
0086             printpf(r, fd, mpoption(mpopt, 'out.all', -1));
0087         else
0088             printpf(r, fd, mpopt);
0089         end
0090         fclose(fd);
0091     end
0092 end
0093 printpf(r, 1, mpopt);
0094 
0095 %% save solved case
0096 if solvedcase
0097     savecase(solvedcase, r);
0098 end
0099 
0100 if nargout == 1 || nargout == 2
0101     MVAbase = r;
0102     bus = success;
0103 elseif nargout > 2
0104     [MVAbase, bus, gen, gencost, branch, f, et] = ...
0105         deal(r.baseMVA, r.bus, r.gen, r.gencost, r.branch, r.f, r.et);
0106 % else  %% don't define MVAbase, so it doesn't print anything
0107 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005