Inheritance: IReaction
Exemple #1
0
    //! Load the diffusion reactions from an array of files and a Medium list

    /*!
     *  \param files Array of files which contain information about diffusion reaction.
     *  \param mediums The list of all the mediums.
     *
     *  This function loads the diffusion reactions based on Fick model. It takes an Array of file paths
     *  and a list of Medium that should contain all the mediums of the simulation.
     *  This function creates the list of all the reactions between all Medium which exist and initialize their parameters to 0.
     *  Only the reactions explicitly defined in files are initialized to the values explicited in files.
     *  If a parameter of a fick reaction is not specified in files then this parameter will be equal to 0.
     */
    public void loadFicksReactionsFromFiles(string[] files, LinkedList <Medium> mediums)
    {
        Logger.Log("Fick::loadFicksReactionsFromFiles("
                   + Logger.EnumerableToString <string> (files)
                   + ") starts"
                   , Logger.Level.INFO);
        LinkedList <FickProperties> propsList = new LinkedList <FickProperties> ();
        LinkedList <FickProperties> newPropList;

        foreach (string file in files)
        {
            newPropList = loadObjectsFromFile <FickProperties> (file, "ficks");
            if (newPropList != null)
            {
                LinkedListExtensions.AppendRange <FickProperties> (propsList, newPropList);
            }
        }
        _reactions = FickReaction.getFickReactionsFromMediumList(mediums);
        finalizeFickReactionFromProps(propsList, _reactions);

        Logger.Log("Fick::loadFicksReactionsFromFiles("
                   + Logger.EnumerableToString <string> (files)
                   + ") starts"
                   , Logger.Level.INFO);
    }
Exemple #2
0
 public FickReaction(FickReaction r) : base(r)
 {
     _surface = r._surface;
     _P       = r._P;
     _medium1 = r._medium1;
     _medium2 = r._medium2;
 }
Exemple #3
0
 public FickReaction(FickReaction r) : base(r)
 {
   _surface = r._surface;
   _P = r._P;
   _medium1 = r._medium1;
   _medium2 = r._medium2;
 }
    void OnTriggerEnter(Collider collider)
    {
        Logger.Log("PhenoFickContact::OnTriggerEnter collider=" + collider, Logger.Level.DEBUG);
        PhysicalMedium PMext = collider.gameObject.GetComponent <PhysicalMedium>();

        if (PMext == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerEnter collider.PMext == null", Logger.Level.TRACE);
            return;
        }
        int    colliderMediumIdExt = PMext.MediumId;
        Medium colliderMediumExt   = ReactionEngine.getMediumFromId(colliderMediumIdExt, _reactionEngine.getMediumList());

        if (colliderMediumExt == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerEnter The collided medium does not exist in the reaction Engine. Load it or change the MediumId number in the PhysicalMedium script.", Logger.Level.WARN);
            return;
        }

        PhysicalMedium PM = GetComponent <PhysicalMedium>();

        if (PMext == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerEnter this.PMext == null", Logger.Level.TRACE);
            return;
        }
        int    mediumId = PM.MediumId;
        Medium medium   = ReactionEngine.getMediumFromId(mediumId, _reactionEngine.getMediumList());

        if (medium == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerEnter The medium does not exist in the reaction Engine. Load it or change the MediumId number in the PhysicalMedium script.", Logger.Level.WARN);
            return;
        }

        float        surface  = Math.Min(PM.Size, PMext.Size);
        Fick         fick     = _reactionEngine.getFick();
        FickReaction reaction = Fick.getFickReactionFromIds(colliderMediumIdExt, mediumId, fick.getFickReactions());

        if (reaction == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerEnter This FickReaction does not exist.", Logger.Level.WARN);
            return;
        }
        reaction.setSurface(surface);

        // set medium as medium of collider
        Logger.Log("colliderMediumIdExt : " + colliderMediumIdExt, Logger.Level.INFO);
        configureExternalDisplays(colliderMediumIdExt);
        _collidedMediumIds.AddLast(colliderMediumIdExt);

        /*
         * Logger.Log("PhenoFickContact::OnTriggerEnter"
         +" reaction.setSurface("+surface+")"
         +" _collidedMediumIds.Count="+_collidedMediumIds.Count
         +" _collidedMediumIds.Last.Value="+_collidedMediumIds.Last.Value
         * ,Logger.Level.);
         */
    }
Exemple #5
0
    /* !
     * \brief Checks that two reactions have the same FickReaction field values.
     * \param reaction The reaction that will be compared to 'this'.
     */
    protected override bool PartialEquals(IReaction reaction)
    {
        FickReaction fick = reaction as FickReaction;

        return((fick != null) &&
               base.PartialEquals(reaction) &&
               (_surface == fick._surface) &&
               (_P == fick._P) &&
               _medium1.Equals(fick._medium1) &&
               _medium2.Equals(fick._medium2));
        //TODO check Medium equality
    }
Exemple #6
0
    public static IReaction        buildFickReactionFromProps(FickProperties props, LinkedList <Medium> mediums)
    {
        FickReaction reaction = new FickReaction();
        Medium       med1     = ReactionEngine.getMediumFromId(props.MediumId1, mediums);
        Medium       med2     = ReactionEngine.getMediumFromId(props.MediumId2, mediums);

        if (med1 == null || med2 == null)
        {
            Debug.Log("failed to build FickReaction from FickProperties beacause one or all the medium id don't exist");
            return(null);
        }
        reaction.setSurface(props.surface);
        reaction.setPermCoef(props.P);
        reaction.setMedium1(med1);
        reaction.setMedium2(med2);
        reaction.setEnergyCost(props.energyCost);

        return(reaction);
    }
