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_slice.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_log,test_log)37 TEST(ascent_log, test_log)
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 log of field");
60 
61 
62     string output_path = prepare_output_dir();
63     string output_file = conduit::utils::join_file_path(output_path,"tout_log_field");
64 
65     // remove old images before rendering
66     remove_test_image(output_file);
67 
68 
69     //
70     // Create the actions.
71     //
72 
73     conduit::Node pipelines;
74     // pipeline 1
75     pipelines["pl1/f1/type"] = "vector_magnitude";
76     conduit::Node &params = pipelines["pl1/f1/params"];
77     params["field"] = "vel";         // name of the vector field
78     params["output_name"] = "mag";   // name of the output field
79 
80     pipelines["pl1/f2/type"] = "log";
81     conduit::Node &params2 = pipelines["pl1/f2/params"];
82     params2["field"] = "mag";             // name of the input field
83     params2["output_name"] = "log_mag";   // name of the output field
84 
85     conduit::Node scenes;
86     scenes["s1/plots/p1/type"]         = "pseudocolor";
87     scenes["s1/plots/p1/field"] = "log_mag";
88     scenes["s1/plots/p1/pipeline"] = "pl1";
89 
90     scenes["s1/image_prefix"] = output_file;
91 
92     conduit::Node actions;
93     // add the pipeline
94     conduit::Node &add_pipelines = actions.append();
95     add_pipelines["action"] = "add_pipelines";
96     add_pipelines["pipelines"] = pipelines;
97     // add the scenes
98     conduit::Node &add_scenes= actions.append();
99     add_scenes["action"] = "add_scenes";
100     add_scenes["scenes"] = scenes;
101 
102     //
103     // Run Ascent
104     //
105 
106     Ascent ascent;
107 
108     Node ascent_opts;
109     ascent_opts["runtime/type"] = "ascent";
110     ascent.open(ascent_opts);
111     ascent.publish(data);
112     ascent.execute(actions);
113     ascent.close();
114 
115     // check that we created an image
116     EXPECT_TRUE(check_test_image(output_file));
117     std::string msg = "An example of using the log filter.";
118     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
119 }
120 //-----------------------------------------------------------------------------
TEST(ascent_log,test_log_clamp)121 TEST(ascent_log, test_log_clamp)
122 {
123     Node n;
124     ascent::about(n);
125     // only run this test if ascent was built with vtkm support
126     if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
127     {
128         ASCENT_INFO("Ascent vtkm support disabled, skipping test");
129         return;
130     }
131 
132     //
133     // Create an example mesh.
134     //
135     Node data, verify_info;
136     conduit::blueprint::mesh::examples::braid("hexs",
137                                               EXAMPLE_MESH_SIDE_DIM,
138                                               EXAMPLE_MESH_SIDE_DIM,
139                                               EXAMPLE_MESH_SIDE_DIM,
140                                               data);
141     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
142 
143     ASCENT_INFO("Testing log clamp of field");
144 
145 
146     string output_path = prepare_output_dir();
147     string output_file = conduit::utils::join_file_path(output_path,"tout_log_field_clamp");
148 
149     // remove old images before rendering
150     remove_test_image(output_file);
151 
152 
153     //
154     // Create the actions.
155     //
156 
157     conduit::Node pipelines;
158     // pipeline 1
159     pipelines["pl1/f1/type"] = "vector_magnitude";
160     conduit::Node &params = pipelines["pl1/f1/params"];
161     params["field"] = "vel";         // name of the vector field
162     params["output_name"] = "mag";   // name of the output field
163 
164     pipelines["pl1/f2/type"] = "log";
165     conduit::Node &params2 = pipelines["pl1/f2/params"];
166     params2["field"] = "mag";             // name of the input field
167     params2["output_name"] = "log_mag";   // name of the output field
168     params2["clamp_min_value"] = 2.f;
169 
170     conduit::Node scenes;
171     scenes["s1/plots/p1/type"]         = "pseudocolor";
172     scenes["s1/plots/p1/field"] = "log_mag";
173     scenes["s1/plots/p1/pipeline"] = "pl1";
174 
175     scenes["s1/image_prefix"] = output_file;
176 
177     conduit::Node actions;
178     // add the pipeline
179     conduit::Node &add_pipelines = actions.append();
180     add_pipelines["action"] = "add_pipelines";
181     add_pipelines["pipelines"] = pipelines;
182     // add the scenes
183     conduit::Node &add_scenes= actions.append();
184     add_scenes["action"] = "add_scenes";
185     add_scenes["scenes"] = scenes;
186 
187     //
188     // Run Ascent
189     //
190 
191     Ascent ascent;
192 
193     Node ascent_opts;
194     ascent_opts["runtime/type"] = "ascent";
195     ascent.open(ascent_opts);
196     ascent.publish(data);
197     ascent.execute(actions);
198     ascent.close();
199 
200     // check that we created an image
201     EXPECT_TRUE(check_test_image(output_file));
202     std::string msg = "An example of using the log filter and clamping the min value."
203                       " This can help when there are negative values present.";
204     ASCENT_ACTIONS_DUMP(actions,output_file,msg);
205 }
206 //-----------------------------------------------------------------------------
main(int argc,char * argv[])207 int main(int argc, char* argv[])
208 {
209     int result = 0;
210 
211     ::testing::InitGoogleTest(&argc, argv);
212 
213     // allow override of the data size via the command line
214     if(argc == 2)
215     {
216         EXAMPLE_MESH_SIDE_DIM = atoi(argv[1]);
217     }
218 
219     result = RUN_ALL_TESTS();
220     return result;
221 }
222 
223 
224