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 14385 : Tecplot::validParams() 22 : { 23 : // Get the base class parameters 24 14385 : InputParameters params = SampledOutput::validParams(); 25 : 26 : // Add binary toggle 27 14385 : params.addParam<bool>("binary", false, "Set Tecplot files to output in binary format"); 28 14385 : params.addParamNamesToGroup("binary", "Advanced"); 29 : 30 : // Add optional parameter to turn on appending to ASCII files 31 43155 : params.addParam<bool>( 32 : "ascii_append", 33 28770 : 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 14385 : params.addRelationshipManager("ElementPointNeighborLayers", 38 : Moose::RelationshipManagerType::GEOMETRIC); 39 : 40 : // Add description for the Tecplot class 41 14385 : params.addClassDescription("Object for outputting data in the Tecplot format"); 42 : 43 : // Return the InputParameters 44 14385 : return params; 45 0 : } 46 : 47 60 : Tecplot::Tecplot(const InputParameters & parameters) 48 : : SampledOutput(parameters), 49 60 : _binary(getParam<bool>("binary")), 50 60 : _ascii_append(getParam<bool>("ascii_append")), 51 120 : _first_time(declareRestartableData<bool>("first_time", true)) 52 : { 53 : #ifndef LIBMESH_HAVE_TECPLOT_API 54 60 : if (_binary) 55 : { 56 12 : mooseWarning( 57 : "Teclplot binary output requested but not available, outputting ASCII format instead."); 58 12 : _binary = false; 59 : } 60 : #endif 61 60 : } 62 : 63 : void 64 121 : Tecplot::output() 65 : { 66 121 : 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 121 : if (_ascii_append && !_first_time) 71 11 : out.ascii_append() = true; 72 : 73 121 : 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 121 : if (_binary || !_ascii_append) 78 99 : _file_num++; 79 : 80 : // If this was the first time we called output(), the next time will not be 81 : // the first time. 82 121 : if (_first_time) 83 55 : _first_time = false; 84 121 : } 85 : 86 : std::string 87 181 : Tecplot::filename() 88 : { 89 181 : std::ostringstream output; 90 181 : output << _file_base; 91 : 92 : // If not appending, put the padded time step in the filename. 93 181 : if (_binary || !_ascii_append) 94 147 : output << "_" << std::setw(_padding) << std::setprecision(0) << std::setfill('0') << std::right 95 147 : << _file_num; 96 : 97 : // .plt extension is for binary files 98 : // .dat extension is for ASCII files 99 181 : if (_binary) 100 0 : return output.str() + ".plt"; 101 : else 102 362 : return output.str() + ".dat"; 103 181 : }