Commit cd44b9a2 authored by Sergey Kireev's avatar Sergey Kireev
Browse files

gathering of group statistics is operational now

parent 45485050
......@@ -625,23 +625,28 @@ int CA2D<State,hood_type>::find_groups_hex(std::function<bool(const State &)> ma
}
template<class State,Neighborhood_type hood_type>
CA2D<State,hood_type>::GroupStatistics CA2D<State,hood_type>::get_groups_statistics(int threshold) {
int grpSizeThreshold = threshold;
int grpCount = 0;
int grpMinSize = nx*ny;
int grpMidSize = 0;
int grpMaxSize = 0;
GroupStatistics CA2D<State,hood_type>::get_group_statistics(int threshold) {
int Count = 0;
int MinSize = nx*ny;
int SumSize = 0;
int MaxSize = 0;
int SumTotal = 0;
for (int i=0;i<group_labels_upper_bound;i++) {
const int size = groupsize[i];
if (size > 0 && size > threshold) {
grpCount++;
grpMinSize = std::min(grpMinSize,size);
grpMaxSize = std::max(grpMaxSize,size);
grpMidSize += size;
if (size > 0) {
SumTotal += size;
if (size >= threshold) {
Count++;
MinSize = std::min(MinSize,size);
MaxSize = std::max(MaxSize,size);
SumSize += size;
}
}
}
grpMidSize /= grpCount;
return { threshold, grpCount, grpMinSize, grpMidSize, grpMaxSize };
const float MidSize = Count > 0 ? static_cast<float>(SumSize) / Count : 0;
if (Count == 0) MinSize = 0;
const float Part = 100.0f * static_cast<float>(SumSize) / SumTotal;
return { threshold, Count, MinSize, MidSize, MaxSize, Part };
}
} // namespace ca2d
......
......@@ -124,6 +124,15 @@ class Neighborhood<hood_hex> : public Neighborhood_base<Neighborhood_value<hood_
std::string name() { return "hood_hex"; }
};
struct GroupStatistics {
int grpSizeThreshold;
int grpCount;
int grpMinSize;
float grpMidSize;
int grpMaxSize;
float grpPart;
};
template<class State,Neighborhood_type hood_type>
class CA2D {
......@@ -171,14 +180,6 @@ private:
public:
struct GroupStatistics {
int grpSizeThreshold;
int grpCount;
int grpMinSize;
int grpMidSize;
int grpMaxSize;
};
const int nx,ny;
const int groups_max;
......@@ -234,7 +235,7 @@ public:
return find_groups_sqr4(match);
}
GroupStatistics get_groups_statistics(int minsize=0);
GroupStatistics get_group_statistics(int minsize=0);
//void save_char(const std::string &fn,int it=-1,const std::string &ext="") const;
......
......@@ -51,6 +51,16 @@ void count(const Parameters &p) {
}
}
std::ofstream gstf;
if (p.is_groupstatistics()) {
std::string fn = p.get_file_groupstatistics();
try { gstf.open(fn); } catch (std::ofstream::failure e) {
std::cerr << "Error: Can't open output file '" << fn << "'\n";
exit(1);
}
gstf << "# it cnt min mid max %" << std::endl;
}
{
auto time_start = std::chrono::high_resolution_clock::now();
......@@ -61,10 +71,18 @@ void count(const Parameters &p) {
if (p.is_save_groups()) ca->save_groups(p.get_groups_prefix(),nt0,p.get_groups_suffix());
}
if (p.is_maxgroupsize()) { mgsf << nt0 << " " << ca->get_maxgroupsize() << std::endl; }
if (p.is_groupstatistics()) {
const GroupStatistics gst = ca->get_N_group_statistics(p.get_gstmin());
gstf << std::fixed << std::setprecision(2) << nt0 << " " << gst.grpCount << " " << gst.grpMinSize << " " << gst.grpMidSize << " " << gst.grpMaxSize << " " << gst.grpPart << std::endl;
}
for (int it=0;it<nt;it++) {
ca->iterate();
if (p.is_maxgroupsize()) { mgsf << nt0+it+1 << " " << ca->get_maxgroupsize() << std::endl; }
if (p.is_groupstatistics()) {
const GroupStatistics gst = ca->get_N_group_statistics(p.get_gstmin());
gstf << std::fixed << std::setprecision(2) << nt0+it+1 << " " << gst.grpCount << " " << gst.grpMinSize << " " << gst.grpMidSize << " " << gst.grpMaxSize << " " << gst.grpPart << std::endl;
}
if (ns != 0 && (it+1)%ns == 0) {
ca->save_binary(prefix,nt0+it+1,suffix);
if (p.is_save_groups()) ca->save_groups(p.get_groups_prefix(),nt0+it+1,p.get_groups_suffix());
......@@ -80,7 +98,7 @@ void count(const Parameters &p) {
printf("Time: %.3lf s\n",(time_end - time_start)/std::chrono::milliseconds(1)*1e-3); fflush(stdout);
}
if (p.is_maxgroupsize()) mgsf.close();
if (p.is_groupstatistics()) gstf.close();
}
int main(int argc,char *argv[]) {
......
......@@ -266,6 +266,11 @@ class NLE_CA_base : public CA2D<int,hood_type> {
return maxgroupsize;
}
GroupStatistics get_N_group_statistics(int minsize=0) {
if (!groups_found) find_groups();
return ca::get_group_statistics(minsize);
}
void save_groups(const std::string &fn,int it=-1,const std::string &ext="") {
if (!groups_found) find_groups();
const std::string filename = ca::construct_filename(fn,it,ext);
......
......@@ -105,6 +105,14 @@
#define FILE_MAXGROUPSIZE ""
#endif
#ifndef FILE_GROUPSTATISTICS
#define FILE_GROUPSTATISTICS ""
#endif
#ifndef GSTMIN
#define GSTMIN 1
#endif
#ifndef SQUHEX
#define SQUHEX 4
#endif
......@@ -142,6 +150,8 @@ Parameters::Parameters():
default_groupfile_suffix(GROUP_SUFFIX),
default_save_groups(SAVE_GROUPS),
default_file_maxgroupsize(FILE_MAXGROUPSIZE),
default_file_groupstatistics(FILE_GROUPSTATISTICS),
default_gstmin(GSTMIN),
default_squhex(SQUHEX),
default_check(CHECK),
default_fill_debug(FILL_DEBUG) {
......@@ -176,6 +186,8 @@ void Parameters::reset() {
groupfile_suffix = default_groupfile_suffix;
save_groups = default_save_groups;
file_maxgroupsize = default_file_maxgroupsize;
file_groupstatistics = default_file_groupstatistics;
gstmin = default_gstmin;
load_file = false;
......@@ -236,6 +248,8 @@ bool Parameters::read_from_cmdline(int argc,char *argv[]) {
std::cout << " -gfp <string> - set output file prefix for groups (default: '" << default_groupfile_prefix << "')" << std::endl;
std::cout << " -gfs <string> - set output file suffix for groups (default: '" << default_groupfile_suffix << "')" << std::endl;
std::cout << " -mgslog <filename> - log maximum group size to file (default: " << (default_file_maxgroupsize.size() == 0 ? "none" : default_file_maxgroupsize) << ")" << std::endl;
std::cout << " -gstlog <filename> - log group statistics to file (default: " << (default_file_groupstatistics.size() == 0 ? "none" : default_file_groupstatistics)<< ")" << std::endl;
std::cout << " -gstmin <size> - set minimum number of nonocrystals in a group for statistics (default: " << default_gstmin << ")" << std::endl;
std::cout << " -long - set long output format (default: " << (default_long_output ? "enabled" : "disabled") << ")" << std::endl;
std::cout << " -short - set short output format (default: " << (default_long_output ? "disabled" : "enabled") << ")" << std::endl;
//std::cout << " -O[<level>] - use optimized rule (0 - basic general rule, 1,2,3(default) - optimized rules)" << std::endl;
......@@ -438,6 +452,18 @@ bool Parameters::read_from_cmdline(int argc,char *argv[]) {
file_maxgroupsize = argv[cnt];
cnt++;
}
else if (strcmp("-gstlog",argv[cnt])==0) {
cnt++;
if (cnt == argc) { std::cout << "Error: Option '-gstlog' requires string parameter\n"; return false; }
file_groupstatistics = argv[cnt];
cnt++;
}
else if (strcmp("-gstmin",argv[cnt])==0) {
cnt++;
if (cnt == argc) { std::cout << "Error: Option '-gstmin' requires integer parameter\n"; return false; }
gstmin = std::stoi(argv[cnt]);
cnt++;
}
else { std::cout << "Error: Unknown parameter: " << argv[cnt] << std::endl; return false; }
}
......@@ -493,6 +519,8 @@ bool Parameters::verify() const {
if (ns<0 || ns>1000000000) { std::cout << "Error: wrong 'ns' parameter value: " << ns << std::endl; result = false; }
if (np<0 || np>1000000000) { std::cout << "Error: wrong 'np' parameter value: " << np << std::endl; result = false; }
if (gstmin<0 || gstmin>1000000000) { std::cout << "Error: wrong 'gstmin' parameter value: " << gstmin << std::endl; result = false; }
if (nsize<0 || nsize>nx || nsize>ny) { std::cout << "Error: wrong 'nsize' parameter value: " << nsize << std::endl; result = false; }
if (fraction_n<0.0 || fraction_n>1.0) { std::cout << "Error: wrong initial fraction of 'N': " << fraction_n << std::endl; result = false; }
......
......@@ -14,6 +14,7 @@ class Parameters {
int default_save_groups;
int default_check;
int default_fill_debug;
int default_gstmin;
double default_fraction_n;
double default_fraction_l;
......@@ -32,6 +33,7 @@ class Parameters {
std::string default_groupfile_prefix;
std::string default_groupfile_suffix;
std::string default_file_maxgroupsize;
std::string default_file_groupstatistics;
// values
double fraction_n;
......@@ -49,12 +51,14 @@ class Parameters {
int initial_step;
int squhex;
int save_groups;
int gstmin;
std::string datafile_prefix;
std::string datafile_suffix;
std::string groupfile_prefix;
std::string groupfile_suffix;
std::string file_maxgroupsize;
std::string file_groupstatistics;
std::string input_filename;
bool load_file;
......@@ -100,6 +104,9 @@ public:
bool is_maxgroupsize() const { return file_maxgroupsize.size() > 0; }
std::string get_file_maxgroupsize() const { return file_maxgroupsize; }
bool is_groupstatistics() const { return file_groupstatistics.size() > 0; }
std::string get_file_groupstatistics() const { return file_groupstatistics; }
int get_gstmin() const { return gstmin; }
bool is_long_output() const { return long_output != 0; }
bool is_short_output() const { return long_output == 0; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment