Skip to content

Commit

Permalink
Added giveVal and write methods to tensor data type
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaHobbyist committed Jun 7, 2024
1 parent d2efed5 commit d927d85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions pyvnt/Reference/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ def schur(self, t: Self) -> Self:
self.yx()*t.yx(), self.yy()*t.yy(), self.yz()*t.yz(),
self.zx()*t.zx(), self.zy()*t.zy(), self.zz()*t.zz()])

def giveVal(self):
'''
Returns the tensor value
'''
res = (self.xx(), self.xy(), self.xz(),
self.yx(), self.yy(), self.yz(),
self.zx(), self.zy(), self.zz())
return res

def writeOut(self, file):
'''
Writes the tensor value to a file
Parameters:
file: The file object to write the value to
'''
file.write(f"{self.giveVal()}")

def __repr__(self):
return f"PropertyTensor(name = {self._ValueProperty__name}, xx = {self.xx()}, xy = {self.xy()}, xz = {self.xz()}, yx = {self.yx()}, yy = {self.yy()}, yz = {self.yz()}, zx = {self.zx()}, zy = {self.zy()}, zz = {self.zz()})"

Expand Down
6 changes: 5 additions & 1 deletion tests/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ def test_row(self):
def test_col(self):
assert str(self.tprop1.col(1)) == f"PropertyVector(name = val1_col, x = 1, y = 4, z = 7)"
assert str(self.tprop1.col(2)) == f"PropertyVector(name = val1_col, x = 2, y = 5, z = 8)"
assert str(self.tprop1.col(3)) == f"PropertyVector(name = val1_col, x = 3, y = 6, z = 9)"
assert str(self.tprop1.col(3)) == f"PropertyVector(name = val1_col, x = 3, y = 6, z = 9)"

def test_giveVal(self):
assert self.tprop1.giveVal() == (1, 2, 3, 4, 5, 6, 7, 8, 9)
assert self.tprop2.giveVal() == (4, 5, 6, 7, 8, 9, 1, 2, 3)

0 comments on commit d927d85

Please sign in to comment.