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/)
-   -   Writing in another case (https://www.cfd-online.com/Forums/openfoam-solving/58261-writing-another-case.html)

johndeas October 17, 2008 09:38

Hi, I am writing a tool wit
 
Hi,

I am writing a tool with which I would like to be able to write in another case than the one used to launched the tool (To do operations between fields obtained in different cases).

Here is the kind of field I use to write at time directory 2 in another case:

volVectorField UBase
(
IOobject
(
"UBase",
"../channel-base/2",
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
UFirst
);

However, a call to UBase.write() did not produce the creation of the file in the corresponding directory. Is this a restriction, and is there a way to bypass it ?

Note: I have already used "../" in a case name for an IOobject to read data, it works, but writing does not.

Thanks !

JD

johndeas October 20, 2008 08:35

Problem solved, there seem to
 
Problem solved, there seem to be no problem to use "../" . I was just writing the wrong fields in my test case and got the impression that nothing was done.

johndeas October 20, 2008 11:07

Another thing, if the destinat
 
Another thing, if the destination directory ("2" in my example) exist, the file is written there, otherwise a zero directory is created and files are wrtten into it. I don't understand this behaviour.

mattijs October 20, 2008 14:34

Bit strange usage. Split the .
 
Bit strange usage. Split the ../channel-base/2 into a local (directory, "../channel-base") and an instance (time, "2"). Might still not work though. Or have an additional runTime to point to the other directory like e.g. mapFields.

johndeas December 1, 2008 11:21

Hi, I would like to get rid
 
Hi,

I would like to get rid of the strange usage to get a code similar to mapFields: multiple runTime objects. My problem is different in that the number of cases will only be known at runtime (through command-line argument) and I would like to automatize in a loop calls to the constructors. My first attempt was to use something like this:

Foam::Time * dynRunTime = new Foam::Time[nbCases];

for (label i=1;i<nbCases;i++)
{
dynRunTime[i] = Foam::Time
(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
)
}

where args.rootPath() and args.caseName() would have been replaced by apropriate pathnames generated automatically using i as a parameter. This construction is however impossible, because the "new" keyword call the constructors immediately.

Is there a simple way to achieve this ?

johndeas December 1, 2008 12:27

I also tried using std::vector
 
I also tried using std::vector with

std::vector<foam::time> dynRuntime;

dynRuntime.push_back(
Foam::Time(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
)
);

but only got compilation errors: http://pastebin.com/f4de2fe3

johndeas December 1, 2008 12:58

Finally, using initializers
 
Finally,

using initializers and a fixed size array (having to recompile is not a pb, as the array still provide a benefit for loops further in my code):

Foam::Time dynRunTime[2] = {
Foam::Time
(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
),
Foam::Time
(
Foam::Time::controlDictName,
args.rootPath(),
args.caseName()
)
};

I still got compilation error ( http://pastebin.com/f78914746 )

Enough for today... If somebody knowledgeable pass by... please... help...

olesen December 2, 2008 02:20

John, Why don't you try a P
 
John,

Why don't you try a PtrList to store your pointers?

eg, (pseudo-code)

PtrList<foam::time> myTimes(nbCases);

forAll(myTimes, timeI)
{
myTimes.set
(
timeI,
new Time
(
Foam::Time::controlDictName,
rootPath[timeI],
caseName[timeI]
)
);
}


All times are GMT -4. The time now is 06:08.