Skip to content

Commit 7495635

Browse files
committed
Following of the second_generation for the
Working Betti numbers
1 parent e1c6956 commit 7495635

10 files changed

Lines changed: 412 additions & 158 deletions

File tree

config/characterisation.ini

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ S_mean = 0
1313
S_skew = 0
1414

1515
[edges_lab]
16-
el_active = 1
17-
config_entropy = 1
18-
S_mean = 1
19-
S_skew = 1
20-
j_fractions = 1
21-
d_fractions = 1
22-
analytical = 1
16+
el_active = 0
17+
config_entropy = 0
18+
S_mean = 0
19+
S_skew = 0
20+
j_fractions = 0
21+
d_fractions = 0
22+
analytical = 0
2323

2424
[nodes_lab]
2525
nl_active = 0
@@ -28,7 +28,8 @@ S_mean = 0
2828
S_skew = 0
2929

3030
[spectra_lab]
31-
laplacians = 0
31+
calc_steps_numb = 50
32+
laplacians = 1
3233
laplacians_spectra = 0
3334
laplacians_betti = 0
3435

config/main.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PCC_Writer=ON
1111

1212
[general]
1313
dim=3
14-
source_dir=/Users/user/Dropbox/OFFICE/NEPER/Kinetic_PCC_examples_/Voronoi_1k/
15-
;source_dir=/Users/user/Dropbox/OFFICE/EGitHub/_Kinetic_PCC_examples/Siying500Complex/
16-
output_dir=/Users/user/Dropbox/OFFICE/NEPER/resultsFebruary2023/v1k_processing/
17-
;output_dir=/Users/user/Dropbox/OFFICE/NEPER/resultsMay2023/500cells_processing/
14+
; source_dir=/Users/user/Dropbox/OFFICE/NEPER/Kinetic_PCC_examples_/Voronoi_1k/
15+
source_dir=/Users/user/Dropbox/OFFICE/EGitHub/_Kinetic_PCC_examples/Siying500Complex/
16+
;output_dir=/Users/user/Dropbox/OFFICE/NEPER/resultsFebruary2023/v1k_processing/
17+
output_dir=/Users/user/Dropbox/OFFICE/NEPER/resultsMay2023/500cells_processing/

config/processing.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pmax_fraction3 = 0.0
1414

1515
[faces]
1616
face_types_number = 1
17-
pf_mode = S
17+
pf_mode = R
1818
; "S" - read from source, "R" or "F" -> Smax, "D" -> Smin (max S_deviatoric (skew) part) or "L"
1919
source = /Users/user/Dropbox/OFFICE/NEPER/resultsFebruary2023/v1k_processing/Random099/s_cells_sequence.txt
2020
pf_index = 0

config/writer.ini

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
; writer specifications
22

33
[sequences]
4-
isSequencesOutput = 1
5-
isDesignvectorsOutput = 1
4+
isSequencesOutput = 0
5+
isDesignvectorsOutput = 0
66

77
[entropic_polyhedrons]
88
isPolyhedronFractions = 0
99

10-
1110
[entropic_faces]
1211
isFaceFractions = 0
1312
isConfEntropy = 0
1413

1514
[entropic_edges]
16-
isConfEntropy = 1
17-
isFractions = 1
18-
isDegreeFractions = 1
15+
isConfEntropy = 0
16+
isFractions = 0
17+
isDegreeFractions = 0
1918

2019
[entropic_nodes]
2120
isNodeFractions = 0
2221

2322
[entropic_analytical]
24-
isEdgeFractions = 1
25-
isEdgeConfEntropies = 1
23+
isEdgeFractions = 0
24+
isEdgeConfEntropies = 0
25+
26+
[component_analysis]
27+
isBetti = 1

src/lib/PCC_Characterisation/LaplaciansLab.h

Lines changed: 203 additions & 85 deletions
Large diffs are not rendered by default.

src/lib/PCC_Characterisation/PCC_StructureCharacterisation.h

