-
Notifications
You must be signed in to change notification settings - Fork 4
Implement postprocessors for OpenFOAM-based quantities #76
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
base: main
Are you sure you want to change the base?
Changes from 28 commits
3aab0c2
3c30f86
34a58e1
da0b2c0
c242915
3212f1e
b812998
dbee885
f274432
b3bfff1
acfbcd6
0c9d93e
ab557d8
3823599
af701b7
8f8792d
18dc1b3
02f1b4e
aa6af7f
2491921
243e9e8
ffc896f
4a704f3
2a52b95
192f2d5
81fd65b
efa55c4
a783bd9
1110245
d99f673
732c092
5cae496
4637d20
521cd59
192dc99
aaac42d
2e8b293
b180c1d
25756c4
b3fcc03
d9cd77b
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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
|
|
||
| #include "InputParameters.h" | ||
| #include "Postprocessor.h" | ||
| #include "ElementUserObject.h" | ||
| #include "fvMesh.H" | ||
|
|
||
| class FoamPostprocessorBase : public ElementUserObject, public Postprocessor | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| FoamPostprocessorBase(const InputParameters & params); | ||
|
|
||
| // We dont want the usual UserObject functions to be executed | ||
| // But we still want the Foam Postprocessors to be reported with the other | ||
| // Foam postprocessors | ||
| virtual void initialize() final; | ||
|
|
||
| virtual void execute() final; | ||
|
|
||
| virtual void finalize() final; | ||
|
|
||
| virtual void threadJoin(const UserObject & uo) final; | ||
|
|
||
| // Compute postprocessor, to be called within FoamProblem | ||
| virtual void compute() = 0; | ||
|
|
||
| protected: | ||
| Foam::fvMesh * _foam_mesh; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #pragma once | ||
| #include "FoamSidePostprocessor.h" | ||
|
|
||
| class FoamSideAdvectiveFluxIntegral : public FoamSidePostprocessor | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| FoamSideAdvectiveFluxIntegral(const InputParameters & params); | ||
|
|
||
| virtual PostprocessorValue getValue() const override; | ||
|
|
||
| virtual void compute() override; | ||
|
|
||
| protected: | ||
| Real _value; | ||
|
|
||
| std::string _foam_scalar; | ||
| std::string _advection_velocity; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #pragma once | ||
| #include "FoamSideIntegratedValue.h" | ||
| #include "InputParameters.h" | ||
|
|
||
| #include <functionObjects/field/wallHeatFlux/wallHeatFlux.H> | ||
| #include <functionObjects/field/wallShearStress/wallShearStress.H> | ||
|
|
||
| class FoamSideAverageValue : public FoamSideIntegratedValue | ||
| { | ||
| public: | ||
| static InputParameters validParams() { return FoamSideIntegratedValue::validParams(); } | ||
|
|
||
| FoamSideAverageValue(const InputParameters & params); | ||
|
|
||
| virtual void compute() override; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
| #include "FoamSidePostprocessor.h" | ||
| #include <functionObjects/field/wallHeatFlux/wallHeatFlux.H> | ||
| #include <functionObjects/field/wallShearStress/wallShearStress.H> | ||
|
|
||
| static MooseEnum _pp_function_objects("wallHeatFlux wallShearStress"); | ||
|
|
||
| class FoamSideIntegratedValue : public FoamSidePostprocessor | ||
|
||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| FoamSideIntegratedValue(const InputParameters & params); | ||
|
|
||
| virtual PostprocessorValue getValue() const override; | ||
|
|
||
| virtual void compute() override; | ||
|
|
||
| protected: | ||
| /// Creates function objects to be executed by compute | ||
| void createFunctionObject(); | ||
|
|
||
| Real _value; | ||
|
|
||
| std::string _foam_variable; | ||
|
|
||
| bool _is_vector; | ||
|
|
||
| Foam::functionObject * _function_object; | ||
|
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #pragma once | ||
|
|
||
| #include "FoamPostprocessorBase.h" | ||
| #include "MooseTypes.h" | ||
|
|
||
| class FoamSidePostprocessor : public FoamPostprocessorBase | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| FoamSidePostprocessor(const InputParameters & params); | ||
|
|
||
| protected: | ||
| std::vector<SubdomainName> _boundary; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #include "FoamMesh.h" | ||
| #include "FoamPostprocessorBase.h" | ||
| #include "InputParameters.h" | ||
| #include "Postprocessor.h" | ||
| #include "ElementUserObject.h" | ||
| #include "FoamProblem.h" | ||
|
|
||
| InputParameters | ||
| FoamPostprocessorBase::validParams() | ||
| { | ||
| auto params = ElementUserObject::validParams(); | ||
| params += Postprocessor::validParams(); | ||
| return params; | ||
| } | ||
|
|
||
| FoamPostprocessorBase::FoamPostprocessorBase(const InputParameters & params) | ||
| : ElementUserObject(params), Postprocessor(this), _foam_mesh(nullptr) | ||
| { | ||
| FoamProblem * problem = dynamic_cast<FoamProblem *>(&getSubProblem()); | ||
| if (!problem) | ||
| mooseError("Foam-based Postprocessors can only be used with FoamProblem"); | ||
|
|
||
| _foam_mesh = &problem->mesh().fvMesh(); | ||
| } | ||
|
|
||
| void | ||
| FoamPostprocessorBase::initialize() | ||
| { | ||
| } | ||
|
|
||
| void | ||
| FoamPostprocessorBase::execute() | ||
| { | ||
| } | ||
|
|
||
| void | ||
| FoamPostprocessorBase::finalize() | ||
| { | ||
| } | ||
|
|
||
| void | ||
| FoamPostprocessorBase::threadJoin(const UserObject & uo) | ||
|
||
| { | ||
| (void)uo; | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #include "ElementUserObject.h" | ||
| #include "FoamSideAdvectiveFluxIntegral.h" | ||
| #include "InputParameters.h" | ||
| #include "MooseTypes.h" | ||
| #include "FoamMesh.h" | ||
|
|
||
| registerMooseObject("hippoApp", FoamSideAdvectiveFluxIntegral); | ||
|
|
||
| InputParameters | ||
| FoamSideAdvectiveFluxIntegral::validParams() | ||
| { | ||
| auto params = FoamSidePostprocessor::validParams(); | ||
| params.addClassDescription( | ||
| "Class that calculates the average or scalar on a OpenFOAM boundary patch."); | ||
| params.addRequiredParam<std::string>("foam_scalar", "Foam scalar being advected."); | ||
| params.addParam<std::string>("advective_velocity", "U", "Advection velocity"); | ||
| return params; | ||
| } | ||
|
|
||
| FoamSideAdvectiveFluxIntegral::FoamSideAdvectiveFluxIntegral(const InputParameters & params) | ||
| : FoamSidePostprocessor(params), | ||
| _value(0.), | ||
| _foam_scalar(params.get<std::string>("foam_scalar")), | ||
| _advection_velocity(params.get<std::string>("advective_velocity")) | ||
| { | ||
|
|
||
| if (!_foam_mesh->foundObject<Foam::volScalarField>(_foam_scalar)) | ||
| mooseError("foam_scalar '", _foam_scalar, "' not found."); | ||
|
|
||
| if (!_foam_mesh->foundObject<Foam::volVectorField>(_advection_velocity)) | ||
| mooseError("advective_velocity '", _advection_velocity, "' not found."); | ||
| } | ||
|
|
||
| void | ||
| FoamSideAdvectiveFluxIntegral::compute() | ||
| { | ||
| _value = 0.; | ||
| for (auto & boundary : _boundary) | ||
| { | ||
| auto & var_array = | ||
| _foam_mesh->boundary()[boundary].lookupPatchField<Foam::volScalarField, double>( | ||
| _foam_scalar); | ||
|
|
||
| auto & vel_array = | ||
| _foam_mesh->boundary()[boundary].lookupPatchField<Foam::volVectorField, double>( | ||
| _advection_velocity); | ||
|
|
||
| auto & areas = _foam_mesh->boundary()[boundary].magSf(); | ||
| auto && normals = _foam_mesh->boundary()[boundary].nf(); | ||
|
|
||
| // integrate locally | ||
| for (int i = 0; i < var_array.size(); ++i) | ||
| { | ||
| _value += var_array[i] * areas[i] * (normals->data()[i] & vel_array[i]); | ||
| } | ||
| } | ||
|
|
||
| // Sum across ranks | ||
| gatherSum(_value); | ||
| } | ||
|
|
||
| PostprocessorValue | ||
| FoamSideAdvectiveFluxIntegral::getValue() const | ||
| { | ||
| return _value; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "Field.H" | ||
| #include "FoamSideAverageValue.h" | ||
| #include "FoamSideIntegratedValue.h" | ||
| #include "InputParameters.h" | ||
|
|
||
| registerMooseObject("hippoApp", FoamSideAverageValue); | ||
|
|
||
| FoamSideAverageValue::FoamSideAverageValue(const InputParameters & params) | ||
| : FoamSideIntegratedValue(params) | ||
| { | ||
| } | ||
|
|
||
| void | ||
| FoamSideAverageValue::compute() | ||
| { | ||
|
|
||
| FoamSideIntegratedValue::compute(); | ||
|
|
||
| Real volume = 0.; | ||
| // loop over boundary ids | ||
| for (auto & boundary : _boundary) | ||
| { | ||
| auto & areas = _foam_mesh->boundary()[boundary].magSf(); | ||
| for (int i = 0; i < areas.size(); ++i) | ||
| { | ||
| volume += areas[i]; | ||
| } | ||
| } | ||
| // sum over ranks | ||
| gatherSum(volume); | ||
|
||
|
|
||
| // divide by area | ||
| _value /= volume; | ||
|
||
| } | ||
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.
We spotted this PR doesn't build in debug mode because of the problem documented in
fvCFD.H. You can move your necessary includes there and include foam things via that file.All your foam includes in header files can be replaced with forward declarations.