ppap4lmp
0.7.2
|
Element inherits Generator class and contains data element (or entity) as a Json object. More...
#include <element.h>
Public Member Functions | |
Element () | |
Constructor of Element class. More... | |
virtual ShPtr< Element > | get_element (const Json &name=nullptr) override |
Get this object as a shared pointer of Element class. More... | |
virtual ShPtr< Generator > | get_generator (const Json &name=nullptr) override |
Get this object as a shared pointer of Generator class. More... | |
virtual void | accessed_by_instance_of (const Str &classname) override |
Set class name of an instance calling Element::check_required_keys. More... | |
ShPtr< Element > | append_updater (const ShPtr< Updater > &upd) |
Append an Updater object to this Element object: the only way to extend an updating process associated with this object. More... | |
const Json & | get_data () |
Get a reference to data of this object. More... | |
Set< Str > | get_keys () |
Get keys of the data of this object. More... | |
Json | make_reduced_data (const Json &key_) |
Get reduced data of this object. More... | |
template<typename T > | |
void | make_1darray_from_data (T &array, const Str &key) |
Extract values of a property in data as a one-dimensional Eigen-Array. More... | |
template<typename T > | |
void | make_2darray_from_data (T &array, const Vec< Str > &keys) |
Extract values of properties in data as a two-dimensional Eigen-Array. More... | |
void | update_keys () |
Update datakeys. This method must be called after setting new properties to data. More... | |
void | check_required_keys (const Json &key_) |
Check if this object has required key(s). More... | |
bool | check_optional_keys (const Json &key_) |
Check if this object has optional key(s). More... | |
const Json & | get_data_py () |
Get a reference to data of this object. More... | |
Set< Str > | get_keys_py () |
Get keys of the data of this object. More... | |
ArrayXi | get_1d_int_py (const Str &key) |
Get integer values stored in Element::data of this object as a one-dimensional Numpy-Array. More... | |
ArrayXd | get_1d_float_py (const Str &key) |
Get float values stored in Element::data of this object as a one-dimensional Numpy-Array. More... | |
ArrayXXi | get_2d_int_py (const py::args &args) |
Get integer values stored in Element::data of this object as a two-dimensional Numpy-Array. More... | |
ArrayXXd | get_2d_float_py (const py::args &args) |
Get float values stored in Element::data of this object as a two-dimensional Numpy-Array. More... | |
![]() | |
void | book_to_generate_data () |
Appoint to this Generator object. More... | |
void | generate_data () |
Hello to this Generator object. More... | |
void | finish_using_generated_data () |
Goodbye to this object. More... | |
const Vec< UpdatePair > & | get_update_chain () |
Get update_chain of this object. More... | |
Private Member Functions | |
void | increment_bookings () |
void | decrement_bookings () |
void | update_data (const ShPtr< Updater > &upd) |
Vec< std::pair< Str, int > > | get_distances_between_keys (const Json &key_) |
To speed up accessing values in Json. More... | |
void | init_for_python () |
Private Attributes | |
int | n_bookings = 0 |
int | elementid |
Json | data |
Vec< Str > | datakeys |
Str | accessing_classname |
omp_lock_t | omp_lock |
Static Private Attributes | |
static int | n_element_instances = 0 |
Friends | |
class | Generator |
To use increment_bookings, decrement_bookings and update_data. | |
Additional Inherited Members | |
![]() | |
void | merge_update_chain (const Vec< UpdatePair > &new_chain) |
![]() | |
Vec< UpdatePair > | update_chain |
Element inherits Generator class and contains data element (or entity) as a Json object.
This class inherits Generator class and std::enable_shared_from_this<Element>.
Element class is different from Generator, GenDict and GenList by owning data element (or entity). The data is stored as data, and a set of keys for properties in the data is stored as datakeys. Note that data can be either an array Json object or a non-array Json object. A non-array Json object consists of items: pairs of a string key and int/bool/double/string/array value. The key represents a property name. For array data, it contains non-array Json objects. Each non-array Json object should have the same set of keys; this set is the one stored as datakeys.
An object of this class can update itself by calling its update_data where a shared pointer of this object is passed to an Updater object paired as UpdatePair.
About usage in Python, please see pybind::py_element.
Element::Element | ( | ) |
Constructor of Element class.
This constructor is thread-unsafe because it accesses its members thread-globally. Ensure this constructor is not called in a multithreading context.
Definition at line 22 of file element.cpp.
|
overridevirtual |
Set class name of an instance calling Element::check_required_keys.
classname | A string to be assigned to Element::accessing_classname. |
Implements Generator.
Reimplemented in PyElement.
Definition at line 146 of file element.cpp.
Append an Updater object to this Element object: the only way to extend an updating process associated with this object.
upd | An Adder or Filter object to be paired with this Element object as an UpdatePair object, which is appended to a sequence of UpdatePair objects describing the updating process of this object. |
To update the data, one needs to create an Updater object and then appends it to an Element object using this method. In this method, Generator::update_chain stored in Updater::ext_generator of the upd
is merged to Generator::update_chain of this object; then an UpdatePair consisting of this object and the upd
is appended to Generator::update_chain of this object.
Definition at line 157 of file element.cpp.
bool Element::check_optional_keys | ( | const Json & | key_ | ) |
Check if this object has optional key(s).
key_ | A Json object for either a key or an array of keys for optional property. |
If this object has the given key(s), it returns true. If not, it returns false.
Definition at line 315 of file element.cpp.
void Element::check_required_keys | ( | const Json & | key_ | ) |
Check if this object has required key(s).
key_ | A Json object for either a key or an array of keys for required property. |
If this object does not have the given required key(s), a runtime error is thrown in C++ (and also raised in Python).
Definition at line 284 of file element.cpp.
|
private |
This method decrements n_bookings.
If one increments n_bookings of this object before using data and then decrements it after using it, the data is cleared to save memory. This system is convenient to access data multiple times while saving memory.
Definition at line 39 of file element.cpp.
Get float values stored in Element::data of this object as a one-dimensional Numpy-Array.
key | A string key specifying a property. |
Definition at line 366 of file element.cpp.
Get integer values stored in Element::data of this object as a one-dimensional Numpy-Array.
key | A string key specifying a property. |
Definition at line 351 of file element.cpp.
ArrayXXd Element::get_2d_float_py | ( | const py::args & | args | ) |
Get float values stored in Element::data of this object as a two-dimensional Numpy-Array.
*args | An ordered list of keys specifying properties (Python's variable number arguments). |
Definition at line 399 of file element.cpp.
ArrayXXi Element::get_2d_int_py | ( | const py::args & | args | ) |
Get integer values stored in Element::data of this object as a two-dimensional Numpy-Array.
*args | An ordered list of keys specifying properties (Python's variable number arguments). |
Definition at line 381 of file element.cpp.
const Json & Element::get_data | ( | ) |
Get a reference to data of this object.
One can refer the whole data stored in this object by this method.
Definition at line 174 of file element.cpp.
const Json & Element::get_data_py | ( | ) |
Get a reference to data of this object.
One can refer the whole data stored in this object by this method.
Definition at line 333 of file element.cpp.
To speed up accessing values in Json.
The pairs are sorted by their keys in the same order with datakeys. The i th distance of the list is measured from the i-1 th key to i th key in datakeys (distance from the beginning for the first item).
Definition at line 96 of file element.cpp.
Get this object as a shared pointer of Element class.
name | Leave it as it is (default is nullptr ). |
One needs to get as Element when using this data.
Implements Generator.
Reimplemented in PyElement.
Definition at line 120 of file element.cpp.
Get this object as a shared pointer of Generator class.
name | Leave it as it is (default is nullptr ). |
One needs to get as Generator when storing this object.
Implements Generator.
Reimplemented in PyElement.
Definition at line 133 of file element.cpp.
Get keys of the data of this object.
One can refer the keys (property names) in this object by this method.
Definition at line 181 of file element.cpp.
Get keys of the data of this object.
One can refer the keys (property names) in this object by this method.
Definition at line 342 of file element.cpp.
|
private |
This method increments n_bookings.
If one increments n_bookings of this object before using data and then decrements it after using it, the data is cleared to save memory. This system is convenient to access data multiple times while saving memory.
Definition at line 31 of file element.cpp.
|
private |
Routines to be conducted when a wrapper of getter is called from Python.
This method runs updating process associated with this object so that a wrapper of getter can access the filled data.
Definition at line 417 of file element.cpp.
void Element::make_1darray_from_data | ( | T & | array, |
const Str & | key | ||
) |
Extract values of a property in data as a one-dimensional Eigen-Array.
array | Mutable reference to ArrayXi or ArrayXd. |
key | A string key for a property to be extracted. |
If one passed ArrayXi or ArrayXd as a reference, this method fills it by values of a property specified by key
.
Definition at line 218 of file element.cpp.
Extract values of properties in data as a two-dimensional Eigen-Array.
array | Mutable reference to ArrayXXi or ArrayXXd. |
keys | List of string keys for properties to be extracted. |
If one passed ArrayXXi or ArrayXXd as a reference, this method fills it by values of some properties specified by keys
.
Definition at line 238 of file element.cpp.
Get reduced data of this object.
key_ | Either a key or an array of keys. |
Returned Json object has items whose key is or is in key_
only.
Definition at line 188 of file element.cpp.
This method updates data of this object.
This method updates data using an object of Updater taken as upd
. This object and the Updater object are paired as UpdatePair by append_updater in advance. In this method, a shared pointer of this object is passed to Updater::compute of the Updater object.
Definition at line 84 of file element.cpp.
void Element::update_keys | ( | ) |
Update datakeys. This method must be called after setting new properties to data.
If data is an array, only the first element is used for investigating keys.
Definition at line 272 of file element.cpp.
|
private |
Class name of instance accessing this Element instance. The name is shown in error messages thrown by check_required_keys.
|
private |
Data element (or entity) itself. This member is a Json object, which is a very flexible data container consisting of hierarchically organized items: pairs of a string key and int/bool/double/string/array value. Thanks to this flexibility, this class can store data for box, atoms, molecules, beads, cube, ... and more!!
|
private |
|
private |
The number of times this object will be used in the future. This member can be incremented by increment_bookings and decremented by decrement_bookings. If this member becomes 0 in decrement_bookings, data is cleared to save memory.
|
staticprivate |
|
private |
A variable used by OpenMP. In this program, data is updated in a multithreading context. To prevent the data from being updated from multiple threads at the same time, this member must be locked in update_data, increment_bookings and decrement_bookings.