当前位置: 首页>>代码示例>>C++>>正文


C++ AssemblyContext::interior_gradient方法代码示例

本文整理汇总了C++中AssemblyContext::interior_gradient方法的典型用法代码示例。如果您正苦于以下问题:C++ AssemblyContext::interior_gradient方法的具体用法?C++ AssemblyContext::interior_gradient怎么用?C++ AssemblyContext::interior_gradient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AssemblyContext的用法示例。


在下文中一共展示了AssemblyContext::interior_gradient方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

  void LowMachNavierStokes<Mu,SH,TC>::assemble_thermo_press_elem_time_deriv( bool /*compute_jacobian*/,
									     AssemblyContext& context )
  {
    // Element Jacobian * quadrature weights for interior integration
    const std::vector<libMesh::Real> &JxW = 
      context.get_element_fe(this->_T_var)->get_JxW();

    // The number of local degrees of freedom in each variable
    const unsigned int n_p0_dofs = context.get_dof_indices(this->_p0_var).size();

    // The subvectors and submatrices we need to fill:
    libMesh::DenseSubVector<libMesh::Real> &F_p0 = context.get_elem_residual(this->_p0_var);

    unsigned int n_qpoints = context.get_element_qrule().n_points();

    for (unsigned int qp = 0; qp != n_qpoints; ++qp)
      {
	libMesh::Number T;
	T = context.interior_value(this->_T_var, qp);

	libMesh::Gradient grad_u, grad_v, grad_w;
	grad_u = context.interior_gradient(this->_u_var, qp);
	grad_v = context.interior_gradient(this->_v_var, qp);
	if (this->_dim == 3)
	  grad_w = context.interior_gradient(this->_w_var, qp);

	libMesh::Number divU = grad_u(0) + grad_v(1);
	if(this->_dim==3)
	  divU += grad_w(2);

	//libMesh::Number cp = this->_cp(T);
	//libMesh::Number cv = cp + this->_R;
	//libMesh::Number gamma = cp/cv;
	//libMesh::Number gamma_ratio = gamma/(gamma-1.0);

	libMesh::Number p0 = context.interior_value( this->_p0_var, qp );

	for (unsigned int i = 0; i != n_p0_dofs; ++i)
	  {
	    F_p0(i) += (p0/T - this->_p0/this->_T0)*JxW[qp];
	    //F_p0(i) -= p0*gamma_ratio*divU*JxW[qp];
	  } // End DoF loop i
      }

    return;
  }
开发者ID:SylvainPlessis,项目名称:grins,代码行数:46,代码来源:low_mach_navier_stokes.C

示例2: U

void LowMachNavierStokesSPGSMStabilization<Mu,SH,TC>::assemble_energy_time_deriv( bool /*compute_jacobian*/,
        AssemblyContext& context )
{
    // The number of local degrees of freedom in each variable.
    const unsigned int n_T_dofs = context.get_dof_indices(this->_temp_vars.T()).size();

    // Element Jacobian * quadrature weights for interior integration.
    const std::vector<libMesh::Real> &JxW =
        context.get_element_fe(this->_temp_vars.T())->get_JxW();

    // The temperature shape functions gradients at interior quadrature points.
    const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi =
        context.get_element_fe(this->_temp_vars.T())->get_dphi();

    libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(this->_temp_vars.T()); // R_{T}

    unsigned int n_qpoints = context.get_element_qrule().n_points();

    for (unsigned int qp=0; qp != n_qpoints; qp++)
    {
        libMesh::Number u, v;
        u = context.interior_value(this->_flow_vars.u(), qp);
        v = context.interior_value(this->_flow_vars.v(), qp);

        libMesh::Gradient grad_T = context.interior_gradient(this->_temp_vars.T(), qp);

        libMesh::NumberVectorValue U(u,v);
        if (this->mesh_dim(context) == 3)
            U(2) = context.interior_value(this->_flow_vars.w(), qp); // w

        libMesh::Real T = context.interior_value( this->_temp_vars.T(), qp );
        libMesh::Real rho = this->rho( T, this->get_p0_steady( context, qp ) );

        libMesh::Real k = this->_k(T);
        libMesh::Real cp = this->_cp(T);

        libMesh::Number rho_cp = rho*this->_cp(T);

        libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());

        libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
        libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );

        libMesh::Real tau_E = this->_stab_helper.compute_tau_energy( context, qp, g, G, rho, U, k, cp, this->_is_steady );

        libMesh::Real RE_s = this->compute_res_energy_steady( context, qp );

        for (unsigned int i=0; i != n_T_dofs; i++)
        {
            FT(i) -= rho_cp*tau_E*RE_s*U*T_gradphi[i][qp]*JxW[qp];
        }

    }

    return;
}
开发者ID:nicholasmalaya,项目名称:grins,代码行数:56,代码来源:low_mach_navier_stokes_spgsm_stab.C

