Ejemplo n.º 1
0
void IBFECentroidPostProcessor::reconstructVariables(double data_time)
{
    EquationSystems* equation_systems = d_fe_data_manager->getEquationSystems();
    const MeshBase& mesh = equation_systems->get_mesh();
    const int dim = mesh.mesh_dimension();
    AutoPtr<QBase> qrule = QBase::build(QGAUSS, NDIM, CONSTANT);

    // Set up all system data required to evaluate the mesh functions.
    System& X_system = equation_systems->get_system<System>(IBFEMethod::COORDS_SYSTEM_NAME);
    const DofMap& X_dof_map = X_system.get_dof_map();
    for (unsigned d = 0; d < NDIM; ++d)
        TBOX_ASSERT(X_dof_map.variable_type(d) == X_dof_map.variable_type(0));
    std::vector<std::vector<unsigned int> > X_dof_indices(NDIM);
    AutoPtr<FEBase> X_fe(FEBase::build(dim, X_dof_map.variable_type(0)));
    X_fe->attach_quadrature_rule(qrule.get());
    const std::vector<libMesh::Point>& q_point = X_fe->get_xyz();
    const std::vector<std::vector<double> >& phi_X = X_fe->get_phi();
    const std::vector<std::vector<VectorValue<double> > >& dphi_X = X_fe->get_dphi();
    X_system.solution->localize(*X_system.current_local_solution);
    NumericVector<double>& X_data = *(X_system.current_local_solution);
    X_data.close();

    for (std::set<unsigned int>::const_iterator cit = d_var_fcn_systems.begin();
         cit != d_var_fcn_systems.end();
         ++cit)
    {
        System& system = equation_systems->get_system(*cit);
        system.update();
    }

    const unsigned int num_scalar_vars = d_scalar_var_systems.size();
    std::vector<const DofMap*> scalar_var_dof_maps(num_scalar_vars);
    std::vector<std::vector<unsigned int> > scalar_var_dof_indices(num_scalar_vars);
    std::vector<NumericVector<double>*> scalar_var_data(num_scalar_vars);
    std::vector<unsigned int> scalar_var_system_num(num_scalar_vars);
    std::vector<std::vector<NumericVector<double>*> > scalar_var_fcn_data(num_scalar_vars);
    for (unsigned int k = 0; k < num_scalar_vars; ++k)
    {
        scalar_var_dof_maps[k] = &d_scalar_var_systems[k]->get_dof_map();
        scalar_var_data[k] = d_scalar_var_systems[k]->solution.get();
        scalar_var_system_num[k] = d_scalar_var_systems[k]->number();
        scalar_var_fcn_data[k].reserve(d_scalar_var_fcn_systems[k].size());
        for (std::vector<unsigned int>::const_iterator cit =
                 d_scalar_var_fcn_systems[k].begin();
             cit != d_scalar_var_fcn_systems[k].end();
             ++cit)
        {
            System& system = equation_systems->get_system(*cit);
            scalar_var_fcn_data[k].push_back(system.current_local_solution.get());
        }
    }

    const unsigned int num_vector_vars = d_vector_var_systems.size();
    std::vector<const DofMap*> vector_var_dof_maps(num_vector_vars);
    std::vector<std::vector<std::vector<unsigned int> > > vector_var_dof_indices(
        num_vector_vars);
    std::vector<NumericVector<double>*> vector_var_data(num_vector_vars);
    std::vector<unsigned int> vector_var_system_num(num_vector_vars);
    std::vector<std::vector<NumericVector<double>*> > vector_var_fcn_data(num_vector_vars);
    for (unsigned int k = 0; k < num_vector_vars; ++k)
    {
        vector_var_dof_maps[k] = &d_vector_var_systems[k]->get_dof_map();
        vector_var_dof_indices[k].resize(d_vector_var_dims[k]);
        vector_var_data[k] = d_vector_var_systems[k]->solution.get();
        vector_var_system_num[k] = d_vector_var_systems[k]->number();
        vector_var_fcn_data[k].reserve(d_vector_var_fcn_systems[k].size());
        for (std::vector<unsigned int>::const_iterator cit =
                 d_vector_var_fcn_systems[k].begin();
             cit != d_vector_var_fcn_systems[k].end();
             ++cit)
        {
            System& system = equation_systems->get_system(*cit);
            vector_var_fcn_data[k].push_back(system.current_local_solution.get());
        }
    }

    const unsigned int num_tensor_vars = d_tensor_var_systems.size();
    std::vector<const DofMap*> tensor_var_dof_maps(num_tensor_vars);
    std::vector<boost::multi_array<std::vector<unsigned int>, 2> > tensor_var_dof_indices(
        num_tensor_vars);
    std::vector<NumericVector<double>*> tensor_var_data(num_tensor_vars);
    std::vector<unsigned int> tensor_var_system_num(num_tensor_vars);
    std::vector<std::vector<NumericVector<double>*> > tensor_var_fcn_data(num_tensor_vars);
    for (unsigned int k = 0; k < num_tensor_vars; ++k)
    {
        tensor_var_dof_maps[k] = &d_tensor_var_systems[k]->get_dof_map();
        typedef boost::multi_array<std::vector<unsigned int>, 2> array_type;
        array_type::extent_gen extents;
        tensor_var_dof_indices[k].resize(extents[d_tensor_var_dims[k]][d_tensor_var_dims[k]]);
        tensor_var_data[k] = d_tensor_var_systems[k]->solution.get();
        tensor_var_system_num[k] = d_tensor_var_systems[k]->number();
        tensor_var_fcn_data[k].reserve(d_tensor_var_fcn_systems[k].size());
        for (std::vector<unsigned int>::const_iterator cit =
                 d_tensor_var_fcn_systems[k].begin();
             cit != d_tensor_var_fcn_systems[k].end();
             ++cit)
        {
            System& system = equation_systems->get_system(*cit);
            tensor_var_fcn_data[k].push_back(system.current_local_solution.get());
        }
    }

    // Reconstruct the variables via simple function evaluation.
    TensorValue<double> FF_qp, VV;
    libMesh::Point X_qp;
    VectorValue<double> V;
    double v;
    boost::multi_array<double, 2> X_node;
    const MeshBase::const_element_iterator el_begin = mesh.active_local_elements_begin();
    const MeshBase::const_element_iterator el_end = mesh.active_local_elements_end();
    for (MeshBase::const_element_iterator el_it = el_begin; el_it != el_end; ++el_it)
    {
        Elem* const elem = *el_it;
        X_fe->reinit(elem);
        for (unsigned int d = 0; d < NDIM; ++d)
        {
            X_dof_map.dof_indices(elem, X_dof_indices[d], d);
        }

        const unsigned int n_qp = qrule->n_points();
        TBOX_ASSERT(n_qp == 1);
        const unsigned int qp = 0;

        get_values_for_interpolation(X_node, X_data, X_dof_indices);
        interpolate(X_qp, qp, X_node, phi_X);
        jacobian(FF_qp, qp, X_node, dphi_X);
        const libMesh::Point& s_qp = q_point[qp];

        // Scalar-valued variables.
        for (unsigned int k = 0; k < num_scalar_vars; ++k)
        {
            scalar_var_dof_maps[k]->dof_indices(elem, scalar_var_dof_indices[k], 0);
            d_scalar_var_fcns[k](v,
                                 FF_qp,
                                 X_qp,
                                 s_qp,
                                 elem,
                                 scalar_var_fcn_data[k],
                                 data_time,
                                 d_scalar_var_fcn_ctxs[k]);
            scalar_var_data[k]->set(scalar_var_dof_indices[k][0], v);
        }

        // Vector-valued variables.
        for (unsigned int k = 0; k < num_vector_vars; ++k)
        {
            for (unsigned int i = 0; i < d_vector_var_dims[k]; ++i)
            {
                vector_var_dof_maps[k]->dof_indices(elem, vector_var_dof_indices[k][i], i);
            }
            d_vector_var_fcns[k](V,
                                 FF_qp,
                                 X_qp,
                                 s_qp,
                                 elem,
                                 vector_var_fcn_data[k],
                                 data_time,
                                 d_vector_var_fcn_ctxs[k]);
            for (unsigned int i = 0; i < d_vector_var_dims[k]; ++i)
            {
                vector_var_data[k]->set(vector_var_dof_indices[k][i][0], V(i));
            }
        }

        // Tensor-valued variables.
        for (unsigned int k = 0; k < num_tensor_vars; ++k)
        {
            for (unsigned int i = 0; i < d_tensor_var_dims[k]; ++i)
            {
                for (unsigned int j = 0; j < d_tensor_var_dims[k]; ++j)
                {
                    tensor_var_dof_maps[k]->dof_indices(
                        elem, tensor_var_dof_indices[k][i][j], j + i * d_tensor_var_dims[k]);
                }
            }
            d_tensor_var_fcns[k](VV,
                                 FF_qp,
                                 X_qp,
                                 s_qp,
                                 elem,
                                 tensor_var_fcn_data[k],
                                 data_time,
                                 d_tensor_var_fcn_ctxs[k]);
            for (unsigned int i = 0; i < d_tensor_var_dims[k]; ++i)
            {
                for (unsigned int j = 0; j < d_tensor_var_dims[k]; ++j)
                {
                    tensor_var_data[k]->set(tensor_var_dof_indices[k][i][j][0], VV(i, j));
                }
            }
        }
    }

    // Close all vectors.
    for (unsigned int k = 0; k < num_scalar_vars; ++k)
    {
        scalar_var_data[k]->close();
    }
    for (unsigned int k = 0; k < num_vector_vars; ++k)
    {
        vector_var_data[k]->close();
    }
    for (unsigned int k = 0; k < num_tensor_vars; ++k)
    {
        tensor_var_data[k]->close();
    }
    return;
} // reconstructVariables
Ejemplo n.º 2
0
void
postprocess_data(Pointer<PatchHierarchy<NDIM> > /*patch_hierarchy*/,
                 Pointer<INSHierarchyIntegrator> /*navier_stokes_integrator*/,
                 Mesh& mesh,
                 EquationSystems* equation_systems,
                 const int /*iteration_num*/,
                 const double loop_time,
                 const string& /*data_dump_dirname*/)
{
    const unsigned int dim = mesh.mesh_dimension();
    double F_integral[NDIM];
    for (unsigned int d = 0; d < NDIM; ++d) F_integral[d] = 0.0;

    System& F_system = equation_systems->get_system(IBFEMethod::FORCE_SYSTEM_NAME);
    NumericVector<double>* F_vec = F_system.solution.get();
    NumericVector<double>* F_ghost_vec = F_system.current_local_solution.get();
    F_vec->localize(*F_ghost_vec);
    const DofMap& dof_map = F_system.get_dof_map();
    FEType fe_type = dof_map.variable_type(0);
    std::unique_ptr<FEBase> fe(FEBase::build(dim, fe_type));
    std::unique_ptr<QBase> qrule = fe_type.default_quadrature_rule(dim);
    fe->attach_quadrature_rule(qrule.get());
    const vector<double>& JxW = fe->get_JxW();
    const vector<vector<double> >& phi = fe->get_phi();

    std::vector<std::vector<unsigned int> > dof_indices(NDIM);
    boost::multi_array<double, 2> F_node;
    VectorValue<double> F;

    const MeshBase::const_element_iterator el_begin = mesh.active_local_elements_begin();
    const MeshBase::const_element_iterator el_end = mesh.active_local_elements_end();
    for (MeshBase::const_element_iterator el_it = el_begin; el_it != el_end; ++el_it)
    {
        Elem* const elem = *el_it;
        fe->reinit(elem);
        for (unsigned int d = 0; d < NDIM; ++d)
        {
            dof_map.dof_indices(elem, dof_indices[d], d);
        }
        get_values_for_interpolation(F_node, *F_ghost_vec, dof_indices);

        const unsigned int n_qp = qrule->n_points();
        for (unsigned int qp = 0; qp < n_qp; ++qp)
        {
            interpolate(F, qp, F_node, phi);
            for (int d = 0; d < NDIM; ++d)
            {
                F_integral[d] += F(d) * JxW[qp];
            }
        }
    }
    SAMRAI_MPI::sumReduction(F_integral, NDIM);
    static const double rho = 1.0;
    static const double U_max = 1.0;
    static const double D = 2.0 * R;
    if (SAMRAI_MPI::getRank() == 0)
    {
        drag_stream << loop_time << " " << -F_integral[0] / (0.5 * rho * U_max * U_max * D) << endl;
        lift_stream << loop_time << " " << -F_integral[1] / (0.5 * rho * U_max * U_max * D) << endl;
    }
    return;
} // postprocess_data