Lines changed: 113 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
ProcessedComplex PCC_StructureCharacterisation(CellsDesign &new_cells_design) {
1111
ProcessedComplex PCC_characteristics; // module output
1212
/// Read simulation configuration from file :: the number of special face types and calculating parameters. Then Output of the current configuration to the screen
13-
std::vector<int> charlabs_polyhedrons, charlabs_faces, charlabs_edges, charlabs_nodes;
14-
std::vector<double> ConfigVector = config_reader_characterisation(source_path, charlabs_polyhedrons, charlabs_faces, charlabs_edges, charlabs_nodes, Out_logfile_stream); // vector<double> (!) from ini_readers.h library
13+
std::vector<int> charlabs_polyhedrons, charlabs_faces, charlabs_edges, charlabs_nodes, charlabs_laplacians;
14+
std::vector<double> ConfigVector = config_reader_characterisation(source_path, charlabs_polyhedrons, charlabs_faces, charlabs_edges, charlabs_nodes, charlabs_laplacians, Out_logfile_stream); // vector<double> (!) from ini_readers.h library
1515

1616
/// # 1 # Creation of the State Vectors
1717
// Faces
@@ -26,49 +26,119 @@ ProcessedComplex PCC_StructureCharacterisation(CellsDesign &new_cells_design) {
2626

2727
} // end for(auto fseq...)
2828

29-
for (int i = 0; i < 4; ++i) { // for all types of cells
29+
for (int i = 0; i < 4; ++i) { /// for all types of cells
30+
31+
/// # 2 # Measures: fractions and entropies
32+
if(i == 1 && charlabs_edges.size() > 0) { // Edges lab
33+
if (charlabs_edges.at(0) == 1) {
34+
vector<int> EdgeTypes_char(CellNumbs.at(1 + (dim - 3)),
35+
0); // vector<int> in the form [ 0 2 3 3 2 1 ...] with the TJs type ID as its values
36+
std::vector<double> j_edge_fractions(dim + 1, 0), d_edge_fractions(dim,
37+
0); // fractions of (1) edges of different types and (2) edges of different degrees
38+
39+
/// for each state:
40+
tuple<double, double> conf_entropy_t;
41+
for (auto current_seq: PCC_characteristics.face_process_seq) {
42+
EdgeTypes_char.clear();
43+
std::fill(j_edge_fractions.begin(), j_edge_fractions.end(), 0);
44+
std::fill(d_edge_fractions.begin(), d_edge_fractions.end(), 0);
45+
46+
EdgeTypes_char = Edge_types_byFaces(CellNumbs, current_seq, j_edge_fractions, d_edge_fractions);
47+
48+
conf_entropy_t = Configuration_Entropy_tuple(j_edge_fractions); // conf entropy
49+
50+
PCC_characteristics.e_entropy_mean_vector.push_back(std::get<0>(
51+
conf_entropy_t)); // std::tuple<double, double> Configuration_Entropy_tuple(std::vector<double> const &j_fractions) based on Edges fraction vector
52+
PCC_characteristics.e_entropy_skrew_vector.push_back(std::get<1>(conf_entropy_t)); // tuple
53+
//// MUST BE IMPROVED (!) :
54+
PCC_characteristics.e_entropy_full_vector.push_back(
55+
std::get<0>(conf_entropy_t) + std::get<1>(conf_entropy_t));
56+
57+
PCC_characteristics.je_fractions_vector.push_back(j_edge_fractions);
58+
PCC_characteristics.de_fractions_vector.push_back(d_edge_fractions);
59+
} // for (auto current_seq : PCC_characteristics.face_process_seq)
60+
61+
if (charlabs_edges.at(4) == 1) { // analytical
62+
/// Measures: Analytical solutions for edge fractions and configuration entropies
63+
std::vector<tuple<double, double>> AnalyticalRandEntropies, AnalyticalCrystEntropies;
64+
PCC_characteristics.j_analytical_rand_vector = TJsAnalytics_random(CellNumbs.at(2 + (dim - 3)),
65+
AnalyticalRandEntropies);
66+
PCC_characteristics.AnRandEntropies_vector = AnalyticalRandEntropies;
67+
68+
PCC_characteristics.j_analytical_cryst_vector = TJsAnalytics_crystallography(
69+
CellNumbs.at(2 + (dim - 3)), AnalyticalCrystEntropies);
70+
PCC_characteristics.AnCrystEntropies_vector = AnalyticalCrystEntropies;
71+
72+
// analytical edge degree fractions
73+
PCC_characteristics.d_analytical_rand_vector = TJDsAnalytics_random(CellNumbs.at(2 + (dim - 3)));
74+
PCC_characteristics.d_analytical_cryst_vector = TJDsAnalytics_crystallography(
75+
CellNumbs.at(2 + (dim - 3)));
76+
} // enf if(charlabs_edges.at(4) == 1)
77+
78+
} // end of if(charlabs_edges.at(0) == 1)
79+
} // end of if(i == 1 && charlabs_edges.at(0) == 1) { // Edges lab
3080

31-
/// # 2 # Measures: fractions and entropies
32-
if(i == 1 && charlabs_edges.at(0) == 1) { // Edges lab
33-
vector<int> EdgeTypes_char(CellNumbs.at(1 + (dim - 3)), 0); // vector<int> in the form [ 0 2 3 3 2 1 ...] with the TJs type ID as its values
34-
std::vector<double> j_edge_fractions(dim+1,0), d_edge_fractions(dim,0); // fractions of (1) edges of different types and (2) edges of different degrees
35-
36-
/// for each state:
37-
tuple<double,double> conf_entropy_t;
38-
for (auto current_seq : PCC_characteristics.face_process_seq) {
39-
EdgeTypes_char.clear();
40-
std::fill(j_edge_fractions.begin(), j_edge_fractions.end(),0);
41-
std::fill(d_edge_fractions.begin(), d_edge_fractions.end(),0);
42-
43-
EdgeTypes_char = Edge_types_byFaces(CellNumbs, current_seq, j_edge_fractions, d_edge_fractions);
44-
45-
conf_entropy_t = Configuration_Entropy_tuple(j_edge_fractions); // conf entropy
46-
47-
PCC_characteristics.e_entropy_mean_vector.push_back(std::get<0>(conf_entropy_t)); // std::tuple<double, double> Configuration_Entropy_tuple(std::vector<double> const &j_fractions) based on Edges fraction vector
48-
PCC_characteristics.e_entropy_skrew_vector.push_back(std::get<1>(conf_entropy_t)); // tuple
49-
//// MUST BE IMPROVED (!) :
50-
PCC_characteristics.e_entropy_full_vector.push_back( std::get<0>(conf_entropy_t) + std::get<1>(conf_entropy_t));
51-
52-
PCC_characteristics.je_fractions_vector.push_back(j_edge_fractions);
53-
PCC_characteristics.de_fractions_vector.push_back(d_edge_fractions);
54-
}
55-
56-
if(charlabs_edges.at(4) == 1) { // analytical
57-
/// Measures: Analytical solutions for edge fractions and configuration entropies
58-
std::vector<tuple<double, double>> AnalyticalRandEntropies, AnalyticalCrystEntropies;
59-
PCC_characteristics.j_analytical_rand_vector = TJsAnalytics_random(CellNumbs.at(2 + (dim - 3)), AnalyticalRandEntropies);
60-
PCC_characteristics.AnRandEntropies_vector = AnalyticalRandEntropies;
61-
62-
PCC_characteristics.j_analytical_cryst_vector = TJsAnalytics_crystallography(CellNumbs.at(2 + (dim - 3)), AnalyticalCrystEntropies);
63-
PCC_characteristics.AnCrystEntropies_vector = AnalyticalCrystEntropies;
64-
65-
// analytical edge degree fractions
66-
PCC_characteristics.d_analytical_rand_vector = TJDsAnalytics_random(CellNumbs.at(2 + (dim - 3)));
67-
PCC_characteristics.d_analytical_cryst_vector = TJDsAnalytics_crystallography(CellNumbs.at(2 + (dim - 3)));
68-
} // enf if(charlabs_edges.at(4) == 1)
69-
70-
} // if(i == 1 && charlabs_edges.at(0) == 1) { // Edges lab
7181
} // end for (int i = 0; i < 4; ++i)
7282

83+
/// # 3 # Laplacians of specail cells
84+
if(charlabs_laplacians.at(1) == 1) {
85+
// AN - Nodes (Vertices or 0-Cells) sparse adjacency matrix in the form of three column {i, j, value}, where i and j are the indices of elements with non-zero values
86+
// AE - Edges (Triple Junctions or 1-Cells) sparse adjacency matrix in the form of three column {i, j, value}, where i and j are the indices of elements with non-zero values
87+
// AF - Faces (Grain Boundaries or 2-Cells) sparse adjacency matrix in the form of three column {i, j, value}, where i and j are the indices of elements with non-zero values
88+
// AG - Grains (Volumes or 3-Cells) sparse adjacency matrix in the form of three column {i, j, value}, where i and j are the indices of elements with non-zero values
89+
// MEN - Edges - Nodes (1-Cells to 0-Cells) sparse incidence matrix in the form of three column {i, j, value}, where i and j are the indices of elements with non-zero values
90+
// MFE - Faces - Edges (2-Cells to 1-Cells) sparse incidence matrix in the form of three column {i, j, value}, where i and j are the indices of elements with non-zero values
91+
// MGF - Grains - Faces (3-Cells to 2-Cells) sparse incidence matrix in the form of three column {i, j, value}, where i and j are the indices of elements with non-zero values // odir - source path
92+
93+
/// Adjacency sparse matrix for nodes /// Adjacency sparse matrix for edges /// Adjacency sparse matrix for faces /// Adjacency sparse matrix for grains
94+
// SpMat ANS(CellNumbs.at(0), CellNumbs.at(0)), AES(CellNumbs.at(1 + (dim - 3)), CellNumbs.at(1 + (dim - 3))), AFS(CellNumbs.at(2 + (dim - 3)), CellNumbs.at(2 + (dim - 3))), AGS(CellNumbs.at(3 + (dim - 3)), CellNumbs.at(3 + (dim - 3)));
95+
// ANS = SMatrixReader(paths.at(0), (CellNumbs.at(0)), (CellNumbs.at(0))); //all Nodes
96+
// ANS = 0.5 * (ANS + SparseMatrix<double>(ANS.transpose())); // Full matrix instead of triagonal
97+
// AES = SMatrixReader(paths.at(1 + (dim - 3)), (CellNumbs.at(1 + (dim - 3))), (CellNumbs.at(1 + (dim - 3)))); //all Edges
98+
// AES = 0.5 * (AES + SparseMatrix<double>(AES.transpose())); // Full matrix instead of triagonal
99+
// AFS = SMatrixReader(paths.at(2 + (dim - 3)), (CellNumbs.at(2 + (dim - 3))), (CellNumbs.at(2 + (dim - 3)))); //all Faces
100+
// AFS = 0.5 * (AFS + SparseMatrix<double>(AFS.transpose())); // Full matrix instead of triagonal
101+
// AGS = SMatrixReader(paths.at(3 + (dim - 3)), (CellNumbs.at(3 + (dim - 3))), (CellNumbs.at(3 + (dim - 3)))); //all Volumes
102+
// AGS = 0.5 * (AGS + SparseMatrix<double>(AGS.transpose())); // Full matrix instead of triagonal
103+
104+
/// Incidence sparse matrix for Edges and Nodes /// Incidence sparse matrix for Faces and Edges /// Incidence sparse matrix for Grains and Faces
105+
SpMat ENS(CellNumbs.at(0), CellNumbs.at(1)), FES(CellNumbs.at(1 + (dim - 3)), CellNumbs.at(2 + (dim - 3))), GFS(
106+
CellNumbs.at(2 + (dim - 3)), CellNumbs.at(3 + (dim - 3)));
107+
108+
ENS = SMatrixReader(paths.at(4 + (dim - 3)), (CellNumbs.at(0)), (CellNumbs.at(1))); //all Nodes-Edges
109+
FES = SMatrixReader(paths.at(5 + (dim - 3)), (CellNumbs.at(1 + (dim - 3))),
110+
(CellNumbs.at(2 + (dim - 3)))); //all Edges-Faces
111+
GFS = SMatrixReader(paths.at(6 + (dim - 3)), (CellNumbs.at(2 + (dim - 3))),
112+
(CellNumbs.at(3 + (dim - 3)))); //all Faces-Grains
113+
114+
double number_of_steps = (double) charlabs_laplacians.at(0); // reading from Characterisation.ini file (!)
115+
unsigned int d_seq = std::floor((double) PCC_characteristics.face_process_seq.size() / number_of_steps);
116+
std::vector<unsigned int> new_current_seq;
117+
std::vector<double> new_Betti_numbers;
118+
119+
std::vector<unsigned int> Betti_calc_time;
120+
121+
#pragma omp parallel for // parallel execution by OpenMP
122+
for (unsigned int i = 0; i <= number_of_steps; ++i) {
123+
new_current_seq = PCC_characteristics.face_process_seq.at(i*d_seq);
124+
cout << "---------------------------------------------------------------------------" << endl;
125+
cout << "[CHAR] Current special faces fraction: " << new_current_seq.size()/ (double) CellNumbs.at(2 + (dim - 3)) << endl;
126+
Out_logfile_stream << "---------------------------------------------------------------------------" << endl;
127+
Out_logfile_stream << "[CHAR] Current special faces fraction: " << new_current_seq.size()/ (double) CellNumbs.at(2 + (dim - 3)) << endl;
128+
// Elapsing time for 3 Betti numbers
129+
clock_t t;
130+
Betti_calc_time.push_back(clock());
131+
132+
new_Betti_numbers = OperatorsBetti(new_current_seq, ENS, FES, GFS);
133+
cout << "[CHAR] p & Betti numbers: " << new_current_seq.size()/ (double) CellNumbs.at(2) << " " << new_Betti_numbers.at(0) << " " << new_Betti_numbers.at(1) << " " << new_Betti_numbers.at(2) << endl;
134+
Out_logfile_stream << "[CHAR] p & Betti numbers: " << new_current_seq.size()/ (double) CellNumbs.at(2) << " " << new_Betti_numbers.at(0) << " " << new_Betti_numbers.at(1) << " " << new_Betti_numbers.at(2) << endl;
135+
//
136+
Betti_calc_time.back() = clock() - Betti_calc_time.back();
137+
cout << "[CHAR] Calculation time [s] of the Betti numbers is equal to " << Betti_calc_time.back()/ pow(10.0,6.0)<< endl;
138+
Out_logfile_stream << "[CHAR] Calculation time [s] of the Betti numbers is equal to " << Betti_calc_time.back()/ pow(10.0,6.0)<< endl;
139+
140+
PCC_characteristics.Betti_vector.push_back({new_current_seq.size()/(double) CellNumbs.at(2), new_Betti_numbers.at(0), new_Betti_numbers.at(1), new_Betti_numbers.at(2)});
141+
}
142+
} // end of for (int i = 0; i < number_of_steps, ++i)
73143
return PCC_characteristics;
74144
}

src/lib/PCC_Objects.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,18 +695,22 @@ class ProcessedComplex { // Essential for Characterisation module
695695
pcc_design = pcc_design;
696696
}
697697

698+
// Sequences of special k-cells
698699
std::vector<vector<unsigned int>> face_process_seq;
699700
std::vector<vector<int>> face_process_state;
700701

702+
// Entropic analysis
701703
std::vector<double> e_entropy_mean_vector, e_entropy_skrew_vector, e_entropy_full_vector;
702-
703704
std::vector<vector<double>> je_fractions_vector, de_fractions_vector;
704705

705-
// analytical solutions
706+
// Analytical solutions
706707
std::vector<vector<double>> j_analytical_rand_vector, d_analytical_rand_vector;
707708
std::vector<vector<double>> j_analytical_cryst_vector, d_analytical_cryst_vector;
708709
std::vector<tuple<double, double>> AnRandEntropies_vector, AnCrystEntropies_vector;
709710

711+
// Laplacian lab
712+
std::vector<std::vector<double>> Betti_vector;
713+
710714
}; /// end of class ProcessedComplex
711715

