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 ///
9 /// file: t_ascent_gradient.cpp
10 ///
11 //-----------------------------------------------------------------------------
12 
13 
14 #include "gtest/gtest.h"
15 
16 #include <ascent.hpp>
17 
18 #include <iostream>
19 #include <math.h>
20 
21 #include <conduit_blueprint.hpp>
22 
23 #include "t_config.hpp"
24 #include "t_utils.hpp"
25 
26 
27 
28 
29 using namespace std;
30 using namespace conduit;
31 using namespace ascent;
32 
33 
34 index_t EXAMPLE_MESH_SIDE_DIM = 20;
35 
36 //-----------------------------------------------------------------------------
TEST(ascent_gradient,vel_gradient)37 TEST(ascent_gradient, vel_gradient)
38 {
39     Node n;
40     ascent::about(n);
41     // only run this test if ascent was built with vtkm support
42     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
43     {
44         ASCENT_INFO("Ascent vtkm support disabled, skipping test");
45         return;
46     }
47 
48     //
49     // Create an example mesh.
50     //
51     Node data, verify_info;
52     conduit::blueprint::mesh::examples::braid("hexs",
53                                               EXAMPLE_MESH_SIDE_DIM,
54                                               EXAMPLE_MESH_SIDE_DIM,
55                                               EXAMPLE_MESH_SIDE_DIM,
56                                               data);
57     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
58 
59     ASCENT_INFO("Testing the qcriterion of a field");
60 
61 
62     string output_path = prepare_output_dir();
63     string output_file = conduit::utils::join_file_path(output_path,"tout_qcriterion_vel");
64 
65     // remove old images before rendering
66     remove_test_image(output_file);
67 
68     //
69     // Create the actions.
70     //
71 
72     conduit::Node pipelines;
73     // pipeline 1
74 
75     pipelines["pl1/f2/type"] = "qcriterion";
76     conduit::Node &params2 = pipelines["pl1/f2/params"];
77     params2["field"] = "vel";                  // name of the input field
78     params2["output_name"] = "vel_qcriterion";   // name of the output field
79     params2["use_cell_gradient"] = "false";
80 
81     conduit::Node scenes;
82     scenes["s1/plots/p1/type"]         = "pseudocolor";
83     scenes["s1/plots/p1/field"] = "vel_qcriterion";
84     scenes["s1/plots/p1/pipeline"] = "pl1";
85 
86     scenes["s1/image_prefix"] = output_file;
87 
88     conduit::Node actions;
89     // add the pipeline
90     conduit::Node &add_pipelines = actions.append();
91     add_pipelines["action"] = "add_pipelines";
92     add_pipelines["pipelines"] = pipelines;
93     // add the scenes
94     conduit::Node &add_scenes= actions.append();
95     add_scenes["action"] = "add_scenes";
96     add_scenes["scenes"] = scenes;
97 
98     //
99     // Run Ascent
100     //
101 
102     Ascent ascent;
103 
104     Node ascent_opts;
105     ascent_opts["runtime/type"] = "ascent";
106     ascent.open(ascent_opts);
107     ascent.publish(data);
108     ascent.execute(actions);
109     ascent.close();
110 
111     // check that we created an image
112     EXPECT_TRUE(check_test_image(output_file));
113     std::string msg = "An example of using the gradient filter "
114                       "and plotting the magnitude.";
115     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
116 
117 }
118 
119 //-----------------------------------------------------------------------------
main(int argc,char * argv[])120 int main(int argc, char* argv[])
121 {
122     int result = 0;
123 
124     ::testing::InitGoogleTest(&argc, argv);
125 
126     // allow override of the data size via the command line
127     if(argc == 2)
128     {
129         EXAMPLE_MESH_SIDE_DIM = atoi(argv[1]);
130     }
131 
132     result = RUN_ALL_TESTS();
133     return result;
134 }
135 
136 
137