MFEM v4.8.0
Finite element discretization library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
visualizer.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details
11
12#include "visualizer.hpp"
13#include <string>
14
15namespace mfem
16{
17namespace spde
18{
19
21{
22 ParaViewDataCollection paraview_dc("SurrogateMaterial", mesh_);
23 paraview_dc.SetPrefixPath("ParaView");
24 paraview_dc.SetLevelsOfDetail(order_);
25 paraview_dc.SetCycle(0);
27 paraview_dc.SetHighOrderOutput(true);
28 paraview_dc.SetTime(0.0); // set the time
29 paraview_dc.RegisterField("random_field", &g1_);
30 if (is_3D_)
31 {
32 paraview_dc.RegisterField("topological_support", &g2_);
33 paraview_dc.RegisterField("imperfect_topology", &g3_);
34 paraview_dc.RegisterField("level_set", &g4_);
35 }
36 paraview_dc.Save();
37}
38
39void Visualizer::SendToGLVis(int visport) const
40{
41 std::string vishost{"localhost"};
42 int num_procs = Mpi::WorldSize();
43 int process_rank = Mpi::WorldRank();
44 socketstream uout;
45 std::ostringstream oss_u;
46 uout.open(vishost.c_str(), visport);
47 uout.precision(8);
48 oss_u.str("");
49 oss_u.clear();
50 oss_u << "Random Field";
51 uout << "parallel " << num_procs << " " << process_rank << "\n"
52 << "solution\n"
53 << *mesh_ << g1_ << "window_geometry 0 20 400 350 "
54 << "window_title '" << oss_u.str() << "'" << std::flush;
55 uout.close();
56
57 if (!is_3D_)
58 {
59 return;
60 }
61
62 socketstream vout;
63 std::ostringstream oss_v;
64 vout.open(vishost.c_str(), visport);
65 vout.precision(8);
66 oss_v.str("");
67 oss_v.clear();
68 oss_v << "Topological Support";
69 vout << "parallel " << num_procs << " " << process_rank << "\n"
70 << "solution\n"
71 << *mesh_ << g2_ << "window_geometry 403 20 400 350 "
72 << "window_title '" << oss_v.str() << "'" << std::flush;
73 vout.close();
74
75 socketstream wout;
76 std::ostringstream oss_w;
77 wout.open(vishost.c_str(), visport);
78 wout.precision(8);
79 oss_w.str("");
80 oss_w.clear();
81 oss_w << "Imperfect Topology";
82 wout << "parallel " << num_procs << " " << process_rank << "\n"
83 << "solution\n"
84 << *mesh_ << g3_ << "window_geometry 0 420 400 350 "
85 << "window_title '" << oss_w.str() << "'" << std::flush;
86 wout.close();
87
88 socketstream lout;
89 std::ostringstream oss_l;
90 lout.open(vishost.c_str(), visport);
91 lout.precision(8);
92 oss_l.str("");
93 oss_l.clear();
94 oss_l << "Level Set";
95 lout << "parallel " << num_procs << " " << process_rank << "\n"
96 << "solution\n"
97 << *mesh_ << g4_ << "window_geometry 403 420 400 350 "
98 << "window_title '" << oss_l.str() << "'" << std::flush;
99 lout.close();
100}
101
102} // namespace spde
103} // namespace mfem
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetTime(real_t t)
Set physical time (for time-dependent simulations)
void SetPrefixPath(const std::string &prefix)
Set the path where the DataCollection will be saved.
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static int WorldSize()
Return the size of MPI_COMM_WORLD.
Helper class for ParaView visualization data.
void SetHighOrderOutput(bool high_order_output_)
void SetLevelsOfDetail(int levels_of_detail_)
void SetDataFormat(VTKFormat fmt)
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
int close()
Close the socketstream.
void SendToGLVis(int visport=19916) const
const char vishost[]