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

Move all print statements to execute() #435

Draft
wants to merge 3 commits into
base: issue-432
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions include/IO/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ namespace IO {
specfem::mesh::mesh<specfem::dimension::type::dim2>
read_mesh(const std::string filename, const specfem::MPI::MPI *mpi);

/**
* @brief Print the information of a mesh
*
* @param mesh Mesh object to print
* @param mpi pointer to MPI object to manage communication
* @return specfem::mesh::mesh Specfem mesh object
*
*/
void print_mesh(const specfem::mesh::mesh<specfem::dimension::type::dim2> &mesh,
const specfem::MPI::MPI *mpi);

/**
* @brief Read station file
*
Expand Down
11 changes: 11 additions & 0 deletions include/quadrature/quadratures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ struct quadratures {
specfem::quadrature::gll::gll gll;

quadratures(const specfem::quadrature::gll::gll &gll) : gll(gll) {}

void print(std::ostream &out) const {
out << " Quadrature in X-dimension \n";
gll.print(out);

out << " Quadrature in Z-dimension \n";
gll.print(out);
}
Comment on lines +13 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::cout << gll has already been defined, but at this stage not declared. I could use some help on the import order.

};

std::ostream &operator<<(std::ostream &out,
const specfem::quadrature::quadratures &quad);
} // namespace quadrature
} // namespace specfem

Expand Down
37 changes: 24 additions & 13 deletions src/IO/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,40 @@ specfem::IO::read_mesh(const std::string filename,

stream.close();

// Print material properties
const auto &l_elastic_isotropic =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a separate print mesh function, the osstream operator could be overloaded like so:

class A {
    int val;
public:
    A(int v) : val(v) {}
    friend ostream& operator<<(ostream& os, const A& obj) {
        os << obj.val;
        return os;
    }
};

then you can just

std::cout << mesh << std::endl;

Copy link
Collaborator Author

@icui icui Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we define std::cout << mesh, it should call mesh.print(), which is already defined and prints different stuff.

mesh.materials.elastic_isotropic.material_properties;
const auto &l_acoustic_isotropic =
mesh.materials.acoustic_isotropic.material_properties;

const auto &l_elastic_anisotropic =
mesh.materials.elastic_anisotropic.material_properties;

assert(l_elastic_isotropic.size() + l_acoustic_isotropic.size() +
l_elastic_anisotropic.size() ==
mesh.materials.n_materials);

mesh.tags = specfem::mesh::tags<specfem::dimension::type::dim2>(
mesh.materials, mesh.boundaries);

return mesh;
}

void specfem::IO::print_mesh(
const specfem::mesh::mesh<specfem::dimension::type::dim2> &mesh,
const specfem::MPI::MPI *mpi) {

mpi->cout("Material systems:\n"
"------------------------------");

mpi->cout("Number of material systems = " +
std::to_string(mesh.materials.n_materials) + "\n\n");

const auto l_elastic_isotropic =
const auto &l_elastic_isotropic =
mesh.materials.elastic_isotropic.material_properties;
const auto l_acoustic_isotropic =
const auto &l_acoustic_isotropic =
mesh.materials.acoustic_isotropic.material_properties;

const auto l_elastic_anisotropic =
const auto &l_elastic_anisotropic =
mesh.materials.elastic_anisotropic.material_properties;

for (const auto material : l_elastic_isotropic) {
Expand All @@ -212,13 +232,4 @@ specfem::IO::read_mesh(const std::string filename,
for (const auto material : l_elastic_anisotropic) {
mpi->cout(material.print());
}

assert(l_elastic_isotropic.size() + l_acoustic_isotropic.size() +
l_elastic_anisotropic.size() ==
mesh.materials.n_materials);

mesh.tags = specfem::mesh::tags<specfem::dimension::type::dim2>(
mesh.materials, mesh.boundaries);

return mesh;
}
10 changes: 5 additions & 5 deletions src/IO/mesh/impl/fortran/read_material_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ std::vector<specfem::mesh::materials::material_specification> read_materials(
std::vector<specfem::mesh::materials::material_specification> index_mapping(
numat);

message << "Material systems:\n"
<< "------------------------------";
// message << "Material systems:\n"
// << "------------------------------";

mpi->cout(message.str());
// mpi->cout(message.str());

if (mpi->get_rank() == 0)
std::cout << "Number of material systems = " << numat << "\n\n";
// if (mpi->get_rank() == 0)
// std::cout << "Number of material systems = " << numat << "\n\n";

// Section for elastic isotropic
std::vector<specfem::medium::material<elastic, isotropic> >
Expand Down
11 changes: 9 additions & 2 deletions src/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ void execute(
// --------------------------------------------------------------
// Read mesh and materials
// --------------------------------------------------------------
const auto quadrature = setup.instantiate_quadrature();
const auto quadratures = setup.instantiate_quadrature();
if (mpi->main_proc()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the options are two, either you check here whether it's the main_proc() and then use the ostream << overload, or you parse mpi check locally if you are on main_proc and return if you aren't.

What do you think? Am i forgetting something?

Option 3:
the struct should all have the osstream overload. mpi->cout should really check whether you are on main proc.

std::cout << quadratures << std::endl;
}

const auto mesh = specfem::IO::read_mesh(database_filename, mpi);
if (mpi->main_proc()) {
specfem::IO::print_mesh(mesh, mpi);
}
// --------------------------------------------------------------

// --------------------------------------------------------------
Expand Down Expand Up @@ -101,7 +108,7 @@ void execute(
mpi->cout("-------------------------------");
const type_real dt = setup.get_dt();
specfem::compute::assembly assembly(
mesh, quadrature, sources, receivers, setup.get_seismogram_types(),
mesh, quadratures, sources, receivers, setup.get_seismogram_types(),
setup.get_t0(), dt, nsteps, max_seismogram_time_step,
nstep_between_samples, setup.get_simulation_type(),
setup.instantiate_property_reader());
Expand Down
6 changes: 0 additions & 6 deletions src/parameter_parser/quadrature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ specfem::runtime_configuration::quadrature::instantiate() {

specfem::quadrature::gll::gll gll(this->alpha, this->beta, this->ngll);

std::cout << " Quadrature in X-dimension \n";
std::cout << gll << std::endl;

std::cout << " Quadrature in Z-dimension \n";
std::cout << gll << std::endl;

return specfem::quadrature::quadratures(gll);
}

Expand Down
2 changes: 1 addition & 1 deletion src/parameter_parser/time_scheme/time_scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ specfem::runtime_configuration::time_scheme::time_scheme::instantiate(
}

// User output
std::cout << *it << "\n";
// std::cout << *it << "\n";

return it;
}
Expand Down
8 changes: 8 additions & 0 deletions src/quadrature/quadrature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ specfem::quadrature::operator<<(std::ostream &out,
return out;
}

std::ostream &
specfem::quadrature::operator<<(std::ostream &out,
const specfem::quadrature::quadratures &quad) {
quad.print(out);

return out;
}

void specfem::quadrature::quadrature::print(std::ostream &out) const {
out << "Quadrature wasn't initialized properly. Base class being called";

Expand Down
Loading