Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Rotare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rouma Alexandre
Rotare
Commits
18e19121
Verified
Commit
18e19121
authored
1 year ago
by
Thomas Lambert
Browse files
Options
Downloads
Patches
Plain Diff
chore(Rotare): Adjust autosave to Result.save
parent
e464bbe5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/classes/@Result/Result.m
+7
-1
7 additions, 1 deletion
src/classes/@Result/Result.m
src/classes/@Result/save.m
+91
-0
91 additions, 0 deletions
src/classes/@Result/save.m
src/rotare.m
+9
-9
9 additions, 9 deletions
src/rotare.m
with
107 additions
and
10 deletions
src/classes/@Result/Result.m
+
7
−
1
View file @
18e19121
...
...
@@ -14,9 +14,11 @@ classdef Result < handle
% indvel - Results obtained with the indVel solver
% stahlhut - Results obtained with the stalhlut solver
% operPts - Table with the operating points for each individual result
% ModExt - Modelling enstension options (losses, etc)
%
%
% Result methods:
% save - Save the Result object to file
%
% Result constructor:
% Result = Result() creates an empty object.
...
...
@@ -45,7 +47,8 @@ classdef Result < handle
indfact
(
1
,
:)
OperRotor
% Results obtained with the indFact solver
indvel
(
1
,
:)
OperRotor
% Results obtained with the indVel solver
stahlhut
(
1
,
:)
OperRotor
% Results obtained with the stalhlut solver
operPts
(:,
4
)
table
% Table of operating points for each individual result
operPts
(:,
4
)
table
% Table of operating points for each individual result
ModExt
(
1
,
1
)
struct
% Modelling enstension options (losses, etc)
end
methods
...
...
@@ -57,5 +60,8 @@ classdef Result < handle
% Currently empty on purpose. Results are to be assigned manually.
end
% Other methods
save
(
self
,
SaveOpts
)
% Save the results to file
end
end
This diff is collapsed.
Click to expand it.
src/
utils/saveresults
.m
→
src/
classes/@Result/save
.m
+
91
−
0
View file @
18e19121
function
save
results
(
Struct
,
Save
,
Mod
)
% SAVE
RESULTS Save the fields of a strucure in a MAT-file, according to user's config
.
% This
function
saves the
fields of the input structure 'Struct' as individual variables,
%
following the user's configuration defin
ed rules for the file naming.
function
save
(
self
,
Save
Opts
)
% SAVE
Method to save the Result object to a MAT-file
.
% This
method
saves the
Result object in a MAT-file, following the user's the user's
%
configur
ed rules for the file naming
and the saving directory
.
% -----
%
% Syntax:
% saveresults(Struct, Save, Mod) Saves each field of the input Struct as individual variables
% in a MAT-File, following the configuration options described in Sim.Save and Mod
% (see configs/template.m).
% Result.save() Prompt the user for a file name and directory and then save it.
%
% Result.save(SaveOpts) Save the result object and name it following the options passed in
% SaveOpts.
%
% Inputs:
% Struct : Struct whose fileds will be saved
% Save : Save options (see Sim.Save structure)
% Mod : Model configuration (see Mod structure)
% SaveOpts : (optional) Options for the naming of the saved file. Sturcture with fields
% - overwrite (bool) Overwrite previous result if filename is the same
% - dir (char) Directory where the results are saved
% - filename (char) Base file name of the saved result
%
% Outputs:
% MAT-file with the
Struct fields as variables
.
% MAT-file with the
saved Result object
.
%
% See also: rotare, template.
% See also: rotare,
Result,
template.
%
% <a href="https://gitlab.uliege.be/rotare/documentation">Complete documentation (online)</a>
...
...
@@ -31,47 +33,59 @@ function saveresults(Struct, Save, Mod)
% Issues: https://gitlab.uliege.be/rotare/rotare/-/issues
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create directory for the results if it does not exist
if
~
isfolder
(
Save
.
dir
)
mkdir
(
Save
.
dir
);
end
% Defaults and constants
DEF
.
OVERWRITE
=
false
;
DEF
.
FILENAME
=
'RotareResult.mat'
;
% Generate proper name based on user inputs
filename
=
formatfilename
(
Save
,
Mod
);
if
nargin
<
2
% Prompt user for filename
[
filename
,
SaveOpts
.
dir
]
=
uiputfile
(
DEF
.
FILENAME
,
'*.mat'
);
filename
=
removeextension
(
filename
);
% Remove ext as it is added during save()
else
% Create directory for the results if it does not exist
if
~
isfolder
(
SaveOpts
.
dir
)
mkdir
(
SaveOpts
.
dir
);
end
% Generate proper name based on user inputs
filename
=
formatfilename
(
SaveOpts
);
end
% Save to file
save
([
Save
.
dir
,
filename
,
'.mat'
],
'-struct'
,
'Struct'
);
tempFile
.
Results
=
self
;
% So it can be saved properly
save
([
SaveOpts
.
dir
,
filename
,
'.mat'
],
'-struct'
,
'tempFile'
);
end
function
filename
=
formatfilename
(
Save
,
Mod
)
function
filename
=
formatfilename
(
Save
Opts
)
% FORMATFILENAME Format the filename using user configuration preferences.
filename
=
Save
.
filename
;
TIME_FORMAT
=
'YYYYmmddTHHMM'
;
% Ensure user did not put an extension already
[
path
,
file
,
~
]
=
fileparts
(
filename
);
filename
=
fullfile
(
path
,
file
);
% Append the solver name and loss model to the file name
if
Save
.
appendInfo
filename
=
[
filename
,
'_'
,
Mod
.
solver
,
'_'
,
Mod
.
Ext
.
losses
];
end
filename
=
removeextension
(
SaveOpts
.
filename
);
% Prepend the file name with a timestamp
if
Save
.
prependTime
timestamp
=
datestr
(
datetime
(
'now'
),
Save
.
timeFormat
);
% Prevent overwriting file
if
~
SaveOpts
.
overwrite
% First preprend a timestamp at the front of the filename
timestamp
=
datestr
(
datetime
(
'now'
),
TIME_FORMAT
);
filename
=
[
timestamp
,
'-'
,
filename
];
end
% Prevent overwriting file
if
~
Save
.
overwrite
% If not enough, add a _v1 at the end of the filename
baseFilename
=
filename
;
i
=
0
;
while
isfile
([
Save
.
dir
,
filename
,
'.mat'
])
while
isfile
([
Save
Opts
.
dir
,
filename
,
'.mat'
])
i
=
i
+
1
;
filename
=
[
baseFilename
,
'_v'
,
num2str
(
i
)];
end
end
end
function
filename
=
removeextension
(
filename
)
% REMOVEEXTENSION Remove extension from a filename if there was one
[
path
,
file
,
~
]
=
fileparts
(
filename
);
filename
=
fullfile
(
path
,
file
);
end
This diff is collapsed.
Click to expand it.
src/rotare.m
+
9
−
9
View file @
18e19121
...
...
@@ -152,17 +152,17 @@ function [Results] = rotare(configFile)
% Output result in an easily accessible form
Results
.
(
Mod
.
solver
)
=
OpRot
;
Results
.
operPts
=
array2table
(
operPoints
,
...
'VariableNames'
,
{
'Alt'
,
'V_ax'
,
'RPM'
,
'Coll'
});
% Save solution to MAT-file for future reusability
if
Sim
.
Save
.
autosave
TmpStruct
.
OpRot
=
OpRot
;
saveresults
(
TmpStruct
,
Sim
.
Save
,
Mod
);
clear
TmpStruct
;
end
end
% Add context to the Results and save if needed
Results
.
operPts
=
array2table
(
operPoints
,
...
'VariableNames'
,
{
'Alt'
,
'V_ax'
,
'RPM'
,
'Coll'
});
Results
.
ModExt
=
Mod
.
Ext
;
if
Sim
.
Save
.
autosave
Results
.
save
(
Sim
.
Save
);
end
% ==============================================================================================
% ====================================== Analysis ==============================================
% ==============================================================================================
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment