コード例 #1
0
ファイル: main.C プロジェクト: MSV-Project/IBAMR
void
update_triads(
    const double freq,
    tbox::Pointer<hier::PatchHierarchy<NDIM> > hierarchy,
    LDataManager* const l_data_manager,
    const double current_time,
    const double /*dt*/)
{
    // The angular velocity.
    static const double angw = 2.0*M_PI*freq;

    // The LMesh object provides the set of local Lagrangian nodes.
    const int finest_ln = hierarchy->getFinestLevelNumber();
    const tbox::Pointer<LMesh> mesh = l_data_manager->getLMesh(finest_ln);
    const std::vector<LNode*>& local_nodes = mesh->getNodes();

    // Update the director triads for all anchored points.
    tbox::Pointer<LData> D_data = l_data_manager->getLData("D", finest_ln);
    blitz::Array<double,2>& D_array = *D_data->getLocalFormVecArray();
    for (std::vector<LNode*>::const_iterator cit = local_nodes.begin();
         cit != local_nodes.end(); ++cit)
    {
        const LNode& node_idx = **cit;

        // If spec is NULL, then the IB point is NOT anchored.  Otherwise, the
        // IB point IS anchored.
        tbox::Pointer<IBAnchorPointSpec> spec = node_idx.getNodeDataItem<IBAnchorPointSpec>();
        if (!spec.isNull())
        {
            // `global_idx' is the index of the vertex in the input file.
            const int global_idx = node_idx.getLagrangianIndex();
            NULL_USE(global_idx);

            // `local_petsc_idx' is the index of the vertex in the internal
            // IBAMR data structures.  Generally, global_idx != local_petsc_idx.
            const int local_petsc_idx = node_idx.getLocalPETScIndex();

            double* D1 = &D_array(local_petsc_idx,0);
            D1[0] =  cos(angw*current_time);
            D1[1] =  sin(angw*current_time);
            D1[2] = 0.0;

            double* D2 = &D_array(local_petsc_idx,3);
            D2[0] = -sin(angw*current_time);
            D2[1] =  cos(angw*current_time);
            D2[2] = 0.0;

            double* D3 = &D_array(local_petsc_idx,6);
            D3[0] = 0.0;
            D3[1] = 0.0;
            D3[2] = 1.0;
        }
    }
    D_data->restoreArrays();
    return;
}// update_triads
コード例 #2
0
ファイル: main.C プロジェクト: MSV-Project/IBAMR
void
output_data(
    tbox::Pointer<hier::PatchHierarchy<NDIM> > patch_hierarchy,
    LDataManager* l_data_manager,
    const int iteration_num,
    const double loop_time,
    const string& data_dump_dirname)
{
    tbox::pout << "writing hierarchy data at iteration " << iteration_num << " to disk" << endl;
    tbox::pout << "simulation time is " << loop_time << endl;

    const int finest_hier_level = patch_hierarchy->getFinestLevelNumber();

    string file_name;
    char temp_buf[128];

    /*
     * Write Lagrangian data.
     */
    tbox::Pointer<LData> X_data = l_data_manager->getLData("X", finest_hier_level);
    Vec X_petsc_vec = X_data->getVec();
    Vec X_lag_vec;
    VecDuplicate(X_petsc_vec, &X_lag_vec);
    l_data_manager->scatterPETScToLagrangian(X_petsc_vec, X_lag_vec, finest_hier_level);
    file_name = data_dump_dirname + "/" + "X.";
    sprintf(temp_buf, "%05d", iteration_num);
    file_name += temp_buf;
    for (int rank = 0; rank < tbox::SAMRAI_MPI::getNodes(); ++rank)
    {
        if (tbox::SAMRAI_MPI::getRank() == rank)
        {
            ofstream str(file_name.c_str(), rank == 0 ? ios_base::trunc : ios_base::app);

            if (rank == 0)
            {
                str << X_data->getGlobalNodeCount() << "\n";
            }

            int size;
            VecGetLocalSize(X_lag_vec, &size);
            if (size > 0)
            {
                str.precision(12);
                str.setf(ios::scientific);
                str.setf(ios::showpos);
                double* X_lag_arr;
                VecGetArray(X_lag_vec, &X_lag_arr);
                const int depth = NDIM;
                for (int k = 0; k < size/depth; ++k)
                {
                    for (int d = 0; d < depth; ++d)
                    {
                        str << X_lag_arr[depth*k+d];
                        if (d < depth-1)
                        {
                            str << " ";
                        }
                        else
                        {
                            str << "\n";
                        }
                    }
                }
                VecRestoreArray(X_lag_vec, &X_lag_arr);
            }
        }
        tbox::SAMRAI_MPI::barrier();
    }
    VecDestroy(X_lag_vec);

    tbox::Pointer<LData> D_data = l_data_manager->getLData("D", finest_hier_level);
    Vec D_petsc_vec = D_data->getVec();
    Vec D_lag_vec;
    VecDuplicate(D_petsc_vec, &D_lag_vec);
    l_data_manager->scatterPETScToLagrangian(D_petsc_vec, D_lag_vec, finest_hier_level);
    file_name = data_dump_dirname + "/" + "D.";
    sprintf(temp_buf, "%05d", iteration_num);
    file_name += temp_buf;
    for (int rank = 0; rank < tbox::SAMRAI_MPI::getNodes(); ++rank)
    {
        if (tbox::SAMRAI_MPI::getRank() == rank)
        {
            ofstream str(file_name.c_str(), rank == 0 ? ios_base::trunc : ios_base::app);

            if (rank == 0)
            {
                str << D_data->getGlobalNodeCount() << "\n";
            }

            int size;
            VecGetLocalSize(D_lag_vec, &size);
            if (size > 0)
            {
                str.precision(12);
                str.setf(ios::scientific);
                str.setf(ios::showpos);
                double* D_lag_arr;
                VecGetArray(D_lag_vec, &D_lag_arr);
                const int depth = 3;
                for (int k = 0; k < size/depth; ++k)
                {
                    for (int d = 0; d < depth; ++d)
                    {
                        str << D_lag_arr[depth*k+d];
                        if (d < depth-1)
                        {
                            str << " ";
                        }
                        else
                        {
                            str << "\n";
                        }
                    }
                }
                VecRestoreArray(D_lag_vec, &D_lag_arr);
            }
        }
        tbox::SAMRAI_MPI::barrier();
    }
    VecDestroy(D_lag_vec);
    return;
}// output_data
void
update_target_point_positions(
			      tbox::Pointer<hier::PatchHierarchy<NDIM> > hierarchy,
			      LDataManager* const l_data_manager,
			      const double current_time,
			      const double dt)
{
  const int finest_ln = hierarchy->getFinestLevelNumber();

  static const double pi = 4*atan(1);
  static const double V = 0.2; //velocity of the wing during translation (meters/sec)
  
  	////////////////////////////////////////////////////////////////////////////////////////
	// these parameters require modification to match the desired geometry and motion
	
    static const double L1 = 1; // length of computational domain (meters)
    static const int N1 = 512; // number of cartesian grid meshwidths at the finest level of the AMR grid
	static const double diameter = 0.1;			// diameter of tube
	static const double R2 = 0.1;				// distance from middle of domain to inner wall
	static const double R1 = R2+diameter;		// distance from middle of domain to outer wall
	static const double pamp = 0.8;				//percent occlusion of the tube
	static const double amp = pamp*diameter/2.0;	//amplitude of contraction of each piece of the actuator
	static const double freq = 1.0;
 
 ////////////////////////////////////////////////////////////////////////////////////////////////

  // Find out the Lagrangian index ranges.
  const std::pair<int,int>& actuator_top_idxs = l_data_manager->getLagrangianStructureIndexRange(0, finest_ln);
  const std::pair<int,int>& actuator_bot_idxs = l_data_manager->getLagrangianStructureIndexRange(1, finest_ln);
	
  // Get the LMesh (which we assume to be associated with the finest level of
  // the patch hierarchy).  Note that we currently need to update both "local"
  // and "ghost" node data.
  Pointer<LMesh> mesh = l_data_manager->getLMesh(finest_ln);
  vector<LNode*> nodes;
  nodes.insert(nodes.end(), mesh->getLocalNodes().begin(), mesh->getLocalNodes().end());
  nodes.insert(nodes.end(), mesh->getGhostNodes().begin(), mesh->getGhostNodes().end());

  // Update the target point positions in their associated target point force
  // specs.
  tbox::Pointer<hier::PatchLevel<NDIM> > level = hierarchy->getPatchLevel(finest_ln);
  for (vector<LNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it)
    {
      LNode* node_idx = *it;
      IBTargetPointForceSpec* force_spec = node_idx->getNodeDataItem<IBTargetPointForceSpec>();
      if (force_spec == NULL) continue;  // skip to next node

      // Here we update the position of the target point.
      //
      // NOTES: lag_idx      is the "index" of the Lagrangian point (lag_idx = 0, 1, ..., N-1, where N is the number of Lagrangian points)
      //        X_target     is the target position of the target point
      //        X_target[0]  is the x component of the target position
      //        X_target[1]  is the y component of the target position
      //        X_target[2]  is the z component of the target position (for a 3D simulation)
      //
      // The target position is shifted to the left or right by the
      // increment dt*V

      const int lag_idx = node_idx->getLagrangianIndex();
      //Depending on the version of IBAMR, you need to select one of the ways of accessing target point positions. 
      //TinyVector<double,NDIM>& X_target = force_spec->getTargetPointPosition();
      //IBTK::Vector<double,NDIM>& X_target = force_spec->getTargetPointPosition();
      Point& X_target = force_spec->getTargetPointPosition();
	  
		//move the top piece
	    if (actuator_top_idxs.first <= lag_idx && lag_idx < actuator_top_idxs.second)
	      {
				X_target[1] = -R2-V*dt;  //(amp/2)*(1+sin(2*pi*freq*current_time - pi/2));
	      }
		//move the bottom piece
		if (actuator_bot_idxs.first <= lag_idx && lag_idx < actuator_bot_idxs.second)
	      {
				X_target[1] = -R1+V*dt; //(amp/2)*(1+sin(2*pi*freq*current_time - pi/2));
	      }
      
    }
  return;
}// update_target_point_positions