Skip to content

Commit

Permalink
Fixed the name of wrapped Array2D<MFEM object *> object names
Browse files Browse the repository at this point in the history
  • Loading branch information
sshiraiwa committed Oct 5, 2024
1 parent ed7d848 commit 5e81cd5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 64 deletions.
6 changes: 3 additions & 3 deletions mfem/_par/array.i
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ IGNORE_ARRAY_METHODS(mfem::DenseMatrix *)
IGNORE_ARRAY_METHODS(mfem::SparseMatrix *)
IGNORE_ARRAY_METHODS(mfem::HypreParMatrix *)

%template(densematArray2D) mfem::Array2D<mfem::DenseMatrix *>;
%template(sparsematArray2D) mfem::Array2D<mfem::SparseMatrix *>;
%template(hypreparmatArray2D) mfem::Array2D<mfem::HypreParMatrix *>;
%template(DenseMatrixArray2D) mfem::Array2D<mfem::DenseMatrix *>;
%template(SparseMatrixArray2D) mfem::Array2D<mfem::SparseMatrix *>;
%template(HypreParMatrixArray2D) mfem::Array2D<mfem::HypreParMatrix *>;

8 changes: 2 additions & 6 deletions mfem/_ser/array.i
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,5 @@ INSTANTIATE_ARRAY2(Array<int> *, Array<int>, intArray, 1)
IGNORE_ARRAY_METHODS(mfem::DenseMatrix *)
IGNORE_ARRAY_METHODS(mfem::SparseMatrix *)

%template(densematArray2D) mfem::Array2D<mfem::DenseMatrix *>;
%template(sparsematArray2D) mfem::Array2D<mfem::SparseMatrix *>;
//%template(hypreparmatArray2D) mfem::Array2D<mfem::HypreParMatrix *>;



%template(DenseMatrixArray2D) mfem::Array2D<mfem::DenseMatrix *>;
%template(SparseMatrixArray2D) mfem::Array2D<mfem::SparseMatrix *>;
3 changes: 2 additions & 1 deletion mfem/common/array_instantiation_macro.i
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
%define INSTANTIATE_ARRAY2(XXX, YYY, ZZZ, USEPTR)
#if USEPTR == 1
%template(##ZZZ##Ptr##Array) mfem::Array<mfem::XXX>;
//%template(##ZZZ##Ptr##Array) mfem::Array<mfem::XXX>;
%template(##ZZZ##Array) mfem::Array<mfem::XXX>;
#else
%template(##ZZZ##Array) mfem::Array<mfem::XXX>;
#endif
Expand Down
36 changes: 0 additions & 36 deletions mfem/common/array_setitem_typemap.i

This file was deleted.

29 changes: 15 additions & 14 deletions test/test_coefficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,48 @@
def test():
dim = 3
max_attr = 5
sigma_attr_coefs = mfem.MatrixCoefficientPtrArray(max_attr)
sigma_attr_coefs = mfem.MatrixCoefficientArray(max_attr)
sigma_attr = mfem.intArray(max_attr)


tensors = [mfem.DenseMatrix(np.ones((3,3))*i) for i in range(max_attr)]
tensor_coefs = [mfem.MatrixConstantCoefficient(mat) for mat in tensors]

sigma_array = mfem.MatrixCoefficientArray(tensor_coefs)
sigma_attr = mfem.intArray([1,2,3,4,5])
sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, sigma_array, False)

for ti, tensor in enumerate(tensors):
# add matrix coefficient to list
print(ti)
xx = mfem.MatrixConstantCoefficient(tensor)
sigma_attr_coefs[ti] = xx
sigma_attr[ti] = ti+1


# Create PW Matrix Coefficient
sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, sigma_attr_coefs, False)
sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, tensor_coefs, False)

tensor_coefs = mfem.MatrixCoefficientPtrArray([mfem.MatrixConstantCoefficient(mat) for mat in tensors])
sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, tensor_coefs, False)
tensor_coefs = mfem.MatrixCoefficientArray([mfem.MatrixConstantCoefficient(mat) for mat in tensors])
sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, tensor_coefs, False)

data = tensor_coefs.GetData()
tensor_coefs2 = mfem.MatrixCoefficientPtrArray(data, 5, False)
tensor_coefs2 = mfem.MatrixCoefficientArray(data, 5, False)
sigmaCoef = mfem.PWMatrixCoefficient(dim, sigma_attr, tensor_coefs2, False)

print("exiting")





if __name__ == '__main__':
import tracemalloc

tracemalloc.start()

for i in range(10):
print(tracemalloc.get_traced_memory())

for i in range(3000):
test()
print(tracemalloc.get_traced_memory())
print(tracemalloc.get_traced_memory())
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
top_stats = snapshot.statistics('lineno')
for stat in top_stats[:10]:
print(stat)

6 changes: 3 additions & 3 deletions test/test_intrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def run_test():

irs = [mfem.IntRules.Get(i, 2) for i in range(mfem.Geometry.NumGeom)]

rulearray = mfem.IntegrationRulePtrArray(irs)
rulearray = mfem.IntegrationRuleArray(irs)

ir2 = rulearray[2]
points3 = [(ir2[i].x, ir2[i].y) for i in range(ir2.GetNPoints())]
assert (points3 == points), "IntegrationPointArray coords does not agree (check 2)."

# check slice of IntegrationRulePtrArray
# check slice of IntegrationRuleArray
rulearray2 = rulearray[:5]
assert not rulearray2.OwnsData(), "subarray should not own data"
ir2 = rulearray2[2]
Expand All @@ -67,7 +67,7 @@ def run_test():

# create it from a pointer array
data = rulearray2.GetData() # this returns <Swig Object of type 'mfem::IntegrationRule **'>
rulearray3 = mfem.IntegrationRulePtrArray((data, 5))
rulearray3 = mfem.IntegrationRuleArray((data, 5))
ir2 = rulearray3[2]
points3 = [(ir2[i].x, ir2[i].y) for i in range(ir2.GetNPoints())]
assert (points3 == points), "IntegrationPointArray coords does not agree (check 3)."
Expand Down
2 changes: 1 addition & 1 deletion test/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run_test():
a.Print_HYPRE("vector_hypre.dat")


x = mfem.VectorPtrArray([a]*3)
x = mfem.VectorArray([a]*3)
x[2].Print()

if __name__=='__main__':
Expand Down

0 comments on commit 5e81cd5

Please sign in to comment.