1 /*******************************************************************************
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * VTT Technical Research Centre of Finland - initial API and implementation
10 *******************************************************************************/
11 package org.simantics.simulation.test;
13 import java.util.Formatter;
14 import java.util.concurrent.Executor;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.accessor.error.AccessorException;
18 import org.simantics.simulation.data.Datasource;
19 import org.simantics.simulation.data.PseudoSolver;
20 import org.simantics.simulation.data.Datasource.DatasourceListener;
21 import org.simantics.simulation.data.VariableHandle;
23 public class TestPseudoSolver {
25 public static void main(String[] args) throws InterruptedException {
27 PseudoSolver solver = new PseudoSolver();
28 solver.addListener( new DatasourceListener() {
30 public void onStep(Datasource source) {
31 StringBuilder sb = new StringBuilder();
32 Formatter f = new Formatter(sb);
34 VariableHandle sineHandle = source.openHandle(null, PseudoSolver.SINE, Bindings.DOUBLE);
35 VariableHandle rampHandle = source.openHandle(null, PseudoSolver.RAMP, Bindings.DOUBLE);
37 double time = (Double) source.getTime(Bindings.DOUBLE);
39 double sine = (Double) sineHandle.getValue();
40 double ramp = (Double) rampHandle.getValue();
41 f.format("%3f: sine=%,5f, ramp=%,5f\n", time, sine, ramp);
43 } catch (AccessorException e) {
49 public Executor getExecutor() {
55 Thread.sleep(10*1000L);