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

setFields.C within solver code

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 4, 2012, 02:29
Default setFields.C within solver code
  #1
Member
 
ak
Join Date: May 2011
Posts: 64
Rep Power: 14
newOFuser is on a distinguished road
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
newOFuser is offline   Reply With Quote

Old   April 5, 2012, 05:01
Default
  #2
Member
 
Sachin Kanetkar
Join Date: Mar 2009
Posts: 57
Rep Power: 17
sachin is on a distinguished road
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
sachin is offline   Reply With Quote

Old   April 5, 2012, 07:13
Default
  #3
Super Moderator
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,086
Rep Power: 34
bigphil will become famous soon enoughbigphil will become famous soon enough
Quote:
Originally Posted by newOFuser View Post
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
bigphil is offline   Reply With Quote

Old   April 9, 2012, 11:15
Default
  #4
Member
 
ak
Join Date: May 2011
Posts: 64
Rep Power: 14
newOFuser is on a distinguished road
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;
}
newOFuser is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
thobois class engineTopoChangerMesh error Peter_600 OpenFOAM 4 August 2, 2014 10:52
Disabling and Enabling Solver Summary Outputs within code adona058 OpenFOAM Running, Solving & CFD 3 November 1, 2007 12:00
free C code for large sparse matrix linear solver ztdep Main CFD Forum 7 May 24, 2007 15:14
AMG solver code Ankan Main CFD Forum 1 May 9, 2007 12:44
Open source CFD code development, possible? Dr. Yazid Bindar Main CFD Forum 27 July 18, 2000 01:18


All times are GMT -4. The time now is 10:42.