~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to dolfin/swig/mesh/post.i

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
}
76
76
 
77
77
//-----------------------------------------------------------------------------
 
78
// Extend SubDomain
 
79
//-----------------------------------------------------------------------------
 
80
%pythoncode
 
81
%{
 
82
_subdomain_mark_doc_string = SubDomain._mark.__doc__
 
83
%}
 
84
 
 
85
%extend dolfin::SubDomain {
 
86
%pythoncode
 
87
%{
 
88
# NOTE: This is a hardcoded check, which rely on SubDomain::mark only taking
 
89
# a MeshFunction as its first argument when mark is called with two arguments
 
90
def mark(self, *args):
 
91
    import common
 
92
    if len(args) == 2 and not isinstance(args[0], \
 
93
                    (MeshFunctionSizet, MeshFunctionInt,
 
94
                     MeshFunctionDouble, MeshFunctionBool)):
 
95
        common.dolfin_error("dolfin.cpp.mesh.py",
 
96
                            "mark MeshFunction",
 
97
                            "Expected a MeshFunction of type \"size_t\", \"int\", \"double\" or \"bool\"")
 
98
            
 
99
    self._mark(*args)
 
100
 
 
101
%}
 
102
}
 
103
 
 
104
%pythoncode
 
105
%{
 
106
SubDomain.mark.__func__.__doc__ = _subdomain_mark_doc_string
 
107
del _subdomain_mark_doc_string
 
108
%}
 
109
 
 
110
//-----------------------------------------------------------------------------
78
111
// Macro for declaring MeshFunctions
79
112
//-----------------------------------------------------------------------------
80
113
%define DECLARE_MESHFUNCTION(TYPE, TYPENAME)
84
117
// Extend MeshFunction interface for get and set items
85
118
%extend dolfin::MeshFunction<TYPE>
86
119
{
87
 
  TYPE __getitem__(unsigned int i) { return (*self)[i]; }
88
 
  void __setitem__(unsigned int i, TYPE val) { (*self)[i] = val; }
 
120
  TYPE __getitem__(std::size_t i) { return (*self)[i]; }
 
121
  void __setitem__(std::size_t i, TYPE val) { (*self)[i] = val; }
89
122
 
90
123
  TYPE __getitem__(dolfin::MeshEntity& e) { return (*self)[e]; }
91
124
  void __setitem__(dolfin::MeshEntity& e, TYPE val) { (*self)[e] = val; }
109
142
%template(FaceFunction ## TYPENAME) dolfin::FaceFunction<TYPE>;
110
143
%template(FacetFunction ## TYPENAME) dolfin::FacetFunction<TYPE>;
111
144
%template(VertexFunction ## TYPENAME) dolfin::VertexFunction<TYPE>;
 
145
 
 
146
//-----------------------------------------------------------------------------
 
147
// Modifying the interface of Hierarchical
 
148
//-----------------------------------------------------------------------------
 
149
%pythoncode %{
 
150
HierarchicalMeshFunction ## TYPENAME.leaf_node = HierarchicalMeshFunction ## TYPENAME._leaf_node
 
151
HierarchicalMeshFunction ## TYPENAME.root_node = HierarchicalMeshFunction ## TYPENAME._root_node
 
152
HierarchicalMeshFunction ## TYPENAME.child = HierarchicalMeshFunction ## TYPENAME._child
 
153
HierarchicalMeshFunction ## TYPENAME.parent = HierarchicalMeshFunction ## TYPENAME._parent
 
154
%}
112
155
%enddef
113
156
 
114
157
 
115
158
//-----------------------------------------------------------------------------
116
159
// Run Macros to declare the different MeshFunctions
117
160
//-----------------------------------------------------------------------------
 
161
DECLARE_MESHFUNCTION(std::size_t, Sizet)
118
162
DECLARE_MESHFUNCTION(unsigned int, UInt)
119
163
DECLARE_MESHFUNCTION(int, Int)
120
164
DECLARE_MESHFUNCTION(double, Double)
128
172
  *Arguments*
129
173
    tp (str)
130
174
      String defining the type of the MeshFunction
131
 
      Allowed: 'int', 'uint', 'double', and 'bool'
 
175
      Allowed: 'int', 'size_t', 'uint', 'double', and 'bool'
132
176
    mesh (_Mesh_)
133
177
      A DOLFIN mesh.
134
178
      Optional.
149
193
            return MeshFunctionInt(*args)
150
194
        if tp == "uint":
151
195
            return MeshFunctionUInt(*args)
 
196
        elif tp == "size_t":
 
197
            return MeshFunctionSizet(*args)
152
198
        elif tp == "double":
153
199
            return MeshFunctionDouble(*args)
154
200
        elif tp == "bool":
167
213
            return eval("%sInt(mesh, value)"%MeshType)
168
214
        if tp == "uint":
169
215
            return eval("%sUInt(mesh, value)"%MeshType)
 
216
        if tp == "size_t":
 
217
            return eval("%sSizet(mesh, value)"%MeshType)
170
218
        elif tp == "double":
171
219
            return eval("%sDouble(mesh, float(value))"%MeshType)
172
220
        elif tp == "bool":
227
275
//-----------------------------------------------------------------------------
228
276
// Run macros for declaring MeshValueCollection
229
277
//-----------------------------------------------------------------------------
 
278
DECLARE_MESHVALUECOLLECTION(std::size_t, Sizet)
230
279
DECLARE_MESHVALUECOLLECTION(unsigned int, UInt)
231
280
DECLARE_MESHVALUECOLLECTION(int, Int)
232
281
DECLARE_MESHVALUECOLLECTION(double, Double)
240
289
  *Arguments*
241
290
      tp (str)
242
291
         String defining the type of the MeshValueCollection
243
 
          Allowed: 'int', 'uint', 'double', and 'bool'
 
292
          Allowed: 'int', 'uint', 'size_t', 'double', and 'bool'
244
293
      dim (uint)
245
294
          The topological dimension of the MeshValueCollection.
246
295
          Optional.
267
316
            return MeshValueCollectionInt(*args)
268
317
        if tp == "uint":
269
318
            return MeshValueCollectionUInt(*args)
 
319
        elif tp == "size_t":
 
320
            return MeshValueCollectionSizet(*args)
270
321
        elif tp == "double":
271
322
            return MeshValueCollectionDouble(*args)
272
323
        elif tp == "bool":
358
409
 
359
410
%}
360
411
}
 
412
 
 
413
//-----------------------------------------------------------------------------
 
414
// Modifying the interface of Hierarchical
 
415
//-----------------------------------------------------------------------------
 
416
%pythoncode %{
 
417
HierarchicalMesh.leaf_node = HierarchicalMesh._leaf_node
 
418
HierarchicalMesh.root_node = HierarchicalMesh._root_node
 
419
HierarchicalMesh.child = HierarchicalMesh._child
 
420
HierarchicalMesh.parent = HierarchicalMesh._parent
 
421
%}
 
422