static final IndexType[] extractTypesFromMatrix(SimpleTensor matrix) { if (matrix.getIndices().size() != 3) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); NameDescriptor descriptor = CC.getNameDescriptor(matrix.getName()); StructureOfIndices typeStructure = descriptor.getStructureOfIndices(); byte metricType = -1, matrixType = -1; int typeCount; for (byte type = 0; type < IndexType.TYPES_COUNT; ++type) { typeCount = typeStructure.typeCount(type); if (typeCount == 0) continue; else if (typeCount == 2) { if (matrixType != -1) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); matrixType = type; if (CC.isMetric(matrixType)) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } else if (typeCount == 1) { if (metricType != -1) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); metricType = type; if (!CC.isMetric(metricType)) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } else throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } return new IndexType[]{IndexType.getType(metricType), IndexType.getType(matrixType)}; }
public SimpleTransformer(ParseTokenSimpleTensor node, InsertionRule insertionRule) { this.node = node; //this.insertionRule = insertionRule; StructureOfIndices originalStructure = insertionRule.originalStructureAndName.getStructure()[0]; StructureOfIndices currentStructure = node.getIndicesTypeStructureAndName().getStructure()[0]; for (IndexType type : insertionRule.indicesAllowedToOmit) if (currentStructure.getStates(type).size() == 0) { BitArray originalStates = originalStructure.getStates(type); if (originalStates != null) { outerIndices.upper[type.getType()] = originalStates.bitCount(); outerIndices.lower[type.getType()] = originalStates.size() - outerIndices.upper[type.getType()]; } else { outerIndices.upper[type.getType()] = outerIndices.lower[type.getType()] = originalStructure.typeCount(type.getType()) / 2; } } else if (currentStructure.typeCount(type.getType()) != originalStructure.typeCount(type.getType())) throw new IllegalArgumentException(); outerIndices.init(); }
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); }