Changeset 487 for trunk/matml
- Timestamp:
- 10/12/2009 02:31:51 PM (3 years ago)
- Location:
- trunk/matml/src/ternary
- Files:
-
- 6 modified
-
ChangeLog (modified) (1 diff)
-
configure.in (modified) (1 diff)
-
freenergy.c (modified) (1 diff)
-
freenergy.h (modified) (1 diff)
-
Makefile.am (modified) (1 diff)
-
ternary.tex.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/matml/src/ternary/ChangeLog
r484 r487 3 3 * New arbitrary polynomial terms in the free energy functions. 4 4 * Fixed and considerably improved spinodal caculation. 5 * New adjust_gaussians function to aid in setting Gaussian parameters. 5 6 6 7 -- -
trunk/matml/src/ternary/configure.in
r471 r487 28 28 AC_MSG_ERROR([Cannot find qhull library which ternary requires; you can download it at http://www.qhull.org/ or install the libqhull-dev .deb package.])) 29 29 30 MATH_BLASLAPACK_CHECKS 31 30 32 dnl Documentation tools 31 33 CXREF_LATEX_CHECKS -
trunk/matml/src/ternary/freenergy.c
r486 r487 592 592 return 0; 593 593 } 594 595 596 #if HAVE_LAPACK == yes 597 #include <stdlib.h> /*+ For malloc and free +*/ 598 #include <stdio.h> /*+ For printf +*/ 599 void dgetrf_ (int *, int *, double *, int *, int *, int *); 600 void dlaswp_ (int *, double *, int *, int *, int *, int *, int *); 601 void dtrsm_ (char *, char *, char *, char *, int *, int *, double *, 602 double *, int *, double *, int *); 603 604 /*++++++++++++++++++++++++++++++++++++++ 605 Adjust the Gaussian energy parameters (G) such that on return, the free 606 energy at each Gaussian concentration is equal to the incoming value of G0. 607 608 int adjust_gaussians Retunrs 0 or an error code. 609 610 double T Temperature. 611 612 double P Pressure (ignored for now). 613 614 double *G0 Intended free energy values at Gaussian center compositions. 615 616 energy_params *eparams Free energy function parameters. 617 618 int efunc Index indicating which set of energy parameters to use 619 ++++++++++++++++++++++++++++++++++++++*/ 620 621 int adjust_gaussians 622 (double T, double P, double *G0, energy_params *eparams, int efunc) 623 { 624 double *G_scratch, *G_matrix, one=1.; 625 int i,j, gs = eparams [efunc].n_gauss, piv[gs]; 626 627 // Do one malloc for both arrays 628 if (!(G_scratch = malloc (gs*(gs+1) * sizeof (double)))) 629 return 1; 630 G_matrix = G_scratch + gs; 631 632 // Calculate the free energy at each point without any Gaussians. 633 for (i=0; i<gs; i++) 634 (eparams[efunc].gauss)[i].G = 0.; 635 for (i=0; i<gs; i++) 636 G_scratch [i] = free_energy 637 ((eparams[efunc].gauss)[i].C2, (eparams[efunc].gauss)[i].C3, T, P, 638 eparams+efunc); 639 640 // Calculate the effect of each Gaussian on the energy at all of the other 641 // points. 642 for (i=0; i<gs; i++) 643 { 644 (eparams[efunc].gauss)[i].G = 1.; 645 for (j=0; j<gs; j++) 646 G_matrix [i*gs+j] = free_energy 647 ((eparams[efunc].gauss)[j].C2, (eparams[efunc].gauss)[j].C3, T, P, 648 eparams+efunc) - G_scratch [j]; 649 (eparams[efunc].gauss)[i].G = 0.; 650 } 651 652 // Set G_scratch values to G0 for solving below 653 for (i=0; i<gs; i++) 654 G_scratch [i] = G0 [i] - G_scratch [i]; 655 656 // Solve for the new G values values using LAPACK 657 dgetrf_ (&gs, &gs, G_matrix, &gs, piv, &i); 658 if (i != 0) 659 return i; 660 i=1; 661 dlaswp_ (&i, G_scratch, &gs, &i, &gs, piv, &i); 662 dtrsm_("Left", "Lower", "No transpose", "Unit", &gs, &i, &one, G_matrix, &gs, 663 G_scratch, &gs); 664 dtrsm_("Left", "Upper", "No transpose", "Non-Unit", &gs, &i, &one, G_matrix, 665 &gs, G_scratch, &gs); 666 667 // Put them into the Gaussian structures 668 for (i=0; i<gs; i++) 669 (eparams[efunc].gauss)[i].G = G_scratch [i]; 670 671 #ifdef DEBUG 672 // Test the results 673 for (i=0; i<gs; i++) 674 printf ("Point %d at %g,%g: G=%g, energy=%g, G0=%g\n", i, 675 (eparams[efunc].gauss)[i].C2, (eparams[efunc].gauss)[i].C3, 676 (eparams[efunc].gauss)[i].G, 677 free_energy ((eparams[efunc].gauss)[i].C2, 678 (eparams[efunc].gauss)[i].C3, T, P, eparams+efunc), 679 G0 [i]); 680 #endif 681 682 // Clean up and go home 683 free(G_scratch); 684 return 0; 685 } 686 #endif -
trunk/matml/src/ternary/freenergy.h
r475 r487 111 111 (energy_point *points, int n, double T, double P, energy_params *eparams, 112 112 int efunc, free_energy_flags flags); 113 #if HAVE_LAPACK == yes 114 int adjust_gaussians 115 (double T, double P, double *G0, energy_params *eparams, int efunc); 116 #endif 113 117 114 118 #endif // FREENERGY_H -
trunk/matml/src/ternary/Makefile.am
r474 r487 12 12 13 13 libfreenergy_la_SOURCES = freenergy.c 14 libfreenergy_la_LIBADD = -lm 15 libfreenergy_la_CFLAGS = -std=c99 #-DDEBUG16 libfreenergy_la_LDFLAGS = -version-info 0:0:014 libfreenergy_la_LIBADD = -lm $(BLASLAPACK_LIBS) 15 libfreenergy_la_CFLAGS = -std=c99 -DHAVE_LAPACK=$(HAVE_LAPACK) #-DDEBUG 16 libfreenergy_la_LDFLAGS = -version-info 1:0:0 17 17 18 18 libgibbs_la_SOURCES = geomview.c qhull.c book.c spinodal.c -
trunk/matml/src/ternary/ternary.tex.in
r479 r487 49 49 50 50 To compile {\tt Ternary}, you need the qhull library and geomview program, as 51 well as a C compiler. On Ubuntu, installing the {\tt build-essential}, {\tt 52 libqhull-dev} and {\tt geomview} packages satisfy this. If you want to build 53 the documentation as well, you will also need {\tt cxref} along with \Latex (in 54 the {\tt texlive-base-bin} package) for the PDF, and either hevea or latex2html 55 for HTML documentation. 51 well as a C compiler. On Debian and Ubuntu, installing the {\tt 52 build-essential}, {\tt liblapack-dev}, {\tt libqhull-dev} and {\tt geomview} 53 packages satisfy this. If you want to build the documentation as well, you 54 will also need {\tt cxref} along with \LaTeX (in the {\tt texlive-latex-base} 55 package) for the PDF, and either {\tt hevea} or {\tt latex2html} for HTML 56 documentation. 56 57 57 Next, unpack the .tar.gzsource archive by typing (at the command line):58 Next, unpack the {\tt .tar.gz} source archive by typing (at the command line): 58 59 \begin{quote} 59 60 \tt tar xzf Ternary-[version].tar.gz