libMesh
Loading...
Searching...
No Matches
miscellaneous_ex7.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20// <h1>Miscellaneous Example 7 - The PetscDMNonlinearSolver and
21// Variational Inequality (VI) problems</h1>
22// \author Dmitry Karpeyev
23// \date 2012
24//
25// In this example, LibMesh interfaces directly with PETSc's
26// variational inequality solver through PetscDMNonlinearSolver
27// (available in PETSc-3.3.0 or above).
28
29// libmesh includes
30#include "libmesh/enum_solver_package.h"
31
32// Example include files
33#include "biharmonic.h"
34
35// Bring in everything from the libMesh namespace
36using namespace libMesh;
37
38// Print usage information if requested on command line
39void print_help(int argc, char ** argv);
40
41int main(int argc, char ** argv)
42{
43 // Initialize libMesh.
44 LibMeshInit init (argc, argv);
45 if (on_command_line("--help"))
46 print_help(argc, argv);
47 else
48 {
49#if !defined(LIBMESH_ENABLE_SECOND_DERIVATIVES)
50 libmesh_example_requires(false, "--enable-second");
51#elif !defined(LIBMESH_ENABLE_PERIODIC)
52 libmesh_example_requires(false, "--enable-periodic");
53#endif
54
55 // This is a PETSc-specific solver
56 libmesh_example_requires(libMesh::default_solver_package() == PETSC_SOLVERS, "--enable-petsc");
57
58 const int dim = command_line_value("dim", 1);
59
60 // Skip higher-dimensional examples on a lower-dimensional libMesh build
61 libmesh_example_requires(dim <= LIBMESH_DIM, "2D/3D support");
62
63 // This example only works with ReplicatedMesh.
64 ReplicatedMesh mesh(init.comm());
65 Biharmonic biharmonic(mesh);
66 biharmonic.viewParameters();
67 biharmonic.init();
68 biharmonic.run();
69 }
70 return 0;
71}
72
73
74
75
76
77void print_help(int, char ** argv)
78{
79 libMesh::out << "This example solves the Cahn-Hillard equation with chemical potential f:\n"
80 << " u_t = \\div(M(u)\\grad f(u))\n"
81 << "Here we have\n"
82 << " u, -1 <= u <= 1 -- relative concentration (difference of two concentrations in a binary mixture) \n"
83 << " M, M >= 0 -- mobility of the mixture\n"
84 << " f = \\delta E/\\delta u -- variational derivative of the free energy functional E\n"
85 << " E = \\int[\\kappa/2 |\\grac u|^ + g(u)]\n"
86 << "where the gradient term is the interfacial energy density with \\kappa quantifying the energy of the interface,\n"
87 << "and g(u) is the bulk energy density\n"
88 << " g(u) = \\theta L(u) + \\theta_c W(u),\n"
89 << "L(u) is the (optional, in this model) logarithmic term corresponding to the entropy of the mixture:\n"
90 << " L(u) = (\\theta/2)[(1+u)\\ln((1+u)/2) + (1-u)\\ln((1-u)/2)],\n"
91 << "where \\theta is related to the Boltzmann factor k_B T - a proxy for the absolute temperature T.\n"
92 << "L can be optionally approximated ('truncated') using a quadratic or a cubic polynomial on [-1,1]\n"
93 << "W(u) is the (optional, in this model) potential promoting demixing. It can take the form of \n"
94 << "a 'double well' potential\n"
95 << " W(u) = \\theta_c (u^4/4 - u^2/2),\n"
96 << " or \n"
97 << "a 'double obstacle' potential\n"
98 << " W(u) = (\\theta_c/2)(1-u^2),\n"
99 << "where \\theta_c is the critical 'temperature'.\n"
100 << "Finally, mobility M can be constant of 'degenerate', by which we mean that M is varying with u and \n"
101 << "vanishing (degenerating) whenever u reaches critical values +1 or -1:\n"
102 << " M(u) = 1.0\n"
103 << " or\n"
104 << " M(u) = (1.0 - u^2)\n"
105 << "Degenerate mobility should generally be used only in conjunction with logarithmic free energy terms.\n\n"
106 << "The equation is solved on a periodic domain (in 1D, 2D or 3D)\n"
107 << "using a Galerkin formulation with C^1 elements approximating the H^2_{per} function space.\n\n"
108 << "\n-----------\n"
109 << "COMPILING: "
110 << "\n-----------\n"
111 << "Compile as follows (assuming libmesh has been built): \n"
112 << "METHOD=<method> make \n"
113 << "where <method> is dbg or opt.\n"
114 << "\n-----------\n"
115 << "HELP: "
116 << "\n-----------\n"
117 << "Print this help message:\n"
118 << argv[0] << " --help\n"
119 << "\n-----------\n"
120 << "RUNNING: "
121 << "\n-----------\n"
122 << "Run in serial with PETSc-3.4 and above as follows:\n"
123 << "\n"
124 << argv[0] << "\n"
125 << " [--verbose] dim=<1|2|3> N=<number_of_linear_elements> \n"
126 << " kappa=<kappa_value> growth=<yes|no> degenerate=<yes|no> [--cahn-hillard] \n"
127 << " [--netforce] energy=<double_well|double_obstacle|log_double_well|log_double_obstacle> log_truncation_order=<2|3> \n"
128 << " theta=<theta_value> theta_c=<theta_c_value> \n"
129 << " initial_state=<ball|rod|strip> initial_center='x [y [z]]' initial_width=<width> \n"
130 << " min_time=<initial_time> max_time=<final_time> dt=<timestep_size> crank_nicholson_weight=<between_0_and_1> \n"
131 << " output_base=<base_filename> output_dt=<output_timestep_size> [-snes_type vinewtonrsls | vinewtonssls] \n"
132 << "(with PETSc-3.3 use -snes_type virs | viss).\n"
133 << argv[0] << " --verbose \n"
134 << "is a pretty good start.\n"
135 << "\nModeling a 1D system with 2D or 3D (for a strip the second and third components of the center are immaterial):\n"
136 << argv[0]<< " --verbose dim=1 N=1024 initial_state=strip initial_center=0.5 initial_width=0.1 dt=1e-10 max_time=1e-6\n"
137 << argv[0]<< " --verbose dim=2 N=64 initial_state=strip initial_center=0.5 initial_width=0.1 dt=1e-10 max_time=1e-6 \n"
138 << argv[0]<< " --verbose dim=3 N=32 initial_state=strip initial_center=0.5 initial_width=0.1 dt=1e-10 max_time=1e-6 \n"
139 << "\n"
140 << "Modeling a 2D system with 3D (for a rod the third component of the center is immaterial) \n"
141 << argv[0]<< " --verbose dim=2 N=64 initial_state=rod initial_center='0.5 0.5' initial_width=0.1 dt=1e-10 max_time=1e-6 \n"
142 << argv[0]<< " --verbose dim=3 N=32 initial_state=rod initial_center='0.5 0.5' initial_width=0.1 dt=1e-10 max_time=1e-6 \n"
143 << "\n"
144 << "A 3D system with an initial ball in the center\n"
145 << argv[0] << " --verbose dim=3 N=32 initial_state=ball initial_center='0.5 0.5 0.5' initial_width=0.1 dt=1e-10 max_time=1e-6 \n"
146 << "\n"
147 << "Add -snes_type vinewtonrsls to run the variational inequality version that ensures the solution is between -1.0 and 1.0 at all times.\n"
148 << "If using PETSc-3.3, run with -snes_type virs.\n"
149 << "\n"
150 << std::endl;
151}
unsigned int dim
The Biharmonic class encapsulates most of the data structures necessary to calculate the biharmonic r...
Definition biharmonic.h:46
void viewParameters()
Definition biharmonic.C:165
void init()
Initialize all the systems.
Definition biharmonic.C:212
void run()
Definition biharmonic.C:289
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
MeshBase & mesh
void print_help(int argc, char **argv)
The libMesh namespace provides an interface to certain functionality in the library.
SolverPackage default_solver_package()
Definition libmesh.C:1064
OStreamProxy out
T command_line_value(const std::string &, T)
Definition libmesh.C:971
bool on_command_line(std::string arg)
Definition libmesh.C:934
int main()