@Override public Indices getIndices() { return content[0].getIndices().getFree(); }
private static void getAllIndices1(ParseToken node, Set<Integer> set) { if (node instanceof ParseTokenSimpleTensor) { Indices indices = node.getIndices(); for (int i = indices.size() - 1; i >= 0; --i) set.add(IndicesUtils.getNameWithType(indices.get(i))); } else for (ParseToken pn : node.content) if (!(pn instanceof ParseTokenScalarFunction)) getAllIndices1(pn, set); }
/** * Returns {@link Indices} of the corresponding mathematical expression. * * @return {@link Indices} of the corresponding mathematical expression */ public Indices getIndices() { switch (tokenType) { case Product: case Trace: IndicesBuilder builder = new IndicesBuilder(); for (ParseToken node : content) builder.append(node.getIndices()); return builder.getIndices(); case Sum: return IndicesFactory.create(content[0].getIndices()); case Power: return IndicesFactory.EMPTY_INDICES; } throw new ParserException("Unknown tensor type: " + tokenType); }
public ParseTokenDerivative(TokenType tokenType, ParseToken... content) { super(tokenType, content); IndicesBuilder ib = new IndicesBuilder(); ib.append(content[0].getIndices().getFree()); for (int i = content.length - 1; i >= 1; --i) ib.append(content[i].getIndices().getInverted().getFree()); indices = ib.getIndices(); }
&& simpleTensorNode.indices.size() == 0 && arguments.size() == 1 && arguments.get(0).getIndices().getFree().size() == 0) return new ParseToken(TokenType.Power, new ParseToken[]{arguments.get(0), new ParseTokenNumber(Complex.ONE_HALF)});
private static void getAllIndicesT1(ParseToken node, TIntSet set) { if (node instanceof ParseTokenSimpleTensor) { Indices indices = node.getIndices(); for (int i = indices.size() - 1; i >= 0; --i) set.add(IndicesUtils.getNameWithType(indices.get(i))); } else for (ParseToken pn : node.content) if (!(pn instanceof ParseTokenScalarFunction)) getAllIndicesT1(pn, set); } }
@Override public NameAndStructureOfIndices getIndicesTypeStructureAndName() { StructureOfIndices[] typeStructures = new StructureOfIndices[1 + argumentsIndices.length]; typeStructures[0] = StructureOfIndices.create(indices); for (int i = 0; i < argumentsIndices.length; ++i) { if (argumentsIndices[i] == null) argumentsIndices[i] = IndicesFactory.createSimple(null, content[i].getIndices().getFree()); typeStructures[i + 1] = StructureOfIndices.create(argumentsIndices[i]); } return new NameAndStructureOfIndices(name, typeStructures); }
@Override public ParseToken transform(ParseToken node) { final int[] freeIndices = node.getIndices().getFree().getAllIndices().copy(); int i; for (i = 0; i < freeIndices.length; ++i)
@Override public ParseToken parseToken(String expression, Parser parser) { ParseToken node = super.parseToken(expression, parser); if (node == null || !parser.isAllowSameVariance()) return node; TIntHashSet indices = new TIntHashSet(); for (ParseToken c : node.content) { Indices free = c.getIndices().getFree(); for (int i = 0; i < free.size(); i++) { int ind = free.get(i); if (indices.contains(ind)) revertIndex(c, ind); else indices.add(ind); } } return node; }
private void transformInsideFieldsAndScalarFunctions(ParseToken pn) { if (pn.tokenType == TokenType.TensorField) { ParseTokenTensorField pntf = (ParseTokenTensorField) pn; for (int i = 0; i < pn.content.length; ++i) { ParseToken newArgNode = transform(pntf.content[i]); pntf.content[i] = newArgNode; newArgNode.parent = pntf; SimpleIndices oldArgIndices = pntf.argumentsIndices[i]; if (oldArgIndices != null) { IntArrayList newArgIndices = new IntArrayList(oldArgIndices.getAllIndices().copy()); Indices newIndices = newArgNode.getIndices(); for (byte j = 0; j < TYPES_COUNT; ++j) { if (oldArgIndices.size(IndexType.getType(j)) < newIndices.size(IndexType.getType(j))) { if (oldArgIndices.size(IndexType.getType(j)) != 0) throw new IllegalArgumentException("Error in field arg indices."); newArgIndices.addAll(newIndices.getOfType(IndexType.getType(j)).getAllIndices()); } } pntf.argumentsIndices[i] = IndicesFactory.createSimple(null, newArgIndices.toArray()); } } } if (pn.tokenType == TokenType.Power || pn.tokenType == TokenType.ScalarFunction) { for (int i = 0; i < pn.content.length; ++i) pn.content[i] = transform(pn.content[i]); } for (int i = 0; i < pn.content.length; ++i) transformInsideFieldsAndScalarFunctions(pn.content[i]); }
@Override public ParseToken transform(ParseToken node) { TokenType type = node.tokenType; switch (type) { case SimpleTensor: ParseTokenSimpleTensor st = (ParseTokenSimpleTensor) node; NameAndStructureOfIndices ds = st.getIndicesTypeStructureAndName(); return new ParseTokenSimpleTensor(transformIndices(st.getIndices(), ds), transformer.newName(ds.getName(), ds)); case TensorField: ParseTokenTensorField tf = (ParseTokenTensorField) node; ParseToken[] newContent = transformContent(tf.content); SimpleIndices[] newArgsIndices = new SimpleIndices[tf.argumentsIndices.length]; for (int i = newArgsIndices.length - 1; i >= 0; --i) newArgsIndices[i] = IndicesFactory.createSimple(null, newContent[i].getIndices()); NameAndStructureOfIndices dsf = tf.getIndicesTypeStructureAndName(); return new ParseTokenTensorField(transformIndices(tf.getIndices(), dsf), transformer.newName(dsf.getName(), dsf), newContent, newArgsIndices); case Number: return node; case ScalarFunction: return new ParseTokenScalarFunction(((ParseTokenScalarFunction) node).function, transformContent(node.content)); case Expression: ParseToken[] nContent = transformContent(node.content); return new ParseTokenExpression(((ParseTokenExpression) node).preprocess, nContent[0], nContent[1]); default: return new ParseToken(node.tokenType, transformContent(node.content)); } }