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_recenter.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_recenter,test_recenter_to_element)37 TEST(ascent_recenter, test_recenter_to_element)
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 recenter of field");
60
61
62 string output_path = prepare_output_dir();
63 string output_file = conduit::utils::join_file_path(output_path,"tout_recenter_element");
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"] = "recenter";
76 conduit::Node ¶ms = pipelines["pl1/f1/params"];
77 params["field"] = "radial"; // name of the input field
78 params["association"] = "vertex"; // new field association
79
80 conduit::Node scenes;
81 scenes["s1/plots/p1/type"] = "pseudocolor";
82 scenes["s1/plots/p1/field"] = "radial";
83 scenes["s1/plots/p1/pipeline"] = "pl1";
84
85 scenes["s1/image_prefix"] = output_file;
86
87 conduit::Node actions;
88 // add the pipeline
89 conduit::Node &add_pipelines = actions.append();
90 add_pipelines["action"] = "add_pipelines";
91 add_pipelines["pipelines"] = pipelines;
92 // add the scenes
93 conduit::Node &add_scenes= actions.append();
94 add_scenes["action"] = "add_scenes";
95 add_scenes["scenes"] = scenes;
96
97 //
98 // Run Ascent
99 //
100
101 Ascent ascent;
102
103 Node ascent_opts;
104 ascent_opts["runtime/type"] = "ascent";
105 ascent.open(ascent_opts);
106 ascent.publish(data);
107 ascent.execute(actions);
108 ascent.close();
109
110 // check that we created an image
111 EXPECT_TRUE(check_test_image(output_file));
112 std::string msg = "An example if using the re-center filter (to vertex).";
113 ASCENT_ACTIONS_DUMP(actions,output_file,msg);
114 }
115 //-----------------------------------------------------------------------------
TEST(ascent_recenter,test_recenter_to_vertex)116 TEST(ascent_recenter, test_recenter_to_vertex)
117 {
118 Node n;
119 ascent::about(n);
120 // only run this test if ascent was built with vtkm support
121 if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
122 {
123 ASCENT_INFO("Ascent vtkm support disabled, skipping test");
124 return;
125 }
126
127 //
128 // Create an example mesh.
129 //
130 Node data, verify_info;
131 conduit::blueprint::mesh::examples::braid("hexs",
132 EXAMPLE_MESH_SIDE_DIM,
133 EXAMPLE_MESH_SIDE_DIM,
134 EXAMPLE_MESH_SIDE_DIM,
135 data);
136 EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
137
138 ASCENT_INFO("Testing recenter of field");
139
140
141 string output_path = prepare_output_dir();
142 string output_file = conduit::utils::join_file_path(output_path,"tout_recenter_vertex");
143
144 // remove old images before rendering
145 remove_test_image(output_file);
146
147
148 //
149 // Create the actions.
150 //
151
152 conduit::Node pipelines;
153 // pipeline 1
154 pipelines["pl1/f1/type"] = "recenter";
155 conduit::Node ¶ms = pipelines["pl1/f1/params"];
156 params["field"] = "braid"; // name of the input field
157 params["association"] = "element"; // new field association
158
159 conduit::Node scenes;
160 scenes["s1/plots/p1/type"] = "pseudocolor";
161 scenes["s1/plots/p1/field"] = "braid";
162 scenes["s1/plots/p1/pipeline"] = "pl1";
163
164 scenes["s1/image_prefix"] = output_file;
165
166 conduit::Node actions;
167 // add the pipeline
168 conduit::Node &add_pipelines = actions.append();
169 add_pipelines["action"] = "add_pipelines";
170 add_pipelines["pipelines"] = pipelines;
171 // add the scenes
172 conduit::Node &add_scenes= actions.append();
173 add_scenes["action"] = "add_scenes";
174 add_scenes["scenes"] = scenes;
175
176 //
177 // Run Ascent
178 //
179
180 Ascent ascent;
181
182 Node ascent_opts;
183 ascent_opts["runtime/type"] = "ascent";
184 ascent.open(ascent_opts);
185 ascent.publish(data);
186 ascent.execute(actions);
187 ascent.close();
188
189 // check that we created an image
190 EXPECT_TRUE(check_test_image(output_file));
191 std::string msg = "An example if using the re-center filter (to element).";
192 ASCENT_ACTIONS_DUMP(actions,output_file,msg);
193 }
194 //-----------------------------------------------------------------------------
main(int argc,char * argv[])195 int main(int argc, char* argv[])
196 {
197 int result = 0;
198
199 ::testing::InitGoogleTest(&argc, argv);
200
201 // allow override of the data size via the command line
202 if(argc == 2)
203 {
204 EXAMPLE_MESH_SIDE_DIM = atoi(argv[1]);
205 }
206
207 result = RUN_ALL_TESTS();
208 return result;
209 }
210
211
212