-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibLinkFunctionsExported.cpp
executable file
·168 lines (108 loc) · 3.9 KB
/
LibLinkFunctionsExported.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//
// MathLibLink.cpp
// EXL_Model
//
// Created by Will Zhang on 7/22/15.
// Copyright (c) 2015 Will Zhang. All rights reserved.
//
#include <stdio.h>
#include <math.h>
#include "WolframLibrary.h"
#include "BetaDistribution.hpp"
#include "CollagenConstitutiveModels.hpp"
/* Return the version of Library Link */
EXTERN_C DLLEXPORT mint WolframLibrary_getVersion( ) {
return WolframLibraryVersion;
}
/* Initialize Library */
EXTERN_C DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData) {
return LIBRARY_NO_ERROR;
}
/* Uninitialize Library */
EXTERN_C DLLEXPORT void WolframLibrary_uninitialize( WolframLibraryData libData) {
return;
}
/* */
EXTERN_C DLLEXPORT int BetaODF( WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
double result;
//Start of Mathematica to C Communication
//get the inputs
mreal T1 = MArgument_getReal(Args[0]);
mreal T2 = MArgument_getReal(Args[1]);
mreal T3 = MArgument_getReal(Args[2]);
beta_ODF fiberODF(T1, T2);
result = fiberODF.ODF(T3);
MArgument_setReal(Res, result); //Set results to be the actually output
return LIBRARY_NO_ERROR;
}
/* */
EXTERN_C DLLEXPORT int BetaPDF( WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
//Start of Mathematica to C Communication
//get the inputs
mreal mu = MArgument_getReal(Args[0]);
mreal sd = MArgument_getReal(Args[1]);
mreal lb = MArgument_getReal(Args[2]);
mreal ub = MArgument_getReal(Args[3]);
mreal x = MArgument_getReal(Args[4]);
beta_PDF fiberPDF(mu, sd, lb, ub);
double result = fiberPDF.PDF(x);
MArgument_setReal(Res, result); //Set results to be the actually output
return LIBRARY_NO_ERROR;
}
EXTERN_C DLLEXPORT int ColExpModel( WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
//Start of Mathematica to C Communication
int err;
MTensor T0;
MTensor T1;
MTensor Tout;
mint dims[1];
double* vC;
double* vparm;
double* results;
dims[0] = 4;
T0 = MArgument_getMTensor(Args[0]);
T1 = MArgument_getMTensor(Args[1]);
vparm = libData->MTensor_getRealData(T0);
vC = libData->MTensor_getRealData(T1);
double kc = vparm[0];
double mu = vparm[1];
double sd = vparm[2];
double expB = vparm[3];
double lfmax = vparm[4];
err = libData->MTensor_new(MType_Real, 1, dims, &Tout);
results = libData->MTensor_getRealData(Tout);
col_tissue_PF_exp model(kc, mu, sd, expB, lfmax);
err = model.stress(vC, results); //Compute results
MArgument_setMTensor(Res, Tout); //Set results to be the actually output
return LIBRARY_NO_ERROR;
}
EXTERN_C DLLEXPORT int ColExpModelPsi( WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
//Start of Mathematica to C Communication
//Mathematica type for the inputs
MTensor T0;
MTensor T1;
//The inputs from mathematica
double* vC;
double* vparm;
//The type for the result
double results;
//Take input from mathematica
T0 = MArgument_getMTensor(Args[0]);
T1 = MArgument_getMTensor(Args[1]);
//Convert it to C types
vparm = libData->MTensor_getRealData(T0);
vC = libData->MTensor_getRealData(T1);
//Define the parameters from the input vector
double kc = vparm[0];
double mu = vparm[1];
double sd = vparm[2];
double expB = vparm[3];
double lfmax = vparm[4];
//Create the model object
col_tissue_PF_exp model(kc, mu, sd, expB, lfmax);
//Compute the strain energy and set it to the results
results = model.strainenergy(vC); //Compute results
//Send the results to mathematica
MArgument_setReal(Res, results); //Set results to be the actually output
return LIBRARY_NO_ERROR;
}