Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindPointsGSLIB::GetCode() does not return mfem::Array<unsigned int> #193

Closed
dreamer2368 opened this issue Aug 17, 2023 · 1 comment
Closed

Comments

@dreamer2368
Copy link

Hello,

I'm trying to use FindPointsGSLIB class within PyMFEM. One function I need to use is FindPointsGSLIB::GetCode(), which returns mfem::Array<unsigned int> according to the definition.

In PyMFEM, this function only returns a SwigPyObject that is not associated with any mfem class. For example, I added three lines of code on line 199 of miniapps/gslib/field_interp.py:

# Evaluate source grid function
interp_vals = mfem.Vector(nodes_cnt * tar_ncomp)
finder = mfem.FindPointsGSLIB()
finder.Setup(mesh_1)
finder.Interpolate(vxyz, func_source, interp_vals)

# Added lines
code_out = self.finder.GetCode()
print(type(code_out))
print(code_out.__dir__())

The resulting output is:

<class 'SwigPyObject'>
['__repr__', '__getattribute__', '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__int__', 'disown', 'acquire', 'own', 'append', 'next', '__doc__', '__hash__', '__new__', '__str__', '__setattr__', '__delattr__', '__init__', '__reduce_ex__', '__reduce__', '__subclasshook__', '__init_subclass__', '__format__', '__sizeof__', '__dir__', '__class__']

The output object does not have any attribute related to mfem::Array<unsigned int>. What is the proper way to use the function FindPointsGSLIB::GetCode()?

@sshiraiwa
Copy link
Member

Thank you for reporting this. It tooked (very) long to address this. This is is going to be resolved in PyMFEM4.6 (#204).

       - wrappers for Array<char>, Array<long long>, and Array<unsigned char> are added as
         uintArray, int8Array, int64Array.
       - Since Array<unsigned int> is not explicitly instantiated in Array.cpp, thus some
         method such as Print, Sort etc are not avaialbe. As a workaround, GetDataArray is
         added to return a numpy array view of underlying memory section.
             >>> v = mfem.uintArray(10)
             >>> v.GetDataArray()[:] = (1, 105, 20, 3, 50, 4, 2, 15, 8)
             >>> v.GetDataArray()[:] = np.sort(a.GetDataArray())
             >>> v.ToList()
              [1, 2, 3, 4, 8, 15, 20, 50, 105, 300]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants