void Octorok::update(float deltaTime) { _time -= deltaTime; if (_time < 0) { _time += 2; directions dirAux = directions(pointsToDirection4(getPosition(),_scene->getPlayer()->getPosition())); if (dirAux == _dir && _blocked) dirAux = directions(rand()%4); _dir = dirAux; } if (std::rand()%(FRAMERATE*3) == 0) shot(); _moving = true; Enemy::update(deltaTime); _blocked = false; }
std::string Environment::description() const { std::stringstream ss; std::vector<Direction> dirs = directions(); ss << "Möjliga vägar att välja mellan: "; // TODO: detta skriver ut ett tal (0,1,2,3) och inte motsvarande enumvärde. for (int i = 0; i < dirs.size() - 1; ++i) ss << dirs[i] << ", "; ss << dirs[dirs.size() - 1] << '\n'; if (objects.size() > 0) { ss << "Det ligger lite prylar på marken: "; for (int i = 0; i < objects.size() - 1; ++i) ss << objects[i]->type() << ", "; ss << objects[objects.size() - 1]->type() << '\n'; } if (actors.size() > 1) { ss << "Du ser minst en annan levande varelse: "; auto it = actors.begin(); if (dynamic_cast<Player*>(it->second) != nullptr) ++it; ss << it->second; for (++it; it != actors.end(); ++it) if (dynamic_cast<Player*>(it->second) == nullptr) ss << ", " << it->second; ss << std::endl; } return ss.str(); }
dcomplex PatchSideDataNormOpsComplex::integral( const boost::shared_ptr<pdat::SideData<dcomplex> >& data, const hier::Box& box, const boost::shared_ptr<pdat::SideData<double> >& vol) const { TBOX_ASSERT(data); int dimVal = box.getDim().getValue(); dcomplex retval = dcomplex(0.0, 0.0); const hier::IntVector& directions = data->getDirectionVector(); TBOX_ASSERT(directions == hier::IntVector::min(directions, vol->getDirectionVector())); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { retval += d_array_ops.integral( data->getArrayData(d), vol->getArrayData(d), pdat::SideGeometry::toSideBox(box, d)); } } return retval; }
void setVTKFilter(medAbstractData* d,typename itk::SphericalHarmonicITKToVTKFilter<SH_IMAGE>::Pointer& filter) { SH_IMAGE* dataset = static_cast<SH_IMAGE*>(d->data()); if (filter) filter->Delete(); filter = itk::SphericalHarmonicITKToVTKFilter<SH_IMAGE>::New(); filter->SetInput(dataset); filter->UpdateOutputInformation(); // This line generates the vtkSHs, otherwise is not generated, even if the next filter // in the pipeline is connected and Update() is called filter->Update(); itk::ImageBase<3>::DirectionType directions = dataset->GetDirection(); itk::ImageBase<3>::PointType origin = dataset->GetOrigin(); orientationMatrix = vtkMatrix4x4::New(); orientationMatrix->Identity(); for (int i=0; i<3; i++) for (int j=0; j<3; j++) orientationMatrix->SetElement (i, j, directions (i,j)); double v_origin[4], v_origin2[4]; for (int i=0; i<3; i++) v_origin[i] = origin[i]; v_origin[3] = 1.0; orientationMatrix->MultiplyPoint (v_origin, v_origin2); for (int i=0; i<3; i++) orientationMatrix->SetElement (i, 3, v_origin[i]-v_origin2[i]); double v_spacing[3]; for (int i=0; i<3; i++) v_spacing[i] = dataset->GetSpacing()[i]; // We need to call this function because GetOutput() just returns the input manager->SetInput(filter->GetVTKSphericalHarmonic()); manager->SetDirectionMatrix(filter->GetDirectionMatrix()); manager->ResetPosition(); const int number = dataset->GetNumberOfComponentsPerPixel(); const int Order = -1.5+std::sqrt((float)(0.25+2*number)); manager->SetOrder(Order); manager->Update(); data = d; if (view) { int dim[3]; manager->GetSphericalHarmonicDimensions(dim); view2d->SetInput(manager->GetSHVisuManagerAxial()->GetActor(), view->layer(data), orientationMatrix, dim, v_spacing, v_origin); view2d->SetInput(manager->GetSHVisuManagerSagittal()->GetActor(), view->layer(data), orientationMatrix, dim, v_spacing, v_origin); view2d->SetInput(manager->GetSHVisuManagerCoronal()->GetActor(), view->layer(data), orientationMatrix, dim, v_spacing, v_origin); } }
double PatchSideDataNormOpsReal<TYPE>::sumControlVolumes( const boost::shared_ptr<pdat::SideData<TYPE> >& data, const boost::shared_ptr<pdat::SideData<double> >& cvol, const hier::Box& box) const { TBOX_ASSERT(data && cvol); double retval = 0.0; const hier::IntVector& directions = data->getDirectionVector(); TBOX_ASSERT(directions == hier::IntVector::min(directions, cvol->getDirectionVector())); tbox::Dimension::dir_t dimVal = data->getDim().getValue(); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); retval += d_array_ops.sumControlVolumes(data->getArrayData(d), cvol->getArrayData(d), side_box); } } return retval; }
TYPE PatchSideDataNormOpsReal<TYPE>::integral( const boost::shared_ptr<pdat::SideData<TYPE> >& data, const hier::Box& box, const boost::shared_ptr<pdat::SideData<double> >& vol) const { TBOX_ASSERT(data); TBOX_ASSERT(vol); TBOX_ASSERT_OBJDIM_EQUALITY3(*data, box, *vol); tbox::Dimension::dir_t dimVal = data->getDim().getValue(); TYPE retval = 0.0; const hier::IntVector& directions = data->getDirectionVector(); TBOX_ASSERT(directions == hier::IntVector::min(directions, vol->getDirectionVector())); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); retval += d_array_ops.integral( data->getArrayData(d), vol->getArrayData(d), side_box); } } return retval; }
double PatchSideDataNormOpsComplex::weightedL2Norm( const boost::shared_ptr<pdat::SideData<dcomplex> >& data, const boost::shared_ptr<pdat::SideData<dcomplex> >& weight, const hier::Box& box, const boost::shared_ptr<pdat::SideData<double> >& cvol) const { TBOX_ASSERT(data && weight); TBOX_ASSERT_OBJDIM_EQUALITY3(*data, *weight, box); int dimVal = box.getDim().getValue(); double retval = 0.0; const hier::IntVector& directions = data->getDirectionVector(); TBOX_ASSERT(directions == hier::IntVector::min(directions, weight->getDirectionVector())); if (!cvol) { for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); double aval = d_array_ops.weightedL2Norm(data->getArrayData(d), weight->getArrayData(d), side_box); retval += aval * aval; } } } else { TBOX_ASSERT(directions == hier::IntVector::min(directions, cvol->getDirectionVector())); TBOX_ASSERT_OBJDIM_EQUALITY2(*data, *cvol); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); double aval = d_array_ops.weightedL2NormWithControlVolume( data->getArrayData(d), weight->getArrayData(d), cvol->getArrayData(d), side_box); retval += aval * aval; } } } return sqrt(retval); }
void MagneticFieldInteraction::calculateEnergy(const Cell &cell, double &energy) { r = cell.getPosition(sl_r); double S = cell[r].getMoment(); const Matrix3 &inv = cell[r].getInverseMatrix(); size_t numberOfAtoms = cell[r].size(); double temp{0.0}; for (int i = 0; i < 3; i++) { if (std::abs(directions(i)) > 1.0e-10) { temp -= directions(i) * inv(i, 2); } } energy += value * S * numberOfAtoms * temp; }
ostream &Basis::output(ostream &os, int level) const { os << indent(level) << "Basis " << quote(name()) << ": Configuration " << quote(configuration()->name()) << " TangentSpace " << quote(tangentspace()->name()) << "\n"; for (const auto &db : directions()) db.second->output(os, level + 1); return os; }
/** * @brief Create the PeakShape * @param source : source JSON * @return PeakShape via this factory or it's successors */ Mantid::Geometry::PeakShape * PeakShapeEllipsoidFactory::create(const std::string &source) const { Json::Reader reader; Json::Value root; Mantid::Geometry::PeakShape *product = nullptr; if (reader.parse(source, root)) { const std::string shape = root["shape"].asString(); if (shape == PeakShapeEllipsoid::ellipsoidShapeName()) { const std::string algorithmName(root["algorithm_name"].asString()); const int algorithmVersion(root["algorithm_version"].asInt()); const SpecialCoordinateSystem frame( static_cast<SpecialCoordinateSystem>(root["frame"].asInt())); std::vector<double> abcRadii, abcRadiiBackgroundInner, abcRadiiBackgroundOuter; abcRadii.push_back(root["radius0"].asDouble()); abcRadii.push_back(root["radius1"].asDouble()); abcRadii.push_back(root["radius2"].asDouble()); abcRadiiBackgroundInner.push_back( root["background_inner_radius0"].asDouble()); abcRadiiBackgroundInner.push_back( root["background_inner_radius1"].asDouble()); abcRadiiBackgroundInner.push_back( root["background_inner_radius2"].asDouble()); abcRadiiBackgroundOuter.push_back( root["background_outer_radius0"].asDouble()); abcRadiiBackgroundOuter.push_back( root["background_outer_radius1"].asDouble()); abcRadiiBackgroundOuter.push_back( root["background_outer_radius2"].asDouble()); std::vector<V3D> directions(3); directions[0].fromString(root["direction0"].asString()); directions[1].fromString(root["direction1"].asString()); directions[2].fromString(root["direction2"].asString()); product = new PeakShapeEllipsoid( directions, abcRadii, abcRadiiBackgroundInner, abcRadiiBackgroundOuter, frame, algorithmName, algorithmVersion); } else { if (m_successor) { product = m_successor->create(source); } else { throw std::invalid_argument("PeakShapeSphericalFactory:: No successor " "factory able to process : " + source); } } } else { throw std::invalid_argument("PeakShapeSphericalFactory:: Source JSON for " "the peak shape is not valid: " + source); } return product; }
InputParameters validParams<CoupledDirectionalMeshHeightInterpolation>() { InputParameters params = validParams<AuxKernel>(); params.addRequiredCoupledVar("coupled_var", "The variable whose values are going to be interpolated."); MooseEnum directions("x y z"); params.addRequiredParam<MooseEnum>("direction", directions, "The direction to interpolate in."); return params; }
TYPE PatchSideDataNormOpsReal<TYPE>::dot( const boost::shared_ptr<pdat::SideData<TYPE> >& data1, const boost::shared_ptr<pdat::SideData<TYPE> >& data2, const hier::Box& box, const boost::shared_ptr<pdat::SideData<double> >& cvol) const { TBOX_ASSERT(data1 && data2); TBOX_ASSERT(data1->getDirectionVector() == data2->getDirectionVector()); tbox::Dimension::dir_t dimVal = data1->getDim().getValue(); TYPE retval = 0.0; const hier::IntVector& directions = data1->getDirectionVector(); if (!cvol) { for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); retval += d_array_ops.dot(data1->getArrayData(d), data2->getArrayData(d), side_box); } } } else { TBOX_ASSERT_OBJDIM_EQUALITY2(*data1, *cvol); TBOX_ASSERT(directions == hier::IntVector::min(directions, cvol->getDirectionVector())); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); retval += d_array_ops.dotWithControlVolume( data1->getArrayData(d), data2->getArrayData(d), cvol->getArrayData(d), side_box); } } } return retval; }
double PatchSideDataNormOpsReal<TYPE>::maxNorm( const boost::shared_ptr<pdat::SideData<TYPE> >& data, const hier::Box& box, const boost::shared_ptr<pdat::SideData<double> >& cvol) const { TBOX_ASSERT(data); TBOX_ASSERT_OBJDIM_EQUALITY2(*data, box); tbox::Dimension::dir_t dimVal = data->getDim().getValue(); double retval = 0.0; const hier::IntVector& directions = data->getDirectionVector(); if (!cvol) { for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); retval = tbox::MathUtilities<double>::Max(retval, d_array_ops.maxNorm(data->getArrayData(d), side_box)); } } } else { TBOX_ASSERT_OBJDIM_EQUALITY2(*data, *cvol); TBOX_ASSERT(directions == hier::IntVector::min(directions, cvol->getDirectionVector())); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); retval = tbox::MathUtilities<double>::Max(retval, d_array_ops.maxNormWithControlVolume( data->getArrayData(d), cvol->getArrayData(d), side_box)); } } } return retval; }
void MagneticFieldInteraction::calcConstantValues(const Cell &cell) { complex<double> XI(0.0, 1.0); // find location of r r = cell.getPosition(sl_r); M = cell.size(); const Matrix3 &inv = cell[r].getInverseMatrix(); LNrr = complex<double>(0.0, 0.0); for (int i = 0; i < 3; i++) { // cout << i << " " << j << " " << directions(i,j) << endl; if (abs(directions(i)) > 1.0e-10) { LNrr += 0.5 * value * directions(i) * inv(i, 2); } } // cout << LNrr << endl; }
void MagneticFieldInteraction::calculateFirstOrderTerms(const Cell &cell, Eigen::VectorXcd &elements) { complex<double> XI(0.0, 1.0); r = cell.getPosition(sl_r); M = cell.size(); double S = cell[r].getMoment(); const Matrix3 &inv = cell[r].getInverseMatrix(); for (int i = 0; i < 3; i++) { // cout << i << " " << j << " " << directions(i,j) << endl; if (abs(directions(i)) > 1.0e-10) { double X = value * directions(i) * sqrt(S / 2.0); complex<double> nu = inv(i, 0) + XI * inv(i, 1); // cout << "nu= " << nu << endl; elements(r) -= X * conj(nu); elements(r + M) -= X * nu; } } }
InputParameters validParams<LayeredBase>() { InputParameters params = emptyInputParameters(); MooseEnum directions("x, y, z"); params.addRequiredParam<MooseEnum>("direction", directions, "The direction of the layers."); params.addRequiredParam<unsigned int>("num_layers", "The number of layers."); MooseEnum sample_options("direct, interpolate, average", "direct"); params.addParam<MooseEnum>("sample_type", sample_options, "How to sample the layers. 'direct' means get the value of the layer the point falls in directly (or average if that layer has no value). 'interpolate' does a linear interpolation between the two closest layers. 'average' averages the two closest layers."); params.addParam<unsigned int>("average_radius", 1, "When using 'average' sampling this is how the number of values both above and below the layer that will be averaged."); return params; }
//Moves the motor a certain amount of steps with a certain amount of microseconds in between each step. // 200 microseconds at a maximum speed otherwise the stepper motor doesn't have enough time to step void Actuator::steps(int steps, int micro, bool state){ //decide direction directions(state); for(int i = 0 ; i <= steps ; i++){ one_step(micro); //if debug is enables this will print out how many steps the motor has taken. if(state == BACKWARD){ count++; } else{ if(state == FORWARD){ count--; } } } }
Octorok::Octorok(ScenePlayable* scene, Map* map, sf::Vector2f pos) : Enemy(scene, map,pos) { _sprite.setTexture(Resources::overEnemies); _description = Resources::descriptions[octorokDescriptions]; _dir = directions(std::rand()%4); _action = linkActions::move; _elapsedWalking = 0.5; _speed = sf::Vector2f(7,7); _walkBounds = sf::IntRect(2,2,12,12); _bounds = _walkBounds; _time = 0; _damage = 0.5; _sprite.setTextureRect(_description[_action*4+_dir][_currentAnimation%_description[_action*4+_dir].size()]); }
InputParameters validParams<LayeredBase>() { InputParameters params = emptyInputParameters(); MooseEnum directions("x y z"); params.addRequiredParam<MooseEnum>("direction", directions, "The direction of the layers."); params.addParam<unsigned int>("num_layers", "The number of layers."); params.addParam<std::vector<Real> >("bounds", "The 'bounding' positions of the layers i.e.: '0, 1.2, 3.7, 4.2' will mean 3 layers between those positions."); MooseEnum sample_options("direct interpolate average", "direct"); params.addParam<MooseEnum>("sample_type", sample_options, "How to sample the layers. 'direct' means get the value of the layer the point falls in directly (or average if that layer has no value). 'interpolate' does a linear interpolation between the two closest layers. 'average' averages the two closest layers."); params.addParam<unsigned int>("average_radius", 1, "When using 'average' sampling this is how the number of values both above and below the layer that will be averaged."); params.addParam<bool>("cumulative", false, "When true the value in each layer is the sum of the values up to and including that layer"); return params; }
void PatchSideDataOpsComplex::copyData( const std::shared_ptr<pdat::SideData<dcomplex> >& dst, const std::shared_ptr<pdat::SideData<dcomplex> >& src, const hier::Box& box) const { TBOX_ASSERT(dst && src); TBOX_ASSERT(dst->getDirectionVector() == src->getDirectionVector()); TBOX_ASSERT_OBJDIM_EQUALITY3(*dst, *src, box); int dimVal = box.getDim().getValue(); const hier::IntVector& directions = dst->getDirectionVector(); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { dst->getArrayData(d).copy(src->getArrayData(d), pdat::SideGeometry::toSideBox(box, d)); } } }
int PatchSideDataNormOpsComplex::numberOfEntries( const boost::shared_ptr<pdat::SideData<dcomplex> >& data, const hier::Box& box) const { TBOX_ASSERT(data); TBOX_ASSERT_OBJDIM_EQUALITY2(*data, box); int dimVal = box.getDim().getValue(); int retval = 0; const hier::Box ibox = box * data->getGhostBox(); const hier::IntVector& directions = data->getDirectionVector(); const int data_depth = data->getDepth(); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { retval += static_cast<int>((pdat::SideGeometry::toSideBox(ibox, d).size()) * data_depth); } } return retval; }
size_t PatchSideDataNormOpsReal<TYPE>::numberOfEntries( const boost::shared_ptr<pdat::SideData<TYPE> >& data, const hier::Box& box) const { TBOX_ASSERT(data); TBOX_ASSERT_OBJDIM_EQUALITY2(*data, box); tbox::Dimension::dir_t dimVal = box.getDim().getValue(); size_t retval = 0; const hier::Box ibox = box * data->getGhostBox(); const hier::IntVector& directions = data->getDirectionVector(); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box dbox = pdat::SideGeometry::toSideBox(ibox, d); retval += (dbox.size() * data->getDepth()); } } return retval; }
main() { void directions(void); FILE *InitFile(const string_t); void FileToArray(el_t item[], int *NumEls_ptr, FILE *infile_ptr); void GroceryList(el_t item[], int NumEls); el_t item[MAX_NUM_ELS]; /* array of structures */ /* of names and prices */ int NumEls; /* number of elements in array item */ FILE *infile_ptr; /* pointer to input file */ directions(); printf("Give the name of the input file: "); infile_ptr = InitFile("r"); FileToArray(item, &NumEls, infile_ptr); fclose(infile_ptr); GroceryList(item, NumEls); }
void PatchSideDataNormOpsReal<TYPE>::abs( const boost::shared_ptr<pdat::SideData<TYPE> >& dst, const boost::shared_ptr<pdat::SideData<TYPE> >& src, const hier::Box& box) const { TBOX_ASSERT(dst && src); TBOX_ASSERT(dst->getDirectionVector() == src->getDirectionVector()); TBOX_ASSERT_OBJDIM_EQUALITY3(*dst, *src, box); tbox::Dimension::dir_t dimVal = dst->getDim().getValue(); const hier::IntVector& directions = dst->getDirectionVector(); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box side_box = pdat::SideGeometry::toSideBox(box, d); d_array_ops.abs(dst->getArrayData(d), src->getArrayData(d), side_box); } } }
int main() { //intializing different variables accordingly char input[3],dir; int flag,data=0; //scan data fo root printf("enter the data to the root"); root=(node*)malloc(sizeof(node)); scanf("%d",&root->data); root->right=NULL; root->left=NULL; //asking for new node to added or not printf("\nDo you want to enter new node(yes/no):"); scanf("%s",input); //chacking the input if yes than return 1 and enters into while loop flag=string_test(input); while(flag==1) { //asking to direction to traverse tree from root for adding new node printf("\nStartinf from root enter direction(l/r)?"); dir=getche(); //calling direction function directions(root,dir); printf("\nDo you want to enter new node(yes/no):"); scanf("%s",input); //calling string_test fuction to check whether the input is yes or no flag=string_test(input); } //printing the tree print_inorder(root); return 0; flag=check_balance(root); if(flag) printf("\nBinary Tree is height balanced"); else printf("\nBinary Tree is not height balanced"); }
void Cone_spanners_ipelet::protected_run(int fn) { std::vector<Point_2> lst; int number_of_cones; switch (fn){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: { std::vector<Point_2> points_read; read_active_objects( CGAL::dispatch_or_drop_output<Point_2>(std::back_inserter(points_read)) ); if (points_read.empty()) { print_error_message("No mark selected"); return; } for(std::vector<Point_2>::iterator it = points_read.begin(); it != points_read.end(); it++) { if(std::find(points_read.begin(), it, *it) == it) { lst.push_back(*it); } } int ret_val; boost::tie(ret_val,number_of_cones)=request_value_from_user<int>("Enter the number of cones"); if (ret_val < 0) { print_error_message("Incorrect value"); return; } if(number_of_cones < 2) { print_error_message("The number of cones must be larger than 1!"); return; } break; } case 7: show_help(); return; } if(fn >= 0 && fn <= 5) { CGAL::Cones_selected cones_selected = CGAL::ALL_CONES; if(fn == 2 || fn == 3) cones_selected = CGAL::EVEN_CONES; else if(fn == 4 || fn == 5) cones_selected = CGAL::ODD_CONES; Graph g; switch (fn){ case 0: case 2: case 4: { CGAL::Construct_theta_graph_2<Kernel, Graph> theta(number_of_cones, Direction_2(1,0), cones_selected); theta(lst.begin(), lst.end(), g); break; } case 1: case 3: case 5: { CGAL::Construct_yao_graph_2<Kernel, Graph> yao(number_of_cones, Direction_2(1,0), cones_selected); yao(lst.begin(), lst.end(), g); break; } } boost::graph_traits<Graph>::edge_iterator ei, ei_end; for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) { boost::graph_traits<Graph>::edge_descriptor e = *ei; boost::graph_traits<Graph>::vertex_descriptor u = source(e, g); boost::graph_traits<Graph>::vertex_descriptor v = target(e, g); draw_in_ipe(Segment_2(g[u], g[v])); } group_selected_objects_(); } else if(fn == 6) { CGAL::Compute_cone_boundaries_2<Kernel> cones; std::vector<Direction_2> directions(number_of_cones); cones(number_of_cones, Direction_2(1,0), directions.begin()); for(std::vector<Point_2>::iterator it = lst.begin(); it != lst.end(); it++) { for(std::vector<Direction_2>::iterator dir = directions.begin(); dir != directions.end(); dir++) { draw_in_ipe(Segment_2(*it,*it + 100*dir->to_vector())); } group_selected_objects_(); get_IpePage()->deselectAll(); } } }
void CartesianSideFloatWeightedAverage::coarsen( hier::Patch& coarse, const hier::Patch& fine, const int dst_component, const int src_component, const hier::Box& coarse_box, const hier::IntVector& ratio) const { const tbox::Dimension& dim(fine.getDim()); TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, coarse_box, ratio); std::shared_ptr<pdat::SideData<float> > fdata( SAMRAI_SHARED_PTR_CAST<pdat::SideData<float>, hier::PatchData>( fine.getPatchData(src_component))); std::shared_ptr<pdat::SideData<float> > cdata( SAMRAI_SHARED_PTR_CAST<pdat::SideData<float>, hier::PatchData>( coarse.getPatchData(dst_component))); TBOX_ASSERT(fdata); TBOX_ASSERT(cdata); TBOX_ASSERT(cdata->getDepth() == fdata->getDepth()); const hier::IntVector& directions = cdata->getDirectionVector(); TBOX_ASSERT(directions == hier::IntVector::min(directions, fdata->getDirectionVector())); const hier::Index& filo = fdata->getGhostBox().lower(); const hier::Index& fihi = fdata->getGhostBox().upper(); const hier::Index& cilo = cdata->getGhostBox().lower(); const hier::Index& cihi = cdata->getGhostBox().upper(); const std::shared_ptr<CartesianPatchGeometry> fgeom( SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>( fine.getPatchGeometry())); const std::shared_ptr<CartesianPatchGeometry> cgeom( SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>( coarse.getPatchGeometry())); TBOX_ASSERT(fgeom); TBOX_ASSERT(cgeom); const hier::Index& ifirstc = coarse_box.lower(); const hier::Index& ilastc = coarse_box.upper(); for (int d = 0; d < cdata->getDepth(); ++d) { if ((dim == tbox::Dimension(1))) { if (directions(0)) { SAMRAI_F77_FUNC(cartwgtavgsideflot1d, CARTWGTAVGSIDEFLOT1D) (ifirstc(0), ilastc(0), filo(0), fihi(0), cilo(0), cihi(0), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); } } else if ((dim == tbox::Dimension(2))) { if (directions(0)) { SAMRAI_F77_FUNC(cartwgtavgsideflot2d0, CARTWGTAVGSIDEFLOT2D0) (ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), filo(0), filo(1), fihi(0), fihi(1), cilo(0), cilo(1), cihi(0), cihi(1), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); } if (directions(1)) { SAMRAI_F77_FUNC(cartwgtavgsideflot2d1, CARTWGTAVGSIDEFLOT2D1) (ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), filo(0), filo(1), fihi(0), fihi(1), cilo(0), cilo(1), cihi(0), cihi(1), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(1, d), cdata->getPointer(1, d)); } } else if ((dim == tbox::Dimension(3))) { if (directions(0)) { SAMRAI_F77_FUNC(cartwgtavgsideflot3d0, CARTWGTAVGSIDEFLOT3D0) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); } if (directions(1)) { SAMRAI_F77_FUNC(cartwgtavgsideflot3d1, CARTWGTAVGSIDEFLOT3D1) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(1, d), cdata->getPointer(1, d)); } if (directions(2)) { SAMRAI_F77_FUNC(cartwgtavgsideflot3d2, CARTWGTAVGSIDEFLOT3D2) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(2, d), cdata->getPointer(2, d)); } } else { TBOX_ERROR("CartesianSideFloatWeightedAverage error...\n" << "dim > 3 not supported." << std::endl); } } }
//direction adds a new node to the tree dependingon the direction provided by the user void directions(node *temp,char dir) { //switch case for left and right movement switch(dir) { //if l is pressed it meanes we move to left of the parent node case 'l': //if left of the parent node is null then new node is added if(temp->left==NULL) { //initialization node *new_node=NULL; //allocating memory to the new node new_node=(node*)malloc(sizeof(node)); //scanning data printf("\nEnter the data:"); scanf("%d",&new_node->data); //linking it with tree temp->left=new_node; new_node->left=NULL; new_node->right=NULL; } //else than move to left of parent node and ask for fyrther directions else { temp=temp->left; printf("\nMoved to %d further direction(l/r)?",temp->data); dir=getche(); directions(temp,dir); } break; //if r is pressed it meanes we move to right of the parent node case 'r': //if right of the parent node is null then new node is added if(temp->right==NULL) { //initialization node *new_node=NULL; //allocating memory to the new node new_node=(node*)malloc(sizeof(node)); //scanning data printf("\nEnter the data:"); scanf("%d",&new_node->data); //linking it with tree temp->right=new_node; new_node->left=NULL; new_node->right=NULL; } //else than move to right of parent node and ask for fyrther directions else { temp=temp->right; printf("\nMoved to %d. further direction(l/r)?",temp->data); dir=getche(); directions(temp,dir); } break; //if wrong key is pressed default: printf("\nwrong directin entered press 'l' tom move left and press 'r' to move right"); dir=getche(); directions(temp,dir); } }
void SideComplexLinearTimeInterpolateOp::timeInterpolate( hier::PatchData& dst_data, const hier::Box& where, const hier::PatchData& src_data_old, const hier::PatchData& src_data_new) const { const tbox::Dimension& dim(where.getDim()); const SideData<dcomplex>* old_dat = CPP_CAST<const SideData<dcomplex> *>(&src_data_old); const SideData<dcomplex>* new_dat = CPP_CAST<const SideData<dcomplex> *>(&src_data_new); SideData<dcomplex>* dst_dat = CPP_CAST<SideData<dcomplex> *>(&dst_data); TBOX_ASSERT(old_dat != 0); TBOX_ASSERT(new_dat != 0); TBOX_ASSERT(dst_dat != 0); TBOX_ASSERT((where * old_dat->getGhostBox()).isSpatiallyEqual(where)); TBOX_ASSERT((where * new_dat->getGhostBox()).isSpatiallyEqual(where)); TBOX_ASSERT((where * dst_dat->getGhostBox()).isSpatiallyEqual(where)); TBOX_ASSERT_OBJDIM_EQUALITY4(dst_data, where, src_data_old, src_data_new); const hier::IntVector& directions = dst_dat->getDirectionVector(); TBOX_ASSERT(directions == hier::IntVector::min(directions, old_dat->getDirectionVector())); TBOX_ASSERT(directions == hier::IntVector::min(directions, new_dat->getDirectionVector())); const hier::Index old_ilo = old_dat->getGhostBox().lower(); const hier::Index old_ihi = old_dat->getGhostBox().upper(); const hier::Index new_ilo = new_dat->getGhostBox().lower(); const hier::Index new_ihi = new_dat->getGhostBox().upper(); const hier::Index dst_ilo = dst_dat->getGhostBox().lower(); const hier::Index dst_ihi = dst_dat->getGhostBox().upper(); const hier::Index ifirst = where.lower(); const hier::Index ilast = where.upper(); const double old_time = old_dat->getTime(); const double new_time = new_dat->getTime(); const double dst_time = dst_dat->getTime(); TBOX_ASSERT((old_time < dst_time || tbox::MathUtilities<double>::equalEps(old_time, dst_time)) && (dst_time < new_time || tbox::MathUtilities<double>::equalEps(dst_time, new_time))); double tfrac = dst_time - old_time; double denom = new_time - old_time; if (denom > tbox::MathUtilities<double>::getMin()) { tfrac /= denom; } else { tfrac = 0.0; } for (int d = 0; d < dst_dat->getDepth(); ++d) { if (dim == tbox::Dimension(1)) { if (directions(0)) { SAMRAI_F77_FUNC(lintimeintsidecmplx1d, LINTIMEINTSIDECMPLX1D) (ifirst(0), ilast(0), old_ilo(0), old_ihi(0), new_ilo(0), new_ihi(0), dst_ilo(0), dst_ihi(0), tfrac, old_dat->getPointer(0, d), new_dat->getPointer(0, d), dst_dat->getPointer(0, d)); } } else if (dim == tbox::Dimension(2)) { if (directions(0)) { SAMRAI_F77_FUNC(lintimeintsidecmplx2d0, LINTIMEINTSIDECMPLX2D0) (ifirst(0), ifirst(1), ilast(0), ilast(1), old_ilo(0), old_ilo(1), old_ihi(0), old_ihi(1), new_ilo(0), new_ilo(1), new_ihi(0), new_ihi(1), dst_ilo(0), dst_ilo(1), dst_ihi(0), dst_ihi(1), tfrac, old_dat->getPointer(0, d), new_dat->getPointer(0, d), dst_dat->getPointer(0, d)); } if (directions(1)) { SAMRAI_F77_FUNC(lintimeintsidecmplx2d1, LINTIMEINTSIDECMPLX2D1) (ifirst(0), ifirst(1), ilast(0), ilast(1), old_ilo(0), old_ilo(1), old_ihi(0), old_ihi(1), new_ilo(0), new_ilo(1), new_ihi(0), new_ihi(1), dst_ilo(0), dst_ilo(1), dst_ihi(0), dst_ihi(1), tfrac, old_dat->getPointer(1, d), new_dat->getPointer(1, d), dst_dat->getPointer(1, d)); } } else if (dim == tbox::Dimension(3)) { if (directions(0)) { SAMRAI_F77_FUNC(lintimeintsidecmplx3d0, LINTIMEINTSIDECMPLX3D0) (ifirst(0), ifirst(1), ifirst(2), ilast(0), ilast(1), ilast(2), old_ilo(0), old_ilo(1), old_ilo(2), old_ihi(0), old_ihi(1), old_ihi(2), new_ilo(0), new_ilo(1), new_ilo(2), new_ihi(0), new_ihi(1), new_ihi(2), dst_ilo(0), dst_ilo(1), dst_ilo(2), dst_ihi(0), dst_ihi(1), dst_ihi(2), tfrac, old_dat->getPointer(0, d), new_dat->getPointer(0, d), dst_dat->getPointer(0, d)); } if (directions(1)) { SAMRAI_F77_FUNC(lintimeintsidecmplx3d1, LINTIMEINTSIDECMPLX3D1) (ifirst(0), ifirst(1), ifirst(2), ilast(0), ilast(1), ilast(2), old_ilo(0), old_ilo(1), old_ilo(2), old_ihi(0), old_ihi(1), old_ihi(2), new_ilo(0), new_ilo(1), new_ilo(2), new_ihi(0), new_ihi(1), new_ihi(2), dst_ilo(0), dst_ilo(1), dst_ilo(2), dst_ihi(0), dst_ihi(1), dst_ihi(2), tfrac, old_dat->getPointer(1, d), new_dat->getPointer(1, d), dst_dat->getPointer(1, d)); } if (directions(2)) { SAMRAI_F77_FUNC(lintimeintsidecmplx3d2, LINTIMEINTSIDECMPLX3D2) (ifirst(0), ifirst(1), ifirst(2), ilast(0), ilast(1), ilast(2), old_ilo(0), old_ilo(1), old_ilo(2), old_ihi(0), old_ihi(1), old_ihi(2), new_ilo(0), new_ilo(1), new_ilo(2), new_ihi(0), new_ihi(1), new_ihi(2), dst_ilo(0), dst_ilo(1), dst_ilo(2), dst_ihi(0), dst_ihi(1), dst_ihi(2), tfrac, old_dat->getPointer(2, d), new_dat->getPointer(2, d), dst_dat->getPointer(2, d)); } } else { TBOX_ERROR( "SideComplexLinearTimeInterpolateOp::TimeInterpolate dim > 3 not supported" << std::endl); } } }