|
[Sponsors] |
November 18, 2020, 09:13 |
Constructors in OpenFOAM
|
#1 |
New Member
Join Date: Nov 2020
Posts: 6
Rep Power: 6 |
Hello!
I appreciate any direct help with the topic below ... or a reference/guide/video which explains the full story for beginners ________________________________________________ my understanding of constructors in C++ is the following: Class name (parameter list) : Member initializer list {statement} I tried to match with OpenFOAM using Lines 37 to 47 below from the code here ------------------------------------------------- Foam:: prghPressureFvPatchScalarField:: prghPressureFvPatchScalarField ( const fvPatch& p, const DimensionedField<scalar, volMesh>& iF ) : fixedValueFvPatchScalarField(p, iF), rhoName_("rho"), p_(p.size(), Zero) {} ------------------------------------------------- My guess (please correct me if I'm wrong) - Class name is prghPressureFvPatchScalarField - fvPatch and DimensionedField<scalar, volMesh> are parameters and they were given aliases p and iF my questions - what is fixedValueFvPatchScalarField(p, iF) - {} is empty, I'm not sure what the constructor is doing overall - what is the first line Foam::X::X (I've seen this frequently in different codes) Thank you |
|
November 20, 2020, 05:39 |
|
#2 |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8 |
i commented the lines for you
Foam:: prghPressureFvPatchScalarField:: //Foam is the namespace :: yourClassName :: yourConstructorAsFunction prghPressureFvPatchScalarField ( const fvPatch& p, const DimensionedField<scalar, volMesh>& iF ) : fixedValueFvPatchScalarField(p, iF), //your class inherits from this class, so //this must be included, you cannot ignore //the parent class, if multiple parents exist, do same for other parents rhoName_("rho"), // next two lines overwrite attributes p_(p.size(), Zero) {} //you already overwrote attributes, so // nothing to do for that class here, // other classes might need it to do stuff |
|
November 20, 2020, 06:16 |
|
#3 | ||
New Member
Join Date: Nov 2020
Posts: 6
Rep Power: 6 |
Thank you I have a few more clarifications if you don't mind
Quote:
Quote:
where the update could be a new name or some changes on how the variable is defined |
|||
November 24, 2020, 09:46 |
|
#4 |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8 |
i don't quite get what you mean by className(),
but let my clarify few things. p and iF are arguments for the function fixedValueFvPatchScalarField, fixedValueFvPatchScalarField(p, iF) is a parameter constructor bc it takes arguments to construct an instance. what p and iF mean you can look up and decipher from the code (p means pressure, don't know what iF means, didnt look it up, maybe initialField?). if you have a constructor without an argument (maybe you mean that by className()) you can create instances from that class without providing input. next point: if you want to update an attribute automatically when creating an instance of a class you can do this like rhoName_("rho") // so rhoName_-value will be updated with rho-value. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Frequently Asked Questions about Installing OpenFOAM | wyldckat | OpenFOAM Installation | 3 | November 14, 2023 12:58 |
OpenFOAM Foundation Releases OpenFOAM v2.3.0 | opencfd | OpenFOAM Announcements from OpenFOAM Foundation | 3 | December 23, 2014 04:43 |
Suggestion for a new sub-forum at OpenFOAM's Forum | wyldckat | Site Help, Feedback & Discussions | 20 | October 28, 2014 10:04 |
[Gmsh] 2D Mesh Generation Tutorial for GMSH | aeroslacker | OpenFOAM Meshing & Mesh Conversion | 12 | January 19, 2012 04:52 |
The OpenFOAM extensions project | mbeaudoin | OpenFOAM | 16 | October 9, 2007 10:33 |