// ------------------ surface --------------------- SReal Cell::surface() { if (getProperties()->getType()== StructureProperties::QUAD || getProperties()->getType()== StructureProperties::TRIANGLE) { SReal A[3]= {0.0, 0.0, 0.0 }; unsigned int nbElem; nbElem = Cell::getNumberOfStructures(); SReal posi[3], posip1[3]; ((Atom*)getStructure(0))->getPosition(posip1); for (unsigned int i=0; i<nbElem; i++) { posi[0]=posip1[0]; posi[1]=posip1[1]; posi[2]=posip1[2]; ((Atom*)getStructure((i+1)%nbElem))->getPosition(posip1); //Cross(posi, posip1, inter); A[0] += posi[1]*posip1[2] - posi[2]*posip1[1]; A[1] += posi[2]*posip1[0] - posi[0]*posip1[2]; A[2] += posi[0]*posip1[1] - posi[1]*posip1[0]; } // here A is in fact twice the theoritical area vector A[0] /= 2.0; A[1] /= 2.0; A[2] /= 2.0; // face normal : SReal * N = normal(); SReal surface = N[0]*A[0] + N[1]*A[1] + N[2]*A[2]; return surface>0?surface:-surface; } else { StructuralComponent * facets = getFacets(); if (!facets) return 0.0; SReal surface=0.0; for (unsigned int i=0 ; i<facets->getNumberOfCells() ; i++) { surface += facets->getCell(i)->surface(); } return surface; } }
// ------------------ volume --------------------- SReal Cell::volume() { StructuralComponent * facets = getFacets(); if (!facets || getProperties()->getType()== StructureProperties::QUAD || getProperties()->getType()== StructureProperties::TRIANGLE) return 0.0; SReal vol=0.0; Cell * face; for (unsigned int i=0; i < facets->getNumberOfCells(); i++) { face = facets->getCell(i); SReal pos[3]; ((Atom*)face->getStructure(0))->getPosition(pos); SReal * N = face->normal(); vol += face->surface()* ( pos[0]*N[0] + pos[1]*N[1] + pos[2]*N[2] ); } vol /= 3.0; return vol>0?vol:-vol; }
// // Assign facets // assign common facets // assign additional facet // void AbstractNumericFacetValidator::assignFacet(MemoryManager* const manager) { RefHashTableOf<KVStringPair>* facets = getFacets(); if (!facets) // no facets defined return; XMLCh* key; RefHashTableOfEnumerator<KVStringPair> e(facets, false, manager); while (e.hasMoreElements()) { KVStringPair pair = e.nextElement(); key = pair.getKey(); XMLCh* value = pair.getValue(); if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN)) { setPattern(value); if (getPattern()) setFacetsDefined(DatatypeValidator::FACET_PATTERN); // do not construct regex until needed } else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXINCLUSIVE)) { try { setMaxInclusive(value); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MaxIncl, value, manager); } setFacetsDefined(DatatypeValidator::FACET_MAXINCLUSIVE); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXEXCLUSIVE)) { try { setMaxExclusive(value); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MaxExcl, value, manager); } setFacetsDefined(DatatypeValidator::FACET_MAXEXCLUSIVE); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MININCLUSIVE)) { try { setMinInclusive(value); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MinIncl, value, manager); } setFacetsDefined(DatatypeValidator::FACET_MININCLUSIVE); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MINEXCLUSIVE)) { try { setMinExclusive(value); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MinExcl, value, manager); } setFacetsDefined(DatatypeValidator::FACET_MINEXCLUSIVE); } else if (XMLString::equals(key, SchemaSymbols::fgATT_FIXED)) { unsigned int val; bool retStatus; try { retStatus = XMLString::textToBin(value, val, fMemoryManager); } catch (RuntimeException&) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); } if (!retStatus) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); } setFixed(val); //no setFacetsDefined here } else { assignAdditionalFacet(key, value, manager); } }//while }// end of assigneFacet()
// // Assign facets // assign common facets // assign additional facet // void AbstractStringValidator::assignFacet(MemoryManager* const manager) { RefHashTableOf<KVStringPair>* facets = getFacets(); if (!facets) return; XMLCh* key; RefHashTableOfEnumerator<KVStringPair> e(facets, false, manager); while (e.hasMoreElements()) { KVStringPair pair = e.nextElement(); key = pair.getKey(); XMLCh* value = pair.getValue(); if (XMLString::equals(key, SchemaSymbols::fgELT_LENGTH)) { int val; try { val = XMLString::parseInt(value, manager); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value, manager); } if ( val < 0 ) ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value, manager); setLength(val); setFacetsDefined(DatatypeValidator::FACET_LENGTH); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MINLENGTH)) { int val; try { val = XMLString::parseInt(value, manager); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value, manager); } if ( val < 0 ) ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value, manager); setMinLength(val); setFacetsDefined(DatatypeValidator::FACET_MINLENGTH); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXLENGTH)) { int val; try { val = XMLString::parseInt(value, manager); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value, manager); } if ( val < 0 ) ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value, manager); setMaxLength(val); setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH); } else if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN)) { setPattern(value); if (getPattern()) setFacetsDefined(DatatypeValidator::FACET_PATTERN); // do not construct regex until needed } else if (XMLString::equals(key, SchemaSymbols::fgATT_FIXED)) { unsigned int val; bool retStatus; try { retStatus = XMLString::textToBin(value, val, fMemoryManager); } catch (RuntimeException&) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); } if (!retStatus) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); } setFixed(val); //no setFacetsDefined here } // // else if (XMLString::equals(key, SchemaSymbols::fgELT_SPECIAL_TOKEN)) // TODO // // Note: whitespace is taken care of by TraverseSchema. // else { assignAdditionalFacet(key, value, manager); } }//while }//end of assigneFacet()