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

Add a function to retrieve the current last mesh generator #15125

Merged
merged 4 commits into from Apr 27, 2020

Conversation

YaqiWang
Copy link
Contributor

Close #15121.

@moosebuild
Copy link
Contributor

Job Precheck on 73766cd wanted to post the following:

Your code requires style changes.

A patch was auto generated and copied here
You can directly apply the patch by running, in the top level of your repository:

curl -s https://mooseframework.inl.gov/docs/PRs/15125/style.patch | git apply -v

Alternatively, with your repository up to date and in the top level of your repository:

git clang-format 77b75378dd3cd3e4eff8741383a1ff9f847c3ded

@YaqiWang YaqiWang force-pushed the get_final_mesh_generator branch 2 times, most recently from b40ee1f to 8cb44a5 Compare April 22, 2020 20:40
@moosebuild
Copy link
Contributor

moosebuild commented Apr 22, 2020

Job Documentation on 78fca05 wanted to post the following:

View the site here

This comment will be updated on new commits.

@YaqiWang
Copy link
Contributor Author

This is ready for review or merge.

Copy link
Member

@permcody permcody left a comment

Choose a reason for hiding this comment

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

I think appending is a good API to add, however, I would try to do it internally. Unless you have another use case I don't see why we can't refactor this a bit.

mooseError("Cannot append a mesh generator that does not take input mesh generators");

_moose_object_pars.set<MeshGeneratorName>("input") = _app.getCurrentFinalMeshGenerator();
_app.addMeshGenerator(_type, _name, _moose_object_pars);
Copy link
Member

Choose a reason for hiding this comment

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

Is this your use case, or do you expect others? The reason I ask is I don't see a reason to expose the name of the last generator at all if your use case is to add to the "end". A better design would be to add a new method called "appendMeshGenerators" that just does the appending internally. Exposing the end as you've done in this PR has issues. As you've already stated, it doesn't quite work correctly if the user also explicitly sets the final generator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are probably right. I do not need to expose this but rather create appendMeshGenerator function. Let me rewrite this PR.


std::string final_generator_name;
if (ordered_generators.size())
final_generator_name = ordered_generators.back().back()->name();
Copy link
Member

Choose a reason for hiding this comment

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

Rather than duplicate this logic, perhaps you could factor out this piece from the execute method and just call it from there? However, see my other comment below as I don't think you should expose this API at all. Especially if it's not always correct.

@YaqiWang
Copy link
Contributor Author

@permcody Your comments are addressed. I create a function appendMeshGenerator instead of expose the final mesh generator to users as you suggested. It indeed ends up with a better design. One small thing is that after ordered mesh generators are created, I should be able to clear the _mesh_generators member variable because it uses shared pointers. But I can not do it only after all mesh generators are executed. Maybe dependency resolver is not copying the shared pointers properly?

}
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially tried to delete _mesh_generators here after _ordered_generators is created. But got errors. So I end it up putting the clear at Line 1758.

Copy link
Member

Choose a reason for hiding this comment

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

Shared pointers are easy to copy. You just do normal assignment and you have a copy. As long as somebody is holding a pointer to the underlying object, it will not be deleted. So I don't see how a clear of one vector would cause errors unless it holds the only pointer to an object. What was the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think doing _mesh_generators.clear() after _ordered_generators is created seems deleted all mesh generators. All mesh generator tests failed. Once I moved the clear later after all mesh generators are executed, every test works fine. I did not look into it further. But seems inside DependencyResolver, shared pointer copying is not doing the right thing. I have no much experience with shared pointer though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw, the diff seems a lot, but I actually did not change much in the code.

Copy link
Member

Choose a reason for hiding this comment

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

The _mesh_generators vector is the "warehouse" for the generators. We don't have a second copy of those anywhere. They must not be cleared before execution.

Copy link
Member

Choose a reason for hiding this comment

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

The issue might be that _mesh_generators are accessed through public APIs. I bet there are some assumptions about getting access to the generators externally, which are probably where your errors come from.

@YaqiWang
Copy link
Contributor Author

@cody, if you do not care if the _mesh_modifiers can be cleared earlier or not, this PR is ready fore review again. Thanks.

permcody
permcody previously approved these changes Apr 23, 2020
framework/include/base/MooseApp.h Outdated Show resolved Hide resolved
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The issue might be that _mesh_generators are accessed through public APIs. I bet there are some assumptions about getting access to the generators externally, which are probably where your errors come from.

test/tests/meshgenerators/append_mesh_generator/tests Outdated Show resolved Hide resolved
@YaqiWang
Copy link
Contributor Author

@permcody can this be merged? Thanks.

permcody
permcody previously approved these changes Apr 27, 2020
framework/include/base/MooseApp.h Outdated Show resolved Hide resolved
@permcody
Copy link
Member

Looks like we forgot to drop the declaration for that one method. I'll merge this one complete.

@YaqiWang
Copy link
Contributor Author

Oh, my bad. Sorry.

@permcody permcody merged commit beb8f13 into idaholab:next Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supporting appending mesh generators with actions
3 participants