示例3: U

  void AxisymmetricHeatTransfer<Conductivity>::element_time_derivative( bool compute_jacobian,
									AssemblyContext& context,
									CachedValues& /*cache*/ )
  {
#ifdef GRINS_USE_GRVY_TIMERS
    this->_timer->BeginTimer("AxisymmetricHeatTransfer::element_time_derivative");
#endif

    // The number of local degrees of freedom in each variable.
    const unsigned int n_T_dofs = context.get_dof_indices(_T_var).size();
    const unsigned int n_u_dofs = context.get_dof_indices(_u_r_var).size();

    //TODO: check n_T_dofs is same as n_u_dofs, n_v_dofs, n_w_dofs

    // We get some references to cell-specific data that
    // will be used to assemble the linear system.

    // Element Jacobian * quadrature weights for interior integration.
    const std::vector<libMesh::Real> &JxW =
      context.get_element_fe(_T_var)->get_JxW();

    // The temperature shape functions at interior quadrature points.
    const std::vector<std::vector<libMesh::Real> >& T_phi =
      context.get_element_fe(_T_var)->get_phi();

    // The velocity shape functions at interior quadrature points.
    const std::vector<std::vector<libMesh::Real> >& vel_phi =
      context.get_element_fe(_u_r_var)->get_phi();

    // The temperature shape function gradients (in global coords.)
    // at interior quadrature points.
    const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi =
      context.get_element_fe(_T_var)->get_dphi();

    // Physical location of the quadrature points
    const std::vector<libMesh::Point>& u_qpoint =
      context.get_element_fe(_u_r_var)->get_xyz();

    // The subvectors and submatrices we need to fill:
    libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(_T_var); // R_{T}

    libMesh::DenseSubMatrix<libMesh::Number> &KTT = context.get_elem_jacobian(_T_var, _T_var); // R_{T},{T}

    libMesh::DenseSubMatrix<libMesh::Number> &KTr = context.get_elem_jacobian(_T_var, _u_r_var); // R_{T},{r}
    libMesh::DenseSubMatrix<libMesh::Number> &KTz = context.get_elem_jacobian(_T_var, _u_z_var); // R_{T},{z}


    // Now we will build the element Jacobian and residual.
    // Constructing the residual requires the solution and its
    // gradient from the previous timestep.  This must be
    // calculated at each quadrature point by summing the
    // solution degree-of-freedom values by the appropriate
    // weight functions.
    unsigned int n_qpoints = context.get_element_qrule().n_points();

    for (unsigned int qp=0; qp != n_qpoints; qp++)
      {
	const libMesh::Number r = u_qpoint[qp](0);
      
	// Compute the solution & its gradient at the old Newton iterate.
	libMesh::Number u_r, u_z;
	u_r = context.interior_value(_u_r_var, qp);
	u_z = context.interior_value(_u_z_var, qp);

	libMesh::Gradient grad_T;
	grad_T = context.interior_gradient(_T_var, qp);

	libMesh::NumberVectorValue U (u_r,u_z);

	libMesh::Number k = this->_k( context, qp );

        // FIXME - once we have T-dependent k, we'll need its
        // derivatives in Jacobians
	// libMesh::Number dk_dT = this->_k.deriv( T );

	// First, an i-loop over the  degrees of freedom.
	for (unsigned int i=0; i != n_T_dofs; i++)
	  {
	    FT(i) += JxW[qp]*r*
	      (-_rho*_Cp*T_phi[i][qp]*(U*grad_T)    // convection term
	       -k*(T_gradphi[i][qp]*grad_T) );  // diffusion term

	    if (compute_jacobian)
	      {
		libmesh_assert (context.get_elem_solution_derivative() == 1.0);

		for (unsigned int j=0; j != n_T_dofs; j++)
		  {
		    // TODO: precompute some terms like:
		    //   _rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*T_grad_phi[j][qp])

		    KTT(i,j) += JxW[qp] * context.get_elem_solution_derivative() *r*
		      (-_rho*_Cp*T_phi[i][qp]*(U*T_gradphi[j][qp])  // convection term
		       -k*(T_gradphi[i][qp]*T_gradphi[j][qp])); // diffusion term
		  } // end of the inner dof (j) loop

#if 0
		if( dk_dT != 0.0 )
		{
		  for (unsigned int j=0; j != n_T_dofs; j++)
//.........这里部分代码省略.........
开发者ID:vikramvgarg,项目名称:grins,代码行数:101,代码来源:axisym_heat_transfer.C

示例4: U

  void SpalartAllmarasSPGSMStabilization<Mu>::element_time_derivative
  ( bool compute_jacobian,
    AssemblyContext & context )
  {
    // Get a pointer to the current element, we need this for computing the distance to wall for the
    // quadrature points
    libMesh::Elem &elem_pointer = context.get_elem();

    // The number of local degrees of freedom in each variable.
    const unsigned int n_nu_dofs = context.get_dof_indices(this->_turbulence_vars.nu()).size();

    // Element Jacobian * quadrature weights for interior integration.
    const std::vector<libMesh::Real> &JxW =
      context.get_element_fe(this->_turbulence_vars.nu())->get_JxW();

    // The viscosity shape function gradients (in global coords.)
    // at interior quadrature points.
    const std::vector<std::vector<libMesh::RealGradient> >& nu_gradphi =
      context.get_element_fe(this->_turbulence_vars.nu())->get_dphi();

    // Quadrature point locations
    //const std::vector<libMesh::Point>& nu_qpoint =
    //context.get_element_fe(this->_turbulence_vars.nu())->get_xyz();

    //libMesh::DenseSubMatrix<libMesh::Number> &Knunu = context.get_elem_jacobian(this->_turbulence_vars.nu(), this->_turbulence_vars.nu()); // R_{nu},{nu}

    libMesh::DenseSubVector<libMesh::Number> &Fnu = context.get_elem_residual(this->_turbulence_vars.nu()); // R_{nu}

    libMesh::FEBase* fe = context.get_element_fe(this->_turbulence_vars.nu());

    unsigned int n_qpoints = context.get_element_qrule().n_points();

    // Auto pointer to distance fcn evaluated at quad points
    std::unique_ptr< libMesh::DenseVector<libMesh::Real> > distance_qp;

    // Fill the vector of distances to quadrature points
    distance_qp = this->distance_function->interpolate(&elem_pointer, context.get_element_qrule().get_points());

    for (unsigned int qp=0; qp != n_qpoints; qp++)
      {
        libMesh::Gradient grad_nu;
        grad_nu = context.interior_gradient(this->_turbulence_vars.nu(), qp);

        libMesh::Real jac = JxW[qp];

        // The physical viscosity
        libMesh::Real _mu_qp = this->_mu(context, qp);

        // To be fixed
        // For the channel flow we will just set the distance function analytically
        //(*distance_qp)(qp) = std::min(fabs(y),fabs(1 - y));

        // The flow velocity
        libMesh::Number u,v;
        u = context.interior_value(this->_flow_vars.u(), qp);
        v = context.interior_value(this->_flow_vars.v(), qp);

        libMesh::NumberVectorValue U(u,v);
        if (this->_flow_vars.dim() == 3)
          U(2) = context.interior_value(this->_flow_vars.w(), qp);

        // Stabilization terms

        libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
        libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );

        libMesh::Real tau_spalart = this->_stab_helper.compute_tau_spalart( context, qp, g, G, this->_rho, U, _mu_qp, this->_is_steady );

        libMesh::Number RM_spalart = this->_stab_helper.compute_res_spalart_steady( context, qp, this->_rho, _mu_qp, (*distance_qp)(qp), this->_infinite_distance );

        for (unsigned int i=0; i != n_nu_dofs; i++)
          {
            Fnu(i) += jac*( -tau_spalart*RM_spalart*this->_rho*(U*nu_gradphi[i][qp]) );
          }

        if( compute_jacobian )
          {
            libmesh_not_implemented();
          }

      }
  }
开发者ID:tradowsk,项目名称:grins,代码行数:82,代码来源:spalart_allmaras_spgsm_stab.C

示例5: U

  void ReactingLowMachNavierStokesStabilizationBase<Mixture,Evaluator>::compute_res_steady( AssemblyContext& context,
                                                                                            unsigned int qp,
                                                                                            libMesh::Real& RP_s,
                                                                                            libMesh::RealGradient& RM_s,
                                                                                            libMesh::Real& RE_s,
                                                                                            std::vector<libMesh::Real>& Rs_s )
  {
    Rs_s.resize(this->n_species(),0.0);

    // Grab r-coordinate for axisymmetric terms
    // We're assuming all variables are using the same quadrature rule
    libMesh::Real r = (context.get_element_fe(this->_flow_vars.u())->get_xyz())[qp](0);

    libMesh::RealGradient grad_p = context.interior_gradient(this->_press_var.p(), qp);

    libMesh::RealGradient grad_u = context.interior_gradient(this->_flow_vars.u(), qp);
    libMesh::RealGradient grad_v = context.interior_gradient(this->_flow_vars.v(), qp);

    libMesh::RealGradient U( context.interior_value(this->_flow_vars.u(), qp),
                             context.interior_value(this->_flow_vars.v(), qp) );
    libMesh::Real divU = grad_u(0) + grad_v(1);

    if( this->_is_axisymmetric )
      divU += U(0)/r;

    if(this->mesh_dim(context) == 3)
      {
        U(2) = context.interior_value(this->_flow_vars.w(), qp);
        divU += (context.interior_gradient(this->_flow_vars.w(), qp))(2);
      }

    // We don't add axisymmetric terms here since we don't directly use hess_{u,v}
    // axisymmetric terms are built into divGradU, etc. functions below
    libMesh::RealTensor hess_u = context.interior_hessian(this->_flow_vars.u(), qp);
    libMesh::RealTensor hess_v = context.interior_hessian(this->_flow_vars.v(), qp);

    libMesh::Real T = context.interior_value(this->_temp_vars.T(), qp);

    libMesh::Gradient grad_T = context.interior_gradient(this->_temp_vars.T(), qp);
    libMesh::Tensor hess_T = context.interior_hessian(this->_temp_vars.T(), qp);

    libMesh::Real hess_T_term = hess_T(0,0) + hess_T(1,1);
#if LIBMESH_DIM > 2
    hess_T_term += hess_T(2,2);
#endif
    // Add axisymmetric terms, if needed
    if( this->_is_axisymmetric )
      hess_T_term += grad_T(0)/r;

    std::vector<libMesh::Real> ws(this->n_species());
    std::vector<libMesh::RealGradient> grad_ws(this->n_species());
    std::vector<libMesh::RealTensor> hess_ws(this->n_species());
    for(unsigned int s=0; s < this->_n_species; s++ )
      {
        ws[s] = context.interior_value(this->_species_vars.species(s), qp);
        grad_ws[s] = context.interior_gradient(this->_species_vars.species(s), qp);
        hess_ws[s] = context.interior_hessian(this->_species_vars.species(s), qp);
      }

    Evaluator gas_evaluator( this->_gas_mixture );
    const libMesh::Real R_mix = gas_evaluator.R_mix(ws);
    const libMesh::Real p0 = this->get_p0_steady(context,qp);
    libMesh::Real rho = this->rho(T, p0, R_mix );
    libMesh::Real cp = gas_evaluator.cp(T,p0,ws);
    libMesh::Real M = gas_evaluator.M_mix( ws );

    std::vector<libMesh::Real> D( this->n_species() );
    libMesh::Real mu, k;

    gas_evaluator.mu_and_k_and_D( T, rho, cp, ws, mu, k, D );


    // grad_rho = drho_dT*gradT + \sum_s drho_dws*grad_ws
    const libMesh::Real drho_dT = -p0/(R_mix*T*T);
    libMesh::RealGradient grad_rho = drho_dT*grad_T;
    for(unsigned int s=0; s < this->_n_species; s++ )
      {
        libMesh::Real Ms = gas_evaluator.M(s);
        libMesh::Real R_uni = Constants::R_universal/1000.0; /* J/kmol-K --> J/mol-K */

        // drho_dws = -p0/(T*R_mix*R_mix)*dR_dws
        // dR_dws = R_uni*d_dws(1/M)
        // d_dws(1/M) = d_dws(\sum_s w_s/Ms) =  1/Ms
        const libMesh::Real drho_dws = -p0/(R_mix*R_mix*T)*R_uni/Ms;
        grad_rho += drho_dws*grad_ws[s];
      }

    libMesh::RealGradient rhoUdotGradU;
    libMesh::RealGradient divGradU;
    libMesh::RealGradient divGradUT;
    libMesh::RealGradient divdivU;

    if( this->mesh_dim(context) < 3 )
      {
        rhoUdotGradU = rho*_stab_helper.UdotGradU( U, grad_u, grad_v );

        // Call axisymmetric versions if we are doing an axisymmetric run
        if( this->_is_axisymmetric )
          {
            divGradU  = _stab_helper.div_GradU_axi( r, U, grad_u, grad_v, hess_u, hess_v );
//.........这里部分代码省略.........
开发者ID:coreymbryant,项目名称:grins,代码行数:101,代码来源:reacting_low_mach_navier_stokes_stab_base.C

示例6: element_time_derivative

  void HeatTransfer::element_time_derivative( bool compute_jacobian,
					      AssemblyContext& context,
					      CachedValues& /*cache*/ )
  {
#ifdef GRINS_USE_GRVY_TIMERS
    this->_timer->BeginTimer("HeatTransfer::element_time_derivative");
#endif

    // The number of local degrees of freedom in each variable.
    const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size();
    const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u_var()).size();

    //TODO: check n_T_dofs is same as n_u_dofs, n_v_dofs, n_w_dofs

    // We get some references to cell-specific data that
    // will be used to assemble the linear system.

    // Element Jacobian * quadrature weights for interior integration.
    const std::vector<libMesh::Real> &JxW =
      context.get_element_fe(_temp_vars.T_var())->get_JxW();

    // The temperature shape functions at interior quadrature points.
    const std::vector<std::vector<libMesh::Real> >& T_phi =
      context.get_element_fe(_temp_vars.T_var())->get_phi();

    // The velocity shape functions at interior quadrature points.
    const std::vector<std::vector<libMesh::Real> >& vel_phi =
      context.get_element_fe(_flow_vars.u_var())->get_phi();

    // The temperature shape function gradients (in global coords.)
    // at interior quadrature points.
    const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi =
      context.get_element_fe(_temp_vars.T_var())->get_dphi();

    const std::vector<libMesh::Point>& u_qpoint = 
      context.get_element_fe(this->_flow_vars.u_var())->get_xyz();

    libMesh::DenseSubMatrix<libMesh::Number> &KTT = context.get_elem_jacobian(_temp_vars.T_var(), _temp_vars.T_var()); // R_{T},{T}

    libMesh::DenseSubMatrix<libMesh::Number> &KTu = context.get_elem_jacobian(_temp_vars.T_var(), _flow_vars.u_var()); // R_{T},{u}
    libMesh::DenseSubMatrix<libMesh::Number> &KTv = context.get_elem_jacobian(_temp_vars.T_var(), _flow_vars.v_var()); // R_{T},{v}
    libMesh::DenseSubMatrix<libMesh::Number>* KTw = NULL;

    libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(_temp_vars.T_var()); // R_{T}

    if( this->_dim == 3 )
      {
        KTw = &context.get_elem_jacobian(_temp_vars.T_var(), _flow_vars.w_var()); // R_{T},{w}
      }

    // Now we will build the element Jacobian and residual.
    // Constructing the residual requires the solution and its
    // gradient from the previous timestep.  This must be
    // calculated at each quadrature point by summing the
    // solution degree-of-freedom values by the appropriate
    // weight functions.
    unsigned int n_qpoints = context.get_element_qrule().n_points();

    for (unsigned int qp=0; qp != n_qpoints; qp++)
      {
	// Compute the solution & its gradient at the old Newton iterate.
	libMesh::Number u, v;
	u = context.interior_value(_flow_vars.u_var(), qp);
	v = context.interior_value(_flow_vars.v_var(), qp);

	libMesh::Gradient grad_T;
	grad_T = context.interior_gradient(_temp_vars.T_var(), qp);

	libMesh::NumberVectorValue U (u,v);
	if (_dim == 3)
	  U(2) = context.interior_value(_flow_vars.w_var(), qp);

        const libMesh::Number r = u_qpoint[qp](0);

        libMesh::Real jac = JxW[qp];

        if( _is_axisymmetric )
          {
            jac *= r;
          }

	// First, an i-loop over the  degrees of freedom.
	for (unsigned int i=0; i != n_T_dofs; i++)
	  {
	    FT(i) += jac *
	      (-_rho*_Cp*T_phi[i][qp]*(U*grad_T)    // convection term
	       -_k*(T_gradphi[i][qp]*grad_T) );  // diffusion term

	    if (compute_jacobian)
	      {
		for (unsigned int j=0; j != n_T_dofs; j++)
		  {
		    // TODO: precompute some terms like:
		    //   _rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*T_grad_phi[j][qp])

		    KTT(i,j) += jac *
		      (-_rho*_Cp*T_phi[i][qp]*(U*T_gradphi[j][qp])  // convection term
		       -_k*(T_gradphi[i][qp]*T_gradphi[j][qp])); // diffusion term
		  } // end of the inner dof (j) loop

//.........这里部分代码省略.........
开发者ID:SylvainPlessis,项目名称:grins,代码行数:101,代码来源:heat_transfer.C

示例7: element_time_derivative

	void PracticeCDRinv::element_time_derivative( bool compute_jacobian,
						AssemblyContext& context,
						CachedValues& /*cache*/ ){
	
		// The number of local degrees of freedom in each variable.
    const unsigned int n_c_dofs = context.get_dof_indices(_c_var).size();

    // We get some references to cell-specific data that
    // will be used to assemble the linear system.

    // Element Jacobian * quadrature weights for interior integration.
    const std::vector<libMesh::Real> &JxW =
      context.get_element_fe(_c_var)->get_JxW();

    // The temperature shape function gradients (in global coords.)
    // at interior quadrature points.
    const std::vector<std::vector<libMesh::RealGradient> >& dphi =
      context.get_element_fe(_c_var)->get_dphi();
    const std::vector<std::vector<libMesh::Real> >& phi = context.get_element_fe(_c_var)->get_phi();

    const std::vector<libMesh::Point>& q_points = 
      context.get_element_fe(_c_var)->get_xyz();
    
  	libMesh::DenseSubMatrix<libMesh::Number> &J_c_zc = context.get_elem_jacobian(_c_var, _zc_var);
		libMesh::DenseSubMatrix<libMesh::Number> &J_c_c = context.get_elem_jacobian(_c_var, _c_var);
	
		libMesh::DenseSubMatrix<libMesh::Number> &J_zc_c = context.get_elem_jacobian(_zc_var, _c_var);
		libMesh::DenseSubMatrix<libMesh::Number> &J_zc_fc = context.get_elem_jacobian(_zc_var, _fc_var);
	
		libMesh::DenseSubMatrix<libMesh::Number> &J_fc_zc = context.get_elem_jacobian(_fc_var, _zc_var);
		libMesh::DenseSubMatrix<libMesh::Number> &J_fc_fc = context.get_elem_jacobian(_fc_var, _fc_var);
		
		libMesh::DenseSubVector<libMesh::Number> &Rc = context.get_elem_residual( _c_var );;
		libMesh::DenseSubVector<libMesh::Number> &Rzc = context.get_elem_residual( _zc_var );
		libMesh::DenseSubVector<libMesh::Number> &Rfc = context.get_elem_residual( _fc_var );

    // Now we will build the element Jacobian and residual.
    // Constructing the residual requires the solution and its
    // gradient from the previous timestep.  This must be
    // calculated at each quadrature point by summing the
    // solution degree-of-freedom values by the appropriate
    // weight functions.
    unsigned int n_qpoints = context.get_element_qrule().n_points();

    for (unsigned int qp=0; qp != n_qpoints; qp++){

			libMesh::Number 
	      c = context.interior_value(_c_var, qp),
	      zc = context.interior_value(_zc_var, qp),
	      fc = context.interior_value(_fc_var, qp);
	    libMesh::Gradient 
	      grad_c = context.interior_gradient(_c_var, qp),
	      grad_zc = context.interior_gradient(_zc_var, qp),
	      grad_fc = context.interior_gradient(_fc_var, qp);
			
	  	//location of quadrature point
	  	const libMesh::Real ptx = q_points[qp](0);
	  	const libMesh::Real pty = q_points[qp](1);
			
   		int xind, yind;
   		libMesh::Real xdist = 1.e10; libMesh::Real ydist = 1.e10;
   		for(int ii=0; ii<x_pts.size(); ii++){
   			libMesh::Real tmp = std::abs(ptx - x_pts[ii]);
   			if(xdist > tmp){
   				xdist = tmp;
   				xind = ii;
   			}
   			else
   				break;
   		} 
   		for(int jj=0; jj<y_pts[xind].size(); jj++){
   			libMesh::Real tmp = std::abs(pty - y_pts[xind][jj]);
   			if(ydist > tmp){
   				ydist = tmp;
   				yind = jj;
   			}
   			else
   				break;
   		}
   		libMesh::Real u = vel_field[xind][yind](0);
   		libMesh::Real v = vel_field[xind][yind](1);

	    libMesh::NumberVectorValue U     (u,     v);

	
			// First, an i-loop over the  degrees of freedom.
			for (unsigned int i=0; i != n_c_dofs; i++){
				
				Rc(i) += JxW[qp]*(-_k*grad_zc*dphi[i][qp] + U*grad_zc*phi[i][qp] + 2*_R*zc*c*phi[i][qp]);
	      Rzc(i) += JxW[qp]*(-_k*grad_c*dphi[i][qp] - U*grad_c*phi[i][qp] + _R*c*c*phi[i][qp] + fc*phi[i][qp]);
     		Rfc(i) += JxW[qp]*(_beta*grad_fc*dphi[i][qp] + zc*phi[i][qp]);

				if (compute_jacobian){
					for (unsigned int j=0; j != n_c_dofs; j++){
						J_c_zc(i,j) += JxW[qp]*(-_k*dphi[j][qp]*dphi[i][qp] + U*dphi[j][qp]*phi[i][qp] 
															+ 2*_R*phi[j][qp]*c*phi[i][qp]);
						J_c_c(i,j) += JxW[qp]*(2*_R*zc*phi[j][qp]*phi[i][qp]);

						J_zc_c(i,j) += JxW[qp]*(-_k*dphi[j][qp]*dphi[i][qp] - U*dphi[j][qp]*phi[i][qp] 
																+ 2*_R*c*phi[j][qp]*phi[i][qp]);
//.........这里部分代码省略.........
开发者ID:kameeko,项目名称:harriet_libmesh,代码行数:101,代码来源:practice_cdr_inv.C

示例8: FT

  void HeatConduction<K>::element_time_derivative( bool compute_jacobian,
						AssemblyContext& context,
						CachedValues& /*cache*/ )
  {
    // The number of local degrees of freedom in each variable.
    const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size();

    // We get some references to cell-specific data that
    // will be used to assemble the linear system.

    // Element Jacobian * quadrature weights for interior integration.
    const std::vector<libMesh::Real> &JxW =
      context.get_element_fe(_temp_vars.T_var())->get_JxW();

    // The temperature shape function gradients (in global coords.)
    // at interior quadrature points.
    const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi =
      context.get_element_fe(_temp_vars.T_var())->get_dphi();

    // The subvectors and submatrices we need to fill:
    //
    // K_{\alpha \beta} = R_{\alpha},{\beta} = \partial{ R_{\alpha} } / \partial{ {\beta} } (where R denotes residual)
    // e.g., for \alpha = T and \beta = v we get: K_{Tu} = R_{T},{u}
    //

    libMesh::DenseSubMatrix<libMesh::Number> &KTT = context.get_elem_jacobian(_temp_vars.T_var(), _temp_vars.T_var()); // R_{T},{T}

    libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(_temp_vars.T_var()); // R_{T}

    // Now we will build the element Jacobian and residual.
    // Constructing the residual requires the solution and its
    // gradient from the previous timestep.  This must be
    // calculated at each quadrature point by summing the
    // solution degree-of-freedom values by the appropriate
    // weight functions.
    unsigned int n_qpoints = context.get_element_qrule().n_points();

    for (unsigned int qp=0; qp != n_qpoints; qp++)
      {
	// Compute the solution & its gradient at the old Newton iterate.
	libMesh::Gradient grad_T;
	grad_T = context.interior_gradient(_temp_vars.T_var(), qp);

	// Compute the conductivity at this qp
	libMesh::Real _k_qp = this->_k(context, qp);
	
	// First, an i-loop over the  degrees of freedom.
	for (unsigned int i=0; i != n_T_dofs; i++)
	  {
	    FT(i) += JxW[qp]*(-_k_qp*(T_gradphi[i][qp]*grad_T));

	    if (compute_jacobian)
	      {
		for (unsigned int j=0; j != n_T_dofs; j++)
		  {
		    // TODO: precompute some terms like:
		    //   _rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*T_grad_phi[j][qp])

		    KTT(i,j) += JxW[qp] * context.get_elem_solution_derivative() *
		      ( -_k_qp*(T_gradphi[i][qp]*T_gradphi[j][qp]) ); // diffusion term
		  } // end of the inner dof (j) loop

	      } // end - if (compute_jacobian && context.get_elem_solution_derivative())

	  } // end of the outer dof (i) loop
      } // end of the quadrature point (qp) loop

    return;
  }
开发者ID:jcamata,项目名称:grins,代码行数:69,代码来源:heat_conduction.C


注:本文中的AssemblyContext::interior_gradient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。