libMesh
Functions
calculator.C File Reference

Go to the source code of this file.

Functions

void usage_error (const char *progname)
 
template<typename T >
assert_argument (GetPot &cl, const std::string &argname, const char *progname, const T &defaultarg)
 
int main (int argc, char **argv)
 

Function Documentation

◆ assert_argument()

template<typename T >
T assert_argument ( GetPot &  cl,
const std::string &  argname,
const char *  progname,
const T &  defaultarg 
)

Definition at line 64 of file calculator.C.

68 {
69  if (!cl.search(argname))
70  {
71  libMesh::err << ("No " + argname + " argument found!") << std::endl;
72  usage_error(progname);
73  }
74  return cl.next(defaultarg);
75 }

References libMesh::err, and usage_error().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 78 of file calculator.C.

79 {
80  LibMeshInit init(argc, argv);
81 
82  GetPot cl(argc, argv);
83 
84  // In case the mesh file doesn't let us auto-infer dimension, we let
85  // the user specify it on the command line
86  const unsigned char requested_dim =
87  cast_int<unsigned char>(cl.follow(3, "--dim"));
88 
89  // Load the old mesh from --inmesh filename.
90  // Keep it serialized; we don't want elements on the new mesh to be
91  // looking for data on old mesh elements that live off-processor.
92  Mesh old_mesh(init.comm(), requested_dim);
93 
94  const std::string meshname =
95  assert_argument(cl, "--inmesh", argv[0], std::string("mesh.xda"));
96 
97  old_mesh.read(meshname);
98  std::cout << "Mesh:" << std::endl;
99  old_mesh.print_info();
100 
101  // Create a new mesh for a new EquationSystems
102  Mesh new_mesh(init.comm(), requested_dim);
103  new_mesh.read(meshname);
104 
105  // Load the old solution from --insoln filename
106  // Construct the new solution from the old solution's headers, so
107  // that we get the system names and types, variable names and types,
108  // etc.
109  const std::string solnname =
110  assert_argument(cl, "--insoln", argv[0], std::string("soln.xda"));
111 
112  EquationSystems old_es(old_mesh);
113  EquationSystems new_es(new_mesh);
114 
115  XdrMODE read_mode;
116 
117  if (solnname.rfind(".xdr") < solnname.size())
118  read_mode = DECODE;
119  else if (solnname.rfind(".xda") < solnname.size())
120  read_mode = READ;
121  else
122  libmesh_error_msg("Unrecognized file extension on " << solnname);
123 
124  old_es.read(solnname, read_mode,
125  EquationSystems::READ_HEADER |
126  EquationSystems::READ_DATA |
127  EquationSystems::READ_ADDITIONAL_DATA |
128  EquationSystems::READ_BASIC_ONLY);
129 
130  old_es.print_info();
131 
132 
133  const unsigned int sysnum =
134  cl.follow(0, "--insys");
135 
136  libmesh_assert_less(sysnum, old_es.n_systems());
137 
138  System & old_sys = old_es.get_system(sysnum);
139  std::string current_sys_name = old_sys.name();
140 
141  libMesh::out << "Calculating with system " << current_sys_name << std::endl;
142 
143  L2System & new_sys = new_es.add_system<L2System>(current_sys_name);
144 
145  new_sys.time_solver =
146  libmesh_make_unique<SteadySolver>(new_sys);
147 
148  new_sys.fe_family() =
149  cl.follow(std::string("LAGRANGE"), "--family");
150 
151  new_sys.fe_order() =
152  cl.follow(1, "--order");
153 
154  const std::string calcfunc =
155  assert_argument(cl, "--calc", argv[0], std::string(""));
156 
157  ParsedFEMFunction<Number> goal_function(old_sys, calcfunc);
158 
159  new_sys.goal_func = goal_function.clone();
160  new_sys.input_system = &old_sys;
161 
162  new_es.init();
163 
164  DiffSolver & solver = *(new_sys.time_solver->diff_solver().get());
165  solver.quiet = false;
166  solver.verbose = true;
167  solver.relative_step_tolerance = 1e-10;
168 
169  new_sys.solve();
170 
171  // Write out the new solution file
172  const std::string outsolnname = cl.follow(std::string("out_"+solnname), "--outsoln");
173 
174  new_es.write(outsolnname.c_str(),
175  EquationSystems::WRITE_DATA |
176  EquationSystems::WRITE_ADDITIONAL_DATA);
177  libMesh::out << "Wrote solution " << outsolnname << std::endl;
178 
179  return 0;
180 }

