findRefCell.C
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 #include "findRefCell.H"
00028
00029
00030
00031 void Foam::setRefCell
00032 (
00033 const volScalarField& field,
00034 const dictionary& dict,
00035 label& refCelli,
00036 scalar& refValue,
00037 const bool forceReference
00038 )
00039 {
00040 if (field.needReference() || forceReference)
00041 {
00042 word refCellName = field.name() + "RefCell";
00043 word refPointName = field.name() + "RefPoint";
00044
00045 word refValueName = field.name() + "RefValue";
00046
00047 if (dict.found(refCellName))
00048 {
00049 if (Pstream::master())
00050 {
00051 refCelli = readLabel(dict.lookup(refCellName));
00052
00053 if (refCelli < 0 || refCelli >= field.mesh().nCells())
00054 {
00055 FatalIOErrorIn
00056 (
00057 "void Foam::setRefCell\n"
00058 "(\n"
00059 " const volScalarField&,\n"
00060 " const dictionary&,\n"
00061 " label& scalar&,\n"
00062 " bool\n"
00063 ")",
00064 dict
00065 ) << "Illegal master cellID " << refCelli
00066 << ". Should be 0.." << field.mesh().nCells()
00067 << exit(FatalIOError);
00068 }
00069 }
00070 else
00071 {
00072 refCelli = -1;
00073 }
00074 }
00075 else if (dict.found(refPointName))
00076 {
00077 point refPointi(dict.lookup(refPointName));
00078 refCelli = field.mesh().findCell(refPointi);
00079 label hasRef = (refCelli >= 0 ? 1 : 0);
00080 label sumHasRef = returnReduce<label>(hasRef, sumOp<label>());
00081 if (sumHasRef != 1)
00082 {
00083 FatalIOErrorIn
00084 (
00085 "void Foam::setRefCell\n"
00086 "(\n"
00087 " const volScalarField&,\n"
00088 " const dictionary&,\n"
00089 " label& scalar&,\n"
00090 " bool\n"
00091 ")",
00092 dict
00093 ) << "Unable to set reference cell for field " << field.name()
00094 << nl << " Reference point " << refPointName
00095 << " " << refPointi
00096 << " found on " << sumHasRef << " domains (should be one)"
00097 << nl << exit(FatalIOError);
00098 }
00099 }
00100 else
00101 {
00102 FatalIOErrorIn
00103 (
00104 "void Foam::setRefCell\n"
00105 "(\n"
00106 " const volScalarField&,\n"
00107 " const dictionary&,\n"
00108 " label& scalar&,\n"
00109 " bool\n"
00110 ")",
00111 dict
00112 ) << "Unable to set reference cell for field " << field.name()
00113 << nl
00114 << " Please supply either " << refCellName
00115 << " or " << refPointName << nl << exit(FatalIOError);
00116 }
00117
00118 refValue = readScalar(dict.lookup(refValueName));
00119 }
00120 }
00121
00122
00123 Foam::scalar Foam::getRefCellValue
00124 (
00125 const volScalarField& field,
00126 const label refCelli
00127 )
00128 {
00129 scalar refCellValue = (refCelli >= 0 ? field[refCelli] : 0.0);
00130 return returnReduce<label>(refCellValue, sumOp<scalar>());
00131 }
00132
00133
00134
Copyright © 2000-2009 OpenCFD Ltd