-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeleLM_Ascent.cpp
214 lines (177 loc) · 7.07 KB
/
PeleLM_Ascent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//
// Demonstrates how to generate of a Conduit Mesh Blueprint
// description of an AMReX Single Level dataset and render this
// data in situ using with ALPINE Ascent.
//
#include <AMReX_Utility.H>
#include <AMReX_PlotFileUtil.H>
#include <AMReX_ParmParse.H>
#include <AMReX_Print.H>
#include <AMReX_Geometry.H>
#include <AMReX_MultiFab.H>
#include <AMReX_Conduit_Blueprint.H>
#include <PeleLM.H>
#include <conduit/conduit.hpp>
#include <conduit/conduit_blueprint.hpp>
#include <conduit/conduit_relay.hpp>
#include <ascent.hpp>
#include "AMReX_buildInfo.H"
using std::string;
using namespace amrex;
using namespace conduit;
using namespace ascent;
void
PeleLM::goAscent (int nstep)
{
amrex::Print() << " goAscent at nstep " << nstep << std::endl;
Real strt_time = ParallelDescriptor::second();
std::vector<std::pair<int,int> > plot_var_map;
Vector<std::string> var_names;
for (int typ = 0; typ < desc_lst.size(); typ++)
{
for (int comp = 0; comp < desc_lst[typ].nComp();comp++)
{
if (parent->isStatePlotVar(desc_lst[typ].name(comp)) &&
desc_lst[typ].getType() == IndexType::TheCellType())
{
plot_var_map.push_back(std::pair<int,int>(typ,comp));
var_names.push_back(desc_lst[typ].name(comp));
// Debug
// amrex::Print()<<"Var "<<desc_lst[typ].name(comp)<<"\n";
}
}
}
int n_data_items = plot_var_map.size();
amrex::Print() << " n_data_items " << n_data_items << std::endl;
if(n_data_items == 0) return;
Real time = state[State_Type].curTime();
// We combine all of the multifabs -- state, derived, etc -- into one
// multifab -- plotMF.
// NOTE: we are assuming that each state variable has one component,
// but a derived variable is allowed to have multiple components.
amrex::Print()<<"0000000000000000000000000000000000000000000000000000000000000000000000\n";
//const std::list<std::string>& plot_vars = amrptr->statePlotVars();
Vector<const MultiFab*> mfs;
Vector<Geometry> geoms;
// const int nGrow = 1;
const int nGrow = 0;
MultiFab plotMF(grids,dmap,1,nGrow,MFInfo(),Factory());
Vector<int> level_steps;
Vector<IntVect> ref_ratios;
for(int lev = 0; lev <= parent->finestLevel(); ++lev)
{
MultiFab* level_mf = new MultiFab(parent->getLevel(lev).boxArray(),
parent->getLevel(lev).DistributionMap(),
n_data_items,
nGrow,
MFInfo(),
parent->getLevel(lev).Factory());
level_mf->FillBoundary(); // Added by Matt for rendering
mfs.push_back(level_mf);
MultiFab* this_dat = 0;
//
// Cull data from state variables --
//
int cnt = 0;
for (int i = 0; i < static_cast<int>(plot_var_map.size()); i++)
{
int type = plot_var_map[i].first;
int comp = plot_var_map[i].second;
this_dat = &parent->getLevel(lev).get_new_data(type);
MultiFab::Copy(*level_mf,*this_dat,comp,i,1,nGrow);
amrex::Print()<< "Index " << i << " Copy cnt " << type << " " << comp << std::endl;
cnt++;
}
geoms.push_back(parent->getLevel(lev).Geom());
level_steps.push_back(parent->levelSteps(lev));
ref_ratios.push_back(parent->getLevel(lev).fineRatio());
}
//MultiFab plotMF(grids,dmap,1,nGrow,MFInfo(),Factory());
//MultiFab plotMF(grids,dmap,n_data_items,nGrow,MFInfo(),Factory());
Real collect_time = ParallelDescriptor::second() - strt_time;
amrex::Print()<< "goAscent collected variables in time " << collect_time << std::endl;
strt_time = ParallelDescriptor::second();
/////////////////////////////
// Setup Ascent
/////////////////////////////
// Create an instance of Ascent
Ascent ascent;
Node open_opts;
// for the MPI case, provide the mpi comm
#ifdef BL_USE_MPI
open_opts["mpi_comm"] = MPI_Comm_c2f(ParallelDescriptor::Communicator());
#endif
ascent.open(open_opts);
///////////////////////////////////////////////////////////////////
// Wrap our AMReX Mesh into a Conduit Mesh Blueprint Tree
///////////////////////////////////////////////////////////////////
// Write a plotfile of the current data and write a conduit blueprint
// file as well
// in Base/AMReX_PlotFileUtil.cpp
///////////////////////////////////////////////////////////////////
// Wrap our AMReX Mesh into a Conduit Mesh Blueprint Tree
///////////////////////////////////////////////////////////////////
conduit::Node bp_mesh;
MultiLevelToBlueprint( parent->finestLevel()+1,
mfs,
var_names,
geoms,
parent->cumTime(),
level_steps,
ref_ratios,
bp_mesh);
conduit::Node verify_info;
if(!conduit::blueprint::mesh::verify(bp_mesh,verify_info))
{
// verify failed, print error message
ASCENT_INFO("Error: Mesh Blueprint Verify Failed!");
// show details of what went awry
verify_info.print();
}
else
{
amrex::Print()<< " everything A-ok" << std::endl;
// verify_info.print();
}
amrex::Print() << "HERE IS THE SIZE OF OUR DATA " << bp_mesh.total_bytes_compact() << std::endl;
conduit::Node bp_mesh_des;
bp_mesh.describe(bp_mesh_des);
amrex::Print() << bp_mesh_des.to_yaml() << std::endl;
Real setup_time = ParallelDescriptor::second() - strt_time;
amrex::Print()<< "goAscent setup " << setup_time << std::endl;
strt_time = ParallelDescriptor::second();
///////////////////////////////////////////////////////////////////
// Render with Ascent
///////////////////////////////////////////////////////////////////
// add a scene with a pseudocolor plot
Node scenes;
scenes["s1/plots/p1/type"] = "pseudocolor";
scenes["s1/plots/p1/field"] = "temperature";
//Set the output file name (ascent will add ".png")
const std::string& png_out = amrex::Concatenate("ascent_render_",n_data_items,5);
scenes["s1/image_prefix"] = png_out;
///////////////////////////////////////////////////////////////////
// setup actions
Node actions;
Node &add_act = actions.append();
add_act["action"] = "add_scenes";
add_act["scenes"] = scenes;
// add_act["action"] = "add_extracts";
// add_act["extracts"] = extracts;
actions.append()["action"] = "execute";
actions.append()["action"] = "reset";
#if 0
conduit::Node add_pipelines = actions.append();
add_pipelines["action"] = "add_pipelines";
add_pipelines["pipelines"] = pipelines;
#endif
bool GO == nstep > 30;
if(GO)
{
ascent.publish(bp_mesh);
ascent.execute(actions);
}
Real action_time = ParallelDescriptor::second() - strt_time;
amrex::Print()<< "goAscent action " << action_time << std::endl;
ascent.close();
}