Skip to content

Commit

Permalink
Merge pull request #1118 from hschilling/P169489646-n2-newton-solver-…
Browse files Browse the repository at this point in the history
…colors

P169489646 indicate in the N2 if solve_subsystems is True for Newton solvers
  • Loading branch information
swryan committed Nov 15, 2019
2 parents 1c08e2c + 17eb485 commit 3e742b5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
3 changes: 3 additions & 0 deletions openmdao/docs/features/model_visualization/n2_details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ Here is what section of the legend looks like for both linear and nonlinear solv

|linear_solvers_legend| |nonlinear_solvers_legend|

When a System has a Newton nonlinear solver and the `solve_subsystems` option is set to True for that solver,
the Solver Structure box for that System has the text `NL: Newton (sub_solve)`.

Toolbar
-------

Expand Down
10 changes: 7 additions & 3 deletions openmdao/visualization/n2_viewer/n2_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
from openmdao.core.problem import Problem
from openmdao.core.component import Component
from openmdao.core.implicitcomponent import ImplicitComponent
from openmdao.visualization.html_utils import read_files, write_script, DiagramWriter
from openmdao.drivers.doe_driver import DOEDriver
from openmdao.recorders.case_reader import CaseReader
from openmdao.solvers.nonlinear.newton import NewtonSolver
from openmdao.utils.class_util import overrides_method
from openmdao.utils.general_utils import warn_deprecation, simple_warning, make_serializable
from openmdao.utils.record_util import check_valid_sqlite3_db
from openmdao.utils.mpi import MPI
from openmdao.recorders.case_reader import CaseReader
from openmdao.drivers.doe_driver import DOEDriver
from openmdao.visualization.html_utils import read_files, write_script, DiagramWriter

