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

Attribute sets dev #219

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/ex5p.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def EvalValue(self, x):
u_sock << "parallel " << num_procs << " " << myid << "\n"
u_sock.precision(8)
u_sock << "solution\n" << pmesh << u << "window_title 'Velocity'\n"
MPI.Barrier()
MPI.COMM_WORLD.Barrier()
p_sock = mfem.socketstream("localhost", 19916)
p_sock << "parallel " << num_procs << " " << myid << "\n"
p_sock.precision(8)
Expand Down
31 changes: 31 additions & 0 deletions mfem/_par/arrays_by_name.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
%module(package="mfem._par") arrays_by_name
%{
#include "mfem.hpp"
#include "numpy/arrayobject.h"
#include "../common/io_stream.hpp"
#include "../common/pyoperator.hpp"
#include "../common/pycoefficient.hpp"
#include "../common/pyintrules.hpp"
%}

%include "../common/existing_mfem_headers.i"

#ifdef FILE_EXISTS_GENERAL_ARRAYS_BY_NAME
%init %{
import_array();
%}

%include "exception.i"
%include "../common/exception.i"

%import "array.i"
%import "../common/io_stream_typemap.i"
OSTREAM_TYPEMAP(std::ostream&)
ISTREAM_TYPEMAP(std::istream&)

%include "general/arrays_by_name.hpp"
%ignore mfem::ArraysByName::begin;
%ignore mfem::ArraysByName::end;

%template(intArraysByName) mfem::ArraysByName<int>;
#endif
29 changes: 29 additions & 0 deletions mfem/_par/attribute_sets.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%module(package="mfem._par") attribute_sets
%{
#include "mfem.hpp"
#include "numpy/arrayobject.h"
#include "../common/io_stream.hpp"
#include "../common/pyoperator.hpp"
#include "../common/pycoefficient.hpp"
#include "../common/pyintrules.hpp"
%}

%include "../common/existing_mfem_headers.i"
#ifdef FILE_EXISTS_MESH_ATTRIBUTE_SETS

%init %{
import_array();
%}

%include "exception.i"
%include "../common/exception.i"

%import "array.i"
%import "arrays_by_name.i"
%import "../common/io_stream_typemap.i"
OSTREAM_TYPEMAP(std::ostream&)
ISTREAM_TYPEMAP(std::istream&)

%include "mesh/attribute_sets.hpp"

#endif
21 changes: 13 additions & 8 deletions mfem/_par/mesh.i
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import_array();

%import "matrix.i"
%import "array.i"
%import "attribute_sets.i"
%import "sort_pairs.i"
%import "ncmesh.i"
%import "vector.i"
Expand Down Expand Up @@ -217,30 +218,34 @@ def GetFaceElements(self, Face):
return Elem1.value(), Elem2.value()
%}
%feature("shadow") mfem::Mesh::GetElementTransformation %{
def GetElementTransformation(self, i):
def GetElementTransformation(self, i, Tr=None):
from mfem.par import IsoparametricTransformation
Tr = IsoparametricTransformation()
if Tr is None:
Tr = IsoparametricTransformation()
$action(self, i, Tr)
return Tr
%}
%feature("shadow") mfem::Mesh::GetBdrElementTransformation %{
def GetBdrElementTransformation(self, i):
def GetBdrElementTransformation(self, i, Tr=None):
from mfem.par import IsoparametricTransformation
Tr = IsoparametricTransformation()
if Tr is None:
Tr = IsoparametricTransformation()
$action(self, i, Tr)
return Tr
%}
%feature("shadow") mfem::Mesh::GetFaceTransformation %{
def GetFaceTransformation(self, i):
def GetFaceTransformation(self, i, Tr=None):
from mfem.par import IsoparametricTransformation
Tr = IsoparametricTransformation()
if Tr is None:
Tr = IsoparametricTransformation()
$action(self, i, Tr)
return Tr
%}
%feature("shadow") mfem::Mesh::GetEdgeTransformation %{
def GetEdgeTransformation(self, i):
def GetEdgeTransformation(self, i, Tr=None):
from mfem.par import IsoparametricTransformation
Tr = IsoparametricTransformation()
if Tr is None:
Tr = IsoparametricTransformation()
$action(self, i, Tr)
return Tr
%}
Expand Down
4 changes: 2 additions & 2 deletions mfem/_par/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def get_extensions():
"tmop", "tmop_amr", "tmop_tools", "qspace", "qfunction",
"quadinterpolator", "quadinterpolator_face",
"submesh", "transfermap", "staticcond","sidredatacollection",
"psubmesh", "ptransfermap", "enzyme"]

"psubmesh", "ptransfermap", "enzyme",
"attribute_sets", "arrays_by_name"]
if add_pumi == '1':
from setup_local import puminc, pumilib
modules.append("pumi")
Expand Down
31 changes: 31 additions & 0 deletions mfem/_ser/arrays_by_name.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
%module(package="mfem._ser") arrays_by_name
%{
#include "mfem.hpp"
#include "numpy/arrayobject.h"
#include "../common/io_stream.hpp"
#include "../common/pyoperator.hpp"
#include "../common/pycoefficient.hpp"
#include "../common/pyintrules.hpp"
%}

