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 n \times m. 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

 

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;
}