Skip to content

Commit

Permalink
Merge pull request #66 from chrishavlin/low_hanging
Browse files Browse the repository at this point in the history
Various small fixes and improvements
  • Loading branch information
chrishavlin authored Sep 22, 2023
2 parents b6bd5d8 + ba948f2 commit 04bf464
Show file tree
Hide file tree
Showing 26 changed files with 326 additions and 199 deletions.
5 changes: 2 additions & 3 deletions Projects/bayesian_fitting/functions/process_SeismicModels.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
% lon longitude - assumed to be positive [degrees East]
% z_min minimum depth for observation range [km]
% z_max maximum depth for observation range [km]
% (smooth_rad) half-width of box size in which to average
% observations - if this field is not in location,
% a default value of 0.5 is assumed [degrees E and N]
% smooth_rad half-width of box size in which to average
% observations [degrees]
%
% model_file string with path to saved .mat file of observations
% This .mat file is expected to contain a single variable
Expand Down
6 changes: 3 additions & 3 deletions docs/_pages/vbrmethods/visc/xfit_premelt.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Steady state flow law for pre-melting viscosity drop following Yamauchi and Take

## Requires

In addition to the state variable arrays required by the other viscous methods (see [HK2003](/vbrmethods/visc/hk2003/), [HZK2011](/vbrmethods/visc/hzk2011/)), this method also requires a solidus:
In addition to the state variable arrays required by the other viscous methods (see [HK2003](/vbr/vbrmethods/visc/hk2003/), [HZK2011](/vbr/vbrmethods/visc/hzk2011/)), this method also requires a solidus:

```matlab
VBR.in.SV.Tsolidus_K % solidus in degrees K
Expand Down Expand Up @@ -43,9 +43,9 @@ VBR.in.viscous.xfit_premelt = Params_Viscous('xfit_premelt');
disp(VBR.in.viscous.xfit_premelt)
```

### eta_dry_method
### eta_melt_free_method

The parameter, `VBR.in.viscous.xfit_premelt.eta_dry_method`, controls what viscosity method to use to calculate the melt free viscosity. By default, this is set to `xfit_premelt`, in which case it uses the upper mantle fit directly from Yamauchi and Takei (2016). If set to one of the other viscosity mtehods, `HK2003` or `HZK2011`, then the melt free viscosity is calculated using those methods with melt fraction set to 0 and then the near-solidus pre-melting effect is then multiplied on.
The parameter, `VBR.in.viscous.xfit_premelt.eta_melt_free_method`, controls what viscosity method is used to calculate the melt free viscosity. By default, this is set to `xfit_premelt`, in which case it uses the upper mantle fit directly from Yamauchi and Takei (2016). If set to one of the other viscosity mtehods, `HK2003` or `HZK2011`, then the melt free viscosity is calculated using those methods with melt fraction set to 0 and then the near-solidus pre-melting effect is then multiplied on.

## Output
Output is stored in `VBR.out.viscous.xfit_premelt`. Unlike the other viscous methods, `xfit_premelt` only returns a diffusion creep viscosity sub-structure:
Expand Down
28 changes: 18 additions & 10 deletions release_history.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
# v1.0.1

Bug fix release.

## bug fixes

- rename `Project/bayesian_fitting/run.m` to `run_bayes.m` to avoid name conflict.

# v1.0.0

This is the first series-1 release! It is backwards compatible.

## new features
## new features

- units metadata: `VBR.in.SV` as well as all output methods now contain a units structure that contains the units for each field. You can also call `SV_input_units()` to get a structure that lists the expected units for each `VBR.in.SV` field.
- version tracking: after calling `VBR_spine`, all `VBR` structures will have a field, `VBR.version_used` with info on the VBR version that you used.
- a new function for calculating density as a function of pressure, using an interpolation of experimental measurements on F90 San Carlos olivine, `san_carlos_density_from_pressure`, following Abramson et al., JGR, 1997. Useful for
- a new function for calculating density as a function of pressure, using an interpolation of experimental measurements on F90 San Carlos olivine, `san_carlos_density_from_pressure`, following Abramson et al., JGR, 1997. Useful for
quickly calculating olivine density for a given pressure.

## bug fixes

(add bug fixes)

## changes
## changes

- some of the functions related to non-seismic material properties used in the forward
models directory have been moved and renamed. No change in usage, but it is now easier
- some of the functions related to non-seismic material properties used in the forward
models directory have been moved and renamed. No change in usage, but it is now easier
to use those functions in a piecemeal fashion if desired. See functions in the `density`
and `thermal_properties` subdirectories within `vbr/vbrCore/fucntions/` for available
functions.
and `thermal_properties` subdirectories within `vbr/vbrCore/fucntions/` for available
functions.

