Package cc.redberry.core.context

Examples of cc.redberry.core.context.NameDescriptor


                descriptor.getSymmetries().addUnsafe(type, new Symmetry(nextPermutation(typeData.length), false));
        }
    }

    public SimpleTensor nextSimpleTensor() {
        NameDescriptor nd = nextNameDescriptor();
        IndicesTypeStructure indicesTypeStructure = nd.getIndicesTypeStructure();
        int[] indices = nextIndices(indicesTypeStructure);
        return new SimpleTensor(nd.getId(), IndicesFactory.createSimple(indices));
    }
View Full Code Here


        if (minProductSize < 2)
            throw new IllegalArgumentException();//CHECKSTYLE
        IndicesTypeStructure typeStructure = new IndicesTypeStructure(indices);
        List<NameDescriptor> descriptors = new ArrayList<>();
        int totalIndicesCounts[] = new int[TYPES.length];
        NameDescriptor nd;
        int i;
        for (i = 0; i < minProductSize; ++i) {
            descriptors.add(nd = nextNameDescriptor());
            for (byte b : TYPES) {
                IndicesTypeStructure.TypeData typeData = nd.getIndicesTypeStructure().getTypeDatas(b);
                if (typeData != null)
                    totalIndicesCounts[b] += typeData.length;
            }
        }

        //if tensors are not not enough (product.indices.size < freeIndices.size)
        for (byte b : TYPES) {
            IndicesTypeStructure.TypeData typeData = typeStructure.getTypeDatas(b);
            if (typeData == null)
                continue;
            while (totalIndicesCounts[b] < typeData.length) {
                descriptors.add(nd = nextNameDescriptor());
                for (byte bb : TYPES) {
                    IndicesTypeStructure.TypeData typeData1 = nd.getIndicesTypeStructure().getTypeDatas(bb);
                    if (typeData1 != null)
                        totalIndicesCounts[bb] += typeData1.length;
                }
            }
        }
View Full Code Here

     * @param name    string name of the tensor
     * @param indices indices
     * @return new instance of {@link SimpleTensor} object
     */
    public static SimpleTensor simpleTensor(String name, SimpleIndices indices) {
        NameDescriptor descriptor = CC.getNameManager().mapNameDescriptor(name, indices.getStructureOfIndices());
        return new SimpleTensor(descriptor.getId(),
                UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(),
                        indices));
    }
View Full Code Here

     * @param name    int name of the tensor
     * @param indices indices
     * @return new instance of {@link SimpleTensor} object
     */
    public static SimpleTensor simpleTensor(int name, SimpleIndices indices) {
        NameDescriptor descriptor = CC.getNameDescriptor(name);
        if (descriptor == null)
            throw new IllegalArgumentException("This name is not registered in the system.");
        if (!descriptor.getStructureOfIndices().isStructureOf(indices))
            throw new IllegalArgumentException("Specified indices are not indices of specified tensor.");
        return new SimpleTensor(name,
                UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(),
                        indices));
    }
View Full Code Here

            throw new IllegalArgumentException("Illegal derivative indices.");

        int[] orders = new int[parent.size()];
        orders[argPosition] = order;
        NameDescriptorForTensorField fieldDescriptor = parent.getNameDescriptor();
        NameDescriptor derivativeDescriptor = fieldDescriptor.getDerivative(orders);

        SimpleIndices totalIndices;

        if (!fieldDescriptor.isDerivative() || derivativeIndices.size() == 0 || parent.indices.size() == 0) {
            totalIndices = new SimpleIndicesBuilder().append(parent.getIndices()).append(derivativeIndices).getIndices();
        } else {
            orders = fieldDescriptor.getDerivativeOrders();

            SimpleIndicesBuilder ib = new SimpleIndicesBuilder();
            StructureOfIndices[] structures = fieldDescriptor.getStructuresOfIndices();
            int i, from;
            SimpleIndices singleType;
            IndexType eType;
            for (byte type = IndexType.TYPES_COUNT - 1; type >= 0; --type) {
                eType = IndexType.values()[type];
                singleType = parent.getIndices().getOfType(eType);
                from = fieldDescriptor.getParent().getStructureOfIndices().getTypeData(type).length;
                for (i = 0; i <= argPosition; ++i)
                    from += structures[i + 1].getTypeData(type).length * orders[i];
                for (i = 0; i < from; ++i)
                    ib.append(singleType.get(i));
                ib.append(derivativeIndices.getOfType(eType));
                for (; i < singleType.size(); ++i)
                    ib.append(singleType.get(i));
            }
            totalIndices = ib.getIndices();
        }

        return new TensorField(derivativeDescriptor.getId(),
                UnsafeIndicesFactory.createOfTensor(derivativeDescriptor.getSymmetries(), totalIndices),
                parent.args, parent.argIndices);
    }
