| 157 | |
| 158 | |
| 159 | void |
| 160 | WriteMultiLevelPlotfile (const std::string& plotfilename, int nlevels, |
| 161 | const Vector<const MultiFab*>& mf, |
| 162 | const Vector<std::string>& varnames, |
| 163 | const Vector<Geometry>& geom, Real time, |
| 164 | const Vector<int>& level_steps, |
| 165 | const Vector<IntVect>& ref_ratio, |
| 166 | const std::string &versionName, |
| 167 | const std::string &levelPrefix, |
| 168 | const std::string &mfPrefix, |
| 169 | const Vector<std::string>& extra_dirs) |
| 170 | { |
| 171 | BL_PROFILE("WriteMultiLevelPlotfile()"); |
| 172 | |
| 173 | BL_ASSERT(nlevels <= mf.size()); |
| 174 | BL_ASSERT(nlevels <= geom.size()); |
| 175 | BL_ASSERT(nlevels <= ref_ratio.size()+1); |
| 176 | BL_ASSERT(nlevels <= level_steps.size()); |
| 177 | BL_ASSERT(mf[0]->nComp() == varnames.size()); |
| 178 | |
| 179 | int finest_level = nlevels-1; |
| 180 | |
| 181 | bool callBarrier(false); |
| 182 | PreBuildDirectorHierarchy(plotfilename, levelPrefix, nlevels, callBarrier); |
| 183 | if (!extra_dirs.empty()) { |
| 184 | for (const auto& d : extra_dirs) { |
| 185 | std::string ed = plotfilename; |
| 186 | ed.append("/").append(d); |
| 187 | amrex::PreBuildDirectorHierarchy(ed, levelPrefix, nlevels, callBarrier); |
| 188 | } |
| 189 | } |
| 190 | ParallelDescriptor::Barrier(); |
| 191 | |
| 192 | if (ParallelDescriptor::MyProc() == ParallelDescriptor::NProcs()-1) { |
| 193 | Vector<BoxArray> boxArrays(nlevels); |
| 194 | for(int level(0); level < boxArrays.size(); ++level) { |
| 195 | boxArrays[level] = mf[level]->boxArray(); |
| 196 | } |
| 197 | |
| 198 | auto f = [=]() { |
| 199 | VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size); |
| 200 | std::string HeaderFileName(plotfilename + "/Header"); |
| 201 | std::ofstream HeaderFile; |
| 202 | HeaderFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size()); |
| 203 | HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out | |
| 204 | std::ofstream::trunc | |
| 205 | std::ofstream::binary); |
| 206 | if( ! HeaderFile.good()) { FileOpenFailed(HeaderFileName); } |
| 207 | WriteGenericPlotfileHeader(HeaderFile, nlevels, boxArrays, varnames, |
| 208 | geom, time, level_steps, ref_ratio, versionName, |
| 209 | levelPrefix, mfPrefix); |
| 210 | }; |
| 211 | |
| 212 | if (AsyncOut::UseAsyncOut()) { |
| 213 | AsyncOut::Submit(std::move(f)); |
| 214 | } else { |
| 215 | f(); |
| 216 | } |