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

Open
wants to merge 3 commits into
base: issue-432
Choose a base branch
from
Open

Move all print statements to execute() #435

wants to merge 3 commits into from

Conversation

icui
Copy link
Collaborator

@icui icui commented Jan 24, 2025

Issue Number

Closes #434

@@ -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.

Comment on lines +13 to +19
void print(std::ostream &out) const {
out << " Quadrature in X-dimension \n";
gll.print(out);

out << " Quadrature in Z-dimension \n";
gll.print(out);
}
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.

@@ -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.

Copy link
Collaborator

@lsawade lsawade left a comment

Choose a reason for hiding this comment

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

I like this otherwise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants