CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   setFields.C within solver code (https://www.cfd-online.com/Forums/openfoam/99462-setfields-c-within-solver-code.html)

newOFuser April 4, 2012 01:29

setFields.C within solver code
 
Hi

Does anyone know if it is possible to call setFields.C from within the solver C code? What is the correct procedure since both C codes have main function (and this gives an error).

Still learning C++!

ak

sachin April 5, 2012 04:01

Hi AK...
Probably a very stupid answer..but hope it helps ...
Create your own solver ... and change name of setFields.C keeping the references same and change the mail function in it to your name...
Might work ... If it doesnt... dont blame me :)

Best Luck
Sachin

bigphil April 5, 2012 06:13

Quote:

Originally Posted by newOFuser (Post 353030)
Hi

Does anyone know if it is possible to call setFields.C from within the solver C code? What is the correct procedure since both C codes have main function (and this gives an error).

Still learning C++!

ak

Hi ak,

what fields do you want to set? You probably only need a few lines of code to set the fields you want.

For example, if you want to set the value of a volScalarField vsf based on the x coordinate of the cell centre:
Code:

forAll(mesh.C(). celli) // for all mesh cell centres
{
  if(mesh.C()[celli].component(vector::X) > 3.1)
  {
    vsf.internalField()[celli] = 1;
  }
  else
  {
    vsf.internalField()[celli] = 0;
  }
}

Philip

newOFuser April 9, 2012 10:15

Thanks for your replies. I wanted to change the temperature, which has a constant access in the source code. So unless I add a non constant access to T in the source code, I have to use other ways to change T.

I tried some ways based on what I found in the forum, and found that using setFields works. But I want to use it to change T over a few time steps, and so am looking to include it in the solver.

Following is the code I use (and it works) but for this to work, I need to have time directories after each computation. Any ways to avoid this and use the previous time step computations directly, without creating time directories?


Info<<"Igniting"<<endl;

timeSelector::addOptions();
instantList timeDirs = instantList(1, instant(runTime.value(), runTime.timeName())); //writeInterval has to be same as computational 'fixed' deltaT

Info<< "Reading setFieldsDict\n" << endl;
IOdictionary setFieldsDict
(
IOobject
(
"setFieldsDict",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);

Info<< "Setting field region values" << endl;
PtrList<entry> regions(setFieldsDict.lookup("regions"));
forAll(regions, regionI)
{
const entry& region = regions[regionI];
autoPtr<topoSetSource> cellSelector =
topoSetSource::New(region.keyword(), mesh, region.dict());
cellSet selectedCellSet
(
mesh,
"cellSet",
mesh.nCells()/10+1 // Reasonable size estimate.
);
Info<<"Step a"<<endl;
cellSelector->applyToSet
(
topoSetSource::NEW,
selectedCellSet
);
Info<<"Step b"<<endl;
PtrList<setField> fieldValues
(
region.dict().lookup("fieldValues"),
setField::iNew(mesh, selectedCellSet.toc())
);
Info<<"Step c"<<endl;
}


All times are GMT -4. The time now is 23:38.