Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #include <OpenFOAM/argList.H>
00064 #include <OpenFOAM/timeSelector.H>
00065 #include <OpenFOAM/Time.H>
00066 #include <finiteVolume/fvMesh.H>
00067 #include <meshTools/topoSetSource.H>
00068 #include <meshTools/cellSet.H>
00069 #include <finiteVolume/volFields.H>
00070
00071 using namespace Foam;
00072
00073 template<class GeoField>
00074 void setFieldType
00075 (
00076 const fvMesh& mesh,
00077 const labelList& selectedCells,
00078 Istream& fieldValueStream
00079 )
00080 {
00081 word fieldName(fieldValueStream);
00082
00083 IOobject fieldHeader
00084 (
00085 fieldName,
00086 mesh.time().timeName(),
00087 mesh,
00088 IOobject::MUST_READ
00089 );
00090
00091
00092 if (fieldHeader.headerOk())
00093 {
00094 Info<< " Setting " << fieldHeader.headerClassName()
00095 << " " << fieldName << endl;
00096
00097 GeoField field(fieldHeader, mesh);
00098
00099 typename GeoField::value_type value
00100 (
00101 static_cast<const typename GeoField::value_type&>
00102 (
00103 pTraits<typename GeoField::value_type>(fieldValueStream)
00104 )
00105 );
00106
00107 if (selectedCells.size() == field.size())
00108 {
00109 field.internalField() = value;
00110 }
00111 else
00112 {
00113 forAll(selectedCells, celli)
00114 {
00115 field[selectedCells[celli]] = value;
00116 }
00117 }
00118
00119 forAll(field.boundaryField(), patchi)
00120 {
00121 field.boundaryField()[patchi] =
00122 field.boundaryField()[patchi].patchInternalField();
00123 }
00124
00125 field.write();
00126 }
00127 else
00128 {
00129 WarningIn
00130 (
00131 "void setFieldType"
00132 "(const fvMesh& mesh, const labelList& selectedCells,"
00133 "Istream& fieldValueStream)"
00134 ) << "Field " << fieldName << " not found" << endl;
00135 }
00136 }
00137
00138
00139 class setField
00140 {
00141
00142 public:
00143
00144 setField()
00145 {}
00146
00147 autoPtr<setField> clone() const
00148 {
00149 return autoPtr<setField>(new setField());
00150 }
00151
00152 class iNew
00153 {
00154 const fvMesh& mesh_;
00155 const labelList& selectedCells_;
00156
00157 public:
00158
00159 iNew(const fvMesh& mesh, const labelList& selectedCells)
00160 :
00161 mesh_(mesh),
00162 selectedCells_(selectedCells)
00163 {}
00164
00165 autoPtr<setField> operator()(Istream& fieldValues) const
00166 {
00167 word fieldType(fieldValues);
00168
00169 if (fieldType == "volScalarFieldValue")
00170 {
00171 setFieldType<volScalarField>
00172 (mesh_, selectedCells_, fieldValues);
00173 }
00174 else if (fieldType == "volVectorFieldValue")
00175 {
00176 setFieldType<volVectorField>
00177 (mesh_, selectedCells_, fieldValues);
00178 }
00179 else if (fieldType == "volSphericalTensorFieldValue")
00180 {
00181 setFieldType<volSphericalTensorField>
00182 (mesh_, selectedCells_, fieldValues);
00183 }
00184 else if (fieldType == "volSymmTensorFieldValue")
00185 {
00186 setFieldType<volSymmTensorField>
00187 (mesh_, selectedCells_, fieldValues);
00188 }
00189 else if (fieldType == "volTensorFieldValue")
00190 {
00191 setFieldType<volTensorField>
00192 (mesh_, selectedCells_, fieldValues);
00193 }
00194 else
00195 {
00196 WarningIn("setField::iNew::operator()(Istream& is)")
00197 << "field type " << fieldType << " not currently supported"
00198 << endl;
00199 }
00200
00201 return autoPtr<setField>(new setField());
00202 }
00203 };
00204 };
00205
00206
00207
00208
00209 int main(int argc, char *argv[])
00210 {
00211 timeSelector::addOptions();
00212
00213 # include <OpenFOAM/setRootCase.H>
00214 # include <OpenFOAM/createTime.H>
00215
00216
00217 instantList timeDirs = timeSelector::select0(runTime, args);
00218
00219 # include <OpenFOAM/createMesh.H>
00220
00221 Info<< "Reading setFieldsDict\n" << endl;
00222
00223 IOdictionary setFieldsDict
00224 (
00225 IOobject
00226 (
00227 "setFieldsDict",
00228 runTime.system(),
00229 mesh,
00230 IOobject::MUST_READ,
00231 IOobject::NO_WRITE
00232 )
00233 );
00234
00235 if (setFieldsDict.found("defaultFieldValues"))
00236 {
00237 Info<< "Setting field default values" << endl;
00238 PtrList<setField> defaultFieldValues
00239 (
00240 setFieldsDict.lookup("defaultFieldValues"),
00241 setField::iNew(mesh, labelList(mesh.nCells()))
00242 );
00243 Info<< endl;
00244 }
00245
00246
00247 Info<< "Setting field region values" << endl;
00248
00249 PtrList<entry> regions(setFieldsDict.lookup("regions"));
00250
00251 forAll(regions, regionI)
00252 {
00253 const entry& region = regions[regionI];
00254
00255 autoPtr<topoSetSource> cellSelector =
00256 topoSetSource::New(region.keyword(), mesh, region.dict());
00257
00258 cellSet selectedCellSet
00259 (
00260 mesh,
00261 "cellSet",
00262 mesh.nCells()/10+1
00263 );
00264
00265 cellSelector->applyToSet
00266 (
00267 topoSetSource::NEW,
00268 selectedCellSet
00269 );
00270
00271 PtrList<setField> fieldValues
00272 (
00273 region.dict().lookup("fieldValues"),
00274 setField::iNew(mesh, selectedCellSet.toc())
00275 );
00276 }
00277
00278 Info<< "\nEnd" << endl;
00279
00280 return 0;
00281 }
00282
00283
00284