OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
DumpEMFields.h
Go to the documentation of this file.
1//
2// Class DumpEMFields
3// DumpEMFields dumps the dynamically changing fields of a Ring in a user-
4// defined grid.
5//
6// Copyright (c) 2017, Chris Rogers
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
19#ifndef OPAL_BASICACTIONS_DUMPEMFIELDS_HH
20#define OPAL_BASICACTIONS_DUMPEMFIELDS_HH
21
22#include <memory>
23#include <set>
24#include <string>
25#include <unordered_set>
29
30namespace interpolation {
31 class NDGrid;
32}
33class Component;
34
55class DumpEMFields : public Action {
56public:
58 enum {
82 SIZE
83 };
84
87
89 DumpEMFields(const std::string& name, DumpEMFields* parent);
90
92 ~DumpEMFields() override = default;
93
99 DumpEMFields* clone(const std::string& name) override;
100
107 void execute() override;
108
123 static void writeFields(const std::set<std::shared_ptr<Component>>& elements);
124
126 void print(std::ostream& os) const override;
127
128 /* For use only by unit tests, simulate a grid failures */
129 static void failGrid() {
130 for (auto& g : dumpsSet_m) {
131 g->grid_m.reset();
132 }
133 }
134 /* For use only by unit tests, simulate file write failures */
135 static void failWrite() {
136 for (auto& g : dumpsSet_m) {
137 g->failWrite_m = true;
138 }
139 }
140 /* For use only by unit tests, clear the set of dump objects */
141 static void clearDumps() { dumpsSet_m.clear(); }
142
143private:
144 enum class CoordinateSystem : unsigned short { CARTESIAN, CYLINDRICAL };
145
146 virtual void writeFieldThis(const std::set<std::shared_ptr<Component>>& elements);
147 virtual void buildGrid();
149 static void checkInt(double value, const std::string& name, double tolerance = 1e-9);
150 void writeHeader(std::ofstream& fout) const;
151 void writeFieldLine(
152 const std::set<std::shared_ptr<Component>>& elements, const Vector_t<double, 3>& point,
153 const double& time, std::ofstream& fout) const;
154
155 std::unique_ptr<interpolation::NDGrid> grid_m{};
157 std::string filename_m{};
158
160
161 static std::unordered_set<std::unique_ptr<DumpEMFields>> dumpsSet_m;
162
163 DumpEMFields(const DumpEMFields& dump) = delete;
164 DumpEMFields& operator=(const DumpEMFields& dump) = delete;
165
166 // For use only by unit tests
167 bool failWrite_m{false};
168};
169
170inline std::ostream& operator<<(std::ostream& os, const DumpEMFields& b) {
171 b.print(os);
172 return os;
173}
174
175#endif // ifdef OPAL_BASICACTIONS_DUMPEMFIELDS_HH
Defines the abstract interface for a single beamline component in the accelerator model.
ippl::Vector< T, Dim > Vector_t
std::ostream & operator<<(std::ostream &os, const DumpEMFields &b)
elements
Definition IndexMap.cpp:168
The base class for all OPAL actions.
Definition Action.h:29
void execute() override
DumpEMFields * clone(const std::string &name) override
DumpEMFields & operator=(const DumpEMFields &dump)=delete
static std::unordered_set< std::unique_ptr< DumpEMFields > > dumpsSet_m
void print(std::ostream &os) const override
static void failWrite()
virtual void buildGrid()
Vector_t< double, 3 > cylindricalOrigin_m
void parseCoordinateSystem()
static void checkInt(double value, const std::string &name, double tolerance=1e-9)
std::string filename_m
static void writeFields(const std::set< std::shared_ptr< Component > > &elements)
CoordinateSystem coordinates_m
void writeHeader(std::ofstream &fout) const
void writeFieldLine(const std::set< std::shared_ptr< Component > > &elements, const Vector_t< double, 3 > &point, const double &time, std::ofstream &fout) const
~DumpEMFields() override=default
std::unique_ptr< interpolation::NDGrid > grid_m
static void failGrid()
static void clearDumps()
DumpEMFields(const DumpEMFields &dump)=delete
virtual void writeFieldThis(const std::set< std::shared_ptr< Component > > &elements)