Exemple #7
0
    //! Return all the FickReactions possible from a Medium list.

    /*!
     *  \param mediums The list of mediums.
     *
     *  \details
     *  This function return all the possible combinaisons of FickReaction in Medium list.
     *
     *  Example :
     *    - Medium1 + Medium2 + Medium3 = FickReaction(1, 2) + FickReaction(1, 3) + FickReaction(2, 3)
     */
    public static LinkedList <FickReaction> getFickReactionsFromMediumList(LinkedList <Medium> mediums)
    {
        FickReaction              newReaction;
        LinkedListNode <Medium>   node;
        LinkedListNode <Medium>   start         = mediums.First;
        LinkedList <FickReaction> fickReactions = new LinkedList <FickReaction>();

        while (start != null)
        {
            node = start.Next;
            while (node != null)
            {
                newReaction = new FickReaction();
                newReaction.setMedium1(start.Value);
                newReaction.setMedium2(node.Value);
                fickReactions.AddLast(newReaction);
                node = node.Next;
            }
            start = start.Next;
        }
        return(fickReactions);
    }
Exemple #8
0
    //! Return all the FickReactions possible from a Medium list.
    /*!
      \param mediums The list of mediums.

      \details
      This function return all the possible combinaisons of FickReaction in Medium list.

      Example :
        - Medium1 + Medium2 + Medium3 = FickReaction(1, 2) + FickReaction(1, 3) + FickReaction(2, 3)
      */
    public static LinkedList<FickReaction> getFickReactionsFromMediumList(LinkedList<Medium> mediums)
    {
        FickReaction                newReaction;
        LinkedListNode<Medium>      node;
        LinkedListNode<Medium>      start = mediums.First;
        LinkedList<FickReaction>    fickReactions = new LinkedList<FickReaction>();

        while (start != null)
          {
        node = start.Next;
        while (node != null)
          {
            newReaction = new FickReaction();
            newReaction.setMedium1(start.Value);
            newReaction.setMedium2(node.Value);
            fickReactions.AddLast(newReaction);
            node = node.Next;
          }
        start = start.Next;
          }
        return fickReactions;
    }
Exemple #9
0
    public static IReaction buildFickReactionFromProps(FickProprieties props, LinkedList<Medium> mediums)
    {
        FickReaction reaction = new FickReaction();
        Medium med1 = ReactionEngine.getMediumFromId(props.MediumId1, mediums);
        Medium med2 = ReactionEngine.getMediumFromId(props.MediumId2, mediums);

        if (med1 == null || med2 == null)
          {
        Debug.Log("failed to build FickReaction from FickProprieties beacause one or all the medium id don't exist");
        return null;
          }
        reaction.setSurface(props.surface);
        reaction.setPermCoef(props.P);
        reaction.setMedium1(med1);
        reaction.setMedium2(med2);
        reaction.setEnergyCost(props.energyCost);

        return reaction;
    }
    public void OnTriggerExit(Collider collider)
    {
        Logger.Log("PhenoFickContact::OnTriggerExit collider=" + collider, Logger.Level.DEBUG);
        PhysicalMedium PMext = collider.gameObject.GetComponent <PhysicalMedium>();

        if (PMext == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerExit collider.PMext == null", Logger.Level.TRACE);
            return;
        }
        int    colliderMediumIdExt = PMext.MediumId;
        Medium colliderMediumExt   = ReactionEngine.getMediumFromId(colliderMediumIdExt, _reactionEngine.getMediumList());

        if (colliderMediumExt == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerExit The collided medium does not exist in the reaction Engine. Load it or change the MediumId number in the PhysicalMedium script.", Logger.Level.WARN);
            return;
        }

        PhysicalMedium PM = GetComponent <PhysicalMedium>();

        if (PMext == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerExit this.PMext == null", Logger.Level.TRACE);
            return;
        }
        int    mediumId = PM.MediumId;
        Medium medium   = ReactionEngine.getMediumFromId(mediumId, _reactionEngine.getMediumList());

        if (medium == null)
        {
            Logger.Log("PhenoFickContact::OnTriggerExit The medium does not exist in the reaction Engine. Load it or change the MediumId number in the PhysicalMedium script.", Logger.Level.WARN);
            return;
        }

        // un-set medium as medium of collider
        _collidedMediumIds.Remove(colliderMediumIdExt);

        //string nullLast = (null != _collidedMediumIds.Last)?_collidedMediumIds.Last.Value.ToString():"null";

        /*
         * Logger.Log("PhenoFickContact::OnTriggerExit"
         +" _collidedMediumIds.Count="+_collidedMediumIds.Count
         +" _collidedMediumIds.Last.Value="+nullLast
         * ,Logger.Level.);
         */
        //Logger.Log("PhenoFickContact::OnTriggerExit _collidedMediumIds.Last.Value="+nullLast, Logger.Level.);

        if (null != _collidedMediumIds.Last)
        {
            // TODO consider the current medium as superposition of mediums the ids of which are _collidedMediumIds
            configureExternalDisplays(_collidedMediumIds.Last.Value);
        }
        else
        {
            //not in any Fick contact anymore
            configureExternalDisplays(_vectroPanelInitMediumId);

            Fick         fick     = _reactionEngine.getFick();
            FickReaction reaction = Fick.getFickReactionFromIds(colliderMediumIdExt, mediumId, fick.getFickReactions());
            if (reaction == null)
            {
                Logger.Log("PhenoFickContact::OnTriggerExit This FickReaction does not exist.", Logger.Level.WARN);
            }
            reaction.setSurface(0);
        }
    }