# Toolbar settings
_FONT_SIZES = [8, 9, 10, 11, 12, 13, 14]
Expand Down Expand Up @@ -139,6 +140,9 @@ def _get_tree_dict(system, component_execution_orders, component_execution_index

if system.nonlinear_solver:
tree_dict['nonlinear_solver'] = system.nonlinear_solver.SOLVER

if system.nonlinear_solver.SOLVER == NewtonSolver.SOLVER:
tree_dict['solve_subsystems'] = system._nonlinear_solver.options['solve_subsystems']
else:
tree_dict['nonlinear_solver'] = ""

Expand Down
12 changes: 6 additions & 6 deletions openmdao/visualization/n2_viewer/src/N2Diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class N2Diagram {
this.showLinearSolverNames = true;

this.style = new N2Style(this.dom.svgStyle, this.dims.size.font);
this.layout = new N2Layout(this.model, this.zoomedElement, true, this.dims);
this.layout = new N2Layout(this.model, this.zoomedElement, this.showLinearSolverNames, this.dims);
this.ui = new N2UserInterface(this);

this._setupSvgElements();
Expand Down Expand Up @@ -403,8 +403,8 @@ class N2Diagram {
let nodeEnter = selection.enter().append("svg:g")
.attr("class", function (d) {
let solver_class = self.style.getSolverClass(self.showLinearSolverNames,
{ 'linear': d.linear_solver, 'nonLinear': d.nonlinear_solver })
return solver_class + " " + "solver_group " + self.style.getNodeClass(d);
{ 'linear': d.linear_solver, 'nonLinear': d.nonlinear_solver });
return solver_class + " solver_group " + self.style.getNodeClass(d);
})
.attr("transform", function (d) {
let x = 1.0 - d.prevSolverDims.x - d.prevSolverDims.width;
Expand Down Expand Up @@ -459,7 +459,7 @@ class N2Diagram {
if (d.depth < self.zoomedElement.depth) return 0;
return d.textOpacity;
})
.text(self.layout.getSolverText);
.text(self.layout.getSolverText.bind(self.layout));

return ({ 'selection': selection, 'nodeEnter': nodeEnter });
}
Expand All @@ -472,7 +472,7 @@ class N2Diagram {
.attr("class", function (d) {
let solver_class = self.style.getSolverClass(self.showLinearSolverNames,
{ 'linear': d.linear_solver, 'nonLinear': d.nonlinear_solver });
return solver_class + " " + "solver_group " + self.style.getNodeClass(d);
return solver_class + " solver_group " + self.style.getNodeClass(d);
})
.attr("transform", function (d) {
let x = 1.0 - d.solverDims.x - d.solverDims.width;
Expand Down Expand Up @@ -501,7 +501,7 @@ class N2Diagram {
if (d.depth < self.zoomedElement.depth) return 0;
return d.textOpacity;
})
.text(self.layout.getSolverText);
.text(self.layout.getSolverText.bind(self.layout));
}

_runSolverTransition(selection) {
Expand Down
10 changes: 8 additions & 2 deletions openmdao/visualization/n2_viewer/src/N2Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,14 @@ class N2Layout {
* @param {N2TreeNode} node The item to get the solver text from.
*/
getSolverText(node) {
return this.showLinearSolverNames ?
node.linear_solver : node.nonlinear_solver;

let solver_name = this.showLinearSolverNames ? node.linear_solver : node.nonlinear_solver;

if (!this.showLinearSolverNames && node.hasOwnProperty("solve_subsystems") && node.solve_subsystems){
return solver_name + " (sub_solve)";
} else {
return solver_name;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
self.sqlite_html_filename = os.path.join(self.dir, "sqlite_n2.html")
self.problem_html_filename = os.path.join(self.dir, "problem_n2.html")

self.expected_tree = json.loads('{"name": "root", "type": "root", "class": "SellarStateConnection", "component_type": null, "subsystem_type": "group", "is_parallel": false, "linear_solver": "LN: SCIPY", "nonlinear_solver": "NL: Newton", "children": [{"name": "px", "type": "subsystem", "class": "IndepVarComp", "subsystem_type": "component", "is_parallel": false, "component_type": "indep", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "x", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "pz", "type": "subsystem", "class": "IndepVarComp", "subsystem_type": "component", "is_parallel": false, "component_type": "indep", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "z", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "sub", "type": "subsystem", "class": "Group", "component_type": null, "subsystem_type": "group", "is_parallel": false, "linear_solver": "LN: SCIPY", "nonlinear_solver": "NL: RUNONCE", "children": [{"name": "state_eq_group", "type": "subsystem", "class": "Group", "component_type": null, "subsystem_type": "group", "is_parallel": false, "linear_solver": "LN: SCIPY", "nonlinear_solver": "NL: RUNONCE", "children": [{"name": "state_eq", "type": "subsystem", "class": "StateConnection", "subsystem_type": "component", "is_parallel": false, "component_type": "implicit", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "y2_actual", "type": "param", "dtype": "ndarray"}, {"name": "y2_command", "type": "unknown", "implicit": true, "dtype": "ndarray"}]}]}, {"name": "d1", "type": "subsystem", "class": "SellarDis1withDerivatives", "subsystem_type": "component", "is_parallel": false, "component_type": "explicit", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "z", "type": "param", "dtype": "ndarray"}, {"name": "x", "type": "param", "dtype": "ndarray"}, {"name": "y2", "type": "param", "dtype": "ndarray"}, {"name": "y1", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "d2", "type": "subsystem", "class": "SellarDis2withDerivatives", "subsystem_type": "component", "is_parallel": false, "component_type": "explicit", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "z", "type": "param", "dtype": "ndarray"}, {"name": "y1", "type": "param", "dtype": "ndarray"}, {"name": "y2", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}]}, {"name": "obj_cmp", "type": "subsystem", "class": "ExecComp", "subsystem_type": "component", "is_parallel": false, "component_type": "exec", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "x", "type": "param", "dtype": "ndarray"}, {"name": "y1", "type": "param", "dtype": "ndarray"}, {"name": "y2", "type": "param", "dtype": "ndarray"}, {"name": "z", "type": "param", "dtype": "ndarray"}, {"name": "obj", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "con_cmp1", "type": "subsystem", "class": "ExecComp", "subsystem_type": "component", "is_parallel": false, "component_type": "exec", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "y1", "type": "param", "dtype": "ndarray"}, {"name": "con1", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "con_cmp2", "type": "subsystem", "class": "ExecComp", "subsystem_type": "component", "is_parallel": false, "component_type": "exec", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "y2", "type": "param", "dtype": "ndarray"}, {"name": "con2", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}]}')
self.expected_tree = json.loads('{"name": "root", "type": "root", "class": "SellarStateConnection", "component_type": null, "subsystem_type": "group", "is_parallel": false, "linear_solver": "LN: SCIPY", "nonlinear_solver": "NL: Newton", "solve_subsystems": false, "children": [{"name": "px", "type": "subsystem", "class": "IndepVarComp", "subsystem_type": "component", "is_parallel": false, "component_type": "indep", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "x", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "pz", "type": "subsystem", "class": "IndepVarComp", "subsystem_type": "component", "is_parallel": false, "component_type": "indep", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "z", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "sub", "type": "subsystem", "class": "Group", "component_type": null, "subsystem_type": "group", "is_parallel": false, "linear_solver": "LN: SCIPY", "nonlinear_solver": "NL: RUNONCE", "children": [{"name": "state_eq_group", "type": "subsystem", "class": "Group", "component_type": null, "subsystem_type": "group", "is_parallel": false, "linear_solver": "LN: SCIPY", "nonlinear_solver": "NL: RUNONCE", "children": [{"name": "state_eq", "type": "subsystem", "class": "StateConnection", "subsystem_type": "component", "is_parallel": false, "component_type": "implicit", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "y2_actual", "type": "param", "dtype": "ndarray"}, {"name": "y2_command", "type": "unknown", "implicit": true, "dtype": "ndarray"}]}]}, {"name": "d1", "type": "subsystem", "class": "SellarDis1withDerivatives", "subsystem_type": "component", "is_parallel": false, "component_type": "explicit", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "z", "type": "param", "dtype": "ndarray"}, {"name": "x", "type": "param", "dtype": "ndarray"}, {"name": "y2", "type": "param", "dtype": "ndarray"}, {"name": "y1", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "d2", "type": "subsystem", "class": "SellarDis2withDerivatives", "subsystem_type": "component", "is_parallel": false, "component_type": "explicit", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "z", "type": "param", "dtype": "ndarray"}, {"name": "y1", "type": "param", "dtype": "ndarray"}, {"name": "y2", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}]}, {"name": "obj_cmp", "type": "subsystem", "class": "ExecComp", "subsystem_type": "component", "is_parallel": false, "component_type": "exec", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "x", "type": "param", "dtype": "ndarray"}, {"name": "y1", "type": "param", "dtype": "ndarray"}, {"name": "y2", "type": "param", "dtype": "ndarray"}, {"name": "z", "type": "param", "dtype": "ndarray"}, {"name": "obj", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "con_cmp1", "type": "subsystem", "class": "ExecComp", "subsystem_type": "component", "is_parallel": false, "component_type": "exec", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "y1", "type": "param", "dtype": "ndarray"}, {"name": "con1", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}, {"name": "con_cmp2", "type": "subsystem", "class": "ExecComp", "subsystem_type": "component", "is_parallel": false, "component_type": "exec", "linear_solver": "", "nonlinear_solver": "", "children": [{"name": "y2", "type": "param", "dtype": "ndarray"}, {"name": "con2", "type": "unknown", "implicit": false, "dtype": "ndarray"}]}]}')
self.expected_pathnames = json.loads('["sub.d1", "sub.d2", "sub.state_eq_group.state_eq"]')
self.expected_conns = json.loads("""
[
Expand Down

0 comments on commit 3e742b5

Please sign in to comment.