deal.II version GIT relicensing-6750-g1dc21bc838 2026-09-15 17:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Crystal_Growth_Phase_Field_Model.h
Go to the documentation of this file.
1
117 *  
118 *   #include "PhaseFieldSolver.h"
119 *  
120 *   void InitialValues::vector_value(const Point<2> &/*p*/,
121 *   Vector<double> & values) const
122 *   {
123 *   values(0)= 0.0; //Initial p value of domain
124 *   values(1)= 0.2; //Initial temperature of domain
125 *   }
126 * @endcode
127
128
129<a name="ann-PhaseFieldSolver.cpp"></a>
130<h1>Annotated version of PhaseFieldSolver.cpp</h1>
131 *
132 *
133 *
134 *
135 * @code
136 *   /* -----------------------------------------------------------------------------
137 *   *
138 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
139 *   * Copyright (C) 2024 by Umair Hussain
140 *   *
141 *   * This file is part of the deal.II code gallery.
142 *   *
143 *   * -----------------------------------------------------------------------------
144 *   */
145 *  
146 *   #include "PhaseFieldSolver.h"
147 *  
148 *   PhaseFieldSolver::PhaseFieldSolver()
149 *   : mpi_communicator(MPI_COMM_WORLD)
152 *   , pcout(std::cout, (this_mpi_process == 0))
153 *   , fe(FE_Q<2>(1), 2)
154 *   , dof_handler(triangulation)
155 *   , time(0.0)
156 *   , final_time(1.)
157 *   , time_step(.0002)
158 *   , theta(0.5)
159 *   , epsilon(0.01)
160 *   , tau(0.0003)
161 *   , gamma(10.)
162 *   , latent_heat(1.4)
163 *   , alpha(0.9)
164 *   , t_eq(1.)
165 *   , a(0.01)
166 *   {}
167 * @endcode
168
169
170<a name="ann-PhaseFieldSolver.h"></a>
171<h1>Annotated version of PhaseFieldSolver.h</h1>
172 *
173 *
174 *
175 *
176
177 *
178 *
179 * @code
180 *   /* -----------------------------------------------------------------------------
181 *   *
182 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
183 *   * Copyright (C) 2024 by Umair Hussain
184 *   *
185 *   * This file is part of the deal.II code gallery.
186 *   *
187 *   * -----------------------------------------------------------------------------
188 *   */
189 *  
190 *   #ifndef KOBAYASHI_PARALLEL_PHASEFIELDSOLVER_H
191 *   #define KOBAYASHI_PARALLEL_PHASEFIELDSOLVER_H
192 *  
193 *   #include <deal.II/base/quadrature_lib.h>
194 *   #include <deal.II/base/function.h>
195 *   #include <deal.II/base/utilities.h>
196 *   #include <deal.II/lac/vector.h>
197 *   #include <deal.II/lac/full_matrix.h>
198 *   #include <deal.II/lac/sparse_matrix.h>
199 *   #include <deal.II/lac/sparse_direct.h>
200 *   #include <deal.II/lac/dynamic_sparsity_pattern.h>
201 *   #include <deal.II/lac/solver_cg.h>
202 *   #include <deal.II/lac/precondition.h>
203 *   #include <deal.II/lac/affine_constraints.h>
204 *   #include <deal.II/grid/tria.h>
205 *   #include <deal.II/grid/grid_generator.h>
206 *   #include <deal.II/dofs/dof_handler.h>
207 *   #include <deal.II/dofs/dof_tools.h>
208 *   #include <deal.II/fe/fe_q.h>
209 *   #include <deal.II/fe/fe_values.h>
210 *   #include <deal.II/fe/fe_system.h>
211 *   #include <deal.II/numerics/vector_tools.h>
212 *   #include <deal.II/numerics/matrix_tools.h>
213 *   #include <deal.II/numerics/data_out.h>
214 *   #include <deal.II/grid/grid_in.h>
215 *  
216 * @endcode
217 *
218 * For Parallel Computation
219 *
220 * @code
221 *   #include <deal.II/base/conditional_ostream.h>
222 *   #include <deal.II/base/mpi.h>
223 *   #include <deal.II/lac/petsc_vector.h>
224 *   #include <deal.II/lac/petsc_sparse_matrix.h>
225 *   #include <deal.II/lac/petsc_solver.h>
226 *   #include <deal.II/lac/petsc_precondition.h>
227 *   #include <deal.II/grid/grid_tools.h>
228 *   #include <deal.II/dofs/dof_renumbering.h>
229 *  
230 *   #include <fstream>
231 *   #include <iostream>
232 *  
233 *   using namespace dealii;
234 *  
235 *   class PhaseFieldSolver {
236 *   public:
237 *   PhaseFieldSolver();
238 *   void run();
239 *  
240 *   private:
241 *   void make_grid_and_dofs();
242 *   void assemble_system();
243 *   void solve();
244 *   void output_results(const unsigned int timestep_number) const;
245 *   double compute_residual();
246 *   void applying_bc();
247 *   float get_random_number();
248 *  
249 *   MPI_Comm mpi_communicator;
250 *   const unsigned int n_mpi_processes;
251 *   const unsigned int this_mpi_process;
252 *   ConditionalOStream pcout;
253 *  
254 *   Triangulation<2> triangulation;
255 *   FESystem<2> fe;
256 *   DoFHandler<2> dof_handler;
257 *   GridIn<2> gridin;
258 *  
259 *   PETScWrappers::MPI::SparseMatrix jacobian_matrix;
260 *  
261 *   double time;
262 *   const double final_time, time_step;
263 *   const double theta;
264 *   const double epsilon, tau, gamma, latent_heat, alpha, t_eq, a; //as given in Ref. [1]
265 *  
266 *   PETScWrappers::MPI::Vector conv_solution; //solution vector at last newton-raphson iteration
267 *   PETScWrappers::MPI::Vector old_solution; //solution vector at last time step
268 *   PETScWrappers::MPI::Vector solution_update; //increment in solution or delta solution
269 *   PETScWrappers::MPI::Vector system_rhs; //to store residual
270 *   Vector<double> conv_solution_np, old_solution_np; //creating non parallel vectors to store data for easy access of old solution values by all processes
271 *  
272 *   };
273 *  
274 * @endcode
275 *
276 * Initial values class
277 *
278 * @code
279 *   class InitialValues : public Function<2>
280 *   {
281 *   public:
282 *   InitialValues(): Function<2>(2)
283 *   {}
284 *   virtual void vector_value(const Point<2> &p,
285 *   Vector<double> & value) const override;
286 *   };
287 *  
288 *  
289 *   #endif //KOBAYASHI_PARALLEL_PHASEFIELDSOLVER_H
290 * @endcode
291
292
293<a name="ann-applying_bc.cpp"></a>
294<h1>Annotated version of applying_bc.cpp</h1>
295 *
296 *
297 *
298 *
299
300 *
301 *
302 * @code
303 *   /* -----------------------------------------------------------------------------
304 *   *
305 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
306 *   * Copyright (C) 2024 by Umair Hussain
307 *   *
308 *   * This file is part of the deal.II code gallery.
309 *   *
310 *   * -----------------------------------------------------------------------------
311 *   */
312 *  
313 *   #include "PhaseFieldSolver.h"
314 *  
315 *   void PhaseFieldSolver::applying_bc(){
316 *   FEValuesExtractors::Scalar phase_parameter(0);
318 *  
319 *   QGauss<2> quadrature_formula(fe.degree + 1);
320 *   FEValues<2> fe_values(fe,
321 *   quadrature_formula,
323 *  
324 *   ComponentMask p_mask = fe.component_mask(phase_parameter);
325 *   ComponentMask t_mask = fe.component_mask(temperature);
326 *  
327 *   std::map<types::global_dof_index,double> boundary_values;
328 *  
329 * @endcode
330 *
331 * Prescribing p=1 at the left face (this will be maintained in the subsequent iterations when zero BC is applied in the Newton-Raphson iterations)
332 *
333 * @code
335 *   1,
337 *   boundary_values,p_mask);
338 *  
339 * @endcode
340 *
341 * To apply the boundary values only to the solution vector without the Jacobian Matrix and RHS Vector
342 *
343 * @code
344 *   for (auto &boundary_value : boundary_values)
345 *   old_solution(boundary_value.first) = boundary_value.second;
346 *  
347 *   old_solution.compress(VectorOperation::insert);
348 *  
349 *   }
350 * @endcode
351
352
353<a name="ann-assemble_system.cpp"></a>
354<h1>Annotated version of assemble_system.cpp</h1>
355 *
356 *
357 *
358 *
359 * @code
360 *   /* -----------------------------------------------------------------------------
361 *   *
362 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
363 *   * Copyright (C) 2024 by Umair Hussain
364 *   *
365 *   * This file is part of the deal.II code gallery.
366 *   *
367 *   * -----------------------------------------------------------------------------
368 *   */
369 *  
370 *   #include "PhaseFieldSolver.h"
371 *   #include <cmath>
372 *  
373 *   void PhaseFieldSolver::assemble_system() {
374 * @endcode
375 *
376 * Separating each variable as a scalar to easily call the respective shape functions
377 *
378 * @code
379 *   FEValuesExtractors::Scalar phase_parameter(0);
381 *  
382 *   QGauss<2> quadrature_formula(fe.degree + 1);
383 *   FEValues<2> fe_values(fe,
384 *   quadrature_formula,
386 *  
387 *   const unsigned int dofs_per_cell = fe.n_dofs_per_cell();
388 *   const unsigned int n_q_points = quadrature_formula.size();
389 *   FullMatrix<double> cell_matrix(dofs_per_cell, dofs_per_cell);
390 *  
391 *   Vector<double> cell_rhs(dofs_per_cell);
392 *  
393 * @endcode
394 *
395 * To copy values and gradients of solution from previous iteration
396 * Old Newton iteration
397 *
398 * @code
399 *   std::vector<Tensor<1, 2>> old_newton_solution_gradients_p(n_q_points);
400 *   std::vector<double> old_newton_solution_values_p(n_q_points);
401 *   std::vector<Tensor<1, 2>> old_newton_solution_gradients_t(n_q_points);
402 *   std::vector<double> old_newton_solution_values_t(n_q_points);
403 * @endcode
404 *
405 * Old time step iteration
406 *
407 * @code
408 *   std::vector<Tensor<1, 2>> old_time_solution_gradients_p(n_q_points);
409 *   std::vector<double> old_time_solution_values_p(n_q_points);
410 *   std::vector<Tensor<1, 2>> old_time_solution_gradients_t(n_q_points);
411 *   std::vector<double> old_time_solution_values_t(n_q_points);
412 *  
413 *   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
414 *   jacobian_matrix.operator=(0.0);
415 *   system_rhs.operator=(0.0);
416 *  
417 *   for (const auto &cell : dof_handler.active_cell_iterators()){
418 *   if (cell->subdomain_id() == this_mpi_process) {
419 *   cell_matrix = 0;
420 *   cell_rhs = 0;
421 *  
422 *   fe_values.reinit(cell);
423 *  
424 * @endcode
425 *
426 * Copying old solution values
427 *
428 * @code
429 *   fe_values[phase_parameter].get_function_values(conv_solution_np,old_newton_solution_values_p);
430 *   fe_values[phase_parameter].get_function_gradients(conv_solution_np,old_newton_solution_gradients_p);
431 *   fe_values[temperature].get_function_values(conv_solution_np,old_newton_solution_values_t);
432 *   fe_values[temperature].get_function_gradients(conv_solution_np,old_newton_solution_gradients_t);
433 *   fe_values[phase_parameter].get_function_values(old_solution_np,old_time_solution_values_p);
434 *   fe_values[phase_parameter].get_function_gradients(old_solution_np,old_time_solution_gradients_p);
435 *   fe_values[temperature].get_function_values(old_solution_np,old_time_solution_values_t);
436 *   fe_values[temperature].get_function_gradients(old_solution_np,old_time_solution_gradients_t);
437 *  
438 *   for (unsigned int q = 0; q < n_q_points; ++q){
439 *   double khi = get_random_number();
440 * @endcode
441 *
442 * Old solution values
443 *
444 * @code
445 *   double p_on = old_newton_solution_values_p[q]; //old newton solution
446 *   auto grad_p_on = old_newton_solution_gradients_p[q];
447 *   double p_ot = old_time_solution_values_p[q]; //old time step solution
448 *   auto grad_p_ot = old_time_solution_gradients_p[q];
449 *   double t_on = old_newton_solution_values_t[q];
450 *   auto grad_t_on = old_newton_solution_gradients_t[q];
451 *   double t_ot = old_time_solution_values_t[q];
452 *   auto grad_t_ot = old_time_solution_gradients_t[q];
453 *   for (unsigned int i = 0; i < dofs_per_cell; ++i){
454 * @endcode
455 *
456 * Shape Functions
457 *
458 * @code
459 *   double psi_i = fe_values[phase_parameter].value(i,q);
460 *   auto grad_psi_i = fe_values[phase_parameter].gradient(i,q);
461 *   double phi_i = fe_values[temperature].value(i,q);
462 *   auto grad_phi_i = fe_values[temperature].gradient(i,q);
463 *   for (unsigned int j = 0; j < dofs_per_cell; ++j){
464 * @endcode
465 *
466 * Shape Functions
467 *
468 * @code
469 *   double psi_j = fe_values[phase_parameter].value(j,q);
470 *   auto grad_psi_j = fe_values[phase_parameter].gradient(j,q);
471 *   double phi_j = fe_values[temperature].value(j,q);
472 *   auto grad_phi_j = fe_values[temperature].gradient(j,q);
473 *  
474 *   double mp = psi_i*(tau*psi_j);
475 *   double kp = grad_psi_i*(std::pow(epsilon,2)*grad_psi_j);
476 *   double m = (alpha/M_PI)*std::atan(gamma*(t_eq - t_on));
477 *   double t1 = (1-p_on)*(p_on-0.5+m);
478 *   double t2 = -(p_on)*(p_on-0.5+m);
479 *   double t3 = (p_on)*(1-p_on);
480 *   double nl_p = psi_i*((t1+t2+t3)*psi_j);
481 * @endcode
482 *
483 * Adding random noise at the interface
484 *
485 * @code
486 *   nl_p -= a*khi*psi_i*((1.0 - 2*(p_on))*psi_j);
487 *   double f1_p= mp + time_step*theta*kp - time_step*theta*nl_p; // doh f1 by doh p (first Jacobian terms)
488 *  
489 *   double t4 = (p_on)*(1-p_on)*(-(alpha*gamma/(M_PI*(1+std::pow((gamma*(t_eq-t_on)),2)))));
490 *   double nl_t = psi_i*(t4*phi_j);
491 *   double f1_t = -time_step*theta*nl_t; // doh f1 by doh t (second Jacobian terms)
492 *  
493 *   double mpt = phi_i*(latent_heat*psi_j);
494 *   double f2_p = -mpt; // doh f2 by doh p (third Jacobian terms)
495 *  
496 *   double mt = phi_i*(phi_j);
497 *   double kt = grad_phi_i*(grad_phi_j);
498 *   double f2_t = mt + time_step*theta*kt; // doh f2 by doh t (fourth Jacobian terms)
499 *  
500 * @endcode
501 *
502 * Assembling Jacobian matrix
503 *
504 * @code
505 *   cell_matrix(i,j) += (f1_p + f1_t + f2_p + f2_t)*fe_values.JxW(q);
506 *  
507 *   }
508 * @endcode
509 *
510 * Finding f1 and f2 at previous iteration for rhs vector
511 *
512 * @code
513 *   double mp_n = psi_i*(tau*p_on);
514 *   double kp_n = grad_psi_i*(std::pow(epsilon,2)*grad_p_on);
515 *   double m_n = (alpha/M_PI)*std::atan(gamma*(t_eq-t_on));
516 *   double nl_n = psi_i*((p_on)*(1-p_on)*(p_on-0.5+m_n));
517 *   double mp_t = psi_i*(tau*p_ot);
518 *   double kp_t = grad_psi_i*(tau*grad_p_ot);
519 *   double m_t = (alpha/M_PI)*std::atan(gamma*(t_eq-t_ot));
520 *   double nl_t = psi_i*(p_ot)*(1-p_ot)*(p_ot-0.5+m_t);
521 * @endcode
522 *
523 * Adding random noise at the interface
524 *
525 * @code
526 *   nl_n -= psi_i*(a*khi*(p_on)*(1-p_on));
527 *   nl_t -= psi_i*(a*khi*(p_ot)*(1-p_ot));
528 *  
529 *   double f1n = mp_n + time_step*theta*kp_n - time_step*theta*nl_n - mp_t + time_step*(1-theta)*kp_t - time_step*(1-theta)*nl_t; //f1 at last newton iteration
530 *  
531 *   double mt_n = phi_i*(t_on);
532 *   double kt_n = grad_phi_i*(grad_t_on);
533 *   double mpt_n = phi_i*(latent_heat*p_on);
534 *   double mt_t = phi_i*(t_ot);
535 *   double kt_t = grad_phi_i*(grad_t_ot);
536 *   double mpt_t = phi_i*(latent_heat*p_ot);
537 *  
538 *   double f2n = mt_n + time_step*theta*kt_n - mpt_n - mt_t + time_step*(1-theta)*kt_t + mpt_t; //f2 at last newton iteration
539 *  
540 * @endcode
541 *
542 * Assembling RHS vector
543 *
544 * @code
545 *   cell_rhs(i) -= (f1n + f2n)*fe_values.JxW(q);
546 *   }
547 *   }
548 *  
549 *   cell->get_dof_indices(local_dof_indices);
550 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
551 *   {
552 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
553 *   jacobian_matrix.add(local_dof_indices[i],
554 *   local_dof_indices[j],
555 *   cell_matrix(i, j));
556 *   system_rhs(local_dof_indices[i]) += cell_rhs(i);
557 *   }
558 *   }
559 *   }
560 *  
561 *   jacobian_matrix.compress(VectorOperation::add);
562 *   system_rhs.compress(VectorOperation::add);
563 *  
564 * @endcode
565 *
566 * Applying zero BC
567 *
568 * @code
569 *   std::map<types::global_dof_index, double> boundary_values;
571 *   1,
573 *   boundary_values);
574 *   MatrixTools::apply_boundary_values(boundary_values,
575 *   jacobian_matrix,
576 *   solution_update,
577 *   system_rhs, false);
578 *  
579 *   jacobian_matrix.compress(VectorOperation::insert);
580 *  
581 *   system_rhs.compress(VectorOperation::insert);
582 *   }
583 * @endcode
584
585
586<a name="ann-get_random_number.cpp"></a>
587<h1>Annotated version of get_random_number.cpp</h1>
588 *
589 *
590 *
591 *
592 * @code
593 *   /* -----------------------------------------------------------------------------
594 *   *
595 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
596 *   * Copyright (C) 2024 by Umair Hussain
597 *   *
598 *   * This file is part of the deal.II code gallery.
599 *   *
600 *   * -----------------------------------------------------------------------------
601 *   */
602 *  
603 *   #include "PhaseFieldSolver.h"
604 *   #include <random>
605 *  
606 *   float PhaseFieldSolver::get_random_number()
607 *   {
608 *   static std::default_random_engine e;
609 *   static std::uniform_real_distribution<> dis(-0.5, 0.5); // returns a random number in the range of -0.5 to 0.5
610 *   return dis(e);
611 *   }
612 * @endcode
613
614
615<a name="ann-grid_dof.cpp"></a>
616<h1>Annotated version of grid_dof.cpp</h1>
617 *
618 *
619 *
620 *
621 * @code
622 *   /* -----------------------------------------------------------------------------
623 *   *
624 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
625 *   * Copyright (C) 2024 by Umair Hussain
626 *   *
627 *   * This file is part of the deal.II code gallery.
628 *   *
629 *   * -----------------------------------------------------------------------------
630 *   */
631 *  
632 *   #include "PhaseFieldSolver.h"
633 *  
634 *   void PhaseFieldSolver::make_grid_and_dofs() {
635 * @endcode
636 *
637 * Reading mesh
638 *
639 * @code
640 *   gridin.attach_triangulation(triangulation);
641 *   std::ifstream f("mesh/Kobayashi_mesh100x400.msh");
642 *   gridin.read_msh(f);
643 *  
644 *  
645 *   GridTools::partition_triangulation(n_mpi_processes, triangulation);
646 *   dof_handler.distribute_dofs(fe);
647 *   DoFRenumbering::subdomain_wise(dof_handler);
648 *  
649 *   DynamicSparsityPattern dsp(dof_handler.n_dofs());
650 *   DoFTools::make_sparsity_pattern(dof_handler, dsp);
651 *  
652 *   const std::vector<IndexSet> locally_owned_dofs_per_proc =
654 *   const IndexSet locally_owned_dofs =
655 *   locally_owned_dofs_per_proc[this_mpi_process];
656 *   jacobian_matrix.reinit(locally_owned_dofs,
657 *   locally_owned_dofs,
658 *   dsp,
659 *   mpi_communicator);
660 *   old_solution.reinit(locally_owned_dofs, mpi_communicator);
661 *   system_rhs.reinit(locally_owned_dofs, mpi_communicator);
662 *   conv_solution.reinit(locally_owned_dofs, mpi_communicator);
663 *   solution_update.reinit(locally_owned_dofs, mpi_communicator);
664 *  
665 *   conv_solution_np.reinit(dof_handler.n_dofs());
666 *   old_solution_np.reinit(dof_handler.n_dofs());
667 *   }
668 * @endcode
669
670
671<a name="ann-main.cpp"></a>
672<h1>Annotated version of main.cpp</h1>
673 *
674 *
675 *
676 *
677 * @code
678 *   /* -----------------------------------------------------------------------------
679 *   *
680 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
681 *   * Copyright (C) 2024 by Umair Hussain
682 *   *
683 *   * This file is part of the deal.II code gallery.
684 *   *
685 *   * -----------------------------------------------------------------------------
686 *   */
687 *  
688 *   #include <iostream>
689 *   #include "PhaseFieldSolver.h"
690 *  
691 *   int main(int argc, char **argv) {
692 *   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
693 *   PhaseFieldSolver phasefieldsolver;
694 *   phasefieldsolver.run();
695 *   return 0;
696 *   }
697 * @endcode
698
699
700<a name="ann-output_results.cpp"></a>
701<h1>Annotated version of output_results.cpp</h1>
702 *
703 *
704 *
705 *
706 * @code
707 *   /* -----------------------------------------------------------------------------
708 *   *
709 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
710 *   * Copyright (C) 2024 by Umair Hussain
711 *   *
712 *   * This file is part of the deal.II code gallery.
713 *   *
714 *   * -----------------------------------------------------------------------------
715 *   */
716 *  
717 *   #include "PhaseFieldSolver.h"
718 *  
719 *   void PhaseFieldSolver::output_results(const unsigned int timestep_number) const {
720 *   const Vector<double> localized_solution(old_solution);
721 *  
722 * @endcode
723 *
724 * using only one process to output the result
725 *
726 * @code
727 *   if (this_mpi_process == 0)
728 *   {
729 *   DataOut<2> data_out;
730 *   data_out.attach_dof_handler(dof_handler);
731 *  
732 *   std::vector<std::string> solution_names;
733 *   solution_names.emplace_back ("p");
734 *   solution_names.emplace_back ("T");
735 *  
736 *   data_out.add_data_vector(localized_solution, solution_names);
737 *   const std::string filename =
738 *   "solution-" + Utilities::int_to_string(timestep_number, 3) + ".vtk";
739 *   DataOutBase::VtkFlags vtk_flags;
740 *   vtk_flags.compression_level =
742 *   data_out.set_flags(vtk_flags);
743 *   std::ofstream output(filename);
744 *  
745 *   data_out.build_patches();
746 *   data_out.write_vtk(output);
747 *   }
748 *   }
749 * @endcode
750
751
752<a name="ann-run.cpp"></a>
753<h1>Annotated version of run.cpp</h1>
754 *
755 *
756 *
757 *
758 * @code
759 *   /* -----------------------------------------------------------------------------
760 *   *
761 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
762 *   * Copyright (C) 2024 by Umair Hussain
763 *   *
764 *   * This file is part of the deal.II code gallery.
765 *   *
766 *   * -----------------------------------------------------------------------------
767 *   */
768 *  
769 *   #include "PhaseFieldSolver.h"
770 *   #include <time.h>
771 *  
772 *   void PhaseFieldSolver::run() {
773 *   make_grid_and_dofs();
774 *   pcout << "Processors used: " << n_mpi_processes << std::endl;
775 *   pcout << " Number of degrees of freedom: " << dof_handler.n_dofs()
776 *   << " (by partition:";
777 *   for (unsigned int p = 0; p < n_mpi_processes; ++p)
778 *   pcout << (p == 0 ? ' ' : '+')
780 *   p));
781 *   pcout << ")" << std::endl;
782 * @endcode
783 *
784 * Initialise the solution
785 *
786 * @code
787 *   InitialValues initial_value;
788 *   VectorTools::interpolate(dof_handler,
789 *   initial_value,
790 *   old_solution);
791 *   VectorTools::interpolate(dof_handler,
792 *   initial_value,
793 *   conv_solution);
794 * @endcode
795 *
796 * Applying Boundary Conditions at t=0
797 *
798 * @code
799 *   applying_bc();
800 * @endcode
801 *
802 * Plotting initial solution
803 *
804 * @code
805 *   output_results(0);
806 *  
807 * @endcode
808 *
809 * Time steps begin here:
810 *
811 * @code
812 *   unsigned int timestep_number = 1;
813 *   for (; time <= final_time; time += time_step, ++timestep_number) {
814 *  
815 *   pcout << "Time step " << timestep_number << " at t=" << time+time_step
816 *   << std::endl;
817 *  
818 *   conv_solution.operator=(old_solution); // initialising the newton solution
819 *  
820 * @endcode
821 *
822 * Newton-Raphson iterations begin here:
823 *
824 * @code
825 *   for (unsigned int it = 1; it <= 100; ++it) {
826 *   pcout << "Newton iteration number:" << it << std::endl;
827 *  
828 *   if (it == 100) {
829 *   pcout << "Convergence Failure!!!!!!!!!!!!!!!" << std::endl;
830 *   std::exit(0);
831 *   }
832 * @endcode
833 *
834 * Saving parallel vectors as non-parallel ones
835 *
836 * @code
837 *   conv_solution_np = conv_solution;
838 *   old_solution_np = old_solution;
839 * @endcode
840 *
841 * Initialise the delta solution as zero
842 *
843 * @code
844 *   VectorTools::interpolate(dof_handler,
846 *   solution_update);
847 *   solution_update.compress(VectorOperation::insert);
848 * @endcode
849 *
850 * Assemble Jacobian and Residual
851 *
852 * @code
853 *   assemble_system();
854 * @endcode
855 *
856 * Solving to get delta solution
857 *
858 * @code
859 *   solve();
860 * @endcode
861 *
862 * Checking for convergence
863 *
864 * @code
865 *   double residual_norm = system_rhs.l2_norm(); //the norm of residual should converge to zero as the solution converges
866 * @endcode
867 *
868 * pcout << "Nothing wrong till here!!!!!!" << std::endl;
869 *
870 * @code
871 *   pcout << "the residual is:" << residual_norm << std::endl;
872 *   if (residual_norm <= (1e-4)) {
873 *   pcout << "Solution Converged!" << std::endl;
874 *   break; //Break to next time step if the N-R iterations converge
875 *   }
876 *   }
877 * @endcode
878 *
879 * Transfer the converged solution to the old_solution vector to plot output
880 *
881 * @code
882 *   old_solution.operator=(conv_solution);
883 *   old_solution.compress(VectorOperation::insert);
884 * @endcode
885 *
886 * output the solution at only specific number of time steps
887 *
888 * @code
889 *   if (timestep_number%10 == 0)
890 *   output_results(timestep_number);
891 *   }
892 *   }
893 * @endcode
894
895
896<a name="ann-solve.cpp"></a>
897<h1>Annotated version of solve.cpp</h1>
898 *
899 *
900 *
901 *
902 * @code
903 *   /* -----------------------------------------------------------------------------
904 *   *
905 *   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
906 *   * Copyright (C) 2024 by Umair Hussain
907 *   *
908 *   * This file is part of the deal.II code gallery.
909 *   *
910 *   * -----------------------------------------------------------------------------
911 *   */
912 *  
913 *   #include "PhaseFieldSolver.h"
914 *  
915 *   void PhaseFieldSolver::solve(){
916 * @endcode
917 *
918 * Using a direct parallel solver
919 *
920 * @code
921 *   SolverControl cn;
923 *   A_direct.solve(jacobian_matrix, solution_update, system_rhs);
924 * @endcode
925 *
926 * Updating the solution by adding the delta solution
927 *
928 * @code
929 *   conv_solution.add(1, solution_update);
930 *   conv_solution.compress(VectorOperation::add);
931 *   }
932 * @endcode
933
934
935*/
*  *  int main(int argc, char **argv)
*  *  iterator begin()
*  *  *  struct InterferenceTaperTransform *  
std::vector< bool > component_mask
void attach_dof_handler(const DoFHandler< dim, spacedim > &)
Definition fe_q.h:552
Definition point.h:111
Point< 2 > second
Definition grid_out.cc:4640
Point< 2 > first
Definition grid_out.cc:4639
void make_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
@ update_values
Shape function values.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
const Event initial
Definition event.cc:69
void subdomain_wise(DoFHandler< dim, spacedim > &dof_handler)
void random(DoFHandler< dim, spacedim > &dof_handler)
std::vector< IndexSet > locally_owned_dofs_per_subdomain(const DoFHandler< dim, spacedim > &dof_handler)
unsigned int count_dofs_with_subdomain_association(const DoFHandler< dim, spacedim > &dof_handler, const types::subdomain_id subdomain)
void partition_triangulation(const unsigned int n_partitions, Triangulation< dim, spacedim > &triangulation, const SparsityTools::Partitioner partitioner=SparsityTools::Partitioner::metis)
@ matrix
Contents is actually a matrix.
constexpr types::blas_int zero
constexpr types::blas_int one
void cell_matrix(FullMatrix< double > &M, const FEValuesBase< dim > &fe, const FEValuesBase< dim > &fetest, const ArrayView< const std::vector< double > > &velocity, const double factor=1.)
Definition advection.h:72
void apply_boundary_values(const std::map< types::global_dof_index, number > &boundary_values, SparseMatrix< number > &matrix, Vector< number > &solution, Vector< number > &right_hand_side, const bool eliminate_columns=true)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > epsilon(const Tensor< 2, dim, Number > &Grad_u)
*  *  *  *  std::vector< Number > ThermoPlasticMaterial< dim, ViscoplasticYieldLaw, Number >::get_state_parameters   const
void apply(const Kokkos::TeamPolicy< MemorySpace::Default::kokkos_space::execution_space >::member_type &team_member, const Kokkos::View< Number *, ShapeDataMemorySpace > shape_data, const ViewTypeIn in, ViewTypeOut out)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
Definition mpi.cc:103
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
Definition mpi.cc:118
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition utilities.cc:464
void interpolate(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Function< spacedim, typename VectorType::value_type > &function, VectorType &vec, const ComponentMask &component_mask={}, const unsigned int level=numbers::invalid_unsigned_int)
void interpolate_boundary_values(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const std::map< types::boundary_id, const Function< spacedim, number > * > &function_map, std::map< types::global_dof_index, number > &boundary_values, const ComponentMask &component_mask={})
void run(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
long double gamma(const unsigned int n)
void copy(const T *begin, const T *end, U *dest)
int(&) functions(const void *v1, const void *v2)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
inline ::VectorizedArray< Number, width > atan(const ::VectorizedArray< Number, width > &x)
DataOutBase::CompressionLevel compression_level