1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
2 // Copyright (c) Lawrence Livermore National Security, LLC and other Ascent
3 // Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
4 // other details. No copyright assignment is required to contribute to Ascent.
5 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
6 //-----------------------------------------------------------------------------
7 ///
8 /// file: t_ascent_cinema_a.cpp
9 ///
10 //-----------------------------------------------------------------------------
11 
12 #include "gtest/gtest.h"
13 
14 #include <ascent.hpp>
15 
16 #include <iostream>
17 #include <math.h>
18 
19 #include <conduit_blueprint.hpp>
20 
21 #include "t_config.hpp"
22 #include "t_utils.hpp"
23 
24 
25 
26 using namespace std;
27 using namespace conduit;
28 using namespace ascent;
29 
30 index_t EXAMPLE_MESH_SIDE_DIM = 32;
31 
32 //-----------------------------------------------------------------------------
TEST(ascent_queries,max_query)33 TEST(ascent_queries, max_query)
34 {
35     // the vtkm runtime is currently our only rendering runtime
36     Node n;
37     ascent::about(n);
38 
39     //
40     // Create example mesh.
41     //
42     Node data, verify_info;
43     conduit::blueprint::mesh::examples::braid("hexs",
44                                                EXAMPLE_MESH_SIDE_DIM,
45                                                EXAMPLE_MESH_SIDE_DIM,
46                                                EXAMPLE_MESH_SIDE_DIM,
47                                                data);
48 
49     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
50 
51     string output_path = prepare_output_dir();
52     string output_file = conduit::utils::join_file_path(output_path,"tout_max_query");
53     // remove old file
54     if(conduit::utils::is_file(output_file))
55     {
56         conduit::utils::remove_file(output_file);
57     }
58 
59 
60     //
61     // Create the actions.
62     //
63     Node actions;
64 
65     conduit::Node queries;
66     queries["q1/params/expression"] = "max(field('braid'))";
67     queries["q1/params/name"] = "max_braid";
68 
69     conduit::Node &add_queries = actions.append();
70     add_queries["action"] = "add_queries";
71     add_queries["queries"] = queries;
72     actions.print();
73 
74     //
75     // Run Ascent
76     //
77 
78     Ascent ascent;
79     Node ascent_opts;
80     // default is now ascent
81     ascent_opts["runtime/type"] = "ascent";
82     ascent.open(ascent_opts);
83     ascent.publish(data);
84     ascent.execute(actions);
85 
86     conduit::Node info;
87     ascent.info(info);
88     EXPECT_TRUE(info.has_path("expressions/max_braid/100/attrs/value"));
89     info["expressions"].save(output_file, "json");
90     info["expressions/max_braid"].print();
91 
92     ascent.close();
93 
94     // check that we created an image
95     EXPECT_TRUE(conduit::utils::is_file(output_file));
96     std::string msg = "An example of quiering the maximum value of a field.";
97     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
98 }
99 
100 //-----------------------------------------------------------------------------
TEST(ascent_queries,max_query_pipeline)101 TEST(ascent_queries, max_query_pipeline)
102 {
103     // the vtkm runtime is currently our only rendering runtime
104     Node n;
105     ascent::about(n);
106 
107     // only run this test if ascent was built with vtkm support
108     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
109     {
110         ASCENT_INFO("Ascent vtkm support disabled: skipping");
111 
112         return;
113     }
114     //
115     // Create example mesh.
116     //
117     Node data, verify_info;
118     conduit::blueprint::mesh::examples::braid("hexs",
119                                                EXAMPLE_MESH_SIDE_DIM,
120                                                EXAMPLE_MESH_SIDE_DIM,
121                                                EXAMPLE_MESH_SIDE_DIM,
122                                                data);
123 
124     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
125 
126     string output_path = prepare_output_dir();
127     string output_file = conduit::utils::join_file_path(output_path,"tout_max_pipeline_query");
128     // remove old file
129     if(conduit::utils::is_file(output_file))
130     {
131         conduit::utils::remove_file(output_file);
132     }
133 
134     //
135     // Create the actions.
136     //
137     Node actions;
138 
139 
140     conduit::Node pipelines;
141     // pipeline 1
142     pipelines["pl1/f1/type"] = "slice";
143     // filter knobs
144     conduit::Node &slice_params = pipelines["pl1/f1/params"];
145     slice_params["point/x"] = 0.f;
146     slice_params["point/y"] = 0.f;
147     slice_params["point/z"] = 0.f;
148 
149     slice_params["normal/x"] = 0.f;
150     slice_params["normal/y"] = 0.f;
151     slice_params["normal/z"] = 1.f;
152 
153     conduit::Node queries;
154     queries["q1/params/expression"] = "max(field('braid'))";
155     queries["q1/params/name"] = "max_braid_pipeline";
156     queries["q1/pipeline"] = "pl1";
157 
158     conduit::Node &add_queries = actions.append();
159     add_queries["action"] = "add_queries";
160     add_queries["queries"] = queries;
161 
162     // add the pipeline
163     conduit::Node &add_pipelines = actions.append();
164     add_pipelines["action"] = "add_pipelines";
165     add_pipelines["pipelines"] = pipelines;
166 
167     //actions.print();
168     //
169     // Run Ascent
170     //
171 
172     Ascent ascent;
173     Node ascent_opts;
174     // default is now ascent
175     ascent_opts["runtime/type"] = "ascent";
176     ascent.open(ascent_opts);
177     ascent.publish(data);
178     ascent.execute(actions);
179 
180     conduit::Node info;
181     ascent.info(info);
182     EXPECT_TRUE(info.has_path("expressions/max_braid_pipeline/100/attrs/value"));
183     info["expressions"].print();
184     info["expressions"].save(output_file, "json");
185 
186     ascent.close();
187 
188     // check that we created an image
189     EXPECT_TRUE(conduit::utils::is_file(output_file));
190     std::string msg = "An example of quiering the maximum value of a field from the result of a pipeline.";
191     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
192 }
193 
194 //-----------------------------------------------------------------------------
TEST(ascent_queries,cycle_query)195 TEST(ascent_queries, cycle_query)
196 {
197     // the vtkm runtime is currently our only rendering runtime
198     Node n;
199     ascent::about(n);
200 
201     //
202     // Create example mesh.
203     //
204     Node data, verify_info;
205     conduit::blueprint::mesh::examples::braid("hexs",
206                                                EXAMPLE_MESH_SIDE_DIM,
207                                                EXAMPLE_MESH_SIDE_DIM,
208                                                EXAMPLE_MESH_SIDE_DIM,
209                                                data);
210 
211     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
212 
213     string output_path = prepare_output_dir();
214     string output_file = conduit::utils::join_file_path(output_path,"tout_cycle_query");
215     // remove old file
216     if(conduit::utils::is_file(output_file))
217     {
218         conduit::utils::remove_file(output_file);
219     }
220 
221     //
222     // Create the actions.
223     //
224     Node actions;
225 
226     conduit::Node queries;
227     queries["q1/params/expression"] = "cycle()";
228     queries["q1/params/name"] = "cycle";
229 
230     conduit::Node &add_queries = actions.append();
231     add_queries["action"] = "add_queries";
232     add_queries["queries"] = queries;
233     //actions.print();
234 
235     //
236     // Run Ascent
237     //
238 
239     Ascent ascent;
240     Node ascent_opts;
241     // default is now ascent
242     ascent_opts["runtime/type"] = "ascent";
243     ascent.open(ascent_opts);
244     ascent.publish(data);
245     ascent.execute(actions);
246 
247     conduit::Node info;
248     ascent.info(info);
249     EXPECT_TRUE(info.has_path("expressions/cycle/100/value"));
250     EXPECT_TRUE(info["expressions/cycle/100/value"].to_int32() == 100);
251     info["expressions"].save(output_file, "json");
252 
253     ascent.close();
254 
255     // check that we created an image
256     EXPECT_TRUE(conduit::utils::is_file(output_file));
257     std::string msg = "An example of quiering the current cycle.";
258     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
259 }
260 
261 //-----------------------------------------------------------------------------
TEST(ascent_queries,filter_params)262 TEST(ascent_queries, filter_params)
263 {
264     // the vtkm runtime is currently our only rendering runtime
265     Node n;
266     ascent::about(n);
267 
268     // only run this test if ascent was built with vtkm support
269     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
270     {
271         ASCENT_INFO("Ascent vtkm support disabled: skipping");
272 
273         return;
274     }
275 
276     //
277     // Create example mesh.
278     //
279     Node data, verify_info;
280     conduit::blueprint::mesh::examples::braid("hexs",
281                                                EXAMPLE_MESH_SIDE_DIM,
282                                                EXAMPLE_MESH_SIDE_DIM,
283                                                EXAMPLE_MESH_SIDE_DIM,
284                                                data);
285 
286     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
287 
288     string output_path = prepare_output_dir();
289     string output_file =
290       conduit::utils::join_file_path(output_path,"tout_filter_params_query");
291     // remove old file
292     if(conduit::utils::is_file(output_file))
293     {
294         conduit::utils::remove_file(output_file);
295     }
296 
297     //
298     // Create the actions.
299     //
300     Node actions;
301 
302     conduit::Node queries;
303     queries["q1/params/expression"] = "min(field('braid')).value";
304     queries["q1/params/name"] = "min_value";
305     queries["q2/params/expression"] = "max(field('braid')).value";
306     queries["q2/params/name"] = "max_value";
307     queries["q3/params/expression"] = "max_value - min_value";
308     queries["q3/params/name"] = "length";
309 
310     conduit::Node &add_queries = actions.append();
311     add_queries["action"] = "add_queries";
312     add_queries["queries"] = queries;
313     //actions.print();
314 
315     conduit::Node pipelines;
316     // pipeline 1
317     pipelines["pl1/f1/type"] = "threshold";
318     // filter knobs
319     conduit::Node &thresh_params = pipelines["pl1/f1/params"];
320     thresh_params["field"] = "braid";
321     thresh_params["min_value"] = "0.75 * length + min_value";
322     thresh_params["max_value"] = "max_value";
323 
324     // add the pipeline
325     conduit::Node &add_pipelines = actions.append();
326     add_pipelines["action"] = "add_pipelines";
327     add_pipelines["pipelines"] = pipelines;
328 
329     conduit::Node scenes;
330     scenes["s1/plots/p1/type"]         = "pseudocolor";
331     scenes["s1/plots/p1/field"] = "braid";
332     scenes["s1/plots/p1/pipeline"] = "pl1";
333     scenes["s1/image_prefix"] = output_file;
334 
335     // add the scene
336     conduit::Node &add_scenes= actions.append();
337     add_scenes["action"] = "add_scenes";
338     add_scenes["scenes"] = scenes;
339 
340     //
341     // Run Ascent
342     //
343 
344     Ascent ascent;
345     Node ascent_opts;
346     // default is now ascent
347     ascent_opts["runtime/type"] = "ascent";
348     ascent.open(ascent_opts);
349     ascent.publish(data);
350     ascent.execute(actions);
351 
352 
353     ascent.close();
354 
355     // check that we created an image
356     EXPECT_TRUE(check_test_image(output_file));
357     std::string msg = "An example of using queries in filter parameters.";
358     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
359 }
360 
361 //-----------------------------------------------------------------------------
TEST(ascent_queries,save_session)362 TEST(ascent_queries, save_session)
363 {
364     // the vtkm runtime is currently our only rendering runtime
365     Node n;
366     ascent::about(n);
367 
368     //
369     // Create example mesh.
370     //
371     Node data, verify_info;
372     conduit::blueprint::mesh::examples::braid("hexs",
373                                                EXAMPLE_MESH_SIDE_DIM,
374                                                EXAMPLE_MESH_SIDE_DIM,
375                                                EXAMPLE_MESH_SIDE_DIM,
376                                                data);
377 
378     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
379 
380     string output_path = prepare_output_dir();
381     string output_file =
382       conduit::utils::join_file_path(output_path,"tout_save_session");
383 
384     string session_file = "ascent_session.yaml";
385     // remove old file
386     if(conduit::utils::is_file(output_file))
387     {
388       conduit::utils::remove_file(output_file);
389     }
390     // make sure we get rid of the session file
391     if(conduit::utils::is_file(session_file))
392     {
393       std::cout<<"Removing session file "<<session_file<<"\n";
394       conduit::utils::remove_file(session_file);
395     }
396 
397     //
398     // Create the actions.
399     //
400     Node actions;
401 
402     conduit::Node queries;
403     queries["q1/params/expression"] = "min(field('braid')).value";
404     queries["q1/params/name"] = "bananas";
405 
406     conduit::Node &add_queries = actions.append();
407     add_queries["action"] = "add_queries";
408     add_queries["queries"] = queries;
409 
410     conduit::Node &save_session = actions.append();
411     save_session["action"] = "save_session";
412     actions.print();
413     //
414     // Run Ascent
415     //
416 
417     Ascent ascent;
418     Node ascent_opts;
419     // default is now ascent
420     ascent_opts["runtime/type"] = "ascent";
421     ascent.open(ascent_opts);
422     ascent.publish(data);
423     ascent.execute(actions);
424 
425 
426     ascent.close();
427 
428     EXPECT_TRUE(conduit::utils::is_file(session_file));
429     std::string msg = "An example of explicitly saving a session file.";
430     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
431 }
432 
433 //-----------------------------------------------------------------------------
main(int argc,char * argv[])434 int main(int argc, char* argv[])
435 {
436     int result = 0;
437 
438     ::testing::InitGoogleTest(&argc, argv);
439 
440     // allow override of the data size via the command line
441     if(argc == 2)
442     {
443         EXAMPLE_MESH_SIDE_DIM = atoi(argv[1]);
444     }
445 
446     result = RUN_ALL_TESTS();
447     return result;
448 }
449 
450 
451