# -*- coding: utf-8 -*-
"""
  sub0_base.py generated by WhatsOpt 1.8.2
"""
# DO NOT EDIT unless you know what you are doing
# whatsopt_url:
# analysis_id: 6


import numpy as np
from numpy import nan

from openmdao.api import Problem, Group, ParallelGroup, IndepVarComp
from openmdao.api import NonlinearBlockGS
from openmdao.api import ScipyKrylov
from openmdao import __version__ as OPENMDAO_VERSION

from parallel.sub0.states_comp import StatesComp
from parallel.sub0.displacements_comp import DisplacementsComp
from parallel.sub0.compliance_comp import ComplianceComp


class Sub0Base(Group):
    """An OpenMDAO base component to encapsulate Sub0 MDA"""

    def __init__(self, thrift_client=None, **kwargs):
        super(Sub0Base, self).__init__(**kwargs)

        self.nonlinear_solver = NonlinearBlockGS()
        self.nonlinear_solver.options["atol"] = 1.0e-10
        self.nonlinear_solver.options["rtol"] = 1.0e-10
        self.nonlinear_solver.options["err_on_non_converge"] = True
        self.nonlinear_solver.options["reraise_child_analysiserror"] = False
        self.nonlinear_solver.options["iprint"] = 1

        self.linear_solver = ScipyKrylov()
        self.linear_solver.options["atol"] = 1.0e-10
        self.linear_solver.options["rtol"] = 1.0e-10
        self.linear_solver.options["err_on_non_converge"] = True
        self.linear_solver.options["iprint"] = 1

    def setup(self):
        self.add_subsystem(
            "StatesComp", self.create_states_comp(), promotes=["d_0", "d_1", "K_local"]
        )
        self.add_subsystem(
            "DisplacementsComp",
            self.create_displacements_comp(),
            promotes=["displacements_0", "displacements_1", "d_0", "d_1"],
        )
        self.add_subsystem(
            "ComplianceComp",
            self.create_compliance_comp(),
            promotes=[
                "compliance_0",
                "compliance_1",
                "displacements_0",
                "displacements_1",
            ],
        )

    def create_states_comp(self):
        return StatesComp()

    def create_displacements_comp(self):
        return DisplacementsComp()

    def create_compliance_comp(self):
        return ComplianceComp()


# Used by Thrift server to serve disciplines
class Sub0FactoryBase(object):
    @staticmethod
    def create_parallel_sub0_states_comp():
        return StatesComp()

    @staticmethod
    def create_parallel_sub0_displacements_comp():
        return DisplacementsComp()

    @staticmethod
    def create_parallel_sub0_compliance_comp():
        return ComplianceComp()
