voxcraft / voxcraft-sim

a GPU-accelerated voxel-based physics engine
Creative Commons Zero v1.0 Universal
48 stars 11 forks source link

VX3/VX3_Link.cu:129 assert error - floating point imprecision #21

Closed ai-honzik closed 4 years ago

ai-honzik commented 4 years ago

Sometimes I get assert error from VX3_Link.cu at line 129 (VX3_Link::orientLink()). Looking at the asserts it feels like there could be some floating point imprecision.

liusida commented 4 years ago

if it is one of these lines

    assert(!(angle1v.x != angle1v.x) || !(angle1v.y != angle1v.y) || !(angle1v.z != angle1v.z)); // assert non QNAN
    assert(!(angle2v.x != angle2v.x) || !(angle2v.y != angle2v.y) || !(angle2v.z != angle2v.z)); // assert non QNAN

I think the simulation has diverged.

So can you tell us more about your simulation and the running environment? Thanks.

ai-honzik commented 4 years ago

Here's base.vxa:

<VXA Version="1.1">
  <Simulator>
    <Integration>
      <DtFrac>0.9</DtFrac>
    </Integration>
    <Damping>
      <BondDampingZ>0.1</BondDampingZ>
      <ColDampingZ>1.0</ColDampingZ>
      <SlowDampingZ>1.0</SlowDampingZ>
    </Damping>
    <StopCondition>
      <StopConditionFormula>
        <mtSUB>
          <mtVAR>t</mtVAR>
          <mtCONST>3</mtCONST>
        </mtSUB>
      </StopConditionFormula>
    </StopCondition>
    <RecordHistory>
      <RecordStepSize>100</RecordStepSize>
      <RecordVoxel>1</RecordVoxel>
      <RecordLink>0</RecordLink>
    </RecordHistory>
    <AttachDetach>
      <EnableCollision>1</EnableCollision>
      <SafetyGuard>500</SafetyGuard>
    </AttachDetach>
    <EnableSignals>0</EnableSignals>
    <EnableCilia>0</EnableCilia>
    <SavePositionOfAllVoxels>0</SavePositionOfAllVoxels>
    <MaxDistInVoxelLengthsToCountAsPair>0</MaxDistInVoxelLengthsToCountAsPair>
  </Simulator>
  <Environment>
    <Gravity>
      <GravEnabled>1</GravEnabled>
      <GravAcc>-9.81</GravAcc>
      <FloorEnabled>1</FloorEnabled>
    </Gravity>
    <Thermal>
      <TempEnabled>1</TempEnabled>
      <VaryTempEnabled>1</VaryTempEnabled>
      <TempBase>25</TempBase>
      <TempAmplitude>14.4714</TempAmplitude>
      <TempPeriod>0.2</TempPeriod>
    </Thermal>
  </Environment>
  <VXC Version="0.94">
    <Lattice>
      <Lattice_Dim>0.01</Lattice_Dim>
    </Lattice>
    <Palette>
      <Material ID="1">
        <Name>Material 0</Name>
        <Display>
          <Red>0.3285109566477631</Red>
          <Green>0.5785790143257142</Green>
          <Blue>0.3055528010936237</Blue>
          <Alpha>1</Alpha>
        </Display>
        <Mechanical>
          <isTarget>0</isTarget>
          <isMeasured>1</isMeasured>
          <Fixed>0</Fixed>
          <Sticky>0</Sticky>
          <Cilia>False</Cilia>
          <PaceMakerPeriod>0</PaceMakerPeriod>
          <signalValueDecay>0.9</signalValueDecay>
          <signalTimeDelay>0.03</signalTimeDelay>
          <inactivePeriod>0.03</inactivePeriod>
          <MatModel>0</MatModel>
          <Elastic_Mod>441274.84564525186</Elastic_Mod>
          <Fail_Stress>0</Fail_Stress>
          <Density>1400.9653250102235</Density>
          <Poissons_Ratio>0</Poissons_Ratio>
          <CTE>0.06888200352646083</CTE>
          <uStatic>1.4825579118944283</uStatic>
          <uDynamic>0.857855370999932</uDynamic>
          <Cilia>0</Cilia>
        </Mechanical>
      </Material>
      <Material ID="2">
        <Name>Material 1</Name>
        <Display>
          <Red>0.6742717228327393</Red>
          <Green>0.168105908949584</Green>
          <Blue>0.13248528801962312</Blue>
          <Alpha>1</Alpha>
        </Display>
        <Mechanical>
          <isTarget>0</isTarget>
          <isMeasured>1</isMeasured>
          <Fixed>0</Fixed>
          <Sticky>0</Sticky>
          <Cilia>False</Cilia>
          <PaceMakerPeriod>0</PaceMakerPeriod>
          <signalValueDecay>0.9</signalValueDecay>
          <signalTimeDelay>0.03</signalTimeDelay>
          <inactivePeriod>0.03</inactivePeriod>
          <MatModel>0</MatModel>
          <Elastic_Mod>7494043.496188642</Elastic_Mod>
          <Fail_Stress>0</Fail_Stress>
          <Density>338.15268018771684</Density>
          <Poissons_Ratio>0</Poissons_Ratio>
          <CTE>0.0</CTE>
          <uStatic>4.920633165404592</uStatic>
          <uDynamic>0.8471648059826079</uDynamic>
          <Cilia>0</Cilia>
        </Mechanical>
      </Material>
      <Material ID="3">
        <Name>Material 2</Name>
        <Display>
          <Red>0.8576355403675837</Red>
          <Green>0.30896717247739636</Green>
          <Blue>0.21509161873780458</Blue>
          <Alpha>1</Alpha>
        </Display>
        <Mechanical>
          <isTarget>0</isTarget>
          <isMeasured>1</isMeasured>
          <Fixed>0</Fixed>
          <Sticky>0</Sticky>
          <Cilia>False</Cilia>
          <PaceMakerPeriod>0</PaceMakerPeriod>
          <signalValueDecay>0.9</signalValueDecay>
          <signalTimeDelay>0.03</signalTimeDelay>
          <inactivePeriod>0.03</inactivePeriod>
          <MatModel>0</MatModel>
          <Elastic_Mod>287171.9460809029</Elastic_Mod>
          <Fail_Stress>0</Fail_Stress>
          <Density>377.9367937612897</Density>
          <Poissons_Ratio>0</Poissons_Ratio>
          <CTE>-0.0837087214087211</CTE>
          <uStatic>1.4009254271707867</uStatic>
          <uDynamic>0.9804866414159955</uDynamic>
          <Cilia>0</Cilia>
        </Mechanical>
      </Material>
    </Palette>
  </VXC>
