Documentation of 'cc.redberry.core.context.Context' Java class
Context
cc.redberry.core.context

Class Context



  • public final class Context
    extends java.lang.Object
    This class represents Redberry context. It stores all Redberry session data (in some sense it stores static data).

    Management of current Redberry context is made through ContextManager class. Context of Redberry is attached to the current thread, so that any thread created from the outside of Redebrry will hold a unique instance of Context object. In such a way tensors created in one thread can not be used in the other thread because they are in some sense "attached" to the initial thread. However, if thread is created through the executor service which is obtained from ContextManager.getExecutorService(), it will share the same context as initial thread (such threads could hold concurrent computations regarding single context, the appropriate synchronization is assumed). In order to create a new session of Redberry with a particular context, an instance of this class should be set as a current context via ContextManager.setCurrentContext(Context).

    Since:
    1.0
    See Also:
    NameManager, IndexConverterManager, ParseManager, OutputFormat, ContextManager, ContextSettings
    • Constructor Detail

      • Context

        public Context(ContextSettings contextSettings)
        Creates context from the settings
        Parameters:
        contextSettings - settings
        See Also:
        ContextSettings
    • Method Detail

      • getMetricTypes

        public java.util.Set<IndexType> getMetricTypes()
        Returns all metric types.
        Returns:
        all metric types
      • getMatrixTypes

        public java.util.Set<IndexType> getMatrixTypes()
        Returns all matrix types.
        Returns:
        all matrix types
      • resetTensorNames

        public void resetTensorNames()
        This method resets all tensor names in the namespace.

        Any tensor created before this method call becomes invalid, and must not be used! This method is mainly used in unit tests, so avoid invocations of this method in general computations.

      • resetTensorNames

        public void resetTensorNames(long seed)
        This method resets all tensor names in the namespace and sets a specified seed to the NameManager. If this method is invoked with constant seed before any interactions with Redberry, further behaviour of Redberry will be fully deterministic from run to run (order of summands and multipliers will be fixed, computation time will be pretty constant, hash codes will be the same).

        Any tensor created before this method call becomes invalid, and must not be used! This method is mainly used in unit tests, so avoid invocations of this method in general computations.

      • setDefaultOutputFormat

        public void setDefaultOutputFormat(OutputFormat defaultOutputFormat)
        Sets the default output format. After this step, all expressions will be printed according to the specified output format.
        Parameters:
        defaultOutputFormat - output format
      • getDefaultOutputFormat

        public OutputFormat getDefaultOutputFormat()
        Returns current default output format.
        Returns:
        current default output format
      • getIndexConverterManager

        public IndexConverterManager getIndexConverterManager()
        Returns index converter manager of current session.
        Returns:
        index converter manager of current session
      • getNameManager

        public NameManager getNameManager()
        Returns the name manager (namespace) of current session.
        Returns:
        the name manager (namespace) of current session.
      • getNameDescriptor

        public NameDescriptor getNameDescriptor(int nameId)
        Returns NameDescriptor corresponding to the specified int nameId.
        Parameters:
        nameId - integer name of tensor
        Returns:
        corresponding NameDescriptor
      • getKroneckerName

        public java.lang.String getKroneckerName()
        Returns string representation of Kronecker delta name
        Returns:
        string representation of Kronecker delta name
      • getMetricName

        public java.lang.String getMetricName()
        Returns string representation of metric tensor name
        Returns:
        string representation of metric tensor name
      • setMetricName

        public void setMetricName(java.lang.String name)
        Sets the default metric tensor name. After this step, metric tensor will be printed with the specified string name.
        Parameters:
        name - string representation of metric tensor name
      • setKroneckerName

        public void setKroneckerName(java.lang.String name)
        Sets the default Kronecker tensor name. After this step, Kronecker tensor will be printed with the specified string name.
        Parameters:
        name - string representation of Kronecker tensor name
      • isKronecker

        public boolean isKronecker(SimpleTensor t)
        Returns true if specified tensor is a Kronecker tensor
        Parameters:
        t - tensor
        Returns:
        true if specified tensor is a Kronecker tensor
      • isMetric

        public boolean isMetric(SimpleTensor t)
        Returns true if specified tensor is a metric tensor
        Parameters:
        t - tensor
        Returns:
        true if specified tensor is a metric tensor
      • isKroneckerOrMetric

        public boolean isKroneckerOrMetric(SimpleTensor t)
        Returns true if specified tensor is a metric or a Kronecker tensor
        Parameters:
        t - tensor
        Returns:
        true if specified tensor is a metric or a Kronecker tensor
      • getParseManager

        public ParseManager getParseManager()
        Returns parse manager of current session
        Returns:
        parse manager of current session
      • isMetric

        public boolean isMetric(byte type)
        Returns true if metric is defined for the specified index type.
        Parameters:
        type - index type
        Returns:
        true if metric is defined for the specified index type
      • createKronecker

        public SimpleTensor createKronecker(int index1,
                                            int index2)
        Returns Kronecker tensor with specified upper and lower indices.
        Parameters:
        index1 - first index
        index2 - second index
        Returns:
        Kronecker tensor with specified upper and lower indices
        Throws:
        java.lang.IllegalArgumentException - if indices have same states
        java.lang.IllegalArgumentException - if indices have different types
      • createMetric

        public SimpleTensor createMetric(int index1,
                                         int index2)
        Returns metric tensor with specified indices.
        Parameters:
        index1 - first index
        index2 - second index
        Returns:
        metric tensor with specified indices
        Throws:
        java.lang.IllegalArgumentException - if indices have different states
        java.lang.IllegalArgumentException - if indices have different types
        java.lang.IllegalArgumentException - if indices have non metric types
      • createMetricOrKronecker

        public SimpleTensor createMetricOrKronecker(int index1,
                                                    int index2)
        Returns metric tensor if specified indices have same states and Kronecker tensor if specified indices have different states.
        Parameters:
        index1 - first index
        index2 - second index
        Returns:
        metric tensor if specified indices have same states and Kronecker tensor if specified indices have different states
        Throws:
        java.lang.IllegalArgumentException - if indices have different types
        java.lang.IllegalArgumentException - if indices have same states and non metric types
      • generateNewSymbol

        public SimpleTensor generateNewSymbol()
        Generates a new symbol which never used before during current session.
        Returns:
        new symbol which never used before during current session
      • getRandomGenerator

        public org.apache.commons.math3.random.RandomGenerator getRandomGenerator()
        Returns random generator used by Redberry in current session.
        Returns:
        random generator used by Redberry in current session
      • get

        public static Context get()
        Returns the current context of Redberry session.
        Returns:
        the current context of Redberry session.

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.