cmcmgui
Andre's notes while testing out using CMGUI libraries in a computational problem.
 1 Outline
 2 Goals
 3 Methods
 4 Notes, problems, and gotya's
 5 Outcomes
 6 Code
1  Project Outline Develop a test application which solves a static Laplace (e.g., steady state heat distribution) model over a twodimensional domain with bilinear element interpolation using the CMGUI finite element data structures to store field information. The application will be written in C using the C API to CMGUI. 
2  Project Goals

3  Methods Found my old afem project code (written in C) and got that working again for static 2D Laplace. Using CMISS examples 314(1,2,3,4) this code was able to obtain identical solutions as current cm. This code formed the basis of the test application. The first step was to replace the Node and Element structures defined in my afem code with accessing field information from the CMGUI data structures. Access is primarily through the function_finite_element interface. The only field of interest in this example application is the coordinates field, or more specifically the spatial derivatives with respect to local xi at the Gaussian quadrature points. Using the derivatives from the coordinate field at Gauss points (ds/dxi) you can invert to get dxi/ds and assemble the element stiffness matrix. The element stiffness matrix can then be added into the global stiffness matrix where we are still using node numbers/ids as indexes into the global matrix. Once we have the global stiffness matrix, we read in and apply some boundary conditions (using the dodgy file format from my afem project) and then solve the system. This results in a vector u containing the value solution at each node and a vector fluxes containing the weighted nodal flux solutions. The solutions are then put into new fields defined at the nodes (u and fluxes) and interpolated over the elements (u only) and the full mesh written out with all fields. 
4  Notes, Problems, and Gotya's Put here all the things that I find out along the way. Node IDs as matrix/vector indices
Boundary Conditions So far just using a basic struct for the storage of boundary condition information and reading in from a file in the format I made up for my afem project (Have a script to generate file from the CMISS ipinit files for essential BCs only). Ideally the BCs would come from additional fields in the mesh? Node field creator
Global nodes for a specific element
Destroying elements There is a method 'destroy_Cmiss_node(Cmiss_node_id *node_id_address)' in api/cmiss_finite_element.h which is simply a wrapper around the deaccessing of the actual FE_node. There is no corresponding 'destroy_Cmiss_element(Cmiss_element_id *element_id_address)' function  is there a reason for this or is it just missing?? Element dimension The only method I can find in the API to get an element's dimension is to create a function_element for the element ('Cmiss_function_element_create(element)') and then use 'Cmiss_function_element_dimension(functionElement,&dimension)' to get the dimension. Seems like a lot of work to only get the dimension. Perhaps there could be a 'int Cmiss_element_get_dimension(Cmiss_element_id element)' wrapper function around 'int get_FE_element_dimension(FE_element *element)' added to api/cmiss_finite_element.h? Basis function derivatives Would be good to be able to get the derivatives of an field's basis function for a given element/xi location. Derivative matrix
Scalar data type Need to check the simple casting between Scalar and double. Or maybe the application should be using the Scalar data type and the API can provide things like the format specifier and functions for converting to double/float types? Types of funnctions returned by evaluate and evaluate_derivative

5  Project Outcomes Seems to be working fine and giving the same answers as CMISS examples 314(1,2,3,4) and 312. Have yet to determine the best method for performance comparisons with backend CMISS. 
6  Code Code now available "here":/opencm/wiki/200506.tar.gz/file_view 