Re: [deal.II] modifying of only one component of solution

2018-02-05 Thread Marek Čapek
Hi,
I have Cahn-Hilliard system - scalar equation for
phase field and chemical potential. I tried to modify only
the phase field part of solution in distributed code like 
step-40:

template
> void Main::postprocess_solution(){
>
> nsSystem.computing_timer.enter_subsection("Solution postprocessing");
>
>
>
> std::vector 
> selected_dofs(dofHandlerCrate.dof_handler_phase->n_locally_owned_dofs());
>
>
> //here I choose to modify only the phase-field part of solution
> std::vector component_mask_vec = {true,false};
>
> ComponentMask component_mask(component_mask_vec);
>
> //modified_phase_solution is the nonghosted trilinoswrappers mpi vector
> modified_phase_solution.reinit 
> (dofHandlerCrate.dof_handler_phase->locally_owned_dofs(), MPI_COMM_WORLD);
>
> IndexSet locally_owned 
> =dofHandlerCrate.dof_handler_phase->locally_owned_dofs();
> 
> DoFTools::extract_dofs(*dofHandlerCrate.dof_handler_phase,component_mask,selected_dofs);
>
> for (types::global_dof_index i=0; 
> in_locally_owned_dofs(); ++i){
> int global_index=locally_owned.nth_index_in_set(i);
> double value = globalCrateCurrent.solution_phase_n(global_index);
>
> if(selected_dofs[i]==true){
>
//modify if it is phase field part of solution 
>
 modified_phase_solution(global_index)=truncate_conc(value);
>  }
> else
>
   //else let it be
>
  modified_phase_solution(global_index)=value;
>
> }
>
> modified_phase_solution.compress(VectorOperation::insert);
>
> //globalCrateCurrent.solution_phase_n is ghosted vector of solution
> globalCrateCurrent.solution_phase_n=modified_phase_solution;
>
> nsSystem.computing_timer.leave_subsection("Solution postprocessing");
>
> }
>

However the solution does not get modified. It appears to me, that 
selected_dofs vector
is filled with false values.Maybe I use wrongly the function
DoFTools::extract_dofs for the distributed case.
Could You please provide me guidance, how to use it properly?

Thanks

Marek

Dne pondělí 28. srpna 2017 18:55:30 UTC+2 Wolfgang Bangerth napsal(a):
>
> On 08/27/2017 11:53 AM, Marek Čapek wrote: 
> > 
> > 
> > I am getting the solution in 
> > 
> >PetscWrappers::MPI::Vector solution_phase_n; 
> > 
> > I am interested in modifying the vector of the solution - I 
> > want to cut the undershoots and overshoots in phase-field component 
> > of the solution. Namely I have values of phase field like -1.005 or 
> 1.005, 
> > however they should be only in <-1,1>. 
> > Is it possible to modify only the relevant parts of the 
> > PetscWrappers::MPI::Vector ? 
> > 
> > I want to get  afterwards the solution values and gradients using 
> > 
> > fe_v_phase.get_function_values 
> > fe_v_phase.get_function_gradients 
> > 
> > to get the "repaired" values and gradients of phase field. 
> > 
> > Or should I split the system, ie. firstly solve for the phase 
> > field, then modify the phase field solution and afterwards 
> > solve for chemical potential? 
>
> The easiest solution is probably to use a 
> PETScWrappers::MPI::BlockVector with two blocks that corresponds to the 
> two variables. You would then just apply the operation on one of the 
> blocks. This may require you to also substructure your matrix into 
> blocks, but all of your solvers should continue to work. In particular, 
> just because your matrix is substructured does not imply that you have 
> to solve one equation at the time (though you can). 
>
> The alternative is to figure out which elements of your vector 
> correspond to the phase-field. Namespace DoFTools has functions that 
> give you a mask or IndexSet that indicates which variables belong to one 
> particular vector component. You would then just operate on those vector 
> elements that are listed in the mask/IndexSet. 
>
> Best 
>   W. 
>
>
> -- 
>  
> Wolfgang Bangerth  email: bang...@colostate.edu 
>  
> www: http://www.math.colostate.edu/~bangerth/ 
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [deal.II] modifying of only one component of solution

2017-08-28 Thread Wolfgang Bangerth

On 08/27/2017 11:53 AM, Marek Čapek wrote:



I am getting the solution in

   PetscWrappers::MPI::Vector solution_phase_n;

I am interested in modifying the vector of the solution - I
want to cut the undershoots and overshoots in phase-field component
of the solution. Namely I have values of phase field like -1.005 or 1.005,
however they should be only in <-1,1>.
Is it possible to modify only the relevant parts of the
PetscWrappers::MPI::Vector ?

I want to get  afterwards the solution values and gradients using

fe_v_phase.get_function_values
fe_v_phase.get_function_gradients

to get the "repaired" values and gradients of phase field.

Or should I split the system, ie. firstly solve for the phase
field, then modify the phase field solution and afterwards
solve for chemical potential?


The easiest solution is probably to use a 
PETScWrappers::MPI::BlockVector with two blocks that corresponds to the 
two variables. You would then just apply the operation on one of the 
blocks. This may require you to also substructure your matrix into 
blocks, but all of your solvers should continue to work. In particular, 
just because your matrix is substructured does not imply that you have 
to solve one equation at the time (though you can).


The alternative is to figure out which elements of your vector 
correspond to the phase-field. Namespace DoFTools has functions that 
give you a mask or IndexSet that indicates which variables belong to one 
particular vector component. You would then just operate on those vector 
elements that are listed in the mask/IndexSet.


Best
 W.


--

Wolfgang Bangerth  email: bange...@colostate.edu
   www: http://www.math.colostate.edu/~bangerth/

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[deal.II] modifying of only one component of solution

2017-08-27 Thread Marek Čapek
Hello,
I solve phase-field equation, i.e. Cahn-Hilliard equation.
I have the following finite elements  for the phase field and the chemical 
potential
components of solution

FESystem fe_phase;

in the initialization list of constructor:

fe_phase (FE_Q (degree), 2)

(The first component - phase field, the second one - chemical potential)


I am getting the solution in 

  PetscWrappers::MPI::Vector solution_phase_n;

I am interested in modifying the vector of the solution - I
want to cut the undershoots and overshoots in phase-field component
of the solution. Namely I have values of phase field like -1.005 or 1.005,
however they should be only in <-1,1>.
Is it possible to modify only the relevant parts of the
PetscWrappers::MPI::Vector ?

I want to get  afterwards the solution values and gradients using 

fe_v_phase.get_function_values  
fe_v_phase.get_function_gradients 

to get the "repaired" values and gradients of phase field.

Or should I split the system, ie. firstly solve for the phase
field, then modify the phase field solution and afterwards
solve for chemical potential?

Thank You


Marek


-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.