Thread Previous • Date Previous • Date Next • Thread Next |
Anders Logg wrote:
On Fri, Mar 06, 2009 at 04:30:56PM +0100, Patrick Riesen wrote:Anders Logg wrote:On Thu, Mar 05, 2009 at 04:55:38PM +0100, Patrick Riesen wrote:hi all i'm stuck on the following problem: i'd like to compute a term as eta = (gamma)^(-2/3), or general eta = gamma^(n) and n is realin my code, gamma is dependent on a velocity function from a previous interation, so gamma = gamma(u0), and how to compute gamma stems from a form-file, so i do:_M_gamma = new gammaFunctional(u0); Function f_gamma(&mesh, *M_gamma, 0); my question is now how can i create the other function f_eta = f_gamma^(2/3) in a nice way?what i thought about is to create a derived function class Eta where overload the evaluation function in a way asdouble eval(const double* x) const { return (gamma.eval(x)*gamma.eval(x))^(-1/3) }please tell me if this is a possible approach, or else advise me how to handle this :-)thanks a lot for the support, patrick (btw i do this together with dolfin-grade2 so i use dolfin0.8.1 )I'd suggest operating on the vectors of dofs. Send in the gamma function to the constructor of your Function subclass, pick out the vector of dofs, iterate over the dofs and just insert the values into the vector using pow(x[i], 2.0/3.0). Use the get/set methods in Vector to first pick out arrays, operate on the arrays and then put them back.hi anders,i understand how to create the f_eta class and hand in the f_gamma but i'm uncertain on what to do inside f_eta exactly. can you give me some more help, e.g. in a few pseudocode statements?thanks a lot for the help, patrickIn the constructor of EtaFunction, do something like this: const Vector& gamma_vector = gamma.vector(); const Vector& eta_vector = vector(); for (uint i = 0; i < eta_vector.size(); i++) eta_vector.setitem(i, pow(gamma_vector[i], 3.0));
helloSo my Etafunction is now being correctly constructed and there are the correct values in the dof-vector(). i did this by a function class definition and a call to Eta as
class Eta: public Function {Eta (Mesh& mesh, Function& gamma, Form& form, ...) : Function(mesh, form, argument_id)
{ constructor....something as above } and then i call it as f_eta = new Eta(.....); in the main program.calling Eta as Function(mesh,form,id) i thought this should create a discrete function for f_eta, but the type of the f_eta function is 'user'. this gives me an error at the assembly, "missing eval() for user-defined function..." do i have to add an dummy eval() function to my Eta-class, or what do i have to change that no eva()-missing error is raised and my f_eta function is of type discrete?
thanks for your help, patrick
Thread Previous • Date Previous • Date Next • Thread Next |