Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : // Moose includes 11 : #include "Tecplot.h" 12 : #include "MooseApp.h" 13 : #include "FEProblem.h" 14 : #include "MooseMesh.h" 15 : 16 : #include "libmesh/tecplot_io.h" 17 : 18 : registerMooseObject("MooseApp", Tecplot); 19 : 20 : InputParameters 21 14395 : Tecplot::validParams() 22 : { 23 : // Get the base class parameters 24 14395 : InputParameters params = SampledOutput::validParams(); 25 : 26 : // Add binary toggle 27 14395 : params.addParam<bool>("binary", false, "Set Tecplot files to output in binary format"); 28 14395 : params.addParamNamesToGroup("binary", "Advanced"); 29 : 30 : // Add optional parameter to turn on appending to ASCII files 31 43185 : params.addParam<bool>( 32 : "ascii_append", 33 28790 : false, 34 : "If true, append to an existing ASCII file rather than creating a new file each time"); 35 : 36 : // Need a layer of geometric ghosting for mesh serialization 37 14395 : params.addRelationshipManager("ElementPointNeighborLayers", 38 : Moose::RelationshipManagerType::GEOMETRIC); 39 : 40 : // Add description for the Tecplot class 41 14395 : params.addClassDescription("Object for outputting data in the Tecplot format"); 42 : 43 : // Return the InputParameters 44 14395 : return params; 45 0 : } 46 : 47 65 : Tecplot::Tecplot(const InputParameters & parameters) 48 : : SampledOutput(parameters), 49 65 : _binary(getParam<bool>("binary")), 50 65 : _ascii_append(getParam<bool>("ascii_append")), 51 130 : _first_time(declareRestartableData<bool>("first_time", true)) 52 : { 53 : #ifndef LIBMESH_HAVE_TECPLOT_API 54 65 : if (_binary) 55 : { 56 13 : mooseWarning( 57 : "Teclplot binary output requested but not available, outputting ASCII format instead."); 58 13 : _binary = false; 59 : } 60 : #endif 61 65 : } 62 : 63 : void 64 132 : Tecplot::output() 65 : { 66 132 : libMesh::TecplotIO out(*_mesh_ptr, _binary, getOutputTime() + _app.getGlobalTimeOffset()); 67 : 68 : // Only set the append flag on the TecplotIO object if the user has 69 : // asked for it, and this is not the first time we called output(). 70 132 : if (_ascii_append && !_first_time) 71 12 : out.ascii_append() = true; 72 : 73 132 : out.write_equation_systems(filename(), *_es_ptr); 74 : 75 : // If we're not appending, increment the file number. If we are appending, 76 : // we'll use the same filename each time. 77 132 : if (_binary || !_ascii_append) 78 108 : _file_num++; 79 : 80 : // If this was the first time we called output(), the next time will not be 81 : // the first time. 82 132 : if (_first_time) 83 60 : _first_time = false; 84 132 : } 85 : 86 : std::string 87 197 : Tecplot::filename() 88 : { 89 197 : std::ostringstream output; 90 197 : output << _file_base; 91 : 92 : // If not appending, put the padded time step in the filename. 93 197 : if (_binary || !_ascii_append) 94 160 : output << "_" << std::setw(_padding) << std::setprecision(0) << std::setfill('0') << std::right 95 160 : << _file_num; 96 : 97 : // .plt extension is for binary files 98 : // .dat extension is for ASCII files 99 197 : if (_binary) 100 0 : return output.str() + ".plt"; 101 : else 102 394 : return output.str() + ".dat"; 103 197 : }