libMesh
Loading...
Searching...
No Matches
main.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>Solution Transfer Example 1 - </h1>
21// \author Derek Gaston
22// \date 2013
23//
24// This example demonstrates how to use the DTKSolutionTransfer object
25// to transfer a solution from one Mesh to another.
26
27// Basic include files needed for the mesh functionality.
28#include "libmesh/libmesh.h"
29#include "libmesh/mesh.h"
30#include "libmesh/mesh_generation.h"
31#include "libmesh/explicit_system.h"
32#include "libmesh/equation_systems.h"
33#include "libmesh/exodusII_io.h"
34#include "libmesh/libmesh_config.h"
35
36#ifdef LIBMESH_TRILINOS_HAVE_DTK
37#include "libmesh/dtk_solution_transfer.h"
38#endif
39
40// Bring in everything from the libMesh namespace
41using namespace libMesh;
42
43
45 const Parameters & /* parameters */,
46 const std::string &,
47 const std::string &)
48{
49 return p(0)*p(0) + 1; // x^2 + 1
50}
51
53 const std::string & system_name)
54{
55 ExplicitSystem & system = es.get_system<ExplicitSystem>(system_name);
56 es.parameters.set<Real> ("time") = system.time = 0;
57 system.project_solution(initial_value, nullptr, es.parameters);
58}
59
60int main(int argc, char * argv[])
61{
62 LibMeshInit init (argc, argv);
63
64#if !defined(LIBMESH_TRILINOS_HAVE_DTK)
65 // Skip this example (and use a different return code) if libMesh
66 // was compiled without Trilinos+DTK support.
67 libmesh_example_requires(false, "--enable-trilinos");
68
69#else
70
71 Mesh from_mesh(init.comm());
72 MeshTools::Generation::build_cube(from_mesh, 4, 4, 4, 0, 1, 0, 1, 0, 1, HEX8);
73 from_mesh.print_info();
74 EquationSystems from_es(from_mesh);
75 System & from_sys = from_es.add_system<ExplicitSystem>("From");
76 unsigned int from_var = from_sys.add_variable("from");
78 from_es.init();
79
80 ExodusII_IO(from_mesh).write_equation_systems("from.e", from_es);
81
82 Mesh to_mesh(init.comm());
83 MeshTools::Generation::build_cube(to_mesh, 5, 5, 5, 0, 1, 0, 1, 0, 1, TET4);
84 to_mesh.print_info();
85 EquationSystems to_es(to_mesh);
86 System & to_sys = to_es.add_system<ExplicitSystem>("To");
87 unsigned int to_var = to_sys.add_variable("to");
88 to_es.init();
89
90 DTKSolutionTransfer dtk_transfer(init.comm());
91
92 dtk_transfer.transfer(from_sys.variable(from_var), to_sys.variable(to_var));
93
94 to_es.update();
95 ExodusII_IO(to_mesh).write_equation_systems("to.e", to_es);
96
97#endif
98
99 return 0;
100}
Implementation of a SolutionTransfer object that uses the DataTransferKit (https://github....
virtual void transfer(const Variable &from_var, const Variable &to_var) override
Transfer the values of a variable to another.
This is the EquationSystems class.
void update()
Updates local values for all the systems.
Parameters parameters
Data structure holding arbitrary parameters.
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
const T_sys & get_system(std::string_view name) const
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition exodusII_io.h:53
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
Definition mesh_base.C:1755
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition parameters.h:75
T & set(const std::string &)
Definition parameters.h:494
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int > > variable_numbers=std::nullopt) const
Projects arbitrary functions onto the current solution.
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition system.C:2704
void attach_init_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in initializing the system.
Definition system.C:1928
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition system.C:1344
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
Definition system.h:1677
Number initial_value(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition main.C:44
void initialize(EquationSystems &es, const std::string &system_name)
Definition main.C:52
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
int main()