/[escript]/trunk/escript/src/DataFactory.cpp
ViewVC logotype

Contents of /trunk/escript/src/DataFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (show annotations)
Wed Nov 9 02:02:19 2005 UTC (13 years, 7 months ago) by jgs
Original Path: trunk/escript/src/Data/DataFactory.cpp
File size: 2557 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

1 // $Id$
2 /*
3 ******************************************************************************
4 * *
5 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
6 * *
7 * This software is the property of ACcESS. No part of this code *
8 * may be copied in any form or by any means without the expressed written *
9 * consent of ACcESS. Copying, use or modification of this software *
10 * by any unauthorised person is illegal unless that person has a software *
11 * license agreement with ACcESS. *
12 * *
13 ******************************************************************************
14 */
15
16 #include "escript/Data/DataFactory.h"
17
18 #include <boost/python/object.hpp>
19 #include <boost/python/extract.hpp>
20
21 using namespace boost::python;
22
23 namespace escript {
24
25 Data
26 Scalar(double value,
27 const FunctionSpace& what,
28 bool expanded)
29 {
30 //
31 // an empty shape is a scalar
32 DataArrayView::ShapeType shape;
33 return Data(value,shape,what,expanded);
34 }
35
36 Data
37 Vector(double value,
38 const FunctionSpace& what,
39 bool expanded)
40 {
41 DataArrayView::ShapeType shape(1,what.getDomain().getDim());
42 return Data(value,shape,what,expanded);
43 }
44
45 Data
46 Tensor(double value,
47 const FunctionSpace& what,
48 bool expanded)
49 {
50 DataArrayView::ShapeType shape(2,what.getDomain().getDim());
51 return Data(value,shape,what,expanded);
52 }
53
54 Data
55 Tensor3(double value,
56 const FunctionSpace& what,
57 bool expanded)
58 {
59 DataArrayView::ShapeType shape(3,what.getDomain().getDim());
60 return Data(value,shape,what,expanded);
61 }
62
63 Data
64 Tensor4(double value,
65 const FunctionSpace& what,
66 bool expanded)
67 {
68 DataArrayView::ShapeType shape(4,what.getDomain().getDim());
69 return Data(value,shape,what,expanded);
70 }
71
72 Data
73 convertToData(const boost::python::object& value,
74 const FunctionSpace& what)
75 {
76 // first we try to extract a Data object from value
77 extract<Data> value_data(value);
78 if (value_data.check()) {
79 Data extracted_data=value_data();
80 if (extracted_data.isEmpty()) {
81 return extracted_data;
82 } else {
83 return Data(extracted_data,what);
84 }
85 } else {
86 return Data(value,what);
87 }
88 }
89
90 } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26