OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fcst_variables.h
Go to the documentation of this file.
1 // ------------------------------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2006-2013 by Energy Systems Design Laboratory, University of Alberta
6 //
7 // This software is distributed under the MIT License
8 // For more information, see the README file in /doc/LICENSE
9 //
10 // - Class: fcst_variables.h
11 // - Description: This structure keeps a name of an FCST solution variable
12 // and
13 // values of this variable in the quadrature points of a mesh entity
14 // - Developers: Phil Wardlaw, University of Alberta
15 // Madhur Bhaiya, University of Alberta
16 // Valentin N. Zingan, University of Alberta
17 // - $Id: fcst_variables.h 2605 2014-08-15 03:36:44Z secanell $
18 //
19 // ------------------------------------------------------------------------------------------------
20 
21 #ifndef _FCST_FUELCELLSHOP_SOLUTION_VARIABLE_H_
22 #define _FCST_FUELCELLSHOP_SOLUTION_VARIABLE_H_
23 
24 #include <cmath>
25 #include <iostream>
26 
27 #include <base/parameter_handler.h>
28 #include <base/point.h>
29 #include <base/function.h>
30 #include <lac/vector.h>
31 #include <fe/fe_values.h>
32 
34 
35 using namespace dealii;
36 
37 namespace FuelCellShop
38 {
87 {
88 
90 
91 
94  {
95  data = NULL;
96  initialized = false;
97  initialized_default_data = false;
98  initialized_data = false;
99  }
100 
104  SolutionVariable(const std::vector<double>* data_in, const VariableNames& name_in)
105  {
106  data = data_in;
107  name = name_in;
108  initialized = true;
109  initialized_default_data = false;
110  initialized_data = true;
111  }
112 
118  SolutionVariable(const double& value, const unsigned int& length, const VariableNames& name_in)
119  {
120  data = NULL;
121  default_data = std::vector<double>(length, value);
122  name = name_in;
123  initialized = true;
124  initialized_default_data = true;
125  initialized_data = false;
126  }
127 
133  SolutionVariable(const std::vector<double>& data_in, const VariableNames& name_in)
134  {
135  data = NULL;
136  default_data = data_in;
137  name = name_in;
138  initialized = true;
139  initialized_default_data = true;
140  initialized_data = false;
141  }
142 
144 
146 
147 
148  const std::vector<double>& get_default_data() const
149  {
150  Assert( initialized_default_data, ExcMessage("default_data is not initialized") );
151  return default_data;
152  }
153 
154  const std::vector<double>* get_data() const
155  {
156  Assert( initialized_data, ExcMessage("data is not initialized") );
157  return data;
158  }
159 
164  {
165  Assert( initialized, ExcMessage("SolutionVariable not initialized !!!") );
166  return name;
167  }
168 
172  const bool is_initialized() const
173  {
174  return initialized;
175  }
176 
177  const bool is_default_data_initialized() const
178  {
179  return initialized_default_data;
180  }
181 
182  const bool is_data_initialized() const
183  {
184  return initialized_data;
185  }
186 
190  unsigned int size() const
191  {
192  unsigned int answer = 0;
193  //If initialized and pointer is not NULL
194  if (initialized && (data != NULL))
195  answer = data->size();
196  else if (initialized && (data == NULL))
197  answer = default_data.size();
198 
199  return answer;
200  }
201 
203 
205 
206 
211  const double& operator[](const unsigned int& i) const
212  {
213  Assert( initialized, ExcMessage("SolutionVariables struct is not initialized !!!") );
214 
215  if (data != NULL)
216  {
217  Assert( i < data->size(), ExcMessage("Index is out of range in operator[] for SolutionVariables struct.") );
218  return data->at(i);
219  }
220  else if (data == NULL)
221  {
222  Assert( i < default_data.size(), ExcMessage("Index is out of range in operator[] for SolutionVariables struct.") );
223  return default_data.at(i);
224  }
225  }
226 
234  friend SolutionVariable operator* (const SolutionVariable& left,
235  const double& right)
236  {
237  Assert( left.is_default_data_initialized(), ExcMessage("SolutionVariable left operand default_data is not initialized") );
238 
239  std::vector<double> tmp(left.size());
240 
241  const VariableNames name = left.get_variablename();
242 
243  if( left.is_default_data_initialized() && !left.is_data_initialized() )
244  {
245  for(unsigned int q = 0; q < tmp.size(); ++q)
246  tmp[q] = left.get_default_data().at(q);
247 
248  for(unsigned int q = 0; q < tmp.size(); ++q)
249  tmp[q] *= right;
250 
251  return SolutionVariable(tmp,
252  name);
253  }
254  else if( !left.is_default_data_initialized() && left.is_data_initialized() )
255  {
256  AssertThrow( false, ExcNotImplemented() );
257  }
258  else
259  {
260  AssertThrow( false, ExcInternalError() );
261  }
262  }
263 
271  friend SolutionVariable operator* (const double& left,
272  const SolutionVariable& right)
273  {
274  Assert( right.is_default_data_initialized(), ExcMessage("SolutionVariable right operand default_data is not initialized") );
275 
276  std::vector<double> tmp(right.size());
277 
278  const VariableNames name = right.get_variablename();
279 
280  if( right.is_default_data_initialized() && !right.is_data_initialized() )
281  {
282  for(unsigned int q = 0; q < tmp.size(); ++q)
283  tmp[q] = right.get_default_data().at(q);
284 
285  for(unsigned int q = 0; q < tmp.size(); ++q)
286  tmp[q] *= left;
287 
288  return SolutionVariable(tmp,
289  name);
290  }
291  else if( !right.is_default_data_initialized() && right.is_data_initialized() )
292  {
293  AssertThrow( false, ExcNotImplemented() );
294  }
295  else
296  {
297  AssertThrow( false, ExcInternalError() );
298  }
299  }
300 
308  friend SolutionVariable operator/ (const SolutionVariable& left,
309  const double& right)
310  {
311  Assert( left.is_default_data_initialized(), ExcMessage("SolutionVariable left operand default_data is not initialized") );
312 
313  std::vector<double> tmp(left.size());
314 
315  const VariableNames name = left.get_variablename();
316 
317  if( left.is_default_data_initialized() && !left.is_data_initialized() )
318  {
319  for(unsigned int q = 0; q < tmp.size(); ++q)
320  tmp[q] = left.get_default_data().at(q);
321 
322  for(unsigned int q = 0; q < tmp.size(); ++q)
323  tmp[q] /= right;
324 
325  return SolutionVariable(tmp,
326  name);
327  }
328  else if( !left.is_default_data_initialized() && left.is_data_initialized() )
329  {
330  AssertThrow( false, ExcNotImplemented() );
331  }
332  else
333  {
334  AssertThrow( false, ExcInternalError() );
335  }
336  }
337 
338 
340 
341 private:
342 
344 
345 
349  std::vector<double> default_data;
350 
355  const std::vector<double>* data;
356 
362 
368 
374 
380 
382 
383 };
384 
386 
387 
391  static bool is_phiM(const SolutionVariable& sol_var)
392  {
393  return (sol_var.get_variablename() == protonic_electrical_potential);
394  }
395 
399  static bool is_phiS(const SolutionVariable& sol_var)
400  {
402  }
403 
405 
406 
447  class SolutionMap : private std::map< VariableNames, SolutionVariable>
448  {
449  public:
450 
464  void push_back(const SolutionVariable& a){
465 
466 
467  //Check that the key hasn't already been entered
468  if (this->count(a.get_variablename()) > 0)
469  throw std::runtime_error("You have already added a SolutionVariable of corresponding VariableNames type to SolutionMap");
470 
471 
472  //add the variable
473  this->operator [](a.get_variablename()) = a;
474  }
475 
480  return std::map<VariableNames, SolutionVariable>::at(key);
481  }
482 
486  void clear(){
487  std::map<VariableNames, SolutionVariable>::clear();
488  }
489 
493  void erase(const VariableNames& v){
494  std::map<VariableNames, SolutionVariable>::erase(v);
495  }
496 
497 
501  bool has(const VariableNames& v) const{
502  bool answer = false;
503 
504  if(this->count(v) >0)
505  answer = true;
506 
507  return answer;
508  }
509 
515  SolutionVariable temp = this->at(v);
516  std::map<VariableNames, SolutionVariable>::erase(v);
517  return temp;
518  }
519 
520  };
521 
522 
523 
524 
525 }
526 
527 
528 
529 #endif
const std::vector< double > * get_data() const
Definition: fcst_variables.h:154
void clear()
Expose std::map&lt;VariableNames, SolutionVariable&gt;::clear() interface publicly.
Definition: fcst_variables.h:486
bool has(const VariableNames &v) const
Find if a solution corresponding VariableNames type exist inside map.
Definition: fcst_variables.h:501
void erase(const VariableNames &v)
Expose std::map&lt;VariableNames, SolutionVariable&gt;::erase() interface publicly.
Definition: fcst_variables.h:493
const double & operator[](const unsigned int &i) const
Operator to access the value at a particular quadrature point in the cell.
Definition: fcst_variables.h:211
VariableNames get_variablename() const
Function to get the VariableNames enumeration corresponding to this struct.
Definition: fcst_variables.h:163
VariableNames name
FCST variable name stored in VariableNames enumeration.
Definition: fcst_variables.h:361
VariableNames
The enumeration containing the names of some of the available FCST solution variables and their deriv...
Definition: system_management.h:62
Convenient storage object for SolutionVariables.
Definition: fcst_variables.h:447
This structure is used to encapsulate data from constant values and variable solution data that is us...
Definition: fcst_variables.h:86
Definition: system_management.h:70
SolutionVariable pop(const VariableNames &v)
Returns and entry whilst removing it from the list.
Definition: fcst_variables.h:514
SolutionVariable(const std::vector< double > *data_in, const VariableNames &name_in)
Constructor for setting up the pointer to solution variable values and name of the solution variable...
Definition: fcst_variables.h:104
void push_back(const SolutionVariable &a)
Public function for adding SolutionVariable, uses the VariableNames stored within the SolutionVariabl...
Definition: fcst_variables.h:464
const bool is_default_data_initialized() const
Definition: fcst_variables.h:177
std::vector< double > default_data
Constant data.
Definition: fcst_variables.h:349
const std::vector< double > & get_default_data() const
Definition: fcst_variables.h:148
const bool is_data_initialized() const
Definition: fcst_variables.h:182
bool initialized_default_data
true if default_data is initialized.
Definition: fcst_variables.h:373
SolutionVariable & at(VariableNames key)
Expose std::map&lt;VariableNames, SolutionVariable&gt;::at() interface publicly.
Definition: fcst_variables.h:479
bool initialized
true if either default_data or data is initialized.
Definition: fcst_variables.h:367
unsigned int size() const
Function to the length of the internal data element.
Definition: fcst_variables.h:190
static bool is_phiS(const SolutionVariable &sol_var)
Unary Predicate to return true if a SolutionVariable object belongs to electronic_electrical_potentia...
Definition: fcst_variables.h:399
SolutionVariable(const double &value, const unsigned int &length, const VariableNames &name_in)
Constructor to initialize the solution variable values, taking a default value and size of the vector...
Definition: fcst_variables.h:118
SolutionVariable()
Default Constructor.
Definition: fcst_variables.h:93
const std::vector< double > * data
Data in quadrature points of a mesh entity.
Definition: fcst_variables.h:355
Definition: system_management.h:71
static bool is_phiM(const SolutionVariable &sol_var)
Unary Predicate to return true if a SolutionVariable object belongs to protonic_electrical_potential...
Definition: fcst_variables.h:391
bool initialized_data
true if data is initialized.
Definition: fcst_variables.h:379
const bool is_initialized() const
Function to determine whether the structure is initialized or not.
Definition: fcst_variables.h:172
SolutionVariable(const std::vector< double > &data_in, const VariableNames &name_in)
Constructor to initialize the solution variable values, taking values as an input vector argument...
Definition: fcst_variables.h:133