CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Create new object (https://www.cfd-online.com/Forums/openfoam-programming-development/229225-create-new-object.html)

Phigo90 July 31, 2020 07:25

Create new object
 
5 Attachment(s)
Hi Foamer,


I am trying to create a new object of the type "interfaceHeatResistance". This class inherits from the "temperaturePhaseChangeTwoPhaseMixture" class.


However, in the createFields file the object mixture is created with:
Code:

Info<< "Creating temperaturePhaseChangeTwoPhaseMixture\n" << endl;
autoPtr<temperaturePhaseChangeTwoPhaseMixture> mixture =
    temperaturePhaseChangeTwoPhaseMixture::New(thermo(), mesh);

based on


Code:

  // Selectors

        //- Return a reference to the selected phaseChange model
        static autoPtr<temperaturePhaseChangeTwoPhaseMixture> New
        (
            const thermoIncompressibleTwoPhaseMixture& mixture,
            const fvMesh& mesh
        );


    // Constructors

        //- Construct from components
        temperaturePhaseChangeTwoPhaseMixture
        (
            const thermoIncompressibleTwoPhaseMixture& mixture,
            const fvMesh& mesh
        );


    //- Destructor
    virtual ~temperaturePhaseChangeTwoPhaseMixture() = default;

Does anyone of you know how I can create an "interfaceheatresistance" object?


Code:

  // Constructors

        //- Construct from components
        interfaceHeatResistance
        (
            const thermoIncompressibleTwoPhaseMixture& mixture,
            const fvMesh& mesh
        );

I am not an expert in C++ and still learning.

Santiago July 31, 2020 10:38

Quote:

Originally Posted by Phigo90 (Post 779249)
Hi Foamer,


I am trying to create a new object of the type "interfaceHeatResistance". This class inherits from the "temperaturePhaseChangeTwoPhaseMixture" class.


However, in the createFields file the object mixture is created with:
Code:

Info<< "Creating temperaturePhaseChangeTwoPhaseMixture\n" << endl;
autoPtr<temperaturePhaseChangeTwoPhaseMixture> mixture =
    temperaturePhaseChangeTwoPhaseMixture::New(thermo(), mesh);

based on


Code:

  // Selectors

        //- Return a reference to the selected phaseChange model
        static autoPtr<temperaturePhaseChangeTwoPhaseMixture> New
        (
            const thermoIncompressibleTwoPhaseMixture& mixture,
            const fvMesh& mesh
        );


    // Constructors

        //- Construct from components
        temperaturePhaseChangeTwoPhaseMixture
        (
            const thermoIncompressibleTwoPhaseMixture& mixture,
            const fvMesh& mesh
        );


    //- Destructor
    virtual ~temperaturePhaseChangeTwoPhaseMixture() = default;

Does anyone of you know how I can create an "interfaceheatresistance" object?


Code:

  // Constructors

        //- Construct from components
        interfaceHeatResistance
        (
            const thermoIncompressibleTwoPhaseMixture& mixture,
            const fvMesh& mesh
        );

I am not an expert in C++ and still learning.

you are supposed to create a pointer to the thermo(...) abstract class using the selector you show (New), in order to make use of the inheritance hierarchy derived from the base class. If you create the objects directly you may induce additional overhead. It may also mess with the object registry mechanism. So in short, follow the example you just shown.


All times are GMT -4. The time now is 10:53.