Skip to content

Commit 28feaa1

Browse files
committed
Unify formatting
1 parent b7d992f commit 28feaa1

5 files changed

Lines changed: 31 additions & 29 deletions

File tree

include/MaterialManager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ class MaterialManager {
111111
compute_reference_stiffness(reader);
112112

113113
// Print detailed information about material configuration for logging
114-
Log::io->info() << "\n# MaterialManager initialized:\n";
114+
Log::io->info() << "\n";
115+
Log::io->info() << "# MaterialManager initialized:\n";
115116
Log::io->info() << Log::format("# Number of material models: %zu\n", models.size());
116-
Log::io->info() << Log::format("# Number of phases: %d\n#\n", n_phases);
117+
Log::io->info() << Log::format("# Number of phases: %d\n", n_phases);
118+
Log::io->info() << "#\n";
117119

118120
for (size_t i = 0; i < mats.size(); ++i) {
119121
const auto &mg = mats[i];

include/solver.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Solver : private MixedBCController<howmany> {
6161
void postprocess(Reader &reader, int load_idx, int time_idx); //!< Computes Strain and stress
6262

6363
void convolution();
64-
double compute_error(RealArray &r);
64+
double compute_error(RealArray &r, bool has_log_prefix = false);
6565
void CreateFFTWPlans(double *in, fftw_complex *transformed, double *out);
6666

6767
VectorXd homogenized_strain;
@@ -151,7 +151,8 @@ Solver<howmany, n_str>::Solver(Reader &reader, MaterialManager<howmany, n_str> *
151151
template <int howmany, int n_str>
152152
void Solver<howmany, n_str>::computeFundamentalSolution()
153153
{
154-
Log::solver->info() << "\n# Start creating Fundamental Solution(s) \n";
154+
Log::solver->info() << "\n";
155+
Log::solver->info() << "# Start creating Fundamental Solution(s) \n";
155156
clock_t tot_time = clock();
156157

157158
Matrix<double, howmany * 8, howmany * 8> Ker0 = matmanager->models[0]->Compute_Reference_ElementStiffness(matmanager->kapparef_mat);
@@ -412,7 +413,7 @@ void Solver<howmany, n_str>::convolution()
412413
}
413414

414415
template <int howmany, int n_str>
415-
double Solver<howmany, n_str>::compute_error(RealArray &r)
416+
double Solver<howmany, n_str>::compute_error(RealArray &r, const bool has_log_prefix)
416417
{
417418
double err_local;
418419
const std::string &measure = reader.errorParameters["measure"].get<std::string>();
@@ -436,7 +437,7 @@ double Solver<howmany, n_str>::compute_error(RealArray &r)
436437
if (iter == 0) {
437438
Log::solver->info() << Log::format("Before 1st iteration: %16.8e\n", err0);
438439
} else {
439-
Log::solver->info(true) << Log::format("it %3lu .... err %16.8e / %8.4e, ratio: %4.8e, FFT time: %2.6f sec\n", iter, err, err / err0, (iter == 1 ? 0.0 : err / err_all[iter - 1]), double(buftime) / CLOCKS_PER_SEC);
440+
Log::solver->info(has_log_prefix) << Log::format("it %3lu .... err %16.8e / %8.4e, ratio: %4.8e, FFT time: %2.6f sec\n", iter, err, err / err0, (iter == 1 ? 0.0 : err / err_all[iter - 1]), double(buftime) / CLOCKS_PER_SEC);
440441
}
441442

442443
const std::string &error_type = reader.errorParameters["type"].get<std::string>();
@@ -692,12 +693,11 @@ void Solver<howmany, n_str>::postprocess(Reader &reader, int load_idx, int time_
692693
// Compute homogenized tangent only if requested
693694
if (find(reader.resultsToWrite.begin(), reader.resultsToWrite.end(), "homogenized_tangent") != reader.resultsToWrite.end()) {
694695
homogenized_tangent = get_homogenized_tangent(1e-6);
695-
hsize_t dims[2] = {static_cast<hsize_t>(n_str), static_cast<hsize_t>(n_str)};
696-
if (world_rank == 0) {
697-
Log::solver->info() << "# Homogenized tangent: \n"
698-
<< std::setprecision(12) << homogenized_tangent
699-
<< std::defaultfloat << "\n\n";
700-
}
696+
hsize_t dims[2] = {static_cast<hsize_t>(n_str), static_cast<hsize_t>(n_str)};
697+
IOFormat tangent_format{StreamPrecision, 0, " ", "\n", "\t\t"};
698+
Log::solver->info() << "# Homogenized tangent: \n"
699+
<< std::setprecision(12) << homogenized_tangent.format(tangent_format)
700+
<< std::defaultfloat << "\n\n";
701701
reader.writeData("homogenized_tangent", load_idx, time_idx, homogenized_tangent.data(), dims, 2);
702702
}
703703
}

include/solverCG.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ double SolverCG<howmany, n_str>::dotProduct(RealArray &a, RealArray &b)
6363
template <int howmany, int n_str>
6464
void SolverCG<howmany, n_str>::internalSolve()
6565
{
66-
Log::solver->info() << "\t# Start FANS - Conjugate Gradient Solver \n";
66+
Log::solver->info() << "\n";
67+
Log::solver->info() << "# Start FANS - Conjugate Gradient Solver \n";
6768

6869
bool islinear = this->matmanager->all_linear;
6970
alpha_warm = 0.1;
@@ -92,7 +93,8 @@ void SolverCG<howmany, n_str>::internalSolve()
9293
delta0 = delta;
9394
delta = dotProduct(v_r_real, s_real);
9495

95-
if (islinear && !this->isMixedBCActive()) {
96+
const bool no_lss = islinear && !this->isMixedBCActive();
97+
if (no_lss) {
9698
d_real = s_real + fmax(0.0, (delta - deltamid) / delta0) * d_real;
9799
Matrix<double, howmany * 8, 1> res_e;
98100
this->template compute_residual_basic<0>(rnew_real, d_real,
@@ -111,7 +113,7 @@ void SolverCG<howmany, n_str>::internalSolve()
111113
}
112114

113115
iter++;
114-
err_rel = this->compute_error(v_r_real);
116+
err_rel = this->compute_error(v_r_real, not no_lss);
115117

116118
if (iter >= 2 && this->err_all[iter] > this->err_all[iter - 1] && this->err_all[iter - 1] > this->err_all[iter - 2])
117119
ls_converged = false; // Force a CG restart

include/solverFP.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ void SolverFP<howmany, n_str>::internalSolve()
5050
iter++;
5151
err_rel = this->compute_error(v_r_real);
5252
}
53-
if (this->world_rank == 0)
54-
Log::solver->info() << "# Complete FANS - Fixed Point Solver \n";
53+
Log::solver->info() << "# Complete FANS - Fixed Point Solver \n";
5554
}
5655
#endif

src/reader.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,17 @@ void Reader ::ReadMS(int hm)
288288
l_e[1] = L[1] / double(dims[1]);
289289
l_e[2] = L[2] / double(dims[2]);
290290

291-
if (world_rank == 0) {
292-
Log::io->info() << Log::format("# grid size set to [%i x %i x %i] --> %i voxels \nMicrostructure length: [%3.6f x %3.6f x %3.6f]\n", dims[0], dims[1], dims[2], dims[0] * dims[1] * dims[2], L[0], L[1], L[2]);
293-
if (dims[0] % 2 != 0)
294-
Log::io->error() << "[ FANS3D_Grid ] WARNING: n_x is not a multiple of 2\n";
295-
if (dims[1] % 2 != 0)
296-
Log::io->error() << "[ FANS3D_Grid ] WARNING: n_y is not a multiple of 2\n";
297-
if (dims[2] % 2 != 0)
298-
Log::io->error() << "[ FANS3D_Grid ] WARNING: n_z is not a multiple of 2\n";
299-
if (dims[0] / 4 < world_size)
300-
throw std::runtime_error("[ FANS3D_Grid ] ERROR: Please decrease the number of processes or increase the grid size to ensure that each process has at least 4 boxels in the x direction.");
301-
Log::io->info() << Log::format("Voxel length: [%1.8f, %1.8f, %1.8f]\n", l_e[0], l_e[1], l_e[2]);
302-
}
291+
Log::io->info() << Log::format("# grid size set to [%i x %i x %i] --> %i voxels \n", dims[0], dims[1], dims[2], dims[0] * dims[1] * dims[2]);
292+
Log::io->info() << Log::format("Microstructure length: [%3.6f x %3.6f x %3.6f]\n", L[0], L[1], L[2]);
293+
if (dims[0] % 2 != 0)
294+
Log::io->error() << "[ FANS3D_Grid ] WARNING: n_x is not a multiple of 2\n";
295+
if (dims[1] % 2 != 0)
296+
Log::io->error() << "[ FANS3D_Grid ] WARNING: n_y is not a multiple of 2\n";
297+
if (dims[2] % 2 != 0)
298+
Log::io->error() << "[ FANS3D_Grid ] WARNING: n_z is not a multiple of 2\n";
299+
if (dims[0] / 4 < world_size)
300+
throw std::runtime_error("[ FANS3D_Grid ] ERROR: Please decrease the number of processes or increase the grid size to ensure that each process has at least 4 boxels in the x direction.");
301+
Log::io->info() << Log::format("Voxel length: [%1.8f, %1.8f, %1.8f]\n", l_e[0], l_e[1], l_e[2]);
303302

304303
const ptrdiff_t n[3] = {dims[0], dims[1], dims[2] / 2 + 1};
305304
ptrdiff_t block0 = FFTW_MPI_DEFAULT_BLOCK;

0 commit comments

Comments
 (0)