예제 #1
0
QRectF DebugPropertyItem::boundingRect() const
  {
  qreal penWidth = 1;
  QSizeF size = _info.size();

  QRectF bnds(-5 - (penWidth / 2), - 5 - (penWidth / 2), size.width() + 10 + penWidth, size.height() + 10  + penWidth);

  return bnds;
  }
예제 #2
0
//-*****************************************************************************
void OCurvesSchema::set( const OCurvesSchema::Sample &iSamp )
{
    ALEMBIC_ABC_SAFE_CALL_BEGIN( "OCurvesSchema::set()" );

    Alembic::Util::uint8_t basisAndType[4];
    basisAndType[0] = iSamp.getType();
    basisAndType[1] = iSamp.getWrap();
    basisAndType[2] = iSamp.getBasis();

    // repeat so we don't have to change the data layout and bump up
    // the version number
    basisAndType[3] = basisAndType[2];

    // do we need to create velocities prop?
    if ( iSamp.getVelocities() && !m_velocitiesProperty )
    {
        m_velocitiesProperty = Abc::OV3fArrayProperty( this->getPtr(),
            ".velocities", m_positionsProperty.getTimeSampling() );

        std::vector<V3f> emptyVec;
        const V3fArraySample empty(emptyVec);
        const size_t numSamps = m_positionsProperty.getNumSamples();
        for ( size_t i = 0 ; i < numSamps ; ++i )
        {
            m_velocitiesProperty.set( empty );
        }
    }

    // do we need to create uvs?
    if ( iSamp.getUVs() && !m_uvsParam )
    {
        std::vector<V2f> emptyVals;
        std::vector<Util::uint32_t> emptyIndices;

        OV2fGeomParam::Sample empty;

        if ( iSamp.getUVs().getIndices() )
        {
            empty = OV2fGeomParam::Sample( Abc::V2fArraySample( emptyVals ),
                Abc::UInt32ArraySample( emptyIndices ),
                iSamp.getUVs().getScope() );

            // UVs are indexed
            m_uvsParam = OV2fGeomParam( this->getPtr(), "uv", true,
                                        empty.getScope(), 1,
                                        this->getTimeSampling() );
        }
        else
        {
            empty = OV2fGeomParam::Sample( Abc::V2fArraySample( emptyVals ),
                                           iSamp.getUVs().getScope() );

            // UVs are not indexed
            m_uvsParam = OV2fGeomParam( this->getPtr(), "uv", false,
                                   empty.getScope(), 1,
                                   this->getTimeSampling() );
        }

        size_t numSamples = m_positionsProperty.getNumSamples();

        // set all the missing samples
        for ( size_t i = 0; i < numSamples; ++i )
        {
            m_uvsParam.set( empty );
        }
    }

    // do we need to create normals?
    if ( iSamp.getNormals() && !m_normalsParam )
    {
        std::vector<V3f> emptyVals;
        std::vector<Util::uint32_t> emptyIndices;

        ON3fGeomParam::Sample empty;

        if ( iSamp.getNormals().getIndices() )
        {
            empty = ON3fGeomParam::Sample( Abc::V3fArraySample( emptyVals ),
                Abc::UInt32ArraySample( emptyIndices ),
                iSamp.getNormals().getScope() );

            // normals are indexed
            m_normalsParam = ON3fGeomParam( this->getPtr(), "N", true,
                empty.getScope(), 1, this->getTimeSampling() );
        }
        else
        {
            empty = ON3fGeomParam::Sample( Abc::V3fArraySample( emptyVals ),
                                           iSamp.getNormals().getScope() );

            // normals are not indexed
            m_normalsParam = ON3fGeomParam( this->getPtr(), "N", false,
                                        empty.getScope(), 1,
                                        this->getTimeSampling() );
        }

        size_t numSamples = m_positionsProperty.getNumSamples();

        // set all the missing samples
        for ( size_t i = 0; i < numSamples; ++i )
        {
            m_normalsParam.set( empty );
        }
    }

    // do we need to create widths?
    if ( iSamp.getWidths().getVals() && !m_widthsParam )
    {
        std::vector<float> emptyVals;
        std::vector<Util::uint32_t> emptyIndices;
        OFloatGeomParam::Sample empty;

        if ( iSamp.getWidths().getIndices() )
        {
            empty = OFloatGeomParam::Sample( Abc::FloatArraySample( emptyVals ),
                Abc::UInt32ArraySample( emptyIndices ),
                iSamp.getWidths().getScope() );

            // widths are indexed for some weird reason which is
            // technically ok, just wasteful
            m_widthsParam = OFloatGeomParam( this->getPtr(), "width", true,
                                             iSamp.getWidths().getScope(),
                                             1, this->getTimeSampling() );
        }
        else
        {
            empty = OFloatGeomParam::Sample( Abc::FloatArraySample( emptyVals ),
                                             iSamp.getWidths().getScope() );

            // widths are not indexed
            m_widthsParam = OFloatGeomParam( this->getPtr(), "width", false,
                                             iSamp.getWidths().getScope(), 1,
                                             this->getTimeSampling() );
        }

        size_t numSamples = m_positionsProperty.getNumSamples();

        // set all the missing samples
        for ( size_t i = 0; i < numSamples; ++i )
        {
            m_widthsParam.set( empty );
        }
    }

    if ( iSamp.getPositionWeights() && !m_positionWeightsProperty)
    {
        m_positionWeightsProperty = Abc::OFloatArrayProperty( *this, "w",
            this->getTimeSampling() );

        std::vector<float> emptyVec;
        Alembic::Abc::FloatArraySample emptySamp( emptyVec );

        size_t numSamples = m_positionsProperty.getNumSamples();

        // set all the missing samples
        for ( size_t i = 0; i < numSamples; ++i )
        {
            m_positionWeightsProperty.set( emptySamp );
        }
    }

    if ( iSamp.getOrders() && !m_ordersProperty)
    {
        m_ordersProperty = Abc::OUcharArrayProperty( *this, ".orders",
                                                     this->getTimeSampling() );

        std::vector<uint8_t> emptyVec;
        Alembic::Abc::UcharArraySample emptySamp( emptyVec );

        size_t numSamples = m_positionsProperty.getNumSamples();

        // set all the missing samples
        for ( size_t i = 0; i < numSamples; ++i )
        {
            m_ordersProperty.set( emptySamp );
        }
    }

    if ( iSamp.getKnots() && !m_knotsProperty)
    {
        m_knotsProperty = Abc::OFloatArrayProperty( *this, ".knots",
            this->getTimeSampling() );

        std::vector<float> emptyVec;
        Alembic::Abc::FloatArraySample emptySamp( emptyVec );

        size_t numSamples = m_positionsProperty.getNumSamples();

        // set all the missing samples
        for ( size_t i = 0; i < numSamples; ++i )
        {
            m_knotsProperty.set( emptySamp );
        }
    }

    // We could add sample integrity checking here.
    if ( m_positionsProperty.getNumSamples() == 0 )
    {
        // First sample must be valid on all points.
        ABCA_ASSERT( iSamp.getPositions(),
                     "Sample 0 must have valid data for all mesh components" );

        m_positionsProperty.set( iSamp.getPositions() );
        m_nVerticesProperty.set( iSamp.getCurvesNumVertices() );

        m_basisAndTypeProperty.set( basisAndType );

        if ( m_velocitiesProperty )
        { m_velocitiesProperty.set( iSamp.getVelocities() ); }

        if ( iSamp.getSelfBounds().isEmpty() )
        {
            // OTypedScalarProperty::set() is not referentially transparent,
            // so we need a a placeholder variable.
            Abc::Box3d bnds(
                ComputeBoundsFromPositions( iSamp.getPositions() )
                           );

            m_selfBoundsProperty.set( bnds );

        }
        else { m_selfBoundsProperty.set( iSamp.getSelfBounds() ); }

        // process uvs
        if ( iSamp.getUVs() )
        {
            m_uvsParam.set( iSamp.getUVs() );
        }

        // process normals
        if ( iSamp.getNormals() )
        {
            m_normalsParam.set( iSamp.getNormals() );
        }

        // process widths
        if ( iSamp.getWidths() )
        {
            m_widthsParam.set( iSamp.getWidths() );
        }

        // process position weights
        if ( iSamp.getPositionWeights() )
        {
            m_positionWeightsProperty.set( iSamp.getPositionWeights() );
        }

        // process orders
        if ( iSamp.getOrders() )
        {
            m_ordersProperty.set( iSamp.getOrders() );
        }

        // process knots
        if ( iSamp.getKnots() )
        {
            m_knotsProperty.set( iSamp.getKnots() );
        }
    }
    else
    {
        SetPropUsePrevIfNull( m_positionsProperty, iSamp.getPositions() );
        SetPropUsePrevIfNull( m_nVerticesProperty, iSamp.getCurvesNumVertices() );

        // if number of vertices were specified, then the basis and type
        // was specified
        if ( m_nVerticesProperty )
        {
            m_basisAndTypeProperty.set( basisAndType );
        }
        else
        {
            m_basisAndTypeProperty.setFromPrevious();
        }

        if ( m_velocitiesProperty )
        { SetPropUsePrevIfNull( m_velocitiesProperty, iSamp.getVelocities() ); }

        if ( m_uvsParam )
        { m_uvsParam.set( iSamp.getUVs() ); }

        if ( m_normalsParam )
        { m_normalsParam.set( iSamp.getNormals() ); }

        if ( m_widthsParam )
        { m_widthsParam.set( iSamp.getWidths() ); }

        if ( m_positionWeightsProperty )
        {
            SetPropUsePrevIfNull( m_positionWeightsProperty,
                                  iSamp.getPositionWeights() );
        }

        if ( m_ordersProperty )
        {
            SetPropUsePrevIfNull( m_ordersProperty, iSamp.getOrders() );
        }

        if ( m_knotsProperty )
        {
            SetPropUsePrevIfNull( m_knotsProperty, iSamp.getKnots() );
        }

        // update bounds
        if ( iSamp.getSelfBounds().hasVolume() )
        {
            m_selfBoundsProperty.set( iSamp.getSelfBounds() );
        }
        else if ( iSamp.getPositions() )
        {
            Abc::Box3d bnds(
                ComputeBoundsFromPositions( iSamp.getPositions() )
                           );
            m_selfBoundsProperty.set( bnds );
        }
        else
        {
            m_selfBoundsProperty.setFromPrevious();
        }
    }

    ALEMBIC_ABC_SAFE_CALL_END();
}
void
ThermalContactMaterialsAction::act()
{
  if (getParam<std::string>("type") != "GapHeatTransfer")
  {
    return;
  }

  const bool quadrature = getParam<bool>("quadrature");

  const std::string type("GapConductance");

  InputParameters params = _factory.getValidParams(type);
  // Extract global params
  _app.parser().extractParams(_name, params);

  params.set<std::vector<VariableName> >("variable") = std::vector<VariableName>(1, getParam<NonlinearVariableName>("variable"));

  if (!quadrature)
  {
    params.set<std::vector<VariableName> >("gap_temp") = std::vector<VariableName>(1, ThermalContactAuxVarsAction::getGapValueName(_pars));
    std::vector<VariableName> vars(1);
    vars[0] = "penetration";
    params.set<std::vector<VariableName> >("gap_distance") = vars;
  }
  else
  {
    params.set<bool>("quadrature") = true;

    params.set<BoundaryName>("paired_boundary") = getParam<BoundaryName>("master");

    params.set<MooseEnum>("order") = getParam<MooseEnum>("order");
  }

  params.set<bool>("warnings") = getParam<bool>("warnings");

  params.set<Real>("gap_conductivity") = getParam<Real>("gap_conductivity");
  if (isParamValid("gap_conductivity_function"))
    params.set<FunctionName>("gap_conductivity_function") = getParam<FunctionName>("gap_conductivity_function");

  if (isParamValid("gap_conductivity_function_variable"))
    params.set<std::vector<VariableName> >("gap_conductivity_function_variable") = std::vector<VariableName>(1, getParam<VariableName>("gap_conductivity_function_variable"));

  std::vector<BoundaryName> bnds(1, getParam<BoundaryName>("slave"));
  params.set<std::vector<BoundaryName> >("boundary") = bnds;
  params.set<std::string>("appended_property_name") = getParam<std::string>("appended_property_name");

  params.set<std::string>("conductivity_name") = getParam<std::string>("conductivity_name");

  std::string name;
  name += "Materials/" + _name + "_" + "gap_value_" + Moose::stringify(n);
  _problem->addMaterial(type, name, params);

  if (quadrature)
  {
    params.set<BoundaryName>("paired_boundary") = getParam<BoundaryName>("slave");

    std::vector<BoundaryName> bnds(1, getParam<BoundaryName>("master"));
    params.set<std::vector<BoundaryName> >("boundary") = bnds;

    params.set<std::string>("conductivity_name") = getParam<std::string>("conductivity_master_name");

    std::string master_name;
    master_name += "Materials/" + _name + "_" + "gap_value_master_" + Moose::stringify(n);
    _problem->addMaterial(type, master_name, params);
  }

  ++n;
}
예제 #4
0
int main()
{
    const unsigned int VEC_SIZE = 2;
    const unsigned int POP_SIZE = 20;
    const unsigned int NEIGHBORHOOD_SIZE= 5;
    unsigned i;

    // the population:
    eoPop<Particle> pop;

    // Evaluation
    eoEvalFuncPtr<Particle, double, const Particle& > eval(  real_value );

    // position init
    eoUniformGenerator < double >uGen (-3, 3);
    eoInitFixedLength < Particle > random (VEC_SIZE, uGen);

    // velocity init
    eoUniformGenerator < double >sGen (-2, 2);
    eoVelocityInitFixedLength < Particle > veloRandom (VEC_SIZE, sGen);

    // local best init
    eoFirstIsBestInit < Particle > localInit;

    // perform position initialization
    pop.append (POP_SIZE, random);
  
    // topology
    eoLinearTopology<Particle> topology(NEIGHBORHOOD_SIZE);

	// the full initializer
    eoInitializer <Particle> init(eval,veloRandom,localInit,topology,pop);
    init();
    
   
    // bounds
    eoRealVectorBounds bnds(VEC_SIZE,-1.5,1.5);

    // velocity
    eoStandardVelocity <Particle> velocity (topology,1,1.6,2,bnds);

    // flight
    eoStandardFlight <Particle> flight;

    // Terminators
    eoGenContinue <Particle> genCont1 (50);
	eoGenContinue <Particle> genCont2 (50);
	
    // PS flight
    eoEasyPSO<Particle> pso1(genCont1, eval, velocity, flight);

	eoEasyPSO<Particle> pso2(init,genCont2, eval, velocity, flight);
    
    // flight
    try
    {
        pso1(pop);
        std::cout << "FINAL POPULATION AFTER PSO n°1:" << std::endl;
    	for (i = 0; i < pop.size(); ++i)
        	std::cout << "\t" <<  pop[i] << " " << pop[i].fitness() << std::endl;
        
        pso2(pop);
         std::cout << "FINAL POPULATION AFTER PSO n°2:" << std::endl;
    	for (i = 0; i < pop.size(); ++i)
        	std::cout << "\t" <<  pop[i] << " " << pop[i].fitness() << std::endl;
    }
    catch (std::exception& e)
    {
        std::cout << "exception: " << e.what() << std::endl;;
        exit(EXIT_FAILURE);
    }

   

    return 0;
}
예제 #5
0
/*
=====================
idAI::PredictTrajectory

  returns true if there is a collision free trajectory for the clip model
  aimDir is set to the ideal aim direction in order to hit the target
=====================
*/
bool idAI::PredictTrajectory( const idVec3 &firePos, const idVec3 &target, float projectileSpeed, const idVec3 &projGravity, const idClipModel *clip, int clipmask, float max_height, const idEntity *ignore, const idEntity *targetEntity, int drawtime, idVec3 &aimDir ) {
	int n, i, j;
	float zVel, a, t, pitch, s, c;
	trace_t trace;
	ballistics_t ballistics[2];
	idVec3 dir[2];
	idVec3 velocity;
	idVec3 lastPos, pos;

	assert( targetEntity );

	// check if the projectile starts inside the target
	if ( targetEntity->GetPhysics()->GetAbsBounds().IntersectsBounds( clip->GetBounds().Translate( firePos ) ) ) {
		aimDir = target - firePos;
		aimDir.Normalize();
		return true;
	}

	// if no velocity or the projectile is not affected by gravity
	if ( projectileSpeed <= 0.0f || projGravity == vec3_origin ) {

		aimDir = target - firePos;
		aimDir.Normalize();

		gameLocal.clip.Translation( trace, firePos, target, clip, mat3_identity, clipmask, ignore );

		if ( drawtime ) {
			gameRenderWorld->DebugLine( colorRed, firePos, target, drawtime );
			idBounds bnds( trace.endpos );
			bnds.ExpandSelf( 1.0f );
			gameRenderWorld->DebugBounds( ( trace.fraction >= 1.0f || ( gameLocal.GetTraceEntity( trace ) == targetEntity ) ) ? colorGreen : colorYellow, bnds, vec3_zero, drawtime );
		}

		return ( trace.fraction >= 1.0f || ( gameLocal.GetTraceEntity( trace ) == targetEntity ) );
	}

	n = Ballistics( firePos, target, projectileSpeed, projGravity[2], ballistics );
	if ( n == 0 ) {
		// there is no valid trajectory
		aimDir = target - firePos;
		aimDir.Normalize();
		return false;
	}

	// make sure the first angle is the smallest
	if ( n == 2 ) {
		if ( ballistics[1].angle < ballistics[0].angle ) {
			a = ballistics[0].angle; ballistics[0].angle = ballistics[1].angle; ballistics[1].angle = a;
			t = ballistics[0].time; ballistics[0].time = ballistics[1].time; ballistics[1].time = t;
		}
	}

	// test if there is a collision free trajectory
	for ( i = 0; i < n; i++ ) {
		pitch = DEG2RAD( ballistics[i].angle );
		idMath::SinCos( pitch, s, c );
		dir[i] = target - firePos;
		dir[i].z = 0.0f;
		dir[i] *= c * idMath::InvSqrt( dir[i].LengthSqr() );
		dir[i].z = s;

		zVel = projectileSpeed * dir[i].z;

		if ( ai_debugTrajectory.GetBool() ) {
			t = ballistics[i].time / 100.0f;
			velocity = dir[i] * projectileSpeed;
			lastPos = firePos;
			pos = firePos;
			for ( j = 1; j < 100; j++ ) {
				pos += velocity * t;
				velocity += projGravity * t;
				gameRenderWorld->DebugLine( colorCyan, lastPos, pos );
				lastPos = pos;
			}
		}

		if ( TestTrajectory( firePos, target, zVel, projGravity[2], ballistics[i].time, firePos.z + max_height, clip, clipmask, ignore, targetEntity, drawtime ) ) {
			aimDir = dir[i];
			return true;
		}
	}

	aimDir = dir[0];

	// there is no collision free trajectory
	return false;
}
예제 #6
0
/*
=====================
idAI::TestTrajectory
=====================
*/
bool idAI::TestTrajectory( const idVec3 &start, const idVec3 &end, float zVel, float gravity, float time, float max_height, const idClipModel *clip, int clipmask, const idEntity *ignore, const idEntity *targetEntity, int drawtime ) {
	int i, numSegments;
	float maxHeight, t, t2;
	idVec3 points[5];
	trace_t trace;
	bool result;

	t = zVel / gravity;
	// maximum height of projectile
	maxHeight = start.z - 0.5f * gravity * ( t * t );
	// time it takes to fall from the top to the end height
	t = idMath::Sqrt( ( maxHeight - end.z ) / ( 0.5f * -gravity ) );

	// start of parabolic
	points[0] = start;

	if ( t < time ) {
		numSegments = 4;
		// point in the middle between top and start
		t2 = ( time - t ) * 0.5f;
		points[1].ToVec2() = start.ToVec2() + (end.ToVec2() - start.ToVec2()) * ( t2 / time );
		points[1].z = start.z + t2 * zVel + 0.5f * gravity * t2 * t2;
		// top of parabolic
		t2 = time - t;
		points[2].ToVec2() = start.ToVec2() + (end.ToVec2() - start.ToVec2()) * ( t2 / time );
		points[2].z = start.z + t2 * zVel + 0.5f * gravity * t2 * t2;
		// point in the middel between top and end
		t2 = time - t * 0.5f;
		points[3].ToVec2() = start.ToVec2() + (end.ToVec2() - start.ToVec2()) * ( t2 / time );
		points[3].z = start.z + t2 * zVel + 0.5f * gravity * t2 * t2;
	} else {
		numSegments = 2;
		// point halfway through
		t2 = time * 0.5f;
		points[1].ToVec2() = start.ToVec2() + ( end.ToVec2() - start.ToVec2() ) * 0.5f;
		points[1].z = start.z + t2 * zVel + 0.5f * gravity * t2 * t2;
	}

	// end of parabolic
	points[numSegments] = end;

	if ( drawtime ) {
		for ( i = 0; i < numSegments; i++ ) {
			gameRenderWorld->DebugLine( colorRed, points[i], points[i+1], drawtime );
		}
	}

	// make sure projectile doesn't go higher than we want it to go
	for ( i = 0; i < numSegments; i++ ) {
		if ( points[i].z > max_height ) {
			// goes higher than we want to allow
			return false;
		}
	}

	result = true;
	for ( i = 0; i < numSegments; i++ ) {
		gameLocal.clip.Translation( trace, points[i], points[i+1], clip, mat3_identity, clipmask, ignore );
		if ( trace.fraction < 1.0f ) {
			if ( gameLocal.GetTraceEntity( trace ) == targetEntity ) {
				result = true;
			} else {
				result = false;
			}
			break;
		}
	}

	if ( drawtime ) {
		if ( clip ) {
			gameRenderWorld->DebugBounds( result ? colorGreen : colorYellow, clip->GetBounds().Expand( 1.0f ), trace.endpos, drawtime );
		} else {
			idBounds bnds( trace.endpos );
			bnds.ExpandSelf( 1.0f );
			gameRenderWorld->DebugBounds( result ? colorGreen : colorYellow, bnds, vec3_zero, drawtime );
		}
	}

	return result;
}
//-*****************************************************************************
void OCurvesSchema::set( const OCurvesSchema::Sample &iSamp )
{
    if( m_selectiveExport || iSamp.isPartialSample() )
    {
        selectiveSet( iSamp );
        return;
    }

    ALEMBIC_ABC_SAFE_CALL_BEGIN( "OCurvesSchema::set()" );

    Alembic::Util::uint8_t basisAndType[4];
    calcBasisAndType( basisAndType, iSamp );

    if ( iSamp.getVelocities() && !m_velocitiesProperty )
    {
        createVelocityProperty();
    }

    if ( iSamp.getUVs() && !m_uvsParam )
    {
        createUVsProperty( iSamp );
    }

    if ( iSamp.getNormals() && !m_normalsParam )
    {
        createNormalsProperty( iSamp );
    }

    if ( iSamp.getWidths().getVals() && !m_widthsParam )
    {
        createWidthProperty( iSamp );
    }

    if ( iSamp.getPositionWeights() && !m_positionWeightsProperty)
    {
        createPositionWeightsProperty();
    }

    if ( iSamp.getOrders() && !m_ordersProperty)
    {
        createOrdersProperty();
    }

    if ( iSamp.getKnots() && !m_knotsProperty)
    {
        createKnotsProperty();
    }

    // We could add sample integrity checking here.
    if ( m_numSamples == 0 )
    {
        // First sample must be valid on all points.
        ABCA_ASSERT( iSamp.getPositions(),
                     "Sample 0 must have valid data for all mesh components" );

        m_positionsProperty.set( iSamp.getPositions() );
        m_nVerticesProperty.set( iSamp.getCurvesNumVertices() );

        m_basisAndTypeProperty.set( basisAndType );

        if ( m_velocitiesProperty )
        { m_velocitiesProperty.set( iSamp.getVelocities() ); }

        if ( iSamp.getSelfBounds().isEmpty() )
        {
            // OTypedScalarProperty::set() is not referentially transparent,
            // so we need a a placeholder variable.
            Abc::Box3d bnds(
                ComputeBoundsFromPositions( iSamp.getPositions() )
                           );

            m_selfBoundsProperty.set( bnds );

        }
        else { m_selfBoundsProperty.set( iSamp.getSelfBounds() ); }

        // process uvs
        if ( iSamp.getUVs() )
        {
            m_uvsParam.set( iSamp.getUVs() );
        }

        // process normals
        if ( iSamp.getNormals() )
        {
            m_normalsParam.set( iSamp.getNormals() );
        }

        // process widths
        if ( iSamp.getWidths() )
        {
            m_widthsParam.set( iSamp.getWidths() );
        }

        // process position weights
        if ( iSamp.getPositionWeights() )
        {
            m_positionWeightsProperty.set( iSamp.getPositionWeights() );
        }

        // process orders
        if ( iSamp.getOrders() )
        {
            m_ordersProperty.set( iSamp.getOrders() );
        }

        // process knots
        if ( iSamp.getKnots() )
        {
            m_knotsProperty.set( iSamp.getKnots() );
        }
    }
    else
    {
        SetPropUsePrevIfNull( m_positionsProperty, iSamp.getPositions() );
        SetPropUsePrevIfNull( m_nVerticesProperty, iSamp.getCurvesNumVertices() );

        // if number of vertices were specified, then the basis and type
        // was specified
        if ( m_nVerticesProperty )
        {
            m_basisAndTypeProperty.set( basisAndType );
        }
        else
        {
            m_basisAndTypeProperty.setFromPrevious();
        }

        if ( m_velocitiesProperty )
        { SetPropUsePrevIfNull( m_velocitiesProperty, iSamp.getVelocities() ); }

        if ( m_uvsParam )
        { m_uvsParam.set( iSamp.getUVs() ); }

        if ( m_normalsParam )
        { m_normalsParam.set( iSamp.getNormals() ); }

        if ( m_widthsParam )
        { m_widthsParam.set( iSamp.getWidths() ); }

        if ( m_positionWeightsProperty )
        {
            SetPropUsePrevIfNull( m_positionWeightsProperty,
                                  iSamp.getPositionWeights() );
        }

        if ( m_ordersProperty )
        {
            SetPropUsePrevIfNull( m_ordersProperty, iSamp.getOrders() );
        }

        if ( m_knotsProperty )
        {
            SetPropUsePrevIfNull( m_knotsProperty, iSamp.getKnots() );
        }

        // update bounds
        if ( iSamp.getSelfBounds().hasVolume() )
        {
            m_selfBoundsProperty.set( iSamp.getSelfBounds() );
        }
        else if ( iSamp.getPositions() )
        {
            Abc::Box3d bnds(
                ComputeBoundsFromPositions( iSamp.getPositions() )
                           );
            m_selfBoundsProperty.set( bnds );
        }
        else
        {
            m_selfBoundsProperty.setFromPrevious();
        }
    }

    m_numSamples++;

    ALEMBIC_ABC_SAFE_CALL_END();
}
//-*****************************************************************************
void OCurvesSchema::selectiveSet( const OCurvesSchema::Sample &iSamp )
{
    ALEMBIC_ABC_SAFE_CALL_BEGIN( "OCurvesSchema::selectiveSet()" );

    Alembic::Util::uint8_t basisAndType[4];
    calcBasisAndType( basisAndType, iSamp );

    if ( iSamp.getPositions() && !m_positionsProperty )
    {
        createPositionProperty();
    }

    if ( m_positionsProperty )
    {
        SetPropUsePrevIfNull( m_positionsProperty, iSamp.getPositions() );

        if ( iSamp.getSelfBounds().hasVolume() )
        {
            m_selfBoundsProperty.set( iSamp.getSelfBounds() );
        }
        else if ( iSamp.getPositions() )
        {
            Abc::Box3d bnds(
                ComputeBoundsFromPositions( iSamp.getPositions() ) );
            m_selfBoundsProperty.set( bnds );
        }
        else
        {
            m_selfBoundsProperty.setFromPrevious();
        }
    }

    if( iSamp.getCurvesNumVertices() && !m_nVerticesProperty )
    {
        createVertexProperties();
    }

    if( m_nVerticesProperty )
    {
        SetPropUsePrevIfNull( m_nVerticesProperty, iSamp.getCurvesNumVertices() );
        m_basisAndTypeProperty.set( basisAndType );
    }

    if ( iSamp.getVelocities() && !m_velocitiesProperty )
    {
        createVelocityProperty();
    }

    if ( m_velocitiesProperty )
    {
        SetPropUsePrevIfNull( m_velocitiesProperty, iSamp.getVelocities() );
    }

    if ( iSamp.getUVs() && !m_uvsParam )
    {
        createUVsProperty( iSamp );
    }

    if ( m_uvsParam )
    {
        m_uvsParam.set( iSamp.getUVs() );
    }

    if ( iSamp.getNormals() && !m_normalsParam )
    {
        createNormalsProperty( iSamp );
    }

    if ( m_normalsParam )
    {
        m_normalsParam.set( iSamp.getNormals() );
    }

    if ( iSamp.getWidths().getVals() && !m_widthsParam )
    {
        createWidthProperty( iSamp );
    }

    if ( m_widthsParam )
    {
        m_widthsParam.set( iSamp.getWidths() );
    }

    if ( iSamp.getPositionWeights() && !m_positionWeightsProperty)
    {
        createPositionWeightsProperty();
    }

    if ( m_positionWeightsProperty )
    {
        SetPropUsePrevIfNull( m_positionWeightsProperty,
                              iSamp.getPositionWeights() );
    }

    if ( iSamp.getOrders() && !m_ordersProperty)
    {
        createOrdersProperty();
    }

    if ( m_ordersProperty )
    {
        SetPropUsePrevIfNull( m_ordersProperty, iSamp.getOrders() );
    }

    if ( iSamp.getKnots() && !m_knotsProperty)
    {
        createKnotsProperty();
    }

    if ( m_knotsProperty )
    {
        SetPropUsePrevIfNull( m_knotsProperty, iSamp.getKnots() );
    }

    m_numSamples++;

    ALEMBIC_ABC_SAFE_CALL_END();
}
예제 #9
0
int main (int __argc, char *__argv[])
{
  peo :: init( __argc, __argv );
  if (getNodeRank()==1)
    std::cout<<"\n\nTest : PSO Global Best\n\n";
  rng.reseed (10);
  RingTopology topologyMig;
  eoGenContinue < Indi > genContPara (10);
  eoCombinedContinue <Indi> continuatorPara (genContPara);
  eoCheckPoint<Indi> checkpoint(continuatorPara);
  peoEvalFunc<Indi, double, const Indi& > plainEval(f);
  peoPopEval< Indi > eval(plainEval);
  eoUniformGenerator < double >uGen (0, 1.);
  eoInitFixedLength < Indi > random (2, uGen);
  eoUniformGenerator < double >sGen (-1., 1.);
  eoVelocityInitFixedLength < Indi > veloRandom (2, sGen);
  eoFirstIsBestInit < Indi > localInit;
  eoRealVectorBounds bndsFlight(2,0,1.);
  eoStandardFlight < Indi > flight(bndsFlight);
  eoPop < Indi > pop;
  pop.append (10, random);
  eoLinearTopology<Indi> topology(2);
  eoRealVectorBounds bnds(2,-1.,1.);
  eoStandardVelocity < Indi > velocity (topology,1,0.5,2.,bnds);
  eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
  eoPeriodicContinue< Indi > mig_cont( 2 );
  peoPSOSelect<Indi> mig_selec(topology);
  peoGlobalBestVelocity<Indi> mig_replac (2.,velocity);
  eoContinuator<Indi> cont(mig_cont, pop);
  eoSelector <Indi, eoPop<Indi> > mig_select (mig_selec,1,pop);
  eoReplace <Indi, eoPop<Indi> > mig_replace (mig_replac,pop);
  eoGenContinue < Indi > genContPara2 (10);
  eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
  eoCheckPoint<Indi> checkpoint2(continuatorPara2);
  peoEvalFunc<Indi, double, const Indi& > plainEval2(f);
  peoPopEval< Indi > eval2(plainEval2);
  eoUniformGenerator < double >uGen2 (0, 1.);
  eoInitFixedLength < Indi > random2 (2, uGen2);
  eoUniformGenerator < double >sGen2 (-1., 1.);
  eoVelocityInitFixedLength < Indi > veloRandom2 (2, sGen2);
  eoFirstIsBestInit < Indi > localInit2;
  eoRealVectorBounds bndsFlight2(2,0,1.);
  eoStandardFlight < Indi > flight2(bndsFlight2);
  eoPop < Indi > pop2;
  pop2.append (10, random2);
  eoLinearTopology<Indi> topology2(2);
  eoRealVectorBounds bnds2(2,-1.,1.);
  eoStandardVelocity < Indi > velocity2 (topology2,1,0.5,2.,bnds2);
  eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2);
  eoPeriodicContinue< Indi > mig_cont2( 2 );
  peoPSOSelect<Indi> mig_selec2(topology2);
  peoGlobalBestVelocity<Indi> mig_replac2 (2.,velocity2);
  eoContinuator<Indi> cont2(mig_cont2,pop2);
  eoSelector <Indi, eoPop<Indi> > mig_select2 (mig_selec2,1,pop2);
  eoReplace <Indi, eoPop<Indi> > mig_replace2 (mig_replac2,pop2);
  peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig);
  checkpoint.add( mig );
  peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig);
  checkpoint2.add( mig2 );
  eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
  peoWrapper parallelPSO( psa, pop);
  eval.setOwner(parallelPSO);
  mig.setOwner(parallelPSO);
  eoSyncEasyPSO <Indi> psa2(init2,checkpoint2,eval2, velocity2, flight2);
  peoWrapper parallelPSO2( psa2, pop2);
  eval2.setOwner(parallelPSO2);
  mig2.setOwner(parallelPSO2);
  peo :: run();
  peo :: finalize();
  if (getNodeRank()==1)
    {
      pop.sort();
      pop2.sort();
      std::cout << "Final population :\n" << pop << std::endl;
      std::cout << "Final population :\n" << pop2	 << std::endl;
    }
}
예제 #10
0
void
ThermalContactBCsAction::act()
{
  bool quadrature = getParam<bool>("quadrature");

  InputParameters params = _factory.getValidParams(getParam<std::string>("type"));

  // Extract global params
  _app.parser().extractParams(_name, params);

  if(isParamValid("save_in"))
  {
    params.set<std::vector<std::string> >("save_in") = getParam<std::vector<std::string> >("save_in");
  }

  params.set<NonlinearVariableName>("variable") = getParam<NonlinearVariableName>("variable");

  if(!quadrature)
  {
    std::vector<VariableName> vars(1);
    vars[0] = "penetration";
    params.set<std::vector<VariableName> >("gap_distance") = vars;
    vars[0] = ThermalContactAuxVarsAction::getGapValueName(_pars);
    params.set<std::vector<VariableName> >("gap_temp") = vars;
  }
  else
  {
    params.set<bool>("quadrature") = true;
    params.set<BoundaryName>("paired_boundary") = getParam<BoundaryName>("master");
    params.set<MooseEnum>("order") = getParam<MooseEnum>("order");
    params.set<bool>("warnings") = getParam<bool>("warnings");
    params.set<bool>("use_displaced_mesh") = true;
  }

  std::vector<BoundaryName> bnds(1, getParam<BoundaryName>("slave"));
  params.set<std::vector<BoundaryName> >("boundary") = bnds;

  params.set<std::string>("appended_property_name") = getParam<std::string>("appended_property_name");

  if (isParamValid("disp_x"))
  {
    params.addCoupledVar("disp_x", "The x displacement");
    std::vector<VariableName> disp_x(1, getParam<VariableName>("disp_x"));
    params.set< std::vector<VariableName> >("disp_x") = disp_x;
  }
  if (isParamValid("disp_y"))
  {
    params.addCoupledVar("disp_y", "The y displacement");
    std::vector<VariableName> disp_y(1, getParam<VariableName>("disp_y"));
    params.set< std::vector<VariableName> >("disp_y") = disp_y;
  }
  if (isParamValid("disp_z"))
  {
    params.addCoupledVar("disp_z", "The z displacement");
    std::vector<VariableName> disp_z(1, getParam<VariableName>("disp_z"));
    params.set< std::vector<VariableName> >("disp_z") = disp_z;
  }

  _problem->addBoundaryCondition(getParam<std::string>("type"),
      "gap_bc_" + Moose::stringify(n),
      params);

  if(quadrature)
  {
    // Swap master and slave for this one
    std::vector<BoundaryName> bnds(1, getParam<BoundaryName>("master"));
    params.set<std::vector<BoundaryName> >("boundary") = bnds;
    params.set<BoundaryName>("paired_boundary") = getParam<BoundaryName>("slave");

    _problem->addBoundaryCondition(getParam<std::string>("type"),
        "gap_bc_master_" + Moose::stringify(n),
        params);
  }


  ++n;
}
예제 #11
0
//-*****************************************************************************
void OPolyMeshSchema::set( const Sample &iSamp )
{
    ALEMBIC_ABC_SAFE_CALL_BEGIN( "OPolyMeshSchema::set()" );

    // do we need to create velocities prop?
    if ( iSamp.getVelocities() && !m_velocitiesProperty )
    {
        m_velocitiesProperty = Abc::OV3fArrayProperty( this->getPtr(),
            ".velocities", m_positionsProperty.getTimeSampling() );

        std::vector<V3f> emptyVec;
        const V3fArraySample empty( emptyVec );
        const size_t numSamps = m_positionsProperty.getNumSamples();
        for ( size_t i = 0 ; i < numSamps ; ++i )
        {
            m_velocitiesProperty.set( empty );
        }
    }

    // do we need to create uvs?
    if ( iSamp.getUVs() && !m_uvsParam )
    {
        std::vector<V2f> emptyVals;
        std::vector<Util::uint32_t> emptyIndices;

        OV2fGeomParam::Sample empty;
        AbcA::MetaData mdata;
        SetSourceName( mdata, m_uvSourceName );

        if ( iSamp.getUVs().getIndices() )
        {
            empty = OV2fGeomParam::Sample( Abc::V2fArraySample( emptyVals ),
                Abc::UInt32ArraySample( emptyIndices ),
                iSamp.getUVs().getScope() );

            // UVs are indexed
            m_uvsParam = OV2fGeomParam( this->getPtr(), "uv", true,
                                   empty.getScope(), 1,
                                   this->getTimeSampling(), mdata );
        }
        else
        {
            empty = OV2fGeomParam::Sample( Abc::V2fArraySample( emptyVals ),
                                           iSamp.getUVs().getScope() );

            // UVs are not indexed
            m_uvsParam = OV2fGeomParam( this->getPtr(), "uv", false,
                                   empty.getScope(), 1,
                                   this->getTimeSampling() , mdata );
        }

        size_t numSamples = m_positionsProperty.getNumSamples();

        // set all the missing samples
        for ( size_t i = 0; i < numSamples; ++i )
        {
            m_uvsParam.set( empty );
        }
    }

    // do we need to create normals?
    if ( iSamp.getNormals() && !m_normalsParam )
    {
        std::vector<V3f> emptyVals;
        std::vector<Util::uint32_t> emptyIndices;

        ON3fGeomParam::Sample empty;

        if ( iSamp.getNormals().getIndices() )
        {
            empty = ON3fGeomParam::Sample( Abc::V3fArraySample( emptyVals ),
                Abc::UInt32ArraySample( emptyIndices ),
                iSamp.getNormals().getScope() );

            // normals are indexed
            m_normalsParam = ON3fGeomParam( this->getPtr(), "N", true,
                empty.getScope(), 1, this->getTimeSampling() );
        }
        else
        {
            empty = ON3fGeomParam::Sample( Abc::V3fArraySample( emptyVals ),
                                           iSamp.getNormals().getScope() );

            // normals are not indexed
            m_normalsParam = ON3fGeomParam( this->getPtr(), "N", false,
                                        empty.getScope(), 1,
                                        this->getTimeSampling() );
        }

        size_t numSamples = m_positionsProperty.getNumSamples();

        // set all the missing samples
        for ( size_t i = 0; i < numSamples; ++i )
        {
            m_normalsParam.set( empty );
        }
    }

    // We could add sample integrity checking here.
    if ( m_positionsProperty.getNumSamples() == 0 )
    {
        // First sample must be valid on all points.
        ABCA_ASSERT( iSamp.getPositions() &&
                     iSamp.getFaceIndices() &&
                     iSamp.getFaceCounts(),
                     "Sample 0 must have valid data for all mesh components" );

        m_positionsProperty.set( iSamp.getPositions() );
        m_indicesProperty.set( iSamp.getFaceIndices() );
        m_countsProperty.set( iSamp.getFaceCounts() );

        if ( m_velocitiesProperty )
        { SetPropUsePrevIfNull( m_velocitiesProperty, iSamp.getVelocities() ); }

        if ( iSamp.getSelfBounds().isEmpty() )
        {
            // OTypedScalarProperty::set() is not referentially transparent,
            // so we need a a placeholder variable.
            Abc::Box3d bnds(
                ComputeBoundsFromPositions( iSamp.getPositions() ) );
            m_selfBoundsProperty.set( bnds );
        }
        else { m_selfBoundsProperty.set( iSamp.getSelfBounds() ); }

        if ( iSamp.getUVs().getVals() )
        {
            m_uvsParam.set( iSamp.getUVs() );
        }
        if ( iSamp.getNormals().getVals() )
        {
            m_normalsParam.set( iSamp.getNormals() );
        }
    }
    else
    {
        SetPropUsePrevIfNull( m_positionsProperty, iSamp.getPositions() );
        SetPropUsePrevIfNull( m_indicesProperty, iSamp.getFaceIndices() );
        SetPropUsePrevIfNull( m_countsProperty, iSamp.getFaceCounts() );

        if ( m_velocitiesProperty )
        {
            SetPropUsePrevIfNull( m_velocitiesProperty, iSamp.getVelocities() );
        }

        if ( iSamp.getSelfBounds().hasVolume() )
        {
            m_selfBoundsProperty.set( iSamp.getSelfBounds() );
        }
        else if ( iSamp.getPositions() )
        {
            Abc::Box3d bnds(
                ComputeBoundsFromPositions( iSamp.getPositions() ) );
            m_selfBoundsProperty.set( bnds );
        }
        else
        {
            m_selfBoundsProperty.setFromPrevious();
        }

        // OGeomParam will automatically use SetPropUsePrevIfNull internally
        if ( m_uvsParam ) { m_uvsParam.set( iSamp.getUVs() ); }
        if ( m_normalsParam ) { m_normalsParam.set( iSamp.getNormals() ); }
    }

    ALEMBIC_ABC_SAFE_CALL_END();
}