27 using StateVecs = std::vector<std::shared_ptr<FiniteElementState> >;
41 : pv(std::move(pv_)), states(states_), dual_states(tracked_reactions_), opts({})
52 : pv(std::move(pv_)), states(states_), dual_states(tracked_reactions_), opts(opts_)
58 void write(
size_t step,
double time,
const std::vector<const FiniteElementState*>& current_states)
61 SLIC_ERROR_ROOT_IF(current_states.size() != states.size(),
"wrong number of output states to write");
63 for (
size_t n = 0; n < states.size(); ++n) {
64 auto& state = states[n];
65 *state = *current_states[n];
66 state->gridFunction();
69 pv->SetCycle(
static_cast<int>(step));
76 void write(
size_t step,
double time,
const std::vector<const FiniteElementDual*>& current_duals)
79 SLIC_ERROR_ROOT_IF(current_duals.size() != dual_states.size(),
"wrong number of output states to write");
81 for (
size_t n = 0; n < dual_states.size(); ++n) {
82 auto&
dual = dual_states[n];
83 current_duals[n]->linearForm().ParallelAssemble(*
dual);
87 pv->SetCycle(
static_cast<int>(step));
95 void write(
int step,
double time,
const std::vector<FieldState>& current_fields)
98 SLIC_ERROR_ROOT_IF(current_fields.size() != states.size(),
"wrong number of output states to write");
100 for (
size_t n = 0; n < states.size(); ++n) {
101 auto& state = states[n];
102 *state = *current_fields[n].get();
103 state->gridFunction();
106 SLIC_ERROR_ROOT_IF(dual_states.size() != states.size(),
"wrong number of output dual states to write");
107 auto&
dual = dual_states[n];
108 current_fields[n].get_dual()->linearForm().ParallelAssemble(*
dual);
109 dual->gridFunction();
119 void write(
size_t step,
double time,
const std::vector<FieldState>& current_fields)
121 write(
static_cast<int>(step), time, current_fields);
125 std::unique_ptr<mfem::ParaViewDataCollection> pv;
136 if (output_name ==
"") {
137 output_name =
"default";
143 auto non_const_mesh =
const_cast<mfem::ParMesh*
>(&mesh.
mfemParMesh());
144 auto paraview_dc = std::make_unique<mfem::ParaViewDataCollection>(output_name, non_const_mesh);
146 int max_order_in_fields = 1;
149 for (
const auto& fstate : states) {
150 const auto& state = fstate.get();
151 output_states.push_back(std::make_shared<smith::FiniteElementState>(state->space(), state->name()));
152 paraview_dc->RegisterField(state->name(), &output_states.back()->gridFunction());
153 max_order_in_fields =
std::max(max_order_in_fields, state->space().GetOrder(0));
156 const auto&
dual = fstate.get_dual();
157 output_duals.push_back(std::make_shared<smith::FiniteElementState>(
dual->space(),
dual->name()));
158 paraview_dc->RegisterField(
dual->name(), &output_duals.back()->gridFunction());
159 max_order_in_fields =
std::max(max_order_in_fields,
dual->space().GetOrder(0));
164 paraview_dc->SetLevelsOfDetail(max_order_in_fields);
165 paraview_dc->SetHighOrderOutput(
true);
166 paraview_dc->SetDataFormat(mfem::VTKFormat::BINARY);
167 paraview_dc->SetCompression(
true);
169 return ParaviewWriter(std::move(paraview_dc), output_states, output_duals, opts);
177 std::string output_name)
184 inline auto createParaviewWriter(
const mfem::ParMesh& mesh,
const std::vector<const FiniteElementState*>& states,
185 std::string output_name)
187 if (output_name ==
"") {
188 output_name =
"default";
192 for (
const auto& s : states) {
193 output_states.push_back(std::make_shared<smith::FiniteElementState>(s->space(), s->name()));
196 auto non_const_mesh =
const_cast<mfem::ParMesh*
>(&mesh);
197 auto paraview_dc = std::make_unique<mfem::ParaViewDataCollection>(output_name, non_const_mesh);
199 int max_order_in_fields = 1;
202 for (
const auto& state : output_states) {
203 paraview_dc->RegisterField(state->name(), &state->gridFunction());
204 max_order_in_fields =
std::max(max_order_in_fields, state->space().GetOrder(0));
208 paraview_dc->SetLevelsOfDetail(max_order_in_fields);
209 paraview_dc->SetHighOrderOutput(
true);
210 paraview_dc->SetDataFormat(mfem::VTKFormat::BINARY);
211 paraview_dc->SetCompression(
true);
Helper class for constructing a mesh consistent with Smith.
const mfem::ParMesh & mfemParMesh() const
Returns const parallel mfem mesh.
Class which interactions with ParaViewDataCollection to write arbitrary field results to disk....
void write(size_t step, double time, const std::vector< FieldState > ¤t_fields)
overload
std::vector< std::shared_ptr< FiniteElementState > > StateVecs
using
void write(size_t step, double time, const std::vector< const FiniteElementState * > ¤t_states)
write paraview output from vector of finite element states. states must be passed in with a consisten...
void write(size_t step, double time, const std::vector< const FiniteElementDual * > ¤t_duals)
write paraview output from vector of finite element duals. duals must be passed in with a consistent ...
ParaviewWriter(std::unique_ptr< mfem::ParaViewDataCollection > pv_, const StateVecs &states_, const StateVecs &tracked_reactions_)
Construct a writer backed by an existing ParaView data collection.
void write(int step, double time, const std::vector< FieldState > ¤t_fields)
write paraview output from vector of FieldState. These must be passed in with a consistent order as h...
ParaviewWriter(std::unique_ptr< mfem::ParaViewDataCollection > pv_, const StateVecs &states_, const StateVecs &tracked_reactions_, Options opts_)
Construct a writer backed by an existing ParaView data collection with explicit output options.
Smith mesh class which assists in constructing the appropriate parallel mfem meshes and registering a...
Accelerator functionality.
auto createParaviewWriter(const smith::Mesh &mesh, const std::vector< FieldState > &states, std::string output_name, ParaviewWriter::Options opts)
Creates a ParaviewWriter from a mesh, vector of FieldState, and the name of the output paraview file....
SMITH_HOST_DEVICE auto max(dual< gradient_type > a, double b)
Implementation of max for dual numbers.
#define SMITH_MARK_FUNCTION
Options that control which fields are written to ParaView output.
bool write_duals
When true, write dual/reaction fields alongside the primary states.
Dual number struct (value plus gradient)