</VXA>

and bot.vxd:

<VXD>
  <Structure replace="VXA.VXC.Structure" Compression="ASCII_READABLE">
    <X_Voxels>5</X_Voxels>
    <Y_Voxels>1</Y_Voxels>
    <Z_Voxels>1</Z_Voxels>
    <Data>
      <Layer><![CDATA[11123]]></Layer>
    </Data>
  </Structure>
</VXD>

The history file seems to have normal output, until

 File not exist: workspace/locally/20200711160513.vxr. Worker failed to finish the job.

and

/voxcraft-sim/src/VX3/VX3_Link.cu:129: VX3_Quat3D<double> VX3_Link::orientLink(): block: [0,0,0], thread: [3,0,0] Assertion `!(angle1v.x != angle1v.x) || !(angle1v.y != angle1v.y) || !(angle1v.z != angle1v.z)` failed.
liusida commented 4 years ago

Hi, sorry for the late reply.

I figured this out. You can change:

<DtFrac>0.9</DtFrac>

to

<DtFrac>0.8</DtFrac>

The reason behind this is that the recommended timestep is still a little too big for your setup, so taking a slightly smaller timestep can mediate this problem. And the animation looks cute!

ai-honzik commented 4 years ago

Okay, thank you!

Is there any way to determine this? I've noticed you can get negative fitness in the xml file but am not sure if that has anything to do with the simulation diverging. If so, if I were to predefine my own fitness function through math three, would this still be possible?

liusida commented 4 years ago

The principle of determining the step size: too large, it will diverge; too small, it will take a longer time to do the calculation.

So if everything is good, use 1.0. If things diverge, try a smaller fraction.

About the fitness score, you can either define your own math tree, or, because I found that defining math tree is a little messy, you can use the quantities like CoM to calculate your own fitness score in Python, if you want to read the result XML in Python.

ai-honzik commented 4 years ago

For now, I am using CoM but I'll need to get rotation as well. I think this should be possible with history files, I might try math tree too.