# v0.99.4
# v0.99.4

maintenance updates (testing, github CI, documentation)

## new features
## new features

- `vbr_version()` function, returns the version of the VBRc that you are using

# v <= 0.99.3

release_history.md covers v>0.99.3.
release_history.md covers v>0.99.3.
8 changes: 1 addition & 7 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# v1.0.1

Bug fix release.

## bug fixes

- rename `Project/bayesian_fitting/run.m` to `run_bayes.m` to avoid name conflict.
# v1.1.0
8 changes: 8 additions & 0 deletions vbr/support/is_octave.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function is_octave_bool = is_octave()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% is_octave()
%
% returns 1 if running in Octave, 0 if running in MATLAB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
is_octave_bool = exist('OCTAVE_VERSION', 'builtin') ~= 0;
end
52 changes: 34 additions & 18 deletions vbr/testing/run_tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
end

if numel(mfiles) > 0
[TestResults, failedCount, SkippedTests] = runTheMfiles(mfiles, test_config);
[TestResults, failedCount, SkippedTests, ErrorMessages] = runTheMfiles(mfiles, test_config);
TestResults.failedCount = failedCount;
TestResults.n_tests = numel(mfiles);
else
Expand All @@ -49,61 +49,77 @@
disp('Testing complete.')
disp(' ')
if TestResults.failedCount > 0
disp('Displaying failed test functions. Please run each one and debug:')
disp('Displaying failed test functions:')
fldz=fieldnames(TestResults);
for ifi = 1:numel(fldz)
fld=TestResults.(fldz{ifi});
if fld==0
disp([' ',fldz{ifi}])
ei = ErrorMessages.(fldz{ifi});
disp([' ', ei.identifier, ': ', ei.message])

end
end
elseif TestResults.n_tests == 0
disp('found no tests to run')
else
skfields = fieldnames(SkippedTests);
if numel(skfields) > 0
for ifield = 1:numel(skfields)
reason = SkippedTests.(skfields{ifield});
disp('Displaying Skipped tests and reason for skipping:')
disp([' ', skfields{ifield}, " : ", reason])
end
else
disp('all test functions ran successfully')
disp('Test functions ran successfully')
end

skfields = fieldnames(SkippedTests);
if numel(skfields) > 0
for ifield = 1:numel(skfields)
reason = SkippedTests.(skfields{ifield});
disp(' ')
disp('Displaying Skipped tests and reason for skipping:')
disp([' ', skfields{ifield}, " : ", reason])
disp(' ')
end
end


end

function [TestResults,failedCount, SkippedTests] = runTheMfiles(mfiles, test_config)
function [TestResults,failedCount, SkippedTests, ErrorMessages] = runTheMfiles(mfiles, test_config)
TestResults=struct();
SkippedTests = struct();
ErrorMessages = struct();
failedCount=0;
isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0;

for ifile = 1:numel(mfiles)
fname=mfiles(ifile).name;
if ~strcmp('run_tests.m',fname)
[fdir,funcname,ext]=fileparts(fname);

[fdir,funcname,ext]=fileparts(fname);
disp([' **** Running ', funcname, ' ****'])
if any(strcmp(test_config.matlab_only, funcname)) && isOctave
SkippedTests.(funcname) = "MATLAB Only";
else

try
testResult=feval(funcname);
if testResult>0
test_error.message = testResult.fail_message;
test_error.identifier = 'VBRc_TEST_ERROR';
if testResult.passed>0
disp(' test passed :D'); disp(' ')
else
failedCount=failedCount+1;
disp(' test failed :('); disp(' ')
end
catch
catch ME
err_id = ME.identifier;
err_msg = ME.message;
test_error = ME;
disp([' ',funcname,' failed :('])
disp([' please run ',funcname,'() and debug.']); disp(' ')
testResult=false;
disp(' ')
disp([' ', err_id, ': ', err_msg])
disp(' ')
testResult.passed=false;
failedCount=failedCount+1;
end
TestResults.(funcname)=testResult;
TestResults.(funcname)=testResult.passed;
ErrorMessages.(funcname) = test_error;
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions vbr/testing/test_fm_plates_001.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_001 ****')

% Load Default Settings
[settings]=init_settings;
Expand Down Expand Up @@ -42,5 +43,6 @@
% Lithosphere temperature evolution
[Vars,Info]=Thermal_Evolution(Info,settings);

