https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FilePositions.C
Go to the documentation of this file.
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#include "FilePositions.h"
11#include "DelimitedFileReader.h"
12
14
17{
19 params.addClassDescription("Import positions from one or more files.");
20 params.addRequiredParam<std::vector<FileName>>("files",
21 "Text file(s) with the positions, one per line");
22
23 // Input from file should not be re-ordered
24 params.set<bool>("auto_sort") = false;
25 // File is loaded on all processes
26 params.set<bool>("auto_broadcast") = false;
27
28 return params;
29}
30
32{
33 const auto & positions_files = getParam<std::vector<FileName>>("files");
34 _positions_2d.resize(positions_files.size());
35
36 // Copied from MultiApp.C
37 for (const auto p_file_it : index_range(positions_files))
38 {
39 const std::string positions_file = positions_files[p_file_it];
42 file.read();
43
44 const std::vector<Point> & data = file.getDataAsPoints();
45 for (const auto & d : data)
46 {
47 _positions.push_back(d);
48 _positions_2d[p_file_it].push_back(d);
49 }
50 }
51 _initialized = true;
52 // Sort (if requested) and create KDTree
53 finalize();
54}
registerMooseObject("MooseApp", FilePositions)
Positions from a file.
FilePositions(const InputParameters &parameters)
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Utility class for reading delimited data (e.g., CSV data).
const std::vector< Point > getDataAsPoints() const
Get the data in Point format.
void read()
Perform the actual data reading.
Positions objects are under the hood Reporters.
Definition Positions.h:21
std::vector< std::vector< Point > > _positions_2d
2D storage for all the positions
Definition Positions.h:95
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
Definition Positions.h:92
static InputParameters validParams()
Definition Positions.C:15
virtual void finalize() override
In charge of reduction across all ranks & sorting for consistent output.
Definition Positions.C:220
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition Positions.h:116
const Parallel::Communicator & _communicator