예제 #1
0
void exact ( double alpha[], double beta[], double f[], int np, int nprint,
  int problem, int quad_num, double quad_w[], double quad_x[] )

/******************************************************************************/
/*
  Purpose:

    EXACT compares the computed and exact solutions.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    04 July 2013

  Author:

    Original FORTRAN77 version by Max Gunzburger, Teresa Hodge.
    C version by John Burkardt.

  Parameters:

    Input, double ALPHA(NP), BETA(NP), the basis function 
    recurrence coefficients.

    Input, double F(0:NP).
    F contains the basis function coefficients that form the
    representation of the solution U.  That is,
      U(X)  =  SUM (I=0 to NP) F(I) * BASIS(I)(X)
    where "BASIS(I)(X)" means the I-th basis function
    evaluated at the point X.

    Input, int NP.
    The highest degree polynomial to use.

    Input, int NPRINT.
    The number of points at which the computed solution
    should be printed out at the end of the computation.

    Input, int PROBLEM, indicates the problem being solved.
    1, U=1-x^4, P=1, Q=1, F=1.0+12.0*x^2-x^4.
    2, U=cos(0.5*pi*x), P=1, Q=0, F=0.25*pi*pi*cos(0.5*pi*x).

    Input, int QUAD_NUM, the order of the quadrature rule.

    Input, double QUAD_W(QUAD_NUM), the quadrature weights.

    Input, double QUAD_X(QUAD_NUM), the quadrature abscissas.
*/
{
  double big_l2;
  double error;
  int i;
  int ip;
  int j;
  int k;
  int nsub = 10;
  double phii;
  double phiix;
  double ue;
  double up;
  double x;
  double xl;
  double xr;

  printf ( "\n" );
  printf ( "  Comparison of computed and exact solutions:\n" );
  printf ( "\n" );
  printf ( "    X        U computed    U exact     Difference\n" );
  printf ( "\n" );

  for ( i = 0; i <= nprint; i++ )
  {
    x = ( double ) ( 2 * i - nprint ) / ( double ) ( nprint );
    ue = uex ( x, problem );
    up = 0.0;
    for ( j = 0; j <= np; j++ )
    {
      phi ( alpha, beta, j, np, &phii, &phiix, x );
      up = up + phii * f[j];
    }
    printf ( "  %8g  %12g  %12g  %12g\n", x, up, ue, ue - up );
  }
/*
  Compute the big L2 error.
*/
  big_l2 = 0.0;

  for ( i = 1; i <= nsub; i++ )
  {
    xl = ( double ) ( 2 * i - nsub - 1 ) / ( double ) ( nsub );
    xr = ( double ) ( 2 * i - nsub     ) / ( double ) ( nsub );

    for ( j = 0; j < quad_num; j++ )
    {
      x = ( xl * ( 1.0 - quad_x[j] )
          + xr * ( 1.0 + quad_x[j] ) ) / 2.0;

      up = 0.0;
      for ( k = 0; k <= np; k++ )
      {
        phi ( alpha, beta, k, np, &phii, &phiix, x );
        up = up + phii * f[k];
      }

      big_l2 = big_l2 + pow ( up - uex ( x, problem ), 2 ) * quad_w[j]
        * ( xr - xl ) / 2.0;
    }
  }

  big_l2 = sqrt ( big_l2 );

  printf ( "\n" );
  printf ( "  Big L2 error = %g\n", big_l2 );

  return;
}
예제 #2
0
//-----------------------------------------------------------------------------
void
Supplier::publishEvent(const CosNotification::StructuredEvent &event)
{
    //First a sanity check.
    if(CORBA::is_nil(proxyConsumer_m.in()) == true)
	{
    	acsncErrType::PublishEventFailureExImpl ex(__FILE__, __LINE__, "nc::Supplier::publishEvent");
    	ex.setChannelName(channelName_mp);
    	ex.log(LM_DEBUG);
    	throw ex;
	}//if

    CosNotification::StructuredEvent *tmp;
    try
    {
       while( (tmp = eventBuff.front()) != NULL){
          proxyConsumer_m->push_structured_event(*tmp);
          eventBuff.pop();
          delete tmp;
       }
    	// Invoke a method on consumer proxy
    	proxyConsumer_m->push_structured_event(event);
    }
    catch(CORBA::TRANSIENT &ex)
    {
       /* Probably the Notify Service is down.
        * It can be recovery starting the service again.
        * The supplier will store the events.
        */
       eventBuff.push(event);
	   throw ex;
    }
    catch(CosEventComm::Disconnected &ex)
    {
    	ACSErrTypeCommon::CORBAProblemExImpl cex(__FILE__, __LINE__, "nc::SimpleSupplier::publishEvent");
    	cex.setInfo(ex._info().c_str());

    	acsncErrType::PublishEventFailureExImpl ex(cex, __FILE__, __LINE__, "nc::Supplier::publishEvent");
    	ex.setChannelName(channelName_mp);
    	ex.log(LM_DEBUG);
    	throw ex;
    }
    catch(CORBA::SystemException &ex)
    {
    	ACSErrTypeCommon::CORBAProblemExImpl cex(__FILE__, __LINE__, "nc::SimpleSupplier::publishEvent");
    	cex.setMinor(ex.minor());
    	cex.setCompletionStatus(ex.completed());
    	cex.setInfo(ex._info().c_str());

    	acsncErrType::PublishEventFailureExImpl ex(cex, __FILE__, __LINE__, "nc::Supplier::publishEvent");
    	ex.setChannelName(channelName_mp);
    	ex.log(LM_DEBUG);
    	throw ex;
    }
    catch(std::exception &ex)
        {
        	ACSErrTypeCommon::StdExceptionExImpl stdex(__FILE__, __LINE__, "nc::SimpleSupplier::publishEvent");
        	stdex.setWhat(ex.what());

        	acsncErrType::PublishEventFailureExImpl ex(stdex, __FILE__, __LINE__, "nc::Supplier::publishEvent");
        	ex.setChannelName(channelName_mp);
        	ex.log(LM_DEBUG);
        	throw ex;
        }
    catch(...)
    {
    	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, "nc::Supplier::publishEvent");

    	acsncErrType::PublishEventFailureExImpl ex(uex, __FILE__, __LINE__, "nc::Supplier::publishEvent");
    	ex.setChannelName(channelName_mp);
    	ex.log(LM_DEBUG);
    	throw ex;
    }//try-catch
}//publishEvent