| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#31
| |||
| |||
| On Thu, 4 Sep 2008 10:47:46 -0700 (PDT), Will W. posted: > On Sep 2, 11:45*pm, Ron Ford <r...@example.invalid> wrote: >> On Mon, 1 Sep 2008 21:02:59 -0700 (PDT), Will W. posted: >> >>> So what do I want to do? >>> ------------------------------------ >>> Say I want to create a module of integration routines in xy Cartesian >>> geometry for integrating a user-specified function, f(x,y) over a >>> polygon. *Easy enough. >> >> I've never used fortran to integrate. >> >> What would f(x,y) look like in fortran, with, say, a parabola? >> -- >> War will never cease until babies begin to come into the world with larger >> cerebrums and smaller adrenal glands. 2 >> H. L. Mencken > > You could do something like this. > > FUNCTION Specific_Paraboloid(x,y) RESULT(f) > REAL,INTENT(IN) :: x,y > REAL :: f > !!--begin--A=1.0 > B=2.0 > C=3.0 > D=4.0 > E=5.0 > F=6.0 > f = A*x**2 + B*x + C*x*y + D*y**2 + E*y + F > !!--end-- > END FUNCTION > > A more general possible usage could be this, where I have "imported" > the coefficients from a module called VAR_General_Paraboloid (VAR is > for variables), so that one could set the coefficients A-F before > doing the integration and get different paraboloids. > > FUNCTION General_Paraboloid(x,y) RESULT(f) > USE VAR_General_Paraboloid,ONLY: A,B,C,D,E,F > REAL,INTENT(IN) :: x,y > REAL :: f > !!--begin-- > f = A*x**2 + B*x + C*x*y + D*y**2 + E*y + F > !!--end-- > END FUNCTION > > You can get even more general if you use a function parser, like > Stuart Midgley's, which lets you represent functions as text with > variables, then pass values of those variables to an evaluator, which > evaluates the function. This is very useful for reading functions > from input, for example, to read in general boundary conditions or > sources for a PDE solver. Then using the example of a 2D source, > which you would like to integrate over cells to get the cell-average > sources to stick in the RHS of a 2D finite volume method, the f(x,y) > might look like: > > FUNCTION MySourceFunction(x,y) RESULT(f) > USE VAR_MySourceFunction,ONLY: FunctionID > REAL,INTENT(IN) :: x,y > REAL :: f > REAL :: error > !!--begin-- > > call s_evaluatefn(FunctionID, (/x,y/), f ) > > !!--end-- > END FUNCTION > > My source function is specified by the FunctionID handle, which is > returned when the function is created through the parser, with a call > like > > call s_createfn( "1-tanh( (x-0.5)**2 + (y-0.4)**2 )" , > "x y" , FunctionID ) > > Like I alluded to, I use the parser to read in boundary conditions as > functions, then use an integrator to evaluate the face-average values > on the boundary. Stuart Midgley's parser is quite nice. I highly > recommend it. It has quite a few functions, heaviside, hat, an if > statement if( logical-expression , true-val , false-val ), really more > of a substitution and the option to specify uncertainties with the > function's coefficients and propagate them > to output. > +W Gosh, Will, I see a couple functions that I want to play with, but I wouldn't know how to call them. What does the following have to do with the paraboloid? > call s_createfn( "1-tanh( (x-0.5)**2 + (y-0.4)**2 )" , > "x y" , FunctionID ) I've had this difficulty with every previous integration. Ergo, I haven't popped my computer-integration cherry. Of course, it took Madonna Louise Ciccone Ritchie 50 years to sing like a virgin for her nazi head of faith. I'd never sorted with fortran until recently; maybe, I could integrate too. How to you call these functions with appropriate boundaries with the assumption that it is over a dense space? -- When a new source of taxation is found it never means, in practice, that the old source is abandoned. It merely means that the politicians have two ways of milking the taxpayer where they had one before. 8 H. L. Mencken |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.