template <int dim>
class RightHandSide : public Function<dim>
{
public:
RightHandSide () : Function<dim>(dim+1) {}
virtual void vector_value (const Point<dim> &p,
Vector<double> &value) const;
};
template <int dim>
void
RightHandSide<dim>::vector_value (const Point<dim> &p,
Vector<double> &values) const
{
values(0) = pow(p[0],2);
values(1) = pow(p[1],2);
values(2) = 0.0;
}
for (; cell!=endc; ++cell)
{
fe_values.reinit (cell);
local_matrix = 0;
local_rhs = 0;
right_hand_side.vector_value_list(fe_values.get_quadrature_points(),
rhs_values);
for (unsigned int q=0; q<n_q_points; ++q)
{
for (unsigned int k=0; k<dofs_per_cell; ++k)
{
phi_grads_u[k] = fe_values[velocities].symmetric_gradient (k, q);
div_phi_u[k] = fe_values[velocities].divergence (k, q);
phi_p[k] = fe_values[pressure].value (k, q);
}
for (unsigned int i=0; i<dofs_per_cell; ++i)
{
for (unsigned int j=0; j<=i; ++j)
{
local_matrix(i,j) += (phi_grads_u[i] * phi_grads_u[j]
- div_phi_u[i] * phi_p[j]
- phi_p[i] * div_phi_u[j]
+ phi_p[i] * phi_p[j])
* fe_values.JxW(q);
}
const unsigned int component_i =
fe.system_to_component_index(i).first;
local_rhs(i) += fe_values.shape_value(i,q) *
rhs_values[q](component_i) *
fe_values.JxW(q);
}
}
My 'f' is not '0' any more but it has multiple components.
[...]
My governing equation is same with that of step-22, stokes flow-nabla^2 u + grad p = f-grad u = 0but I want to impose 'f',To do this, I made function that gives me f value on each point.For example, if I want function of f thats looks like f=(x^2,y^2);I would make function like this...
[...]
After that I may consider this 'f' term when I assemble system.but I don't see a way to how I should try modify following read lines of the code from step-22
[...]
const unsigned int component_i = fe.system_to_component_index(i).first;
local_rhs(i) += fe_values.shape_value(i,q) * rhs_values[q](component_i) * fe_values.JxW(q);
[...]
My 'f' is not '0' any more but it has multiple components.
in fact, the weak form of the governing equation '-nabla^2 u + grad p = f ' also should have two components,..(x and y) ....
template <int dim>
void
RightHandSide<dim>::vector_value (const Point<dim> &p,
Vector<double> &values) const
{
values(0) = pow(p[0],2);
values(1) = pow(p[1],2);
values(2) = 0.0; // I assumed this always zero. because f is 2 dimensional force, and we will not have third component of f.
}
const unsigned int component_i =
fe.system_to_component_index(i).first; <- Here I only said the first component...
local_rhs(i) += fe_values.shape_value(i,q) *
rhs_values[q](component_i) *
fe_values.JxW(q);
Shouldn't this be some thing like this?
const unsigned int component_i =
fe.system_to_component_index(i).first;
const unsigned int component_j =
fe.system_to_component_index(j).second;
local_rhs(i) += (fe_values.shape_value(i,q) *rhs_values[q](component_i))
(fe_values.shape_value(i,q) *rhs_values[q](component_j))
I just wanted to make sure that whether I implemented it right,but I still cannot sure whether I am doing correctly..... Let me be with more specific questions.