<jupyter_start><jupyter_text>ExplicitComponentExplicit variables are those that are computed as an explicit function of other variables. For instance, $z$ would be an explicit variable, given $z=sin(y)$, while $y$ would not be, given that it is defined implicitly by the nonlinear equation $cos(x⋅y)−z⋅y=0$.In OpenMDAO, explicit variables are defined by writing a class that inherits from the [ExplicitComponent](../../../_srcdocs/packages/core/explicitcomponent)  class. The explicit variables would be considered outputs while the variables on which they depend would be considered inputs (e.g., $y$ in $z=sin(y)$). ExplicitComponent MethodsThe implementation of each method will be illustrated using a simple explicit component that computes the output area as a function of inputs *length* and *width*.<jupyter_code>import openmdao.api as om


class RectangleComp(om.ExplicitComponent):
    """
    A simple Explicit Component that computes the area of a rectangle.
    """<jupyter_output><empty_output><jupyter_text>* `setup()` :Declare input and output variables via `add_input` and `add_output`. Information such as variable names, sizes, units, and bounds are declared here.<jupyter_code>def setup(self):
    self.add_input('length', val=1.)
    self.add_input('width', val=1.)
    self.add_output('area', val=1.)<jupyter_output><empty_output><jupyter_text>* `setup_partials()` :Declare partial derivatives that this component provides, using wild cards to say that this component provides derivatives of all outputs with respect to all inputs.<jupyter_code>def setup_partials(self):
    self.declare_partials('*', '*')<jupyter_output><empty_output><jupyter_text>* `compute(inputs, outputs)` :Compute the `outputs` given the `inputs`.<jupyter_code>def compute(self, inputs, outputs):
    outputs['area'] = inputs['length'] * inputs['width']<jupyter_output><empty_output><jupyter_text>* `compute_partials(inputs, partials)` :```{note}[Optional] Compute the `partials` (partial derivatives) given the `inputs`.```<jupyter_code>def compute_partials(self, inputs, partials):
    partials['area', 'length'] = inputs['width']
    partials['area', 'width'] = inputs['length']<jupyter_output><empty_output><jupyter_text>(matrix-free-api)= The Matrix-Free API: Providing derivatives as a matrix-vector product* `compute_jacvec_product(inputs, d_inputs, d_outputs, mode)` :```{note}[Optional] Provide the partial derivatives as a matrix-vector product. If `mode` is 'fwd', this method must compute $d\_outputs=J⋅d\_inputs$, where J is the partial derivative Jacobian. If `mode` is 'rev', this method must compute $d\_inputs=J^T⋅d\_outputs$.```<jupyter_code>def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):
    if mode == 'fwd':
        if 'area' in d_outputs:
            if 'length' in d_inputs:
                d_outputs['area'] += inputs['width'] * d_inputs['length']
            if 'width' in d_inputs:
                d_outputs['area'] += inputs['length'] * d_inputs['width']
    elif mode == 'rev':
        if 'area' in d_outputs:
            if 'length' in d_inputs:
                d_inputs['length'] += inputs['width'] * d_outputs['area']
            if 'width' in d_inputs:
                d_inputs['width'] += inputs['length'] * d_outputs['area']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1264750378214826, 'fraction_numerical': 0.001210287443267776, 'mean_word_length': 5.043875685557587, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '75882', 'license': 'Apache-2.0', 'n_tokens_mistral': 991, 'n_tokens_neox': 970, 'n_words': 307, 'path': 'openmdao/docs/openmdao_book/features/core_features/working_with_components/explicit_component.ipynb', 'repo_name': 'tong0711/OpenMDAO', 'size': '3305'}