<commit_before># Step 3: Introduction to MOOSE Objects

In this step, [#objects], and the purposes they serve, will be introduced.
To demonstrate this concept, consider the same problem discussed in [Step 2](tutorial01_app_development/step02_input_file.md#physics) and explore the basics of how the Laplace equation was developed in the form of a C++ object.

## Statement of Physics id=physics

Recall, from [Step 2](tutorial01_app_development/step02_input_file.md#physics), that the foregoing [!ac](BVP) is governed by the following [!ac](PDE):

!equation id=laplace
-\nabla \cdot \nabla u = 0 \in \Omega

It is necessary to acknowledge that [!ac](PDEs) must be expressed in a certain format to be able to solve them with MOOSE. That is, assuming that the natural boundary condition, $\nabla u \cdot \hat{n}$, is satisfied, then the *weak form* of [laplace] is

!equation id=weak
\int_{\Omega} \nabla \psi \cdot \nabla u \, d\Omega = 0, \, \forall \,\,\, \psi

In the [next step](tutorial01_app_development/step04_weak_form.md), exactly what is meant by the terminology, "weak form," will be explained when the Galerkin [!ac](FEM) is discussed, so do not worry about this just yet.

## MOOSE Objects id=objects

The core framework of MOOSE is built around systems, where each system uses object-oriented programming to provide a well-defined interface for using the system via C++ inhertience. In short, the framework provides a set of base class(es) for each system. These base classes are specialized using custom C++ objects within an application to achieve the desired behavior for the problem. Resources for object orientiented are abundant, but a solid starting point is [cplusplus.com](https://www.cplusplus.com). This tutorial assumes a basic understanding of both C++ and object-oriented programming.

In practice, all objects in MOOSE and within an application being developed follow the same pattern. Thus, only a broad understanding is required to begin working with MOOSE. For example, consider the `Diffusion` object contianed within the framework as shown in [diffusion-hdr] and [diffusion-src].

!listing framework/include/kernels/Diffusion.h
         re=(?P<remove>\S*^class Diffusion;$.*?<Diffusion>\(\);)
         id=diffusion-hdr
         caption=Header file that declares the `Diffusion` object.

!listing framework/src/kernels/Diffusion.C
         id=diffusion-src
         caption=Source file that define the `Diffusion` object.

This class can be used to demonstrate the form in which all object created in a MOOSE-based application will follow. First, begin with definition in the header. Foremost, all header classes should start with:

!listing framework/include/kernels/Diffusion.h line=#pragma

This line ensures that the compiler does not include the contents of this file more then once.

Next, the base class that is being specialized is included. For the `Diffusion` object, this base class is a `Kernel`, thus the object being created is part of the [Kernels/index.md] system for describing the volumentric term of the weak form. Again, details regarding how the weak form is generated will be covered later in the tutorial.

!listing framework/include/kernels/Diffusion.h line=#include

Finally, the class being created is defined. This definition contains three main compoments common to all object that will be created within an application:

1. a static validParams function for creating input syntax;

   !listing framework/include/kernels/Diffusion.h line=static Input

1. a constructor the has a single input; and

   !listing framework/include/kernels/Diffusion.h line=const InputParameters &

1. one or many methods that are overridden to provide the custo functionality desired for the application.

   !listing framework/include/kernels/Diffusion.h line=virtual

The source (.C) file simply defines the behavior of these three components for the object being created. As the tutorial progresses, this basic structure and syntax of the will be seen regularly and the purpose and use of methods, like `validParams()`, will become more clear.

A `MooseObject` that is capable of solving the Laplace equation was required for [Step 2](tutorial01_app_development/step02_input_file.md). By now, it should be obvious that the `Diffusion` object was capable of solving [laplace] and so there was no need to develop one for this problem.

!alert tip title=The MOOSE does a lot already
Before developing a new `MooseObject` in an application, confirm that something like it does not already exist. All MOOSE applications posses the full capability of the framework and physics modules (more on this later), in addition to their own capabilities.

!content pagination previous=tutorial01_app_development/step02_input_file.md
                    next=tutorial01_app_development/step04_weak_form.md
<commit_msg>Edit Step 3: Moose Object<commit_after># Step 3: Introduction to MOOSE Objects

In this step, [#objects], and the purposes they serve, will be introduced.
To demonstrate this concept, consider the same problem discussed in [Step 2](tutorial01_app_development/step02_input_file.md#physics) and explore the basics of how the Laplace equation was developed in the form of a C++ class.

Anyone who feels that they need to review C++ and/or object-oriented programming are highly encouraged to do so before proceeding with the remainder of this tutorial. The [getting_started/examples_and_tutorials/index.md#programming] provides some helpful starting points for this.

## MOOSE Objects id=objects

The core framework of MOOSE is built around systems, where each system uses object-oriented programming to provide a well-defined interface for using the system via C++ inheritance. In short, the framework provides a set of base class(es) for each system. These base classes are specialized using custom C++ objects within an application to achieve the desired behavior for the problem.

In practice, all objects in MOOSE and within an application being developed follow the same pattern. Thus, only a broad understanding is required to begin working with MOOSE. For example, consider the `ADDiffusion` object contained within the framework as shown in [diffusion-hdr] and [diffusion-src].

!listing framework/include/kernels/ADDiffusion.h
         id=diffusion-hdr
         caption=Header file that declares the `ADDiffusion` object.

!listing framework/src/kernels/ADDiffusion.C
         id=diffusion-src
         caption=Source file that defines the `ADDiffusion` object.

This class can be used to demonstrate the form in which all objects created in a MOOSE-based application will follow. First, begin with the declarations in the header file. Foremost, all class headers should begin with:

!listing framework/include/kernels/ADDiffusion.h line=#pragma link=False

This line ensures that the compiler does not include the contents of this file more then once.

Next, the base class that is being specialized is included. For the `ADDiffusion` object, the base class is `ADKernelGrad`:

!listing framework/include/kernels/ADDiffusion.h line=#include link=False

Finally, the class being created is defined. This definition contains three main components common to all objects that will be created within an application:

1. a static validParams function for creating input syntax,

   !listing framework/include/kernels/ADDiffusion.h line=static Input link=False

1. a constructor that is given the same name as the `MooseObject` that owns it and that consumes `InputParameters` objects, and

   !listing framework/include/kernels/ADDiffusion.h line=const InputParameters & link=False

1. one or more methods that are overridden to provide the custom functionality desired for the application.

   !listing framework/include/kernels/ADDiffusion.h line=precomputeQpResidual() link=False

The source (`.C`) file simply defines the functionality of these three components. As the tutorial progresses, the basic structure and syntax described here will be seen regularly and the purpose and use of methods, like `validParams()`, will become more clear.

## Demonstration id=demo

### Statement of Physics id=physics

Recall, from [Step 2](tutorial01_app_development/step02_input_file.md#physics), that the foregoing [!ac](BVP) is governed by the following [!ac](PDE):

!equation id=laplace
-\nabla \cdot \nabla u = 0 \in \Omega

It is necessary to acknowledge that [!ac](PDEs) must be expressed in a certain format to be able to solve them with MOOSE. That is, assuming that the natural boundary condition, $\nabla u \cdot \hat{n}$, is satisfied, then the *weak form* of [laplace] is

!equation id=weak
\int_{\Omega} \nabla \psi \cdot \nabla u \, d\Omega = 0, \,\,\, \forall \, \psi

In the [next step](tutorial01_app_development/step04_weak_form.md), exactly what is meant by the terminology, "weak form," will be explained when the Galerkin [!ac](FEM) is discussed, so do not worry about this just yet.

### Source Code

A `MooseObject` that was capable of solving the Laplace equation was required for [Step 2](tutorial01_app_development/step02_input_file.md) and it was demonstrated that `ADDiffusion` provides this capability. To understand how it works, consider [diffusion-src], and notice that the $\nabla u$ term of the integrand in [weak] was coded:

!listing framework/src/kernels/ADDiffusion.C
         start=ADRealVectorValue
         link=False

Here, the $\nabla \psi$ term in [weak],
is automatically handled by the `precomputeQpResidual()` method of the [`ADKernelGrad`](source/kernels/ADKernelGrad.md) base class, so there was no need to include this term manually.

!alert tip title=MOOSE does a lot already
Before developing a new `MooseObject` in an application, confirm that something like it does not already exist. All MOOSE applications posses the full capability of the framework and physics modules (more on this later), in addition to their own capabilities.

!content pagination previous=tutorial01_app_development/step02_input_file.md
                    next=tutorial01_app_development/step04_weak_form.md

{'fraction_non_alphanumeric': 0.06529721147166816, 'fraction_numerical': 0.0066488042076014685, 'mean_word_length': 4.697003957037874, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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}}
{'dir': 'git-commits-cleaned', 'id': '2567857', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2547, 'n_words': 1302}