Skip to content

Commit df9dbba

Browse files
committed
Reuse spectroscopy state helper primitives
1 parent fe0ef82 commit df9dbba

3 files changed

Lines changed: 25 additions & 40 deletions

File tree

src/forward_model/optical_properties/state_build/carrier_eval.zig

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,6 @@ fn continuumSigmaAtWavelength(
505505
return continuum_table.interpolateSigma(wavelength_nm);
506506
}
507507

508-
fn strongLineStateAt(
509-
states: ?[]const ReferenceData.StrongLinePreparedState,
510-
local_index: usize,
511-
) ?*const ReferenceData.StrongLinePreparedState {
512-
const owned_states = states orelse return null;
513-
if (local_index >= owned_states.len) return null;
514-
return &owned_states[local_index];
515-
}
516-
517508
fn particleWavelengthScale(
518509
reference_wavelength_nm: f64,
519510
angstrom_exponent: f64,
@@ -619,7 +610,7 @@ pub fn sharedBoundaryCarrierAtLevelWithSpectroscopyCache(
619610
const boundary_row_index: usize = @intCast(level_geometry.support_row_index);
620611
if (boundary_row_index >= sublayers.len) return .{};
621612

622-
const strong_line_state = strongLineStateAt(strong_line_states, boundary_row_index);
613+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, boundary_row_index);
623614
const gas_carrier = sharedOpticalCarrierAtSupportRowWithSpectroscopyCache(
624615
self,
625616
wavelength_nm,
@@ -690,7 +681,7 @@ pub fn sharedBoundaryCarrierAtLevelWithCarrierCache(
690681
const boundary_row_index: usize = @intCast(level_geometry.support_row_index);
691682
if (boundary_row_index >= sublayers.len) return .{};
692683

693-
const strong_line_state = strongLineStateAt(strong_line_states, boundary_row_index);
684+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, boundary_row_index);
694685
var fallback_gas_carrier: SharedOpticalScalars = undefined;
695686
const gas_carrier = wavelength_cache.cachedSupportRowScalarsRef(
696687
self,
@@ -765,7 +756,7 @@ pub fn fillSourceInterfaceAtLevelWithSpectroscopyCache(
765756
return;
766757
}
767758

768-
const strong_line_state = strongLineStateAt(strong_line_states, boundary_row_index);
759+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, boundary_row_index);
769760
const gas_carrier = sharedOpticalCarrierAtSupportRowWithSpectroscopyCache(
770761
self,
771762
wavelength_nm,
@@ -830,7 +821,7 @@ pub fn fillSourceInterfaceAtLevelWithCarrierCache(
830821
source_interface.* = .{ .rtm_weight = rtm_weight };
831822
return;
832823
}
833-
const strong_line_state = strongLineStateAt(strong_line_states, boundary_row_index);
824+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, boundary_row_index);
834825
var fallback_gas_carrier: SharedOpticalScalars = undefined;
835826
const gas_carrier = wavelength_cache.cachedSupportRowScalarsRef(
836827
self,
@@ -935,7 +926,7 @@ pub fn fillRtmQuadratureLevelAtLevelWithSpectroscopyCache(
935926
return;
936927
}
937928

938-
const strong_line_state = strongLineStateAt(strong_line_states, boundary_row_index);
929+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, boundary_row_index);
939930
const gas_carrier = sharedOpticalCarrierAtSupportRowWithSpectroscopyCache(
940931
self,
941932
wavelength_nm,
@@ -996,7 +987,7 @@ pub fn fillRtmQuadratureLevelAtLevelWithCarrierCache(
996987
fillZeroRtmQuadratureLevel(level_geometry, rtm_level, compute_jacobian);
997988
return;
998989
}
999-
const strong_line_state = strongLineStateAt(strong_line_states, boundary_row_index);
990+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, boundary_row_index);
1000991
var fallback_gas_carrier: SharedOpticalScalars = undefined;
1001992
const gas_carrier = wavelength_cache.cachedSupportRowScalarsRef(
1002993
self,
@@ -1104,7 +1095,7 @@ pub fn sharedActiveCarrierAtLevelWithSpectroscopyCache(
11041095
const boundary_row_index: usize = @intCast(level_geometry.support_row_index);
11051096
if (boundary_row_index >= sublayers.len) return .{};
11061097

1107-
const strong_line_state = strongLineStateAt(strong_line_states, boundary_row_index);
1098+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, boundary_row_index);
11081099
const gas_carrier = sharedOpticalCarrierAtSupportRowWithSpectroscopyCache(
11091100
self,
11101101
wavelength_nm,
@@ -1386,7 +1377,10 @@ fn weightedSpectroscopyEvaluationAtSupportRow(
13861377
const weight = line_absorber.number_densities_cm3[global_sublayer_index];
13871378
if (weight <= 0.0) continue;
13881379

1389-
const prepared_state = strongLineStateAt(line_absorber.strong_line_states, global_sublayer_index);
1380+
const prepared_state = SpectroscopyState.strongLineStateAt(
1381+
line_absorber.strong_line_states,
1382+
global_sublayer_index,
1383+
);
13901384
const evaluation = line_absorber.line_list.evaluateAtPrepared(
13911385
wavelength_nm,
13921386
sublayer.temperature_k,

src/forward_model/optical_properties/state_build/shared_carrier.zig

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ pub const SharedRtmSubgrid = struct {
6767
weights_km: []const f64 = &.{},
6868
};
6969

70-
fn strongLineStateAt(
71-
states: ?[]const ReferenceData.StrongLinePreparedState,
72-
local_index: usize,
73-
) ?*const ReferenceData.StrongLinePreparedState {
74-
const owned_states = states orelse return null;
75-
if (local_index >= owned_states.len) return null;
76-
return &owned_states[local_index];
77-
}
78-
7970
pub fn sharedRtmSubgridSampleCount(scene: *const Scene) usize {
8071
return @max(@as(usize, scene.atmosphere.sublayer_divisions), 1);
8172
}
@@ -267,7 +258,7 @@ pub fn fillReducedLayerInputFromSupportRowsWithSpectroscopyCache(
267258
const weight_km = @max(support_sublayer.path_length_cm / 1.0e5, 0.0);
268259
if (weight_km <= 0.0) continue;
269260

270-
const strong_line_state = strongLineStateAt(strong_line_states, local_index);
261+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, local_index);
271262
const carrier = carrier_eval.sharedOpticalCarrierAtSupportRowWithSpectroscopyCache(
272263
self,
273264
wavelength_nm,
@@ -324,7 +315,7 @@ pub fn evaluateReducedLayerFromSupportRowsWithCarrierCache(
324315
const weight_km = @max(support_sublayer.path_length_cm / 1.0e5, 0.0);
325316
if (weight_km <= 0.0) continue;
326317

327-
const strong_line_state = strongLineStateAt(strong_line_states, local_index);
318+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, local_index);
328319
var fallback_scalars: carrier_eval.SharedOpticalScalars = undefined;
329320
const scalars = wavelength_cache.cachedSupportRowScalarsRef(
330321
self,
@@ -367,7 +358,7 @@ pub fn fillReducedLayerInputFromSupportRowsWithCarrierCache(
367358
const weight_km = @max(support_sublayer.path_length_cm / 1.0e5, 0.0);
368359
if (weight_km <= 0.0) continue;
369360

370-
const strong_line_state = strongLineStateAt(strong_line_states, local_index);
361+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, local_index);
371362
var fallback_scalars: carrier_eval.SharedOpticalScalars = undefined;
372363
const scalars = wavelength_cache.cachedSupportRowScalarsRef(
373364
self,
@@ -421,7 +412,7 @@ pub fn fillSharedPseudoSphericalSamplesFromSupportRows(
421412

422413
for (support_sublayers[1 .. support_sublayers.len - 1], 1..) |support_sublayer, local_index| {
423414
const weight_km = @max(support_sublayer.path_length_cm / 1.0e5, 0.0);
424-
const strong_line_state = strongLineStateAt(strong_line_states, local_index);
415+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, local_index);
425416
const optical_depth = choose_optical_depth: {
426417
if (weight_km <= 0.0) break :choose_optical_depth 0.0;
427418

@@ -468,7 +459,7 @@ pub fn fillSharedPseudoSphericalSamplesFromSupportRowsWithCarrierCache(
468459

469460
for (support_sublayers[1 .. support_sublayers.len - 1], 1..) |support_sublayer, local_index| {
470461
const weight_km = @max(support_sublayer.path_length_cm / 1.0e5, 0.0);
471-
const strong_line_state = strongLineStateAt(strong_line_states, local_index);
462+
const strong_line_state = SpectroscopyState.strongLineStateAt(strong_line_states, local_index);
472463
const optical_depth = choose_optical_depth: {
473464
if (weight_km <= 0.0) break :choose_optical_depth 0.0;
474465

src/forward_model/optical_properties/state_build/state_spectroscopy.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ const StrongLineAnchorBuffer = [ReferenceData.max_strong_line_sidecars]Reference
4545
// those slices, writes caller-owned ProfileNodeSpectroscopyCache rows, and returns scalar evaluations. |
4646
// ------------------------------------------------------------------------------------------------------------|
4747

48-
pub inline fn zeroSpectroscopyEvaluation() ReferenceData.SpectroscopyEvaluation {
49-
return .{
50-
.weak_line_sigma_cm2_per_molecule = 0.0,
51-
.strong_line_sigma_cm2_per_molecule = 0.0,
52-
.line_sigma_cm2_per_molecule = 0.0,
53-
.line_mixing_sigma_cm2_per_molecule = 0.0,
54-
.total_sigma_cm2_per_molecule = 0.0,
55-
.d_sigma_d_temperature_cm2_per_molecule_per_k = 0.0,
56-
};
48+
pub const zeroSpectroscopyEvaluation = SpectroscopySupport.zeroEvaluation;
49+
50+
pub inline fn strongLineStateAt(
51+
states: ?[]const ReferenceData.StrongLinePreparedState,
52+
local_index: usize,
53+
) ?*const ReferenceData.StrongLinePreparedState {
54+
const owned_states = states orelse return null;
55+
if (local_index >= owned_states.len) return null;
56+
return &owned_states[local_index];
5757
}
5858

5959
pub inline fn addWeightedSpectroscopyEvaluation(

0 commit comments

Comments
 (0)