Пример #1
0
void
MMO_Expression_::_traverseAlgebraics (Dependencies deps, Index derivativeIndex,
				      Dependencies derivativeDeps,
				      map<Index, Index> *states,
				      map<Index, Index> *discretes,
				      Index variableChange, DEP_Type type,
				      int value)
{
  for (Index *idx = deps->begin (type); !deps->end (type);
      idx = deps->next (type))
    {

      list<MMO_Equation> algEqs = _data->algebraics ()->equation (*idx);
      list<MMO_Equation>::iterator algEq;
      if (type == DEP_ALGEBRAIC_VECTOR_DEF)
	{
	  derivativeDeps->insert (*idx, DEP_ALGEBRAIC_VECTOR);
	}
      int algValue = -1;
      for (algEq = algEqs.begin (); algEq != algEqs.end (); algEq++)
	{
	  Index algebraicIdx = *idx;
	  if (value >= 0 && idx->hasRange ())
	    {
	      algebraicIdx = idx->indexValue (value);
	    }
	  if (!(*algEq)->exp()->deps()->autonomous())
	    {
	      _deps->setAutonomous(false);
	    }
	  Index variableCh;
	  int f = (*algEq)->lhs ().factor ();
	  int c = (*algEq)->lhs ().operConstant ();
	  if (f != 0 && type == DEP_ALGEBRAIC_DEF)
	    {
	      if (f != 1 || c != 0)
		{
		  variableCh.setFactor (f);
		  variableCh.setConstant (-c);
		  variableCh.setLow ((*algEq)->lhs ().low () * f + c);
		  variableCh.setHi ((*algEq)->lhs ().hi () * f + c);
		}
	    }
	  Index algebraicIndex = (*algEq)->lhs ();
	  if (variableChange.isSet ())
	    {
	      algebraicIndex = (*algEq)->lhs ().applyVariableChange (
		  variableChange);
	      algebraicIdx = idx->applyVariableChange (variableChange);
	      algebraicIdx.setLow (variableChange.low ());
	      algebraicIdx.setHi (variableChange.hi ());
	    }
	  Intersection is = algebraicIndex.intersection (algebraicIdx);
	  if (is.type () != IDX_DISJOINT)
	    {
	      Index algKey = algebraicIdx;
	      Index equationIndex;
	      equationIndex.setOffset (_equationIndex++);
	      if (is.hasRange ())
		{
		  equationIndex.setRange ();
		  equationIndex.setLow (is.low ());
		  equationIndex.setHi (is.hi ());
		  algKey.setRange ();
		  algKey.setHi (equationIndex.hi ());
		  algKey.setLow (equationIndex.low ());
		}
	      else
		{
		  equationIndex.setConstant (is.modelicaValue ());
		  if (is.type () == IDX_CONSTANT_BA)
		    {
		      algKey.setConstant (is.modelicaValue () + is.begin ());
		      algValue = is.modelicaValue ();
		    }
		  else if (is.type () == IDX_CONSTANT_AB)
		    {
		      algKey.setConstant (is.modelicaValue () + is.begin ());
		      algValue = is.modelicaValue ();
		    }
		  else
		    {
		      algKey.setConstant (is.modelicaValue ());
		    }
		  algKey.setLow (1);
		  algKey.setHi (1);
		  algKey.setFactor (0);
		}
	      if (type == DEP_ALGEBRAIC_DEF)
		{
		  derivativeDeps->insert (algKey, DEP_ALGEBRAIC);
		}
	      _addAlgebriacDeps (algKey, (*algEq), equationIndex,
				 derivativeIndex, derivativeDeps, states,
				 discretes, variableCh, algValue);
	    }
	}
    }
}