712716
#endif

src/lib/PCC_Writer/PCC_Writer.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ config_reader_writer(source_path, writer_specifications, Out_logfile_stream); //
1616
int output_counter = 0; // special counter for output numeration
1717

1818
/// Output special and ordinary face sequences to the output directory specified in config.txt
19-
PCC_CellSequences_Writer(new_cells_design, output_counter);
20-
PCC_Entropic_Writer(pcc_processed, output_counter);
21-
PCC_AnalyticalFractions_Writer(pcc_processed, output_counter); // analytical solutions
19+
if (writer_specifications.at(0) == 1)
20+
PCC_CellSequences_Writer(new_cells_design, output_counter);
21+
if (writer_specifications.at(2) == 1)
22+
PCC_Entropic_Writer(pcc_processed, output_counter);
23+
if (writer_specifications.at(5) == 1)
24+
PCC_AnalyticalFractions_Writer(pcc_processed, output_counter); // analytical solutions
25+
if(writer_specifications.at(7) == 1)
26+
PCC_Laplacians_Writer(pcc_processed, output_counter);
2227

2328
/*
2429
char* stype = const_cast<char*>(P_type.c_str()); // Processing type variable

src/lib/PCC_Writer/Writer_Functions.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ void PCC_AnalyticalFractions_Writer(ProcessedComplex &pcc_processed, int &output
175175

176176
} // END of PCC_AnalyticalFractions_Writer( )
177177

178+
void PCC_Laplacians_Writer(ProcessedComplex &pcc_processed, int &output_counter) {
179+
ofstream OutBettiFile; // Betti numbers output
180+
string betti_odir = output_dir + "Betti numbers.txt"s; // output directory
181+
182+
for (auto BV : pcc_processed.Betti_vector)
183+
OutBettiFile << BV.at(0) << " " << BV.at(1) << " " << BV.at(2) << " " << BV.at(3) << endl;
184+
185+
OutBettiFile.close();
186+
187+
cout << "(" << output_counter++ << ") " << "Betti numbers of the special cell structure evolution has been successfully written in " << betti_odir << endl;
188+
Out_logfile_stream << "(" << output_counter << ") " << "Betti numbers of the special cell structure evolution has been successfully written in " << betti_odir << endl;
189+
} // END of PCC_Laplacians_Writer()
190+
178191
/// * NEW HEAP * ///
179192

180193
/**

0 commit comments

Comments
 (0)