@@ -74,6 +74,34 @@ InterfaceWithCleaverAlgorithm::InterfaceWithCleaverAlgorithm()
7474 addParameter (VolumeScalingZ,1.0 );
7575}
7676
77+ boost::shared_ptr<Cleaver::ScalarField> InterfaceWithCleaverAlgorithm::makeCleaverFieldFromLatVol (FieldHandle field)
78+ {
79+ // TODO: this function assumes input is completely valid, may want to move various checks from run() function here.
80+
81+ VMesh* vmesh = field->vmesh ();
82+ VField* vfield = field->vfield ();
83+ VMesh::dimension_type dims;
84+ vmesh->get_dimensions ( dims );
85+ float * ptr = static_cast <float *>(vfield->fdata_pointer ());
86+ auto cleaverField = boost::make_shared<Cleaver::FloatField>(dims[0 ], dims[1 ], dims[2 ], ptr);
87+
88+ // 0 = constant, 1 = linear
89+ if (0 == vfield->basis_order ())
90+ cleaverField->setCenter (Cleaver::FloatField::CellCentered);
91+ else if (1 == vfield->basis_order ())
92+ cleaverField->setCenter (Cleaver::FloatField::NodeCentered);
93+ // else: TODO? handle other bases, probably by throwing exception.
94+
95+ // TODO: Cleaver FloatField needs more setup (constructor is not sufficient)
96+ // 1.
97+ // setBounds(BoundingBox). Convert vmesh->get_bounding_box() to Cleaver BoundingBox.
98+ // 2.
99+ // setScale(vec3). Need to figure out which vmesh function to call, and convert to Cleaver::vec3.
100+ // 3. unit test heavily.
101+
102+ return cleaverField;
103+ }
104+
77105FieldHandle InterfaceWithCleaverAlgorithm::run (const std::vector<FieldHandle>& input) const
78106{
79107 FieldHandle output;
@@ -96,15 +124,16 @@ FieldHandle InterfaceWithCleaverAlgorithm::run(const std::vector<FieldHandle>& i
96124 VMesh::dimension_type dims; int x=0 ,y=0 ,z=0 ;
97125 for (size_t p=1 ; p<inputs.size (); p++)
98126 {
99- VMesh* imesh1 = inputs[p]->vmesh ();
127+ FieldHandle input = inputs[p];
128+ VMesh* imesh1 = input->vmesh ();
100129
101130 if ( !imesh1->is_structuredmesh () )
102131 {
103132 THROW_ALGORITHM_INPUT_ERROR (" needs to be structured mesh!" );
104133 }
105134 else
106135 {
107- VField* vfield1 = inputs[p] ->vfield ();
136+ VField* vfield1 = input ->vfield ();
108137 if (!vfield1->is_scalar ())
109138 {
110139 THROW_ALGORITHM_INPUT_ERROR (" values at the node needs to be scalar!" );
@@ -139,7 +168,7 @@ FieldHandle InterfaceWithCleaverAlgorithm::run(const std::vector<FieldHandle>& i
139168 float * ptr = static_cast <float *>(vfield1->fdata_pointer ());
140169 if (ptr)
141170 {
142- fields.push_back (boost::make_shared<Cleaver::FloatField>(dims[ 0 ], dims[ 1 ], dims[ 2 ], ptr ));
171+ fields.push_back (makeCleaverFieldFromLatVol (input ));
143172 }
144173 else
145174 {
0 commit comments