void Foam::hdf5SurfaceWriter::writeData ( const hid_t& file_id, const word& surfaceName, const word& fieldName, const word& time, const Field<scalar>& values ) { ioScalar* scalarData; scalarData = new ioScalar[values.size()]; // Loop through the field and construct the array forAll(values, iter) { scalarData[iter] = values[iter]; } hid_t group = H5Gopen2(file_id, time.c_str(), H5P_DEFAULT); hsize_t dimsf[1]; dimsf[0] = values.size(); hid_t dataspace = H5Screate_simple(1, dimsf, NULL); hid_t datatype = H5Tcopy(H5T_SCALAR); char datasetName[80]; sprintf ( datasetName, "%s/%s", time.c_str(), fieldName.c_str() ); hid_t dataset = H5Dcreate2(file_id, datasetName, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(dataset, H5T_SCALAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, scalarData); H5Dclose(dataset); H5Sclose(dataspace); H5Tclose(datatype); H5Gclose(group); delete [] scalarData; }
Foam::fileName Foam::home(const word& userName) { struct passwd* pw; if (userName.size()) { pw = getpwnam(userName.c_str()); } else { char* env = getenv("HOME"); if (env != NULL) { return fileName(env); } pw = getpwuid(getuid()); } if (pw != NULL) { return pw->pw_dir; } else { return fileName::null; } }
bool env(const word& envName) { const DWORD actualBufferSize = ::GetEnvironmentVariable(envName.c_str(), NULL, 0); const bool envExists = (0 < actualBufferSize); return envExists; }
bool Foam::setEnv ( const word& envName, const string& value, const bool overwrite ) { return setenv(envName.c_str(), value.c_str(), overwrite) == 0; }
string getEnv(const word& envName) { std::string envAsString; const DWORD actualBufferSize = ::GetEnvironmentVariable(envName.c_str(), NULL, 0); if (0 < actualBufferSize) { MSwindows::AutoArray<TCHAR> actualBuffer(actualBufferSize); ::GetEnvironmentVariable(envName.c_str(), actualBuffer.get(), actualBufferSize); envAsString = actualBuffer.get(); toUnixPath(envAsString); } return envAsString; }
bool setEnv ( const word& envName, const string& value, const bool overwrite ) { const bool success = ::SetEnvironmentVariable(envName.c_str(), value.c_str()); return success; }
Foam::string Foam::getEnv(const word& envName) { char* env = getenv(envName.c_str()); if (env) { return string(env); } else { // Return null-constructed string rather than string::null // to avoid cyclic dependencies in the construction of globals return string(); } }
bool Foam::functionEntry::execute ( const word& functionName, const dictionary& parentDict, primitiveEntry& entry, Istream& is ) { is.fatalCheck ( "functionEntry::execute" "(const word&, const dictionary&, primitiveEntry&, Istream&)" ); if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_) { cerr<<"functionEntry::execute" << "(const word&, const dictionary&, primitiveEntry&, Istream&)" << " not yet initialized, function = " << functionName.c_str() << std::endl; // return true to keep reading anyhow return true; } executeprimitiveEntryIstreamMemberFunctionTable::iterator mfIter = executeprimitiveEntryIstreamMemberFunctionTablePtr_->find(functionName); if (mfIter == executeprimitiveEntryIstreamMemberFunctionTablePtr_->end()) { FatalErrorIn ( "functionEntry::execute" "(const word&, const dictionary&, primitiveEntry&, Istream&)" ) << "Unknown functionEntry '" << functionName << "' in " << is.name() << " near line " << is.lineNumber() << endl << endl << "Valid functionEntries are :" << endl << executeprimitiveEntryIstreamMemberFunctionTablePtr_->toc() << exit(FatalError); } return mfIter()(parentDict, entry, is); }
bool Foam::ping ( const word& destName, const label destPort, const label timeOut ) { char *serverAddress; struct in_addr *ptr; struct hostent *hostPtr; volatile int sockfd; struct sockaddr_in destAddr; // will hold the destination addr u_int addr; if ((hostPtr = gethostbyname(destName.c_str())) == NULL) { FatalErrorIn ( "Foam::ping(const word&, const label)" ) << "gethostbyname error " << h_errno << " for host " << destName << abort(FatalError); } // Get first of the SLL of addresses serverAddress = *(hostPtr->h_addr_list); ptr = reinterpret_cast<struct in_addr*>(serverAddress); addr = ptr->s_addr; // Allocate socket sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { FatalErrorIn ( "Foam::ping(const word&, const label)" ) << "socket error" << abort(FatalError); } // Fill sockaddr_in structure with dest address and port memset (reinterpret_cast<char *>(&destAddr), '\0', sizeof(destAddr)); destAddr.sin_family = AF_INET; destAddr.sin_port = htons(ushort(destPort)); destAddr.sin_addr.s_addr = addr; timer myTimer(timeOut); if (timedOut(myTimer)) { // Setjmp from timer jumps back to here fdClose(sockfd); return false; } if ( connect ( sockfd, reinterpret_cast<struct sockaddr*>(&destAddr), sizeof(struct sockaddr) ) != 0 ) { // Connection refused. Check if network was actually used or not. int connectErr = errno; fdClose(sockfd); if (connectErr == ECONNREFUSED) { return true; } //perror("connect"); return false; } fdClose(sockfd); return true; }
bool Foam::env(const word& envName) { return getenv(envName.c_str()) != NULL; }
void LuaFoamDictionaryParserDriver::add(const word& name,const string &value) { lua_pushstring(lua(),value.c_str()); lua_setfield(lua(),-2,name.c_str()); }
void LuaFoamDictionaryParserDriver::add(const word& name,bool value) { lua_pushboolean(lua(),value); lua_setfield(lua(),-2,name.c_str()); }
void LuaFoamDictionaryParserDriver::add(const word& name,label value) { lua_pushinteger(lua(),value); lua_setfield(lua(),-2,name.c_str()); }
void LuaFoamDictionaryParserDriver::add(const word& name,scalar value) { lua_pushnumber(lua(),value); lua_setfield(lua(),-2,name.c_str()); }
Foam::instant::instant(const word& tname) : value_(atof(tname.c_str())), name_(tname) {}
int main(int argc, char *argv[]) { timeSelector::addOptions(); # include "addRegionOption.H" argList::validArgs.append("patchName"); argList::validArgs.append("firstPatchNumber"); argList::validArgs.append("lastPatchNumber"); # include "setRootCase.H" # include "createTime.H" instantList timeDirs = timeSelector::select0(runTime, args); # include "createNamedMesh.H" word patchName = args[1]; const word charfirstPatchNumber = args[2]; const word charlastPatchNumber = args[3]; char* pEnd; int firstPatchNumber = strtod(charfirstPatchNumber.c_str(), &pEnd); int lastPatchNumber = strtod(charlastPatchNumber.c_str(), &pEnd); Info << "Patch name: " << patchName << " id = ["<< charfirstPatchNumber <<":"<< charlastPatchNumber <<"]" << endl; Info << " " << endl; OFstream* outputFile; fileName outpuFilename(mesh.time().path()/"wettedAreaPatch"+patchName+charfirstPatchNumber+"-"+charlastPatchNumber); outputFile = new OFstream(outpuFilename); *outputFile << "#Time " << tab << "totalWettedArea" << tab; for(label id=firstPatchNumber; id<=lastPatchNumber; id++) { *outputFile << "wettedArea-" << id << tab; } *outputFile << endl; forAll(timeDirs, timeI) { runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; mesh.readUpdate(); // Read gas density IOobject alphaheader ( "alpha.water", runTime.timeName(), mesh, IOobject::MUST_READ ); Info<< " Reading alpha" << endl; volScalarField alpha(alphaheader,mesh); scalar totalWettedArea(0); scalarField wettedArea(lastPatchNumber+1,scalar(0)); scalar totalSurfaceArea(0); for(label id=firstPatchNumber; id<=lastPatchNumber; id++) { // Calculate wetted area on the plane word patchNumber; std::stringstream ss; ss << id; patchNumber = ss.str(); const label patchI = mesh.boundaryMesh().findPatchID(patchName+patchNumber); if (patchI < 0) { FatalError << "Unable to find patch " << patchName << nl << exit(FatalError); } wettedArea[id] = gSum(alpha.boundaryField()[patchI]*mesh.magSf().boundaryField()[patchI]); totalWettedArea += wettedArea[id]; totalSurfaceArea += gSum(mesh.magSf().boundaryField()[patchI]); } if(Pstream::master()) //Write only if master { Info<< " Writing mass flow rates into the file " << outpuFilename << endl; *outputFile << alpha.mesh().time().value() << tab << totalWettedArea << tab; for(label id=firstPatchNumber; id<=lastPatchNumber; id++) { *outputFile << wettedArea[id] << tab << " "; } *outputFile << totalSurfaceArea << endl; } Info << " " << endl; }