private void addRandomSymmetries(NameDescriptor descriptor) {//TODO add antisymmetries if (!descriptor.getSymmetries().isTrivial()) //todo <= review this moment return; StructureOfIndices typeStructure = descriptor.getStructureOfIndices(); int i; for (byte type = 0; type < TYPES_COUNT; ++type) { StructureOfIndices.TypeData typeData = typeStructure.getTypeData(type); if (typeData == null) continue; if (typeData.length == 0)//redundant continue; int count = random.nextInt(4); for (i = 0; i < count; ++i) descriptor.getSymmetries().addSymmetry(type, Permutations.createPermutation(false, nextPermutation(typeData.length))); } }
/** * Returns an instance of specified simple tensor with specified indices * * @param tensor simple tensor * @param indices indices * @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(String.format("Illegal structure of indices (tensor = %s, indices = %s).", tensor, indices)); if (indices.size() == 0) return tensor; 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)); }
/** * Returns new tensor field with specified int name (see {@link cc.redberry.core.context.NameManager} * for details), indices and arguments list. Free indices of arguments * assumed as arguments indices bindings of this field bindings. * * @param name int name of the field * @param indices indices * @param arguments arguments list * @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); }
UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices), arguments, argIndices);
public SimpleTensor nextSimpleTensor() { NameDescriptor nd = nextNameDescriptor(); StructureOfIndices structureOfIndices = nd.getStructureOfIndices(); int[] indices = nextIndices(structureOfIndices); return Tensors.simpleTensor(nd.getId(), IndicesFactory.createSimple(nd.getSymmetries(), indices)); }
public SimpleTensor nextSimpleTensor(SimpleIndices indices) { NameDescriptor nd = nextNameDescriptor(indices.getStructureOfIndices()); StructureOfIndices structureOfIndices = nd.getStructureOfIndices(); int[] _indices = nextIndices(structureOfIndices); return Tensors.simpleTensor(nd.getId(), IndicesFactory.createSimple(nd.getSymmetries(), _indices)); }
/** * Returns new tensor field with specified string name, indices, arguments * list and explicit argument indices bindings. * * @param name int name of the field * @param indices indices * @param argIndices argument indices bindings * @param arguments arguments list * @return new instance of {@link TensorField} object */ public static TensorField field(String 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."); for (int i = 0; i < argIndices.length; ++i) if (!arguments[i].getIndices().getFree().equalsRegardlessOrder(argIndices[i])) throw new IllegalArgumentException("Arguments indices are inconsistent with arguments."); 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); }
private NameDescriptor createDescriptor(final String sname, final StructureOfIndices[] structuresOfIndices, int id) { if (structuresOfIndices.length != 1) return new NameDescriptorForTensorFieldImpl(sname, structuresOfIndices, id, sname.equals(diracDeltaName) && structuresOfIndices.length == 3); final StructureOfIndices its = structuresOfIndices[0]; if (its.size() != 2) return new NameDescriptorForSimpleTensor(sname, structuresOfIndices, id); for (byte b = 0; b < IndexType.TYPES_COUNT; ++b) if (its.typeCount(b) == 2) { if (CC.isMetric(b)) { if (sname.equals(kroneckerAndMetricNames[0]) || sname.equals(kroneckerAndMetricNames[1])) { NameDescriptor descriptor = new NameDescriptorForMetricAndKronecker(kroneckerAndMetricNames, b, id); descriptor.getSymmetries().add(b, false, 1, 0); return descriptor; } } else { if (sname.equals(kroneckerAndMetricNames[1])) throw new ParserException("Metric is not specified for non metric index type."); if (sname.equals(kroneckerAndMetricNames[0])) { if (its.getTypeData(b).states.get(0) != true || its.getTypeData(b).states.get(1) != false) throw new ParserException("Illegal Kroneckers indices states."); NameDescriptor descriptor = new NameDescriptorForMetricAndKronecker(kroneckerAndMetricNames, b, id); return descriptor; } } } return new NameDescriptorForSimpleTensor(sname, structuresOfIndices, id); }
UnsafeIndicesFactory.createOfTensor(derivativeDescriptor.getSymmetries(), indices), arguments, argIndices); } catch (RuntimeException re) {
/** * Returns new simple tensor with specified int name (see {@link cc.redberry.core.context.NameManager} * for details) and indices. * * @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 ( " + indices + " )are not indices of specified tensor ( " + descriptor + " )."); if (indices.size() == 0) { assert indices == IndicesFactory.EMPTY_SIMPLE_INDICES; NameDescriptorForSimpleTensor nst = (NameDescriptorForSimpleTensor) descriptor; if (nst.getCachedSymbol() == null) { SimpleTensor st; nst.setCachedInstance(st = new SimpleTensor(descriptor.getId(), indices)); return st; } else return nst.getCachedSymbol(); } return new SimpleTensor(name, UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices)); }
/** * Returns new simple tensor with specified string name and indices. * * @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()); if (indices.size() == 0) { assert indices == IndicesFactory.EMPTY_SIMPLE_INDICES; NameDescriptorForSimpleTensor nst = (NameDescriptorForSimpleTensor) descriptor; if (nst.getCachedSymbol() == null) { SimpleTensor st; nst.setCachedInstance(st = new SimpleTensor(descriptor.getId(), indices)); return st; } else return nst.getCachedSymbol(); } return new SimpleTensor(descriptor.getId(), UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices)); }
UnsafeIndicesFactory.createOfTensor(derivativeDescriptor.getSymmetries(), totalIndices), parent.args, parent.argIndices);