@@ -636,7 +636,9 @@ def mass(
636636
637637 Examples
638638 --------
639- >>> mass = mapdl.math.mass()
639+ >>> import ansys.math.core.math as pymath
640+ >>> mm = pymath.AnsMath()
641+ >>> mass = mm.mass()
640642 >>> mass
641643 AnsMath matrix 60 x 60
642644
@@ -678,7 +680,9 @@ def damp(
678680
679681 Examples
680682 --------
681- >>> ans_mat = mapdl.math.damp()
683+ >>> import ansys.math.core.math as pymath
684+ >>> mm = pymath.AnsMath()
685+ >>> ans_mat = mm.damp()
682686 >>> ans_mat
683687 AnsMath Matrix 60 x 60
684688
@@ -906,7 +910,18 @@ def sparse(self, mat, thresh="", **kwargs):
906910 kwargs .setdefault ("mute" , True )
907911 self ._mapdl .run (f"*COMP,{ mat .id } ,SPARSE,{ thresh } " , ** kwargs )
908912
909- def eigs (self , nev , k , m = None , c = None , phi = None , algo = None , fmin = None , fmax = None ):
913+ def eigs (
914+ self ,
915+ nev ,
916+ k ,
917+ m = None ,
918+ c = None ,
919+ phi = None ,
920+ algo = None ,
921+ fmin = None ,
922+ fmax = None ,
923+ cpxmod = None ,
924+ ):
910925 """Solve an eigenproblem.
911926
912927 Parameters
@@ -937,6 +952,8 @@ def eigs(self, nev, k, m=None, c=None, phi=None, algo=None, fmin=None, fmax=None
937952 fmin = ""
938953 if not fmax :
939954 fmax = ""
955+ if not cpxmod :
956+ cpxmod = ""
940957
941958 cid = ""
942959 if not c :
@@ -951,7 +968,7 @@ def eigs(self, nev, k, m=None, c=None, phi=None, algo=None, fmin=None, fmax=None
951968
952969 self ._mapdl .run ("/SOLU" , mute = True )
953970 self ._mapdl .run ("antype,modal" , mute = True )
954- self ._mapdl .run (f"modopt,{ algo } ,{ nev } ,{ fmin } ,{ fmax } " , mute = True )
971+ self ._mapdl .run (f"modopt,{ algo } ,{ nev } ,{ fmin } ,{ fmax } , { cpxmod } " , mute = True )
955972 ev = self .vec ()
956973
957974 phistr = "" if not phi else phi .id
@@ -1355,6 +1372,53 @@ def axpy(self, obj, val1, val2):
13551372 self ._mapdl .run (f"*AXPY,{ val1 } ,0,{ obj .id } ,{ val2 } ,0,{ self .id } " , mute = True )
13561373 return self
13571374
1375+ def kron (self , obj ):
1376+ """Calculates the Kronecker product of two matrices/vectors
1377+
1378+ Parameters
1379+ ----------
1380+ obj : ``AnsVec`` or ``AnsMat``
1381+ AnsMath object.
1382+
1383+ Returns
1384+ -------
1385+ ``AnsMat`` or ``AnsVec``
1386+ Kronecker product between the two matrices/vectors.
1387+
1388+ .. note::
1389+ Requires at least MAPDL version 2023R2.
1390+
1391+ Examples
1392+ --------
1393+ >>> import ansys.math.core.math as pymath
1394+ >>> mm = pymath.AnsMath()
1395+ >>> m1 = mm.rand(3, 3)
1396+ >>> m2 = mm.rand(4,2)
1397+ >>> res = m1.kron(m2)
1398+ """
1399+
1400+ mapdl_version = self ._mapdl .version
1401+ if mapdl_version < 23.2 : # pragma: no cover
1402+ raise VersionError ("``kron`` requires MAPDL version 2023R2" )
1403+
1404+ if not isinstance (obj , AnsMath ):
1405+ raise TypeError ("Must be an AnsMath object." )
1406+
1407+ if not isinstance (self , (AnsMat , AnsVec )):
1408+ raise TypeError (f"Kron product aborted: Unknown obj type ({ self .type } )" )
1409+ if not isinstance (obj , (AnsMat , AnsVec )):
1410+ raise TypeError (f"Kron product aborted: Unknown obj type ({ obj .type } )" )
1411+
1412+ name = id_generator () # internal name of the new vector/matrix
1413+ # perform the Kronecker product
1414+ self ._mapdl .run (f"*KRON,{ self .id } ,{ obj .id } ,{ name } " )
1415+
1416+ if isinstance (self , AnsVec ) and isinstance (obj , AnsVec ):
1417+ objout = AnsVec (name , self ._mapdl )
1418+ else :
1419+ objout = AnsMat (name , self ._mapdl )
1420+ return objout
1421+
13581422 def __add__ (self , op2 ):
13591423 if not hasattr (op2 , "id" ):
13601424 raise TypeError ("The object to be added must be an AnsMath object." )
@@ -1383,8 +1447,20 @@ def __isub__(self, op):
13831447 return self .axpy (op , - 1 , 1 )
13841448
13851449 def __imul__ (self , val ):
1386- self ._mapdl ._log .info ("Call MAPDL to scale the object." )
1387- self ._mapdl .run (f"*SCAL,{ self .id } ,{ val } " , mute = True )
1450+ mapdl_version = self ._mapdl .version
1451+ self ._mapdl ._log .info ("Call MAPDL to scale the object" )
1452+
1453+ if isinstance (val , AnsVec ):
1454+ if mapdl_version < 23.2 : # pragma: no cover
1455+ raise VersionError ("Scaling by a vector requires MAPDL version 2023R2 or superior." )
1456+ else :
1457+ self ._mapdl ._log .info (f"Scaling ({ self .type } ) by a vector" )
1458+ self ._mapdl .run (f"*SCAL,{ self .id } ,{ val .id } " , mute = False )
1459+ elif isinstance (val , (int , float )):
1460+ self ._mapdl .run (f"*SCAL,{ self .id } ,{ val } " , mute = True )
1461+ else :
1462+ raise TypeError (f"The provided type { type (val )} is not supported." )
1463+
13881464 return self
13891465
13901466 def __itruediv__ (self , val ):
@@ -1433,10 +1509,24 @@ def __repr__(self):
14331509 return f"AnsMath vector size { self .size } "
14341510
14351511 def __getitem__ (self , num ):
1512+ info = self ._mapdl ._data_info (self .id )
1513+ dtype = ANSYS_VALUE_TYPE [info .stype ]
14361514 if num < 0 :
1437- raise ValueError ("Negative indices are not permitted." )
1438- self ._mapdl .run (f"pyval={ self .id } ({ num + 1 } )" , mute = True )
1439- return self ._mapdl .scalar_param ("pyval" )
1515+ raise ValueError ("Negative indices not permitted" )
1516+
1517+ self ._mapdl .run (f"pyval_={ self .id } ({ num + 1 } )" , mute = True )
1518+ item_val = self ._mapdl .scalar_param ("pyval_" )
1519+
1520+ if MYCTYPE [dtype ].upper () in ["C" , "Z" ]:
1521+ self ._mapdl .run (f"pyval_img_={ self .id } ({ num + 1 } ,2)" , mute = True )
1522+ img_val = self ._mapdl .scalar_param ("pyval_img_" )
1523+ item_val = item_val + img_val * 1j
1524+
1525+ # Clean parameters
1526+ self ._mapdl .run ("item_val =" )
1527+ self ._mapdl .run ("pyval_img_=" )
1528+
1529+ return item_val
14401530
14411531 def __mul__ (self , vec ):
14421532 """Return the element-wise product with another AnsMath vector.
@@ -1507,8 +1597,8 @@ def asarray(self, dtype=None) -> np.ndarray:
15071597 ----------
15081598 dtype : numpy.dtype, optional
15091599 NumPy data type to upload the array as. The options are `np.double <numpy.double>`_,
1510- `np.int32 <numpy.int32>`_, and `np.int64 <numpy.int64>`_. The default is the current array
1511- type.
1600+ `np.int32 <numpy.int32>`_, and `np.int64 <numpy.int64>`_. The default is the current
1601+ array type.
15121602
15131603 Returns
15141604 -------
0 commit comments