libMesh
Loading...
Searching...
No Matches
Functions | Variables
solution_components.C File Reference

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

unsigned char dim = 2
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file solution_components.C.

34{
35 using namespace libMesh;
36
37 LibMeshInit init(argc, argv);
38
39 Mesh mesh1(init.comm(), dim);
40 EquationSystems es1(mesh1);
41
42 libMesh::out << "Usage: " << argv[0]
43 << " mesh oldsolution newsolution system1 variable1 [sys2 var2...]" << std::endl;
44
45 // We should have one system name for each variable name, and those
46 // get preceded by an even number of arguments.
47 libmesh_assert (!(argc % 2));
48
49 // We should have at least one system/variable pair following the
50 // initial arguments
51 libmesh_assert_greater_equal (argc, 6);
52
53 mesh1.read(argv[1]);
54 libMesh::out << "Loaded mesh " << argv[1] << std::endl;
55 Mesh mesh2(mesh1);
56 EquationSystems es2(mesh2);
57
58 es1.read(argv[2],
59 EquationSystems::READ_HEADER |
60 EquationSystems::READ_DATA |
61 EquationSystems::READ_ADDITIONAL_DATA |
62 EquationSystems::READ_BASIC_ONLY);
63 libMesh::out << "Loaded solution " << argv[2] << std::endl;
64
65 std::vector<unsigned int> old_sys_num((argc-4)/2),
66 new_sys_num((argc-4)/2),
67 old_var_num((argc-4)/2),
68 new_var_num((argc-4)/2);
69
70 std::vector<const System *> old_system((argc-4)/2);
71 std::vector<System *> new_system((argc-4)/2);
72
73 for (int argi = 4; argi < argc; argi += 2)
74 {
75 const char * sysname = argv[argi];
76 const char * varname = argv[argi+1];
77
78 const unsigned int pairnum = (argi-4)/2;
79
80 libmesh_assert(es1.has_system(sysname));
81
82 const System & old_sys = es1.get_system(sysname);
83 old_system[pairnum] = &old_sys;
84 old_sys_num[pairnum] = old_sys.number();
85
86 libmesh_assert(old_sys.has_variable(varname));
87
88 old_var_num[pairnum] = old_sys.variable_number(varname);
89
90 const Variable & variable = old_sys.variable(old_var_num[pairnum]);
91
92 std::string systype = old_sys.system_type();
93
94 System & new_sys = es2.add_system(systype, sysname);
95 new_system[pairnum] = &new_sys;
96 new_sys_num[pairnum] = new_sys.number();
97
98 new_var_num[pairnum] =
99 new_sys.add_variable(varname, variable.type(),
100 &variable.active_subdomains());
101 }
102
103 es2.init();
104
105 // A future version of this app should copy variables for
106 // non-solution vectors too.
107
108 // Copy over any nodal degree of freedom coefficients
109 MeshBase::const_node_iterator new_nit = mesh2.local_nodes_begin();
110
111 for (const auto & old_node : mesh1.local_node_ptr_range())
112 {
113 const Node * new_node = *new_nit++;
114
115 // Mesh::operator= hopefully preserved elem/node orderings...
116 libmesh_assert (*old_node == *new_node);
117
118 for (int argi = 4; argi < argc; argi += 2)
119 {
120 const unsigned int pairnum = (argi-4)/2;
121
122 const System & old_sys = *old_system[pairnum];
123 System & new_sys = *new_system[pairnum];
124
125 const unsigned int n_comp =
126 old_node->n_comp(old_sys_num[pairnum],old_var_num[pairnum]);
127 libmesh_assert_equal_to(n_comp,
128 new_node->n_comp(new_sys_num[pairnum],new_var_num[pairnum]));
129
130 for (unsigned int i=0; i<n_comp; i++)
131 {
132 const dof_id_type
133 old_index = old_node->dof_number
134 (old_sys_num[pairnum], old_var_num[pairnum], i),
135 new_index = new_node->dof_number
136 (new_sys_num[pairnum], new_var_num[pairnum], i);
137 new_sys.solution->set(new_index,(*old_sys.solution)(old_index));
138 }
139 }
140 }
141
142
143 // Copy over any element degree of freedom coefficients
144 MeshBase::const_element_iterator new_eit = mesh2.active_local_elements_begin();
145
146 for (const auto & old_elem : mesh1.active_local_element_ptr_range())
147 {
148 const Elem * new_elem = *new_eit++;
149
150 // Mesh::operator= hopefully preserved elem/node orderings...
151 libmesh_assert (*old_elem == *new_elem);
152
153 for (int argi = 4; argi < argc; argi += 2)
154 {
155 const unsigned int pairnum = (argi-4)/2;
156
157 const System & old_sys = *old_system[pairnum];
158 System & new_sys = *new_system[pairnum];
159
160 const unsigned int n_comp =
161 old_elem->n_comp(old_sys_num[pairnum],old_var_num[pairnum]);
162 libmesh_assert_equal_to(n_comp,
163 new_elem->n_comp(new_sys_num[pairnum],new_var_num[pairnum]));
164
165 for (unsigned int i=0; i<n_comp; i++)
166 {
167 const dof_id_type
168 old_index = old_elem->dof_number
169 (old_sys_num[pairnum], old_var_num[pairnum], i),
170 new_index = new_elem->dof_number
171 (new_sys_num[pairnum], new_var_num[pairnum], i);
172 new_sys.solution->set(new_index,(*old_sys.solution)(old_index));
173 }
174 }
175 }
176
177 es2.write(argv[3], EquationSystems::WRITE_DATA);
178
179 return 0;
180}
unsigned int n_comp(const unsigned int s, const unsigned int var) const
Definition dof_object.h:978
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This is the EquationSystems class.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
A Node is like a Point, but with more information.
Definition node.h:55
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition system.C:2704
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
virtual std::string system_type() const
Definition system.h:510
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition system.h:1655
unsigned int variable_number(std::string_view var) const
Definition system.C:1398
bool has_variable(std::string_view var) const
Definition system.C:1393
unsigned int number() const
Definition system.h:2393
This class defines the notion of a variable in the system.
Definition variable.h:51
const std::set< subdomain_id_type > & active_subdomains() const
Definition variable.h:181
const FEType & type() const
Definition variable.h:144
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)
OStreamProxy out
uint8_t dof_id_type
Definition id_types.h:67
unsigned char dim
The definition of the const_element_iterator struct.
Definition mesh_base.h:2556
The definition of the const_node_iterator struct.
Definition mesh_base.h:2607

References libMesh::Variable::active_subdomains(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), dim, libMesh::DofObject::dof_number(), libMesh::EquationSystems::get_system(), libMesh::EquationSystems::has_system(), libMesh::System::has_variable(), libMesh::EquationSystems::init(), main(), libMesh::DofObject::n_comp(), libMesh::System::number(), libMesh::out, libMesh::UnstructuredMesh::read(), libMesh::EquationSystems::read(), libMesh::System::solution, libMesh::System::system_type(), libMesh::Variable::type(), libMesh::System::variable(), libMesh::System::variable_number(), and libMesh::EquationSystems::write().

Variable Documentation

◆ dim

unsigned char dim = 2

Definition at line 31 of file solution_components.C.

Referenced by main().