Data Pattern Types and Iterations
In this lesson we will deal with the GSSE standard data type, the data pattern type. Data pattern types are matrices
. They are therefore useful for scalar, vector as well as tensor operations. The data type has overloaded operations such as addition, multiplication as well as element access. Use the files from the first tutorial.
Tasks
- L1: Create a quantity scalar_value and assign the
matrix [1] on all vertices. - L1: Create a quantity vector_value and assign the
matrix [1, 2, 3] on all cells. Assigns the same value to all elements of the matrix. - L2: Use the vertex_on_cell_iterator in order to add all vertex values (vertex_count) of one cell. Store the value on cell_sum.
- L2: Use the cell_on_vertex_iterator in order to add all cell values (cell_count) of one vertex. Store the value on vertex_sum.
- L2: For all cells: sum up all values of scalar_value of vertices which belong to one cell.
- L2: For all vertices: sum up all values of vector_value of cells which belong to one vertex.
- L3: Create your own data pattern type. Implement all necessary methods to accomplish the given mechanisms.
C++ Reference Implementation with the GSSE
// .. include the dimension you need for this tutorial // #include "gsse/gsse_2d_unstructured.hpp" long test(std::string infilename) { // use some strings for your variables // std::string key_pot = "Potential"; std::string key_pot_entry = "@Potential"; // prepare the structure // domain_t domain; segment_iterator segit; domain.read_file(infilename); segit = domain.segment_begin(); // iterate over all vertices within the domain // for (vertex_iterator vit = (*segit).vertex_begin(); vit != (*segit).vertex_end(); ++vit) { // the gsse data pattern type.. a 1x1 matrix..default value: 0.0 // data_pattern_type entry(1, 1, 0.0); // retrieve a value from the structure // (*segit).retrieve_quantity(*vit, key_pot_entry, entry); // basic calculations // entry(0, 0) *= 2; // write the value back // (*segit).store_quantity(*vit, key_pot_entry, entry); // print a value // std::cout << entry(0, 0) << std::endl; // print out a given value // std::cout << (*segit)(*vit, key_pot_entry) << std::endl; } // a different iteration scheme: a cell iteration // for (cell_iterator cit = (*segit).cell_begin(); cit != (*segit).cell_end(); ++cit) { // sub-dimensional iteration.. all vertices on a given cell // domain_traits<domain_t>::vertex_on_cell_iterator iter1(*cit); while(iter1.valid()) { vertex_type v1 = *iter1; // implement some basic algorithms for all vertices on a cell // ++iter1; } } return 0; } int main(int argc, char** argv) { // use the filename // if (argc < 2) { std::cout << "./progname inputfile.gas2" << std::endl; exit (-1); } test(argv[1]); return 0; }