%include "../common/existing_mfem_headers.i"

#ifdef FILE_EXISTS_GENERAL_ARRAYS_BY_NAME
%init %{
import_array();
%}

%include "exception.i"
%include "../common/exception.i"

%import "array.i"
%import "../common/io_stream_typemap.i"
OSTREAM_TYPEMAP(std::ostream&)
ISTREAM_TYPEMAP(std::istream&)

%include "general/arrays_by_name.hpp"
%ignore mfem::ArraysByName::begin;
%ignore mfem::ArraysByName::end;

%template(intArraysByName) mfem::ArraysByName<int>;
#endif
29 changes: 29 additions & 0 deletions mfem/_ser/attribute_sets.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%module(package="mfem._ser") attribute_sets
%{
#include "mfem.hpp"
#include "numpy/arrayobject.h"
#include "../common/io_stream.hpp"
#include "../common/pyoperator.hpp"
#include "../common/pycoefficient.hpp"
#include "../common/pyintrules.hpp"
%}

%include "../common/existing_mfem_headers.i"
#ifdef FILE_EXISTS_MESH_ATTRIBUTE_SETS

%init %{
import_array();
%}

%include "exception.i"
%include "../common/exception.i"

%import "array.i"
%import "arrays_by_name.i"
%import "../common/io_stream_typemap.i"
OSTREAM_TYPEMAP(std::ostream&)
ISTREAM_TYPEMAP(std::istream&)

%include "mesh/attribute_sets.hpp"

#endif
21 changes: 13 additions & 8 deletions mfem/_ser/mesh.i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still trying to better understand SWIG so I apologize if these are basic questions:

  • Does having import statements inside of the function affect performance? (is it okay to move ...import IsoparametricTransformation outside of the functions)?
  • Since these are all almost the same function can we have one function, e.g. GetTransformation(), and all these other functions just compose on-top of it? Not sure how different this is in a *.i vs *.py file.
  • What does $action(self, i, Tr) do?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps moving the import statement out of the functions may help performance issues noted in #216

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from https://www.swig.org/Doc4.2/SWIGDocumentation.html.
$action** is will be replaced by the call to the C/C++ proper method. Note that this does not include the arguments to the C/C++ method.
I will see what can be done with import statement.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import_array();
%import "matrix.i"
%import "mem_manager.i"
%import "array.i"
%import "attribute_sets.i"
%import "sort_pairs.i"
%import "ncmesh.i"
%import "vector.i"
Expand Down Expand Up @@ -222,30 +223,34 @@ def GetFaceElements(self, Face):
return Elem1.value(), Elem2.value()
%}
%feature("shadow") mfem::Mesh::GetElementTransformation %{
def GetElementTransformation(self, i):
def GetElementTransformation(self, i, Tr=None):
from mfem.ser import IsoparametricTransformation
Tr = IsoparametricTransformation()
if Tr is None:
Tr = IsoparametricTransformation()
$action(self, i, Tr)
return Tr
%}
%feature("shadow") mfem::Mesh::GetBdrElementTransformation %{
def GetBdrElementTransformation(self, i):
def GetBdrElementTransformation(self, i, Tr=None):
from mfem.ser import IsoparametricTransformation
Tr = IsoparametricTransformation()
if Tr is None:
Tr = IsoparametricTransformation()
$action(self, i, Tr)
return Tr
%}
%feature("shadow") mfem::Mesh::GetFaceTransformation %{
def GetFaceTransformation(self, i):
def GetFaceTransformation(self, i, Tr=None):
from mfem.ser import IsoparametricTransformation
Tr = IsoparametricTransformation()
if Tr is None:
Tr = IsoparametricTransformation()
$action(self, i, Tr)
return Tr
%}
%feature("shadow") mfem::Mesh::GetEdgeTransformation %{
def GetEdgeTransformation(self, i):
def GetEdgeTransformation(self, i, Tr=None):
from mfem.ser import IsoparametricTransformation
Tr = IsoparametricTransformation()
if Tr is None:
Tr = IsoparametricTransformation()
$action(self, i, Tr)
return Tr
%}
Expand Down
3 changes: 2 additions & 1 deletion mfem/_ser/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def get_extensions():
"tmop", "tmop_amr", "tmop_tools", "qspace", "qfunction",
"quadinterpolator", "quadinterpolator_face",
"submesh", "transfermap", "staticcond",
"sidredatacollection", "enzyme"]
"sidredatacollection", "enzyme",
"attribute_sets", "arrays_by_name"]

if add_cuda == '1':
from setup_local import cudainc
Expand Down
4 changes: 4 additions & 0 deletions mfem/common/bilininteg_ext.i
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ namespace mfem {
self._coeff = args
%}

%pythonappend ElasticityComponentIntegrator::ElasticityComponentIntegrator %{
self._coeff = parent_
%}

%pythonappend DGTraceIntegrator::DGTraceIntegrator %{
self._coeff = args
%}
Expand Down
Loading