Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean screen output #301

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/em_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class ElectromagneticOptions {

bool eval_Rplasma;

int print_level;

ElectromagneticOptions() {
order = 1;
ref_levels = 0;
Expand All @@ -86,6 +88,7 @@ class ElectromagneticOptions {
current_frequency = 1.0;
mu0 = 1.0;
eval_Rplasma = false;
print_level = 0;
}

void print(std::ostream &out) {
Expand All @@ -108,6 +111,7 @@ class ElectromagneticOptions {
out << " current_frequency = " << current_frequency << std::endl;
out << " mu0 = " << mu0 << std::endl;
out << " eval_Rplasma = " << eval_Rplasma << std::endl;
out << " print_level = " << print_level << std::endl;
out << std::endl;
}
};
Expand Down
13 changes: 8 additions & 5 deletions src/quasimagnetostatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ void QuasiMagnetostaticSolver3D::parseSolverOptions() {
tpsP_->getVec("em/current_axis", em_opts_.current_axis, 3, default_axis);

tpsP_->getInput("em/eval_Rplasma", em_opts_.eval_Rplasma, false);
tpsP_->getInput("em/print_level", em_opts_.print_level, 0);

// dump options to screen for user inspection
if (rank0_) {
Expand Down Expand Up @@ -449,7 +450,7 @@ void QuasiMagnetostaticSolver3D::solveStep() {
solver.SetRelTol(em_opts_.rtol);
solver.SetAbsTol(em_opts_.atol);
solver.SetMaxIter(em_opts_.max_iter);
solver.SetPrintLevel(1);
solver.SetPrintLevel(em_opts_.print_level);

solver.Mult(rhs, Avec);

Expand Down Expand Up @@ -498,7 +499,7 @@ void QuasiMagnetostaticSolver3D::solveStep() {

{ /*open scope so that ParaViewDataCollection is destroyed before Ereal_, Eimag_ if needed*/
// 3) Output A and B fields for visualization using paraview
if (verbose) grvy_printf(ginfo, "Writing solution to paraview output.\n");
if (verbose && em_opts_.print_level > 0) grvy_printf(ginfo, "Writing solution to paraview output.\n");
ParaViewDataCollection paraview_dc("magnetostatic", pmesh_);
paraview_dc.SetPrefixPath("ParaView");
paraview_dc.SetLevelsOfDetail(em_opts_.order);
Expand Down Expand Up @@ -777,7 +778,7 @@ void QuasiMagnetostaticSolverAxiSym::initialize() {
//-----------------------------------------------------

// 1a) Read the serial mesh (on each mpi rank)
std::cout << "Reading mesh = " << em_opts_.mesh_file.c_str() << std::endl;
if (verbose) grvy_printf(ginfo, "Reading EM mesh file: %s\n", em_opts_.mesh_file.c_str());
Mesh *mesh = new Mesh(em_opts_.mesh_file.c_str(), 1, 1);
dim_ = mesh->Dimension();
if (dim_ != 2) {
Expand Down Expand Up @@ -1007,6 +1008,8 @@ void QuasiMagnetostaticSolverAxiSym::solveStep() {
Kpre->FormSystemMatrix(ess_bdr_tdofs_, KpreOp);

std::unique_ptr<HypreBoomerAMG> prec(new HypreBoomerAMG(*KpreOp.As<HypreParMatrix>()));
prec->SetPrintLevel(em_opts_.print_level);

BlockDiagonalPreconditioner BDP(offsets_);
BDP.SetDiagonalBlock(0, prec.get());
BDP.SetDiagonalBlock(1, prec.get());
Expand All @@ -1019,7 +1022,7 @@ void QuasiMagnetostaticSolverAxiSym::solveStep() {
solver.SetRelTol(em_opts_.rtol);
solver.SetAbsTol(em_opts_.atol);
solver.SetMaxIter(em_opts_.max_iter);
solver.SetPrintLevel(1);
solver.SetPrintLevel(em_opts_.print_level);

solver.Mult(rhs_vec, Atheta_vec);

Expand Down Expand Up @@ -1051,7 +1054,7 @@ void QuasiMagnetostaticSolverAxiSym::solveStep() {
}

// 3) Output A and B fields for visualization using paraview
if (verbose) grvy_printf(ginfo, "Writing solution to paraview output.\n");
if (verbose && em_opts_.print_level > 0) grvy_printf(ginfo, "Writing solution to paraview output.\n");
ParaViewDataCollection paraview_dc("magnetostatic", pmesh_);
paraview_dc.SetPrefixPath("ParaView");
paraview_dc.SetLevelsOfDetail(em_opts_.order);
Expand Down
11 changes: 9 additions & 2 deletions src/tps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,22 @@ void Tps::getInput(const char *name, T &var, T varDefault) {
void Tps::getVec(const char *name, Vector &vec, size_t numElems, const Vector &vdef) {
if ((size_t)vdef.Size() < numElems) exit(ERROR);
if ((size_t)vec.Size() < numElems) vec.SetSize(numElems);

// To avoid grvy chattiness from Read_Var_Vec, set log level to
// GRVY_NOLOG, just for this call. Reset below to previous value.
const int grvy_log_level = grvy_log_getlevel();
grvy_log_setlevel(GRVY_NOLOG);

if (!iparse_.Read_Var_Vec(name, vec.HostWrite(), numElems)) {
grvy_printf(GRVY_INFO, "Setting input vector %s to default.", name);
grvy_log_setlevel(grvy_log_level);
if (isRank0_) grvy_printf(GRVY_INFO, "Setting input vector %s to default.\n", name);
double *hv = vec.HostWrite();
const double *hd = vdef.HostRead();
for (size_t i = 0; i < numElems; i++) {
hv[i] = hd[i];
}
}
grvy_log_setlevel(grvy_log_level);
}

/** Read an input value for keyword [name] and store in var. If
Expand All @@ -364,7 +372,6 @@ void Tps::getRequiredInput(const char *name, T &var) {
std::cout << "ERROR: Unable to read required input variable -> " << name << std::endl;
exit(ERROR);
}
return;
}

/** \brief Input parsing for vector quantities that must be provided.
Expand Down
Loading