Search in sources :

Example 1 with CompositeState

use of artisynth.core.modelbase.CompositeState in project artisynth_core by artisynth.

the class RootModel method getInitialState.

public void getInitialState(ComponentState newstate, ComponentState oldstate) {
    if (!(newstate instanceof CompositeState)) {
        throw new IllegalArgumentException("newstate is not a CompositeState");
    }
    CompositeState saveState = (CompositeState) newstate;
    CompositeState substate;
    HashMap<ModelInfo, CompositeState> stateMap = new HashMap<ModelInfo, CompositeState>();
    if (oldstate != null) {
        if (!(oldstate instanceof CompositeState)) {
            throw new IllegalArgumentException("oldstate is not a CompositeState");
        }
        CompositeState ostate = (CompositeState) oldstate;
        if (ostate.numComponents() != ostate.numSubStates()) {
            throw new IllegalArgumentException("oldstate has " + ostate.numComponents() + " components vs. " + ostate.numSubStates() + " substates");
        }
        ArrayList<Object> comps = ostate.getComponents();
        if (comps != null) {
            for (int k = 0; k < comps.size(); k++) {
                stateMap.put((ModelInfo) comps.get(k), (CompositeState) ostate.getState(k));
            }
        }
    }
    saveState.clear();
    for (ModelInfo info : myModelInfo.values()) {
        substate = new CompositeState();
        info.getInitialState(substate, stateMap.get(info));
        saveState.addState(substate);
        saveState.addComponent(info);
    }
    substate = new CompositeState();
    myRootInfo.getInitialState(substate, stateMap.get(myRootInfo));
    saveState.addState(substate);
    saveState.addComponent(myRootInfo);
}
Also used : CompositeState(artisynth.core.modelbase.CompositeState) Point(java.awt.Point) WayPoint(artisynth.core.probes.WayPoint)

Example 2 with CompositeState

use of artisynth.core.modelbase.CompositeState in project artisynth_core by artisynth.

the class RootModel method createState.

/**
 * {@inheritDoc}
 */
public ComponentState createState(ComponentState prevState) {
    // state is a composite state for every model plus a numeric state
    // for the root model itself
    int numMods = myModelInfo.size();
    CompositeState state = new CompositeState(numMods + 1);
    for (ModelInfo info : myModelInfo.values()) {
        state.addState(info.createFullState());
    }
    state.addState(myRootInfo.createFullState());
    return state;
}
Also used : CompositeState(artisynth.core.modelbase.CompositeState) Point(java.awt.Point) WayPoint(artisynth.core.probes.WayPoint)

Example 3 with CompositeState

use of artisynth.core.modelbase.CompositeState in project artisynth_core by artisynth.

the class RootModel method advanceModel.

protected void advanceModel(ModelInfo info, double t0, double t1, int flags) {
    double ta = t0;
    if (t0 == 0) {
        applyOutputProbes(info.outputProbes, t0, info);
    }
    while (ta < t1) {
        double s;
        synchronized (this) {
            info.getModelAndControllersState(info.state);
        }
        if (testSaveAndRestoreState) {
            // test save-and-restore of model state
            CompositeState fullState = info.createFullState();
            CompositeState testState = info.createFullState();
            info.getFullState(fullState);
            info.setFullState(fullState);
            info.getFullState(testState);
            if (!testState.equals(fullState)) {
                throw new InternalErrorException("Error: save/restore state test failed");
            }
        }
        double tb = info.getNextAdvanceTime(ta, t1);
        do {
            synchronized (this) {
                StepAdjustment adj;
                // info.model.setDefaultInputs (ta, tb);
                adj = info.model.preadvance(ta, tb, flags);
                s = getRecommendedScaling(adj);
                if (s >= 1) {
                    applyInputProbes(info.inputProbes, tb);
                    applyControllers(info.controllers, ta, tb);
                    adj = info.model.advance(ta, tb, flags);
                    s = getRecommendedScaling(adj);
                }
                if (myAdaptiveStepping && s < 1) {
                    tb = info.reduceAdvanceTime(s, ta, tb, adj.getMessage());
                    info.setModelAndControllersState(info.state);
                    info.model.initialize(ta);
                }
            }
        } while (myAdaptiveStepping && s < 1 && !myStopAdvance);
        if (!(myAdaptiveStepping && s < 1)) {
            // then we have advanced to tb:
            info.updateStepInfo(s);
            applyMonitors(info.monitors, ta, tb);
            applyOutputProbes(info.outputProbes, tb, info);
            ta = tb;
        }
    }
}
Also used : CompositeState(artisynth.core.modelbase.CompositeState) InternalErrorException(maspack.util.InternalErrorException) StepAdjustment(artisynth.core.modelbase.StepAdjustment)

Example 4 with CompositeState

use of artisynth.core.modelbase.CompositeState in project artisynth_core by artisynth.

the class RootModel method getState.

/**
 * {@inheritDoc}
 */
public void getState(ComponentState state) {
    if (!(state instanceof CompositeState)) {
        throw new IllegalArgumentException("state is not a CompositeState");
    }
    CompositeState substate;
    CompositeState saveState = (CompositeState) state;
    saveState.clear();
    for (ModelInfo info : myModelInfo.values()) {
        substate = new CompositeState();
        info.getFullState(substate);
        saveState.addState(substate);
    }
    substate = new CompositeState();
    myRootInfo.getFullState(substate);
    saveState.addState(substate);
}
Also used : CompositeState(artisynth.core.modelbase.CompositeState)

Example 5 with CompositeState

use of artisynth.core.modelbase.CompositeState in project artisynth_core by artisynth.

the class RootModel method setState.

/**
 * {@inheritDoc}
 */
public void setState(ComponentState state) {
    if (!(state instanceof CompositeState)) {
        throw new IllegalArgumentException("state is not a CompositeState");
    }
    CompositeState newState = (CompositeState) state;
    if (newState.numSubStates() != myModels.size() + 1) {
        throw new IllegalArgumentException("new state has " + newState.numSubStates() + " sub-states vs. " + myModels.size() + 1);
    }
    int k = 0;
    for (ModelInfo info : myModelInfo.values()) {
        info.setFullState((CompositeState) newState.getState(k++));
    }
    myRootInfo.setFullState((CompositeState) newState.getState(k++));
}
Also used : CompositeState(artisynth.core.modelbase.CompositeState) Point(java.awt.Point) WayPoint(artisynth.core.probes.WayPoint)

Aggregations

CompositeState (artisynth.core.modelbase.CompositeState)5 WayPoint (artisynth.core.probes.WayPoint)3 Point (java.awt.Point)3 StepAdjustment (artisynth.core.modelbase.StepAdjustment)1 InternalErrorException (maspack.util.InternalErrorException)1