## Re: [Libmesh-users] Help with initialization functions for vector solutions

 Re: [Libmesh-users] Help with initialization functions for vector solutions From: Andrew E Slaughter - 2012-06-28 01:40:41 Here is my test problem with an initialization class that inherits from FunctionBase. Thanks for the help! -Andrew // Standard library includes #include #include #include #include #include using std::string; // libMesh includes #include "libmesh.h" #include "mesh.h" #include "mesh_generation.h" #include "equation_systems.h" #include "nonlinear_implicit_system.h" #include "transient_system.h" #include "explicit_system.h" #include "analytic_function.h" #include "exodusII_io.h" // Bring in everything from the libMesh namespace using namespace libMesh; // A class for initilizing velocity template class EqInit : public FunctionBase{ public: // Returns the velocity by its components virtual Number component(unsigned int index, const Point& p, Real time = 0){ if (index == 0){ return 1; // add some intensive calculation here } else { return 2; // add some intensive calculation here } } // Do not use the scalar output version of the operator() Output operator() (const Point& p, const Real t = 0.){ libmesh_not_implemented(); } // Use the component member to build the vector output version of operator() void operator() (const Point& p, const Real t, DenseVector& output){ output.resize(2); output(0) = component(0,p,t); output(1) = component(1,p,t); return; } // Create a copy of the class virtual AutoPtr > clone () const{ return AutoPtr > (new EqInit()); } }; // The main function int main (int argc, char** argv){ // Initialize libraries LibMeshInit init (argc, argv); // Generate a mesh Mesh mesh; MeshTools::Generation::build_square(mesh, 1, 1, -1., 1, -1, 1, QUAD4); mesh.all_first_order(); // Create an equation system EquationSystems eq_sys(mesh); // Create a system and add two variables (x and y velocity components) eq_sys.add_system("test"); eq_sys.get_system("test").add_variable("vx", FIRST); eq_sys.get_system("test").add_variable("vy", FIRST); // Initilize the equation system eq_sys.get_system("test").init(); // Project the velocity using the EqInit class EqInit init_velocity; eq_sys.get_system("test").project_solution(&init_velocity); // Test that values are correct for each point on the only element DenseVector v(2); Elem* elem = mesh.elem(0); for (unsigned int i = 0; i < elem->n_nodes(); i++){ Point& p = elem->point(i); v(0) = eq_sys.get_system("test").point_value(0,p); v(1) = eq_sys.get_system("test").point_value(1,p); printf("Point %g,%g; v = %f,%f\n", p(0),p(1),v(0),v(1)); } // Done return 0; } On Wed, Jun 27, 2012 at 9:20 PM, Andrew E Slaughter < andrew.e.slaughter@...> wrote: > Paul, > Thanks for linking the function, that is where I will head with > my initialization. I will post my implementation when I am done in case > anyone needs this in the future. > > One question, where is libmesh_not_implemented() defined, I can't seem to > find any documentation on it, but it looks useful? > > Thanks, > Andrew > > > On Wed, Jun 27, 2012 at 8:31 PM, Paul T. Bauman wrote: > >> On Wed, Jun 27, 2012 at 6:35 PM, Andrew E Slaughter < >> andrew.e.slaughter@...> wrote: >> >>> I just checkout out the trunk with the following and the folder you >>> specify does not exist, only examples/vector_fe/vector_fe_ex1.C >>> >> >> *facepalm* >> >> Sorry, that patch is still being discussed on libmesh-devel. You can grab >> the function here (I also include the function that it calls for >> posterity): http://users.ices.utexas.edu/~pbauman/bound_func/ >> >> Sorry about that. >> >> Paul >> > > > > -- > Andrew E. Slaughter, PhD > andrew.e.slaughter@... > > Materials Process Design and Control Laboratory > Sibley School of Mechanical and Aerospace Engineering > 169 Frank H. T. Rhodes Hall > Cornell University > Ithaca, NY 14853-3801 > (607) 229-1829 > http://aeslaughter.github.com/ > > -- Andrew E. Slaughter, PhD andrew.e.slaughter@... Materials Process Design and Control Laboratory Sibley School of Mechanical and Aerospace Engineering 169 Frank H. T. Rhodes Hall Cornell University Ithaca, NY 14853-3801 (607) 229-1829 http://aeslaughter.github.com/