pointers[j] = getTypeData((byte) j).from;
/** * Adds specified symmetry written in one-line notation to this symmetries. * * @param sign {@code true} for antisymmetry, {@code false} for symmetry * @param permutation permutation written in one-line notation * @throws java.lang.IllegalStateException if this instance of symmetries is already in use (permutation group * calculated) * @throws java.lang.IllegalArgumentException if specified permutation is inconsistent with one-line notation * @throws java.lang.IllegalArgumentException when inputting antisymmetry with odd order * @throws java.lang.IllegalArgumentException if this structure of indices is inconsistent with specified * permutation (permutation mixes indices of different types) */ public void add(boolean sign, int[] permutation) { byte type = -1; StructureOfIndices.TypeData typeData; for (int i = 0; i < IndexType.TYPES_COUNT; ++i) { typeData = structureOfIndices.getTypeData((byte) i); if (typeData.length != 0) { if (type != -1) throw new IllegalArgumentException(); if (typeData.length != permutation.length) throw new IllegalArgumentException(); type = (byte) i; } } addSymmetry(type, Permutations.createPermutation(sign, permutation)); }
public void addInsertionRule(NameDescriptor nd, IndexType omittedIndexType) { NameAndStructureOfIndices originalStructureAndName = NameDescriptor.extractKey(nd); StructureOfIndices structure = nd.getStructureOfIndices(); if (structure.getTypeData(omittedIndexType.getType()).length == 0) throw new IllegalArgumentException("No indices of specified type in tensor."); if (CC.isMetric(omittedIndexType.getType())) { int omittedIndicesCount = structure.getTypeData(omittedIndexType.getType()).length; if ((omittedIndicesCount % 2) == 1) throw new IllegalArgumentException("The number of omitted indices for metric types should be even."); omittedIndicesCount /= 2; BitArray omittedIndices = structure.getTypeData(omittedIndexType.getType()).states; for (int i = 0, size = omittedIndices.size(); i < size; ++i) { if (i < omittedIndicesCount && !omittedIndices.get(i)) throw new IllegalArgumentException("Inconsistent states signature for metric type."); if (i >= omittedIndicesCount && omittedIndices.get(i)) throw new IllegalArgumentException("Inconsistent states signature for metric type."); } } mappedRules = null; InsertionRule rule = initialRules.get(originalStructureAndName); if (rule == null) initialRules.put(originalStructureAndName, rule = new InsertionRule(originalStructureAndName)); rule.indicesAllowedToOmit.add(omittedIndexType); }
/** * Adds specified symmetry to symmetries of indices of specified type. * * @param type type of indices * @param symmetry symmetry * @throws java.lang.IllegalStateException if this instance of symmetries is already in use (permutation group * calculated) * @throws java.lang.IllegalArgumentException if this structure of indices is inconsistent with specified * permutation (permutation mixes indices of different types) */ public void addSymmetry(byte type, Permutation symmetry) { if (symmetry.isIdentity()) return; if (permutationGroup != null) throw new IllegalStateException("Permutation group is already in use."); StructureOfIndices.TypeData data = structureOfIndices.getTypeData(type); if (data == null) throw new IllegalArgumentException("No such type: " + IndexType.getType(type)); if (data.length < symmetry.degree()) throw new IllegalArgumentException("Wrong symmetry length."); int[] s = new int[structureOfIndices.size()]; int i = 0; for (; i < data.from; ++i) s[i] = i; for (int j = 0; j < data.length; ++j, ++i) s[i] = symmetry.newIndexOf(j) + data.from; for (; i < structureOfIndices.size(); ++i) s[i] = i; generators.add(Permutations.createPermutation(symmetry.antisymmetry(), s)); }
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); }
private void checkConsistency() { int i; for (i = 0; i < actualInput; ++i) { if (!(inputValues[i].get(0) instanceof SimpleTensor)) throw new IllegalArgumentException(); SimpleTensor st = (SimpleTensor) inputValues[i].get(0); NameDescriptor nd = CC.getNameDescriptor(st.getName()); if (!nd.getName(null).equals(getStringInputName(i))) throw new IllegalArgumentException(); } for (; i < INPUT_VALUES_GENERAL_COUNT; ++i) if (inputValues[i] != null) throw new IllegalArgumentException(); SimpleIndices indices = (SimpleIndices) inputValues[1].get(0).getIndices(); StructureOfIndices structureOfIndices = indices.getStructureOfIndices(); if (structureOfIndices.getTypeData(IndexType.LatinLower.getType()).length != structureOfIndices.size()) throw new IllegalArgumentException("Only Latin lower indices are legal."); int matrixIndicesCount = indices.size() - operatorOrder; if (matrixIndicesCount % 2 != 0) throw new IllegalArgumentException(); if (inputValues[0].get(0).getIndices().size() != matrixIndicesCount) throw new IllegalArgumentException(); for (i = 1; i < actualInput; ++i) { structureOfIndices = ((SimpleIndices) inputValues[i].get(0).getIndices()).getStructureOfIndices(); if (structureOfIndices.getTypeData(IndexType.LatinLower.getType()).length != structureOfIndices.size()) throw new IllegalArgumentException("Only Latin lower indices are legal."); if (structureOfIndices.size() + i - 1 != operatorOrder + matrixIndicesCount) throw new IllegalArgumentException(); } }
public int[] nextIndices(StructureOfIndices structureOfIndices) { int[] indices = new int[structureOfIndices.size()]; int[] typeInd; int p = 0; for (byte b : TYPES) { StructureOfIndices.TypeData typeData = structureOfIndices.getTypeData(b); if (typeData == null || typeData.length == 0) continue; typeInd = new int[typeData.length]; if (typeData.states != null) { //in the case of matrix indices int[] names = nextPermutation(typeInd.length); for (int i = 0; i < typeInd.length; ++i) typeInd[i] = IndicesUtils.createIndex(names[i], b, typeData.states.get(i)); } else { int i; int contracted = (contracted = nextInt(indices.length / 2)) == 0 ? 1 : contracted; for (i = 0; i < typeInd.length / contracted; ++i) typeInd[i] = IndicesUtils.setType(b, i); if (i - contracted < 0) contracted = i; for (; i < typeInd.length; ++i) typeInd[i] = IndicesUtils.createIndex(i - contracted, b, true); shuffle(typeInd); } System.arraycopy(typeInd, 0, indices, p, typeInd.length); p += typeInd.length; } return indices; }
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))); } }
descriptors.add(nd = nextTensorTree(TensorType.Sum, depth - 1, parameters)); for (byte b : TYPES) { StructureOfIndices.TypeData typeData = IndicesFactory.createSimple(null, nd.getIndices().getFree()).getStructureOfIndices().getTypeData(b); if (typeData != null) totalIndicesCounts[b] += typeData.length; StructureOfIndices.TypeData typeData = typeStructure.getTypeData(b); if (typeData == null) continue; descriptors.add(nd = nextTensorTree(TensorType.Sum, depth - 1, parameters)); for (byte bb : TYPES) { StructureOfIndices.TypeData typeData1 = IndicesFactory.createSimple(null, nd.getIndices().getFree()).getStructureOfIndices().getTypeData(bb); if (typeData1 != null) totalIndicesCounts[bb] += typeData1.length; StructureOfIndices.TypeData typeData = typeStructure.getTypeData(b); if ((totalIndicesCounts[b] - (typeData == null ? 0 : typeData.length)) % 2 != 0) { int[] typeCount = new int[TYPES.length]; for (byte b : TYPES) { indicesSpace[b] = new int[totalIndicesCounts[b]]; StructureOfIndices.TypeData typeData = typeStructure.getTypeData(b); if (typeData == null) freeIndices[b] = new int[0]; int position = 0; for (byte b : TYPES) { StructureOfIndices.TypeData typeData = its.getTypeData(b);
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));