|
[Sponsors] |
April 4, 2012, 02:29 |
setFields.C within solver code
|
#1 |
Member
ak
Join Date: May 2011
Posts: 64
Rep Power: 15 |
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 |
|
April 5, 2012, 05:01 |
|
#2 |
Member
Sachin Kanetkar
Join Date: Mar 2009
Posts: 57
Rep Power: 17 |
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 |
|
April 5, 2012, 07:13 |
|
#3 | |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,093
Rep Power: 34 |
Quote:
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; } } |
||
April 9, 2012, 11:15 |
|
#4 |
Member
ak
Join Date: May 2011
Posts: 64
Rep Power: 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; } |
|
|
|
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 |