View Full Code Here

            structures[0] = structureOfIndices;

            NameDescriptorForTensorField fieldDescriptor =
                    (NameDescriptorForTensorField) CC.getNameManager().mapNameDescriptor(name, structures);

            NameDescriptor derivativeDescriptor = fieldDescriptor.getDerivative(orders);

            return new TensorField(derivativeDescriptor.getId(),
                    UnsafeIndicesFactory.createOfTensor(derivativeDescriptor.getSymmetries(), indices),
                    arguments, argIndices);
        } catch (RuntimeException re) {
            throw new IllegalArgumentException("Inconsistent derivative orders/indices.", re);
        }
    }
View Full Code Here

        StructureOfIndices[] structures = new StructureOfIndices[argIndices.length + 1];
        structures[0] = indices.getStructureOfIndices();
        for (int i = 0; i < argIndices.length; ++i)
            structures[i + 1] = argIndices[i].getStructureOfIndices();
        NameDescriptor descriptor = CC.getNameManager().mapNameDescriptor(name, structures);
        return new TensorField(descriptor.getId(),
                UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices),
                arguments, argIndices);
    }
View Full Code Here

    public static TensorField field(int name, SimpleIndices indices, SimpleIndices[] argIndices, Tensor[] arguments) {
        if (argIndices.length != arguments.length)
            throw new IllegalArgumentException("Argument indices array and arguments array have different length.");
        if (arguments.length == 0)
            throw new IllegalArgumentException("No arguments in field.");
        NameDescriptor descriptor = CC.getNameDescriptor(name);
        if (descriptor == null)
            throw new IllegalArgumentException("This name is not registered in the system.");
        if (!descriptor.isField())
            throw new IllegalArgumentException("Name correspods to simple tensor (not a field).");
        if (descriptor.getStructuresOfIndices().length - 1 != argIndices.length)
            throw new IllegalArgumentException("This name corresponds to field with different number of arguments.");
        if (!descriptor.getStructureOfIndices().isStructureOf(indices))
            throw new IllegalArgumentException("Specified indices are not indices of specified tensor.");
        for (int i = 0; i < argIndices.length; ++i) {
            if (!descriptor.getStructuresOfIndices()[i + 1].isStructureOf(argIndices[i]))
                throw new IllegalArgumentException("Arguments indices are inconsistent with field signature.");
            if (!arguments[i].getIndices().getFree().equalsRegardlessOrder(argIndices[i]))
                throw new IllegalArgumentException("Arguments indices are inconsistent with arguments.");
        }
        return new TensorField(name,
                UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices),
                arguments, argIndices);
    }
View Full Code Here

     * @return new instance of {@link TensorField} object
     */
    public static TensorField field(int name, SimpleIndices indices, Tensor[] arguments) {
        if (arguments.length == 0)
            throw new IllegalArgumentException("No arguments in field.");
        NameDescriptor descriptor = CC.getNameDescriptor(name);
        if (descriptor == null)
            throw new IllegalArgumentException("This name is not registered in the system.");
        if (!descriptor.getStructureOfIndices().isStructureOf(indices))
            throw new IllegalArgumentException("Specified indices are not indices of specified tensor.");
        SimpleIndices[] argIndices = new SimpleIndices[arguments.length];
        for (int i = 0; i < arguments.length; ++i)
            argIndices[i] = IndicesFactory.createSimple(null, arguments[i].getIndices().getFree());
        return new TensorField(name,
                UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices),
                arguments, argIndices);
    }
View Full Code Here

     * @return instance of specified simple tensor with specified indices
     */
    public static SimpleTensor setIndices(SimpleTensor tensor, SimpleIndices indices) {
        if (tensor.getIndices() == indices) return tensor;

        NameDescriptor descriptor = tensor.getNameDescriptor();
        if (!descriptor.getStructureOfIndices().isStructureOf(indices))
            throw new IllegalArgumentException("Illegal structure of indices.");
        if (descriptor.isField())
            return new TensorField(tensor.name,
                    UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices),
                    ((TensorField) tensor).args, ((TensorField) tensor).argIndices);
        else
            return new SimpleTensor(tensor.name,
                    UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(),
                            indices));
    }
View Full Code Here

TOP

Related Classes of cc.redberry.core.context.NameDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.