/** * Returns {@code NameDescriptor} corresponding to the specified {@code int} nameId. * * @param nameId integer name of tensor * @return corresponding {@code NameDescriptor} */ public NameDescriptor getNameDescriptor(int nameId) { return nameManager.getNameDescriptor(nameId); }
/** * Returns {@code true} if specified tensor is a metric or a Kronecker tensor * * @param t tensor * @return {@code true} if specified tensor is a metric or a Kronecker tensor */ public boolean isKroneckerOrMetric(SimpleTensor t) { return nameManager.isKroneckerOrMetric(t.getName()); }
NameDescriptorForTensorFieldDerivative createDescriptorForFieldDerivative(NameDescriptorForTensorFieldImpl field, int[] orders) { //todo readLock? writeLock.lock(); try { NameDescriptorForTensorFieldDerivative result = new NameDescriptorForTensorFieldDerivative(generateNewName(), orders, field); registerDescriptor(result); return result; } finally { writeLock.unlock(); } }
public boolean isKroneckerOrMetric() { return name.equals(CC.getNameManager().getKroneckerName()) || name.equals(CC.getNameManager().getMetricName()); }
knownND = fromStructure.get(key); if (knownND == null) { //Double check int name = generateNewName(); NameDescriptor descriptor = createDescriptor(sname, structureOfIndices, name); if (descriptor instanceof NameDescriptorForMetricAndKronecker) { kroneckerAndMetricIds.add(name); kroneckerAndMetricIds.sort(); registerDescriptor(descriptor); stringNames.add(sname); return descriptor;
/** * Returns metric tensor with specified indices. * * @param index1 first index * @param index2 second index * @return metric tensor with specified indices * @throws IllegalArgumentException if indices have different states * @throws IllegalArgumentException if indices have different types * @throws IllegalArgumentException if indices have non metric types */ public SimpleTensor createMetric(int index1, int index2) { byte type; if ((type = IndicesUtils.getType(index1)) != IndicesUtils.getType(index2) || !IndicesUtils.haveEqualStates(index1, index2) || !metricTypesBits.get(type)) throw new IllegalArgumentException("Not metric indices."); SimpleIndices indices = IndicesFactory.createSimple(null, index1, index2); NameDescriptor nd = nameManager.mapNameDescriptor(nameManager.getMetricName(), StructureOfIndices.create(indices)); int name = nd.getId(); return Tensors.simpleTensor(name, indices); }
/** * Returns Kronecker tensor with specified upper and lower indices. * * @param index1 first index * @param index2 second index * @return Kronecker tensor with specified upper and lower indices * @throws IllegalArgumentException if indices have same states * @throws IllegalArgumentException if indices have different types */ public SimpleTensor createKronecker(int index1, int index2) { byte type; if ((type = IndicesUtils.getType(index1)) != IndicesUtils.getType(index2) || IndicesUtils.getRawStateInt(index1) == IndicesUtils.getRawStateInt(index2)) throw new IllegalArgumentException("This is not kronecker indices!"); if (!isMetric(type) && IndicesUtils.getState(index2)) { int t = index1; index1 = index2; index2 = t; } SimpleIndices indices = IndicesFactory.createSimple(null, index1, index2); NameDescriptor nd = nameManager.mapNameDescriptor(nameManager.getKroneckerName(), StructureOfIndices.create(indices)); int name = nd.getId(); return Tensors.simpleTensor(name, indices); }
/** * Returns string representation of Kronecker delta name * * @return string representation of Kronecker delta name */ public String getKroneckerName() { return nameManager.getKroneckerName(); }
/** * Returns string representation of metric tensor name * * @return string representation of metric tensor name */ public String getMetricName() { return nameManager.getMetricName(); }
/** * Returns a delta function with specified arguments * * @param a tensor * @param b tensor * @return DiracDelta[a, b] */ public TensorField createDeltaFunction(Tensor a, Tensor b) { return Tensors.field(nameManager.getDiracDeltaName(), IndicesFactory.EMPTY_SIMPLE_INDICES, new Tensor[]{a, b}); }
@Override public NameDescriptorForTensorField getDerivative(int... orders) { if (orders.length != structuresOfIndices.length - 1) throw new IllegalArgumentException(); boolean b = true; for (int o : orders) { if (o < 0) throw new IllegalArgumentException("Negative derivative order."); if (o != 0) b = false; } if (b) return this; final DerivativeDescriptor derivativeDescriptor = new DerivativeDescriptor(orders); NameDescriptorForTensorFieldDerivative nd = derivatives.get(derivativeDescriptor); if (nd == null) synchronized (this) { nd = derivatives.get(derivativeDescriptor); if (nd == null) derivatives.put(derivativeDescriptor, nd = nameManager.createDescriptorForFieldDerivative(this, orders)); } return nd; }
/** * Generates a new symbol which never used before during current session. * * @return new symbol which never used before during current session */ public SimpleTensor generateNewSymbol() { NameDescriptor nameDescriptor = nameManager.generateNewSymbolDescriptor(); return Tensors.simpleTensor(nameDescriptor.getId(), IndicesFactory.EMPTY_SIMPLE_INDICES); }
/** * Creates context from the settings * * @param contextSettings settings * @see ContextSettings */ public Context(ContextSettings contextSettings) { this.parseManager = new ParseManager(contextSettings.getParser()); this.converterManager = contextSettings.getConverterManager(); this.nameManager = new NameManager(contextSettings.getNameManagerSeed(), contextSettings.getKronecker(), contextSettings.getMetricName()); this.defaultOutputFormat = contextSettings.getDefaultOutputFormat(); EnumSet<IndexType> metricTypes = EnumSet.noneOf(IndexType.class); EnumSet<IndexType> matrixTypes = EnumSet.allOf(IndexType.class); for (IndexType type : contextSettings.getMetricTypes()) { matrixTypes.remove(type); metricTypes.add(type); this.metricTypesBits.set(type.getType()); } this.metricTypes = Collections.unmodifiableSet(metricTypes); this.matrixTypes = Collections.unmodifiableSet(matrixTypes); }
public boolean isKronecker() { return name.equals(CC.getNameManager().getKroneckerName()); }
private static boolean isUnitaryMatrixOrOne(Tensor tensor, int unitaryMatrix) { if (tensor instanceof SimpleTensor) { int name = ((SimpleTensor) tensor).getName(); return name == unitaryMatrix || CC.getNameManager().isKroneckerOrMetric(name); } return false; }
readLock.lock(); try { int newNameId = generateNewName(); writeLock.lock(); try { registerDescriptor(nd); readLock.lock(); rLocked = true;
this.typeOfLeviCivitaIndices = IndicesUtils.getTypeEnum(leviCivita.getIndices().get(0)); final String leviCivitaName = CC.getNameManager().getNameDescriptor(leviCivita.getName()).getName(null);
/** * Returns {@code true} if specified tensor is a metric tensor * * @param t tensor * @return {@code true} if specified tensor is a metric tensor */ public boolean isMetric(SimpleTensor t) { return nameManager.isKroneckerOrMetric(t.getName()) && IndicesUtils.haveEqualStates(t.getIndices().get(0), t.getIndices().get(1)); }
/** * Returns {@code true} if specified tensor is a Kronecker tensor * * @param t tensor * @return {@code true} if specified tensor is a Kronecker tensor */ public boolean isKronecker(SimpleTensor t) { return nameManager.isKroneckerOrMetric(t.getName()) && !IndicesUtils.haveEqualStates(t.getIndices().get(0), t.getIndices().get(1)); }