TestResult=true;
TestResult.passed=true;
TestResult.fail_message = '';
end
23 changes: 14 additions & 9 deletions vbr/testing/test_fm_plates_002.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_002 ****')
disp(' (takes a few minutes)')
TestResult=true;
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TestResult.passed=true;
TestResult.fail_message = '';
% Load Default Settings
[settings]=init_settings;

Expand Down Expand Up @@ -53,8 +54,10 @@
% get the diffusivity (make sure it's constant)
kappa=Vars.Kc ./ (Vars.rho .* Vars.cp);
if min(kappa(:))<max(kappa(:))
TestResult=false;
disp(' diffusivity is not constant!!!!!')
TestResult.passed=false;
msg = ' diffusivity is not constant!!!!!';
TestResult.fail_message = msg;
disp(msg)
end
kappa=min(kappa(:));

Expand All @@ -73,8 +76,10 @@
t_cutoffs=[5,Info.tMyrs(end)]; % min/max for transient h space soln
tmask=(Info.tMyrs>=t_cutoffs(1))&(Info.tMyrs<=t_cutoffs(2));
if sum(max_err(tmask)>max_err_tol)
disp(' half space cooling solution incorrect!!!!!')
TestResult=false;
msg = ' half space cooling solution incorrect!!!!!';
TestResult.passed=false;
TestResult.fail_message = msg;
disp(msg)
end

end
17 changes: 10 additions & 7 deletions vbr/testing/test_fm_plates_003.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_003 ****')
disp(' (takes <1 minute)')
TestResult=true;
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TestResult.passed =true;
TestResult.fail_message = '';
% Load Default Settings
[settings]=init_settings;

Expand Down Expand Up @@ -56,7 +57,9 @@
% check if it passes
max_err_tol=1e-5;
if max_err_tol>max_err_tol
disp(' steady state plate solution incorrect!!!!!')
TestResult=false;
msg = ' steady state plate solution incorrect!!!!!'
disp(msg)
TestResult.passed=false;
TestResult.fail_message = msg;
end
end
16 changes: 9 additions & 7 deletions vbr/testing/test_fm_plates_004_solidus.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_004_solidus ****')

% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Note that the SoLiquidus function now lives in the vbrCore/functions/thermal_properties/
% directory.

TestResult=true;
% directory.

TestResult.passed =true;
TestResult.fail_message = '';

F = 0.05;
z = linspace(0,200,100)*1e3;
Expand Down
9 changes: 6 additions & 3 deletions vbr/testing/test_fm_plates_005_box.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_005_box ****')
TestResult=true;

TestResult.passed =true;
TestResult.fail_message = '';
% Parameter sweep settings
% define parameter sweep here. var1name must match EXACTLY a field in
% settings structure. var1 must be defined, var2 lines can be
Expand Down
29 changes: 19 additions & 10 deletions vbr/testing/test_fm_plates_006_thermoprops.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_006_thermoprops ****')
TestResult=true;

TestResult.passed =true;
TestResult.fail_message = '';

z=transpose(linspace(0,400,100)*1e3);
P0=1e5;
Expand All @@ -25,7 +28,7 @@
T=1400*z/z_L;
T(z>z_L)=(z(z>z_L)-z_L) * dTdz_ad + max(T(z<=z_L));
T=T+273;
PropTypes= {'con';'P_dep';'T_dep';'PT_dep'};
PropTypes= {'con';'P_dep';'T_dep';'PT_dep'};
P1=zeros(numel(z),4);
P2=zeros(numel(z),4);

Expand All @@ -37,14 +40,20 @@
% [Rho,Cp,Kc,P]
diff=sum(abs(P1(:)-P2(:))./P1(:));
if diff > 0
TestResult=false;
disp(' ThermodynamicProps not matching MaterialProperties')
TestResult.passed=false;
msg = ' ThermodynamicProps not matching MaterialProperties';
TestResult.fail_message = msg;
disp(msg)
elseif sum(isnan(P1))>0
TestResult=false;
disp(' ThermodynamicProps solution contains nans')
TestResult.passed=false;
msg = ' ThermodynamicProps solution contains nans';
disp(msg)
TestResult.fail_message = msg;
elseif sum(isnan(P2))>0
TestResult=false;
disp(' MaterialProperties solution contains nans')
TestResult.passed=false;
msg = ' MaterialProperties solution contains nans';
disp(msg)
TestResult.fail_message = msg;
end
end

Expand Down
Loading

0 comments on commit 04bf464

Please sign in to comment.