00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SIM_GasAdd.h"
00029 #include <UT/UT_DSOVersion.h>
00030 #include <UT/UT_Interrupt.h>
00031 #include <PRM/PRM_Include.h>
00032 #include <SIM/SIM_PRMShared.h>
00033 #include <SIM/SIM_DopDescription.h>
00034 #include <SIM/SIM_ScalarField.h>
00035 #include <SIM/SIM_VectorField.h>
00036 #include <SIM/SIM_MatrixField.h>
00037 #include <SIM/SIM_Object.h>
00038 #include <GAS/GAS_SubSolver.h>
00039
00040 using namespace HDK_Sample;
00041
00042
00043
00044
00045
00046
00047 void
00048 initializeSIM(void *)
00049 {
00050 IMPLEMENT_DATAFACTORY(SIM_GasAdd);
00051 }
00052
00053
00054
00055
00056 SIM_GasAdd::SIM_GasAdd(const SIM_DataFactory *factory)
00057 : BaseClass(factory)
00058 {
00059 }
00060
00061 SIM_GasAdd::~SIM_GasAdd()
00062 {
00063 }
00064
00065
00066
00067 const SIM_DopDescription *
00068 SIM_GasAdd::getDopDescription()
00069 {
00070 static PRM_Name theDstFieldName(GAS_NAME_FIELDDEST, "Dest Field");
00071 static PRM_Name theSrcFieldName(GAS_NAME_FIELDSOURCE, "Source Field");
00072
00073 static PRM_Template theTemplates[] = {
00074 PRM_Template(PRM_STRING, 1, &theDstFieldName),
00075 PRM_Template(PRM_STRING, 1, &theSrcFieldName),
00076 PRM_Template()
00077 };
00078
00079 static SIM_DopDescription theDopDescription(
00080 true,
00081 "hdk_gasadd",
00082 "Gas Add",
00083 "Solver",
00084 classname(),
00085 theTemplates);
00086
00087 return &theDopDescription;
00088 }
00089
00090 bool
00091 SIM_GasAdd::solveGasSubclass(SIM_Engine &engine,
00092 SIM_Object *obj,
00093 SIM_Time time,
00094 SIM_Time timestep)
00095 {
00096 SIM_ScalarField *srcscalar, *dstscalar;
00097 SIM_VectorField *srcvector, *dstvector;
00098 SIM_MatrixField *srcmatrix, *dstmatrix;
00099
00100 SIM_DataArray src, dst;
00101 int i, j, k;
00102
00103 getMatchingData(src, obj, GAS_NAME_FIELDSOURCE);
00104 getMatchingData(dst, obj, GAS_NAME_FIELDDEST);
00105
00106
00107
00108
00109
00110 for (i = 0; i < dst.entries(); i++)
00111 {
00112
00113 if (i >= src.entries())
00114 {
00115 addError(obj, SIM_MESSAGE, "Fewer source fields than destination fields.", UT_ERROR_WARNING);
00116 break;
00117 }
00118
00119
00120 dstscalar = SIM_DATA_CAST(dst(i), SIM_ScalarField);
00121 srcscalar = SIM_DATA_CAST(src(i), SIM_ScalarField);
00122
00123 dstvector = SIM_DATA_CAST(dst(i), SIM_VectorField);
00124 srcvector = SIM_DATA_CAST(src(i), SIM_VectorField);
00125
00126 dstmatrix = SIM_DATA_CAST(dst(i), SIM_MatrixField);
00127 srcmatrix = SIM_DATA_CAST(src(i), SIM_MatrixField);
00128
00129 if (dstscalar && srcscalar)
00130 {
00131 addFields(dstscalar->getField(), srcscalar->getField());
00132 }
00133
00134 if (dstvector && srcvector)
00135 {
00136 for (j = 0; j < 3; j++)
00137 addFields(dstvector->getField(j), srcvector->getField(j));
00138 }
00139
00140 if (dstmatrix && srcmatrix)
00141 {
00142 for (j = 0; j < 3; j++)
00143 for (k = 0; k < 3; k++)
00144 addFields(dstmatrix->getField(j, k), srcmatrix->getField(j, k));
00145 }
00146
00147
00148 if (dstscalar)
00149 dstscalar->pubHandleModification();
00150 if (dstvector)
00151 dstvector->pubHandleModification();
00152 if (dstmatrix)
00153 dstmatrix->pubHandleModification();
00154 }
00155
00156
00157 return true;
00158 }
00159
00160 void
00161 SIM_GasAdd::addFieldsPartial(SIM_RawField *dst, const SIM_RawField *src, const UT_JobInfo &info)
00162 {
00163 UT_VoxelArrayIteratorF vit;
00164 UT_Interrupt *boss = UTgetInterrupt();
00165
00166
00167 vit.setArray(dst->field());
00168
00169
00170
00171 vit.setCompressOnExit(true);
00172
00173
00174
00175 vit.setPartialRange(info.job(), info.numJobs());
00176
00177
00178
00179
00180 if (dst->isAligned(src))
00181 {
00182 UT_VoxelProbeF probe;
00183
00184 probe.setArray(src->field());
00185
00186 for (vit.rewind(); !vit.atEnd(); vit.advance())
00187 {
00188 if (vit.isStartOfTile() && boss->opInterrupt())
00189 break;
00190
00191
00192
00193 probe.setIndex(vit);
00194
00195
00196
00197
00198 vit.setValue( vit.getValue() + probe.getValue() );
00199 }
00200 }
00201 else
00202 {
00203
00204
00205 UT_Vector3 pos;
00206
00207 for (vit.rewind(); !vit.atEnd(); vit.advance())
00208 {
00209 if (vit.isStartOfTile() && boss->opInterrupt())
00210 break;
00211 dst->indexToPos(vit.x(), vit.y(), vit.z(), pos);
00212
00213
00214
00215
00216 vit.setValue( vit.getValue() + src->getValue(pos) );
00217 }
00218 }
00219 }