📄 fem2d_poisson.cpp
字号:
double r8_min ( double x, double y )
//****************************************************************************80
//
// Purpose:
//
// R8_MIN returns the minimum of two R8's.
//
// Modified:
//
// 09 May 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input double X, Y, the quantities to compare.
//
// Output, double R8_MIN, the minimum of X and Y.
//
{
if ( y < x )
{
return y;
}
else
{
return x;
}
}
//****************************************************************************80
int r8_nint ( double x )
//****************************************************************************80
//
// Purpose:
//
// R8_NINT returns the nearest integer to an R8.
//
// Examples:
//
// X R8_NINT
//
// 1.3 1
// 1.4 1
// 1.5 1 or 2
// 1.6 2
// 0.0 0
// -0.7 -1
// -1.1 -1
// -1.6 -2
//
// Modified:
//
// 26 August 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double X, the value.
//
// Output, int R8_NINT, the nearest integer to X.
//
{
int s;
if ( x < 0.0 )
{
s = -1;
}
else
{
s = 1;
}
return ( s * ( int ) ( fabs ( x ) + 0.5 ) );
}
//****************************************************************************80
void r8vec_print_some ( int n, double a[], int max_print, char *title )
//****************************************************************************80
//
// Purpose:
//
// R8VEC_PRINT_SOME prints "some" of an R8VEC.
//
// Discussion:
//
// The user specifies MAX_PRINT, the maximum number of lines to print.
//
// If N, the size of the vector, is no more than MAX_PRINT, then
// the entire vector is printed, one entry per line.
//
// Otherwise, if possible, the first MAX_PRINT-2 entries are printed,
// followed by a line of periods suggesting an omission,
// and the last entry.
//
// Modified:
//
// 14 November 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the number of entries of the vector.
//
// Input, double A[N], the vector to be printed.
//
// Input, int MAX_PRINT, the maximum number of lines to print.
//
// Input, char *TITLE, an optional title.
//
{
int i;
if ( max_print <= 0 )
{
return;
}
if ( n <= 0 )
{
return;
}
if ( 0 < s_len_trim ( title ) )
{
cout << "\n";
cout << title << "\n";
cout << "\n";
}
if ( n <= max_print )
{
for ( i = 0; i < n; i++ )
{
cout << setw(6) << i + 1 << " "
<< setw(14) << a[i] << "\n";
}
}
else if ( 3 <= max_print )
{
for ( i = 0; i < max_print-2; i++ )
{
cout << setw(6) << i + 1 << " "
<< setw(14) << a[i] << "\n";
}
cout << "...... ..............\n";
i = n - 1;
cout << setw(6) << i + 1 << " "
<< setw(14) << a[i] << "\n";
}
else
{
for ( i = 0; i < max_print-1; i++ )
{
cout << setw(6) << i + 1 << " "
<< setw(14) << a[i] << "\n";
}
i = max_print - 1;
cout << setw(6) << i + 1 << " "
<< setw(14) << a[i] << "...more entries...\n";
}
return;
}
//****************************************************************************80*
double rhs ( double x, double y )
//****************************************************************************80*
//
// Purpose:
//
// RHS gives the right-hand side of the differential equation.
//
// Discussion:
//
// The function specified here depends on the problem being
// solved. This is one of the routines that a user will
// normally want to change.
//
// Modified:
//
// 20 February 2004
//
// Parameters:
//
// Input, double X, Y, the coordinates of a point
// in the region, at which the right hand side of the
// differential equation is to be evaluated.
//
// Output, double RHS, the value of the right
// hand side of the differential equation at (X,Y).
//
{
# define PI 3.14159265358979323846264338327950288419716939937510
double value;
value = 2.0E+00 * PI * PI * sin ( PI * x ) * sin ( PI * y );
return value;
# undef PI
}
//****************************************************************************80
int s_len_trim ( char *s )
//****************************************************************************80
//
// Purpose:
//
// S_LEN_TRIM returns the length of a string to the last nonblank.
//
// Modified:
//
// 26 April 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, char *S, a pointer to a string.
//
// Output, int S_LEN_TRIM, the length of the string to the last nonblank.
// If S_LEN_TRIM is 0, then the string is entirely blank.
//
{
int n;
char* t;
n = strlen ( s );
t = s + strlen ( s ) - 1;
while ( 0 < n )
{
if ( *t != ' ' )
{
return n;
}
t--;
n--;
}
return n;
}
//****************************************************************************80*
void solution_write ( double f[], int indx[], int node_num, int nunk,
char *output_filename, double node_xy[] )
//****************************************************************************80*
//
// Purpose:
//
// SOLUTION_WRITE writes the solution to a file.
//
// Modified:
//
// 22 March 2005
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double F[NUNK], the coefficients of the solution.
//
// Input, int INDX[NODE_NUM], gives the index of the unknown quantity
// associated with the given node.
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, int NUNK, the number of unknowns.
//
// Input, char *OUTPUT_FILENAME, the name of the file
// in which the data should be stored.
//
// Input, double NODE_XY[2*NODE_NUM], the X and Y coordinates of nodes.
//
{
double dudx;
double dudy;
int node;
ofstream output;
double u;
double x;
double y;
output.open ( output_filename );
if ( !output )
{
cout << "\n";
cout << "SOLUTION_WRITE - Warning!\n";
cout << " Could not write the solution file.\n";
return;
}
for ( node = 0; node < node_num; node++ )
{
x = node_xy[0+node*2];
y = node_xy[1+node*2];
if ( 0 < indx[node] )
{
u = f[indx[node]-1];
}
else
{
exact ( x, y, &u, &dudx, &dudy );
}
output << setw(14) << u << "\n";
}
output.close ( );
return;
}
//****************************************************************************80
void timestamp ( void )
//****************************************************************************80
//
// Purpose:
//
// TIMESTAMP prints the current YMDHMS date as a time stamp.
//
// Example:
//
// May 31 2001 09:45:54 AM
//
// Modified:
//
// 24 September 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// None
//
{
# define TIME_SIZE 40
static char time_buffer[TIME_SIZE];
const struct tm *tm;
size_t len;
time_t now;
now = time ( NULL );
tm = localtime ( &now );
len = strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm );
cout << time_buffer << "\n";
return;
# undef TIME_SIZE
}
//****************************************************************************80
char *timestring ( void )
//****************************************************************************80
//
// Purpose:
//
// TIMESTRING returns the current YMDHMS date as a string.
//
// Example:
//
// May 31 2001 09:45:54 AM
//
// Modified:
//
// 24 September 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Output, char *TIMESTRING, a string containing the current YMDHMS date.
//
{
# define TIME_SIZE 40
const struct tm *tm;
size_t len;
time_t now;
char *s;
now = time ( NULL );
tm = localtime ( &now );
s = new char[TIME_SIZE];
len = strftime ( s, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm );
return s;
# undef TIME_SIZE
}
//****************************************************************************80
void triangulation_order6_plot ( char *file_name, int node_num, double node_xy[],
int tri_num, int triangle_node[], int node_show, int triangle_show )
//****************************************************************************80
//
// Purpose:
//
// TRIANGULATION_ORDER6_PLOT plots a 6-node triangulation of a pointset.
//
// Discussion:
//
// The triangulation is most usually a Delaunay triangulation,
// but this is not necessary.
//
// This routine has been specialized to deal correctly ONLY with
// a mesh of 6 node elements, with the property that starting
// from local node 1 and traversing the edges of the element will
// result in encountering local nodes 1, 4, 2, 5, 3, 6 in that order.
//
// Modified:
//
// 27 September 2006
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, char *FILE_NAME, the name of the file to create.
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, double precision NODE_XY[2*NODE_NUM], the nodes.
//
// Input, int TRI_NUM, the number of triangles.
//
// Input, int TRIANGLE_NODE[6*TRI_NUM], lists, for each triangle,
// the indices of the points that form the vertices and midsides
// of the triangle.
//
// Input, int NODE_SHOW:
// 0, do not show nodes;
// 1, show nodes;
// 2, show nodes and label them.
//
// Input, int TRIANGLE_SHOW:
// 0, do not show triangles;
// 1, show triangles;
// 2, show triangles and label them.
//
{
double ave_x;
double ave_y;
int circle_size;
char *date_time;
int delta;
ofstream file_unit;
int i;
int ip1;
int node;
int order[6] = { 1, 4, 2, 5, 3, 6 };
int triangle;
double x_max;
double x_min;
int x_ps;
int x_ps_max = 576;
int x_ps_max_clip = 594;
int x_ps_min = 36;
int x_ps_min_clip = 18;
double x_scale;
double y_max;
double y_min;
int y_ps;
int y_ps_max = 666;
int y_ps_max_clip = 684
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -