void Foam::csvTableReader<Type>::operator() ( const fileName& fName, List<Tuple2<scalar, Type>>& data ) { IFstream in(fName); DynamicList<Tuple2<scalar, Type>> values; // Skip header if (headerLine_) { string line; in.getLine(line); } while (in.good()) { string line; in.getLine(line); DynamicList<string> splitted; std::size_t pos = 0; while (pos != std::string::npos) { std::size_t nPos = line.find(separator_, pos); if (nPos == std::string::npos) { splitted.append(line.substr(pos)); pos=nPos; } else { splitted.append(line.substr(pos, nPos-pos)); pos=nPos+1; } } if (splitted.size() <= 1) { break; } scalar time = readScalar(IStringStream(splitted[timeColumn_])()); Type value = readValue(splitted); values.append(Tuple2<scalar,Type>(time, value)); } data.transfer(values); }
scalar CSV<scalar>::readValue(const List<string>& splitted) { if (componentColumns_[0] >= splitted.size()) { FatalErrorIn("CSV<scalar>::readValue(const List<string>&)") << "No column " << componentColumns_[0] << " in " << splitted << endl << exit(FatalError); } return readScalar(IStringStream(splitted[componentColumns_[0]])()); }
Foam::dictionary Foam::ICCG::solverDict ( const scalar tol, const scalar relTol ) { dictionary dict(IStringStream("solver PCG; preconditioner DIC;")()); dict.add("tolerance", tol); dict.add("relTol", relTol); return dict; }
scalar csvTableReader<scalar>::readValue(const List<string>& split) { if (componentColumns_[0] >= split.size()) { FatalErrorInFunction << "No column " << componentColumns_[0] << " in " << split << endl << exit(FatalError); } return readScalar(IStringStream(split[componentColumns_[0]])()); }
void Foam::CSV<Type>::read() { IFstream is(fName_.expand()); DynamicList<Tuple2<scalar, Type> > values; // skip header if (headerLine_) { string line; is.getLine(line); } // read data while (is.good()) { string line; is.getLine(line); DynamicList<string> splitted; std::size_t pos = 0; while (pos != std::string::npos) { std::size_t nPos = line.find(separator_, pos); if (nPos == std::string::npos) { splitted.append(line.substr(pos)); pos = nPos; } else { splitted.append(line.substr(pos, nPos - pos)); pos = nPos + 1; } } if (splitted.size() <= 1) { break; } scalar x = readScalar(IStringStream(splitted[refColumn_])()); Type value = readValue(splitted); values.append(Tuple2<scalar,Type>(x, value)); } this->table_.transfer(values); }
Foam::scalar Foam::fileFormats::NASCore::parseNASCoord ( const string& s ) { size_t expSign = s.find_last_of("+-"); if (expSign != string::npos && expSign > 0 && !isspace(s[expSign-1])) { scalar mantissa = readScalar(IStringStream(s.substr(0, expSign))()); scalar exponent = readScalar(IStringStream(s.substr(expSign+1))()); if (s[expSign] == '-') { exponent = -exponent; } return mantissa * pow(10, exponent); } else { return readScalar(IStringStream(s)()); } }
bool Foam::functionEntries::calcEntry::execute ( const dictionary& parentDict, primitiveEntry& entry, Istream& is ) { dictionary args(parentDict, is); OStringStream resultStream; resultStream << (args.lookup("x")[0].number() + args.lookup("y")[0].number()); entry.read(parentDict, IStringStream(resultStream.str())()); return true; }
Foam::label Foam::Function1Types::CSV<Foam::label>::readValue ( const List<string>& split ) { if (componentColumns_[0] >= split.size()) { FatalErrorInFunction << "No column " << componentColumns_[0] << " in " << split << endl << exit(FatalError); } return readLabel(IStringStream(split[componentColumns_[0]])()); }
typename Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolationMethod Foam::AMIInterpolation<SourcePatch, TargetPatch>::wordTointerpolationMethod ( const word& im ) { interpolationMethod method = imDirect; wordList methods ( IStringStream ( "(" "directAMI " "mapNearestAMI " "faceAreaWeightAMI " "partialFaceAreaWeightAMI" ")" )() ); if (im == "directAMI") { method = imDirect; } else if (im == "mapNearestAMI") { method = imMapNearest; } else if (im == "faceAreaWeightAMI") { method = imFaceAreaWeight; } else if (im == "partialFaceAreaWeightAMI") { method = imPartialFaceAreaWeight; } else { FatalErrorInFunction << "Invalid interpolationMethod " << im << ". Valid methods are:" << methods << exit(FatalError); } return method; }
Type Foam::Function1Types::CSV<Type>::readValue(const List<string>& split) { Type result; for (label i = 0; i < pTraits<Type>::nComponents; i++) { if (componentColumns_[i] >= split.size()) { FatalErrorInFunction << "No column " << componentColumns_[i] << " in " << split << endl << exit(FatalError); } result[i] = readScalar(IStringStream(split[componentColumns_[i]])()); } return result; }
Foam::solidReaction<ReactionThermo>::solidReaction ( const speciesTable& species, const HashPtrTable<ReactionThermo>& thermoDatabase, const dictionary& dict ) : Reaction<ReactionThermo>(species, thermoDatabase, dict), pyrolisisGases_(dict.parent().parent().lookup("gaseousSpecies")), glhs_(), grhs_() { this->setLRhs ( IStringStream(dict.lookup("reaction"))(), pyrolisisGases_, glhs_, grhs_ ); }
Type CSV<Type>::readValue(const List<string>& splitted) { Type result; for (label i = 0; i < pTraits<Type>::nComponents; i++) { if (componentColumns_[i] >= splitted.size()) { FatalErrorIn("CSV<Type>::readValue(const List<string>&)") << "No column " << componentColumns_[i] << " in " << splitted << endl << exit(FatalError); } result[i] = readScalar(IStringStream(splitted[componentColumns_[i]])()); } return result; }
bool triSurface::readNAS(const fileName& fName) { IFstream is(fName); if (!is.good()) { FatalErrorIn("triSurface::readNAS(const fileName&)") << "Cannot read file " << fName << exit(FatalError); } // coordinates of point DynamicList<point> points; // Nastran index of point DynamicList<label> indices; // Faces in terms of Nastran point indices DynamicList<labelledTri> faces; // From face group to patch Map<label> groupToPatch; label nPatches = 0; // Name for face group Map<word> groupToName; // Ansa tags. Denoted by $ANSA_NAME. These will appear just before the // first use of a type. We read them and store the pshell types which // are used to name the patches. label ansaId = -1; word ansaType; string ansaName; // A single warning per unrecognized command HashSet<word> unhandledCmd; while (is.good()) { string line; is.getLine(line); // Ansa extension if (line.substr(0, 10) == "$ANSA_NAME") { string::size_type sem0 = line.find (';', 0); string::size_type sem1 = line.find (';', sem0+1); string::size_type sem2 = line.find (';', sem1+1); if ( sem0 != string::npos && sem1 != string::npos && sem2 != string::npos ) { ansaId = readLabel ( IStringStream(line.substr(sem0+1, sem1-sem0-1))() ); ansaType = line.substr(sem1+1, sem2-sem1-1); string nameString; is.getLine(ansaName); if (ansaName[ansaName.size()-1] == '\r') { ansaName = ansaName.substr(1, ansaName.size()-2); } else { ansaName = ansaName.substr(1, ansaName.size()-1); } // Info<< "ANSA tag for NastranID:" << ansaId // << " of type " << ansaType // << " name " << ansaName << endl; } } // Hypermesh extension // $HMNAME COMP 1"partName" if ( line.substr(0, 12) == "$HMNAME COMP" && line.find ('"') != string::npos ) { label groupId = readLabel ( IStringStream(line.substr(16, 16))() ); IStringStream lineStream(line.substr(32)); string rawName; lineStream >> rawName; groupToName.insert(groupId, string::validate<word>(rawName)); Info<< "group " << groupId << " => " << rawName << endl; } if (line.empty() || line[0] == '$') { // Skip empty or comment continue; } // Check if character 72 is continuation if (line.size() > 72 && line[72] == '+') { line = line.substr(0, 72); while (true) { string buf; is.getLine(buf); if (buf.size() > 72 && buf[72]=='+') { line += buf.substr(8, 64); } else { line += buf.substr(8, buf.size()-8); break; } } } // Read first word IStringStream lineStream(line); word cmd; lineStream >> cmd; if (cmd == "CTRIA3") { label groupId = readLabel(IStringStream(line.substr(16,8))()); label a = readLabel(IStringStream(line.substr(24,8))()); label b = readLabel(IStringStream(line.substr(32,8))()); label c = readLabel(IStringStream(line.substr(40,8))()); // Convert group into patch Map<label>::const_iterator iter = groupToPatch.find(groupId); label patchI; if (iter == groupToPatch.end()) { patchI = nPatches++; groupToPatch.insert(groupId, patchI); Info<< "patch " << patchI << " => group " << groupId << endl; } else { patchI = iter(); } faces.append(labelledTri(a, b, c, patchI)); } else if (cmd == "CQUAD4") { label groupId = readLabel(IStringStream(line.substr(16,8))()); label a = readLabel(IStringStream(line.substr(24,8))()); label b = readLabel(IStringStream(line.substr(32,8))()); label c = readLabel(IStringStream(line.substr(40,8))()); label d = readLabel(IStringStream(line.substr(48,8))()); // Convert group into patch Map<label>::const_iterator iter = groupToPatch.find(groupId); label patchI; if (iter == groupToPatch.end()) { patchI = nPatches++; groupToPatch.insert(groupId, patchI); Info<< "patch " << patchI << " => group " << groupId << endl; } else { patchI = iter(); } faces.append(labelledTri(a, b, c, patchI)); faces.append(labelledTri(c, d, a, patchI)); } else if (cmd == "PSHELL") { // Read shell type since group gives patchnames label groupId = readLabel(IStringStream(line.substr(8,8))()); if (groupId == ansaId && ansaType == "PSHELL") { groupToName.insert(groupId, string::validate<word>(ansaName)); Info<< "group " << groupId << " => " << ansaName << endl; } } else if (cmd == "GRID") { label index = readLabel(IStringStream(line.substr(8,8))()); scalar x = parseNASCoord(line.substr(24, 8)); scalar y = parseNASCoord(line.substr(32, 8)); scalar z = parseNASCoord(line.substr(40, 8)); indices.append(index); points.append(point(x, y, z)); } else if (cmd == "GRID*") { // Long format is on two lines with '*' continuation symbol // on start of second line. // Typical line (spaces compacted) // GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // * 2.14897901E+02 label index = readLabel(IStringStream(line.substr(8,16))()); scalar x = parseNASCoord(line.substr(40, 16)); scalar y = parseNASCoord(line.substr(56, 16)); is.getLine(line); if (line[0] != '*') { FatalErrorIn("triSurface::readNAS(const fileName&)") << "Expected continuation symbol '*' when reading GRID*" << " (double precision coordinate) output" << nl << "Read:" << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << exit(FatalError); } scalar z = parseNASCoord(line.substr(8, 16)); indices.append(index); points.append(point(x, y, z)); } else if (unhandledCmd.insert(cmd)) { Info<< "Unhandled Nastran command " << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << endl; } }
void Foam::calcTypes::randomise::calc ( const argList& args, const Time& runTime, const fvMesh& mesh ) { const stringList& params = args.additionalArgs(); const scalar pertMag = readScalar(IStringStream(params[1])()); const word& fieldName = params[2]; Random rand(1234567); IOobject fieldHeader ( fieldName, runTime.timeName(), mesh, IOobject::MUST_READ ); // Check field exists if (fieldHeader.headerOk()) { bool processed = false; writeRandomField<vector> ( fieldHeader, pertMag, rand, mesh, processed ); writeRandomField<sphericalTensor> ( fieldHeader, pertMag, rand, mesh, processed ); writeRandomField<symmTensor> ( fieldHeader, pertMag, rand, mesh, processed ); writeRandomField<tensor> ( fieldHeader, pertMag, rand, mesh, processed ); if (!processed) { FatalError << "Unable to process " << fieldName << nl << "No call to randomise for fields of type " << fieldHeader.headerClassName() << nl << nl << exit(FatalError); } } else { Info<< " No " << fieldName << endl; } }
#include "IStringStream.H" #include "dictionary.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(ensightPartFaces, 0); addToRunTimeSelectionTable(ensightPart, ensightPartFaces, istream); } Foam::List<Foam::word> Foam::ensightPartFaces::elemTypes_ ( IStringStream ( "(tria3 quad4 nsided)" )() ); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::ensightPartFaces::ensightPartFaces ( label partNumber, const string& partDescription ) : ensightPart(partNumber, partDescription) { isCellData_ = false;
int main(int argc, char *argv[]) { # include "setRootCase.H" # include "createTime.H" # include "createMesh.H" # include "readThermodynamicProperties.H" # include "createFields.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nStarting time loop\n" << endl; while (runTime.loop()) { Info<< "Time = " << runTime.value() << nl << endl; # include "readPISOControls.H" scalar HbyAblend = readScalar(piso.lookup("HbyAblend")); # include "readTimeControls.H" scalar CoNum = max ( mesh.surfaceInterpolation::deltaCoeffs() *mag(phiv)/mesh.magSf() ).value()*runTime.deltaT().value(); Info<< "Max Courant Number = " << CoNum << endl; # include "setDeltaT.H" for (int outerCorr = 0; outerCorr < nOuterCorr; outerCorr++) { magRhoU = mag(rhoU); H = (rhoE + p)/rho; fv::multivariateGaussConvectionScheme<scalar> mvConvection ( mesh, fields, phiv, mesh.schemesDict().divScheme("div(phiv,rhoUH)") ); solve ( fvm::ddt(rho) + mvConvection.fvmDiv(phiv, rho) ); surfaceScalarField rhoUWeights = mvConvection.interpolationScheme()()(magRhoU)() .weights(magRhoU); weighted<vector> rhoUScheme(rhoUWeights); fvVectorMatrix rhoUEqn ( fvm::ddt(rhoU) + fv::gaussConvectionScheme<vector>(mesh, phiv, rhoUScheme) .fvmDiv(phiv, rhoU) ); solve(rhoUEqn == -fvc::grad(p)); solve ( fvm::ddt(rhoE) + mvConvection.fvmDiv(phiv, rhoE) == - mvConvection.fvcDiv(phiv, p) ); T = (rhoE - 0.5*rho*magSqr(rhoU/rho))/Cv/rho; psi = 1.0/(R*T); p = rho/psi; for (int corr = 0; corr < nCorr; corr++) { volScalarField rrhoUA = 1.0/rhoUEqn.A(); surfaceScalarField rrhoUAf("rrhoUAf", fvc::interpolate(rrhoUA)); volVectorField HbyA = rrhoUA*rhoUEqn.H(); surfaceScalarField HbyAWeights = HbyAblend*mesh.weights() + (1.0 - HbyAblend)* LimitedScheme <vector, MUSCLLimiter<NVDTVD>, limitFuncs::magSqr> (mesh, phi, IStringStream("HbyA")()).weights(HbyA); phi = ( surfaceInterpolationScheme<vector>::interpolate (HbyA, HbyAWeights) & mesh.Sf() ) + HbyAblend*fvc::ddtPhiCorr(rrhoUA, rho, rhoU, phi); p.boundaryField().updateCoeffs(); surfaceScalarField phiGradp = rrhoUAf*mesh.magSf()*fvc::snGrad(p); phi -= phiGradp; # include "resetPhiPatches.H" surfaceScalarField rhof = mvConvection.interpolationScheme()()(rho)() .interpolate(rho); phiv = phi/rhof; fvScalarMatrix pEqn ( fvm::ddt(psi, p) + mvConvection.fvcDiv(phiv, rho) + fvc::div(phiGradp) - fvm::laplacian(rrhoUAf, p) ); pEqn.solve(); phi += phiGradp + pEqn.flux(); rho = psi*p; rhof = mvConvection.interpolationScheme()()(rho)() .interpolate(rho); phiv = phi/rhof; rhoU = HbyA - rrhoUA*fvc::grad(p); rhoU.correctBoundaryConditions(); } } U = rhoU/rho; runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; } Info<< "End\n" << endl; return 0; }
bool Foam::fileFormats::NASsurfaceFormat<Face>::read ( const fileName& filename ) { const bool mustTriangulate = this->isTri(); this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorIn ( "fileFormats::NASsurfaceFormat::read(const fileName&)" ) << "Cannot read file " << filename << exit(FatalError); } // Nastran index of points DynamicList<label> pointId; DynamicList<point> dynPoints; DynamicList<Face> dynFaces; DynamicList<label> dynZones; DynamicList<label> dynSizes; Map<label> lookup; // assume the types are not intermixed // leave faces that didn't have a group in 0 bool sorted = true; label zoneI = 0; // Name for face group Map<word> nameLookup; // Ansa tags. Denoted by $ANSA_NAME. // These will appear just before the first use of a type. // We read them and store the PSHELL types which are used to name // the zones. label ansaId = -1; word ansaType, ansaName; // A single warning per unrecognized command HashSet<word> unhandledCmd; while (is.good()) { string line; is.getLine(line); // Ansa extension if (line.substr(0, 10) == "$ANSA_NAME") { string::size_type sem0 = line.find (';', 0); string::size_type sem1 = line.find (';', sem0+1); string::size_type sem2 = line.find (';', sem1+1); if ( sem0 != string::npos && sem1 != string::npos && sem2 != string::npos ) { ansaId = readLabel ( IStringStream(line.substr(sem0+1, sem1-sem0-1))() ); ansaType = line.substr(sem1+1, sem2-sem1-1); string rawName; is.getLine(rawName); if (rawName[rawName.size()-1] == '\r') { rawName = rawName.substr(1, rawName.size()-2); } else { rawName = rawName.substr(1, rawName.size()-1); } string::stripInvalid<word>(rawName); ansaName = rawName; // Info<< "ANSA tag for NastranID:" << ansaId // << " of type " << ansaType // << " name " << ansaName << endl; } } // Hypermesh extension // $HMNAME COMP 1"partName" if ( line.substr(0, 12) == "$HMNAME COMP" && line.find ('"') != string::npos ) { label groupId = readLabel ( IStringStream(line.substr(16, 16))() ); IStringStream lineStream(line.substr(32)); string rawName; lineStream >> rawName; string::stripInvalid<word>(rawName); word groupName(rawName); nameLookup.insert(groupId, groupName); // Info<< "group " << groupId << " => " << groupName << endl; } // Skip empty or comment if (line.empty() || line[0] == '$') { continue; } // Check if character 72 is continuation if (line.size() > 72 && line[72] == '+') { line = line.substr(0, 72); while (true) { string buf; is.getLine(buf); if (buf.size() > 72 && buf[72] == '+') { line += buf.substr(8, 64); } else { line += buf.substr(8, buf.size()-8); break; } } } // Read first word IStringStream lineStream(line); word cmd; lineStream >> cmd; if (cmd == "CTRIA3") { triFace fTri; label groupId = readLabel(IStringStream(line.substr(16,8))()); fTri[0] = readLabel(IStringStream(line.substr(24,8))()); fTri[1] = readLabel(IStringStream(line.substr(32,8))()); fTri[2] = readLabel(IStringStream(line.substr(40,8))()); // Convert groupID into zoneId Map<label>::const_iterator fnd = lookup.find(groupId); if (fnd != lookup.end()) { if (zoneI != fnd()) { // pshell types are intermixed sorted = false; } zoneI = fnd(); } else { zoneI = dynSizes.size(); lookup.insert(groupId, zoneI); dynSizes.append(0); // Info<< "zone" << zoneI << " => group " << groupId <<endl; } dynFaces.append(fTri); dynZones.append(zoneI); dynSizes[zoneI]++; } else if (cmd == "CQUAD4") { face fQuad(4); UList<label>& f = static_cast<UList<label>&>(fQuad); label groupId = readLabel(IStringStream(line.substr(16,8))()); fQuad[0] = readLabel(IStringStream(line.substr(24,8))()); fQuad[1] = readLabel(IStringStream(line.substr(32,8))()); fQuad[2] = readLabel(IStringStream(line.substr(40,8))()); fQuad[3] = readLabel(IStringStream(line.substr(48,8))()); // Convert groupID into zoneId Map<label>::const_iterator fnd = lookup.find(groupId); if (fnd != lookup.end()) { if (zoneI != fnd()) { // pshell types are intermixed sorted = false; } zoneI = fnd(); } else { zoneI = dynSizes.size(); lookup.insert(groupId, zoneI); dynSizes.append(0); // Info<< "zone" << zoneI << " => group " << groupId <<endl; } if (mustTriangulate) { dynFaces.append(triFace(f[0], f[1], f[2])); dynFaces.append(triFace(f[0], f[2], f[3])); dynZones.append(zoneI); dynZones.append(zoneI); dynSizes[zoneI] += 2; } else { dynFaces.append(Face(f)); dynZones.append(zoneI); dynSizes[zoneI]++; } } else if (cmd == "GRID") { label index = readLabel(IStringStream(line.substr(8,8))()); scalar x = parseNASCoord(line.substr(24, 8)); scalar y = parseNASCoord(line.substr(32, 8)); scalar z = parseNASCoord(line.substr(40, 8)); pointId.append(index); dynPoints.append(point(x, y, z)); } else if (cmd == "GRID*") { // Long format is on two lines with '*' continuation symbol // on start of second line. // Typical line (spaces compacted) // GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // * 2.14897901E+02 label index = readLabel(IStringStream(line.substr(8,16))()); scalar x = parseNASCoord(line.substr(40, 16)); scalar y = parseNASCoord(line.substr(56, 16)); is.getLine(line); if (line[0] != '*') { FatalErrorIn ( "fileFormats::NASsurfaceFormat::read(const fileName&)" ) << "Expected continuation symbol '*' when reading GRID*" << " (double precision coordinate) format" << nl << "Read:" << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << exit(FatalError); } scalar z = parseNASCoord(line.substr(8, 16)); pointId.append(index); dynPoints.append(point(x, y, z)); } else if (cmd == "PSHELL") { // pshell type for zone names with the Ansa extension label groupId = readLabel(IStringStream(line.substr(8,8))()); if (groupId == ansaId && ansaType == "PSHELL") { nameLookup.insert(ansaId, ansaName); // Info<< "group " << groupId << " => " << ansaName << endl; } } else if (unhandledCmd.insert(cmd)) { Info<< "Unhandled Nastran command " << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << endl; } }
bool Foam::fileFormats::NASedgeFormat::read ( const fileName& filename ) { clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction << "Cannot read file " << filename << exit(FatalError); } DynamicList<point> dynPoints; DynamicList<edge> dynEdges; DynamicList<label> pointId; // Nastran index of points while (is.good()) { string line; is.getLine(line); // Skip empty or comment if (line.empty() || line[0] == '$') { continue; } // Check if character 72 is continuation if (line.size() > 72 && line[72] == '+') { line = line.substr(0, 72); while (true) { string buf; is.getLine(buf); if (buf.size() > 72 && buf[72] == '+') { line += buf.substr(8, 64); } else { line += buf.substr(8, buf.size()-8); break; } } } // Read first word IStringStream lineStream(line); word cmd; lineStream >> cmd; if (cmd == "CBEAM" || cmd == "CROD") { edge e; // label groupId = readLabel(IStringStream(line.substr(16,8))()); e[0] = readLabel(IStringStream(line.substr(24,8))()); e[1] = readLabel(IStringStream(line.substr(32,8))()); // discard groupID dynEdges.append(e); } else if (cmd == "PLOTEL") { edge e; // label groupId = readLabel(IStringStream(line.substr(16,8))()); e[0] = readLabel(IStringStream(line.substr(16,8))()); e[1] = readLabel(IStringStream(line.substr(24,8))()); // discard groupID dynEdges.append(e); } else if (cmd == "GRID") { label index = readLabel(IStringStream(line.substr(8,8))()); scalar x = parseNASCoord(line.substr(24, 8)); scalar y = parseNASCoord(line.substr(32, 8)); scalar z = parseNASCoord(line.substr(40, 8)); pointId.append(index); dynPoints.append(point(x, y, z)); } else if (cmd == "GRID*") { // Long format is on two lines with '*' continuation symbol // on start of second line. // Typical line (spaces compacted) // GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // * 2.14897901E+02 label index = readLabel(IStringStream(line.substr(8,16))()); scalar x = parseNASCoord(line.substr(40, 16)); scalar y = parseNASCoord(line.substr(56, 16)); is.getLine(line); if (line[0] != '*') { FatalErrorInFunction << "Expected continuation symbol '*' when reading GRID*" << " (double precision coordinate) format" << nl << "Read:" << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << exit(FatalError); } scalar z = parseNASCoord(line.substr(8, 16)); pointId.append(index); dynPoints.append(point(x, y, z)); } } // transfer to normal lists storedPoints().transfer(dynPoints); pointId.shrink(); dynEdges.shrink(); // Build inverse mapping (NASTRAN pointId -> index) Map<label> mapPointId(2*pointId.size()); forAll(pointId, i) { mapPointId.insert(pointId[i], i); }
void Foam::CSV<Type>::read() { fileName expandedFile(fName_); IFstream is(expandedFile.expand()); if (!is.good()) { FatalIOErrorIn("CSV<Type>::read()", is) << "Cannot open CSV file for reading." << exit(FatalIOError); } DynamicList<Tuple2<scalar, Type> > values; // skip header for (label i = 0; i < nHeaderLine_; i++) { string line; is.getLine(line); } label nEntries = max(componentColumns_); // read data while (is.good()) { string line; is.getLine(line); label n = 0; std::size_t pos = 0; DynamicList<string> splitted; if (mergeSeparators_) { std::size_t nPos = 0; while ((pos != std::string::npos) && (n <= nEntries)) { bool found = false; while (!found) { nPos = line.find(separator_, pos); if ((nPos != std::string::npos) && (nPos - pos == 0)) { pos = nPos + 1; } else { found = true; } } nPos = line.find(separator_, pos); if (nPos == std::string::npos) { splitted.append(line.substr(pos)); pos = nPos; n++; } else { splitted.append(line.substr(pos, nPos - pos)); pos = nPos + 1; n++; } } } else { while ((pos != std::string::npos) && (n <= nEntries)) { std::size_t nPos = line.find(separator_, pos); if (nPos == std::string::npos) { splitted.append(line.substr(pos)); pos = nPos; n++; } else { splitted.append(line.substr(pos, nPos - pos)); pos = nPos + 1; n++; } } } if (splitted.size() <= 1) { break; } scalar x = readScalar(IStringStream(splitted[refColumn_])()); Type value = readValue(splitted); values.append(Tuple2<scalar,Type>(x, value)); } this->table_.transfer(values); }
int main(int argc, char *argv[]) { argList::validOptions.insert("ybl", "scalar"); argList::validOptions.insert("Cbl", "scalar"); argList::validOptions.insert("writenut", ""); # include "setRootCase.H" # include "createTime.H" # include "createMesh.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "Reading field U\n" << endl; volVectorField U ( IOobject ( "U", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ), mesh ); # include "createPhi.H" Info<< "Calculating wall distance field" << endl; volScalarField y = wallDist(mesh).y(); // Set the mean boundary-layer thickness dimensionedScalar ybl("ybl", dimLength, 0); if (args.options().found("ybl")) { // If the boundary-layer thickness is provided use it ybl.value() = readScalar(IStringStream(args.options()["ybl"])()); } else if (args.options().found("Cbl")) { // Calculate boundary layer thickness as Cbl * mean distance to wall ybl.value() = gAverage(y)*readScalar(IStringStream(args.options()["Cbl"])()); } else { FatalErrorIn(args.executable()) << "Neither option 'ybl' or 'Cbl' have been provided to calculate" " the boundary-layer thickness" << exit(FatalError); } Info<< "\nCreating boundary-layer for U of thickness " << ybl.value() << " m" << nl << endl; // Modify velocity by applying a 1/7th power law boundary-layer // u/U0 = (y/ybl)^(1/7) // assumes U0 is the same as the current cell velocity scalar yblv = ybl.value(); forAll(U, celli) { if (y[celli] <= yblv) { U[celli] *= ::pow(y[celli]/yblv, (1.0/7.0)); } } Info<< "Writing U" << endl; U.write(); // Update/re-write phi phi = fvc::interpolate(U) & mesh.Sf(); phi.write(); // Set turbulence constants dimensionedScalar kappa("kappa", dimless, 0.4187); dimensionedScalar Cmu("Cmu", dimless, 0.09); // Read and modify turbulence fields if present IOobject epsilonHeader ( "epsilon", runTime.timeName(), mesh, IOobject::MUST_READ ); IOobject kHeader ( "k", runTime.timeName(), mesh, IOobject::MUST_READ ); IOobject nuTildaHeader ( "nuTilda", runTime.timeName(), mesh, IOobject::MUST_READ ); // First calculate nut volScalarField nut ( "nut", sqr(kappa*min(y, ybl))*::sqrt(2)*mag(dev(symm(fvc::grad(U)))) ); if (args.options().found("writenut")) { Info<< "Writing nut" << endl; nut.write(); } // Read and modify turbulence fields if present if (nuTildaHeader.headerOk()) { Info<< "Reading field nuTilda\n" << endl; volScalarField nuTilda(nuTildaHeader, mesh); nuTilda = nut; nuTilda.correctBoundaryConditions(); Info<< "Writing nuTilda\n" << endl; nuTilda.write(); } if (kHeader.headerOk() && epsilonHeader.headerOk()) { Info<< "Reading field k\n" << endl; volScalarField k(kHeader, mesh); Info<< "Reading field epsilon\n" << endl; volScalarField epsilon(epsilonHeader, mesh); scalar ck0 = ::pow(Cmu.value(), 0.25)*kappa.value(); k = sqr(nut/(ck0*min(y, ybl))); k.correctBoundaryConditions(); scalar ce0 = ::pow(Cmu.value(), 0.75)/kappa.value(); epsilon = ce0*k*sqrt(k)/min(y, ybl); epsilon.correctBoundaryConditions(); Info<< "Writing k\n" << endl; k.write(); Info<< "Writing epsilon\n" << endl; epsilon.write(); } Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; Info<< "End\n" << endl; return(0); }
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. \*---------------------------------------------------------------------------*/ #include "SemiImplicitSource.H" #include "fvMesh.H" #include "fvMatrices.H" #include "DimensionedField.H" #include "fvmSup.H" // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // template<class Type> const Foam::wordList Foam::fv::SemiImplicitSource<Type>::volumeModeTypeNames_ ( IStringStream("(absolute specific)")() ); // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template<class Type> typename Foam::fv::SemiImplicitSource<Type>::volumeModeType Foam::fv::SemiImplicitSource<Type>::wordToVolumeModeType ( const word& vmtName ) const { forAll(volumeModeTypeNames_, i) { if (vmtName == volumeModeTypeNames_[i])
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. \*---------------------------------------------------------------------------*/ #include "PhaseChangeModel.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // template<class CloudType> const Foam::wordList Foam::PhaseChangeModel<CloudType>:: enthalpyTransferTypeNames ( IStringStream ( "(" "latentHeat " "enthalpyDifference" ")" )() ); // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // template<class CloudType> typename Foam::PhaseChangeModel<CloudType>::enthalpyTransferType Foam::PhaseChangeModel<CloudType>::wordToEnthalpyTransfer(const word& etName) const { forAll(enthalpyTransferTypeNames, i) {
#include "dictionary.H" #include "cellModeller.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(ensightPartCells, 0); addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream); } Foam::List<Foam::word> Foam::ensightPartCells::elemTypes_ ( IStringStream ( "(tetra4 pyramid5 penta6 hexa8 nfaced)" )() ); // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::ensightPartCells::classify(const labelList& idList) { // References to cell shape models const cellModel& tet = *(cellModeller::lookup("tet")); const cellModel& pyr = *(cellModeller::lookup("pyr")); const cellModel& prism = *(cellModeller::lookup("prism")); const cellModel& hex = *(cellModeller::lookup("hex")); const polyMesh& mesh = *meshPtr_;
int main(int argc, char *argv[]) { # include "setRootCase.H" # include "createTime.H" # include "createMesh.H" # include "createFields.H" # include "initContinuityErrs.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nStarting time loop\n" << endl; for (runTime++; !runTime.end(); runTime++) { Info<< "Time = " << runTime.timeName() << nl << endl; # include "readPISOControls.H" # include "CourantNo.H" fvVectorMatrix UEqn ( fvm::ddt(U) + fvm::div(phi, U) - fvm::laplacian(nu, U) ); fvVectorMatrix UEqnp(UEqn == -fvc::grad(p)); lduVectorMatrix U3Eqnp(mesh); U3Eqnp.diag() = UEqnp.diag(); U3Eqnp.upper() = UEqnp.upper(); U3Eqnp.lower() = UEqnp.lower(); U3Eqnp.source() = UEqnp.source(); UEqnp.addBoundaryDiag(U3Eqnp.diag(), 0); UEqnp.addBoundarySource(U3Eqnp.source(), false); autoPtr<lduVectorMatrix::solver> U3EqnpSolver = lduVectorMatrix::solver::New ( U.name(), U3Eqnp, dictionary ( IStringStream ( "{" " solver PBiCG;" " preconditioner DILU;" " tolerance (1e-13 1e-13 1e-13);" " relTol (0 0 0);" "}" )() ) ); U3EqnpSolver->solve(U).print(Info); // --- PISO loop for (int corr=0; corr<nCorr; corr++) { volScalarField rUA = 1.0/UEqn.A(); U = rUA*UEqn.H(); phi = (fvc::interpolate(U) & mesh.Sf()) + fvc::ddtPhiCorr(rUA, U, phi); adjustPhi(phi, U, p); for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) { fvScalarMatrix pEqn ( fvm::laplacian(rUA, p) == fvc::div(phi) ); pEqn.setReference(pRefCell, pRefValue); pEqn.solve(); if (nonOrth == nNonOrthCorr) { phi -= pEqn.flux(); } } # include "continuityErrs.H" U -= rUA*fvc::grad(p); U.correctBoundaryConditions(); } runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; } Info<< "End\n" << endl; return(0); }
int main(int argc, char *argv[]) { argList::validOptions.insert("normal", "vector"); # include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" // Get normal vector normal(0, 0, 1); if (args.options().found("normal")) { normal = vector(IStringStream(args.options()["normal"])()); if (mag(normal) > SMALL) { normal /= mag(normal); } else { FatalErrorIn(args.executable()) << "Invalid normal given: " << normal << abort(FatalError); } } Info << "Normal vector for height field: " << normal << endl; // Get times list instantList Times = runTime.times(); // set startTime and endTime depending on -time and -latestTime options # include "checkTimeOptions.H" runTime.setTime(Times[startTime], startTime); # include "createMesh.H" for (label i=startTime; i<endTime; i++) { runTime.setTime(Times[i], i); Info<< "Time = " << runTime.timeName() << endl; mesh.readUpdate(); Info<< " Calculating height" << endl; volScalarField height ( IOobject ( "height", runTime.timeName(), mesh, IOobject::NO_READ ), mesh.C() & normal ); height.write(); } Info<< "End\n" << endl; return(0); }
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. \*---------------------------------------------------------------------------*/ #include "PatchInteractionModel.H" #include "fvMesh.H" #include "Time.H" #include "volFields.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // template<class CloudType> Foam::wordList Foam::PatchInteractionModel<CloudType>::interactionTypeNames_ ( IStringStream ( "(rebound stick escape)" )() ); // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class CloudType> Foam::word Foam::PatchInteractionModel<CloudType>::interactionTypeToWord ( const interactionType& itEnum ) { word it = "other"; switch (itEnum) {
IStringStream ( "(" "( 1000 0.00032)" "( 1100 0.00091)" "( 1200 0.00213)" "( 1300 0.00432)" "( 1400 0.00779)" "( 1500 0.01280)" "( 1600 0.01972)" "( 1700 0.02853)" "( 1800 0.03934)" "( 1900 0.05210)" "( 2000 0.06672)" "( 2100 0.08305)" "( 2200 0.10088)" "( 2300 0.12002)" "( 2400 0.14025)" "( 2500 0.16135)" "( 2600 0.18311)" "( 2700 0.20535)" "( 2800 0.22788)" "( 2900 0.25055)" "( 3000 0.27322)" "( 3100 0.29576)" "( 3200 0.31809)" "( 3300 0.34009)" "( 3400 0.36172)" "( 3500 0.38290)" "( 3600 0.40359)" "( 3700 0.42375)" "( 3800 0.44336)" "( 3900 0.46240)" "( 4000 0.48085)" "( 4100 0.49872)" "( 4200 0.51599)" "( 4300 0.53267)" "( 4400 0.54877)" "( 4500 0.56429)" "( 4600 0.57925)" "( 4700 0.59366)" "( 4800 0.60753)" "( 4900 0.62088)" "( 5000 0.63372)" "( 5100 0.64606)" "( 5200 0.65794)" "( 5300 0.66935)" "( 5400 0.68033)" "( 5500 0.69087)" "( 5600 0.70101)" "( 5700 0.71076)" "( 5800 0.72012)" "( 5900 0.72913)" "( 6000 0.73778)" "( 6100 0.74610)" "( 6200 0.75410)" "( 6300 0.76180)" "( 6400 0.76920)" "( 6500 0.77631)" "( 6600 0.78316)" "( 6700 0.78975)" "( 6800 0.79609)" "( 6900 0.80219)" "( 7000 0.80807)" "( 7100 0.81373)" "( 7200 0.81918)" "( 7300 0.82443)" "( 7400 0.82949)" "( 7500 0.83436)" "( 7600 0.83906)" "( 7700 0.84359)" "( 7800 0.84796)" "( 7900 0.85218)" "( 8000 0.85625)" "( 8100 0.86017)" "( 8200 0.86396)" "( 8300 0.86762)" "( 8400 0.87115)" "( 8500 0.87456)" "( 8600 0.87786)" "( 8700 0.88105)" "( 8800 0.88413)" "( 8900 0.88711)" "( 9000 0.88999)" "( 9100 0.89277)" "( 9200 0.89547)" "( 9300 0.89807)" "( 9400 0.90060)" "( 9500 0.90304)" "( 9600 0.90541)" "( 9700 0.90770)" "( 9800 0.90992)" "( 9900 0.91207)" "(10000 0.91415)" "(12000 0.94505)" "(15000 0.96893)" "(20000 0.98555)" "(30000 0.99529)" "(40000 0.99792)" "(50000 0.99890)" ")" )()