libMesh
Functions | Variables
projection.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)
 
Number fptr (const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
 
Gradient gptr (const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
 
int main (int argc, char **argv)
 

Variables

std::string current_sys_name
 
std::map< std::string, MeshFunction * > mesh_functions
 

Function Documentation

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

Definition at line 57 of file projection.C.

References libMesh::err, and usage_error().

Referenced by main().

61 {
62  if (!cl.search(argname))
63  {
64  libMesh::err << ("No " + argname + " argument found!") << std::endl;
65  usage_error(progname);
66  }
67  return cl.next(defaultarg);
68 }
OStreamProxy err
void usage_error(const char *progname)
Definition: projection.C:42
Number fptr ( const Point p,
const Parameters ,
const std::string &  libmesh_dbg_varsys_name,
const std::string &  unknown_name 
)

Definition at line 78 of file projection.C.

References current_sys_name, libMesh::libmesh_assert(), and mesh_functions.

Referenced by libMesh::System::attach_assemble_function(), libMesh::System::attach_constraint_function(), libMesh::DiscontinuityMeasure::attach_essential_bc_function(), libMesh::KellyErrorEstimator::attach_flux_bc_function(), libMesh::System::attach_init_function(), libMesh::System::attach_QOI_derivative(), libMesh::System::attach_QOI_function(), libMesh::ExactSolution::attach_reference_solution(), libMesh::FrequencySystem::attach_solve_function(), libMesh::System::boundary_project_solution(), main(), libMesh::AnalyticFunction< Output >::operator()(), libMesh::System::project_solution(), libMesh::System::project_vector(), libMesh::System::read_parallel_data(), libMesh::FrequencySystem::system_type(), libMesh::System::system_type(), libMesh::DiscontinuityMeasure::~DiscontinuityMeasure(), libMesh::ExactErrorEstimator::~ExactErrorEstimator(), and libMesh::KellyErrorEstimator::~KellyErrorEstimator().

82 {
83  libmesh_assert_equal_to (sys_name, current_sys_name);
84  libmesh_assert(mesh_functions.count(unknown_name));
85  libmesh_assert(mesh_functions[unknown_name]);
86 
87  MeshFunction & meshfunc = *mesh_functions[unknown_name];
88 
89  return meshfunc(p);
90 }
std::map< std::string, MeshFunction * > mesh_functions
Definition: projection.C:75
libmesh_assert(j)
std::string current_sys_name
Definition: projection.C:74
This class provides function-like objects for data distributed over a mesh.
Definition: mesh_function.h:53
Gradient gptr ( const Point p,
const Parameters ,
const std::string &  libmesh_dbg_varsys_name,
const std::string &  unknown_name 
)

Definition at line 93 of file projection.C.

References current_sys_name, libMesh::MeshFunction::gradient(), libMesh::libmesh_assert(), and mesh_functions.

Referenced by libMesh::ExactSolution::attach_exact_value(), libMesh::ExactErrorEstimator::attach_exact_value(), libMesh::System::boundary_project_solution(), main(), libMesh::System::project_solution(), libMesh::System::project_vector(), libMesh::System::system_type(), and libMesh::ExactErrorEstimator::~ExactErrorEstimator().

97 {
98  libmesh_assert_equal_to (sys_name, current_sys_name);
99  libmesh_assert(mesh_functions.count(unknown_name));
100  libmesh_assert(mesh_functions[unknown_name]);
101 
102  MeshFunction & meshfunc = *mesh_functions[unknown_name];
103 
104  return meshfunc.gradient(p);
105 }
std::map< std::string, MeshFunction * > mesh_functions
Definition: projection.C:75
Gradient gradient(const Point &p, const Real time=0.)
libmesh_assert(j)
std::string current_sys_name
Definition: projection.C:74
This class provides function-like objects for data distributed over a mesh.
Definition: mesh_function.h:53
int main ( int  argc,
char **  argv 
)

Definition at line 108 of file projection.C.

References assert_argument(), libMesh::NumericVector< T >::build(), libMesh::LibMeshInit::comm(), libMesh::ParallelObject::comm(), current_sys_name, libMesh::DECODE, fptr(), libMesh::System::get_dof_map(), libMesh::EquationSystems::get_system(), gptr(), libMesh::EquationSystems::has_system(), libMesh::TriangleWrapper::init(), libMesh::MeshFunction::init(), libMesh::libmesh_assert(), mesh_functions, libMesh::EquationSystems::n_systems(), n_vars, libMesh::System::n_vars(), libMesh::System::name(), libMesh::out, libMesh::EquationSystems::parameters, libMesh::EquationSystems::print_info(), 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::SERIAL, libMesh::System::solution, libMesh::System::update_global_solution(), libMesh::System::variable_name(), libMesh::EquationSystems::write(), libMesh::EquationSystems::WRITE_ADDITIONAL_DATA, and libMesh::EquationSystems::WRITE_DATA.

109 {
110  LibMeshInit init(argc, argv);
111 
112  GetPot cl(argc, argv);
113 
114  // In case the mesh file doesn't let us auto-infer dimension, we let
115  // the user specify it on the command line
116  const unsigned char requested_dim =
117  cast_int<unsigned char>(cl.follow(3, "--dim"));
118 
119  // Load the old mesh from --inmesh filename.
120  // Keep it serialized; we don't want elements on the new mesh to be
121  // looking for data on old mesh elements that live off-processor.
122  ReplicatedMesh old_mesh(init.comm(), requested_dim);
123 
124  const std::string meshname =
125  assert_argument(cl, "--inmesh", argv[0], std::string("mesh.xda"));
126 
127  old_mesh.read(meshname);
128  std::cout << "Old Mesh:" << std::endl;
129  old_mesh.print_info();
130 
131  // Load the new mesh from --outmesh filename
132  Mesh new_mesh(init.comm(), requested_dim);
133 
134  const std::string outmeshname = cl.follow(std::string("out_"+meshname), "--outmesh");
135 
136  new_mesh.read(outmeshname);
137  std::cout << "New Mesh:" << std::endl;
138  new_mesh.print_info();
139 
140  // Load the old solution from --insoln filename
141  // Construct the new solution from the old solution's headers, so
142  // that we get the system names and types, variable names and types,
143  // etc.
144  const std::string solnname =
145  assert_argument(cl, "--insoln", argv[0], std::string("soln.xda"));
146 
147  EquationSystems old_es(old_mesh);
148  EquationSystems new_es(new_mesh);
149 
150  XdrMODE read_mode;
151 
152  if (solnname.rfind(".xdr") < solnname.size())
153  read_mode = DECODE;
154  else if (solnname.rfind(".xda") < solnname.size())
155  read_mode = READ;
156  else
157  libmesh_error_msg("Unrecognized file extension on " << solnname);
158 
159  old_es.read(solnname, read_mode,
160  EquationSystems::READ_HEADER |
161  EquationSystems::READ_DATA |
162  EquationSystems::READ_ADDITIONAL_DATA |
163  EquationSystems::READ_BASIC_ONLY);
164 
165  new_es.read(solnname, read_mode,
166  EquationSystems::READ_HEADER |
167  EquationSystems::READ_BASIC_ONLY);
168 
169  old_es.print_info();
170 
171  unsigned int n_systems = old_es.n_systems();
172  libmesh_assert_equal_to (new_es.n_systems(), n_systems);
173 
174  // For each system, serialize the solution so we can project it onto
175  // a potentially-very-different partitioning
176  for (unsigned int i = 0; i != n_systems; ++i)
177  {
178  System & old_sys = old_es.get_system(i);
179  current_sys_name = old_sys.name();
180 
181  libMesh::out << "Projecting system " << current_sys_name << std::endl;
182 
183  libmesh_assert (new_es.has_system(current_sys_name));
184 
185  System & new_sys = new_es.get_system(current_sys_name);
186  unsigned int n_vars = old_sys.n_vars();
187  libmesh_assert_equal_to (new_sys.n_vars(), n_vars);
188 
189  UniquePtr<NumericVector<Number>> comparison_soln =
191  std::vector<Number> global_soln;
192  old_sys.update_global_solution(global_soln);
193  comparison_soln->init(old_sys.solution->size(), true, SERIAL);
194  (*comparison_soln) = global_soln;
195 
196  // For each variable, construct a MeshFunction returning that
197  // variable's value
198  for (unsigned int j = 0; j != n_vars; ++j)
199  {
200  libMesh::out << " with variable " << old_sys.variable_name(j) << std::endl;
201 
202  MeshFunction * mesh_func =
203  new MeshFunction(old_es, *comparison_soln,
204  old_sys.get_dof_map(), j);
205  mesh_func->init();
206  mesh_functions[old_sys.variable_name(j)] = mesh_func;
207  }
208 
209  // Project all variables to the new system
210  new_sys.project_solution(fptr, gptr, old_es.parameters);
211 
212  // Clean up the MeshFunctions here so we don't bloat memory
213  for (unsigned int j = 0; j != n_vars; ++j)
214  delete mesh_functions[old_sys.variable_name(j)];
215  }
216 
217  // Write out the new solution file
218  const std::string outsolnname = cl.follow(std::string("out_"+solnname), "--outsoln");
219 
220  new_es.write(outsolnname.c_str(),
221  EquationSystems::WRITE_DATA |
222  EquationSystems::WRITE_ADDITIONAL_DATA);
223  libMesh::out << "Wrote solution " << outsolnname << std::endl;
224 
225  return 0;
226 }
This is the EquationSystems class.
std::map< std::string, MeshFunction * > mesh_functions
Definition: projection.C:75
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
virtual void read(const std::string &name, void *mesh_data=libmesh_nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false) libmesh_override
Reads the file specified by name.
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2134
Numeric vector.
Definition: dof_map.h:66
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:62
const unsigned int n_vars
Definition: tecplot_io.C:68
const std::string & name() const
Definition: system.h:1998
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
void update_global_solution(std::vector< Number > &global_soln) const
Fill the input vector global_soln so that it contains the global solution on all processors.
Definition: system.C:662
const DofMap & get_dof_map() const
Definition: system.h:2030
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:32
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
void init(triangulateio &t)
Initializes the fields of t to NULL/0 as necessary.
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
T assert_argument(GetPot &cl, const std::string &argname, const char *progname, const T &defaultarg)
Definition: projection.C:57
std::string current_sys_name
Definition: projection.C:74
const Parallel::Communicator & comm() const
OStreamProxy out
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:93
unsigned int n_vars() const
Definition: system.h:2086
This class provides function-like objects for data distributed over a mesh.
Definition: mesh_function.h:53
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
virtual void init() libmesh_override
Override the FunctionBase::init() member function by calling our own and specifying the Trees::NODES ...
Definition: mesh_function.h:96
void usage_error ( const char *  progname)

Definition at line 42 of file projection.C.

References libMesh::out.

Referenced by assert_argument().

43 {
44  libMesh::out << "Options: " << progname << '\n'
45  << " --dim d mesh dimension [default: autodetect]\n"
46  << " --inmesh filename input mesh file\n"
47  << " --insoln filename input solution file\n"
48  << " --outmesh filename output mesh file [default: out_<inmesh>]\n"
49  << " --outsoln filename output solution file [default: out_<insoln>]\n"
50  << std::endl;
51 
52  exit(1);
53 }
OStreamProxy out

Variable Documentation

std::string current_sys_name

Definition at line 74 of file projection.C.

Referenced by fptr(), gptr(), and main().

std::map<std::string, MeshFunction *> mesh_functions

Definition at line 75 of file projection.C.

Referenced by fptr(), gptr(), and main().