예제 #1
0
Params SRAssembler::read_param_file(string program_name) {
	ifstream param_file(this->param_file.c_str());
	string line;
	Params params;
	bool found_program = false;
	while (getline(param_file, line)){
		line = trim(line);
		if (line.length() == 0) continue;
		if (line == ("[" + program_name + "]")) {
			found_program = true;
			continue;
		}
		if (line.substr(0,1) == "#") continue;
		if (found_program && line.substr(0,1) == "[") break;
		if (found_program){
			vector<string> tokens;
			tokenize(line, tokens, "=");
			if (tokens.size() == 2){
				string param = trim(tokens[0]);
				string value = trim(tokens[1]);
				params.insert(Params::value_type(param, value));
			}
		}
	}
	return params;
}
void fi::VPDetectionWrapper::parseVPOutputFile(const std::string &vp_results_file, std::vector<Eigen::Vector2f> &vp_hypothesis)
{
	std::string a_line;
	unsigned int num_lines = 0; // the radial distortion params is on the 6 and 7th line!
	//std::ifstream param_file ("E:\\21\\Result\\UniBW\\10884_param.txt");
	std::ifstream param_file (vp_results_file.c_str());
	if (param_file.is_open())
	{
		while ( param_file.good() )
		{
			if (num_lines > 2)
			{
				break;
			}

			getline (param_file, a_line);
			Eigen::Vector2f tmpVP;
			if (a_line == "")
			{
				tmpVP(0) = 0;
				tmpVP(1) = 0;
				vp_hypothesis.push_back(tmpVP);
				break;
			}

			std::vector< std::string> r_vals;
			boost::split(r_vals, a_line, boost::is_any_of(";"));

			tmpVP(0) = boost::lexical_cast<float>(r_vals.at(0));
			tmpVP(1) = boost::lexical_cast<float>(r_vals.at(1));
			vp_hypothesis.push_back(tmpVP);
			num_lines++;
		}
	}
	else
	{
		return;
	}
}
예제 #3
0
bool use_case_5_driver( MPI_Comm comm ,
                        const std::string& mesh_options,
                        const std::string& solver_params )
{
  if ( 0 == stk::parallel_machine_rank( comm ) ) {
    std::cout << "stk_linsys use case 5" << std::endl
              << "  Number Processes = " << stk::parallel_machine_size( comm )
              << std::endl ;
  }

  //--------------------------------------------------------------------

  {
    //------------------------------------------------------------------
    // Declare the mesh meta data: element blocks and associated fields

    stk::mesh::fem::FEMMetaData fem_meta(SpatialDim, stk::mesh::fem::entity_rank_names(SpatialDim) ) ;
    Ioss::Init::Initializer init_db;

    stk::mesh::MetaData & mesh_meta_data = stk::mesh::fem::FEMMetaData::get_meta_data(fem_meta);

    {
      const stk::mesh::fem::FEMMetaData &fmd = fem_meta.get ( mesh_meta_data );
      std::cout <<fmd.is_FEM_initialized()<<endl;
    }

    const stk::mesh::EntityRank element_rank = fem_meta.element_rank();

    //--------------------------------
    // Element-block declarations typically occur when reading the
    // mesh-file meta-data, and thus won't usually appear in application code.
    // Declaring the element blocks and associating an element traits
    // with each element block.

    stk::mesh::Part & universal        = fem_meta.universal_part();
    stk::mesh::Part & block_hex        = fem_meta.declare_part("block_1", element_rank);
    stk::mesh::Part & block_quad_shell = fem_meta.declare_part("block_2", element_rank);

    stk::mesh::fem::CellTopology hex_top(shards::getCellTopologyData<shards::Hexahedron<> >());
    stk::mesh::fem::CellTopology qshell_top(shards::getCellTopologyData<shards::ShellQuadrilateral<> >());
    stk::mesh::fem::set_cell_topology( block_hex, hex_top );
    stk::mesh::fem::set_cell_topology( block_quad_shell, qshell_top );

    stk::io::put_io_part_attribute(block_hex);
    stk::io::put_io_part_attribute(block_quad_shell);

    //--------------------------------
    // Declaring fields of specified types on all nodes:

    VectorFieldType & coordinates_field =
      stk::mesh::put_field(
        fem_meta.declare_field< VectorFieldType >( "coordinates" ) ,
        stk::mesh::fem::FEMMetaData::NODE_RANK , universal , SpatialDim );

    VectorFieldType & displacements_field =
      stk::mesh::put_field(
        fem_meta.declare_field< VectorFieldType >( "displacements" ) ,
        stk::mesh::fem::FEMMetaData::NODE_RANK , universal , SpatialDim );

    //--------------------------------
    // rotation_field only exists on the shell-nodes:

    VectorFieldType & rotation_field =
      stk::mesh::put_field(
        fem_meta.declare_field< VectorFieldType >( "rotation" ),
        stk::mesh::fem::FEMMetaData::NODE_RANK , block_quad_shell , SpatialDim );

    stk::mesh::Part& bcpart = fem_meta.declare_part("bcpart");

    // Define the transient fields that will be output.
    stk::io::set_field_role(displacements_field, Ioss::Field::TRANSIENT);

    //--------------------------------
    // Commit (finalize) the meta data.  Is now ready to be used
    // in the creation and management of mesh bulk data.

    fem_meta.commit();

    //------------------------------------------------------------------
    // stk::mesh::BulkData bulk data conforming to the meta data.

    stk::mesh::BulkData mesh_bulk_data( mesh_meta_data , comm );

    // In a typical app, the mesh would be read from file at this point.
    // But in this use-case, we generate the mesh and initialize
    // field data to use-case defined values.

    use_case_5_generate_mesh(
      mesh_options ,
      mesh_bulk_data ,
      coordinates_field ,
      block_hex ,
      block_quad_shell );

    use_case_5_initialize_data(
      mesh_bulk_data ,
      coordinates_field ,
      displacements_field ,
      rotation_field );

    //Add a node to our boundary-condition part 'bcpart'.
    //let's choose the first locally-owned node. (This will produce a
    //different boundary-condition for different numbers of processors...
    //A more realistic case would simply pick a specific set of nodes
    //regardless of which processors they are on.)

    mesh_bulk_data.modification_begin();

    std::vector<stk::mesh::Entity*> local_nodes;
    stk::mesh::Selector select_owned(fem_meta.locally_owned_part());
    stk::mesh::get_selected_entities(select_owned,
                                     mesh_bulk_data.buckets(stk::mesh::fem::FEMMetaData::NODE_RANK),
                                     local_nodes);

    if (local_nodes.size() > 0) {
      stk::mesh::PartVector partvector;
      partvector.push_back(&bcpart);
      mesh_bulk_data.change_entity_parts(*local_nodes[0], partvector);
    }

    mesh_bulk_data.modification_end();

    //set owner-processors to lowest-sharing (stk::mesh defaults to
    //highest-sharing) If highest-sharing owns, then it isn't correct for the
    //way the fei library sets ownership of shared nodes for vectors etc.
    stk::mesh::set_owners<stk::mesh::LowestRankSharingProcOwns>( mesh_bulk_data );

    //Note: set_owners should throw an error if not done inside a modification_begin/end block.
    //------------------------------------------------------------------

    const unsigned myProc = mesh_bulk_data.parallel_rank();

    //Now begin the use-case:
    //Create a fei::Factory of type Factory_Trilinos, which will produce
    //fei::Matrix and fei::Vector objects with run-time-type compatible with Trilinos.

    fei::SharedPtr<fei::Factory> feifactory(new Factory_Trilinos(comm));
    stk::linsys::LinearSystem ls(comm, feifactory);

    if (myProc == 0) {
      std::cout << "Adding element-node connectivities for displacements field for all locally-owned "
        << "elements..." << std::endl;
    }

    //Add connectivities for our mesh to the linsys::LinearSystem object. This
    //will enable us to generate a matrix-graph:

    stk::linsys::add_connectivities(ls, element_rank,
                                    stk::mesh::fem::FEMMetaData::NODE_RANK,
                                    displacements_field, select_owned, mesh_bulk_data);

    ls.synchronize_mappings_and_structure();

    ls.create_fei_LinearSystem();

    fei::SharedPtr<fei::MatrixGraph> matgraph = ls.get_fei_MatrixGraph();
    fei::SharedPtr<fei::Matrix> matrix = ls.get_fei_LinearSystem()->getMatrix();
    fei::SharedPtr<fei::Vector> rhs = ls.get_fei_LinearSystem()->getRHS();
    fei::SharedPtr<fei::Vector> solution = ls.get_fei_LinearSystem()->getSolutionVector();

    //Now we'll run through the mesh and load up dense element-matrices and element-vectors
    //to assemble into the global sparse linear-system:
    {
      const std::vector<stk::mesh::Bucket*>& mesh_buckets = mesh_bulk_data.buckets(element_rank);
      std::vector<stk::mesh::Bucket*> part_buckets;
      stk::mesh::get_buckets(select_owned, mesh_buckets, part_buckets);

      stk::linsys::DofMapper& dof_mapper = ls.get_DofMapper();

      int field_id = dof_mapper.get_field_id(displacements_field);

      stk::mesh::Entity& first_entity = *(part_buckets[0]->begin());
      stk::mesh::PairIterRelation rel = first_entity.relations(stk::mesh::fem::FEMMetaData::NODE_RANK);
      int num_nodes_per_elem = rel.second - rel.first;

      int pattern_id = matgraph->definePattern(num_nodes_per_elem, stk::mesh::fem::FEMMetaData::NODE_RANK, field_id);

      std::vector<int> node_ids(num_nodes_per_elem);

      const int field_size = dof_mapper.get_fei_VectorSpace()->getFieldSize(field_id);
      const int matsize = num_nodes_per_elem*field_size*num_nodes_per_elem*field_size;
      const int vecsize = num_nodes_per_elem*field_size;

      std::vector<double> elem_matrix_1d(matsize, 0);
      std::vector<double*> elem_matrix_2d(vecsize);

      std::vector<double> elem_vector(vecsize, 0);

      for(size_t i=0; i<elem_matrix_2d.size(); ++i) {
        elem_matrix_2d[i] = &elem_matrix_1d[i*vecsize];
      }

      //fill our dummy elem-matrix:
      //This dummy matrix will be the same for every element. A real application
      //would form a different elem-matrix for each element.
      for(size_t i=0; i<elem_matrix_2d.size(); ++i) {
        double* row = elem_matrix_2d[i];
        if (i>=1) row[i-1] = -1;
        row[i] = 2;
        if (i<elem_matrix_2d.size()-1) row[i+1] = -1;

        elem_vector[i] = 1;
      }

      std::vector<int> eqn_indices(vecsize);

      for(size_t i=0; i<part_buckets.size(); ++i) {
        stk::mesh::Bucket::iterator
          b_iter = part_buckets[i]->begin(),
                 b_end  = part_buckets[i]->end();
        for(; b_iter != b_end; ++b_iter) {
          stk::mesh::Entity& elem = *b_iter;
          rel = elem.relations(stk::mesh::fem::FEMMetaData::NODE_RANK);
          for(int j=0; rel.first != rel.second; ++rel.first, ++j) {
            node_ids[j] = rel.first->entity()->identifier();
          }

          matgraph->getPatternIndices(pattern_id, &node_ids[0], eqn_indices);

          matrix->sumIn(vecsize, &eqn_indices[0], vecsize, &eqn_indices[0],
                        &elem_matrix_2d[0]);
          rhs->sumIn(vecsize, &eqn_indices[0], &elem_vector[0]);
        }
      }

      stk::linsys::dirichlet_bc(ls, mesh_bulk_data, bcpart, stk::mesh::fem::FEMMetaData::NODE_RANK,
                                displacements_field, 0, 3.14159265);

      ls.finalize_assembly();

      //Read solver-parameters out of a file. In a real application this would
      //be done during a parsing phase, *not* here in the assembly code.

      Teuchos::ParameterList params;
      if (solver_params != "") {
        Teuchos::ParameterXMLFileReader param_file(solver_params);
        params = param_file.getParameters();
      }

      //Launch the linear-solver:
      int status = 0, ret;
      ret = ls.solve(status, params);

      if (ret != 0) {
        throw std::runtime_error("Error in the linear solver.");
      }

      //Copy the contents of the solution-vector back into our mesh-data:
      copy_vector_to_mesh( *solution, dof_mapper, mesh_bulk_data);
    }

    //This following section writes mesh data out to an exodus file:
    {
      const std::string out_filename("mesh.e");

      stk::io::MeshData mesh;
      stk::io::create_output_mesh(out_filename, comm, mesh_bulk_data, mesh);
      stk::io::define_output_fields(mesh, fem_meta);

      // Write the model to the mesh file (topology, coordinates, attributes, etc)
      stk::io::process_output_request(mesh, mesh_bulk_data, 0.0);
    }

    //Write out our assembled linear-system to files:

    matrix->writeToFile("A.mtx");
    rhs->writeToFile("rhs.vec");
    solution->writeToFile("solution.vec");
  }
  return true;
}
예제 #4
0
bool ogc_deriving_conv :: to_wkt(
    char      buffer[],
    int       options,
    size_t    buflen) const
{
    OGC_UTF8_NAME buf_name;
    OGC_TBUF      buf_hdr;
    OGC_TBUF      buf_method;
    OGC_TBUF      buf_parameter;
    OGC_TBUF      buf_id;
    int           opts  =  (options | OGC_WKT_OPT_INTERNAL);
    size_t        len   = 0;
    bool          rc    = true;
    const char *  opn   = "[";
    const char *  cls   = "]";
    const char *  kwd   = obj_kwd();

    if ( (options & OGC_WKT_OPT_PARENS) != 0 )
    {
        opn = "(";
        cls = ")";
    }

    if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 )
        opts |= OGC_WKT_OPT_NO_IDS;

    if ( buffer == OGC_NULL )
        return false;
    *buffer = 0;

    if ( !is_visible() )
        return true;

    if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 )
        return true;

    rc &= ogc_method :: to_wkt(_method, buf_method, opts, OGC_TBUF_MAX);

    ogc_string::escape_str(buf_name, _name, OGC_UTF8_NAME_MAX);
    sprintf(buf_hdr, "%s%s\"%s\"",
            kwd, opn, buf_name);

    OGC_CPY_TO_BUF( buf_hdr    );
    OGC_ADD_TO_BUF( buf_method );

    if ( _parameters != OGC_NULL )
    {
        for (int i = 0; i < parameter_count(); i++)
        {
            rc &= ogc_parameter :: to_wkt(parameter(i), buf_parameter, opts, OGC_TBUF_MAX);
            OGC_ADD_TO_BUF( buf_parameter );
        }
    }

    if ( _param_files != OGC_NULL )
    {
        for (int i = 0; i < param_file_count(); i++)
        {
            rc &= ogc_param_file :: to_wkt(param_file(i), buf_parameter, opts, OGC_TBUF_MAX);
            OGC_ADD_TO_BUF( buf_parameter );
        }
    }

    if ( _ids != OGC_NULL && (options & OGC_WKT_OPT_NO_IDS) == 0 )
    {
        for (int i = 0; i < id_count(); i++)
        {
            rc &= ogc_id :: to_wkt(id(i), buf_id, opts, OGC_TBUF_MAX);
            OGC_ADD_TO_BUF( buf_id );
        }
    }

    OGC_CPY_TO_BUF( cls );

    if ( (options & OGC_WKT_OPT_INTERNAL) == 0 &&
            (options & OGC_WKT_OPT_EXPAND)   != 0 )
    {
        rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen);
    }

    return rc;
}