CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Why Do I Need This Workaround? (Custom functionObject)

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 12, 2020, 14:07
Default Why Do I Need This Workaround? (Custom functionObject)
  #1
Member
 
Conor Crickmore
Join Date: Jan 2020
Location: Leicestershire, United Kingdom
Posts: 36
Rep Power: 6
cjc96 is on a distinguished road
Hey!
As always, I hope everyone is keeping well at the moment!

I'm still stumbling my way through self-teaching C++ and basic OpenFOAM editing/development but without the time available to properly devote to learning C++ explicitly, I'm basically building my knowledge one error at a time.

Last week I implemented a new functionObject bringing the DESModelRegions functionality from OpenFOAM v2.3 to OpenFOAM v7 with a little help from wyldckat's own implementation but using a slightly different structure as a practice exercise.

The function itself works but I've had to implement a small workaround to overcome a compilation error. The problem section is as follows:

Code:
{
	const icoDESmodel& DES = dynamic_cast<const icoDESmodel&>(turbModel);

	tmp<volScalarField> tDESfield(DES.LESRegion());
	volScalarField &DESmodelRegions = tDESfield.ref();

	word result("DESmodelRegions");

	return store
	(
		result,
		DESmodelRegions / dimensionedScalar(dimless, 1)
	);
}
Without the (mathematically) redundant division by one, the compiler complains about type mismatches, specifically:

Code:
error: no matching function for call to ‘Foam::functionObjects::DESmodelRegions::store(Foam::word&, Foam::volScalarField&)’

‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ is not derived from ‘const Foam::tmp<T>’
Now, I know enough to infer that the issue is if I just attempt to store 'DESmodelRegions' the program is trying to store a word, whereas with the division by one, it's being forced into storing a volScalarField as is intended. So I think the problem is in improper use of referncing in my actual calculation of DESmodelRegions, but I don't know what I've actually done wrong and arbitrary removal/addition of references didn't accomplish much

Obviously the current implementation works but is far from elegant and I'd like to understand how to avoid it in the future, so if anyone could point out my error I'd be very grateful as always!
__________________
Conor Crickmore
PhD Researcher in Automotive Aerodynamics
Aeronautical and Automotive Engineering
Loughborough University
LE11 3TU
cjc96 is offline   Reply With Quote

Old   October 31, 2020, 14:47
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,687
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by cjc96 View Post
Without the (mathematically) redundant division by one, the compiler complains about type mismatches, specifically:

Code:
error: no matching function for call to ‘Foam::functionObjects::DESmodelRegions::store(Foam::word&, Foam::volScalarField&)’

‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ is not derived from ‘const Foam::tmp<T>’
Now, I know enough to infer that the issue is if I just attempt to store 'DESmodelRegions' the program is trying to store a word, whereas with the division by one, it's being forced into storing a volScalarField as is intended.
Actually the problem the error shows is not the word (first parameter) but the second parameter! The store() expects the second parameter to be tmp type, which it can claim the memory of etc. In your version that didn't compile, you passed a volScalarField for storage, not a tmp. By adding in the pointless division operation, you have created a tmp and it works. You will have to decide yourself which quantity you want to store.
cjc96 and FaroukH like this.
olesen is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making my custom functionObject run in parallel sippanspojk OpenFOAM Programming & Development 21 February 25, 2020 13:13
OF-4.x: Multiple Inheritance of a functionObject A_Pete OpenFOAM Programming & Development 1 September 21, 2016 10:01
Problem in sampling data of custom field function in ANSYS FLUENT v14 apek_great ANSYS 1 February 26, 2014 05:10
Create registered object at runtime using a functionObject CedricVH OpenFOAM Programming & Development 21 November 28, 2012 05:04
defining custom convetive terms CFD user CFX 1 February 22, 2009 22:40


All times are GMT -4. The time now is 17:16.