43 const double* arg[SZ_ARG];
54 for (i = 0; i < N_X; ++i) m->
x[i] = m->
v[x_vr[i]];
55 for (i = 0; i < N_P; ++i) m->
p[i] = m->
v[p_vr[i]];
56 for (i = 0; i < N_U; ++i) m->
u[i] = m->
v[u_vr[i]];
71 mem = MODELNAME_checkout();
72 flag = MODELNAME(m->
arg, m->
res, m->
iw, m->
w, mem);
73 MODELNAME_release(mem);
76 for (i = 0; i < N_X; ++i) m->
v[xdot_vr[i]] = m->
xdot[i];
77 for (i = 0; i < N_Y; ++i) m->
v[y_vr[i]] = m->
y[i];
87 for (i = 0; i < N_X; ++i) m->
dx[i] = m->
d[x_vr[i]];
88 for (i = 0; i < N_P; ++i) m->
dp[i] = m->
d[p_vr[i]];
89 for (i = 0; i < N_U; ++i) m->
du[i] = m->
d[u_vr[i]];
114 mem = fwd1_MODELNAME_checkout();
115 flag = fwd1_MODELNAME(m->
arg, m->
res, m->
iw, m->
w, mem);
116 fwd1_MODELNAME_release(mem);
119 for (i = 0; i < N_X; ++i) m->
d[xdot_vr[i]] = m->
dxdot[i];
120 for (i = 0; i < N_Y; ++i) m->
d[y_vr[i]] = m->
dy[i];
131 for (i = 0; i < N_X; ++i) m->
dxdot[i] = m->
d[xdot_vr[i]];
132 for (i = 0; i < N_Y; ++i) m->
dy[i] = m->
d[y_vr[i]];
135 for (i = 0; i < N_X; ++i) m->
dx[i] = 0;
136 for (i = 0; i < N_P; ++i) m->
dp[i] = 0;
137 for (i = 0; i < N_U; ++i) m->
du[i] = 0;
162 mem = adj1_MODELNAME_checkout();
163 flag = adj1_MODELNAME(m->
arg, m->
res, m->
iw, m->
w, mem);
164 adj1_MODELNAME_release(mem);
167 for (i = 0; i < N_X; ++i) m->
d[x_vr[i]] = m->
dx[i];
168 for (i = 0; i < N_P; ++i) m->
d[p_vr[i]] = m->
dp[i];
169 for (i = 0; i < N_U; ++i) m->
d[u_vr[i]] = m->
du[i];
175 FMI3_Export fmi3Status fmi3Reset(fmi3Instance instance) {
182 for (i = 0; i < SZ_MEM; ++i) m->
v[i] = start[i];
184 for (i = 0; i < SZ_MEM; ++i) m->
d[i] = 0;
191 FMI3_Export fmi3Instance fmi3InstantiateModelExchange(
192 fmi3String instanceName,
193 fmi3String instantiationToken,
194 fmi3String resourcePath,
196 fmi3Boolean loggingOn,
197 fmi3InstanceEnvironment instanceEnvironment,
198 fmi3LogMessageCallback logMessage) {
205 (void)instanceEnvironment;
222 FMI3_Export
void fmi3FreeInstance(fmi3Instance instance) {
231 FMI3_Export fmi3Status fmi3SetFloat64(
232 fmi3Instance instance,
233 const fmi3ValueReference valueReferences[],
234 size_t nValueReferences,
235 const fmi3Float64 values[],
239 size_t i, j, var_off, var_sz, val_ind;
240 fmi3ValueReference vr;
248 for (i = 0; i < nValueReferences; ++i) {
250 vr = valueReferences[i];
252 var_off = var_offset[vr];
253 var_sz = var_offset[vr + 1] - var_off;
255 for (j = 0; j < var_sz; ++j) m->
v[var_off + j] = values[val_ind++];
258 if (val_ind != nValues)
return fmi3Fatal;
263 FMI3_Export fmi3Status fmi3GetFloat64(
264 fmi3Instance instance,
265 const fmi3ValueReference valueReferences[],
266 size_t nValueReferences,
267 fmi3Float64 values[],
271 size_t i, j, var_off, var_sz, val_ind;
272 fmi3ValueReference vr;
278 if (evaluate(m))
return fmi3Error;
285 for (i = 0; i < nValueReferences; ++i) {
287 vr = valueReferences[i];
289 var_off = var_offset[vr];
290 var_sz = var_offset[vr + 1] - var_off;
292 for (j = 0; j < var_sz; ++j) values[val_ind++] = m->
v[var_off + j];
295 if (val_ind != nValues)
return fmi3Fatal;
300 FMI3_Export fmi3Status fmi3EnterInitializationMode(
301 fmi3Instance instance,
302 fmi3Boolean toleranceDefined,
303 fmi3Float64 tolerance,
304 fmi3Float64 startTime,
305 fmi3Boolean stopTimeDefined,
306 fmi3Float64 stopTime) {
310 (void)toleranceDefined;
312 (void)stopTimeDefined;
322 FMI3_Export fmi3Status fmi3ExitInitializationMode(fmi3Instance instance) {
329 FMI3_Export fmi3Status fmi3EnterContinuousTimeMode(fmi3Instance instance) {
336 FMI3_Export fmi3Status fmi3SetTime(fmi3Instance instance, fmi3Float64 time) {
347 FMI3_Export fmi3Status fmi3SetContinuousStates(
348 fmi3Instance instance,
349 const fmi3Float64 continuousStates[],
350 size_t nContinuousStates) {
351 return fmi3SetFloat64(instance, x_vr, N_X, continuousStates, nContinuousStates);
354 FMI3_Export fmi3Status fmi3GetContinuousStates(
355 fmi3Instance instance,
356 fmi3Float64 continuousStates[],
357 size_t nContinuousStates) {
358 return fmi3GetFloat64(instance, x_vr, N_X, continuousStates, nContinuousStates);
361 fmi3Status fmi3GetDirectionalDerivative(
362 fmi3Instance instance,
363 const fmi3ValueReference unknowns[],
365 const fmi3ValueReference knowns[],
367 const fmi3Float64 seed[],
369 fmi3Float64 sensitivity[],
370 size_t nSensitivity) {
373 size_t i, j, var_off, var_sz, val_ind;
374 fmi3ValueReference vr;
381 if (evaluate(m))
return fmi3Error;
387 for (i = 0; i < nKnowns; ++i) {
391 var_off = var_offset[vr];
392 var_sz = var_offset[vr + 1] - var_off;
394 for (j = 0; j < var_sz; ++j) m->
d[var_off + j] = seed[val_ind++];
397 if (val_ind != nSeed)
return fmi3Fatal;
399 flag = evaluate_forward(m);
402 for (i = 0; i < nUnknowns; ++i) {
406 var_off = var_offset[vr];
407 var_sz = var_offset[vr + 1] - var_off;
409 for (j = 0; j < var_sz; ++j) {
410 sensitivity[val_ind++] = m->
d[var_off + j];
411 m->
d[var_off + j] = 0;
415 if (val_ind != nSensitivity)
return fmi3Fatal;
418 for (i = 0; i < nKnowns; ++i) {
422 var_off = var_offset[vr];
423 var_sz = var_offset[vr + 1] - var_off;
425 for (j = 0; j < var_sz; ++j) m->
d[var_off + j] = 0;
428 if (flag)
return fmi3Error;
433 fmi3Status fmi3GetAdjointDerivative(
434 fmi3Instance instance,
435 const fmi3ValueReference unknowns[],
437 const fmi3ValueReference knowns[],
439 const fmi3Float64 seed[],
441 fmi3Float64 sensitivity[],
442 size_t nSensitivity) {
445 size_t i, j, var_off, var_sz, val_ind;
446 fmi3ValueReference vr;
453 if (evaluate(m))
return fmi3Error;
459 for (i = 0; i < nUnknowns; ++i) {
463 var_off = var_offset[vr];
464 var_sz = var_offset[vr + 1] - var_off;
466 for (j = 0; j < var_sz; ++j) m->
d[var_off + j] = seed[val_ind++];
469 if (val_ind != nSeed)
return fmi3Fatal;
471 flag = evaluate_adjoint(m);
474 for (i = 0; i < nKnowns; ++i) {
478 var_off = var_offset[vr];
479 var_sz = var_offset[vr + 1] - var_off;
481 for (j = 0; j < var_sz; ++j) {
482 sensitivity[val_ind++] = m->
d[var_off + j];
483 m->
d[var_off + j] = 0;
487 if (val_ind != nSensitivity)
return fmi3Fatal;
490 for (i = 0; i < nUnknowns; ++i) {
494 var_off = var_offset[vr];
495 var_sz = var_offset[vr + 1] - var_off;
497 for (j = 0; j < var_sz; ++j) m->
d[var_off + j] = 0;
500 if (flag)
return fmi3Error;
const char * instance_name
const double * arg[SZ_ARG]