Skip to content

Commit 0f754f4

Browse files
committed
Unifies the indices used by python and cpp to be same with matlab
1 parent 4c7f159 commit 0f754f4

6 files changed

Lines changed: 17 additions & 13 deletions

File tree

.github/workflows/runTests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
build_and_test_mex:
3737
strategy:
3838
matrix:
39-
platform: [windows-latest, ubuntu-latest, macos-15-intel, macos-latest]
39+
platform: [windows-latest, ubuntu-22.04, macos-15-intel, macos-latest]
4040
runs-on: ${{ matrix.platform }}
4141
needs: [build_cpp]
4242

examples/miscellaneous/alternativeLanguages/customBilayer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ extern "C" {
1313

1414
LIB_EXPORT void customBilayer(std::vector<double>& params, std::vector<double>& bulkIn, std::vector<double>& bulkOut, int contrast, std::vector<double>& output, double* outputSize, double* rough)
1515
{
16+
# Note - The first contrast number is 1 (not 0) so be careful if you use
17+
# this variable for array indexing.
1618
double subRough = params[0];
1719
double oxideThick = params[1];
1820
double oxideHydration = params[2];
@@ -65,9 +67,9 @@ extern "C" {
6567

6668
// Manually deal with hydration for layers in
6769
// this example.
68-
double oxSLD = (oxideHydration * bulkOut[contrast]) + ((1 - oxideHydration) * oxideSLD);
69-
double headSLD = (headHydration * bulkOut[contrast]) + ((1 - headHydration) * SLDhead);
70-
double tailSLD = (bilayerHydration * bulkOut[contrast]) + ((1 - bilayerHydration) * SLDtail);
70+
double oxSLD = (oxideHydration * bulkOut[contrast-1]) + ((1 - oxideHydration) * oxideSLD);
71+
double headSLD = (headHydration * bulkOut[contrast-1]) + ((1 - headHydration) * SLDhead);
72+
double tailSLD = (bilayerHydration * bulkOut[contrast-1]) + ((1 - bilayerHydration) * SLDtail);
7173

7274
// Make the layers
7375
// oxide...
@@ -77,7 +79,7 @@ extern "C" {
7779

7880
// Water...
7981
output.push_back(waterThick);
80-
output.push_back(bulkOut[contrast]);
82+
output.push_back(bulkOut[contrast-1]);
8183
output.push_back(bilayerRough);
8284

8385
// Heads...

examples/miscellaneous/alternativeLanguages/customBilayer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import numpy as np
33

44
def customBilayer(params, bulk_in, bulk_out, contrast):
5+
# Note - The first contrast number is 1 (not 0) so be careful if you use
6+
# this variable for array indexing.
57
params = params
68
bulk_in = bulk_in
79
bulk_out = bulk_out
@@ -58,13 +60,13 @@ def customBilayer(params, bulk_in, bulk_out, contrast):
5860

5961
# Manually deal with hydration for layers in
6062
# this example.
61-
oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
62-
headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
63-
tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
63+
oxSLD = (oxide_hydration * bulk_out[contrast-1]) + ((1 - oxide_hydration) * oxide_SLD)
64+
headSLD = (headHydration * bulk_out[contrast-1]) + ((1 - headHydration) * SLDhead)
65+
tailSLD = (bilayerHydration * bulk_out[contrast-1]) + ((1 - bilayerHydration) * SLDtail)
6466

6567
# Make the layers
6668
oxide = [oxide_thick, oxSLD, sub_rough]
67-
water = [waterThick, bulk_out[contrast], bilayerRough]
69+
water = [waterThick, bulk_out[contrast-1], bilayerRough]
6870
head = [headThick, headSLD, bilayerRough]
6971
tail = [tailThick, tailSLD, bilayerRough]
7072

targetFunctions/+domainsTF/processCustomFunction.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
[output1, subRoughs(i)] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 1);
2222
[output2, ~] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 2);
2323
else
24-
[output1, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, 0);
25-
[output2, ~] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, 1);
24+
[output1, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 1);
25+
[output2, ~] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 2);
2626
end
2727

2828
% If SLD is real, add dummy imaginary column

targetFunctions/+normalTF/processCustomFunction.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
if isnan(str2double(functionHandle))
1717
[output, subRoughs(i)] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 0);
1818
else
19-
[output, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, -1);
19+
[output, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 0);
2020
end
2121

2222
% If SLD is real, add dummy imaginary column

targetFunctions/common/customModelFunctions/callCppFunction.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
bulkOutArray = coder.ceval('convertPtr2Vector', coder.ref(bulkOut), numel(bulkOut));
5252

5353
% domain should either before 0 or 1. A value less than zero indicates no domains
54-
if (domains < 0)
54+
if (domains < 1)
5555
coder.ceval(['std::mem_fn<void(std::vector<double>&, std::vector<double>&, std::vector<double>&, int, ' ...
5656
'std::vector<double>&, double*, double*)>(&CallbackInterface::invoke)'], ...
5757
callback, paramsArray, bulkInArray, bulkOutArray, contrast, outArray, ...

0 commit comments

Comments
 (0)