5 #ifndef ROCKY_ZAGROS_ANALYSIS
6 #define ROCKY_ZAGROS_ANALYSIS
11 #include <rocky/zagros/strategies/strategy.h>
22 template<
typename T_e,
int T_dim>
29 template<
typename T_e,
int T_dim>
52 std::vector<std::vector<T_e>> z;
66 delta_x_ = (x_max_ - x_min_) /
static_cast<double>(width_);
67 delta_y_ = (y_max_ - y_min_) /
static_cast<double>(height_);
69 l_width_ = (x_max_ - x_min_) / delta_x_ ;
70 l_height_ = (y_max_ - y_min_) / delta_y_;
73 for(
int x=0; x<l_width_; x++)
74 z[x].resize(l_height_);
77 std::string path = fmt::format(
"zagros_{}_{}.data", label_, step_);
78 std::fstream handler(path, std::fstream::out);
80 handler << step_ << std::endl;
81 handler << fmt::format(
"{} {} {} {}", x_min_, y_min_, x_max_, y_max_) << std::endl;
82 handler << fmt::format(
"{} {}", l_height_, l_width_) << std::endl;
84 for(
int x=0; x<l_width_; x++)
85 for(
int y=0; y<l_height_; y++)
86 handler << z[x][y] <<
" ";
91 tbb::parallel_for(0, this->l_width_, [&](
auto x){
92 tbb::parallel_for(0, this->l_height_, [&](
auto y){
94 thread_point[0] = x * this->delta_x_ + this->x_min_;
95 thread_point[1] = y * this->delta_y_ + this->y_min_;
96 this->z[x][y] = this->problem_->objective(thread_point);
105 std::string filename;
106 std::fstream log_output;
112 this->filename = filename;
115 this->initialized =
false;
119 this->write_header();
124 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
125 std::string process_spc_filename = fmt::format(
"proc_{}_{}", mpi_rank, filename);
127 log_output.open(process_spc_filename, std::fstream::out);
129 std::fstream& stream(){
133 this->stream() <<
"particle";
134 for(
int i=0; i<dims; i++)
135 this->stream() <<
",x" << std::to_string(i);
136 this->stream() << std::endl;
137 this->initialized =
true;
140 if(this->log_output.is_open())
141 this->log_output.close();
148 template<
typename T_e,
int T_dim>
157 this->problem_ = problem;
158 this->container_ = container;
159 this->handler_ = handler;
161 virtual void apply(){
162 if (!(this->handler_->initialized)){
163 this->handler_->dims = T_dim;
164 this->handler_->write_header();
166 std::stringstream buffer;
167 for(
int p=0; p<this->container_->n_particles(); p++){
169 for(
int d=0; d<T_dim; d++)
170 buffer <<
"," << this->container_->particles[p][d];
173 this->handler_->stream() << buffer.str();
174 this->handler_->step++;