References libMesh::EquationSystems::add_system(), assert_argument(), libMesh::ParsedFEMFunction< Output >::clone(), current_sys_name, libMesh::DECODE, L2System::fe_family(), L2System::fe_order(), libMesh::EquationSystems::get_system(), L2System::goal_func, libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), L2System::input_system, libMesh::EquationSystems::n_systems(), libMesh::out, libMesh::EquationSystems::print_info(), libMesh::DiffSolver::quiet, libMesh::READ, libMesh::UnstructuredMesh::read(), libMesh::EquationSystems::read(), libMesh::EquationSystems::READ_ADDITIONAL_DATA, libMesh::EquationSystems::READ_BASIC_ONLY, libMesh::EquationSystems::READ_DATA, libMesh::EquationSystems::READ_HEADER, libMesh::DiffSolver::relative_step_tolerance, libMesh::FEMSystem::solve(), libMesh::DifferentiableSystem::time_solver, libMesh::DiffSolver::verbose, libMesh::EquationSystems::write(), libMesh::EquationSystems::WRITE_ADDITIONAL_DATA, and libMesh::EquationSystems::WRITE_DATA.

◆ usage_error()

void usage_error ( const char *  progname)

Definition at line 46 of file calculator.C.

47 {
48  libMesh::out << "Options: " << progname << '\n'
49  << " --dim d mesh dimension [default: autodetect]\n"
50  << " --inmesh filename input mesh file\n"
51  << " --insoln filename input solution file\n"
52  << " --calc func function to calculate\n"
53  << " --insys num input system number [default: 0]\n"
54  << " --outsoln filename output solution file [default: out_<insoln>]\n"
55  << " --family famname output FEM family [default: LAGRANGE]\n"
56  << " --order num output FEM order [default: 1]\n"
57  << std::endl;
58 
59  exit(1);
60 }

References libMesh::out.

Referenced by assert_argument().

libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::FEMSystem::solve
virtual void solve() override
Invokes the solver associated with the system.
Definition: fem_system.C:1046
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::System::init
void init()
Initializes degrees of freedom on the current mesh.
Definition: system.C:237
L2System::goal_func
std::unique_ptr< libMesh::FEMFunctionBase< libMesh::Number > > goal_func
Definition: L2system.h:49
L2System::fe_order
unsigned int & fe_order()
Definition: L2system.h:42
libMesh::DiffSolver
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Definition: diff_solver.h:70
libMesh::DifferentiableSystem::time_solver
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
Definition: diff_system.h:233
L2System::fe_family
std::string & fe_family()
Definition: L2system.h:41
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::XdrMODE
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:35
libMesh::DiffSolver::relative_step_tolerance
Real relative_step_tolerance
Definition: diff_solver.h:204
libMesh::DECODE
Definition: enum_xdr_mode.h:39
libMesh::DiffSolver::verbose
bool verbose
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false.
Definition: diff_solver.h:168
L2System
Definition: L2system.h:26
libMesh::UnstructuredMesh::read
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false) override
Reads the file specified by name.
Definition: unstructured_mesh.C:620
current_sys_name
std::string current_sys_name
Definition: projection.C:76
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
libMesh::READ
Definition: enum_xdr_mode.h:41
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::DiffSolver::quiet
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
Definition: diff_solver.h:162
assert_argument
T assert_argument(GetPot &cl, const std::string &argname, const char *progname, const T &defaultarg)
Definition: calculator.C:64
libMesh::ParsedFEMFunction
ParsedFEMFunction provides support for FParser-based parsed functions in FEMSystem.
Definition: parsed_fem_function.h:57
libMesh::err
OStreamProxy err
L2System::input_system
libMesh::System * input_system
Definition: L2system.h:51
libMesh::out
OStreamProxy out
usage_error
void usage_error(const char *progname)
Definition: calculator.C:46