Source code for Muscat.FE.WeakForms.ASTWeakForm

# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#

import Muscat.FE.WeakForms.RPNWeakForm as rpnwf
from Muscat.FE.WeakForms.Operators import NumericalOperators


[docs] class ASTWeakForm: def __init__(self, rpnElem: rpnwf.RPNElement): self.name = rpnElem.name self.value = rpnElem.value self.der1 = rpnElem.der1 self.der2 = rpnElem.der2 self.op: NumericalOperators = rpnElem.type self.leftChild: ASTWeakForm = None self.rightChild: ASTWeakForm = None
[docs] def swapChildren(self): tmp = self.leftChild self.leftChild = self.rightChild self.rightChild = tmp
[docs] def getDepth(self): leftDepth = self.leftChild.getDepth() if self.leftChild is not None else 0 rightDepth = self.rightChild.getDepth() if self.rightChild is not None else 0 return 1 + max(leftDepth, rightDepth)
[docs] def nodes(self, curid=1): # -> List[Tuple[int, ASTWeakForm]] cur = [(curid, self)] if self.leftChild is not None: cur = cur + self.leftChild.nodes(curid * 2) if self.rightChild is not None: cur = cur + self.rightChild.nodes(curid * 2 + 1) return cur
def __str__(self, tabs=0): s = "" TABLEN = 5 s = s + " "*((tabs - 1)* TABLEN) if tabs != 0: s = s + "|" s = s + "-"*(TABLEN - 1) s = s + f"{self.op}" if self.value is not None: s = s + f"(value: {str(self.value)})" if self.name is not None: s = s + f"(name: " if self.der1>=0: s = s + f"d {str(self.name)})/ d {['x','y','z'][self.der1]}" else: s = s + f"{str(self.name)})" s = s + "\n" if self.leftChild is not None: s = s + self.leftChild.__str__(tabs + 1) if self.rightChild is not None: s = s + self.rightChild.__str__(tabs + 1) return s
[docs] def CheckIntegrity(GUI: bool = False): return "OK"
if __name__ == "__main__": print(CheckIntegrity(GUI=True)) # pragma: no cover