void PiersonMoskowitz::set( Ostream& os ) { // Get the input parameters scalar Hs(readScalar(dict_.lookup("Hs"))); scalar Tp(readScalar(dict_.lookup("Tp"))); scalar depth(readScalar(dict_.lookup("depth"))); vector direction(vector(dict_.lookup("direction"))); label N = readLabel(dict_.lookup("N")); // Calculate the frequency axis autoPtr<Foam::frequencyAxis> fA = Foam::frequencyAxis::New(rT_, dict_); scalarField nodeFrequency(N + 1, 0); // An intermediate step needed for certain discretisation types // Placed in scopes such that the temporary variables to not 'survive' { equidistantFrequencyAxis equiFA(rT_, dict_); scalarField tempFreqAxis = equiFA.freqAxis(10000); scalarField tempSpectrum = this->spectralValue(Hs, Tp, tempFreqAxis); nodeFrequency = fA->freqAxis(tempFreqAxis, tempSpectrum, N); } // Prepare variables freq_.setSize(N); amp_.setSize(N); phi_.setSize(N); k_.setSize(N); // Compute spectrum scalarField S = this->spectralValue(Hs, Tp, nodeFrequency); // Prepare stokesFirst to compute wave numbers Foam::stokesFirstProperties stp( rT_, dict_ ); // Compute return variables for (int i = 1; i < N + 1; i++) { // The frequency is the mid-point between two nodes freq_[i - 1] = 0.5*(nodeFrequency[i - 1] + nodeFrequency[i]); // Amplitude is the square root of the trapezoidal integral amp_[i - 1] = Foam::sqrt ( (S[i-1] + S[i]) *(nodeFrequency[i] - nodeFrequency[i - 1]) ); // Wave number based on linear wave theory k_[i - 1] = direction*stp.linearWaveNumber(depth, freq_[i-1]); // The phase is computed based on the phase-function phi_[i - 1] = phases_->phase(freq_[i - 1], k_[i - 1]); } writeSpectrum(os, nodeFrequency, S); }
int main(int argc, char *argv[]) { bool_t analyze_output, equilibria_only; int niter, nact; Atom *atom; Molecule *molecule; /* --- Read input data and initialize -- -------------- */ setOptions(argc, argv); getCPU(0, TIME_START, NULL); SetFPEtraps(); readInput(); spectrum.updateJ = TRUE; getCPU(1, TIME_START, NULL); readAtmos(&atmos, &geometry); if (atmos.Stokes) Bproject(); fillMesh(&geometry); readAtomicModels(); readMolecularModels(); SortLambda(); getBoundary(&atmos, &geometry); Background(analyze_output=TRUE, equilibria_only=FALSE); getProfiles(); initSolution(); initScatter(); getCPU(1, TIME_POLL, "Total initialize"); /* --- Solve radiative transfer for active ingredients -- --------- */ Iterate(input.NmaxIter, input.iterLimit); adjustStokesMode(atom); niter = 0; while (niter < input.NmaxScatter) { if (solveSpectrum(FALSE, FALSE) <= input.iterLimit) break; niter++; } /* --- Write output files -- ------------------ */ getCPU(1, TIME_START, NULL); writeInput(); writeAtmos(&atmos); writeGeometry(&geometry); writeSpectrum(&spectrum); writeFlux(FLUX_DOT_OUT); for (nact = 0; nact < atmos.Nactiveatom; nact++) { atom = atmos.activeatoms[nact]; writeAtom(atom); writePopulations(atom); writeRadRate(atom); writeCollisionRate(atom); writeDamping(atom); } for (nact = 0; nact < atmos.Nactivemol; nact++) { molecule = atmos.activemols[nact]; writeMolPops(molecule); } writeOpacity(); getCPU(1, TIME_POLL, "Write output"); printTotalCPU(); }