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

Refactoring problem creation to allow custom actions to create special problems #12060

Merged
merged 7 commits into from Sep 6, 2018

Conversation

YaqiWang
Copy link
Contributor

Close #12002.

I still need to add tests and docs. But want to test this and let you see what is in my mind. Tag @permcody @andrsd .

@YaqiWang
Copy link
Contributor Author

I do not understand why this PR runs fine on my local mac but fails on test boxes with this weird null feproblem pointer error...

@moosebuild
Copy link
Contributor

moosebuild commented Aug 30, 2018

Job Documentation on 060981b wanted to post the following:

View the site here

This comment will be updated on new commits.

@YaqiWang
Copy link
Contributor Author

oh, crap, I forgot check in two new files...

@YaqiWang YaqiWang force-pushed the redesign_create_problem branch 3 times, most recently from b61de47 to 2b3c28f Compare August 30, 2018 22:16
@moosebuild
Copy link
Contributor

Job Precheck on b61de47 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 http://mooseframework.inl.gov/docs/PRs/12060/style.patch | git apply -v

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

git clang-format ccf22351fc1719a0015c5eeaaa952f302f27eaeb

@permcody
Copy link
Member

You might consider grabbing the tests that I created. You'll have to modify the CreateSpecialProblemAction so that it just creates a problem but the rest of that should be good.

@YaqiWang
Copy link
Contributor Author

Yes, working on that. I also need to add all tests to meet the requirements you proposed.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Aug 30, 2018

This should be it. We possibly still need to polish it a little. The other few requirements without custom action has been tested by other tests so we do not need to test them here.

// Set the object parameters
InputParameters & params = action->getObjectParams();
params.set<bool>("solve") = false;
_action_factory.create("CreateProblemDefaultAction", "Problem", action_params));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

strange, this should fail because CreateProblemDefaultAction is no longer a moose object action. I will spend some time this weekend to polish this PR...

@YaqiWang YaqiWang force-pushed the redesign_create_problem branch 2 times, most recently from f8a5d36 to e162b60 Compare August 31, 2018 16:25
@YaqiWang
Copy link
Contributor Author

YaqiWang commented Aug 31, 2018

Rattlesnake fails because it adds a new action task after create_problem, which should be create_problem_complete with this PR. We will have to merge this first to patch Rattlesnake. I do not have access to Bighorn, looks like the error is real and I guess it is caused by kernel_coverage_check being moved to FEProblemBase with default value true. The tests can probably fixed by add Problem/kernel_coverage_check=false or change the default value to false in FEProblemBase, but it could be better to check the code to see if there is something not very right.

@permcody
Copy link
Member

permcody commented Sep 4, 2018

I don't immediately see why this is failing. My PR worked fine with Bighorn without changing any input files. The kernel coverage check should be fine being moved up into the Problem class.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 4, 2018

Right, even the default value in FEProblemBase before is false, it is reset to true by the CreateProblemAction before.

@@ -218,6 +222,9 @@ addActionTypes(Syntax & syntax)
"(setup_mesh_complete)"
"(determine_system_type)"
"(create_problem)"
"(create_problem_custom)"
"(create_problem_default)"
"(create_problem_complete)"
Copy link
Member

Choose a reason for hiding this comment

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

So if I create a [Problem] block, it seems like the first action would always create the problem with this design. The custom task would run after that and wouldn't take effect. How does this work?

If the design is to allow parameters from the [Problem] to be applied to a custom problem, I don't see how this is working. Should custom be first?

