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
...
@@ -14,9 +14,11 @@ classdef Result < handle
% indvel - Results obtained with the indVel solver
% indvel - Results obtained with the indVel solver
% stahlhut - Results obtained with the stalhlut solver
% stahlhut - Results obtained with the stalhlut solver
% operPts - Table with the operating points for each individual result
% operPts - Table with the operating points for each individual result
% ModExt - Modelling enstension options (losses, etc)
%
%
%
%
% Result methods:
% Result methods:
% save - Save the Result object to file
%
%
% Result constructor:
% Result constructor:
% Result = Result() creates an empty object.
% Result = Result() creates an empty object.
...
@@ -45,7 +47,8 @@ classdef Result < handle
...
@@ -45,7 +47,8 @@ classdef Result < handle
indfact
(
1
,
:)
OperRotor
% Results obtained with the indFact solver
indfact
(
1
,
:)
OperRotor
% Results obtained with the indFact solver
indvel
(
1
,
:)
OperRotor
% Results obtained with the indVel solver
indvel
(
1
,
:)
OperRotor
% Results obtained with the indVel solver
stahlhut
(
1
,
:)
OperRotor
% Results obtained with the stalhlut 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
end
methods
methods
...
@@ -57,5 +60,8 @@ classdef Result < handle
...
@@ -57,5 +60,8 @@ classdef Result < handle
% Currently empty on purpose. Results are to be assigned manually.
% Currently empty on purpose. Results are to be assigned manually.
end
end
% Other methods
save
(
self
,
SaveOpts
)
% Save the results to file
end
end
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
)
function
save
(
self
,
Save
Opts
)
% SAVE
RESULTS Save the fields of a strucure in a MAT-file, according to user's config
.
% SAVE
Method to save the Result object to a MAT-file
.
% This
function
saves the
fields of the input structure 'Struct' as individual variables,
% This
method
saves the
Result object in a MAT-file, following the user's the user's
%
following the user's configuration defin
ed rules for the file naming.
%
configur
ed rules for the file naming
and the saving directory
.
% -----
% -----
%
%
% Syntax:
% Syntax:
% saveresults(Struct, Save, Mod) Saves each field of the input Struct as individual variables
% Result.save() Prompt the user for a file name and directory and then save it.
% in a MAT-File, following the configuration options described in Sim.Save and Mod
%
% (see configs/template.m).
% Result.save(SaveOpts) Save the result object and name it following the options passed in
% SaveOpts.
%
%
% Inputs:
% Inputs:
% Struct : Struct whose fileds will be saved
% SaveOpts : (optional) Options for the naming of the saved file. Sturcture with fields
% Save : Save options (see Sim.Save structure)
% - overwrite (bool) Overwrite previous result if filename is the same
% Mod : Model configuration (see Mod structure)
% - dir (char) Directory where the results are saved
% - filename (char) Base file name of the saved result
%
%
% Outputs:
% 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>
% <a href="https://gitlab.uliege.be/rotare/documentation">Complete documentation (online)</a>
...
@@ -31,47 +33,59 @@ function saveresults(Struct, Save, Mod)
...
@@ -31,47 +33,59 @@ function saveresults(Struct, Save, Mod)
% Issues: https://gitlab.uliege.be/rotare/rotare/-/issues
% Issues: https://gitlab.uliege.be/rotare/rotare/-/issues
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create directory for the results if it does not exist
% Defaults and constants
if
~
isfolder
(
Save
.
dir
)
DEF
.
OVERWRITE
=
false
;
mkdir
(
Save
.
dir
);
DEF
.
FILENAME
=
'RotareResult.mat'
;
end
% Generate proper name based on user inputs
if
nargin
<
2
filename
=
formatfilename
(
Save
,
Mod
);
% 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 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
end
function
filename
=
formatfilename
(
Save
,
Mod
)
function
filename
=
formatfilename
(
Save
Opts
)
% FORMATFILENAME Format the filename using user configuration preferences.
% FORMATFILENAME Format the filename using user configuration preferences.
filename
=
Save
.
filename
;
TIME_FORMAT
=
'YYYYmmddTHHMM'
;
% Ensure user did not put an extension already
% Ensure user did not put an extension already
[
path
,
file
,
~
]
=
fileparts
(
filename
);
filename
=
removeextension
(
SaveOpts
.
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
% Prepend the file name with a timestamp
% Prevent overwriting file
if
Save
.
prependTime
if
~
SaveOpts
.
overwrite
timestamp
=
datestr
(
datetime
(
'now'
),
Save
.
timeFormat
);
% First preprend a timestamp at the front of the filename
timestamp
=
datestr
(
datetime
(
'now'
),
TIME_FORMAT
);
filename
=
[
timestamp
,
'-'
,
filename
];
filename
=
[
timestamp
,
'-'
,
filename
];
end
% Prevent overwriting file
% If not enough, add a _v1 at the end of the filename
if
~
Save
.
overwrite
baseFilename
=
filename
;
baseFilename
=
filename
;
i
=
0
;
i
=
0
;
while
isfile
([
Save
.
dir
,
filename
,
'.mat'
])
while
isfile
([
Save
Opts
.
dir
,
filename
,
'.mat'
])
i
=
i
+
1
;
i
=
i
+
1
;
filename
=
[
baseFilename
,
'_v'
,
num2str
(
i
)];
filename
=
[
baseFilename
,
'_v'
,
num2str
(
i
)];
end
end
end
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)
...
@@ -152,17 +152,17 @@ function [Results] = rotare(configFile)
% Output result in an easily accessible form
% Output result in an easily accessible form
Results
.
(
Mod
.
solver
)
=
OpRot
;
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
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 ==============================================
% ====================================== 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