SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArrayMathEngine.h
Go to the documentation of this file.
1 //
2 // For more information, please see: http://software.sci.utah.edu
3 //
4 // The MIT License
5 //
6 // Copyright (c) 2009 Scientific Computing and Imaging Institute,
7 // University of Utah.
8 //
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 // DEALINGS IN THE SOFTWARE.
27 //
28 
29 #ifndef CORE_PARSER_ARRAYMATHENGINE_H
30 #define CORE_PARSER_ARRAYMATHENGINE_H 1
31 
34 #include <Core/Parser/Parser.h>
35 
36 // Include files needed for Windows
37 #include <Core/Parser/share.h>
38 
39 namespace SCIRun {
40 
42 {
43  public:
44  // Classes for storing data on output variables
46  public:
47  std::string array_name_;
48  std::string field_name_;
50  std::string output_datatype_;
52  };
53 
55  public:
56  std::string array_name_;
57  std::string field_name_;
59  };
60 
61  class OutputMatrix {
62  public:
63  std::string array_name_;
64  std::string matrix_name_;
67  };
68 
70  public:
71  std::string array_name_;
72  std::string bool_array_name_;
73  std::vector<bool>* bool_array_;
74  };
75 
77  public:
78  std::string array_name_;
79  std::string int_array_name_;
80  std::vector<int>* int_array_;
81  };
82 
84  public:
85  std::string array_name_;
86  std::string double_array_name_;
87  std::vector<double>* double_array_;
88  };
89 
90  public:
91  // CALLS TO THIS CLASS SHOULD BE MADE IN THE ORDER
92  // THAT THE FUNCTIONS ARE GIVEN HERE
93 
94  // Make sure it starts with a clean definition file
95  NewArrayMathEngine() { clear(); pr_ = &def_pr_; }
96 
97  void setLogger(Core::Logging::LegacyLoggerInterface* logger) { pr_ = logger; }
98 
99  // Generate inputs for field data and field data properties
100  bool add_input_fielddata(const std::string& name,
101  FieldHandle field);
102  bool add_input_fielddata_location(const std::string& name,
103  FieldHandle field);
104  bool add_input_fielddata_coordinates(const std::string& xname,
105  const std::string& yname,
106  const std::string& zname,
107  FieldHandle field);
108  bool add_input_fielddata_location(const std::string& name,
109  FieldHandle field,
110  int basis_order);
111  bool add_input_fielddata_coordinates(const std::string& xname,
112  const std::string& yname,
113  const std::string& zname,
114  FieldHandle field,
115  int basis_order);
116  bool add_input_fielddata_element(const std::string& name,
117  FieldHandle field);
118  bool add_input_fielddata_element(const std::string& name,
119  FieldHandle field,
120  int basis_order);
121 
122  bool add_input_fieldnodes(const std::string& name,
123  FieldHandle field);
124  bool add_input_fieldnodes_coordinates(const std::string& xname,
125  const std::string& yname,
126  const std::string& zname,
127  FieldHandle field);
128 
129  // Generate input matrices
130  bool add_input_matrix(const std::string& name,
132 
133  bool add_input_fullmatrix(const std::string& name,
135 
136  // Generate input arrays
137  bool add_input_bool_array(const std::string& name, std::vector<bool>* array);
138  bool add_input_int_array(const std::string& name, std::vector<int>* array);
139  bool add_input_double_array(const std::string& name, std::vector<double>* array);
140 
141  bool add_index(const std::string& name);
142  bool add_size(const std::string& name);
143 
144 
145  // Setup an output Field that contains the altered field data
146  // One can add change the basis_order and datatype if needed
147  bool add_output_fielddata(const std::string& name,
148  FieldHandle field,
149  int output_basis_order,
150  const std::string& output_datatype);
151 
152  // Setup an output Field that contains the altered field data
153  // This one takes the input field datatype and basis order
154  bool add_output_fielddata(const std::string& name,
155  FieldHandle field);
156 
157 
158  // Setup a field whose nodes need to be changed, the data is copied
159  // and the field nodes are changed
160  bool add_output_fieldnodes(const std::string& name,
161  FieldHandle field);
162 
163  // Setup a matrix for output
164  bool add_output_matrix(const std::string& name);
165 
166  // Setup a matrix for output, with a predefined length
167  bool add_output_matrix(const std::string& name,
168  size_type size);
169 
170  bool add_output_fullmatrix(const std::string& name,
172 
173  bool add_output_bool_array(const std::string& name,
174  std::vector<bool>* array);
175  bool add_output_int_array(const std::string& name,
176  std::vector<int>* array);
177  bool add_output_double_array(const std::string& name,
178  std::vector<double>* array);
179 
180  // Setup the expression
181  bool add_expressions(const std::string& expressions);
182 
183  // Run the expressions in parallel
184  bool run();
185 
186  // Extract handles to the results
187  bool get_field(const std::string& name, FieldHandle& field);
188  bool get_matrix(const std::string& name, Core::Datatypes::MatrixHandle& matrix);
189 
190  // Clean up the engine
191  void clear();
192 
193  private:
195  // Progress reporter for reporting error
197 
198  // Parser program : the structure of the expressions and simple reduction
199  // of the expressions to simple function calls
200  ParserProgramHandle pprogram_;
201  // Wrapper around the function calls, this piece actually executes the code
202  ArrayMathProgramHandle mprogram_;
203 
204  // Expression to evaluate before the main expression
205  // This one is to extract the variables from the data sources
206  // This reduces the amount of actual functions we need to implement
207  std::string pre_expression_;
208  // The user defined expression
209  std::string expression_;
210  // Expression to get the data back into the data sinks
211  std::string post_expression_;
212 
213  // The size of the array engine, the first call that add an array that is
214  // bigger than 1, will set this variable
215  // Any subsequent array that does not match the size will cause an error
216  size_type array_size_;
217 
218  // Data that needs to be stored as it is needed before and after the parser is
219  // done. An output needs to be set before the parser, otherwise it is optimized
220  // away, but the type is only know when the parser has validated and optimized
221  // the expression tree
222 
223  std::vector<OutputFieldData> fielddata_;
224  std::vector<OutputFieldMesh> fieldmesh_;
225  std::vector<OutputMatrix> matrixdata_;
226  std::vector<OutputBoolArray> boolarraydata_;
227  std::vector<OutputIntArray> intarraydata_;
228  std::vector<OutputDoubleArray> doublearraydata_;
229 
230 };
231 
232 }
233 
234 #endif
std::string array_name_
Definition: ArrayMathEngine.h:47
boost::shared_ptr< Matrix > MatrixHandle
Definition: MatrixFwd.h:44
Definition: ArrayMathEngine.h:45
std::vector< double > * double_array_
Definition: ArrayMathEngine.h:87
std::string field_name_
Definition: ArrayMathEngine.h:48
Definition: LoggerInterface.h:43
Definition: ArrayMathEngine.h:69
std::string array_name_
Definition: ArrayMathEngine.h:63
Definition: Parser.h:680
void setLogger(Core::Logging::LegacyLoggerInterface *logger)
Definition: ArrayMathEngine.h:97
#define SCISHARE
Definition: share.h:39
std::string field_name_
Definition: ArrayMathEngine.h:57
std::string bool_array_name_
Definition: ArrayMathEngine.h:72
Definition: ArrayMathEngine.h:61
Definition: ArrayMathInterpreter.h:462
Definition: ArrayMathEngine.h:54
std::string int_array_name_
Definition: ArrayMathEngine.h:79
const char * name[]
Definition: BoostGraphExampleTests.cc:87
FieldHandle field_
Definition: ArrayMathEngine.h:58
boost::shared_ptr< ArrayMathProgram > ArrayMathProgramHandle
Definition: ArrayMathInterpreter.h:65
std::vector< int > * int_array_
Definition: ArrayMathEngine.h:80
long long size_type
Definition: Types.h:40
size_type size_
Definition: ArrayMathEngine.h:66
std::vector< bool > * bool_array_
Definition: ArrayMathEngine.h:73
std::string array_name_
Definition: ArrayMathEngine.h:78
std::string array_name_
Definition: ArrayMathEngine.h:85
Core::Datatypes::MatrixHandle matrix_
Definition: ArrayMathEngine.h:65
boost::shared_ptr< ParserProgram > ParserProgramHandle
Definition: Parser.h:70
std::string output_datatype_
Definition: ArrayMathEngine.h:50
std::string array_name_
Definition: ArrayMathEngine.h:71
NewArrayMathEngine()
Definition: ArrayMathEngine.h:95
int output_basis_order_
Definition: ArrayMathEngine.h:49
Definition: ArrayMathEngine.h:41
std::string array_name_
Definition: ArrayMathEngine.h:56
std::string matrix_name_
Definition: ArrayMathEngine.h:64
FieldHandle field_
Definition: ArrayMathEngine.h:51
boost::shared_ptr< Field > FieldHandle
Definition: DatatypeFwd.h:65
std::string double_array_name_
Definition: ArrayMathEngine.h:86
Definition: ArrayMathEngine.h:76
Definition: ConsoleLogger.h:42
Definition: ArrayMathEngine.h:83
int size
Definition: eabLatVolData.py:2