1#ifndef LIBVIENNASHE_QUANTITY_WRAPPERS_HPP
2#define LIBVIENNASHE_QUANTITY_WRAPPERS_HPP
70 virtual void fill_single (std::size_t idx, std::vector<double> & values)
const = 0;
76 std::string
name()
const {
return this->name_; }
80 void set_name(std::string
const & n) { this->name_ = n; }
88 template <
typename DeviceT,
typename AccessorT,
typename ElementTagT >
114 dev_(o.dev_); acc_(o.acc_);
120 double get(std::size_t
id)
const
122 return acc_(viennagrid::elements<ElementTagT>(dev_.mesh())[
id]);
130 const std::size_t num = viennagrid::elements<ElementTagT>(dev_.mesh()).size();
132 for (std::size_t i = 0; i < num; ++i)
134 values[i] =
new double();
135 values[i][0] = this->
get(i);
143 virtual void fill_single(std::size_t idx, std::vector<double> & values)
const
146 values[0] = this->
get(idx);
152 DeviceT
const & dev_;
159 template <
typename DeviceT,
typename AccessorT,
typename ElementTagT >
185 dev_(o.dev_); acc_(o.acc_);
193 std::vector<double>
get(std::size_t
id)
const
195 return acc_(viennagrid::elements<ElementTagT>(dev_.mesh())[
id]);
199 virtual void fill_single(std::size_t idx, std::vector<double> & values)
const { values = this->
get(idx); }
204 const std::size_t num = viennagrid::elements<ElementTagT>(dev_.mesh()).size();
206 for (std::size_t i = 0; i < num; ++i)
208 const std::vector<double> valuevector = this->
get(i);
209 const std::size_t current_length = valuevector.size();
211 values[i] =
new double[current_length];
213 for (std::size_t j = 0; j < current_length; ++j) values[i][j] = valuevector.at(j);
223 DeviceT
const & dev_;
231 typedef std::map<std::string, quantity_wrapper * >
quan_map;
235 for (quan_map::iterator it = quans_.begin(); it != quans_.end(); ++it)
237 if (it->second != NULL)
244 std::size_t
size()
const {
return this->quans_.size(); }
249 std::vector<std::string> v;
250 for (quan_map::const_iterator it = quans_.begin(); it != quans_.end(); ++it)
252 v.push_back(it->first);
267 bool has_quan(std::string
const & name)
const {
return (this->quans_.find(name) != this->quans_.end()); }
274 std::string name = quan.
name();
277 viennashe::log::error() <<
"ERROR: ViennaSHE C/C++ Wrappers failed! Where? Quantitiy Management at register_quan for '"
278 << name <<
"', which is already registered!" << std::endl;
279 throw std::runtime_error(
"Quantitiy already exists");
283 this->quans_.insert(std::make_pair(name, quan.
copy()));
Implements quantity_wrapper. Wraps vector valued quantities, which are accessible via a device based ...
accessor_based_array_quantity_wrapper< DeviceT, AccessorT, ElementTagT > self_type
accessor_based_array_quantity_wrapper(AccessorT const &acc, DeviceT const &dev, std::string name)
CTOR.
virtual void fill_single(std::size_t idx, std::vector< double > &values) const
Implements fill_single.
accessor_based_array_quantity_wrapper(accessor_based_array_quantity_wrapper const &o)
void operator=(accessor_based_array_quantity_wrapper const &o)
virtual quantity_wrapper * copy() const
Implements copy.
std::vector< double > get(std::size_t id) const
Simple forward to the accessor.
virtual void fill(double **values, viennashe_index_type *len) const
Implements fill.
Implements quantity_wrapper. Wraps scalar quantities, which are accessible via a device based accesso...
accessor_based_quantity_wrapper< DeviceT, AccessorT, ElementTagT > self_type
void operator=(accessor_based_quantity_wrapper const &o)
accessor_based_quantity_wrapper(AccessorT const &acc, DeviceT const &dev, std::string name)
CTOR.
virtual quantity_wrapper * copy() const
A simple copy factory for storage.
virtual void fill(double **values, viennashe_index_type *len) const
Implementation of fill.
double get(std::size_t id) const
Simple forward to the accessor.
accessor_based_quantity_wrapper(accessor_based_quantity_wrapper const &o)
virtual void fill_single(std::size_t idx, std::vector< double > &values) const
Implemenation of fill_single. Uses get()
The main quantity register. Not deep copy-able!
quantity_wrapper const & get(std::string const &name) const
Returns a single const reference to a quantitiy wrapper.
std::map< std::string, quantity_wrapper * > quan_map
bool has_quan(std::string const &name) const
Returns true if a quantity is registered.
virtual ~quantitiy_register()
void register_quan(quantity_wrapper const &quan)
Registers a quantity.
std::size_t size() const
Returns the number of registered quantities.
std::vector< std::string > get_names() const
Returns all names of the registered quantities.
The main quantity wrapper interface
quantity_wrapper()
Default CTOR. Creates an empty wrapper.
void operator=(quantity_wrapper const &o)
virtual ~quantity_wrapper()
void set_name(std::string const &n)
Name setter for implementing classes.
quantity_wrapper(std::string name)
virtual void fill_single(std::size_t idx, std::vector< double > &values) const =0
Interface. Fills values with a single value (scalar or vector) at the given element index.
quantity_wrapper(quantity_wrapper const &v)
virtual quantity_wrapper * copy() const =0
A simple copy factory for storage.
std::string name() const
Returns the unique name of the quantity.
virtual void fill(double **values, viennashe_index_type *len) const =0
Interface. Fills values with all quantity values, where the length of values[i] is to be found in len...
Provides the exceptions used in the main viennashe namespace.
Contains forward declarations and definition of small classes that must be defined at an early stage.
The internal C++ namespace of the library.
logger< true > error()
Used to log errors. The logging level is logERROR.
C++ to C wrapper of the quantity registry.
std::size_t count() const
libviennashe::quantity::quantitiy_register cell_based
viennashe_simulator_impl * int_sim
Register for vertex based quantities.
Internal C++ to C wrapper for the simulator. Has typedefs and destructor.
unsigned long viennashe_index_type
Contains all viennashe includes and most of the C++/C-wrappers. Contains macros.