CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   dictionary scalarField formatting (https://www.cfd-online.com/Forums/openfoam-solving/100651-dictionary-scalarfield-formatting.html)

mturcios777 April 27, 2012 14:31

dictionary scalarField formatting
 
I'm playing around with some functionality in 1.6-ext and am using a class that requires a scalarField be supplied in a dictionary. Its for a list of times at which to activate a specific boundary condition. How should this entry be formatted? I can't seem to find any tutorials/examples that use this kind of setup.

bigphil April 27, 2012 17:34

Hi,

If you Info a scalarField to the terminal then you can see the format.

It looks like this (where lookupName is just whatever name you want to give it):
Code:

lookupName            5 ( 0 0.005 0.01 0.015 0.02);
Philip

mturcios777 April 27, 2012 17:50

Thanks Phil!

I think that almost does it. How should I format it so that it gets read by code like this:

Code:

scalarField(entries[i].dict().lookup("times"))
?

I currently have

Code:

times 2 (2.0 3.0);
and get the following error:

Code:

--> FOAM FATAL IO ERROR:
    Attempt to return dictionary entry as a primitive


bigphil April 27, 2012 17:54

Hi,

This is how I read a scalarField from a dictionary:
Code:

IOdictionary myData
    (
    IOobject
    (
      "myDict",
      runTime.constant(),
      runTime.db(),
      IOobject::MUST_READ,
      IOobject::NO_WRITE
      )
    );
  const scalarField myTime = myDict.lookup("time");

Philip

mturcios777 April 27, 2012 18:04

That definitely makes more sense to me, but I don't want to go re-writing someone else's class. I've never seen a scalarField read like that, so I'm at a loss here. I'll try enabling some debug switches and see what comes out.

Thanks anyways!

mturcios777 April 27, 2012 20:07

No luck with the debug flags or debug mode. The code I'm looking at is the attachDetach.C. It still exists in OF21x ($FOAM_SRC/dynamicMesh/attachDetach/attachDetach.C), I'm trying it out there and giving it in the same error. Its just syntax, but I can't find anywhere else that uses something similar.

Is it possible that scalarField can't actually be read like this, and no one noticed?

marupio April 30, 2012 10:24

I don't see anything wrong with attachDetach. The only scalarField lookup is for triggerTimes_ in the constructor initialization list, and the syntax is:
Code:

    triggerTimes_(dict.lookup("triggerTimes")),
That's correct as far as I know.

mturcios777 April 30, 2012 13:26

Hi David!

Sorry the confusion, what I meant was is that the problem is with MY syntax in the dictionary to define the triggertimes. The comments made by Philip are correct in that a scalarfield as defined in his first message should be read just fine, but I haven't been able to get it working.

The syntax I have for my attach/detach face is as follows:

Code:

flap1
{
    faceZoneName    flap1; //the internal faces faceZone name
    masterPatch      top;  //the name of the master boundary patch
    slavePatch        bottom; //the name of the slave boundary patch
    triggerTimes      2 (2.0 3.0); //the times to trigger the condition (in this case, at 2.0 and 3.0 seconds)
}

Does anyone have a case that uses the attach/detach condition with a properly formatted dictionary?

marupio April 30, 2012 14:14

I don't know anything about dynamic mesh, but looking at attachDetach.C, the dictionary constructor expects everything to be in the dictionary root. So you need to use "subDict" in your constructor call.

Assume the dictionary you show above is myDict. Your attachDetach constructor call should be something like:

Code:

    attachDetach myAttachDetachObject
    (
        attachDetachName,
        myDict.subDict("flap1"),
        0, // "index"?  I don't know what index is...
        mesh
    );

If you omit .subDict, you will get the error you mention above.

mturcios777 April 30, 2012 18:24

Thanks! I found the error: in the attachDetachFvMesh from 1.6-ext, the modifiers are inside a PtrList<entries>, so the syntax in the dictionary should be:

Code:

modifiers
(
  flap1
  {...}

  flap2
  {...}
//etc.
);

Has anyone used attachDetach in 2.1.x, particularly with compressible flow?


All times are GMT -4. The time now is 03:04.