if (_problem)
{
// problem has been created by CreateProblemAction
if (_problem->type() != "MooseTestProblem")
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this looks right to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this particular action answers your question before. I think we want the input syntax to win always, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also means that the custom action needs to follow the similar pattern here for creating problems.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 4, 2018

Another thing I want to bring up is that maybe we want a normal action like SetProblemParametersAction with input syntax like [ProblemParameters] on create_problem_complete task, that accepts some of the parameters in FEProblemBase to give users second chance to change problem parameters. I can see its usage with custom actions, where users doe not have to use their own syntax to set problem parameters correctly but prefer to use this action to set them. If you think this is ok, I can add a commit on top to add this action.

@andrsd
Copy link
Contributor

andrsd commented Sep 4, 2018

I still think that problem parameters should be with the type = parameter. That's is the syntax we use. Think of a kernel of a custom type with its own parameters, the syntax is:

type = CustomKernel
param1 = something
param2 = something

Now because, the CustomKernel inherits from Kernel all these things have common parameters like variable, block, etc. The same holds for FEProblemBase-derived classes. There should not be an exception to this...

@permcody
Copy link
Member

permcody commented Sep 4, 2018

I agree with @andrsd. This was one of the requirements for this redesign: #12055 (comment)

We already have a [Problem] block, having a [ProblemParameters] block is very inconsistent with MOOSE. My PR solved this, it was possible to have parameters for the problem in the [Problem] block even when that block wasn't responsible for creating the actual problem (e.g. your custom problem creation). Now admittedly, my PR needs one more patch to make that work properly (and obviously a test), but it will work without requiring this separate block. It would be nice if you could figure out how to make this work if it's possible at all with your current design.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 4, 2018

A simple approach is to modify CreateProblemAction in my PR a little:

  1. create problem only when type is set by user;
  2. create a function like void applyProblemParameters(InputParameters & params) const that other actions can call to add parameters.

Then CreateProblemDefaultAction or custom actions can use this function to create the problem. How does this sound?

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 4, 2018

Just added one more commit. I think this works better. InputParameters has already a function applyParameters which does exactly what we want here. Getting CreateProblemAction is a little lengthy and code are duplicated, maybe we should create a function in ActionWarehouse like

  template <class T>
  const T * getActionOnTask(const std::string & task)

I can add this during addressing your possible other comments.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 4, 2018

@permcody can you review this? I want this to be pushed in and removed from my plate soon.

@permcody
Copy link
Member

permcody commented Sep 4, 2018

This is looking pretty good. I looked at Bighorn and it can be patched easily. I have one question on design. Do we really need all these tasks? determine_system_type, create_problem, create_problem_custom, create_problem_default, create_problem_complete.

In determine_system_type you are stashing info in the App which you pull later to create the problem. However, I think this step can simply be skipped since the very next action is create_problem. There's nothing in-between, not even the custom problem step.

Can the custom problem just fire on create_problem? It seems like yes because we have the apply parameters stuff in here, I could be convinced otherwise if the logic gets more complicated.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 4, 2018

CreateProblemAction uses MooseApp::useNonlinear(). But we cannot set useNonlinear there because it may not be created by the parser. So we will have to have a task before create_problem. On the other hand CreateProblemDefaultAction has to be fired after CreateProblemAction, which means we will have to have create_problem_default task.

create_problem_custom also has to exist because we allow Problem/type to create a special problem together with a custom action, refer to the implementation of CreateSpecialProblemAction, which requires the correct ordering of MOOSE CreateProblemAction and custom action. At this moment create_problem_complete is not used but I think it might be a good idea to keep it for the future.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 4, 2018

A side note is that useNonlinear is used to add different systems in FEProblem for our old eigenvalue calculation. It possibly will be removed thus determine_system_type will not be needed. But currently Rattlesnake is using the old eigenvalue capability intensively and new system is not completely ready yet.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 4, 2018

En, create_probem_custom can be removed if we check the existence of Problem/type instead of _problem. Thus we know we will be only having one action creating the problem other than creating the default problem.

@YaqiWang YaqiWang force-pushed the redesign_create_problem branch 2 times, most recently from 003cff6 to e60d038 Compare September 5, 2018 16:41
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.

Ok, my only nitpick is that new method. I don't like that it only gives back one Action. I'd suggest returning the whole container, or just use the existing iterators to get back the items one at a time. I'd rather not create a new interface to maintain in the ActionWarehouse if it can be avoided.

* @return The action pointer. Null means that such an action does not exist.
*/
template <class T>
const T * getActionByTask(const std::string & task)
Copy link
Member

Choose a reason for hiding this comment

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

This method isn't very useful. There are often several Actions for a single task with the same type. This only return the first one. Why not return a container of all the converted ones? A better solution might be to just use the existing iterator (which can be captured and turned into a range trivially) and just loop over them yourself on the receiving side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I was not thinking something like AddMaterialAction, although the use case in this PR always only have one action. Without this helper function, the same functionality has to be repeated several places, like checking the existence of a task, loop through actions on the task. How about I have a check in this function to make sure there is only one action, otherwise throw an 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.

How does this look like?

  /**
   * Retrieve an action on a specific task with its type.
   * Error will be thrown if more than one action is found.
   * @param name The task name.
   * @return The action pointer. Null means that such an action does not exist.
   */
  template <class T>
  const T * getActionByTask(const std::string & task)
  {
    const auto it = _action_blocks.find(task);
    if (it == _action_blocks.end())
      return nullptr;

    T * p = nullptr;
    for (const auto & action : it->second)
    {
      T * tp = dynamic_cast<T *>(action);
      if (tp)
      {
        if (p)
          mooseError("More than one actions have been detected in getActionByTask");
        else
          p = tp;
      }
    }
    return p;
  }

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 5, 2018

@permcody I hope you are satisfied. I have been waiting on this too long...

@permcody
Copy link
Member

permcody commented Sep 6, 2018

@andrsd - This will require another Relap-7 patch. Please review. I already have a Bighorn patch ready.

@permcody permcody requested a review from andrsd September 6, 2018 14:15
permcody
permcody previously approved these changes Sep 6, 2018
framework/include/actions/ActionWarehouse.h Outdated Show resolved Hide resolved
framework/include/problems/FEProblemBase.h Outdated Show resolved Hide resolved
framework/src/actions/CreateProblemAction.C Outdated Show resolved Hide resolved
framework/src/actions/CreateProblemDefaultAction.C Outdated Show resolved Hide resolved
framework/src/actions/CreateProblemDefaultAction.C Outdated Show resolved Hide resolved
framework/src/problems/DumpObjectsProblem.C Outdated Show resolved Hide resolved
framework/src/problems/FEProblemBase.C Outdated Show resolved Hide resolved
@andrsd
Copy link
Contributor

andrsd commented Sep 6, 2018

This will require another Relap-7 patch.

The patch is now ready.

Also, thanks for patching bighorn.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 6, 2018

Thanks, I will address the comments shortly. Just a question to @permcody on factory creating object.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 6, 2018

@andrsd Your comments are addressed. I think this is ready. Thanks guys.

@andrsd
Copy link
Contributor

andrsd commented Sep 6, 2018

I am merging this.

@andrsd andrsd merged commit b614a5e into idaholab:devel Sep 6, 2018
@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 6, 2018

Thanks!

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 6, 2018

Both Rattlesnake and Mammoth have been patched. The fix are all on their devel, because from devel to master is controlled by Civet and Civet will not do it due to App test failure. Looks R7 and Bighorn also have been patched. We will need to do submodule update in Sabertooth and Crab. Then we will back to normal.

@YaqiWang
Copy link
Contributor Author

YaqiWang commented Sep 6, 2018

Tag @andrsd and @permcody.

@YaqiWang YaqiWang deleted the redesign_create_problem branch September 6, 2018 20:11
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.

None yet

4 participants