All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javafmi.skeleton.actions.SetRealInputDerivatives Maven / Gradle / Ivy

Go to download

javaFMI is a Java Library for the functional mock-up interface (or FMI). FMI defines a standardized interface to be used in computer simulations. The FMI Standard has beed developed by a large number of software companies and research centers that have worked in a cooperation project under the name of MODELISAR. This library addresses the connection of a java application with a FMU (functional mock-up unit).

The newest version!
/*
 *  Copyright 2013-2018 - Monentia
 *
 * Daccosim is a collaborative development effort between EDF (France),
 *  CentraleSupélec (France), EIFER Institute (Germany), SIANI institute (Spain)
 *  and Monentia S.L. (Spain)
 *
 *  This File is part of JavaFMI Project
 *
 *  JavaFMI Project is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License.
 *
 *  JavaFMI Project is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with JavaFMI. If not, see .
 */

package org.javafmi.skeleton.actions;

import org.javafmi.framework.FmiSimulation;
import org.javafmi.skeleton.Action;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.util.stream.IntStream.range;

public class SetRealInputDerivatives implements Action {
	@Override
	public String executeOn(FmiSimulation simulation, String... args) {
		int size = parseInt(args[0]);
		int[] valueReferences = toPrimitiveArray(range(1, size + 1).boxed().map(i -> parseInt(args[i])).toArray(Integer[]::new));
		int[] orders = toPrimitiveArray(range(size + 1, 2 * size + 1).boxed().map(i -> parseInt(args[i])).toArray(Integer[]::new));
		double[] values = toPrimitiveArray(range(2 * size + 1, 3 * size + 1).boxed().map(i -> parseDouble(args[i])).toArray(Double[]::new));
		return simulation.setRealInputDerivatives(valueReferences, orders, values).toString();
	}

	public int[] toPrimitiveArray(Integer[] array) {
		int[] result = new int[array.length];
		for (int i = 0; i < array.length; i++) result[i] = array[i];
		return result;
	}

	public double[] toPrimitiveArray(Double[] array) {
		double[] result = new double[array.length];
		for (int i = 0; i < array.length; i++) result[i] = array[i];
		return result;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy