-
Notifications
You must be signed in to change notification settings - Fork 4
Implement inherited MOOSE variable classes to shadow OpenFOAM fields and function objects #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a80280c
030f47c
6a28597
ff54912
1089e33
a5217b0
c802a90
5ac2e55
b5ef32f
1dc89ab
d5721b6
2e3229b
55d570f
db3cfe1
62b6e51
de63e46
72b37b8
31c7a9a
d323940
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,4 @@ repos: | |
| hooks: | ||
| - id: remove-crlf | ||
| - id: forbid-tabs | ||
| exclude: '.*\.mk$' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #include "InputParameters.h" | ||
| #include "MooseObjectAction.h" | ||
|
|
||
| class AddFoamVariableAction : public MooseObjectAction | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| AddFoamVariableAction(const InputParameters & parameters); | ||
|
|
||
| virtual void act() override; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #pragma once | ||
|
|
||
| #include "FoamVariableField.h" | ||
| #include "functionObject.H" | ||
|
|
||
| #include <volFields.H> | ||
|
|
||
| // Class for mirroring functionObjects | ||
| class FoamFunctionObject : public FoamVariableField | ||
| { | ||
| public: | ||
| explicit FoamFunctionObject(const InputParameters & params); | ||
|
|
||
| // function that executes functionObject and transfers variable from | ||
| // OpenFOAM variable to MOOSE | ||
| virtual void transferVariable(); | ||
|
|
||
| // Destroys functionObject pointer | ||
| ~FoamFunctionObject() { delete _shadow_fo; }; | ||
|
|
||
| private: | ||
| // function to construct the functionObject | ||
| Foam::functionObject * _getFunctionObject(Foam::dictionary fo_dict); | ||
|
|
||
| // The function object pointer | ||
| Foam::functionObject * _shadow_fo; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #pragma once | ||
|
|
||
| #include "Moose.h" | ||
| #include "MooseTypes.h" | ||
| #include "FoamMesh.h" | ||
|
|
||
| class FoamVariableField : public MooseObject | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking that when I add handling of vectors at some point I will change it to |
||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| explicit FoamVariableField(const InputParameters & params); | ||
|
|
||
| // transfer variable from OpenFOAM field to MOOSE variable | ||
| virtual void transferVariable(); | ||
|
|
||
| // returns the name of the foam variable this object shadows | ||
| std::string foamVariable() const { return _foam_variable; }; | ||
|
|
||
| protected: | ||
| // variable name or functionObject to be shadowed | ||
| std::string _foam_variable; | ||
|
|
||
| // moose variable that shadows the OpenFOAM variable | ||
| MooseVariableFieldBase & _moose_var; | ||
|
|
||
| // Create Auxilliary variable | ||
| MooseVariableFieldBase & createMooseVariable(std::string name, const InputParameters & params); | ||
|
|
||
| // Pointer to the FoamMesh object | ||
| FoamMesh * _mesh; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "AddFoamVariableAction.h" | ||
| #include "FoamProblem.h" | ||
| #include "FoamVariableField.h" | ||
| #include "InputParameters.h" | ||
| #include "MooseObjectAction.h" | ||
| #include "Registry.h" | ||
|
|
||
| registerMooseAction("hippoApp", AddFoamVariableAction, "add_foam_variable"); | ||
|
|
||
| InputParameters | ||
| AddFoamVariableAction::validParams() | ||
| { | ||
| auto params = MooseObjectAction::validParams(); | ||
| params.addClassDescription("Adds a FoamVariable that shadows an OpenFOAM scalar field."); | ||
| return params; | ||
| } | ||
|
|
||
| AddFoamVariableAction::AddFoamVariableAction(const InputParameters & parameters) | ||
| : MooseObjectAction(parameters) | ||
| { | ||
| } | ||
|
|
||
| void | ||
| AddFoamVariableAction::act() | ||
| { | ||
| if (_current_task == "add_foam_variable") | ||
| { | ||
| auto * foam_problem = dynamic_cast<FoamProblem *>(_problem.get()); | ||
| if (!foam_problem) | ||
| mooseError("FoamVariables block must be used with FoamProblem"); | ||
|
|
||
| foam_problem->addObject<FoamVariableField>(_type, _name, _moose_object_pars, false); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #include "FoamVariableField.h" | ||
| #include "FoamFunctionObject.h" | ||
| #include "InputParameters.h" | ||
| #include "Registry.h" | ||
| #include "SystemBase.h" | ||
| #include "dictionary.H" | ||
| #include "functionObject.H" | ||
| // #include "wallHeatFlux.h" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stray comment
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix this in the tests PR. |
||
| #include <functionObjects/field/wallHeatFlux/wallHeatFlux.H> | ||
|
|
||
| registerMooseObject("hippoApp", FoamFunctionObject); | ||
|
|
||
| FoamFunctionObject::FoamFunctionObject(const InputParameters & params) : FoamVariableField(params) | ||
| { | ||
| auto & mesh = _mesh->fvMesh(); | ||
|
|
||
| // construct input Foam dictionary for the functionObject | ||
| auto fo_dict = mesh.time().controlDict().lookupOrDefault(_foam_variable, Foam::dictionary()); | ||
|
|
||
| // create patch names where functionObject applies | ||
| // TODO: when volumetric mirror is implemented some of this may need to be | ||
| // put in the _getFunctionObject function. | ||
| std::vector<int> patch_ids{_mesh->getSubdomainList()}; | ||
| Foam::wordList patch_names; | ||
| for (auto id : patch_ids) | ||
| patch_names.append(mesh.boundaryMesh()[id].name()); | ||
|
|
||
| fo_dict.set("patches", patch_names); | ||
| fo_dict.set("writeToFile", false); | ||
|
|
||
| // construct functionObject and execute | ||
| _shadow_fo = _getFunctionObject(fo_dict); | ||
| _shadow_fo->execute(); | ||
| } | ||
|
|
||
| Foam::functionObject * | ||
| FoamFunctionObject::_getFunctionObject(Foam::dictionary fo_dict) | ||
| { | ||
| // Create polymorphic pointer to each type of valid functionObject | ||
| if (_foam_variable == "wallHeatFlux") | ||
| { | ||
| Foam::functionObjects::wallHeatFlux * whf_func = | ||
| new Foam::functionObjects::wallHeatFlux("wallHeatFlux", _mesh->fvMesh().time(), fo_dict); | ||
| return static_cast<Foam::functionObject *>(whf_func); | ||
| } | ||
| else | ||
| { | ||
| mooseError("Only wallHeatFlux functionObject is currently supported"); | ||
| } | ||
| } | ||
|
|
||
| void | ||
| FoamFunctionObject::transferVariable() | ||
| { | ||
| // execute functionObject before transfer | ||
| _shadow_fo->execute(); | ||
| FoamVariableField::transferVariable(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we open an issue for this, rather than leaving it as a TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add an issue but would rather leave to todo's in, so I get a reminder when I am doing it