优化点1,2.

This commit is contained in:
xinxiao
2026-04-01 18:58:03 +08:00
parent a166fe007e
commit 0b23161eee
15 changed files with 106 additions and 1315 deletions
-5
View File
@@ -12,7 +12,6 @@ config.meta = struct( ...
'version', '0.1');
config.model = struct( ...
'modelflag', 1, ...
'grid_model', 1, ...
'flow_model', 1);
@@ -39,13 +38,9 @@ config.grid = struct( ...
'cell_mid_coords', []);
config.fracture = struct( ...
'input_style', 1, ...
'input_content', {{}}, ...
'f', [], ...
'fellip', [], ...
'fractureLines', [], ...
'fractureHeights', [], ...
'flowBarrierFlags', [], ...
'frac_information', [], ...
'nf', 0);
+1 -1
View File
@@ -10,4 +10,4 @@ if ~exist(file_path, 'file')
end
json_text = fileread(file_path);
config = jsondecode(json_text);
config = normalize_config(jsondecode(json_text));
+1 -1
View File
@@ -15,4 +15,4 @@ if ~isfield(data, 'config')
'MAT file does not contain variable ''config'': %s', file_path);
end
config = data.config;
config = normalize_config(data.config);
+53
View File
@@ -0,0 +1,53 @@
function config = normalize_config(config)
%NORMALIZE_CONFIG Normalize legacy GUI/runtime config to the current schema.
if nargin == 0 || isempty(config)
config = create_empty_config();
return;
end
defaults = create_empty_config();
config = merge_struct_defaults(config, defaults);
config.model.grid_model = first_nonempty_scalar(config.model.grid_model, 1);
config.model.flow_model = first_nonempty_scalar(config.model.flow_model, 1);
legacy_model_fields = {'modelflag'};
legacy_fracture_fields = {'input_style', 'fractureLines', 'fractureHeights', 'flowBarrierFlags'};
for i = 1:numel(legacy_model_fields)
field_name = legacy_model_fields{i};
if isfield(config.model, field_name)
config.model = rmfield(config.model, field_name);
end
end
for i = 1:numel(legacy_fracture_fields)
field_name = legacy_fracture_fields{i};
if isfield(config.fracture, field_name)
config.fracture = rmfield(config.fracture, field_name);
end
end
end
function s = merge_struct_defaults(s, defaults)
default_fields = fieldnames(defaults);
for i = 1:numel(default_fields)
field_name = default_fields{i};
if ~isfield(s, field_name) || isempty(s.(field_name))
s.(field_name) = defaults.(field_name);
elseif isstruct(defaults.(field_name)) && isstruct(s.(field_name))
s.(field_name) = merge_struct_defaults(s.(field_name), defaults.(field_name));
end
end
end
function value = first_nonempty_scalar(raw_value, fallback)
if isempty(raw_value)
value = fallback;
elseif isscalar(raw_value)
value = raw_value;
else
value = raw_value(1);
end
end